First version
[3rdparty/ote_partner/tlk.git] / lib / fs / ext2 / ext2_fs.h
1 /*
2  *  linux/include/linux/ext2_fs.h
3  *
4  * Copyright (C) 1992, 1993, 1994, 1995
5  * Remy Card (card@masi.ibp.fr)
6  * Laboratoire MASI - Institut Blaise Pascal
7  * Universite Pierre et Marie Curie (Paris VI)
8  *
9  *  from
10  *
11  *  linux/include/linux/minix_fs.h
12  *
13  *  Copyright (C) 1991, 1992  Linus Torvalds
14  */
15
16 #ifndef _LINUX_EXT2_FS_H
17 #define _LINUX_EXT2_FS_H
18
19 #include <sys/types.h>
20 #include <stdint.h>
21
22 //#include <linux/types.h>
23 //#include <linux/magic.h>
24
25 /*
26  * The second extended filesystem constants/structures
27  */
28
29 /*
30  * Special inode numbers
31  */
32 #define EXT2_BAD_INO             1      /* Bad blocks inode */
33 #define EXT2_ROOT_INO            2      /* Root inode */
34 #define EXT2_BOOT_LOADER_INO     5      /* Boot loader inode */
35 #define EXT2_UNDEL_DIR_INO       6      /* Undelete directory inode */
36
37 /* First non-reserved inode for old ext2 filesystems */
38 #define EXT2_GOOD_OLD_FIRST_INO 11
39
40 /*
41  * Maximal count of links to a file
42  */
43 #define EXT2_LINK_MAX           32000
44
45 /*
46  * Macro-instructions used to manage several block sizes
47  */
48 #define EXT2_MIN_BLOCK_SIZE             1024
49 #define EXT2_MAX_BLOCK_SIZE             4096
50 #define EXT2_MIN_BLOCK_LOG_SIZE           10
51 #define EXT2_BLOCK_SIZE(s)              ((uint32_t)EXT2_MIN_BLOCK_SIZE << (s).s_log_block_size)
52 #define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (uint32_t))
53 #define EXT2_BLOCK_SIZE_BITS(s) ((s).s_log_block_size + 10)
54 #define EXT2_INODE_SIZE(s)      (((s).s_rev_level == EXT2_GOOD_OLD_REV) ? \
55                                  EXT2_GOOD_OLD_INODE_SIZE : \
56                                  (s).s_inode_size)
57 #define EXT2_FIRST_INO(s)       (((s).s_rev_level == EXT2_GOOD_OLD_REV) ? \
58                                  EXT2_GOOD_OLD_FIRST_INO : \
59                                  (s).s_first_ino)
60
61 /*
62  * Macro-instructions used to manage fragments
63  */
64 #define EXT2_MIN_FRAG_SIZE              1024
65 #define EXT2_MAX_FRAG_SIZE              4096
66 #define EXT2_MIN_FRAG_LOG_SIZE            10
67 #define EXT2_FRAG_SIZE(s)               (EXT2_MIN_FRAG_SIZE << (s).s_log_frag_size)
68 #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
69
70 /*
71  * Structure of a blocks group descriptor
72  */
73 struct ext2_group_desc
74 {
75         uint32_t        bg_block_bitmap;                /* Blocks bitmap block */
76         uint32_t        bg_inode_bitmap;                /* Inodes bitmap block */
77         uint32_t        bg_inode_table;         /* Inodes table block */
78         uint16_t        bg_free_blocks_count;   /* Free blocks count */
79         uint16_t        bg_free_inodes_count;   /* Free inodes count */
80         uint16_t        bg_used_dirs_count;     /* Directories count */
81         uint16_t        bg_pad;
82         uint32_t        bg_reserved[3];
83 };
84
85 /*
86  * Macro-instructions used to manage group descriptors
87  */
88 #define EXT2_BLOCKS_PER_GROUP(s)        ((s).s_blocks_per_group)
89 #define EXT2_DESC_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
90 #define EXT2_INODES_PER_GROUP(s)        ((s).s_inodes_per_group)
91
92 /*
93  * Constants relative to the data blocks
94  */
95 #define EXT2_NDIR_BLOCKS                12
96 #define EXT2_IND_BLOCK                  EXT2_NDIR_BLOCKS
97 #define EXT2_DIND_BLOCK                 (EXT2_IND_BLOCK + 1)
98 #define EXT2_TIND_BLOCK                 (EXT2_DIND_BLOCK + 1)
99 #define EXT2_N_BLOCKS                   (EXT2_TIND_BLOCK + 1)
100
101 /*
102  * Structure of an inode on the disk
103  */
104 struct ext2_inode {
105         uint16_t        i_mode;         /* File mode */
106         uint16_t        i_uid;          /* Low 16 bits of Owner Uid */
107         uint32_t        i_size;         /* Size in bytes */
108         uint32_t        i_atime;        /* Access time */
109         uint32_t        i_ctime;        /* Creation time */
110         uint32_t        i_mtime;        /* Modification time */
111         uint32_t        i_dtime;        /* Deletion Time */
112         uint16_t        i_gid;          /* Low 16 bits of Group Id */
113         uint16_t        i_links_count;  /* Links count */
114         uint32_t        i_blocks;       /* Blocks count */
115         uint32_t        i_flags;        /* File flags */
116         union {
117                 struct {
118                         uint32_t  l_i_reserved1;
119                 } linux1;
120                 struct {
121                         uint32_t  h_i_translator;
122                 } hurd1;
123                 struct {
124                         uint32_t  m_i_reserved1;
125                 } masix1;
126         } osd1;                         /* OS dependent 1 */
127         uint32_t        i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
128         uint32_t        i_generation;   /* File version (for NFS) */
129         uint32_t        i_file_acl;     /* File ACL */
130         uint32_t        i_dir_acl;      /* Directory ACL */
131         uint32_t        i_faddr;        /* Fragment address */
132         union {
133                 struct {
134                         uint8_t l_i_frag;       /* Fragment number */
135                         uint8_t l_i_fsize;      /* Fragment size */
136                         uint16_t        i_pad1;
137                         uint16_t        l_i_uid_high;   /* these 2 fields    */
138                         uint16_t        l_i_gid_high;   /* were reserved2[0] */
139                         uint32_t        l_i_reserved2;
140                 } linux2;
141                 struct {
142                         uint8_t h_i_frag;       /* Fragment number */
143                         uint8_t h_i_fsize;      /* Fragment size */
144                         uint16_t        h_i_mode_high;
145                         uint16_t        h_i_uid_high;
146                         uint16_t        h_i_gid_high;
147                         uint32_t        h_i_author;
148                 } hurd2;
149                 struct {
150                         uint8_t m_i_frag;       /* Fragment number */
151                         uint8_t m_i_fsize;      /* Fragment size */
152                         uint16_t        m_pad1;
153                         uint32_t        m_i_reserved2[2];
154                 } masix2;
155         } osd2;                         /* OS dependent 2 */
156 };
157
158 #define i_size_high     i_dir_acl
159
160 #define i_reserved1     osd1.linux1.l_i_reserved1
161 #define i_frag          osd2.linux2.l_i_frag
162 #define i_fsize         osd2.linux2.l_i_fsize
163 #define i_uid_low       i_uid
164 #define i_gid_low       i_gid
165 #define i_uid_high      osd2.linux2.l_i_uid_high
166 #define i_gid_high      osd2.linux2.l_i_gid_high
167 #define i_reserved2     osd2.linux2.l_i_reserved2
168
169 /*
170  * File system states
171  */
172 #define EXT2_VALID_FS                   0x0001  /* Unmounted cleanly */
173 #define EXT2_ERROR_FS                   0x0002  /* Errors detected */
174
175 /*
176  * Mount flags
177  */
178 #define EXT2_MOUNT_CHECK                0x000001  /* Do mount-time checks */
179 #define EXT2_MOUNT_OLDALLOC             0x000002  /* Don't use the new Orlov allocator */
180 #define EXT2_MOUNT_GRPID                0x000004  /* Create files with directory's group */
181 #define EXT2_MOUNT_DEBUG                0x000008  /* Some debugging messages */
182 #define EXT2_MOUNT_ERRORS_CONT          0x000010  /* Continue on errors */
183 #define EXT2_MOUNT_ERRORS_RO            0x000020  /* Remount fs ro on errors */
184 #define EXT2_MOUNT_ERRORS_PANIC         0x000040  /* Panic on errors */
185 #define EXT2_MOUNT_MINIX_DF             0x000080  /* Mimics the Minix statfs */
186 #define EXT2_MOUNT_NOBH                 0x000100  /* No buffer_heads */
187 #define EXT2_MOUNT_NO_UID32             0x000200  /* Disable 32-bit UIDs */
188 #define EXT2_MOUNT_XATTR_USER           0x004000  /* Extended user attributes */
189 #define EXT2_MOUNT_POSIX_ACL            0x008000  /* POSIX Access Control Lists */
190 #define EXT2_MOUNT_XIP                  0x010000  /* Execute in place */
191 #define EXT2_MOUNT_USRQUOTA             0x020000 /* user quota */
192 #define EXT2_MOUNT_GRPQUOTA             0x040000 /* group quota */
193
194
195 #define clear_opt(o, opt)               o &= ~EXT2_MOUNT_##opt
196 #define set_opt(o, opt)                 o |= EXT2_MOUNT_##opt
197 #define test_opt(sb, opt)               (EXT2_SB(sb)->s_mount_opt & \
198                                          EXT2_MOUNT_##opt)
199 /*
200  * Maximal mount counts between two filesystem checks
201  */
202 #define EXT2_DFL_MAX_MNT_COUNT          20      /* Allow 20 mounts */
203 #define EXT2_DFL_CHECKINTERVAL          0       /* Don't use interval check */
204
205 /*
206  * Behaviour when detecting errors
207  */
208 #define EXT2_ERRORS_CONTINUE            1       /* Continue execution */
209 #define EXT2_ERRORS_RO                  2       /* Remount fs read-only */
210 #define EXT2_ERRORS_PANIC               3       /* Panic */
211 #define EXT2_ERRORS_DEFAULT             EXT2_ERRORS_CONTINUE
212
213 #define EXT2_SUPER_MAGIC    0xEF53
214 #define EXT3_SUPER_MAGIC    0xEF53
215 #define EXT4_SUPER_MAGIC    0xEF53
216
217 /*
218  * Structure of the super block
219  */
220 struct ext2_super_block {
221         uint32_t        s_inodes_count;         /* Inodes count */
222         uint32_t        s_blocks_count;         /* Blocks count */
223         uint32_t        s_r_blocks_count;       /* Reserved blocks count */
224         uint32_t        s_free_blocks_count;    /* Free blocks count */
225         uint32_t        s_free_inodes_count;    /* Free inodes count */
226         uint32_t        s_first_data_block;     /* First Data Block */
227         uint32_t        s_log_block_size;       /* Block size */
228         uint32_t        s_log_frag_size;        /* Fragment size */
229         uint32_t        s_blocks_per_group;     /* # Blocks per group */
230         uint32_t        s_frags_per_group;      /* # Fragments per group */
231         uint32_t        s_inodes_per_group;     /* # Inodes per group */
232         uint32_t        s_mtime;                /* Mount time */
233         uint32_t        s_wtime;                /* Write time */
234         uint16_t        s_mnt_count;            /* Mount count */
235         uint16_t        s_max_mnt_count;        /* Maximal mount count */
236         uint16_t        s_magic;                /* Magic signature */
237         uint16_t        s_state;                /* File system state */
238         uint16_t        s_errors;               /* Behaviour when detecting errors */
239         uint16_t        s_minor_rev_level;      /* minor revision level */
240         uint32_t        s_lastcheck;            /* time of last check */
241         uint32_t        s_checkinterval;        /* max. time between checks */
242         uint32_t        s_creator_os;           /* OS */
243         uint32_t        s_rev_level;            /* Revision level */
244         uint16_t        s_def_resuid;           /* Default uid for reserved blocks */
245         uint16_t        s_def_resgid;           /* Default gid for reserved blocks */
246         /*
247          * These fields are for EXT2_DYNAMIC_REV superblocks only.
248          *
249          * Note: the difference between the compatible feature set and
250          * the incompatible feature set is that if there is a bit set
251          * in the incompatible feature set that the kernel doesn't
252          * know about, it should refuse to mount the filesystem.
253          * 
254          * e2fsck's requirements are more strict; if it doesn't know
255          * about a feature in either the compatible or incompatible
256          * feature set, it must abort and not try to meddle with
257          * things it doesn't understand...
258          */
259         uint32_t        s_first_ino;            /* First non-reserved inode */
260         uint16_t   s_inode_size;                /* size of inode structure */
261         uint16_t        s_block_group_nr;       /* block group # of this superblock */
262         uint32_t        s_feature_compat;       /* compatible feature set */
263         uint32_t        s_feature_incompat;     /* incompatible feature set */
264         uint32_t        s_feature_ro_compat;    /* readonly-compatible feature set */
265         uint8_t s_uuid[16];             /* 128-bit uuid for volume */
266         char    s_volume_name[16];      /* volume name */
267         char    s_last_mounted[64];     /* directory where last mounted */
268         uint32_t        s_algorithm_usage_bitmap; /* For compression */
269         /*
270          * Performance hints.  Directory preallocation should only
271          * happen if the EXT2_COMPAT_PREALLOC flag is on.
272          */
273         uint8_t s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
274         uint8_t s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
275         uint16_t        s_padding1;
276         /*
277          * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
278          */
279         uint8_t s_journal_uuid[16];     /* uuid of journal superblock */
280         uint32_t        s_journal_inum;         /* inode number of journal file */
281         uint32_t        s_journal_dev;          /* device number of journal file */
282         uint32_t        s_last_orphan;          /* start of list of inodes to delete */
283         uint32_t        s_hash_seed[4];         /* HTREE hash seed */
284         uint8_t s_def_hash_version;     /* Default hash version to use */
285         uint8_t s_reserved_char_pad;
286         uint16_t        s_reserved_word_pad;
287         uint32_t        s_default_mount_opts;
288         uint32_t        s_first_meta_bg;        /* First metablock block group */
289         uint32_t        s_reserved[190];        /* Padding to the end of the block */
290 };
291
292 /*
293  * Codes for operating systems
294  */
295 #define EXT2_OS_LINUX           0
296 #define EXT2_OS_HURD            1
297 #define EXT2_OS_MASIX           2
298 #define EXT2_OS_FREEBSD         3
299 #define EXT2_OS_LITES           4
300
301 /*
302  * Revision levels
303  */
304 #define EXT2_GOOD_OLD_REV       0       /* The good old (original) format */
305 #define EXT2_DYNAMIC_REV        1       /* V2 format w/ dynamic inode sizes */
306
307 #define EXT2_CURRENT_REV        EXT2_GOOD_OLD_REV
308 #define EXT2_MAX_SUPP_REV       EXT2_DYNAMIC_REV
309
310 #define EXT2_GOOD_OLD_INODE_SIZE 128
311
312 /*
313  * Feature set definitions
314  */
315
316 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
317         ( (sb).s_feature_compat & cpu_to_le32(mask) )
318 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)                     \
319         ( (sb).s_feature_ro_compat & cpu_to_le32(mask) )
320 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
321         ( (sb).s_feature_incompat & cpu_to_le32(mask) )
322 #define EXT2_SET_COMPAT_FEATURE(sb,mask)                        \
323         (sb).s_feature_compat |= cpu_to_le32(mask)
324 #define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)                     \
325         (sb).s_feature_ro_compat |= cpu_to_le32(mask)
326 #define EXT2_SET_INCOMPAT_FEATURE(sb,mask)                      \
327         (sb).s_feature_incompat |= cpu_to_le32(mask)
328 #define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)                      \
329         (sb).s_feature_compat &= ~cpu_to_le32(mask)
330 #define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)                   \
331         (sb).s_feature_ro_compat &= ~cpu_to_le32(mask)
332 #define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)                    \
333         (sb).s_feature_incompat &= ~cpu_to_le32(mask)
334
335 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC        0x0001
336 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES       0x0002
337 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL         0x0004
338 #define EXT2_FEATURE_COMPAT_EXT_ATTR            0x0008
339 #define EXT2_FEATURE_COMPAT_RESIZE_INO          0x0010
340 #define EXT2_FEATURE_COMPAT_DIR_INDEX           0x0020
341 #define EXT2_FEATURE_COMPAT_ANY                 0xffffffff
342
343 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
344 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
345 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
346 #define EXT2_FEATURE_RO_COMPAT_ANY              0xffffffff
347
348 #define EXT2_FEATURE_INCOMPAT_COMPRESSION       0x0001
349 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
350 #define EXT3_FEATURE_INCOMPAT_RECOVER           0x0004
351 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008
352 #define EXT2_FEATURE_INCOMPAT_META_BG           0x0010
353 #define EXT2_FEATURE_INCOMPAT_ANY               0xffffffff
354
355 #define EXT2_FEATURE_COMPAT_SUPP        EXT2_FEATURE_COMPAT_EXT_ATTR
356 #define EXT2_FEATURE_INCOMPAT_SUPP      (EXT2_FEATURE_INCOMPAT_FILETYPE| \
357                                          EXT2_FEATURE_INCOMPAT_META_BG)
358 #define EXT2_FEATURE_RO_COMPAT_SUPP     (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
359                                          EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
360                                          EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
361 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED      ~EXT2_FEATURE_RO_COMPAT_SUPP
362 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED       ~EXT2_FEATURE_INCOMPAT_SUPP
363
364 /*
365  * Default values for user and/or group using reserved blocks
366  */
367 #define EXT2_DEF_RESUID         0
368 #define EXT2_DEF_RESGID         0
369
370 /*
371  * Default mount options
372  */
373 #define EXT2_DEFM_DEBUG         0x0001
374 #define EXT2_DEFM_BSDGROUPS     0x0002
375 #define EXT2_DEFM_XATTR_USER    0x0004
376 #define EXT2_DEFM_ACL           0x0008
377 #define EXT2_DEFM_UID16         0x0010
378     /* Not used by ext2, but reserved for use by ext3 */
379 #define EXT3_DEFM_JMODE         0x0060 
380 #define EXT3_DEFM_JMODE_DATA    0x0020
381 #define EXT3_DEFM_JMODE_ORDERED 0x0040
382 #define EXT3_DEFM_JMODE_WBACK   0x0060
383
384 /*
385  * Structure of a directory entry
386  */
387 #define EXT2_NAME_LEN 255
388
389 struct ext2_dir_entry {
390         uint32_t        inode;                  /* Inode number */
391         uint16_t        rec_len;                /* Directory entry length */
392         uint16_t        name_len;               /* Name length */
393         char    name[EXT2_NAME_LEN];    /* File name */
394 };
395
396 /*
397  * The new version of the directory entry.  Since EXT2 structures are
398  * stored in intel byte order, and the name_len field could never be
399  * bigger than 255 chars, it's safe to reclaim the extra byte for the
400  * file_type field.
401  */
402 struct ext2_dir_entry_2 {
403         uint32_t        inode;                  /* Inode number */
404         uint16_t        rec_len;                /* Directory entry length */
405         uint8_t name_len;               /* Name length */
406         uint8_t file_type;
407         char    name[EXT2_NAME_LEN];    /* File name */
408 };
409
410 /*
411  * Ext2 directory file types.  Only the low 3 bits are used.  The
412  * other bits are reserved for now.
413  */
414 enum {
415         EXT2_FT_UNKNOWN,
416         EXT2_FT_REG_FILE,
417         EXT2_FT_DIR,
418         EXT2_FT_CHRDEV,
419         EXT2_FT_BLKDEV,
420         EXT2_FT_FIFO,
421         EXT2_FT_SOCK,
422         EXT2_FT_SYMLINK,
423         EXT2_FT_MAX
424 };
425
426 /*
427  * EXT2_DIR_PAD defines the directory entries boundaries
428  *
429  * NOTE: It must be a multiple of 4
430  */
431 #define EXT2_DIR_PAD                    4
432 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
433 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
434                                          ~EXT2_DIR_ROUND)
435
436 #endif  /* _LINUX_EXT2_FS_H */