File: e2lib.h

package info (click to toggle)
aboot 0.9b-3%2Betchnhalf.1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 980 kB
  • ctags: 1,656
  • sloc: ansic: 8,975; perl: 738; makefile: 382; asm: 309; sh: 3
file content (332 lines) | stat: -rw-r--r-- 10,661 bytes parent folder | download | duplicates (7)
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#ifndef EXT2_LIB_H
#define EXT2_LIB_H

#include <fcntl.h>


/* Definitions cribbed from ext2_fs.h, modified so's to be 64-bit clean
 * when cross-compiling on Alpha
 */

/*
 * The second extended filesystem constants/structures
 */

/*
 * Define EXT2FS_DEBUG to produce debug messages
 */
#undef EXT2FS_DEBUG

/*
 * Define EXT2FS_DEBUG_CACHE to produce cache debug messages
 */
#undef EXT2FS_DEBUG_CACHE

/*
 * Define EXT2FS_CHECK_CACHE to add some checks to the name cache code
 */
#undef EXT2FS_CHECK_CACHE

/*
 * Define EXT2FS_PRE_02B_COMPAT to convert ext 2 fs prior to 0.2b
 */
#undef EXT2FS_PRE_02B_COMPAT

/*
 * Define DONT_USE_DCACHE to inhibit the directory cache
 */
#define DONT_USE_DCACHE

/*
 * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
 */
#define EXT2_PREALLOCATE

/*
 * The second extended file system version
 */
#define EXT2FS_DATE		"94/03/10"
#define EXT2FS_VERSION		"0.5"


/*
 * Special inodes numbers
 */
#define	EXT2_BAD_INO		 1	/* Bad blocks inode */
#define EXT2_ROOT_INO		 2	/* Root inode */
#define EXT2_ACL_IDX_INO	 3	/* ACL inode */
#define EXT2_ACL_DATA_INO	 4	/* ACL inode */
#define EXT2_BOOT_LOADER_INO	 5	/* Boot loader inode */
#define EXT2_UNDEL_DIR_INO	 6	/* Undelete directory inode */
#define EXT2_FIRST_INO		11	/* First non reserved inode */

/*
 * The second extended file system magic number
 */
#define EXT2_PRE_02B_MAGIC	0xEF51
#define EXT2_SUPER_MAGIC	0xEF53
#define EXT2_SUPER_BIGMAGIC	0x53EF	/* Accessing on big-endian system... */

/*
 * Maximal count of links to a file
 */
#define EXT2_LINK_MAX		32000

/*
 * Macro-instructions used to manage several block sizes
 */
#define EXT2_MIN_BLOCK_SIZE		1024
#define	EXT2_MAX_BLOCK_SIZE		4096
#define EXT2_MIN_BLOCK_LOG_SIZE		  10
# define EXT2_BLOCK_SIZE(s)		(EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
#define EXT2_ACLE_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
#define	EXT2_ADDR_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof (unsigned int))
# define EXT2_BLOCK_SIZE_BITS(s)	((s)->s_log_block_size + 10)
#define	EXT2_INODES_PER_BLOCK(s)	(EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))

/*
 * Macro-instructions used to manage fragments
 */
#define EXT2_MIN_FRAG_SIZE		1024
#define	EXT2_MAX_FRAG_SIZE		4096
#define EXT2_MIN_FRAG_LOG_SIZE		  10
# define EXT2_FRAG_SIZE(s)		(EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
# define EXT2_FRAGS_PER_BLOCK(s)	(EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))

/*
 * ACL structures
 */
struct ext2_acl_header	/* Header of Access Control Lists */
{
	unsigned int aclh_size;
	unsigned int aclh_file_count;
	unsigned int aclh_acle_count;
	unsigned int aclh_first_acle;
};

struct ext2_acl_entry	/* Access Control List Entry */
{
	unsigned int  acle_size;
	unsigned short acle_perms;	/* Access permissions */
	unsigned short acle_type;	/* Type of entry */
	unsigned short acle_tag;	/* User or group identity */
	unsigned short acle_pad1;
	unsigned int  acle_next;	/* Pointer on next entry for the */
					/* same inode or on next free entry */
};

/*
 * Structure of a blocks group descriptor
 */
