ext_common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /* Magic value used to identify an ext2 filesystem. */
  37. #define EXT2_MAGIC 0xEF53
  38. /* Amount of indirect blocks in an inode. */
  39. #define INDIRECT_BLOCKS 12
  40. /* Maximum lenght of a pathname. */
  41. #define EXT2_PATH_MAX 4096
  42. /* Maximum nesting of symlinks, used to prevent a loop. */
  43. #define EXT2_MAX_SYMLINKCNT 8
  44. /* Filetype used in directory entry. */
  45. #define FILETYPE_UNKNOWN 0
  46. #define FILETYPE_REG 1
  47. #define FILETYPE_DIRECTORY 2
  48. #define FILETYPE_SYMLINK 7
  49. /* Filetype information as used in inodes. */
  50. #define FILETYPE_INO_MASK 0170000
  51. #define FILETYPE_INO_REG 0100000
  52. #define FILETYPE_INO_DIRECTORY 0040000
  53. #define FILETYPE_INO_SYMLINK 0120000
  54. #define EXT2_ROOT_INO 2 /* Root inode */
  55. /* The size of an ext2 block in bytes. */
  56. #define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
  57. /* Log2 size of ext2 block in bytes. */
  58. #define LOG2_BLOCK_SIZE(data) (__le32_to_cpu \
  59. (data->sblock.log2_block_size) \
  60. + EXT2_MIN_BLOCK_LOG_SIZE)
  61. #define INODE_SIZE_FILESYSTEM(data) (__le32_to_cpu \
  62. (data->sblock.inode_size))
  63. #define EXT2_FT_DIR 2
  64. #define SUCCESS 1
  65. /* Macro-instructions used to manage several block sizes */
  66. #define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
  67. #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
  68. #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
  69. #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
  70. /* The ext2 superblock. */
  71. struct ext2_sblock {
  72. uint32_t total_inodes;
  73. uint32_t total_blocks;
  74. uint32_t reserved_blocks;
  75. uint32_t free_blocks;
  76. uint32_t free_inodes;
  77. uint32_t first_data_block;
  78. uint32_t log2_block_size;
  79. uint32_t log2_fragment_size;
  80. uint32_t blocks_per_group;
  81. uint32_t fragments_per_group;
  82. uint32_t inodes_per_group;
  83. uint32_t mtime;
  84. uint32_t utime;
  85. uint16_t mnt_count;
  86. uint16_t max_mnt_count;
  87. uint16_t magic;
  88. uint16_t fs_state;
  89. uint16_t error_handling;
  90. uint16_t minor_revision_level;
  91. uint32_t lastcheck;
  92. uint32_t checkinterval;
  93. uint32_t creator_os;
  94. uint32_t revision_level;
  95. uint16_t uid_reserved;
  96. uint16_t gid_reserved;
  97. uint32_t first_inode;
  98. uint16_t inode_size;
  99. uint16_t block_group_number;
  100. uint32_t feature_compatibility;
  101. uint32_t feature_incompat;
  102. uint32_t feature_ro_compat;
  103. uint32_t unique_id[4];
  104. char volume_name[16];
  105. char last_mounted_on[64];
  106. uint32_t compression_info;
  107. };
  108. struct ext2_block_group {
  109. __u32 block_id; /* Blocks bitmap block */
  110. __u32 inode_id; /* Inodes bitmap block */
  111. __u32 inode_table_id; /* Inodes table block */
  112. __u16 free_blocks; /* Free blocks count */
  113. __u16 free_inodes; /* Free inodes count */
  114. __u16 used_dir_cnt; /* Directories count */
  115. __u16 bg_flags;
  116. __u32 bg_reserved[2];
  117. __u16 bg_itable_unused; /* Unused inodes count */
  118. __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/
  119. };
  120. /* The ext2 inode. */
  121. struct ext2_inode {
  122. uint16_t mode;
  123. uint16_t uid;
  124. uint32_t size;
  125. uint32_t atime;
  126. uint32_t ctime;
  127. uint32_t mtime;
  128. uint32_t dtime;
  129. uint16_t gid;
  130. uint16_t nlinks;
  131. uint32_t blockcnt; /* Blocks of 512 bytes!! */
  132. uint32_t flags;
  133. uint32_t osd1;
  134. union {
  135. struct datablocks {
  136. uint32_t dir_blocks[INDIRECT_BLOCKS];
  137. uint32_t indir_block;
  138. uint32_t double_indir_block;
  139. uint32_t triple_indir_block;
  140. } blocks;
  141. char symlink[60];
  142. } b;
  143. uint32_t version;
  144. uint32_t acl;
  145. uint32_t dir_acl;
  146. uint32_t fragment_addr;
  147. uint32_t osd2[3];
  148. };
  149. /* The header of an ext2 directory entry. */
  150. struct ext2_dirent {
  151. uint32_t inode;
  152. uint16_t direntlen;
  153. uint8_t namelen;
  154. uint8_t filetype;
  155. };
  156. struct ext2fs_node {
  157. struct ext2_data *data;
  158. struct ext2_inode inode;
  159. int ino;
  160. int inode_read;
  161. };
  162. /* Information about a "mounted" ext2 filesystem. */
  163. struct ext2_data {
  164. struct ext2_sblock sblock;
  165. struct ext2_inode *inode;
  166. struct ext2fs_node diropen;
  167. };
  168. extern unsigned long part_offset;
  169. int do_ext2ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  170. int do_ext2load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  171. int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
  172. char *const argv[]);
  173. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
  174. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  175. char *const argv[]);
  176. #endif