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
10 * linux/include/linux/ext2_fs.h
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)
19 * linux/include/linux/minix_fs.h
21 * Copyright (C) 1991, 1992 Linus Torvalds
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 #ifndef _LINUX_EXT2_FS_H
39 #define _LINUX_EXT2_FS_H
41 #include <sys/types.h>
43 #define __u32 u_int32_t
45 #define __u16 u_int16_t
52 #define umode_t mode_t
55 #define cpu_to_le32(x) htole32(x)
58 * The second extended filesystem constants/structures
62 * Define EXT2FS_DEBUG to produce debug messages
67 * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
69 #define EXT2_PREALLOCATE
70 #define EXT2_DEFAULT_PREALLOC_BLOCKS 8
73 * The second extended file system version
75 #define EXT2FS_DATE "95/08/09"
76 #define EXT2FS_VERSION "0.5b"
82 # define ext2_debug(f, a...) { \
83 printf ("EXT2-fs DEBUG (%s, %d): %s:", \
84 __FILE__, __LINE__, __func__); \
88 # define ext2_debug(f, a...) /**/
92 * Special inode numbers
94 #define EXT2_BAD_INO 1 /* Bad blocks inode */
95 #define EXT2_ROOT_INO 2 /* Root inode */
96 #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
97 #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
99 /* First non-reserved inode for old ext2 filesystems */
100 #define EXT2_GOOD_OLD_FIRST_INO 11
103 * The second extended file system magic number
105 #define EXT2_SUPER_MAGIC 0xEF53
108 #include <linux/ext2_fs_sb.h>
109 static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
111 return sb->s_fs_info;
113 #elif defined(_KERNEL)
115 * FreeBSD passes the pointer to the in-core struct with relevant
116 * fields to EXT2_SB macro when accessing superblock fields.
118 #define EXT2_SB(sb) (sb)
120 /* Assume that user mode programs are passing in an ext2fs superblock, not
121 * a kernel struct super_block. This will allow us to call the feature-test
122 * macros from user land. */
123 #define EXT2_SB(sb) (sb)
127 * Maximal count of links to a file
129 #define EXT2_LINK_MAX 32000
132 * Macro-instructions used to manage several block sizes
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(__KERNEL__) || defined(_KERNEL)
138 # define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
140 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
142 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
143 #if defined(__KERNEL__) || defined(_KERNEL)
144 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
146 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
148 #if defined(__KERNEL__) || defined(_KERNEL)
149 #define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_addr_per_block_bits)
150 #define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
151 #define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
152 #define EXT2_INODES_PER_BLOCK(s) ((s)->s_inodes_per_block)
154 #define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
155 EXT2_GOOD_OLD_INODE_SIZE : \
157 #define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
158 EXT2_GOOD_OLD_FIRST_INO : \
163 * Macro-instructions used to manage fragments
165 #define EXT2_MIN_FRAG_SIZE 1024
166 #define EXT2_MAX_FRAG_SIZE 4096
167 #define EXT2_MIN_FRAG_LOG_SIZE 10
168 #if defined(__KERNEL__) || defined(_KERNEL)
169 # define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size)
170 # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block)
172 # define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
173 # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
179 struct ext2_acl_header /* Header of Access Control Lists */
182 __u32 aclh_file_count;
183 __u32 aclh_acle_count;
184 __u32 aclh_first_acle;
187 struct ext2_acl_entry /* Access Control List Entry */
190 __u16 acle_perms; /* Access permissions */
191 __u16 acle_type; /* Type of entry */
192 __u16 acle_tag; /* User or group identity */
194 __u32 acle_next; /* Pointer on next entry for the */
195 /* same inode or on next free entry */
199 * Structure of a blocks group descriptor
201 struct ext2_group_desc
203 __u32 bg_block_bitmap; /* Blocks bitmap block */
204 __u32 bg_inode_bitmap; /* Inodes bitmap block */
205 __u32 bg_inode_table; /* Inodes table block */
206 __u16 bg_free_blocks_count; /* Free blocks count */
207 __u16 bg_free_inodes_count; /* Free inodes count */
208 __u16 bg_used_dirs_count; /* Directories count */
210 __u32 bg_reserved[3];
214 * Macro-instructions used to manage group descriptors
216 #if defined(__KERNEL__) || defined(_KERNEL)
217 # define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
218 # define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
219 # define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
220 # define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
222 # define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
223 # define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
224 # define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
228 * Constants relative to the data blocks
230 #define EXT2_NDIR_BLOCKS 12
231 #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
232 #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
233 #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
234 #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
235 #define EXT2_MAXSYMLINKLEN (EXT2_N_BLOCKS * sizeof (__u32))
240 #define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
241 #define EXT2_UNRM_FL 0x00000002 /* Undelete */
242 #define EXT2_COMPR_FL 0x00000004 /* Compress file */
243 #define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
244 #define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
245 #define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
246 #define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
247 #define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
248 /* Reserved for compression usage... */
249 #define EXT2_DIRTY_FL 0x00000100
250 #define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
251 #define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
252 #define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
253 /* End compression flags --- maybe not all used */
254 #define EXT2_BTREE_FL 0x00001000 /* btree format dir */
255 #define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
257 #define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
258 #define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
263 #define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
264 #define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
265 #define EXT2_IOC_GETVERSION _IOR('v', 1, long)
266 #define EXT2_IOC_SETVERSION _IOW('v', 2, long)
269 * Structure of an inode on the disk
272 __u16 i_mode; /* File mode */
273 __u16 i_uid; /* Owner Uid */
274 __u32 i_size; /* Size in bytes */
275 __u32 i_atime; /* Access time */
276 __u32 i_ctime; /* Creation time */
277 __u32 i_mtime; /* Modification time */
278 __u32 i_dtime; /* Deletion Time */
279 __u16 i_gid; /* Group Id */
280 __u16 i_links_count; /* Links count */
281 __u32 i_blocks; /* Blocks count */
282 __u32 i_flags; /* File flags */
288 __u32 h_i_translator;
293 } osd1; /* OS dependent 1 */
294 __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
295 __u32 i_generation; /* File version (for NFS) */
296 __u32 i_file_acl; /* File ACL */
297 __u32 i_dir_acl; /* Directory ACL */
298 __u32 i_faddr; /* Fragment address */
301 __u8 l_i_frag; /* Fragment number */
302 __u8 l_i_fsize; /* Fragment size */
304 __u32 l_i_reserved2[2];
307 __u8 h_i_frag; /* Fragment number */
308 __u8 h_i_fsize; /* Fragment size */
315 __u8 m_i_frag; /* Fragment number */
316 __u8 m_i_fsize; /* Fragment size */
318 __u32 m_i_reserved2[2];
320 } osd2; /* OS dependent 2 */
323 #define i_size_high i_dir_acl
325 #if defined(__KERNEL__) || defined(__linux__)
326 #define i_reserved1 osd1.linux1.l_i_reserved1
327 #define i_frag osd2.linux2.l_i_frag
328 #define i_fsize osd2.linux2.l_i_fsize
329 #define i_reserved2 osd2.linux2.l_i_reserved2
333 #define i_translator osd1.hurd1.h_i_translator
334 #define i_frag osd2.hurd2.h_i_frag;
335 #define i_fsize osd2.hurd2.h_i_fsize;
336 #define i_uid_high osd2.hurd2.h_i_uid_high
337 #define i_gid_high osd2.hurd2.h_i_gid_high
338 #define i_author osd2.hurd2.h_i_author
342 #define i_reserved1 osd1.masix1.m_i_reserved1
343 #define i_frag osd2.masix2.m_i_frag
344 #define i_fsize osd2.masix2.m_i_fsize
345 #define i_reserved2 osd2.masix2.m_i_reserved2
351 #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
352 #define EXT2_ERROR_FS 0x0002 /* Errors detected */
357 #define EXT2_MOUNT_CHECK_NORMAL 0x0001 /* Do some more checks */
358 #define EXT2_MOUNT_CHECK_STRICT 0x0002 /* Do again more checks */
359 #define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
360 EXT2_MOUNT_CHECK_STRICT)
361 #define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
362 #define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
363 #define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
364 #define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
365 #define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
366 #define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
368 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
369 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
370 #define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
373 * Maximal mount counts between two filesystem checks
375 #define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
376 #define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
379 * Behaviour when detecting errors
381 #define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
382 #define EXT2_ERRORS_RO 2 /* Remount fs read-only */
383 #define EXT2_ERRORS_PANIC 3 /* Panic */
384 #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
387 * Structure of the super block
389 struct ext2_super_block {
390 __u32 s_inodes_count; /* Inodes count */
391 __u32 s_blocks_count; /* Blocks count */
392 __u32 s_r_blocks_count; /* Reserved blocks count */
393 __u32 s_free_blocks_count; /* Free blocks count */
394 __u32 s_free_inodes_count; /* Free inodes count */
395 __u32 s_first_data_block; /* First Data Block */
396 __u32 s_log_block_size; /* Block size */
397 __s32 s_log_frag_size; /* Fragment size */
398 __u32 s_blocks_per_group; /* # Blocks per group */
399 __u32 s_frags_per_group; /* # Fragments per group */
400 __u32 s_inodes_per_group; /* # Inodes per group */
401 __u32 s_mtime; /* Mount time */
402 __u32 s_wtime; /* Write time */
403 __u16 s_mnt_count; /* Mount count */
404 __s16 s_max_mnt_count; /* Maximal mount count */
405 __u16 s_magic; /* Magic signature */
406 __u16 s_state; /* File system state */
407 __u16 s_errors; /* Behaviour when detecting errors */
408 __u16 s_minor_rev_level; /* minor revision level */
409 __u32 s_lastcheck; /* time of last check */
410 __u32 s_checkinterval; /* max. time between checks */
411 __u32 s_creator_os; /* OS */
412 __u32 s_rev_level; /* Revision level */
413 __u16 s_def_resuid; /* Default uid for reserved blocks */
414 __u16 s_def_resgid; /* Default gid for reserved blocks */
416 * These fields are for EXT2_DYNAMIC_REV superblocks only.
418 * Note: the difference between the compatible feature set and
419 * the incompatible feature set is that if there is a bit set
420 * in the incompatible feature set that the kernel doesn't
421 * know about, it should refuse to mount the filesystem.
423 * e2fsck's requirements are more strict; if it doesn't know
424 * about a feature in either the compatible or incompatible
425 * feature set, it must abort and not try to meddle with
426 * things it doesn't understand...
428 __u32 s_first_ino; /* First non-reserved inode */
429 __u16 s_inode_size; /* size of inode structure */
430 __u16 s_block_group_nr; /* block group # of this superblock */
431 __u32 s_feature_compat; /* compatible feature set */
432 __u32 s_feature_incompat; /* incompatible feature set */
433 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
434 __u8 s_uuid[16]; /* 128-bit uuid for volume */
435 char s_volume_name[16]; /* volume name */
436 char s_last_mounted[64]; /* directory where last mounted */
437 __u32 s_algorithm_usage_bitmap; /* For compression */
439 * Performance hints. Directory preallocation should only
440 * happen if the EXT2_COMPAT_PREALLOC flag is on.
442 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
443 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
445 __u32 s_reserved[204]; /* Padding to the end of the block */
449 * Codes for operating systems
451 #define EXT2_OS_LINUX 0
452 #define EXT2_OS_HURD 1
453 #define EXT2_OS_MASIX 2
454 #define EXT2_OS_FREEBSD 3
455 #define EXT2_OS_LITES 4
460 #define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
461 #define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
463 #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
464 #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
466 #define EXT2_GOOD_OLD_INODE_SIZE 128
469 * Feature set definitions
472 #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
473 ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
474 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
475 ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
476 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
477 ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
479 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
481 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
482 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
483 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
485 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
486 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
488 #define EXT2_FEATURE_COMPAT_SUPP 0
489 #define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
491 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
492 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
493 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
495 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
496 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
500 * Default values for user and/or group using reserved blocks
502 #define EXT2_DEF_RESUID 0
503 #define EXT2_DEF_RESGID 0
506 * Structure of a directory entry
508 #define EXT2_NAME_LEN 255
510 struct ext2_dir_entry {
511 __u32 inode; /* Inode number */
512 __u16 rec_len; /* Directory entry length */
513 __u16 name_len; /* Name length */
514 char name[EXT2_NAME_LEN]; /* File name */
518 * The new version of the directory entry. Since EXT2 structures are
519 * stored in intel byte order, and the name_len field could never be
520 * bigger than 255 chars, it's safe to reclaim the extra byte for the
523 struct ext2_dir_entry_2 {
524 __u32 inode; /* Inode number */
525 __u16 rec_len; /* Directory entry length */
526 __u8 name_len; /* Name length */
528 char name[EXT2_NAME_LEN]; /* File name */
532 * Ext2 directory file types. Only the low 3 bits are used. The
533 * other bits are reserved for now.
535 #define EXT2_FT_UNKNOWN 0
536 #define EXT2_FT_REG_FILE 1
537 #define EXT2_FT_DIR 2
538 #define EXT2_FT_CHRDEV 3
539 #define EXT2_FT_BLKDEV 4
540 #define EXT2_FT_FIFO 5
541 #define EXT2_FT_SOCK 6
542 #define EXT2_FT_SYMLINK 7
544 #define EXT2_FT_MAX 8
547 * EXT2_DIR_PAD defines the directory entries boundaries
549 * NOTE: It must be a multiple of 4
551 #define EXT2_DIR_PAD 4
552 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
553 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
556 #endif /* _LINUX_EXT2_FS_H */