struct ext2_old_group_desc
{
	unsigned int  bg_block_bitmap;		/* Blocks bitmap block */
	unsigned int  bg_inode_bitmap;		/* Inodes bitmap block */
	unsigned int  bg_inode_table;		/* Inodes table block */
	unsigned short bg_free_blocks_count;	/* Free blocks count */
	unsigned short bg_free_inodes_count;	/* Free inodes count */
};

struct ext2_group_desc
{
	unsigned int  bg_block_bitmap;		/* Blocks bitmap block */
	unsigned int  bg_inode_bitmap;		/* Inodes bitmap block */
	unsigned int  bg_inode_table;		/* Inodes table block */
	unsigned short bg_free_blocks_count;	/* Free blocks count */
	unsigned short bg_free_inodes_count;	/* Free inodes count */
	unsigned short bg_used_dirs_count;	/* Directories count */
	unsigned short bg_pad;
	unsigned int  bg_reserved[3];
};

/*
 * Macro-instructions used to manage group descriptors
 */
# define EXT2_BLOCKS_PER_GROUP(s)	((s)->s_blocks_per_group)
# define EXT2_DESC_PER_BLOCK(s)		(EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
# define EXT2_INODES_PER_GROUP(s)	((s)->s_inodes_per_group)

/*
 * Constants relative to the data blocks
 */
#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)

/*
 * Inode flags
 */
#define	EXT2_SECRM_FL			0x0001	/* Secure deletion */
#define	EXT2_UNRM_FL			0x0002	/* Undelete */
#define	EXT2_COMPR_FL			0x0004	/* Compress file */
#define EXT2_SYNC_FL			0x0008	/* Synchronous updates */

/*
 * ioctl commands
 */
#define	EXT2_IOC_GETFLAGS		_IOR('f', 1, int)
#define	EXT2_IOC_SETFLAGS		_IOW('f', 2, int)
#define	EXT2_IOC_GETVERSION		_IOR('v', 1, int)
#define	EXT2_IOC_SETVERSION		_IOW('v', 2, int)

/*
 * Structure of an inode on the disk
 */
struct ext2_inode {
	unsigned short i_mode;		/* File mode */
	unsigned short i_uid;		/* Owner Uid */
	unsigned int  i_size;		/* Size in bytes */
	unsigned int  i_atime;		/* Access time */
	unsigned int  i_ctime;		/* Creation time */
	unsigned int  i_mtime;		/* Modification time */
	unsigned int  i_dtime;		/* Deletion Time */
	unsigned short i_gid;		/* Group Id */
	unsigned short i_links_count;	/* Links count */
	unsigned int  i_blocks;	/* Blocks count */
	unsigned int  i_flags;		/* File flags */
	unsigned int  i_reserved1;
	unsigned int  i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
	unsigned int  i_version;	/* File version (for NFS) */
	unsigned int  i_file_acl;	/* File ACL */
	unsigned int  i_dir_acl;	/* Directory ACL */
	unsigned int  i_faddr;		/* Fragment address */
	unsigned char  i_frag;		/* Fragment number */
	unsigned char  i_fsize;		/* Fragment size */
	unsigned short i_pad1;
	unsigned int  i_reserved2[2];
};

/*
 * File system states
 */
#define	EXT2_VALID_FS			0x0001	/* Unmounted cleany */
#define	EXT2_ERROR_FS			0x0002	/* Errors detected */

/*
 * Mount flags
 */
#define EXT2_MOUNT_CHECK_NORMAL		0x0001	/* Do some more checks */
#define EXT2_MOUNT_CHECK_STRICT		0x0002	/* Do again more checks */
#define EXT2_MOUNT_CHECK		(EXT2_MOUNT_CHECK_NORMAL | \
					 EXT2_MOUNT_CHECK_STRICT)
#define EXT2_MOUNT_GRPID		0x0004	/* Create files with directory's group */
#define EXT2_MOUNT_DEBUG		0x0008	/* Some debugging messages */
#define EXT2_MOUNT_ERRORS_CONT		0x0010	/* Continue on errors */
#define EXT2_MOUNT_ERRORS_RO		0x0020	/* Remount fs ro on errors */
#define EXT2_MOUNT_ERRORS_PANIC		0x0040	/* Panic on errors */

#define clear_opt(o, opt)		o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt)			o |= EXT2_MOUNT_##opt
#define test_opt(sb, opt)		((sb)->u.ext2_sb.s_mount_opt & \
					 EXT2_MOUNT_##opt)
/*
 * Maximal mount counts between two filesystem checks
 */
