aboutsummaryrefslogtreecommitdiffstats
path: root/ext2_fs.h
blob: 5ed938fabff770120e3077e6fe05ca02736523a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#ifndef __EXT2_FS_H
#define __EXT2_FS_H

#include "types.h"

#define	EXT2_SUPER_MAGIC	0xEF53

#define EXT2_GOOD_OLD_REV       0       // The good old (original) format
#define EXT2_DYNAMIC_REV        1       // V2 format w/ dynamic inode sizes
#define EXT2_GOOD_OLD_INODE_SIZE 128

// Special inode numbers
#define	EXT2_BAD_INO		 1	// Bad blocks inode
#define EXT2_ROOT_INO		 2	// Root inode
#define EXT2_BOOT_LOADER_INO	 5	// Boot loader inode
#define EXT2_UNDEL_DIR_INO	 6	// Undelete directory inode
#define EXT3_RESIZE_INO		 7	// Reserved group descriptors inode
#define EXT3_JOURNAL_INO	 8	// Journal inode

// We're readonly, so we only care about incompat features.
#define EXT2_FEATURE_INCOMPAT_COMPRESSION	0x0001
#define EXT2_FEATURE_INCOMPAT_FILETYPE		0x0002
#define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008
#define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
#define EXT2_FEATURE_INCOMPAT_ANY		0xffffffff

#define EXT2_NDIR_BLOCKS	12
#define	EXT2_IND_BLOCK		EXT2_NDIR_BLOCKS
#define EXT2_DIND_BLOCK		(EXT2_IND_BLOCK+1)
#define	EXT2_TIND_BLOCK		(EXT2_DIND_BLOCK+1)
#define	EXT2_N_BLOCKS		(EXT2_TIND_BLOCK+1)


/* for EXT4 extent */
#define EXT4_EXT_MAGIC     0xf30a
#define EXT4_EXTENTS_FLAG  0x00080000

/*
 * File types and file modes
 */
#define S_IFDIR		0040000	        // Directory
#define S_IFCHR		0020000	        // Character device
#define S_IFBLK		0060000  	// Block device
#define S_IFREG		0100000	        // Regular file
#define S_IFIFO		0010000	        // FIFO
#define S_IFLNK		0120000 	// Symbolic link
#define S_IFSOCK	0140000       	// Socket

#define S_IFSHIFT	12

#define T_IFDIR		(S_IFDIR >> S_IFSHIFT)
#define T_IFCHR		(S_IFCHR >> S_IFSHIFT)
#define T_IFBLK		(S_IFBLK >> S_IFSHIFT)
#define T_IFREG		(S_IFREG >> S_IFSHIFT)
#define T_IFIFO		(S_IFIFO >> S_IFSHIFT)
#define T_IFLNK		(S_IFLNK >> S_IFSHIFT)
#define T_IFSOCK	(S_IFSOCK >> S_IFSHIFT)



#define ext2_group_desc_lg2size 5






/*
 * super block structure:
 * include/linux/ext2_fs.h 
 */
struct ext2_super_block 
{
	__u32 s_inodes_count;	/* Inodes count */
	__u32 s_blocks_count;	/* Blocks count */
	__u32 s_r_blocks_count;	/* Reserved blocks count */
	__u32 s_free_blocks_count;	/* Free blocks count */
	__u32 s_free_inodes_count;	/* Free inodes count */
	__u32 s_first_data_block;	/* First Data Block */
	__u32 s_log_block_size;	/* Block size */
	__u32 s_log_frag_size;	/* Fragment size */
	__u32 s_blocks_per_group;	/* # Blocks per group */
	__u32 s_frags_per_group;	/* # Fragments per group */
	__u32 s_inodes_per_group;	/* # Inodes per group */
	__u32 s_mtime;		/* Mount time */
	__u32 s_wtime;		/* Write time */
	__u16 s_mnt_count;		/* Mount count */
	__s16 s_max_mnt_count;	/* Maximal mount count */
	__u16 s_magic;		/* Magic signature */
	__u16 s_state;		/* File system state */
	__u16 s_errors;		/* Behaviour when detecting errors */
	__u16 s_minor_rev_level;
	__u32 s_lastcheck;		/* time of last check */
	__u32 s_checkinterval;	        /* max. time between checks */
	__u32 s_creator_os;		/* OS */
	__u32 s_rev_level;		/* Revision level */
	__u16 s_def_resuid;		/* Default uid for reserved blocks */
	__u16 s_def_resgid;		/* Default gid for reserved blocks */
      
        __u32 s_first_ino; 		/* First non-reserved inode */
	__u16 s_inode_size; 		/* size of inode structure */
	__u16 s_block_group_nr; 	/* block group # of this superblock */
	__u32 s_feature_compat; 	/* compatible feature set */
	__u32 s_feature_incompat; 	/* incompatible feature set */
	__u32 s_feature_ro_compat; 	/* readonly-compatible feature set */
	__u8  s_uuid[16];		/* 128-bit uuid for volume */
        char  s_volume_name[16]; 	/* volume name */
	char  s_last_mounted[64]; 	/* directory where last mounted */
	__u32 s_algorithm_usage_bitmap; /* For compression */
	__u8  s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
	__u8  s_prealloc_dir_blocks;
        __u16 s_padding1;
        __u32 s_reserved[204];   	/* Padding to the end of the block */
};

