aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/bb_e2fs_defs.h561
-rw-r--r--include/bb_linux_ext2_fs.h547
2 files changed, 561 insertions, 547 deletions
diff --git a/include/bb_e2fs_defs.h b/include/bb_e2fs_defs.h
new file mode 100644
index 000000000..7974497ca
--- /dev/null
+++ b/include/bb_e2fs_defs.h
@@ -0,0 +1,561 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * linux/include/linux/ext2_fs.h
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)
9 *
10 * Copyright (C) 1991, 1992 Linus Torvalds
11 */
12
13#ifndef LINUX_EXT2_FS_H
14#define LINUX_EXT2_FS_H 1
15
16/*
17 * Special inode numbers
18 */
19#define EXT2_BAD_INO 1 /* Bad blocks inode */
20#define EXT2_ROOT_INO 2 /* Root inode */
21#define EXT2_ACL_IDX_INO 3 /* ACL inode */
22#define EXT2_ACL_DATA_INO 4 /* ACL inode */
23#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
24#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
25#define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */
26#define EXT2_JOURNAL_INO 8 /* Journal inode */
27
28/* First non-reserved inode for old ext2 filesystems */
29#define EXT2_GOOD_OLD_FIRST_INO 11
30
31/*
32 * The second extended file system magic number
33 */
34#define EXT2_SUPER_MAGIC 0xEF53
35
36/* Assume that user mode programs are passing in an ext2fs superblock, not
37 * a kernel struct super_block. This will allow us to call the feature-test
38 * macros from user land. */
39#define EXT2_SB(sb) (sb)
40
41/*
42 * Maximal count of links to a file
43 */
44#define EXT2_LINK_MAX 32000
45
46/*
47 * Macro-instructions used to manage several block sizes
48 */
49#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
50#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
51#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
52#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
53#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
54#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
55#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
56 EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
57#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
58 EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
59#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t))
60
61/*
62 * Macro-instructions used to manage fragments
63 */
64#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE
65#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE
66#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE
67#define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
68#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
69
70/*
71 * ACL structures
72 */
73struct ext2_acl_header { /* Header of Access Control Lists */
74 uint32_t aclh_size;
75 uint32_t aclh_file_count;
76 uint32_t aclh_acle_count;
77 uint32_t aclh_first_acle;
78};
79
80struct ext2_acl_entry { /* Access Control List Entry */
81 uint32_t acle_size;
82 uint16_t acle_perms; /* Access permissions */
83 uint16_t acle_type; /* Type of entry */
84 uint16_t acle_tag; /* User or group identity */
85 uint16_t acle_pad1;
86 uint32_t acle_next; /* Pointer on next entry for the */
87 /* same inode or on next free entry */
88};
89
90/*
91 * Structure of a blocks group descriptor
92 */
93struct ext2_group_desc {
94 uint32_t bg_block_bitmap; /* Blocks bitmap block */
95 uint32_t bg_inode_bitmap; /* Inodes bitmap block */
96 uint32_t bg_inode_table; /* Inodes table block */
97 uint16_t bg_free_blocks_count; /* Free blocks count */
98 uint16_t bg_free_inodes_count; /* Free inodes count */
99 uint16_t bg_used_dirs_count; /* Directories count */
100 uint16_t bg_pad;
101 uint32_t bg_reserved[3];
102};
103
104/*
105 * Data structures used by the directory indexing feature
106 *
107 * Note: all of the multibyte integer fields are little endian.
108 */
109
110/*
111 * Note: dx_root_info is laid out so that if it should somehow get
112 * overlaid by a dirent the two low bits of the hash version will be
113 * zero. Therefore, the hash version mod 4 should never be 0.
114 * Sincerely, the paranoia department.
115 */
116struct ext2_dx_root_info {
117 uint32_t reserved_zero;
118 uint8_t hash_version; /* 0 now, 1 at release */
119 uint8_t info_length; /* 8 */
120 uint8_t indirect_levels;
121 uint8_t unused_flags;
122};
123
124#define EXT2_HASH_LEGACY 0
125#define EXT2_HASH_HALF_MD4 1
126#define EXT2_HASH_TEA 2
127
128#define EXT2_HASH_FLAG_INCOMPAT 0x1
129
130struct ext2_dx_entry {
131 uint32_t hash;
132 uint32_t block;
133};
134
135struct ext2_dx_countlimit {
136 uint16_t limit;
137 uint16_t count;
138};
139
140
141/*
142 * Macro-instructions used to manage group descriptors
143 */
144#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
145#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
146#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
147/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
148#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
149#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
150#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
151
152/*
153 * Constants relative to the data blocks
154 */
155#define EXT2_NDIR_BLOCKS 12
156#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
157#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
158#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
159#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
160
161/*
162 * Inode flags
163 */
164#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
165#define EXT2_UNRM_FL 0x00000002 /* Undelete */
166#define EXT2_COMPR_FL 0x00000004 /* Compress file */
167#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
168#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
169#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
170#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
171#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
172/* Reserved for compression usage... */
173#define EXT2_DIRTY_FL 0x00000100
174#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
175#define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */
176#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
177/* End compression flags --- maybe not all used */
178#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
179#define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */
180#define EXT2_IMAGIC_FL 0x00002000
181#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
182#define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */
183#define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */
184#define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
185#define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
186#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
187
188#define EXT2_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
189#define EXT2_FL_USER_MODIFIABLE 0x000080FF /* User modifiable flags */
190
191/*
192 * ioctl commands
193 */
194#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
195#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
196#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
197#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
198
199/*
200 * Structure of an inode on the disk
201 */
202struct ext2_inode {
203 uint16_t i_mode; /* File mode */
204 uint16_t i_uid; /* Low 16 bits of Owner Uid */
205 uint32_t i_size; /* Size in bytes */
206 uint32_t i_atime; /* Access time */
207 uint32_t i_ctime; /* Creation time */
208 uint32_t i_mtime; /* Modification time */
209 uint32_t i_dtime; /* Deletion Time */
210 uint16_t i_gid; /* Low 16 bits of Group Id */
211 uint16_t i_links_count; /* Links count */
212 uint32_t i_blocks; /* Blocks count */
213 uint32_t i_flags; /* File flags */
214 union {
215 struct {
216 uint32_t l_i_reserved1;
217 } linux1;
218 struct {
219 uint32_t h_i_translator;
220 } hurd1;
221 struct {
222 uint32_t m_i_reserved1;
223 } masix1;
224 } osd1; /* OS dependent 1 */
225 uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
226 uint32_t i_generation; /* File version (for NFS) */
227 uint32_t i_file_acl; /* File ACL */
228 uint32_t i_dir_acl; /* Directory ACL */
229 uint32_t i_faddr; /* Fragment address */
230 union {
231 struct {
232 uint8_t l_i_frag; /* Fragment number */
233 uint8_t l_i_fsize; /* Fragment size */
234 uint16_t i_pad1;
235 uint16_t l_i_uid_high; /* these 2 fields */
236 uint16_t l_i_gid_high; /* were reserved2[0] */
237 uint32_t l_i_reserved2;
238 } linux2;
239 struct {
240 uint8_t h_i_frag; /* Fragment number */
241 uint8_t h_i_fsize; /* Fragment size */
242 uint16_t h_i_mode_high;
243 uint16_t h_i_uid_high;
244 uint16_t h_i_gid_high;
245 uint32_t h_i_author;
246 } hurd2;
247 struct {
248 uint8_t m_i_frag; /* Fragment number */
249 uint8_t m_i_fsize; /* Fragment size */
250 uint16_t m_pad1;
251 uint32_t m_i_reserved2[2];
252 } masix2;
253 } osd2; /* OS dependent 2 */
254};
255
256/*
257 * Permanent part of an large inode on the disk
258 */
259struct ext2_inode_large {
260 uint16_t i_mode; /* File mode */
261 uint16_t i_uid; /* Low 16 bits of Owner Uid */
262 uint32_t i_size; /* Size in bytes */
263 uint32_t i_atime; /* Access time */
264 uint32_t i_ctime; /* Creation time */
265 uint32_t i_mtime; /* Modification time */
266 uint32_t i_dtime; /* Deletion Time */
267 uint16_t i_gid; /* Low 16 bits of Group Id */
268 uint16_t i_links_count; /* Links count */
269 uint32_t i_blocks; /* Blocks count */
270 uint32_t i_flags; /* File flags */
271 union {
272 struct {
273 uint32_t l_i_reserved1;
274 } linux1;
275 struct {
276 uint32_t h_i_translator;
277 } hurd1;
278 struct {
279 uint32_t m_i_reserved1;
280 } masix1;
281 } osd1; /* OS dependent 1 */
282 uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
283 uint32_t i_generation; /* File version (for NFS) */
284 uint32_t i_file_acl; /* File ACL */
285 uint32_t i_dir_acl; /* Directory ACL */
286 uint32_t i_faddr; /* Fragment address */
287 union {
288 struct {
289 uint8_t l_i_frag; /* Fragment number */
290 uint8_t l_i_fsize; /* Fragment size */
291 uint16_t i_pad1;
292 uint16_t l_i_uid_high; /* these 2 fields */
293 uint16_t l_i_gid_high; /* were reserved2[0] */
294 uint32_t l_i_reserved2;
295 } linux2;
296 struct {
297 uint8_t h_i_frag; /* Fragment number */
298 uint8_t h_i_fsize; /* Fragment size */
299 uint16_t h_i_mode_high;
300 uint16_t h_i_uid_high;
301 uint16_t h_i_gid_high;
302 uint32_t h_i_author;
303 } hurd2;
304 struct {
305 uint8_t m_i_frag; /* Fragment number */
306 uint8_t m_i_fsize; /* Fragment size */
307 uint16_t m_pad1;
308 uint32_t m_i_reserved2[2];
309 } masix2;
310 } osd2; /* OS dependent 2 */
311 uint16_t i_extra_isize;
312 uint16_t i_pad1;
313};
314
315#define i_size_high i_dir_acl
316
317/*
318 * File system states
319 */
320#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
321#define EXT2_ERROR_FS 0x0002 /* Errors detected */
322
323/*
324 * Mount flags
325 */
326#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */
327#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
328#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
329#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
330#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
331#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
332#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
333#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
334
335#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
336#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
337#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
338 EXT2_MOUNT_##opt)
339/*
340 * Maximal mount counts between two filesystem checks
341 */
342#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
343#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
344
345/*
346 * Behaviour when detecting errors
347 */
348#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
349#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
350#define EXT2_ERRORS_PANIC 3 /* Panic */
351#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
352
353/*
354 * Structure of the super block
355 */
356struct ext2_super_block {
357 uint32_t s_inodes_count; /* Inodes count */
358 uint32_t s_blocks_count; /* Blocks count */
359 uint32_t s_r_blocks_count; /* Reserved blocks count */
360 uint32_t s_free_blocks_count; /* Free blocks count */
361 uint32_t s_free_inodes_count; /* Free inodes count */
362 uint32_t s_first_data_block; /* First Data Block */
363 uint32_t s_log_block_size; /* Block size */
364 int32_t s_log_frag_size; /* Fragment size */
365 uint32_t s_blocks_per_group; /* # Blocks per group */
366 uint32_t s_frags_per_group; /* # Fragments per group */
367 uint32_t s_inodes_per_group; /* # Inodes per group */
368 uint32_t s_mtime; /* Mount time */
369 uint32_t s_wtime; /* Write time */
370 uint16_t s_mnt_count; /* Mount count */
371 int16_t s_max_mnt_count; /* Maximal mount count */
372 uint16_t s_magic; /* Magic signature */
373 uint16_t s_state; /* File system state */
374 uint16_t s_errors; /* Behaviour when detecting errors */
375 uint16_t s_minor_rev_level; /* minor revision level */
376 uint32_t s_lastcheck; /* time of last check */
377 uint32_t s_checkinterval; /* max. time between checks */
378 uint32_t s_creator_os; /* OS */
379 uint32_t s_rev_level; /* Revision level */
380 uint16_t s_def_resuid; /* Default uid for reserved blocks */
381 uint16_t s_def_resgid; /* Default gid for reserved blocks */
382 /*
383 * These fields are for EXT2_DYNAMIC_REV superblocks only.
384 *
385 * Note: the difference between the compatible feature set and
386 * the incompatible feature set is that if there is a bit set
387 * in the incompatible feature set that the kernel doesn't
388 * know about, it should refuse to mount the filesystem.
389 *
390 * e2fsck's requirements are more strict; if it doesn't know
391 * about a feature in either the compatible or incompatible
392 * feature set, it must abort and not try to meddle with
393 * things it doesn't understand...
394 */
395 uint32_t s_first_ino; /* First non-reserved inode */
396 uint16_t s_inode_size; /* size of inode structure */
397 uint16_t s_block_group_nr; /* block group # of this superblock */
398 uint32_t s_feature_compat; /* compatible feature set */
399 uint32_t s_feature_incompat; /* incompatible feature set */
400 uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
401 uint8_t s_uuid[16]; /* 128-bit uuid for volume */
402 char s_volume_name[16]; /* volume name */
403 char s_last_mounted[64]; /* directory where last mounted */
404 uint32_t s_algorithm_usage_bitmap; /* For compression */
405 /*
406 * Performance hints. Directory preallocation should only
407 * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
408 */
409 uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
410 uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
411 uint16_t s_reserved_gdt_blocks; /* Per group table for online growth */
412 /*
413 * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
414 */
415 uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
416 uint32_t s_journal_inum; /* inode number of journal file */
417 uint32_t s_journal_dev; /* device number of journal file */
418 uint32_t s_last_orphan; /* start of list of inodes to delete */
419 uint32_t s_hash_seed[4]; /* HTREE hash seed */
420 uint8_t s_def_hash_version; /* Default hash version to use */
421 uint8_t s_jnl_backup_type; /* Default type of journal backup */
422 uint16_t s_reserved_word_pad;
423 uint32_t s_default_mount_opts;
424 uint32_t s_first_meta_bg; /* First metablock group */
425 uint32_t s_mkfs_time; /* When the filesystem was created */
426 uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */
427 uint32_t s_reserved[172]; /* Padding to the end of the block */
428};
429
430/*
431 * Codes for operating systems
432 */
433#define EXT2_OS_LINUX 0
434#define EXT2_OS_HURD 1
435#define EXT2_OS_MASIX 2
436#define EXT2_OS_FREEBSD 3
437#define EXT2_OS_LITES 4
438
439/*
440 * Revision levels
441 */
442#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
443#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
444
445#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
446#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
447
448#define EXT2_GOOD_OLD_INODE_SIZE 128
449
450/*
451 * Journal inode backup types
452 */
453#define EXT3_JNL_BACKUP_BLOCKS 1
454
455/*
456 * Feature set definitions
457 */
458
459#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
460 ( EXT2_SB(sb)->s_feature_compat & (mask) )
461#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
462 ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
463#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
464 ( EXT2_SB(sb)->s_feature_incompat & (mask) )
465
466#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
467#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
468#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
469#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
470#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
471#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
472
473#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
474#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
475/* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */
476
477#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
478#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
479#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
480#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
481#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
482#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
483
484
485#define EXT2_FEATURE_COMPAT_SUPP 0
486#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)
487#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
488 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
489 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
490
491/*
492 * Default values for user and/or group using reserved blocks
493 */
494#define EXT2_DEF_RESUID 0
495#define EXT2_DEF_RESGID 0
496
497/*
498 * Default mount options
499 */
500#define EXT2_DEFM_DEBUG 0x0001
501#define EXT2_DEFM_BSDGROUPS 0x0002
502#define EXT2_DEFM_XATTR_USER 0x0004
503#define EXT2_DEFM_ACL 0x0008
504#define EXT2_DEFM_UID16 0x0010
505#define EXT3_DEFM_JMODE 0x0060
506#define EXT3_DEFM_JMODE_DATA 0x0020
507#define EXT3_DEFM_JMODE_ORDERED 0x0040
508#define EXT3_DEFM_JMODE_WBACK 0x0060
509
510/*
511 * Structure of a directory entry
512 */
513#define EXT2_NAME_LEN 255
514
515struct ext2_dir_entry {
516 uint32_t inode; /* Inode number */
517 uint16_t rec_len; /* Directory entry length */
518 uint16_t name_len; /* Name length */
519 char name[EXT2_NAME_LEN]; /* File name */
520};
521
522/*
523 * The new version of the directory entry. Since EXT2 structures are
524 * stored in intel byte order, and the name_len field could never be
525 * bigger than 255 chars, it's safe to reclaim the extra byte for the
526 * file_type field.
527 */
528struct ext2_dir_entry_2 {
529 uint32_t inode; /* Inode number */
530 uint16_t rec_len; /* Directory entry length */
531 uint8_t name_len; /* Name length */
532 uint8_t file_type;
533 char name[EXT2_NAME_LEN]; /* File name */
534};
535
536/*
537 * Ext2 directory file types. Only the low 3 bits are used. The
538 * other bits are reserved for now.
539 */
540#define EXT2_FT_UNKNOWN 0
541#define EXT2_FT_REG_FILE 1
542#define EXT2_FT_DIR 2
543#define EXT2_FT_CHRDEV 3
544#define EXT2_FT_BLKDEV 4
545#define EXT2_FT_FIFO 5
546#define EXT2_FT_SOCK 6
547#define EXT2_FT_SYMLINK 7
548
549#define EXT2_FT_MAX 8
550
551/*
552 * EXT2_DIR_PAD defines the directory entries boundaries
553 *
554 * NOTE: It must be a multiple of 4
555 */
556#define EXT2_DIR_PAD 4
557#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
558#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
559 ~EXT2_DIR_ROUND)
560
561#endif
diff --git a/include/bb_linux_ext2_fs.h b/include/bb_linux_ext2_fs.h
deleted file mode 100644
index fdc470bc2..000000000
--- a/include/bb_linux_ext2_fs.h
+++ /dev/null
@@ -1,547 +0,0 @@
1/*
2 * Work around linux/ext2_fs.h breakage.
3 * linux/ext2_fs.h might be removed from future kernel header distribution.
4 * See https://bugzilla.kernel.org/show_bug.cgi?id=42986
5 *
6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */
8#ifndef BB_LINUX_EXT2_FS_H
9#define BB_LINUX_EXT2_FS_H
10
11/*
12 * From linux/magic.h
13 */
14
15#define EXT2_SUPER_MAGIC 0xEF53
16#define EXT3_SUPER_MAGIC 0xEF53
17#define EXT4_SUPER_MAGIC 0xEF53
18
19/*
20 * From linux/ext2_fs.h, with minor changes.
21 */
22
23/*
24 * Copyright (C) 1992, 1993, 1994, 1995
25 * Remy Card (card@masi.ibp.fr)
26 * Laboratoire MASI - Institut Blaise Pascal
27 * Universite Pierre et Marie Curie (Paris VI)
28 *
29 * from
30 *
31 * linux/include/linux/minix_fs.h
32 *
33 * Copyright (C) 1991, 1992 Linus Torvalds
34 */
35
36/*
37 * The second extended filesystem constants/structures
38 */
39
40/*
41 * Define EXT2_RESERVATION to reserve data blocks for expanding files
42 */
43#define EXT2_DEFAULT_RESERVE_BLOCKS 8
44/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
45#define EXT2_MAX_RESERVE_BLOCKS 1027
46#define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
47
48/*
49 * Special inode numbers
50 */
51#define EXT2_BAD_INO 1 /* Bad blocks inode */
52#define EXT2_ROOT_INO 2 /* Root inode */
53#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
54#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
55
56/* First non-reserved inode for old ext2 filesystems */
57#define EXT2_GOOD_OLD_FIRST_INO 11
58
59/* Assume that user mode programs are passing in an ext2fs superblock, not
60 * a kernel struct super_block. This will allow us to call the feature-test
61 * macros from user land. */
62#define EXT2_SB(sb) (sb)
63
64/*
65 * Maximal count of links to a file
66 */
67#define EXT2_LINK_MAX 32000
68
69/*
70 * Macro-instructions used to manage several block sizes
71 */
72#define EXT2_MIN_BLOCK_SIZE 1024
73#define EXT2_MAX_BLOCK_SIZE 4096
74#define EXT2_MIN_BLOCK_LOG_SIZE 10
75# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
76#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (uint32_t))
77# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
78#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
79 EXT2_GOOD_OLD_INODE_SIZE : \
80 (s)->s_inode_size)
81#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
82 EXT2_GOOD_OLD_FIRST_INO : \
83 (s)->s_first_ino)
84
85/*
86 * Macro-instructions used to manage fragments
87 */
88#define EXT2_MIN_FRAG_SIZE 1024
89#define EXT2_MAX_FRAG_SIZE 4096
90#define EXT2_MIN_FRAG_LOG_SIZE 10
91# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
92# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
93
94/*
95 * Structure of a blocks group descriptor
96 */
97struct ext2_group_desc
98{
99 uint32_t bg_block_bitmap; /* Blocks bitmap block */
100 uint32_t bg_inode_bitmap; /* Inodes bitmap block */
101 uint32_t bg_inode_table; /* Inodes table block */
102 uint16_t bg_free_blocks_count; /* Free blocks count */
103 uint16_t bg_free_inodes_count; /* Free inodes count */
104 uint16_t bg_used_dirs_count; /* Directories count */
105 uint16_t bg_pad;
106 uint32_t bg_reserved[3];
107};
108
109/*
110 * Macro-instructions used to manage group descriptors
111 */
112# define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
113# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
114# define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
115
116/*
117 * Constants relative to the data blocks
118 */
119#define EXT2_NDIR_BLOCKS 12
120#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
121#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
122#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
123#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
124
125/*
126 * Inode flags (GETFLAGS/SETFLAGS)
127 */
128#define EXT2_SECRM_FL FS_SECRM_FL /* Secure deletion */
129#define EXT2_UNRM_FL FS_UNRM_FL /* Undelete */
130#define EXT2_COMPR_FL FS_COMPR_FL /* Compress file */
131#define EXT2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
132#define EXT2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
133#define EXT2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
134#define EXT2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
135#define EXT2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
136/* Reserved for compression usage... */
137#define EXT2_DIRTY_FL FS_DIRTY_FL
138#define EXT2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
139#define EXT2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
140#define EXT2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
141/* End compression flags --- maybe not all used */
142#define EXT2_BTREE_FL FS_BTREE_FL /* btree format dir */
143#define EXT2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
144#define EXT2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
145#define EXT2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
146#define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
147#define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
148#define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
149#define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
150
151#define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
152#define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
153
154/* Flags that should be inherited by new inodes from their parent. */
155#define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
156 EXT2_SYNC_FL | EXT2_IMMUTABLE_FL | EXT2_APPEND_FL |\
157 EXT2_NODUMP_FL | EXT2_NOATIME_FL | EXT2_COMPRBLK_FL|\
158 EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
159 EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
160
161/* Flags that are appropriate for regular files (all but dir-specific ones). */
162#define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
163
164/* Flags that are appropriate for non-directories/regular files. */
165#define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
166
167/* Mask out flags that are inappropriate for the given type of inode. */
168static inline uint32_t ext2_mask_flags(mode_t mode, uint32_t flags)
169{
170 if (S_ISDIR(mode))
171 return flags;
172 else if (S_ISREG(mode))
173 return flags & EXT2_REG_FLMASK;
174 else
175 return flags & EXT2_OTHER_FLMASK;
176}
177
178/*
179 * ioctl commands
180 */
181#define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS
182#define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS
183#define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
184#define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
185#define EXT2_IOC_GETRSVSZ _IOR('f', 5, long)
186#define EXT2_IOC_SETRSVSZ _IOW('f', 6, long)
187
188/*
189 * ioctl commands in 32 bit emulation
190 */
191#define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
192#define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
193#define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION
194#define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION
195
196/*
197 * Structure of an inode on the disk
198 */
199struct ext2_inode {
200 uint16_t i_mode; /* File mode */
201 uint16_t i_uid; /* Low 16 bits of Owner Uid */
202 uint32_t i_size; /* Size in bytes */
203 uint32_t i_atime; /* Access time */
204 uint32_t i_ctime; /* Creation time */
205 uint32_t i_mtime; /* Modification time */
206 uint32_t i_dtime; /* Deletion Time */
207 uint16_t i_gid; /* Low 16 bits of Group Id */
208 uint16_t i_links_count; /* Links count */
209 uint32_t i_blocks; /* Blocks count */
210 uint32_t i_flags; /* File flags */
211 union {
212 struct {
213 uint32_t l_i_reserved1;
214 } linux1;
215 struct {
216 uint32_t h_i_translator;
217 } hurd1;
218 struct {
219 uint32_t m_i_reserved1;
220 } masix1;
221 } osd1; /* OS dependent 1 */
222 uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
223 uint32_t i_generation; /* File version (for NFS) */
224 uint32_t i_file_acl; /* File ACL */
225 uint32_t i_dir_acl; /* Directory ACL */
226 uint32_t i_faddr; /* Fragment address */
227 union {
228 struct {
229 uint8_t l_i_frag; /* Fragment number */
230 uint8_t l_i_fsize; /* Fragment size */
231 uint16_t i_pad1;
232 uint16_t l_i_uid_high; /* these 2 fields */
233 uint16_t l_i_gid_high; /* were reserved2[0] */
234 uint32_t l_i_reserved2;
235 } linux2;
236 struct {
237 uint8_t h_i_frag; /* Fragment number */
238 uint8_t h_i_fsize; /* Fragment size */
239 uint16_t h_i_mode_high;
240 uint16_t h_i_uid_high;
241 uint16_t h_i_gid_high;
242 uint32_t h_i_author;
243 } hurd2;
244 struct {
245 uint8_t m_i_frag; /* Fragment number */
246 uint8_t m_i_fsize; /* Fragment size */
247 uint16_t m_pad1;
248 uint32_t m_i_reserved2[2];
249 } masix2;
250 } osd2; /* OS dependent 2 */
251};
252
253#define i_size_high i_dir_acl
254
255#if defined(__KERNEL__) || defined(__linux__)
256#define i_reserved1 osd1.linux1.l_i_reserved1
257#define i_frag osd2.linux2.l_i_frag
258#define i_fsize osd2.linux2.l_i_fsize
259#define i_uid_low i_uid
260#define i_gid_low i_gid
261#define i_uid_high osd2.linux2.l_i_uid_high
262#define i_gid_high osd2.linux2.l_i_gid_high
263#define i_reserved2 osd2.linux2.l_i_reserved2
264#endif
265
266#ifdef __hurd__
267#define i_translator osd1.hurd1.h_i_translator
268#define i_frag osd2.hurd2.h_i_frag
269#define i_fsize osd2.hurd2.h_i_fsize
270#define i_uid_high osd2.hurd2.h_i_uid_high
271#define i_gid_high osd2.hurd2.h_i_gid_high
272#define i_author osd2.hurd2.h_i_author
273#endif
274
275#ifdef __masix__
276#define i_reserved1 osd1.masix1.m_i_reserved1
277#define i_frag osd2.masix2.m_i_frag
278#define i_fsize osd2.masix2.m_i_fsize
279#define i_reserved2 osd2.masix2.m_i_reserved2
280#endif
281
282/*
283 * File system states
284 */
285#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
286#define EXT2_ERROR_FS 0x0002 /* Errors detected */
287
288/*
289 * Mount flags
290 */
291#define EXT2_MOUNT_CHECK 0x000001 /* Do mount-time checks */
292#define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
293#define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
294#define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
295#define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
296#define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
297#define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
298#define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
299#define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
300#define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
301#define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
302#define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
303#define EXT2_MOUNT_XIP 0x010000 /* Execute in place */
304#define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
305#define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
306#define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
307
308
309#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
310#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
311#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
312 EXT2_MOUNT_##opt)
313/*
314 * Maximal mount counts between two filesystem checks
315 */
316#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
317#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
318
319/*
320 * Behaviour when detecting errors
321 */
322#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
323#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
324#define EXT2_ERRORS_PANIC 3 /* Panic */
325#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
326
327/*
328 * Structure of the super block
329 */
330struct ext2_super_block {
331 uint32_t s_inodes_count; /* Inodes count */
332 uint32_t s_blocks_count; /* Blocks count */
333 uint32_t s_r_blocks_count; /* Reserved blocks count */
334 uint32_t s_free_blocks_count; /* Free blocks count */
335 uint32_t s_free_inodes_count; /* Free inodes count */
336 uint32_t s_first_data_block; /* First Data Block */
337 uint32_t s_log_block_size; /* Block size */
338 uint32_t s_log_frag_size; /* Fragment size */
339 uint32_t s_blocks_per_group; /* # Blocks per group */
340 uint32_t s_frags_per_group; /* # Fragments per group */
341 uint32_t s_inodes_per_group; /* # Inodes per group */
342 uint32_t s_mtime; /* Mount time */
343 uint32_t s_wtime; /* Write time */
344 uint16_t s_mnt_count; /* Mount count */
345 uint16_t s_max_mnt_count; /* Maximal mount count */
346 uint16_t s_magic; /* Magic signature */
347 uint16_t s_state; /* File system state */
348 uint16_t s_errors; /* Behaviour when detecting errors */
349 uint16_t s_minor_rev_level; /* minor revision level */
350 uint32_t s_lastcheck; /* time of last check */
351 uint32_t s_checkinterval; /* max. time between checks */
352 uint32_t s_creator_os; /* OS */
353 uint32_t s_rev_level; /* Revision level */
354 uint16_t s_def_resuid; /* Default uid for reserved blocks */
355 uint16_t s_def_resgid; /* Default gid for reserved blocks */
356 /*
357 * These fields are for EXT2_DYNAMIC_REV superblocks only.
358 *
359 * Note: the difference between the compatible feature set and
360 * the incompatible feature set is that if there is a bit set
361 * in the incompatible feature set that the kernel doesn't
362 * know about, it should refuse to mount the filesystem.
363 *
364 * e2fsck's requirements are more strict; if it doesn't know
365 * about a feature in either the compatible or incompatible
366 * feature set, it must abort and not try to meddle with
367 * things it doesn't understand...
368 */
369 uint32_t s_first_ino; /* First non-reserved inode */
370 uint16_t s_inode_size; /* size of inode structure */
371 uint16_t s_block_group_nr; /* block group # of this superblock */
372 uint32_t s_feature_compat; /* compatible feature set */
373 uint32_t s_feature_incompat; /* incompatible feature set */
374 uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
375 uint8_t s_uuid[16]; /* 128-bit uuid for volume */
376 char s_volume_name[16]; /* volume name */
377 char s_last_mounted[64]; /* directory where last mounted */
378 uint32_t s_algorithm_usage_bitmap; /* For compression */
379 /*
380 * Performance hints. Directory preallocation should only
381 * happen if the EXT2_COMPAT_PREALLOC flag is on.
382 */
383 uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
384 uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
385 uint16_t s_padding1;
386 /*
387 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
388 */
389 uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
390 uint32_t s_journal_inum; /* inode number of journal file */
391 uint32_t s_journal_dev; /* device number of journal file */
392 uint32_t s_last_orphan; /* start of list of inodes to delete */
393 uint32_t s_hash_seed[4]; /* HTREE hash seed */
394 uint8_t s_def_hash_version; /* Default hash version to use */
395 uint8_t s_reserved_char_pad;
396 uint16_t s_reserved_word_pad;
397 uint32_t s_default_mount_opts;
398 uint32_t s_first_meta_bg; /* First metablock block group */
399 uint32_t s_reserved[190]; /* Padding to the end of the block */
400};
401
402/*
403 * Codes for operating systems
404 */
405#define EXT2_OS_LINUX 0
406#define EXT2_OS_HURD 1
407#define EXT2_OS_MASIX 2
408#define EXT2_OS_FREEBSD 3
409#define EXT2_OS_LITES 4
410
411/*
412 * Revision levels
413 */
414#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
415#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
416
417#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
418#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
419
420#define EXT2_GOOD_OLD_INODE_SIZE 128
421
422/*
423 * Feature set definitions
424 */
425
426#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
427 ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
428#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
429 ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
430#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
431 ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
432#define EXT2_SET_COMPAT_FEATURE(sb,mask) \
433 EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
434#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
435 EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
436#define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
437 EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
438#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
439 EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
440#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
441 EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
442#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
443 EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
444
445#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
446#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
447#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
448#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
449#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
450#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
451#define EXT2_FEATURE_COMPAT_ANY 0xffffffff
452
453#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
454#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
455#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
456#define EXT2_FEATURE_RO_COMPAT_ANY 0xffffffff
457
458#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
459#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
460#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
461#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
462#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
463#define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
464
465#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
466#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
467 EXT2_FEATURE_INCOMPAT_META_BG)
468#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
469 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
470 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
471#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
472#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
473
474/*
475 * Default values for user and/or group using reserved blocks
476 */
477#define EXT2_DEF_RESUID 0
478#define EXT2_DEF_RESGID 0
479
480/*
481 * Default mount options
482 */
483#define EXT2_DEFM_DEBUG 0x0001
484#define EXT2_DEFM_BSDGROUPS 0x0002
485#define EXT2_DEFM_XATTR_USER 0x0004
486#define EXT2_DEFM_ACL 0x0008
487#define EXT2_DEFM_UID16 0x0010
488 /* Not used by ext2, but reserved for use by ext3 */
489#define EXT3_DEFM_JMODE 0x0060
490#define EXT3_DEFM_JMODE_DATA 0x0020
491#define EXT3_DEFM_JMODE_ORDERED 0x0040
492#define EXT3_DEFM_JMODE_WBACK 0x0060
493
494/*
495 * Structure of a directory entry
496 */
497#define EXT2_NAME_LEN 255
498
499struct ext2_dir_entry {
500 uint32_t inode; /* Inode number */
501 uint16_t rec_len; /* Directory entry length */
502 uint16_t name_len; /* Name length */
503 char name[EXT2_NAME_LEN]; /* File name */
504};
505
506/*
507 * The new version of the directory entry. Since EXT2 structures are
508 * stored in intel byte order, and the name_len field could never be
509 * bigger than 255 chars, it's safe to reclaim the extra byte for the
510 * file_type field.
511 */
512struct ext2_dir_entry_2 {
513 uint32_t inode; /* Inode number */
514 uint16_t rec_len; /* Directory entry length */
515 uint8_t name_len; /* Name length */
516 uint8_t file_type;
517 char name[EXT2_NAME_LEN]; /* File name */
518};
519
520/*
521 * Ext2 directory file types. Only the low 3 bits are used. The
522 * other bits are reserved for now.
523 */
524enum {
525 EXT2_FT_UNKNOWN = 0,
526 EXT2_FT_REG_FILE = 1,
527 EXT2_FT_DIR = 2,
528 EXT2_FT_CHRDEV = 3,
529 EXT2_FT_BLKDEV = 4,
530 EXT2_FT_FIFO = 5,
531 EXT2_FT_SOCK = 6,
532 EXT2_FT_SYMLINK = 7,
533 EXT2_FT_MAX
534};
535
536/*
537 * EXT2_DIR_PAD defines the directory entries boundaries
538 *
539 * NOTE: It must be a multiple of 4
540 */
541#define EXT2_DIR_PAD 4
542#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
543#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
544 ~EXT2_DIR_ROUND)
545#define EXT2_MAX_REC_LEN ((1<<16)-1)
546
547#endif