Some cleanup after addition of TRIM support.
[dragonfly.git] / sys / vfs / gnu / ext2fs / ext2_fs.h
blob2184ba15abec64badd0234aa7b3f6cbf886386e0
1 /*
2 * modified for EXT2FS support in Lites 1.1
4 * Aug 1995, Godmar Back (gback@cs.utah.edu)
5 * University of Utah, Department of Computer Science
7 * $FreeBSD: src/sys/gnu/ext2fs/ext2_fs.h,v 1.8.2.2 2001/09/29 12:52:47 iedowse Exp $
8 * $DragonFly: src/sys/vfs/gnu/ext2fs/ext2_fs.h,v 1.6 2006/12/23 00:41:29 swildner Exp $
9 */
11 * linux/include/linux/ext2_fs.h
13 * Copyright (C) 1992, 1993, 1994, 1995
14 * Remy Card (card@masi.ibp.fr)
15 * Laboratoire MASI - Institut Blaise Pascal
16 * Universite Pierre et Marie Curie (Paris VI)
18 * from
20 * linux/include/linux/minix_fs.h
22 * Copyright (C) 1991, 1992 Linus Torvalds
25 #ifndef _LINUX_EXT2_FS_H
26 #define _LINUX_EXT2_FS_H
28 #include <sys/types.h>
29 #include <sys/ioccom.h>
31 #define __u32 u_int32_t
32 #define u32 u_int32_t
33 #define __u16 u_int16_t
34 #define __u8 u_int8_t
36 #define __s32 int32_t
37 #define __s16 int16_t
38 #define __s8 int8_t
40 #define umode_t mode_t
41 #define loff_t off_t
43 /* the Linux implementation of EXT2 stores some information about
44 * an inode in a ext2_inode_info structure which is part of the incore
45 * inode in Linux
46 * I decided to use the "spare" fields instead - we'll see how this
47 * works out
50 #define i_block_group i_spare[0]
51 #define i_next_alloc_block i_spare[1]
52 #define i_next_alloc_goal i_spare[2]
53 #define i_prealloc_block i_din.di_spare[0]
54 #define i_prealloc_count i_din.di_spare[1]
57 * The second extended filesystem constants/structures
61 * Define EXT2FS_DEBUG to produce debug messages
63 #undef EXT2FS_DEBUG
66 * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
68 #define EXT2_PREALLOCATE
69 #define EXT2_DEFAULT_PREALLOC_BLOCKS 8
72 * The second extended file system version
74 #define EXT2FS_DATE "95/08/09"
75 #define EXT2FS_VERSION "0.5b"
78 * Debug code
80 #ifdef EXT2FS_DEBUG
81 # define ext2_debug(f, a...) { \
82 kprintf ("EXT2-fs DEBUG (%s, %d): %s:", \
83 __FILE__, __LINE__, __func__); \
84 kprintf (f, ## a); \
86 #else
87 # define ext2_debug(f, a...) /**/
88 #endif
91 * Special inodes numbers
93 #define EXT2_BAD_INO 1 /* Bad blocks inode */
94 #define EXT2_ROOT_INO 2 /* Root inode */
95 #define EXT2_ACL_IDX_INO 3 /* ACL inode */
96 #define EXT2_ACL_DATA_INO 4 /* ACL inode */
97 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
98 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
100 /* First non-reserved inode for old ext2 filesystems */
101 #define EXT2_GOOD_OLD_FIRST_INO 11
104 * The second extended file system magic number
106 #define EXT2_SUPER_MAGIC 0xEF53
109 * Maximal count of links to a file
111 #define EXT2_LINK_MAX 32000
114 * Note: under FreeBSD, the "user" versions of the following macros are
115 * used (and must be used) in most cases, because ((s)->u.ext2_sb.s_es is
116 * not accessible. This depends on __KERNEL__ not being defined for
117 * kernel builds under FreeBSD.
121 * Macro-instructions used to manage several block sizes
123 #define EXT2_MIN_BLOCK_SIZE 1024
124 #define EXT2_MAX_BLOCK_SIZE 4096
125 #define EXT2_MIN_BLOCK_LOG_SIZE 10
126 #if defined(__KERNEL__) || (defined(__DragonFly__) && defined(_KERNEL))
127 # define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
128 #else
129 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
130 #endif
131 #define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
132 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
133 #ifdef __KERNEL__
134 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
135 #else
136 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
137 #endif
138 #if defined(__KERNEL__) || defined _KERNEL
139 #define EXT2_ADDR_PER_BLOCK_BITS(s) ((s)->s_addr_per_block_bits)
140 #define EXT2_INODE_SIZE(s) ((s)->s_inode_size)
141 #define EXT2_FIRST_INO(s) ((s)->s_first_ino)
142 #else
143 #define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
144 EXT2_GOOD_OLD_INODE_SIZE : \
145 (s)->s_inode_size)
146 #define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
147 EXT2_GOOD_OLD_FIRST_INO : \
148 (s)->s_first_ino)
149 #endif
150 #define EXT2_INODES_PER_BLOCK(s) ((s)->s_inodes_per_block)
152 * Macro-instructions used to manage fragments
154 #define EXT2_MIN_FRAG_SIZE 1024
155 #define EXT2_MAX_FRAG_SIZE 4096
156 #define EXT2_MIN_FRAG_LOG_SIZE 10
157 #ifdef __KERNEL__
158 # define EXT2_FRAG_SIZE(s) ((s)->u.ext2_sb.s_frag_size)
159 # define EXT2_FRAGS_PER_BLOCK(s) ((s)->u.ext2_sb.s_frags_per_block)
160 #else
161 # if defined(_KERNEL) && defined(__DragonFly__)
162 # define EXT2_FRAG_SIZE(s) ((s)->s_frag_size)
163 # else
164 # define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
165 # endif
166 # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
167 #endif
170 * ACL structures
172 struct ext2_acl_header /* Header of Access Control Lists */
174 __u32 aclh_size;
175 __u32 aclh_file_count;
176 __u32 aclh_acle_count;
177 __u32 aclh_first_acle;
180 struct ext2_acl_entry /* Access Control List Entry */
182 __u32 acle_size;
183 __u16 acle_perms; /* Access permissions */
184 __u16 acle_type; /* Type of entry */
185 __u16 acle_tag; /* User or group identity */
186 __u16 acle_pad1;
187 __u32 acle_next; /* Pointer on next entry for the */
188 /* same inode or on next free entry */
192 * Structure of a blocks group descriptor
194 struct ext2_group_desc
196 __u32 bg_block_bitmap; /* Blocks bitmap block */
197 __u32 bg_inode_bitmap; /* Inodes bitmap block */
198 __u32 bg_inode_table; /* Inodes table block */
199 __u16 bg_free_blocks_count; /* Free blocks count */
200 __u16 bg_free_inodes_count; /* Free inodes count */
201 __u16 bg_used_dirs_count; /* Directories count */
202 __u16 bg_pad;
203 __u32 bg_reserved[3];
207 * Macro-instructions used to manage group descriptors
209 #ifdef __KERNEL__
210 # define EXT2_BLOCKS_PER_GROUP(s) ((s)->u.ext2_sb.s_blocks_per_group)
211 # define EXT2_DESC_PER_BLOCK(s) ((s)->u.ext2_sb.s_desc_per_block)
212 # define EXT2_INODES_PER_GROUP(s) ((s)->u.ext2_sb.s_inodes_per_group)
213 # define EXT2_DESC_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_desc_per_block_bits)
214 #else
215 # define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
216 # define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
217 # define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
218 #endif
221 * Constants relative to the data blocks
223 #define EXT2_NDIR_BLOCKS 12
224 #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
225 #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
226 #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
227 #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
228 #define EXT2_MAXSYMLINKLEN (EXT2_N_BLOCKS * sizeof (__u32))
231 * Inode flags
233 #define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
234 #define EXT2_UNRM_FL 0x00000002 /* Undelete */
235 #define EXT2_COMPR_FL 0x00000004 /* Compress file */
236 #define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
237 #define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
238 #define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
239 #define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
240 #define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
241 /* Reserved for compression usage... */
242 #define EXT2_DIRTY_FL 0x00000100
243 #define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
244 #define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
245 #define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
246 /* End compression flags --- maybe not all used */
247 #define EXT2_BTREE_FL 0x00001000 /* btree format dir */
248 #define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
250 #define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
251 #define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
254 * ioctl commands
256 #define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
257 #define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
258 #define EXT2_IOC_GETVERSION _IOR('v', 1, long)
259 #define EXT2_IOC_SETVERSION _IOW('v', 2, long)
262 * Only declare `struct ext2_inode' if <vfs/ufs/inode.h> hasn't made things
263 * difficult by #defining i_mode and other struct members. The details of
264 * the struct are only needed in ext2_inode_cnv.c where the ext2fs on-disk
265 * inode is converted to a ufs in-core inode.
267 #ifndef i_mode
270 * Structure of an inode on the disk
272 struct ext2_inode {
273 __u16 i_mode; /* File mode */
274 __u16 i_uid; /* Owner Uid */
275 __u32 i_size; /* Size in bytes */
276 __u32 i_atime; /* Access time */
277 __u32 i_ctime; /* Creation time */
278 __u32 i_mtime; /* Modification time */
279 __u32 i_dtime; /* Deletion Time */
280 __u16 i_gid; /* Group Id */
281 __u16 i_links_count; /* Links count */
282 __u32 i_blocks; /* Blocks count */
283 __u32 i_flags; /* File flags */
284 union {
285 struct {
286 __u32 l_i_reserved1;
287 } linux1;
288 struct {
289 __u32 h_i_translator;
290 } hurd1;
291 struct {
292 __u32 m_i_reserved1;
293 } masix1;
294 } osd1; /* OS dependent 1 */
295 __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
296 __u32 i_generation; /* File version (for NFS) */
297 __u32 i_file_acl; /* File ACL */
298 __u32 i_dir_acl; /* Directory ACL */
299 __u32 i_faddr; /* Fragment address */
300 union {
301 struct {
302 __u8 l_i_frag; /* Fragment number */
303 __u8 l_i_fsize; /* Fragment size */
304 __u16 i_pad1;
305 __u32 l_i_reserved2[2];
306 } linux2;
307 struct {
308 __u8 h_i_frag; /* Fragment number */
309 __u8 h_i_fsize; /* Fragment size */
310 __u16 h_i_mode_high;
311 __u16 h_i_uid_high;
312 __u16 h_i_gid_high;
313 __u32 h_i_author;
314 } hurd2;
315 struct {
316 __u8 m_i_frag; /* Fragment number */
317 __u8 m_i_fsize; /* Fragment size */
318 __u16 m_pad1;
319 __u32 m_i_reserved2[2];
320 } masix2;
321 } osd2; /* OS dependent 2 */
324 #define i_size_high i_dir_acl
326 #if defined(__KERNEL__) || defined(__linux__)
327 #define i_reserved1 osd1.linux1.l_i_reserved1
328 #define i_frag osd2.linux2.l_i_frag
329 #define i_fsize osd2.linux2.l_i_fsize
330 #define i_reserved2 osd2.linux2.l_i_reserved2
331 #endif
333 #ifdef __hurd__
334 #define i_translator osd1.hurd1.h_i_translator
335 #define i_frag osd2.hurd2.h_i_frag;
336 #define i_fsize osd2.hurd2.h_i_fsize;
337 #define i_uid_high osd2.hurd2.h_i_uid_high
338 #define i_gid_high osd2.hurd2.h_i_gid_high
339 #define i_author osd2.hurd2.h_i_author
340 #endif
342 #ifdef __masix__
343 #define i_reserved1 osd1.masix1.m_i_reserved1
344 #define i_frag osd2.masix2.m_i_frag
345 #define i_fsize osd2.masix2.m_i_fsize
346 #define i_reserved2 osd2.masix2.m_i_reserved2
347 #endif
349 #endif /* i_mode */
352 * File system states
354 #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
355 #define EXT2_ERROR_FS 0x0002 /* Errors detected */
358 * Mount flags
360 #define EXT2_MOUNT_CHECK_NORMAL 0x0001 /* Do some more checks */
361 #define EXT2_MOUNT_CHECK_STRICT 0x0002 /* Do again more checks */
362 #define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
363 EXT2_MOUNT_CHECK_STRICT)
364 #define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
365 #define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
366 #define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
367 #define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
368 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
369 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
371 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
372 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
373 #define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
374 EXT2_MOUNT_##opt)
376 * Maximal mount counts between two filesystem checks
378 #define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
379 #define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
382 * Behaviour when detecting errors
384 #define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
385 #define EXT2_ERRORS_RO 2 /* Remount fs read-only */
386 #define EXT2_ERRORS_PANIC 3 /* Panic */
387 #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
390 * Structure of the super block
392 struct ext2_super_block {
393 __u32 s_inodes_count; /* Inodes count */
394 __u32 s_blocks_count; /* Blocks count */
395 __u32 s_r_blocks_count; /* Reserved blocks count */
396 __u32 s_free_blocks_count; /* Free blocks count */
397 __u32 s_free_inodes_count; /* Free inodes count */
398 __u32 s_first_data_block; /* First Data Block */
399 __u32 s_log_block_size; /* Block size */
400 __s32 s_log_frag_size; /* Fragment size */
401 __u32 s_blocks_per_group; /* # Blocks per group */
402 __u32 s_frags_per_group; /* # Fragments per group */
403 __u32 s_inodes_per_group; /* # Inodes per group */
404 __u32 s_mtime; /* Mount time */
405 __u32 s_wtime; /* Write time */
406 __u16 s_mnt_count; /* Mount count */
407 __s16 s_max_mnt_count; /* Maximal mount count */
408 __u16 s_magic; /* Magic signature */
409 __u16 s_state; /* File system state */
410 __u16 s_errors; /* Behaviour when detecting errors */
411 __u16 s_minor_rev_level; /* minor revision level */
412 __u32 s_lastcheck; /* time of last check */
413 __u32 s_checkinterval; /* max. time between checks */
414 __u32 s_creator_os; /* OS */
415 __u32 s_rev_level; /* Revision level */
416 __u16 s_def_resuid; /* Default uid for reserved blocks */
417 __u16 s_def_resgid; /* Default gid for reserved blocks */
419 * These fields are for EXT2_DYNAMIC_REV superblocks only.
421 * Note: the difference between the compatible feature set and
422 * the incompatible feature set is that if there is a bit set
423 * in the incompatible feature set that the kernel doesn't
424 * know about, it should refuse to mount the filesystem.
426 * e2fsck's requirements are more strict; if it doesn't know
427 * about a feature in either the compatible or incompatible
428 * feature set, it must abort and not try to meddle with
429 * things it doesn't understand...
431 __u32 s_first_ino; /* First non-reserved inode */
432 __u16 s_inode_size; /* size of inode structure */
433 __u16 s_block_group_nr; /* block group # of this superblock */
434 __u32 s_feature_compat; /* compatible feature set */
435 __u32 s_feature_incompat; /* incompatible feature set */
436 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
437 __u8 s_uuid[16]; /* 128-bit uuid for volume */
438 char s_volume_name[16]; /* volume name */
439 char s_last_mounted[64]; /* directory where last mounted */
440 __u32 s_algorithm_usage_bitmap; /* For compression */
442 * Performance hints. Directory preallocation should only
443 * happen if the EXT2_COMPAT_PREALLOC flag is on.
445 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
446 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
447 __u16 s_padding1;
448 __u32 s_reserved[204]; /* Padding to the end of the block */
451 #ifdef __KERNEL__
452 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
453 #else
454 /* Assume that user mode programs are passing in an ext2fs superblock, not
455 * a kernel struct super_block. This will allow us to call the feature-test
456 * macros from user land. */
457 #define EXT2_SB(sb) (sb)
458 #endif
461 * Codes for operating systems
463 #define EXT2_OS_LINUX 0
464 #define EXT2_OS_HURD 1
465 #define EXT2_OS_MASIX 2
466 #define EXT2_OS_FREEBSD 3
467 #define EXT2_OS_LITES 4
470 * Revision levels
472 #define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
473 #define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
475 #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
476 #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
478 #define EXT2_GOOD_OLD_INODE_SIZE 128
481 * Feature set definitions
484 #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
485 ( EXT2_SB(sb)->s_feature_compat & (mask) )
486 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
487 ( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
488 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
489 ( EXT2_SB(sb)->s_feature_incompat & (mask) )
491 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
493 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
494 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
495 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
497 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
498 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
500 #define EXT2_FEATURE_COMPAT_SUPP 0
501 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
502 #ifdef notyet
503 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
504 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
505 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
506 #else
507 #define EXT2_FEATURE_RO_COMPAT_SUPP EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
508 #endif
511 * Default values for user and/or group using reserved blocks
513 #define EXT2_DEF_RESUID 0
514 #define EXT2_DEF_RESGID 0
517 * Structure of a directory entry
519 #define EXT2_NAME_LEN 255
521 struct ext2_dir_entry {
522 __u32 inode; /* Inode number */
523 __u16 rec_len; /* Directory entry length */
524 __u16 name_len; /* Name length */
525 char name[EXT2_NAME_LEN]; /* File name */
529 * The new version of the directory entry. Since EXT2 structures are
530 * stored in intel byte order, and the name_len field could never be
531 * bigger than 255 chars, it's safe to reclaim the extra byte for the
532 * file_type field.
534 struct ext2_dir_entry_2 {
535 __u32 inode; /* Inode number */
536 __u16 rec_len; /* Directory entry length */
537 __u8 name_len; /* Name length */
538 __u8 file_type;
539 char name[EXT2_NAME_LEN]; /* File name */
543 * Ext2 directory file types. Only the low 3 bits are used. The
544 * other bits are reserved for now.
546 #define EXT2_FT_UNKNOWN 0
547 #define EXT2_FT_REG_FILE 1
548 #define EXT2_FT_DIR 2
549 #define EXT2_FT_CHRDEV 3
550 #define EXT2_FT_BLKDEV 4
551 #define EXT2_FT_FIFO 5
552 #define EXT2_FT_SOCK 6
553 #define EXT2_FT_SYMLINK 7
555 #define EXT2_FT_MAX 8
558 * EXT2_DIR_PAD defines the directory entries boundaries
560 * NOTE: It must be a multiple of 4
562 #define EXT2_DIR_PAD 4
563 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
564 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
565 ~EXT2_DIR_ROUND)
567 #endif /* _LINUX_EXT2_FS_H */