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