xref: /minix3/minix/fs/ext2/const.h (revision 970d95ecd592b97088f82dd45b0c93a10fc1d1c4)
1 #ifndef EXT2_CONST_H
2 #define EXT2_CONST_H
3 
4 /* Tables sizes */
5 
6 #define NR_INODES        512    /* # slots in "in core" inode table;
7 				 * should be more or less the same as
8 				 * NR_VNODES in vfs
9 				 */
10 #define GETDENTS_BUFSIZ  257
11 
12 #define INODE_HASH_LOG2   7     /* 2 based logarithm of the inode hash size */
13 #define INODE_HASH_SIZE   ((unsigned long)1<<INODE_HASH_LOG2)
14 #define INODE_HASH_MASK   (((unsigned long)1<<INODE_HASH_LOG2)-1)
15 
16 #define SUPER_MAGIC   0xEF53  /* magic number contained in super-block */
17 
18 #define EXT2_NAME_MAX	255
19 
20 /* Miscellaneous constants */
21 #define SU_UID          ((uid_t) 0)     /* super_user's uid_t */
22 #define NORMAL          0               /* forces get_block to do disk read */
23 #define NO_READ         1       /* prevents get_block from doing disk read */
24 #define PREFETCH        2       /* tells get_block not to read or mark dev */
25 
26 #define NO_BIT   ((bit_t) 0)    /* returned by alloc_bit() to signal failure */
27 
28 #define LOOK_UP            0 /* tells search_dir to lookup string */
29 #define ENTER              1 /* tells search_dir to make dir entry */
30 #define DELETE             2 /* tells search_dir to delete entry */
31 #define IS_EMPTY           3 /* tells search_dir to ret. OK or ENOTEMPTY */
32 
33 /* write_map() args */
34 #define WMAP_FREE           (1 << 0)
35 
36 #define IN_CLEAN              0    /* inode disk and memory copies identical */
37 #define IN_DIRTY              1    /* inode disk and memory copies differ */
38 #define ATIME            002    /* set if atime field needs updating */
39 #define CTIME            004    /* set if ctime field needs updating */
40 #define MTIME            010    /* set if mtime field needs updating */
41 
42 #define SUPER_BLOCK_BYTES       (1024)         /* bytes offset */
43 
44 #define ROOT_INODE      ((ino_t) 2)   /* inode number for root directory */
45 #define BOOT_BLOCK      ((block_t) 0) /* block number of boot block */
46 #define START_BLOCK     ((block_t) 2) /* first block of FS (not counting SB) */
47 #define BLOCK_ADDRESS_BYTES	4     /* bytes per address */
48 
49 #define SUPER_SIZE      sizeof (struct super_block) /* sb size in RAM */
50 #define SUPER_SIZE_D    (1024)  /* max size of superblock stored on disk */
51 
52 /* Directories related macroses */
53 
54 #define DIR_ENTRY_ALIGN         4
55 
56 /* ino + rec_len + name_len + file_type, doesn't include name and padding */
57 #define MIN_DIR_ENTRY_SIZE	8
58 
59 #define DIR_ENTRY_CONTENTS_SIZE(d) (MIN_DIR_ENTRY_SIZE + (d)->d_name_len)
60 
61 /* size with padding */
62 #define DIR_ENTRY_ACTUAL_SIZE(d) (DIR_ENTRY_CONTENTS_SIZE(d) + \
63         ((DIR_ENTRY_CONTENTS_SIZE(d) & 0x03) == 0 ? 0 : \
64 			DIR_ENTRY_ALIGN - (DIR_ENTRY_CONTENTS_SIZE(d) & 0x03) ))
65 
66 /* How many bytes can be taken from the end of dentry */
67 #define DIR_ENTRY_SHRINK(d)    (conv2(le_CPU, (d)->d_rec_len) \
68 					- DIR_ENTRY_ACTUAL_SIZE(d))
69 
70 /* Dentry can have padding, which can be used to enlarge namelen */
71 #define DIR_ENTRY_MAX_NAME_LEN(d)	(conv2(le_CPU, (d)->d_rec_len) \
72 						- MIN_DIR_ENTRY_SIZE)
73 
74 /* Constants relative to the data blocks */
75 /* When change EXT2_NDIR_BLOCKS, modify ext2_max_size()!!!*/
76 #define EXT2_NDIR_BLOCKS        12
77 #define EXT2_IND_BLOCK          EXT2_NDIR_BLOCKS
78 #define EXT2_DIND_BLOCK         (EXT2_IND_BLOCK + 1)
79 #define EXT2_TIND_BLOCK         (EXT2_DIND_BLOCK + 1)
80 #define EXT2_N_BLOCKS           (EXT2_TIND_BLOCK + 1)
81 
82 #define FS_BITMAP_CHUNKS(b) ((b)/sizeof (bitchunk_t))/* # map chunks/blk   */
83 #define FS_BITCHUNK_BITS        (sizeof(bitchunk_t) * CHAR_BIT)
84 #define FS_BITS_PER_BLOCK(b)    (FS_BITMAP_CHUNKS(b) * FS_BITCHUNK_BITS)
85 
86 /* Inodes */
87 
88 /* Next 4 following macroses were taken from linux' ext2_fs.h */
89 #define EXT2_GOOD_OLD_INODE_SIZE	128
90 #define EXT2_GOOD_OLD_FIRST_INO		11
91 
92 #define EXT2_INODE_SIZE(s)	(((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
93 				EXT2_GOOD_OLD_INODE_SIZE : \
94 							(s)->s_inode_size)
95 #define EXT2_FIRST_INO(s)	(((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
96 				EXT2_GOOD_OLD_FIRST_INO : \
97 							(s)->s_first_ino)
98 
99 /* Maximum size of a fast symlink including trailing '\0' */
100 #define MAX_FAST_SYMLINK_LENGTH \
101 	( sizeof(((d_inode *)0)->i_block[0]) * EXT2_N_BLOCKS )
102 
103 /* FS states */
104 #define EXT2_VALID_FS                   0x0001  /* Cleanly unmounted */
105 #define EXT2_ERROR_FS                   0x0002  /* Errors detected */
106 
107 #define EXT2_GOOD_OLD_REV       0       /* The good old (original) format */
108 #define EXT2_DYNAMIC_REV        1       /* V2 format w/ dynamic inode sizes */
109 
110 /* ext2 features, names shorted (cut EXT2_ prefix) */
111 #define COMPAT_DIR_PREALLOC        0x0001
112 #define COMPAT_IMAGIC_INODES       0x0002
113 #define COMPAT_HAS_JOURNAL         0x0004
114 #define COMPAT_EXT_ATTR            0x0008
115 #define COMPAT_RESIZE_INO          0x0010
116 #define COMPAT_DIR_INDEX           0x0020
117 #define COMPAT_ANY                 0xffffffff
118 
119 #define RO_COMPAT_SPARSE_SUPER     0x0001
120 #define RO_COMPAT_LARGE_FILE       0x0002
121 #define RO_COMPAT_BTREE_DIR        0x0004
122 #define RO_COMPAT_ANY              0xffffffff
123 
124 #define INCOMPAT_COMPRESSION       0x0001
125 #define INCOMPAT_FILETYPE          0x0002
126 #define INCOMPAT_RECOVER           0x0004
127 #define INCOMPAT_JOURNAL_DEV       0x0008
128 #define INCOMPAT_META_BG           0x0010
129 #define INCOMPAT_ANY               0xffffffff
130 
131 /* What do we support? */
132 #define SUPPORTED_INCOMPAT_FEATURES	(INCOMPAT_FILETYPE)
133 #define SUPPORTED_RO_COMPAT_FEATURES	(RO_COMPAT_SPARSE_SUPER | \
134 					 RO_COMPAT_LARGE_FILE)
135 
136 /* Ext2 directory file types. Only the low 3 bits are used.
137  * The other bits are reserved for now.
138  */
139 #define EXT2_FT_UNKNOWN         0
140 #define EXT2_FT_REG_FILE        1
141 #define EXT2_FT_DIR             2
142 #define EXT2_FT_CHRDEV          3
143 #define EXT2_FT_BLKDEV          4
144 #define EXT2_FT_FIFO            5
145 #define EXT2_FT_SOCK            6
146 #define EXT2_FT_SYMLINK         7
147 
148 #define EXT2_FT_MAX             8
149 
150 #define HAS_COMPAT_FEATURE(sp, mask)                        \
151         ( (sp)->s_feature_compat & (mask) )
152 #define HAS_RO_COMPAT_FEATURE(sp, mask)                     \
153 	( (sp)->s_feature_ro_compat & (mask) )
154 #define HAS_INCOMPAT_FEATURE(sp, mask)                      \
155 	( (sp)->s_feature_incompat & (mask) )
156 
157 
158 /* hash-indexed directory */
159 #define EXT2_INDEX_FL			0x00001000
160 /* Top of directory hierarchies*/
161 #define EXT2_TOPDIR_FL                  0x00020000
162 
163 #define EXT2_PREALLOC_BLOCKS		8
164 
165 
166 #endif /* EXT2_CONST_H */
167