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