xfs: Use dprintf() for debug messages in xfs_debug()
[syslinux.git] / core / fs / ext2 / ext2_fs.h
blob8adc9bbe579bef45b61a2411e62b33ac5e857599
1 #ifndef __EXT2_FS_H
2 #define __EXT2_FS_H
4 #include <stdint.h>
6 #define EXT2_SUPER_MAGIC 0xEF53
8 #define EXT2_GOOD_OLD_REV 0 // The good old (original) format
9 #define EXT2_DYNAMIC_REV 1 // V2 format w/ dynamic inode sizes
10 #define EXT2_GOOD_OLD_INODE_SIZE 128
12 // Special inode numbers
13 #define EXT2_BAD_INO 1 // Bad blocks inode
14 #define EXT2_ROOT_INO 2 // Root inode
15 #define EXT2_BOOT_LOADER_INO 5 // Boot loader inode
16 #define EXT2_UNDEL_DIR_INO 6 // Undelete directory inode
17 #define EXT3_RESIZE_INO 7 // Reserved group descriptors inode
18 #define EXT3_JOURNAL_INO 8 // Journal inode
20 // We're readonly, so we only care about incompat features.
21 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
22 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
23 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
24 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
25 #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
26 #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
28 #define EXT2_NDIR_BLOCKS 12
29 #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
30 #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK+1)
31 #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK+1)
32 #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK+1)
35 /* for EXT4 extent */
36 #define EXT4_EXT_MAGIC 0xf30a
37 #define EXT4_EXTENTS_FLAG 0x00080000
40 * File types and file modes
42 #define S_IFDIR 0040000 // Directory
43 #define S_IFCHR 0020000 // Character device
44 #define S_IFBLK 0060000 // Block device
45 #define S_IFREG 0100000 // Regular file
46 #define S_IFIFO 0010000 // FIFO
47 #define S_IFLNK 0120000 // Symbolic link
48 #define S_IFSOCK 0140000 // Socket
50 #define S_IFSHIFT 12
52 #define T_IFDIR (S_IFDIR >> S_IFSHIFT)
53 #define T_IFCHR (S_IFCHR >> S_IFSHIFT)
54 #define T_IFBLK (S_IFBLK >> S_IFSHIFT)
55 #define T_IFREG (S_IFREG >> S_IFSHIFT)
56 #define T_IFIFO (S_IFIFO >> S_IFSHIFT)
57 #define T_IFLNK (S_IFLNK >> S_IFSHIFT)
58 #define T_IFSOCK (S_IFSOCK >> S_IFSHIFT)
61 #define ext2_group_desc_lg2size 5
66 * super block structure:
67 * include/linux/ext2_fs.h
69 struct ext2_super_block {
70 uint32_t s_inodes_count; /* Inodes count */
71 uint32_t s_blocks_count; /* Blocks count */
72 uint32_t s_r_blocks_count; /* Reserved blocks count */
73 uint32_t s_free_blocks_count; /* Free blocks count */
74 uint32_t s_free_inodes_count; /* Free inodes count */
75 uint32_t s_first_data_block; /* First Data Block */
76 uint32_t s_log_block_size; /* Block size */
77 uint32_t s_log_frag_size; /* Fragment size */
78 uint32_t s_blocks_per_group; /* # Blocks per group */
79 uint32_t s_frags_per_group; /* # Fragments per group */
80 uint32_t s_inodes_per_group; /* # Inodes per group */
81 uint32_t s_mtime; /* Mount time */
82 uint32_t s_wtime; /* Write time */
83 uint16_t s_mnt_count; /* Mount count */
84 int16_t s_max_mnt_count; /* Maximal mount count */
85 uint16_t s_magic; /* Magic signature */
86 uint16_t s_state; /* File system state */
87 uint16_t s_errors; /* Behaviour when detecting errors */
88 uint16_t s_minor_rev_level;
89 uint32_t s_lastcheck; /* time of last check */
90 uint32_t s_checkinterval; /* max. time between checks */
91 uint32_t s_creator_os; /* OS */
92 uint32_t s_rev_level; /* Revision level */
93 uint16_t s_def_resuid; /* Default uid for reserved blocks */
94 uint16_t s_def_resgid; /* Default gid for reserved blocks */
96 uint32_t s_first_ino; /* First non-reserved inode */
97 uint16_t s_inode_size; /* size of inode structure */
98 uint16_t s_block_group_nr; /* block group # of this superblock */
99 uint32_t s_feature_compat; /* compatible feature set */
100 uint32_t s_feature_incompat; /* incompatible feature set */
101 uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
102 uint8_t s_uuid[16]; /* 128-bit uuid for volume */
103 char s_volume_name[16]; /* volume name */
104 char s_last_mounted[64]; /* directory where last mounted */
105 uint32_t s_algorithm_usage_bitmap; /* For compression */
106 uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
107 uint8_t s_prealloc_dir_blocks;
108 uint16_t s_reserved_gdt_blocks; /* Per group desc for online growth */
110 * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
112 uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
113 uint32_t s_journal_inum; /* inode number of journal file */
114 uint32_t s_journal_dev; /* device number of journal file */
115 uint32_t s_last_orphan; /* start of list of inodes to delete */
116 uint32_t s_hash_seed[4]; /* HTREE hash seed */
117 uint8_t s_def_hash_version; /* Default hash version to use */
118 uint8_t s_reserved_char_pad;
119 uint16_t s_desc_size; /* size of group descriptor */
120 uint32_t s_default_mount_opts;
121 uint32_t s_first_meta_bg; /* First metablock block group */
122 uint32_t s_mkfs_time; /* When the filesystem was created */
123 uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */
124 /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
125 uint32_t s_blocks_count_hi; /* Blocks count */
126 uint32_t s_r_blocks_count_hi; /* Reserved blocks count */
127 uint32_t s_free_blocks_count_hi;/* Free blocks count */
128 uint16_t s_min_extra_isize; /* All inodes have at least # bytes */
129 uint16_t s_want_extra_isize; /* New inodes should reserve # bytes */
130 uint32_t s_flags; /* Miscellaneous flags */
131 uint16_t s_raid_stride; /* RAID stride */
132 uint16_t s_mmp_interval; /* # seconds to wait in MMP checking */
133 uint64_t s_mmp_block; /* Block for multi-mount protection */
134 uint32_t s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
135 uint8_t s_log_groups_per_flex; /* FLEX_BG group size */
136 uint8_t s_reserved_char_pad2;
137 uint16_t s_reserved_pad;
138 uint32_t s_reserved[162]; /* Padding to the end of the block */
141 /*******************************************************************************
142 #ifndef DEPEND
143 #if ext2_super_block_size != 1024
144 #error ext2_super_block definition bogus
145 #endif
146 #endif
147 *******************************************************************************/
150 * ext2 group desc structure:
152 struct ext2_group_desc {
153 uint32_t bg_block_bitmap; /* Blocks bitmap block */
154 uint32_t bg_inode_bitmap; /* Inodes bitmap block */
155 uint32_t bg_inode_table; /* Inodes table block */
156 uint16_t bg_free_blocks_count; /* Free blocks count */
157 uint16_t bg_free_inodes_count; /* Free inodes count */
158 uint16_t bg_used_dirs_count; /* Directories count */
159 uint16_t bg_pad;
160 uint32_t bg_reserved[3];
163 /*******************************************************************************
164 #ifndef DEPEND
165 #if ext2_group_desc_size != 32
166 #error ext2_group_desc definition bogus
167 #endif
168 #endif
169 *******************************************************************************/
173 * ext2 inode structure:
175 struct ext2_inode {
176 uint16_t i_mode; /* File mode */
177 uint16_t i_uid; /* Owner Uid */
178 uint32_t i_size; /* 4: Size in bytes */
179 uint32_t i_atime; /* Access time */
180 uint32_t i_ctime; /* 12: Creation time */
181 uint32_t i_mtime; /* Modification time */
182 uint32_t i_dtime; /* 20: Deletion Time */
183 uint16_t i_gid; /* Group Id */
184 uint16_t i_links_count; /* 24: Links count */
185 uint32_t i_blocks; /* Blocks count */
186 uint32_t i_flags; /* 32: File flags */
187 uint32_t l_i_reserved1;
188 uint32_t i_block[EXT2_N_BLOCKS]; /* 40: Pointers to blocks */
189 uint32_t i_version; /* File version (for NFS) */
190 uint32_t i_file_acl; /* File ACL */
191 uint32_t i_dir_acl; /* Directory ACL */
192 uint32_t i_faddr; /* Fragment address */
193 uint8_t l_i_frag; /* Fragment number */
194 uint8_t l_i_fsize; /* Fragment size */
195 uint16_t i_pad1;
196 uint32_t l_i_reserved2[2];
199 /*******************************************************************************
200 #ifndef DEPEND
201 #if ext2_inode_size != 128
202 #error ext2_inode definition bogus
203 #endif
204 #endif
205 *******************************************************************************/
208 #define EXT2_NAME_LEN 255
209 struct ext2_dir_entry {
210 unsigned int d_inode; /* Inode number */
211 unsigned short d_rec_len; /* Directory entry length */
212 unsigned char d_name_len; /* Name length */
213 unsigned char d_file_type;
214 char d_name[EXT2_NAME_LEN]; /* File name */
217 /*******************************************************************************
218 #define EXT2_DIR_PAD 4
219 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
220 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
221 ~EXT2_DIR_ROUND)
222 *******************************************************************************/
230 * This is the extent on-disk structure.
231 * It's used at the bottom of the tree.
233 struct ext4_extent {
234 uint32_t ee_block; /* first logical block extent covers */
235 uint16_t ee_len; /* number of blocks covered by extent */
236 uint16_t ee_start_hi; /* high 16 bits of physical block */
237 uint32_t ee_start_lo; /* low 32 bits of physical block */
241 * This is index on-disk structure.
242 * It's used at all the levels except the bottom.
244 struct ext4_extent_idx {
245 uint32_t ei_block; /* index covers logical blocks from 'block' */
246 uint32_t ei_leaf_lo; /* pointer to the physical block of the next *
247 * level. leaf or next index could be there */
248 uint16_t ei_leaf_hi; /* high 16 bits of physical block */
249 uint16_t ei_unused;
253 * Each block (leaves and indexes), even inode-stored has header.
255 struct ext4_extent_header {
256 uint16_t eh_magic; /* probably will support different formats */
257 uint16_t eh_entries; /* number of valid entries */
258 uint16_t eh_max; /* capacity of store in entries */
259 uint16_t eh_depth; /* has tree real underlying blocks? */
260 uint32_t eh_generation; /* generation of the tree */
265 #define EXT4_FIRST_EXTENT(header) ( (struct ext4_extent *)(header + 1) )
266 #define EXT4_FIRST_INDEX(header) ( (struct ext4_extent_idx *) (header + 1) )
270 * The ext2 super block information in memory
272 struct ext2_sb_info {
273 uint32_t s_inodes_per_block;/* Number of inodes per block */
274 uint32_t s_inodes_per_group;/* Number of inodes in a group */
275 uint32_t s_blocks_per_group;/* Number of blocks in a group */
276 uint32_t s_desc_per_block; /* Number of group descriptors per block */
277 uint32_t s_groups_count; /* Number of groups in the fs */
278 uint32_t s_first_data_block; /* First Data Block */
279 int s_inode_size;
282 static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs)
284 return fs->fs_info;
287 #define EXT2_BLOCKS_PER_GROUP(fs) (EXT2_SB(fs)->s_blocks_per_group)
288 #define EXT2_INODES_PER_GROUP(fs) (EXT2_SB(fs)->s_inodes_per_group)
289 #define EXT2_INODES_PER_BLOCK(fs) (EXT2_SB(fs)->s_inodes_per_block)
290 #define EXT2_DESC_PER_BLOCK(fs) (EXT2_SB(fs)->s_desc_per_block)
293 * ext2 private inode information
295 struct ext2_pvt_inode {
296 union {
297 uint32_t i_block[EXT2_N_BLOCKS];
298 struct ext4_extent_header i_extent_hdr;
302 #define PVT(i) ((struct ext2_pvt_inode *)((i)->pvt))
305 * functions
307 block_t ext2_bmap(struct inode *, block_t, size_t *);
308 int ext2_next_extent(struct inode *, uint32_t);
310 #endif /* ext2_fs.h */