ext_common.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2011 - 2012 Samsung Electronics
  4. * EXT4 filesystem implementation in Uboot by
  5. * Uma Shankar <uma.shankar@samsung.com>
  6. * Manjunatha C Achar <a.manjunatha@samsung.com>
  7. *
  8. * Data structures and headers for ext4 support have been taken from
  9. * ext2 ls load support in Uboot
  10. *
  11. * (C) Copyright 2004
  12. * esd gmbh <www.esd-electronics.com>
  13. * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
  14. *
  15. * based on code from grub2 fs/ext2.c and fs/fshelp.c by
  16. * GRUB -- GRand Unified Bootloader
  17. * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  18. */
  19. #ifndef __EXT_COMMON__
  20. #define __EXT_COMMON__
  21. #include <command.h>
  22. #define SECTOR_SIZE 0x200
  23. #define LOG2_SECTOR_SIZE 9
  24. /* Magic value used to identify an ext2 filesystem. */
  25. #define EXT2_MAGIC 0xEF53
  26. /* Amount of indirect blocks in an inode. */
  27. #define INDIRECT_BLOCKS 12
  28. /* Maximum lenght of a pathname. */
  29. #define EXT2_PATH_MAX 4096
  30. /* Maximum nesting of symlinks, used to prevent a loop. */
  31. #define EXT2_MAX_SYMLINKCNT 8
  32. /* Filetype used in directory entry. */
  33. #define FILETYPE_UNKNOWN 0
  34. #define FILETYPE_REG 1
  35. #define FILETYPE_DIRECTORY 2
  36. #define FILETYPE_SYMLINK 7
  37. /* Filetype information as used in inodes. */
  38. #define FILETYPE_INO_MASK 0170000
  39. #define FILETYPE_INO_REG 0100000
  40. #define FILETYPE_INO_DIRECTORY 0040000
  41. #define FILETYPE_INO_SYMLINK 0120000
  42. #define EXT2_ROOT_INO 2 /* Root inode */
  43. /* The size of an ext2 block in bytes. */
  44. #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
  45. /* Log2 size of ext2 block in bytes. */
  46. #define LOG2_BLOCK_SIZE(data) (le32_to_cpu \
  47. (data->sblock.log2_block_size) \
  48. + EXT2_MIN_BLOCK_LOG_SIZE)
  49. #define EXT2_FT_DIR 2
  50. #define SUCCESS 1
  51. /* Macro-instructions used to manage several block sizes */
  52. #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
  53. #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
  54. #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
  55. #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
  56. /* The ext2 superblock. */
  57. struct ext2_sblock {
  58. __le32 total_inodes;
  59. __le32 total_blocks;
  60. __le32 reserved_blocks;
  61. __le32 free_blocks;
  62. __le32 free_inodes;
  63. __le32 first_data_block;
  64. __le32 log2_block_size;
  65. __le32 log2_fragment_size;
  66. __le32 blocks_per_group;
  67. __le32 fragments_per_group;
  68. __le32 inodes_per_group;
  69. __le32 mtime;
  70. __le32 utime;
  71. __le16 mnt_count;
  72. __le16 max_mnt_count;
  73. __le16 magic;
  74. __le16 fs_state;
  75. __le16 error_handling;
  76. __le16 minor_revision_level;
  77. __le32 lastcheck;
  78. __le32 checkinterval;
  79. __le32 creator_os;
  80. __le32 revision_level;
  81. __le16 uid_reserved;
  82. __le16 gid_reserved;
  83. __le32 first_inode;
  84. __le16 inode_size;
  85. __le16 block_group_number;
  86. __le32 feature_compatibility;
  87. __le32 feature_incompat;
  88. __le32 feature_ro_compat;
  89. __le32 unique_id[4];
  90. char volume_name[16];
  91. char last_mounted_on[64];
  92. __le32 compression_info;
  93. uint8_t prealloc_blocks;
  94. uint8_t prealloc_dir_blocks;
  95. __le16 reserved_gdt_blocks;
  96. uint8_t journal_uuid[16];
  97. __le32 journal_inode;
  98. __le32 journal_dev;
  99. __le32 last_orphan;
  100. __le32 hash_seed[4];
  101. uint8_t default_hash_version;
  102. uint8_t journal_backup_type;
  103. __le16 descriptor_size;
  104. __le32 default_mount_options;
  105. __le32 first_meta_block_group;
  106. __le32 mkfs_time;
  107. __le32 journal_blocks[17];
  108. __le32 total_blocks_high;
  109. __le32 reserved_blocks_high;
  110. __le32 free_blocks_high;
  111. __le16 min_extra_inode_size;
  112. __le16 want_extra_inode_size;
  113. __le32 flags;
  114. __le16 raid_stride;
  115. __le16 mmp_interval;
  116. __le64 mmp_block;
  117. __le32 raid_stripe_width;
  118. uint8_t log2_groups_per_flex;
  119. uint8_t checksum_type;
  120. };
  121. struct ext2_block_group {
  122. __le32 block_id; /* Blocks bitmap block */
  123. __le32 inode_id; /* Inodes bitmap block */
  124. __le32 inode_table_id; /* Inodes table block */
  125. __le16 free_blocks; /* Free blocks count */
  126. __le16 free_inodes; /* Free inodes count */
  127. __le16 used_dir_cnt; /* Directories count */
  128. __le16 bg_flags;
  129. __le32 bg_exclude_bitmap;
  130. __le16 bg_block_id_csum;
  131. __le16 bg_inode_id_csum;
  132. __le16 bg_itable_unused; /* Unused inodes count */
  133. __le16 bg_checksum; /* crc16(s_uuid+group_num+group_desc)*/
  134. /* following fields only exist if descriptor size is 64 */
  135. __le32 block_id_high;
  136. __le32 inode_id_high;
  137. __le32 inode_table_id_high;
  138. __le16 free_blocks_high;
  139. __le16 free_inodes_high;
  140. __le16 used_dir_cnt_high;
  141. __le16 bg_itable_unused_high;
  142. __le32 bg_exclude_bitmap_high;
  143. __le16 bg_block_id_csum_high;
  144. __le16 bg_inode_id_csum_high;
  145. __le32 bg_reserved;
  146. };
  147. /* The ext2 inode. */
  148. struct ext2_inode {
  149. __le16 mode;
  150. __le16 uid;
  151. __le32 size;
  152. __le32 atime;
  153. __le32 ctime;
  154. __le32 mtime;
  155. __le32 dtime;
  156. __le16 gid;
  157. __le16 nlinks;
  158. __le32 blockcnt; /* Blocks of either 512 or block_size bytes */
  159. __le32 flags;
  160. __le32 osd1;
  161. union {
  162. struct datablocks {
  163. __le32 dir_blocks[INDIRECT_BLOCKS];
  164. __le32 indir_block;
  165. __le32 double_indir_block;
  166. __le32 triple_indir_block;
  167. } blocks;
  168. char symlink[60];
  169. char inline_data[60];
  170. } b;
  171. __le32 version;
  172. __le32 acl;
  173. __le32 size_high; /* previously dir_acl, but never used */
  174. __le32 fragment_addr;
  175. __le32 osd2[3];
  176. };
  177. /* The header of an ext2 directory entry. */
  178. struct ext2_dirent {
  179. __le32 inode;
  180. __le16 direntlen;
  181. __u8 namelen;
  182. __u8 filetype;
  183. };
  184. struct ext2fs_node {
  185. struct ext2_data *data;
  186. struct ext2_inode inode;
  187. int ino;
  188. int inode_read;
  189. };
  190. /* Information about a "mounted" ext2 filesystem. */
  191. struct ext2_data {
  192. struct ext2_sblock sblock;
  193. struct ext2_inode *inode;
  194. struct ext2fs_node diropen;
  195. };
  196. extern lbaint_t part_offset;
  197. int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  198. int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  199. int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
  200. char *const argv[]);
  201. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
  202. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  203. char *const argv[]);
  204. #endif