/*******************************************************************************
#ifndef DEPEND
#if ext2_super_block_size != 1024
#error ext2_super_block definition bogus
#endif
#endif
*******************************************************************************/

/*  
 *  ext2 group desc structure:
 */
struct ext2_group_desc
{
	__u32 bg_block_bitmap;	/* Blocks bitmap block */
	__u32 bg_inode_bitmap;	/* Inodes bitmap block */
	__u32 bg_inode_table;	/* Inodes table block */
	__u16 bg_free_blocks_count;	/* Free blocks count */
	__u16 bg_free_inodes_count;	/* Free inodes count */
	__u16 bg_used_dirs_count;	/* Directories count */
	__u16 bg_pad;
	__u32 bg_reserved[3];
};

/*******************************************************************************
#ifndef DEPEND
#if ext2_group_desc_size != 32
#error ext2_group_desc definition bogus
#endif
#endif
*******************************************************************************/


/*
 * ext2 inode structure:
 */
struct ext2_inode
{
	__u16 i_mode;		/* File mode */
	__u16 i_uid;		/* Owner Uid */
	__u32 i_size;		/* 4: Size in bytes */
	__u32 i_atime;		/* Access time */
	__u32 i_ctime;		/* 12: Creation time */
	__u32 i_mtime;		/* Modification time */
	__u32 i_dtime;		/* 20: Deletion Time */
	__u16 i_gid;		/* Group Id */
	__u16 i_links_count;	/* 24: Links count */
	__u32 i_blocks;		/* Blocks count */
	__u32 i_flags;		/* 32: File flags */
        __u32 l_i_reserved1;
	__u32 i_block[EXT2_N_BLOCKS];	/* 40: Pointers to blocks */
	__u32 i_version;		/* File version (for NFS) */
	__u32 i_file_acl;		/* File ACL */
	__u32 i_dir_acl;		/* Directory ACL */
	__u32 i_faddr;		/* Fragment address */
        __u8  l_i_frag;	        /* Fragment number */
        __u8  l_i_fsize;	/* Fragment size */
        __u16 i_pad1;
        __u32 l_i_reserved2[2];
};

/*******************************************************************************
#ifndef DEPEND
#if ext2_inode_size != 128
#error ext2_inode definition bogus
#endif
#endif
*******************************************************************************/


#define EXT2_NAME_LEN 255
struct ext2_dir_entry {
	unsigned int	d_inode;		/* Inode number */
	unsigned short	d_rec_len;		/* Directory entry length */
	unsigned char	d_name_len;		/* Name length */
	unsigned char	d_file_type;
	char	d_name[EXT2_NAME_LEN];	        /* File name */
};

/*******************************************************************************
#define EXT2_DIR_PAD	 4
#define EXT2_DIR_ROUND 	(EXT2_DIR_PAD - 1)
#define EXT2_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT2_DIR_ROUND) & \
					 ~EXT2_DIR_ROUND)
*******************************************************************************/






/*
 * This is the extent on-disk structure.
 * It's used at the bottom of the tree.
 */
struct ext4_extent {
	__u32	ee_block;	/* first logical block extent covers */
	__u16	ee_len;		/* number of blocks covered by extent */
	__u16	ee_start_hi;	/* high 16 bits of physical block */
	__u32	ee_start_lo;	/* low 32 bits of physical block */
};

/*
 * This is index on-disk structure.
 * It's used at all the levels except the bottom.
 */
struct ext4_extent_idx {
	__u32	ei_block;	/* index covers logical blocks from 'block' */
	__u32	ei_leaf_lo;	/* pointer to the physical block of the next *
				 * level. leaf or next index could be there */
	__u16	ei_leaf_hi;	/* high 16 bits of physical block */
	__u16	ei_unused;
};

/*
 * Each block (leaves and indexes), even inode-stored has header.
 */
struct ext4_extent_header {
	__u16	eh_magic;	/* probably will support different formats */
	__u16	eh_entries;	/* number of valid entries */
	__u16	eh_max;		/* capacity of store in entries */
	__u16	eh_depth;	/* has tree real underlying blocks? */
	__u32	eh_generation;	/* generation of the tree */
};



#define EXT4_FIRST_EXTENT(header) ( (struct ext4_extent *)(header + 1) )
#define EXT4_FIRST_INDEX(header)  ( (struct ext4_extent_idx *) (header + 1) )







/* function declartion */
/*******************************************************************************
extern struct open_file_t * ext2_read(char *);
extern int ext2_read(struct open_file_t *, char *, int);
*******************************************************************************/


#endif /* ext2_fs.h */