ext_common.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * (C) Copyright 2011 - 2012 Samsung Electronics
  3. * EXT4 filesystem implementation in Uboot by
  4. * Uma Shankar <uma.shankar@samsung.com>
  5. * Manjunatha C Achar <a.manjunatha@samsung.com>
  6. *
  7. * Data structures and headers for ext4 support have been taken from
  8. * ext2 ls load support in Uboot
  9. *
  10. * (C) Copyright 2004
  11. * esd gmbh <www.esd-electronics.com>
  12. * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
  13. *
  14. * based on code from grub2 fs/ext2.c and fs/fshelp.c by
  15. * GRUB -- GRand Unified Bootloader
  16. * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #ifndef __EXT_COMMON__
  33. #define __EXT_COMMON__
  34. #include <command.h>
  35. #define SECTOR_SIZE 0x200
  36. #define SECTOR_BITS 9
  37. /* Magic value used to identify an ext2 filesystem. */
  38. #define EXT2_MAGIC 0xEF53
  39. /* Amount of indirect blocks in an inode. */
  40. #define INDIRECT_BLOCKS 12
  41. /* Maximum lenght of a pathname. */
  42. #define EXT2_PATH_MAX 4096
  43. /* Maximum nesting of symlinks, used to prevent a loop. */
  44. #define EXT2_MAX_SYMLINKCNT 8
  45. /* Filetype used in directory entry. */
  46. #define FILETYPE_UNKNOWN 0
  47. #define FILETYPE_REG 1
  48. #define FILETYPE_DIRECTORY 2
  49. #define FILETYPE_SYMLINK 7
  50. /* Filetype information as used in inodes. */
  51. #define FILETYPE_INO_MASK 0170000
  52. #define FILETYPE_INO_REG 0100000
  53. #define FILETYPE_INO_DIRECTORY 0040000
  54. #define FILETYPE_INO_SYMLINK 0120000
  55. #define EXT2_ROOT_INO 2 /* Root inode */
  56. /* Bits used as offset in sector */
  57. #define DISK_SECTOR_BITS 9
  58. /* The size of an ext2 block in bytes. */
  59. #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
  60. /* Log2 size of ext2 block in 512 blocks. */
  61. #define LOG2_EXT2_BLOCK_SIZE(data) (__le32_to_cpu \
  62. (data->sblock.log2_block_size) + 1)
  63. /* Log2 size of ext2 block in bytes. */
  64. #define LOG2_BLOCK_SIZE(data) (__le32_to_cpu \
  65. (data->sblock.log2_block_size) + 10)
  66. #define INODE_SIZE_FILESYSTEM(data) (__le32_to_cpu \
  67. (data->sblock.inode_size))
  68. #define EXT2_FT_DIR 2
  69. #define SUCCESS 1
  70. /* Macro-instructions used to manage several block sizes */
  71. #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
  72. #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
  73. #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
  74. #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
  75. /* The ext2 superblock. */
  76. struct ext2_sblock {
  77. uint32_t total_inodes;
  78. uint32_t total_blocks;
  79. uint32_t reserved_blocks;
  80. uint32_t free_blocks;
  81. uint32_t free_inodes;
  82. uint32_t first_data_block;
  83. uint32_t log2_block_size;
  84. uint32_t log2_fragment_size;
  85. uint32_t blocks_per_group;
  86. uint32_t fragments_per_group;
  87. uint32_t inodes_per_group;
  88. uint32_t mtime;
  89. uint32_t utime;
  90. uint16_t mnt_count;
  91. uint16_t max_mnt_count;
  92. uint16_t magic;
  93. uint16_t fs_state;
  94. uint16_t error_handling;
  95. uint16_t minor_revision_level;
  96. uint32_t lastcheck;
  97. uint32_t checkinterval;
  98. uint32_t creator_os;
  99. uint32_t revision_level;
  100. uint16_t uid_reserved;
  101. uint16_t gid_reserved;
  102. uint32_t first_inode;
  103. uint16_t inode_size;
  104. uint16_t block_group_number;
  105. uint32_t feature_compatibility;
  106. uint32_t feature_incompat;
  107. uint32_t feature_ro_compat;
  108. uint32_t unique_id[4];
  109. char volume_name[16];
  110. char last_mounted_on[64];
  111. uint32_t compression_info;
  112. };
  113. struct ext2_block_group {
  114. __u32 block_id; /* Blocks bitmap block */
  115. __u32 inode_id; /* Inodes bitmap block */
  116. __u32 inode_table_id; /* Inodes table block */
  117. __u16 free_blocks; /* Free blocks count */
  118. __u16 free_inodes; /* Free inodes count */
  119. __u16 used_dir_cnt; /* Directories count */
  120. __u16 bg_flags;
  121. __u32 bg_reserved[2];
  122. __u16 bg_itable_unused; /* Unused inodes count */
  123. __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
  124. };
  125. /* The ext2 inode. */
  126. struct ext2_inode {
  127. uint16_t mode;
  128. uint16_t uid;
  129. uint32_t size;
  130. uint32_t atime;
  131. uint32_t ctime;
  132. uint32_t mtime;
  133. uint32_t dtime;
  134. uint16_t gid;
  135. uint16_t nlinks;
  136. uint32_t blockcnt; /* Blocks of 512 bytes!! */
  137. uint32_t flags;
  138. uint32_t osd1;
  139. union {
  140. struct datablocks {
  141. uint32_t dir_blocks[INDIRECT_BLOCKS];
  142. uint32_t indir_block;
  143. uint32_t double_indir_block;
  144. uint32_t triple_indir_block;
  145. } blocks;
  146. char symlink[60];
  147. } b;
  148. uint32_t version;
  149. uint32_t acl;
  150. uint32_t dir_acl;
  151. uint32_t fragment_addr;
  152. uint32_t osd2[3];
  153. };
  154. /* The header of an ext2 directory entry. */
  155. struct ext2_dirent {
  156. uint32_t inode;
  157. uint16_t direntlen;
  158. uint8_t namelen;
  159. uint8_t filetype;
  160. };
  161. struct ext2fs_node {
  162. struct ext2_data *data;
  163. struct ext2_inode inode;
  164. int ino;
  165. int inode_read;
  166. };
  167. /* Information about a "mounted" ext2 filesystem. */
  168. struct ext2_data {
  169. struct ext2_sblock sblock;
  170. struct ext2_inode *inode;
  171. struct ext2fs_node diropen;
  172. };
  173. int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  174. int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  175. int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
  176. char *const argv[]);
  177. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
  178. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  179. char *const argv[]);
  180. int do_ext_load(cmd_tbl_t *cmdtp, int flag, int argc,
  181. char *const argv[]);
  182. int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
  183. #endif