1 From 0b2b0f31a38d77ebfb2a6416011562687ef58191 Mon Sep 17 00:00:00 2001
2 From: Denys Vlasenko <vda.linux@googlemail.com>
3 Date: Fri, 13 Apr 2012 16:39:18 +0200
4 Subject: [PATCH 01/32] Create and use our own copy of linux/ext2_fs.h
6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
8 e2fsprogs/tune2fs.c | 8 +-
9 include/bb_linux_ext2_fs.h | 547 ++++++++++++++++++++++++++++++++++++++++++++
10 util-linux/mkfs_ext2.c | 8 +-
11 3 files changed, 549 insertions(+), 14 deletions(-)
12 create mode 100644 include/bb_linux_ext2_fs.h
14 diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c
15 index 8da7432..841d58a 100644
16 --- a/e2fsprogs/tune2fs.c
17 +++ b/e2fsprogs/tune2fs.c
23 - * Work around linux/ext2_fs.h breakage.
24 - * See https://bugzilla.kernel.org/show_bug.cgi?id=42986.
26 -typedef mode_t bb__umode_t;
27 -#define umode_t bb__umode_t
28 -#include <linux/ext2_fs.h>
29 +#include "bb_linux_ext2_fs.h"
32 char BUG_wrong_field_size(void);
33 diff --git a/include/bb_linux_ext2_fs.h b/include/bb_linux_ext2_fs.h
35 index 0000000..fdc470b
37 +++ b/include/bb_linux_ext2_fs.h
40 + * Work around linux/ext2_fs.h breakage.
41 + * linux/ext2_fs.h might be removed from future kernel header distribution.
42 + * See https://bugzilla.kernel.org/show_bug.cgi?id=42986
44 + * Licensed under GPLv2, see file LICENSE in this source tree.
46 +#ifndef BB_LINUX_EXT2_FS_H
47 +#define BB_LINUX_EXT2_FS_H
50 + * From linux/magic.h
53 +#define EXT2_SUPER_MAGIC 0xEF53
54 +#define EXT3_SUPER_MAGIC 0xEF53
55 +#define EXT4_SUPER_MAGIC 0xEF53
58 + * From linux/ext2_fs.h, with minor changes.
62 + * Copyright (C) 1992, 1993, 1994, 1995
63 + * Remy Card (card@masi.ibp.fr)
64 + * Laboratoire MASI - Institut Blaise Pascal
65 + * Universite Pierre et Marie Curie (Paris VI)
69 + * linux/include/linux/minix_fs.h
71 + * Copyright (C) 1991, 1992 Linus Torvalds
75 + * The second extended filesystem constants/structures
79 + * Define EXT2_RESERVATION to reserve data blocks for expanding files
81 +#define EXT2_DEFAULT_RESERVE_BLOCKS 8
82 +/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
83 +#define EXT2_MAX_RESERVE_BLOCKS 1027
84 +#define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
87 + * Special inode numbers
89 +#define EXT2_BAD_INO 1 /* Bad blocks inode */
90 +#define EXT2_ROOT_INO 2 /* Root inode */
91 +#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
92 +#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
94 +/* First non-reserved inode for old ext2 filesystems */
95 +#define EXT2_GOOD_OLD_FIRST_INO 11
97 +/* Assume that user mode programs are passing in an ext2fs superblock, not
98 + * a kernel struct super_block. This will allow us to call the feature-test
99 + * macros from user land. */
100 +#define EXT2_SB(sb) (sb)
103 + * Maximal count of links to a file
105 +#define EXT2_LINK_MAX 32000
108 + * Macro-instructions used to manage several block sizes
110 +#define EXT2_MIN_BLOCK_SIZE 1024
111 +#define EXT2_MAX_BLOCK_SIZE 4096
112 +#define EXT2_MIN_BLOCK_LOG_SIZE 10
113 +# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
114 +#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (uint32_t))
115 +# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
116 +#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
117 + EXT2_GOOD_OLD_INODE_SIZE : \
119 +#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
120 + EXT2_GOOD_OLD_FIRST_INO : \
124 + * Macro-instructions used to manage fragments
126 +#define EXT2_MIN_FRAG_SIZE 1024
127 +#define EXT2_MAX_FRAG_SIZE 4096
128 +#define EXT2_MIN_FRAG_LOG_SIZE 10
129 +# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
130 +# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
133 + * Structure of a blocks group descriptor
135 +struct ext2_group_desc
137 + uint32_t bg_block_bitmap; /* Blocks bitmap block */
138 + uint32_t bg_inode_bitmap; /* Inodes bitmap block */
139 + uint32_t bg_inode_table; /* Inodes table block */
140 + uint16_t bg_free_blocks_count; /* Free blocks count */
141 + uint16_t bg_free_inodes_count; /* Free inodes count */
142 + uint16_t bg_used_dirs_count; /* Directories count */
144 + uint32_t bg_reserved[3];
148 + * Macro-instructions used to manage group descriptors
150 +# define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
151 +# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
152 +# define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
155 + * Constants relative to the data blocks
157 +#define EXT2_NDIR_BLOCKS 12
158 +#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
159 +#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
160 +#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
161 +#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
164 + * Inode flags (GETFLAGS/SETFLAGS)
166 +#define EXT2_SECRM_FL FS_SECRM_FL /* Secure deletion */
167 +#define EXT2_UNRM_FL FS_UNRM_FL /* Undelete */
168 +#define EXT2_COMPR_FL FS_COMPR_FL /* Compress file */
169 +#define EXT2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
170 +#define EXT2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
171 +#define EXT2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
172 +#define EXT2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
173 +#define EXT2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
174 +/* Reserved for compression usage... */
175 +#define EXT2_DIRTY_FL FS_DIRTY_FL
176 +#define EXT2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
177 +#define EXT2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
178 +#define EXT2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
179 +/* End compression flags --- maybe not all used */
180 +#define EXT2_BTREE_FL FS_BTREE_FL /* btree format dir */
181 +#define EXT2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
182 +#define EXT2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
183 +#define EXT2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
184 +#define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
185 +#define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
186 +#define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
187 +#define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
189 +#define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
190 +#define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
192 +/* Flags that should be inherited by new inodes from their parent. */
193 +#define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
194 + EXT2_SYNC_FL | EXT2_IMMUTABLE_FL | EXT2_APPEND_FL |\
195 + EXT2_NODUMP_FL | EXT2_NOATIME_FL | EXT2_COMPRBLK_FL|\
196 + EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
197 + EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
199 +/* Flags that are appropriate for regular files (all but dir-specific ones). */
200 +#define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
202 +/* Flags that are appropriate for non-directories/regular files. */
203 +#define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
205 +/* Mask out flags that are inappropriate for the given type of inode. */
206 +static inline uint32_t ext2_mask_flags(mode_t mode, uint32_t flags)
210 + else if (S_ISREG(mode))
211 + return flags & EXT2_REG_FLMASK;
213 + return flags & EXT2_OTHER_FLMASK;
219 +#define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS
220 +#define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS
221 +#define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
222 +#define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
223 +#define EXT2_IOC_GETRSVSZ _IOR('f', 5, long)
224 +#define EXT2_IOC_SETRSVSZ _IOW('f', 6, long)
227 + * ioctl commands in 32 bit emulation
229 +#define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
230 +#define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
231 +#define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION
232 +#define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION
235 + * Structure of an inode on the disk
238 + uint16_t i_mode; /* File mode */
239 + uint16_t i_uid; /* Low 16 bits of Owner Uid */
240 + uint32_t i_size; /* Size in bytes */
241 + uint32_t i_atime; /* Access time */
242 + uint32_t i_ctime; /* Creation time */
243 + uint32_t i_mtime; /* Modification time */
244 + uint32_t i_dtime; /* Deletion Time */
245 + uint16_t i_gid; /* Low 16 bits of Group Id */
246 + uint16_t i_links_count; /* Links count */
247 + uint32_t i_blocks; /* Blocks count */
248 + uint32_t i_flags; /* File flags */
251 + uint32_t l_i_reserved1;
254 + uint32_t h_i_translator;
257 + uint32_t m_i_reserved1;
259 + } osd1; /* OS dependent 1 */
260 + uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
261 + uint32_t i_generation; /* File version (for NFS) */
262 + uint32_t i_file_acl; /* File ACL */
263 + uint32_t i_dir_acl; /* Directory ACL */
264 + uint32_t i_faddr; /* Fragment address */
267 + uint8_t l_i_frag; /* Fragment number */
268 + uint8_t l_i_fsize; /* Fragment size */
270 + uint16_t l_i_uid_high; /* these 2 fields */
271 + uint16_t l_i_gid_high; /* were reserved2[0] */
272 + uint32_t l_i_reserved2;
275 + uint8_t h_i_frag; /* Fragment number */
276 + uint8_t h_i_fsize; /* Fragment size */
277 + uint16_t h_i_mode_high;
278 + uint16_t h_i_uid_high;
279 + uint16_t h_i_gid_high;
280 + uint32_t h_i_author;
283 + uint8_t m_i_frag; /* Fragment number */
284 + uint8_t m_i_fsize; /* Fragment size */
286 + uint32_t m_i_reserved2[2];
288 + } osd2; /* OS dependent 2 */
291 +#define i_size_high i_dir_acl
293 +#if defined(__KERNEL__) || defined(__linux__)
294 +#define i_reserved1 osd1.linux1.l_i_reserved1
295 +#define i_frag osd2.linux2.l_i_frag
296 +#define i_fsize osd2.linux2.l_i_fsize
297 +#define i_uid_low i_uid
298 +#define i_gid_low i_gid
299 +#define i_uid_high osd2.linux2.l_i_uid_high
300 +#define i_gid_high osd2.linux2.l_i_gid_high
301 +#define i_reserved2 osd2.linux2.l_i_reserved2
305 +#define i_translator osd1.hurd1.h_i_translator
306 +#define i_frag osd2.hurd2.h_i_frag
307 +#define i_fsize osd2.hurd2.h_i_fsize
308 +#define i_uid_high osd2.hurd2.h_i_uid_high
309 +#define i_gid_high osd2.hurd2.h_i_gid_high
310 +#define i_author osd2.hurd2.h_i_author
314 +#define i_reserved1 osd1.masix1.m_i_reserved1
315 +#define i_frag osd2.masix2.m_i_frag
316 +#define i_fsize osd2.masix2.m_i_fsize
317 +#define i_reserved2 osd2.masix2.m_i_reserved2
321 + * File system states
323 +#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
324 +#define EXT2_ERROR_FS 0x0002 /* Errors detected */
329 +#define EXT2_MOUNT_CHECK 0x000001 /* Do mount-time checks */
330 +#define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
331 +#define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
332 +#define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
333 +#define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
334 +#define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
335 +#define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
336 +#define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
337 +#define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
338 +#define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
339 +#define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
340 +#define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
341 +#define EXT2_MOUNT_XIP 0x010000 /* Execute in place */
342 +#define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
343 +#define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
344 +#define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
347 +#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
348 +#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
349 +#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
352 + * Maximal mount counts between two filesystem checks
354 +#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
355 +#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
358 + * Behaviour when detecting errors
360 +#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
361 +#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
362 +#define EXT2_ERRORS_PANIC 3 /* Panic */
363 +#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
366 + * Structure of the super block
368 +struct ext2_super_block {
369 + uint32_t s_inodes_count; /* Inodes count */
370 + uint32_t s_blocks_count; /* Blocks count */
371 + uint32_t s_r_blocks_count; /* Reserved blocks count */
372 + uint32_t s_free_blocks_count; /* Free blocks count */
373 + uint32_t s_free_inodes_count; /* Free inodes count */
374 + uint32_t s_first_data_block; /* First Data Block */
375 + uint32_t s_log_block_size; /* Block size */
376 + uint32_t s_log_frag_size; /* Fragment size */
377 + uint32_t s_blocks_per_group; /* # Blocks per group */
378 + uint32_t s_frags_per_group; /* # Fragments per group */
379 + uint32_t s_inodes_per_group; /* # Inodes per group */
380 + uint32_t s_mtime; /* Mount time */
381 + uint32_t s_wtime; /* Write time */
382 + uint16_t s_mnt_count; /* Mount count */
383 + uint16_t s_max_mnt_count; /* Maximal mount count */
384 + uint16_t s_magic; /* Magic signature */
385 + uint16_t s_state; /* File system state */
386 + uint16_t s_errors; /* Behaviour when detecting errors */
387 + uint16_t s_minor_rev_level; /* minor revision level */
388 + uint32_t s_lastcheck; /* time of last check */
389 + uint32_t s_checkinterval; /* max. time between checks */
390 + uint32_t s_creator_os; /* OS */
391 + uint32_t s_rev_level; /* Revision level */
392 + uint16_t s_def_resuid; /* Default uid for reserved blocks */
393 + uint16_t s_def_resgid; /* Default gid for reserved blocks */
395 + * These fields are for EXT2_DYNAMIC_REV superblocks only.
397 + * Note: the difference between the compatible feature set and
398 + * the incompatible feature set is that if there is a bit set
399 + * in the incompatible feature set that the kernel doesn't
400 + * know about, it should refuse to mount the filesystem.
402 + * e2fsck's requirements are more strict; if it doesn't know
403 + * about a feature in either the compatible or incompatible
404 + * feature set, it must abort and not try to meddle with
405 + * things it doesn't understand...
407 + uint32_t s_first_ino; /* First non-reserved inode */
408 + uint16_t s_inode_size; /* size of inode structure */
409 + uint16_t s_block_group_nr; /* block group # of this superblock */
410 + uint32_t s_feature_compat; /* compatible feature set */
411 + uint32_t s_feature_incompat; /* incompatible feature set */
412 + uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
413 + uint8_t s_uuid[16]; /* 128-bit uuid for volume */
414 + char s_volume_name[16]; /* volume name */
415 + char s_last_mounted[64]; /* directory where last mounted */
416 + uint32_t s_algorithm_usage_bitmap; /* For compression */
418 + * Performance hints. Directory preallocation should only
419 + * happen if the EXT2_COMPAT_PREALLOC flag is on.
421 + uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
422 + uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
423 + uint16_t s_padding1;
425 + * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
427 + uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
428 + uint32_t s_journal_inum; /* inode number of journal file */
429 + uint32_t s_journal_dev; /* device number of journal file */
430 + uint32_t s_last_orphan; /* start of list of inodes to delete */
431 + uint32_t s_hash_seed[4]; /* HTREE hash seed */
432 + uint8_t s_def_hash_version; /* Default hash version to use */
433 + uint8_t s_reserved_char_pad;
434 + uint16_t s_reserved_word_pad;
435 + uint32_t s_default_mount_opts;
436 + uint32_t s_first_meta_bg; /* First metablock block group */
437 + uint32_t s_reserved[190]; /* Padding to the end of the block */
441 + * Codes for operating systems
443 +#define EXT2_OS_LINUX 0
444 +#define EXT2_OS_HURD 1
445 +#define EXT2_OS_MASIX 2
446 +#define EXT2_OS_FREEBSD 3
447 +#define EXT2_OS_LITES 4
452 +#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
453 +#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
455 +#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
456 +#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
458 +#define EXT2_GOOD_OLD_INODE_SIZE 128
461 + * Feature set definitions
464 +#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
465 + ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
466 +#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
467 + ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
468 +#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
469 + ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
470 +#define EXT2_SET_COMPAT_FEATURE(sb,mask) \
471 + EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
472 +#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
473 + EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
474 +#define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
475 + EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
476 +#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
477 + EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
478 +#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
479 + EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
480 +#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
481 + EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
483 +#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
484 +#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
485 +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
486 +#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
487 +#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
488 +#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
489 +#define EXT2_FEATURE_COMPAT_ANY 0xffffffff
491 +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
492 +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
493 +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
494 +#define EXT2_FEATURE_RO_COMPAT_ANY 0xffffffff
496 +#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
497 +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
498 +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
499 +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
500 +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
501 +#define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
503 +#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
504 +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
505 + EXT2_FEATURE_INCOMPAT_META_BG)
506 +#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
507 + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
508 + EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
509 +#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
510 +#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
513 + * Default values for user and/or group using reserved blocks
515 +#define EXT2_DEF_RESUID 0
516 +#define EXT2_DEF_RESGID 0
519 + * Default mount options
521 +#define EXT2_DEFM_DEBUG 0x0001
522 +#define EXT2_DEFM_BSDGROUPS 0x0002
523 +#define EXT2_DEFM_XATTR_USER 0x0004
524 +#define EXT2_DEFM_ACL 0x0008
525 +#define EXT2_DEFM_UID16 0x0010
526 + /* Not used by ext2, but reserved for use by ext3 */
527 +#define EXT3_DEFM_JMODE 0x0060
528 +#define EXT3_DEFM_JMODE_DATA 0x0020
529 +#define EXT3_DEFM_JMODE_ORDERED 0x0040
530 +#define EXT3_DEFM_JMODE_WBACK 0x0060
533 + * Structure of a directory entry
535 +#define EXT2_NAME_LEN 255
537 +struct ext2_dir_entry {
538 + uint32_t inode; /* Inode number */
539 + uint16_t rec_len; /* Directory entry length */
540 + uint16_t name_len; /* Name length */
541 + char name[EXT2_NAME_LEN]; /* File name */
545 + * The new version of the directory entry. Since EXT2 structures are
546 + * stored in intel byte order, and the name_len field could never be
547 + * bigger than 255 chars, it's safe to reclaim the extra byte for the
550 +struct ext2_dir_entry_2 {
551 + uint32_t inode; /* Inode number */
552 + uint16_t rec_len; /* Directory entry length */
553 + uint8_t name_len; /* Name length */
555 + char name[EXT2_NAME_LEN]; /* File name */
559 + * Ext2 directory file types. Only the low 3 bits are used. The
560 + * other bits are reserved for now.
563 + EXT2_FT_UNKNOWN = 0,
564 + EXT2_FT_REG_FILE = 1,
566 + EXT2_FT_CHRDEV = 3,
567 + EXT2_FT_BLKDEV = 4,
570 + EXT2_FT_SYMLINK = 7,
575 + * EXT2_DIR_PAD defines the directory entries boundaries
577 + * NOTE: It must be a multiple of 4
579 +#define EXT2_DIR_PAD 4
580 +#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
581 +#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
583 +#define EXT2_MAX_REC_LEN ((1<<16)-1)
586 diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c
587 index 759bb0a..2d9d720 100644
588 --- a/util-linux/mkfs_ext2.c
589 +++ b/util-linux/mkfs_ext2.c
593 #include <linux/fs.h>
595 - * Work around linux/ext2_fs.h breakage.
596 - * See https://bugzilla.kernel.org/show_bug.cgi?id=42986.
598 -typedef mode_t bb__umode_t;
599 -#define umode_t bb__umode_t
600 -#include <linux/ext2_fs.h>
601 +#include "bb_linux_ext2_fs.h"
603 #define ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT 0
604 #define ENABLE_FEATURE_MKFS_EXT2_DIR_INDEX 1