#define EXT2_DFL_MAX_MNT_COUNT		20	/* Allow 20 mounts */
#define EXT2_DFL_CHECKINTERVAL		0	/* Don't use interval check */

/*
 * Behaviour when detecting errors
 */
#define EXT2_ERRORS_CONTINUE		1	/* Continue execution */
#define EXT2_ERRORS_RO			2	/* Remount fs read-only */
#define EXT2_ERRORS_PANIC		3	/* Panic */
#define EXT2_ERRORS_DEFAULT		EXT2_ERRORS_CONTINUE

/*
 * Structure of the super block
 */
struct ext2_super_block {
	unsigned int  s_inodes_count;	/* 0: Inodes count */
	unsigned int  s_blocks_count;	/* 4: Blocks count */
	unsigned int  s_r_blocks_count;/* 8: Reserved blocks count */
	unsigned int  s_free_blocks_count;/* 12: Free blocks count */
	unsigned int  s_free_inodes_count;/* 16: Free inodes count */
	unsigned int  s_first_data_block;/* 20: First Data Block */
	unsigned int  s_log_block_size;/* 24: Block size */
	int           s_log_frag_size;	/* 28: Fragment size */
	unsigned int  s_blocks_per_group;/* 32: # Blocks per group */
	unsigned int  s_frags_per_group;/* 36: # Fragments per group */
	unsigned int  s_inodes_per_group;/* 40: # Inodes per group */
	unsigned int  s_mtime;		/* 44: Mount time */
	unsigned int  s_wtime;		/* 48: Write time */
	unsigned short s_mnt_count;	/* 52: Mount count */
	short          s_max_mnt_count;	/* 54: Maximal mount count */
	unsigned short s_magic;		/* 56: Magic signature */
	unsigned short s_state;		/* 58: File system state */
	unsigned short s_errors;	/* 60: Behaviour when detecting errors */
	unsigned short s_pad;		/* 62: */
	unsigned int  s_lastcheck;	/* 64: time of last check */
	unsigned int  s_checkinterval;	/* 68: max. time between checks */
	unsigned int  s_reserved[238];	/* 72: Padding to the end of the block */
};

/*
 * Structure of a directory entry
 */
#define EXT2_NAME_LEN 255

struct ext2_dir_entry {
	unsigned int  inode;			/* Inode number */
	unsigned short rec_len;			/* Directory entry length */
	unsigned short name_len;		/* Name length */
	char           name[EXT2_NAME_LEN];	/* File name */
};

/*
 * EXT2_DIR_PAD defines the directory entries boundaries
 *
 * NOTE: It must be a multiple of 4
 */
#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)


/* These definitions are cribbed from other file system include files, so that
 * we can take a stab at identifying non-ext2 file systems as well...
 */
/*
 * minix super-block data on disk
 */
struct minix_super_block {
        unsigned short s_ninodes;
        unsigned short s_nzones;
        unsigned short s_imap_blocks;
        unsigned short s_zmap_blocks;
        unsigned short s_firstdatazone;
        unsigned short s_log_zone_size;
        unsigned int s_max_size;
        unsigned short s_magic;
        unsigned short s_state;
};

#define MINIX_SUPER_MAGIC       0x137F          /* original minix fs */
#define MINIX_SUPER_MAGIC2      0x138F          /* minix fs, 30 char names */
#define NEW_MINIX_SUPER_MAGIC   0x2468          /* minix V2 - not implemented */

extern int 			ext2_init(char * name, int access);
extern void 			ext2_close();
extern struct ext2_inode *	ext2_iget(int ino);
extern void 			ext2_iput(struct ext2_inode *ip);
extern int			ext2_balloc(void);
extern int			ext2_ialloc(void);
extern int			ext2_blocksize(void);
extern int			ext2_blkno(struct ext2_inode *ip, int blkoff,
					   int allocate);
extern void			ext2_bread(struct ext2_inode *ip, int blkno,
					   char * buffer);
extern void			ext2_bwrite(struct ext2_inode *ip, int blkno,
					    char * buffer);
extern struct ext2_inode *	ext2_namei(char * name);
extern void			ext2_truncate(struct ext2_inode *ip);
extern void			ext2_mknod(struct ext2_inode *dip,
					   char * name, int ino);
extern int			ext2_fill_contiguous(struct ext2_inode * ip,
						     int nblocks);
extern void			ext2_write_bootblock(char *bb);

#endif /* EXT2_LIB_H */