Merge branch 'vendor/LIBRESSL'
[dragonfly.git] / sys / gnu / vfs / ext2fs / ext2_fs.h
1 /*
2  *  modified for EXT2FS support in Lites 1.1
3  *
4  *  Aug 1995, Godmar Back (gback@cs.utah.edu)
5  *  University of Utah, Department of Computer Science
6  *
7  * $FreeBSD: src/sys/gnu/ext2fs/ext2_fs.h,v 1.8.2.2 2001/09/29 12:52:47 iedowse Exp $
8  */
9 /*
10  *  linux/include/linux/ext2_fs.h
11  *
12  * Copyright (C) 1992, 1993, 1994, 1995
13  * Remy Card (card@masi.ibp.fr)
14  * Laboratoire MASI - Institut Blaise Pascal
15  * Universite Pierre et Marie Curie (Paris VI)
16  *
17  *  from
18  *
19  *  linux/include/linux/minix_fs.h
20  *
21  *  Copyright (C) 1991, 1992  Linus Torvalds
22  */
23
24 #ifndef _LINUX_EXT2_FS_H
25 #define _LINUX_EXT2_FS_H
26
27 #include <sys/types.h>
28 #include <sys/ioccom.h>
29
30 #define __u32 u_int32_t
31 #define u32   u_int32_t
32 #define __u16 u_int16_t
33 #define __u8  u_int8_t
34
35 #define __s32 int32_t
36 #define __s16 int16_t
37 #define __s8  int8_t
38
39 #define umode_t mode_t
40 #define loff_t  off_t
41
42 /* the Linux implementation of EXT2 stores some information about
43  * an inode in a ext2_inode_info structure which is part of the incore
44  * inode in Linux
45  * I decided to use the "spare" fields instead - we'll see how this
46  * works out
47  */
48
49 #define i_block_group           i_spare[0]
50 #define i_next_alloc_block      i_spare[1]
51 #define i_next_alloc_goal       i_spare[2]
52 #define i_prealloc_block        i_din.di_spare[0]
53 #define i_prealloc_count        i_din.di_spare[1]
54
55 /*
56  * The second extended filesystem constants/structures
57  */
58
59 /*
60  * Define EXT2FS_DEBUG to produce debug messages
61  */
62 #undef EXT2FS_DEBUG
63
64 /*
65  * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
66  */
67 #define EXT2_PREALLOCATE
68 #define EXT2_DEFAULT_PREALLOC_BLOCKS    8
69
70 /*
71  * The second extended file system version
72  */
73 #define EXT2FS_DATE             "95/08/09"
74 #define EXT2FS_VERSION          "0.5b"
75
76 /*
77  * Debug code
78  */
79 #ifdef EXT2FS_DEBUG
80 #define ext2_debug(f, a...)     { \
81                                         kprintf ("EXT2-fs DEBUG (%s, %d): %s:", \
82                                                 __FILE__, __LINE__, __func__); \
83                                         kprintf (f, ## a); \
84                                 }
85 #else
86 #define ext2_debug(f, a...)     /**/
87 #endif
88
89 /*
90  * Special inodes numbers
91  */
92 #define EXT2_BAD_INO             1      /* Bad blocks inode */
93 #define EXT2_ROOT_INO            2      /* Root inode, but rather use EXT2_ROOTINO */
94 #define EXT2_ACL_IDX_INO         3      /* ACL inode */
95 #define EXT2_ACL_DATA_INO        4      /* ACL inode */
96 #define EXT2_BOOT_LOADER_INO     5      /* Boot loader inode */
97 #define EXT2_UNDEL_DIR_INO       6      /* Undelete directory inode */
98
99 /* First non-reserved inode for old ext2 filesystems */
100 #define EXT2_GOOD_OLD_FIRST_INO 11
101
102 /*
103  * The second extended file system magic number
104  */
105 #define EXT2_SUPER_MAGIC        0xEF53
106
107 /*
108  * Maximal count of links to a file
109  */
110 #define EXT2_LINK_MAX           32000
111
112 /*
113  * Note: under FreeBSD, the "user" versions of the following macros are
114  * used (and must be used) in most cases, because ((s)->u.ext2_sb.s_es is
115  * not accessible.  This depends on __KERNEL__ not being defined for
116  * kernel builds under FreeBSD.
117  */
118 /*
119  * Arguments s of the following EXT2_XXX(s) macros in Linux kernel take
120  * generic (non-ext2 specific) inmemory superblock structure.  On DragonFly,
121  * the type of s is either generic inmemory, ext2 inmemory, or ext2 ondisk
122  * superblock structure.  These macro definitions are actually taken from
123  * e2fsprogs and made to work.
124  *
125  * Also note that on DragonFly, the macro EXT2_SB(s) takes ext2 ondisk
126  * superblock structure and does nothing (see the comment on EXT2_SB(s),
127  * it's for userspace to access ondisk superblock structure for testings,
128  * etc, originally introduced by e2fsprogs).
129  */
130
131 /*
132  * Macro-instructions used to manage several block sizes
133  */
134 #define EXT2_MIN_BLOCK_SIZE             1024
135 #define EXT2_MAX_BLOCK_SIZE             4096
136 #define EXT2_MIN_BLOCK_LOG_SIZE           10
137 #if (defined(__DragonFly__) && defined(_KERNEL))
138 #define EXT2_BLOCK_SIZE(s)              ((s)->s_blocksize)
139 #else
140 #define EXT2_BLOCK_SIZE(s)              (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
141 #endif
142 #define EXT2_ACLE_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
143 #define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
144 /*
145  * XXX DragonFly's inmemory superblock has no s_addr_per_block_bits.
146  */
147 /* #define EXT2_ADDR_PER_BLOCK_BITS(s)  ((s)->s_addr_per_block_bits) */
148 /*
149  * XXX The first one takes ext2 inmemory superblock structure and the
150  * second one takes ext2 ondisk superblock structure.  The second one
151  * has been used on DragonFly to compute ((s)->s_blocksize_bits).
152  */
153 /* #define EXT2_BLOCK_SIZE_BITS(s)      ((s)->s_blocksize_bits) */
154 #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)  /* log2(siz)-10 + log2(1024) */
155 #if defined _KERNEL
156 #define EXT2_INODE_SIZE(s)              ((s)->s_inode_size)
157 #define EXT2_FIRST_INO(s)               ((s)->s_first_ino)
158 #else
159 #define EXT2_INODE_SIZE(s)      (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
160                                  EXT2_GOOD_OLD_INODE_SIZE : \
161                                  (s)->s_inode_size)
162 #define EXT2_FIRST_INO(s)       (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
163                                  EXT2_GOOD_OLD_FIRST_INO : \
164                                  (s)->s_first_ino)
165 #endif
166 #define EXT2_INODES_PER_BLOCK(s)        ((s)->s_inodes_per_block)
167 /*
168  * Macro-instructions used to manage fragments
169  */
170 #define EXT2_MIN_FRAG_SIZE              1024
171 #define EXT2_MAX_FRAG_SIZE              4096
172 #define EXT2_MIN_FRAG_LOG_SIZE            10
173 #if defined(_KERNEL) && defined(__DragonFly__)
174 #define EXT2_FRAG_SIZE(s)               ((s)->s_frag_size)
175 /*
176  * XXX The second one has been used on DragonFly, but the first one
177  * with properly initialized s_frags_per_block is probably a better way.
178  * Also note that ext2 does not support block fragmentation.
179  */
180 /* #define EXT2_FRAGS_PER_BLOCK(s)         ((s)->s_frags_per_block) */
181 #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
182 #else
183 #define EXT2_FRAG_SIZE(s)               (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
184 #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
185 #endif
186
187 /*
188  * ACL structures
189  */
190 struct ext2_acl_header  /* Header of Access Control Lists */
191 {
192         __u32   aclh_size;
193         __u32   aclh_file_count;
194         __u32   aclh_acle_count;
195         __u32   aclh_first_acle;
196 };
197
198 struct ext2_acl_entry   /* Access Control List Entry */
199 {
200         __u32   acle_size;
201         __u16   acle_perms;     /* Access permissions */
202         __u16   acle_type;      /* Type of entry */
203         __u16   acle_tag;       /* User or group identity */
204         __u16   acle_pad1;
205         __u32   acle_next;      /* Pointer on next entry for the */
206                                         /* same inode or on next free entry */
207 };
208
209 /*
210  * Structure of a blocks group descriptor
211  */
212 struct ext2_group_desc
213 {
214         __u32   bg_block_bitmap;                /* Blocks bitmap block */
215         __u32   bg_inode_bitmap;                /* Inodes bitmap block */
216         __u32   bg_inode_table;         /* Inodes table block */
217         __u16   bg_free_blocks_count;   /* Free blocks count */
218         __u16   bg_free_inodes_count;   /* Free inodes count */
219         __u16   bg_used_dirs_count;     /* Directories count */
220         __u16   bg_pad;
221         __u32   bg_reserved[3];
222 };
223
224 /*
225  * Macro-instructions used to manage group descriptors
226  */
227 #define EXT2_BLOCKS_PER_GROUP(s)        ((s)->s_blocks_per_group)
228 #define EXT2_DESC_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
229 #define EXT2_INODES_PER_GROUP(s)        ((s)->s_inodes_per_group)
230
231 /*
232  * Constants relative to the data blocks
233  */
234 #define EXT2_NDIR_BLOCKS                12
235 #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
236 #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
237 #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
238 #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
239 #define EXT2_MAXSYMLINKLEN              (EXT2_N_BLOCKS * sizeof (__u32))
240
241 /*
242  * Inode flags
243  */
244 #define EXT2_SECRM_FL                   0x00000001 /* Secure deletion */
245 #define EXT2_UNRM_FL                    0x00000002 /* Undelete */
246 #define EXT2_COMPR_FL                   0x00000004 /* Compress file */
247 #define EXT2_SYNC_FL                    0x00000008 /* Synchronous updates */
248 #define EXT2_IMMUTABLE_FL               0x00000010 /* Immutable file */
249 #define EXT2_APPEND_FL                  0x00000020 /* writes to file may only append */
250 #define EXT2_NODUMP_FL                  0x00000040 /* do not dump file */
251 #define EXT2_NOATIME_FL                 0x00000080 /* do not update atime */
252 /* Reserved for compression usage... */
253 #define EXT2_DIRTY_FL                   0x00000100
254 #define EXT2_COMPRBLK_FL                0x00000200 /* One or more compressed clusters */
255 #define EXT2_NOCOMP_FL                  0x00000400 /* Don't compress */
256 #define EXT2_ECOMPR_FL                  0x00000800 /* Compression error */
257 /* End compression flags --- maybe not all used */
258 #define EXT2_BTREE_FL                   0x00001000 /* btree format dir */
259 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
260
261 #define EXT2_FL_USER_VISIBLE            0x00001FFF /* User visible flags */
262 #define EXT2_FL_USER_MODIFIABLE         0x000000FF /* User modifiable flags */
263
264 /*
265  * ioctl commands
266  */
267 #define EXT2_IOC_GETFLAGS               _IOR('f', 1, long)
268 #define EXT2_IOC_SETFLAGS               _IOW('f', 2, long)
269 #define EXT2_IOC_GETVERSION             _IOR('v', 1, long)
270 #define EXT2_IOC_SETVERSION             _IOW('v', 2, long)
271
272 /*
273  * Only declare `struct ext2_inode' if <vfs/ufs/inode.h> hasn't made things
274  * difficult by #defining i_mode and other struct members.  The details of
275  * the struct are only needed in ext2_inode_cnv.c where the ext2fs on-disk
276  * inode is converted to a ufs in-core inode.
277  */
278 #ifndef i_mode
279
280 /*
281  * Structure of an inode on the disk
282  */
283 struct ext2_inode {
284         __u16   i_mode;         /* File mode */
285         __u16   i_uid;          /* Owner Uid */
286         __u32   i_size;         /* Size in bytes */
287         __u32   i_atime;        /* Access time */
288         __u32   i_ctime;        /* Creation time */
289         __u32   i_mtime;        /* Modification time */
290         __u32   i_dtime;        /* Deletion Time */
291         __u16   i_gid;          /* Group Id */
292         __u16   i_links_count;  /* Links count */
293         __u32   i_blocks;       /* Blocks count */
294         __u32   i_flags;        /* File flags */
295         union {
296                 struct {
297                         __u32  l_i_reserved1;
298                 } linux1;
299                 struct {
300                         __u32  h_i_translator;
301                 } hurd1;
302                 struct {
303                         __u32  m_i_reserved1;
304                 } masix1;
305         } osd1;                         /* OS dependent 1 */
306         __u32   i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
307         __u32   i_generation;   /* File version (for NFS) */
308         __u32   i_file_acl;     /* File ACL */
309         __u32   i_dir_acl;      /* Directory ACL */
310         __u32   i_faddr;        /* Fragment address */
311         union {
312                 struct {
313                         __u8    l_i_frag;       /* Fragment number */
314                         __u8    l_i_fsize;      /* Fragment size */
315                         __u16   i_pad1;
316                         __u16   l_i_uid_high;   /* these 2 fields    */
317                         __u16   l_i_gid_high;   /* were reserved2[0] */
318                         __u32   l_i_reserved2;
319                 } linux2;
320                 struct {
321                         __u8    h_i_frag;       /* Fragment number */
322                         __u8    h_i_fsize;      /* Fragment size */
323                         __u16   h_i_mode_high;
324                         __u16   h_i_uid_high;
325                         __u16   h_i_gid_high;
326                         __u32   h_i_author;
327                 } hurd2;
328                 struct {
329                         __u8    m_i_frag;       /* Fragment number */
330                         __u8    m_i_fsize;      /* Fragment size */
331                         __u16   m_pad1;
332                         __u32   m_i_reserved2[2];
333                 } masix2;
334         } osd2;                         /* OS dependent 2 */
335 };
336
337 #define i_size_high     i_dir_acl
338
339 #if defined(__KERNEL__) || defined(__linux__)
340 #define i_reserved1     osd1.linux1.l_i_reserved1
341 #define i_frag          osd2.linux2.l_i_frag
342 #define i_fsize         osd2.linux2.l_i_fsize
343 #define i_uid_low       i_uid
344 #define i_gid_low       i_gid
345 #define i_uid_high      osd2.linux2.l_i_uid_high
346 #define i_gid_high      osd2.linux2.l_i_gid_high
347 #define i_reserved2     osd2.linux2.l_i_reserved2
348 #endif
349
350 #ifdef  __hurd__
351 #define i_translator    osd1.hurd1.h_i_translator
352 #define i_frag          osd2.hurd2.h_i_frag;
353 #define i_fsize         osd2.hurd2.h_i_fsize;
354 #define i_uid_high      osd2.hurd2.h_i_uid_high
355 #define i_gid_high      osd2.hurd2.h_i_gid_high
356 #define i_author        osd2.hurd2.h_i_author
357 #endif
358
359 #ifdef  __masix__
360 #define i_reserved1     osd1.masix1.m_i_reserved1
361 #define i_frag          osd2.masix2.m_i_frag
362 #define i_fsize         osd2.masix2.m_i_fsize
363 #define i_reserved2     osd2.masix2.m_i_reserved2
364 #endif
365
366 #endif /* i_mode */
367
368 /*
369  * File system states
370  */
371 #define EXT2_VALID_FS                   0x0001  /* Unmounted cleanly */
372 #define EXT2_ERROR_FS                   0x0002  /* Errors detected */
373
374 /*
375  * Mount flags
376  */
377 #define EXT2_MOUNT_CHECK_NORMAL         0x0001  /* Do some more checks */
378 #define EXT2_MOUNT_CHECK_STRICT         0x0002  /* Do again more checks */
379 #define EXT2_MOUNT_CHECK                (EXT2_MOUNT_CHECK_NORMAL | \
380                                          EXT2_MOUNT_CHECK_STRICT)
381 #define EXT2_MOUNT_GRPID                0x0004  /* Create files with directory's group */
382 #define EXT2_MOUNT_DEBUG                0x0008  /* Some debugging messages */
383 #define EXT2_MOUNT_ERRORS_CONT          0x0010  /* Continue on errors */
384 #define EXT2_MOUNT_ERRORS_RO            0x0020  /* Remount fs ro on errors */
385 #define EXT2_MOUNT_ERRORS_PANIC         0x0040  /* Panic on errors */
386 #define EXT2_MOUNT_MINIX_DF             0x0080  /* Mimics the Minix statfs */
387 #define EXT2_MOUNT_NOBH                 0x000100  /* No buffer_heads */
388 #define EXT2_MOUNT_NO_UID32             0x000200  /* Disable 32-bit UIDs */
389 #define EXT2_MOUNT_XATTR_USER           0x004000  /* Extended user attributes */
390 #define EXT2_MOUNT_POSIX_ACL            0x008000  /* POSIX Access Control Lists */
391 #define EXT2_MOUNT_XIP                  0x010000  /* Obsolete, use DAX */
392 #define EXT2_MOUNT_USRQUOTA             0x020000  /* user quota */
393 #define EXT2_MOUNT_GRPQUOTA             0x040000  /* group quota */
394 #define EXT2_MOUNT_RESERVATION          0x080000  /* Preallocation */
395
396 #define clear_opt(o, opt)               o &= ~EXT2_MOUNT_##opt
397 #define set_opt(o, opt)                 o |= EXT2_MOUNT_##opt
398 #define test_opt(sb, opt)               ((sb)->u.ext2_sb.s_mount_opt & \
399                                          EXT2_MOUNT_##opt)
400 /*
401  * Maximal mount counts between two filesystem checks
402  */
403 #define EXT2_DFL_MAX_MNT_COUNT          20      /* Allow 20 mounts */
404 #define EXT2_DFL_CHECKINTERVAL          0       /* Don't use interval check */
405
406 /*
407  * Behaviour when detecting errors
408  */
409 #define EXT2_ERRORS_CONTINUE            1       /* Continue execution */
410 #define EXT2_ERRORS_RO                  2       /* Remount fs read-only */
411 #define EXT2_ERRORS_PANIC               3       /* Panic */
412 #define EXT2_ERRORS_DEFAULT             EXT2_ERRORS_CONTINUE
413
414 /*
415  * Structure of the super block
416  */
417 struct ext2_super_block {
418         __u32   s_inodes_count;         /* Inodes count */
419         __u32   s_blocks_count;         /* Blocks count */
420         __u32   s_r_blocks_count;       /* Reserved blocks count */
421         __u32   s_free_blocks_count;    /* Free blocks count */
422         __u32   s_free_inodes_count;    /* Free inodes count */
423         __u32   s_first_data_block;     /* First Data Block */
424         __u32   s_log_block_size;       /* Block size */
425         __s32   s_log_frag_size;        /* Fragment size */
426         __u32   s_blocks_per_group;     /* # Blocks per group */
427         __u32   s_frags_per_group;      /* # Fragments per group */
428         __u32   s_inodes_per_group;     /* # Inodes per group */
429         __u32   s_mtime;                /* Mount time */
430         __u32   s_wtime;                /* Write time */
431         __u16   s_mnt_count;            /* Mount count */
432         __s16   s_max_mnt_count;        /* Maximal mount count */
433         __u16   s_magic;                /* Magic signature */
434         __u16   s_state;                /* File system state */
435         __u16   s_errors;               /* Behaviour when detecting errors */
436         __u16   s_minor_rev_level;      /* minor revision level */
437         __u32   s_lastcheck;            /* time of last check */
438         __u32   s_checkinterval;        /* max. time between checks */
439         __u32   s_creator_os;           /* OS */
440         __u32   s_rev_level;            /* Revision level */
441         __u16   s_def_resuid;           /* Default uid for reserved blocks */
442         __u16   s_def_resgid;           /* Default gid for reserved blocks */
443         /*
444          * These fields are for EXT2_DYNAMIC_REV superblocks only.
445          *
446          * Note: the difference between the compatible feature set and
447          * the incompatible feature set is that if there is a bit set
448          * in the incompatible feature set that the kernel doesn't
449          * know about, it should refuse to mount the filesystem.
450          *
451          * e2fsck's requirements are more strict; if it doesn't know
452          * about a feature in either the compatible or incompatible
453          * feature set, it must abort and not try to meddle with
454          * things it doesn't understand...
455          */
456         __u32   s_first_ino;            /* First non-reserved inode */
457         __u16   s_inode_size;           /* size of inode structure */
458         __u16   s_block_group_nr;       /* block group # of this superblock */
459         __u32   s_feature_compat;       /* compatible feature set */
460         __u32   s_feature_incompat;     /* incompatible feature set */
461         __u32   s_feature_ro_compat;    /* readonly-compatible feature set */
462         __u8    s_uuid[16];             /* 128-bit uuid for volume */
463         char    s_volume_name[16];      /* volume name */
464         char    s_last_mounted[64];     /* directory where last mounted */
465         __u32   s_algorithm_usage_bitmap; /* For compression */
466         /*
467          * Performance hints.  Directory preallocation should only
468          * happen if the EXT2_COMPAT_PREALLOC flag is on.
469          */
470         __u8    s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
471         __u8    s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
472         __u16   s_padding1;
473         /*
474          * Journaling support for ext3.
475          */
476         __u8    s_journal_uuid[16];     /* uuid of journal superblock */
477         __u32   s_journal_inum;         /* inode number of journal file */
478         __u32   s_journal_dev;          /* device number of journal file */
479         __u32   s_last_orphan;          /* start of list of inodes to delete */
480         __u32   s_hash_seed[4];         /* HTREE hash seed */
481         __u8    s_def_hash_version;     /* Default hash version to use */
482         __u8    s_reserved_char_pad;
483         __u16   s_reserved_word_pad;
484         __u32   s_default_mount_opts;
485         __u32   s_first_meta_bg;        /* First metablock block group */
486         __u32   s_reserved[190];        /* Padding to the end of the block */
487 };
488
489 /* Assume that user mode programs are passing in an ext2fs superblock, not
490  * a kernel struct super_block.  This will allow us to call the feature-test
491  * macros from user land. */
492 #define EXT2_SB(sb)     (sb)
493
494 /*
495  * Codes for operating systems
496  */
497 #define EXT2_OS_LINUX           0
498 #define EXT2_OS_HURD            1
499 #define EXT2_OS_MASIX           2
500 #define EXT2_OS_FREEBSD         3
501 #define EXT2_OS_LITES           4
502
503 /*
504  * Revision levels
505  */
506 #define EXT2_GOOD_OLD_REV       0       /* The good old (original) format */
507 #define EXT2_DYNAMIC_REV        1       /* V2 format w/ dynamic inode sizes */
508
509 #define EXT2_CURRENT_REV        EXT2_GOOD_OLD_REV
510 #define EXT2_MAX_SUPP_REV       EXT2_DYNAMIC_REV
511
512 #define EXT2_GOOD_OLD_INODE_SIZE 128
513
514 /*
515  * Feature set definitions
516  */
517
518 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
519         ( EXT2_SB(sb)->s_feature_compat & (mask) )
520 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)                     \
521         ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
522 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
523         ( EXT2_SB(sb)->s_feature_incompat & (mask) )
524 #define EXT2_SET_COMPAT_FEATURE(sb,mask)                        \
525         EXT2_SB(sb)->s_es->s_feature_compat |= (mask)
526 #define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)                     \
527         EXT2_SB(sb)->s_es->s_feature_ro_compat |= (mask)
528 #define EXT2_SET_INCOMPAT_FEATURE(sb,mask)                      \
529         EXT2_SB(sb)->s_es->s_feature_incompat |= (mask)
530 #define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)                      \
531         EXT2_SB(sb)->s_es->s_feature_compat &= ~(mask)
532 #define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)                   \
533         EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~(mask)
534 #define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)                    \
535         EXT2_SB(sb)->s_es->s_feature_incompat &= ~(mask)
536
537 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC        0x0001
538 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES       0x0002
539 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL         0x0004
540 #define EXT2_FEATURE_COMPAT_EXT_ATTR            0x0008
541 #define EXT2_FEATURE_COMPAT_RESIZE_INO          0x0010
542 #define EXT2_FEATURE_COMPAT_DIR_INDEX           0x0020
543 #define EXT2_FEATURE_COMPAT_ANY                 0xffffffff
544
545 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
546 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
547 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
548 #define EXT2_FEATURE_RO_COMPAT_ANY              0xffffffff
549
550 #define EXT2_FEATURE_INCOMPAT_COMPRESSION       0x0001
551 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
552 #define EXT3_FEATURE_INCOMPAT_RECOVER           0x0004
553 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008
554 #define EXT2_FEATURE_INCOMPAT_META_BG           0x0010
555 #define EXT2_FEATURE_INCOMPAT_ANY               0xffffffff
556
557 #if 1
558 #define EXT2_FEATURE_COMPAT_SUPP       0
559 #define EXT2_FEATURE_INCOMPAT_SUPP     EXT2_FEATURE_INCOMPAT_FILETYPE
560 #else
561 #define EXT2_FEATURE_COMPAT_SUPP        EXT2_FEATURE_COMPAT_EXT_ATTR
562 #define EXT2_FEATURE_INCOMPAT_SUPP      (EXT2_FEATURE_INCOMPAT_FILETYPE| \
563                                          EXT2_FEATURE_INCOMPAT_META_BG)
564 #endif
565
566 #ifdef notyet
567 #define EXT2_FEATURE_RO_COMPAT_SUPP     (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
568                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
569                                          EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
570 #else
571 #define EXT2_FEATURE_RO_COMPAT_SUPP     EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
572 #endif
573 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED      ~EXT2_FEATURE_RO_COMPAT_SUPP
574 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED       ~EXT2_FEATURE_INCOMPAT_SUPP
575
576 /*
577  * Default values for user and/or group using reserved blocks
578  */
579 #define EXT2_DEF_RESUID         0
580 #define EXT2_DEF_RESGID         0
581
582 /*
583  * Structure of a directory entry
584  */
585 #define EXT2_NAME_LEN 255
586
587 struct ext2_dir_entry {
588         __u32   inode;                  /* Inode number */
589         __u16   rec_len;                /* Directory entry length */
590         __u16   name_len;               /* Name length */
591         char    name[EXT2_NAME_LEN];    /* File name */
592 };
593
594 /*
595  * The new version of the directory entry.  Since EXT2 structures are
596  * stored in intel byte order, and the name_len field could never be
597  * bigger than 255 chars, it's safe to reclaim the extra byte for the
598  * file_type field.
599  */
600 struct ext2_dir_entry_2 {
601         __u32   inode;                  /* Inode number */
602         __u16   rec_len;                /* Directory entry length */
603         __u8    name_len;               /* Name length */
604         __u8    file_type;
605         char    name[EXT2_NAME_LEN];    /* File name */
606 };
607
608 /*
609  * Ext2 directory file types.  Only the low 3 bits are used.  The
610  * other bits are reserved for now.
611  */
612 #define EXT2_FT_UNKNOWN         0
613 #define EXT2_FT_REG_FILE        1
614 #define EXT2_FT_DIR             2
615 #define EXT2_FT_CHRDEV          3
616 #define EXT2_FT_BLKDEV          4
617 #define EXT2_FT_FIFO            5
618 #define EXT2_FT_SOCK            6
619 #define EXT2_FT_SYMLINK         7
620
621 #define EXT2_FT_MAX             8
622
623 /*
624  * EXT2_DIR_PAD defines the directory entries boundaries
625  *
626  * NOTE: It must be a multiple of 4
627  */
628 #define EXT2_DIR_PAD                    4
629 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
630 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
631                                          ~EXT2_DIR_ROUND)
632 #define EXT2_MAX_REC_LEN                ((1<<16)-1)
633
634 #endif  /* _LINUX_EXT2_FS_H */