1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #ifndef _LINUX_EXT2_FS_H
17 #define _LINUX_EXT2_FS_H
18
19 #include <linux/types.h>
20
21
22
23
24
25
26
27
28 #undef EXT2FS_DEBUG
29
30
31
32
33 #define EXT2_PREALLOCATE
34
35
36
37
38 #define EXT2FS_DATE "95/08/09"
39 #define EXT2FS_VERSION "0.5b"
40
41
42
43
44 #ifdef EXT2FS_DEBUG
45 # define ext2_debug(f, a...) { \
46 printk ("EXT2-fs DEBUG (%s, %d): %s:", \
47 __FILE__, __LINE__, __FUNCTION__); \
48 printk (f, ## a); \
49 }
50 #else
51 # define ext2_debug(f, a...)
52 #endif
53
54
55
56
57 #define EXT2_BAD_INO 1
58 #define EXT2_ROOT_INO 2
59 #define EXT2_ACL_IDX_INO 3
60 #define EXT2_ACL_DATA_INO 4
61 #define EXT2_BOOT_LOADER_INO 5
62 #define EXT2_UNDEL_DIR_INO 6
63 #define EXT2_FIRST_INO 11
64
65
66
67
68 #define EXT2_SUPER_MAGIC 0xEF53
69
70
71
72
73 #define EXT2_LINK_MAX 32000
74
75
76
77
78 #define EXT2_MIN_BLOCK_SIZE 1024
79 #define EXT2_MAX_BLOCK_SIZE 4096
80 #define EXT2_MIN_BLOCK_LOG_SIZE 10
81 #ifdef __KERNEL__
82 # define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
83 #else
84 # define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
85 #endif
86 #define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
87 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
88 #ifdef __KERNEL__
89 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
90 #else
91 # define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
92 #endif
93 #define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))
94 #ifdef __KERNEL__
95 #define EXT2_ADDR_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_addr_per_block_bits)
96 #define EXT2_INODES_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_inodes_per_block_bits)
97 #endif
98
99
100
101
102 #define EXT2_MIN_FRAG_SIZE 1024
103 #define EXT2_MAX_FRAG_SIZE 4096
104 #define EXT2_MIN_FRAG_LOG_SIZE 10
105 #ifdef __KERNEL__
106 # define EXT2_FRAG_SIZE(s) ((s)->u.ext2_sb.s_frag_size)
107 # define EXT2_FRAGS_PER_BLOCK(s) ((s)->u.ext2_sb.s_frags_per_block)
108 #else
109 # define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
110 # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
111 #endif
112
113
114
115
116 struct ext2_acl_header
117 {
118 __u32 aclh_size;
119 __u32 aclh_file_count;
120 __u32 aclh_acle_count;
121 __u32 aclh_first_acle;
122 };
123
124 struct ext2_acl_entry
125 {
126 __u32 acle_size;
127 __u16 acle_perms;
128 __u16 acle_type;
129 __u16 acle_tag;
130 __u16 acle_pad1;
131 __u32 acle_next;
132
133 };
134
135
136
137
138 struct ext2_group_desc
139 {
140 __u32 bg_block_bitmap;
141 __u32 bg_inode_bitmap;
142 __u32 bg_inode_table;
143 __u16 bg_free_blocks_count;
144 __u16 bg_free_inodes_count;
145 __u16 bg_used_dirs_count;
146 __u16 bg_pad;
147 __u32 bg_reserved[3];
148 };
149
150
151
152
153 #ifdef __KERNEL__
154 # define EXT2_BLOCKS_PER_GROUP(s) ((s)->u.ext2_sb.s_blocks_per_group)
155 # define EXT2_DESC_PER_BLOCK(s) ((s)->u.ext2_sb.s_desc_per_block)
156 # define EXT2_INODES_PER_GROUP(s) ((s)->u.ext2_sb.s_inodes_per_group)
157 # define EXT2_DESC_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_desc_per_block_bits)
158 #else
159 # define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
160 # define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
161 # define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
162 #endif
163
164
165
166
167 #define EXT2_NDIR_BLOCKS 12
168 #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
169 #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
170 #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
171 #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
172
173
174
175
176 #define EXT2_SECRM_FL 0x00000001
177 #define EXT2_UNRM_FL 0x00000002
178 #define EXT2_COMPR_FL 0x00000004
179 #define EXT2_SYNC_FL 0x00000008
180 #define EXT2_IMMUTABLE_FL 0x00000010
181 #define EXT2_APPEND_FL 0x00000020
182 #define EXT2_NODUMP_FL 0x00000040
183
184
185
186
187 #define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
188 #define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
189 #define EXT2_IOC_GETVERSION _IOR('v', 1, long)
190 #define EXT2_IOC_SETVERSION _IOW('v', 2, long)
191
192
193
194
195 struct ext2_inode {
196 __u16 i_mode;
197 __u16 i_uid;
198 __u32 i_size;
199 __u32 i_atime;
200 __u32 i_ctime;
201 __u32 i_mtime;
202 __u32 i_dtime;
203 __u16 i_gid;
204 __u16 i_links_count;
205 __u32 i_blocks;
206 __u32 i_flags;
207 union {
208 struct {
209 __u32 l_i_reserved1;
210 } linux1;
211 struct {
212 __u32 h_i_translator;
213 } hurd1;
214 struct {
215 __u32 m_i_reserved1;
216 } masix1;
217 } osd1;
218 __u32 i_block[EXT2_N_BLOCKS];
219 __u32 i_version;
220 __u32 i_file_acl;
221 __u32 i_dir_acl;
222 __u32 i_faddr;
223 union {
224 struct {
225 __u8 l_i_frag;
226 __u8 l_i_fsize;
227 __u16 i_pad1;
228 __u32 l_i_reserved2[2];
229 } linux2;
230 struct {
231 __u8 h_i_frag;
232 __u8 h_i_fsize;
233 __u16 h_i_mode_high;
234 __u16 h_i_uid_high;
235 __u16 h_i_gid_high;
236 __u32 h_i_author;
237 } hurd2;
238 struct {
239 __u8 m_i_frag;
240 __u8 m_i_fsize;
241 __u16 m_pad1;
242 __u32 m_i_reserved2[2];
243 } masix2;
244 } osd2;
245 };
246
247 #if defined(__KERNEL__) || defined(__linux__)
248 #define i_reserved1 osd1.linux1.l_i_reserved1
249 #define i_frag osd2.linux2.l_i_frag
250 #define i_fsize osd2.linux2.l_i_fsize
251 #define i_reserved2 osd2.linux2.l_i_reserved2
252 #endif
253
254 #ifdef __hurd__
255 #define i_translator osd1.hurd1.h_i_translator
256 #define i_frag osd2.hurd2.h_i_frag;
257 #define i_fsize osd2.hurd2.h_i_fsize;
258 #define i_uid_high osd2.hurd2.h_i_uid_high
259 #define i_gid_high osd2.hurd2.h_i_gid_high
260 #define i_author osd2.hurd2.h_i_author
261 #endif
262
263 #ifdef __masix__
264 #define i_reserved1 osd1.masix1.m_i_reserved1
265 #define i_frag osd2.masix2.m_i_frag
266 #define i_fsize osd2.masix2.m_i_fsize
267 #define i_reserved2 osd2.masix2.m_i_reserved2
268 #endif
269
270
271
272
273 #define EXT2_VALID_FS 0x0001
274 #define EXT2_ERROR_FS 0x0002
275
276
277
278
279 #define EXT2_MOUNT_CHECK_NORMAL 0x0001
280 #define EXT2_MOUNT_CHECK_STRICT 0x0002
281 #define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
282 EXT2_MOUNT_CHECK_STRICT)
283 #define EXT2_MOUNT_GRPID 0x0004
284 #define EXT2_MOUNT_DEBUG 0x0008
285 #define EXT2_MOUNT_ERRORS_CONT 0x0010
286 #define EXT2_MOUNT_ERRORS_RO 0x0020
287 #define EXT2_MOUNT_ERRORS_PANIC 0x0040
288 #define EXT2_MOUNT_MINIX_DF 0x0080
289
290 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
291 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
292 #define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
293 EXT2_MOUNT_##opt)
294
295
296
297 #define EXT2_DFL_MAX_MNT_COUNT 20
298 #define EXT2_DFL_CHECKINTERVAL 0
299
300
301
302
303 #define EXT2_ERRORS_CONTINUE 1
304 #define EXT2_ERRORS_RO 2
305 #define EXT2_ERRORS_PANIC 3
306 #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
307
308
309
310
311 struct ext2_super_block {
312 __u32 s_inodes_count;
313 __u32 s_blocks_count;
314 __u32 s_r_blocks_count;
315 __u32 s_free_blocks_count;
316 __u32 s_free_inodes_count;
317 __u32 s_first_data_block;
318 __u32 s_log_block_size;
319 __s32 s_log_frag_size;
320 __u32 s_blocks_per_group;
321 __u32 s_frags_per_group;
322 __u32 s_inodes_per_group;
323 __u32 s_mtime;
324 __u32 s_wtime;
325 __u16 s_mnt_count;
326 __s16 s_max_mnt_count;
327 __u16 s_magic;
328 __u16 s_state;
329 __u16 s_errors;
330 __u16 s_pad;
331 __u32 s_lastcheck;
332 __u32 s_checkinterval;
333 __u32 s_creator_os;
334 __u32 s_rev_level;
335 __u16 s_def_resuid;
336 __u16 s_def_resgid;
337 __u32 s_reserved[235];
338 };
339
340
341
342
343 #define EXT2_OS_LINUX 0
344 #define EXT2_OS_HURD 1
345 #define EXT2_OS_MASIX 2
346 #define EXT2_OS_FREEBSD 3
347 #define EXT2_OS_LITES 4
348
349
350
351
352 #define EXT2_GOOD_OLD_REV 0
353
354 #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
355
356
357
358
359 #define EXT2_DEF_RESUID 0
360 #define EXT2_DEF_RESGID 0
361
362
363
364
365 #define EXT2_NAME_LEN 255
366
367 struct ext2_dir_entry {
368 __u32 inode;
369 __u16 rec_len;
370 __u16 name_len;
371 char name[EXT2_NAME_LEN];
372 };
373
374
375
376
377
378
379 #define EXT2_DIR_PAD 4
380 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
381 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
382 ~EXT2_DIR_ROUND)
383
384 #ifdef __KERNEL__
385
386
387
388
389
390
391
392
393 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
394 # define NORET_TYPE __volatile__
395 # define ATTRIB_NORET
396 # define NORET_AND
397 #else
398 # define NORET_TYPE
399 # define ATTRIB_NORET __attribute__((noreturn))
400 # define NORET_AND noreturn,
401 #endif
402
403
404 extern int ext2_permission (struct inode *, int);
405
406
407 extern int ext2_new_block (const struct inode *, unsigned long,
408 __u32 *, __u32 *, int *);
409 extern void ext2_free_blocks (const struct inode *, unsigned long,
410 unsigned long);
411 extern unsigned long ext2_count_free_blocks (struct super_block *);
412 extern void ext2_check_blocks_bitmap (struct super_block *);
413
414
415 extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
416
417
418 extern int ext2_check_dir_entry (const char *, struct inode *,
419 struct ext2_dir_entry *, struct buffer_head *,
420 unsigned long);
421
422
423 extern int ext2_read (struct inode *, struct file *, char *, int);
424 extern int ext2_write (struct inode *, struct file *, char *, int);
425
426
427 extern int ext2_sync_file (struct inode *, struct file *);
428
429
430 extern struct inode * ext2_new_inode (const struct inode *, int, int *);
431 extern void ext2_free_inode (struct inode *);
432 extern unsigned long ext2_count_free_inodes (struct super_block *);
433 extern void ext2_check_inodes_bitmap (struct super_block *);
434
435
436 extern int ext2_bmap (struct inode *, int);
437
438 extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
439 extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
440
441 extern int ext2_getcluster (struct inode * inode, long block);
442 extern void ext2_read_inode (struct inode *);
443 extern void ext2_write_inode (struct inode *);
444 extern void ext2_put_inode (struct inode *);
445 extern int ext2_sync_inode (struct inode *);
446 extern void ext2_discard_prealloc (struct inode *);
447
448
449 extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
450 unsigned long);
451
452
453 extern void ext2_release (struct inode *, struct file *);
454 extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
455 extern int ext2_create (struct inode *,const char *, int, int,
456 struct inode **);
457 extern int ext2_mkdir (struct inode *, const char *, int, int);
458 extern int ext2_rmdir (struct inode *, const char *, int);
459 extern int ext2_unlink (struct inode *, const char *, int);
460 extern int ext2_symlink (struct inode *, const char *, int, const char *);
461 extern int ext2_link (struct inode *, struct inode *, const char *, int);
462 extern int ext2_mknod (struct inode *, const char *, int, int, int);
463 extern int ext2_rename (struct inode *, const char *, int,
464 struct inode *, const char *, int);
465
466
467 extern void ext2_error (struct super_block *, const char *, const char *, ...)
468 __attribute__ ((format (printf, 3, 4)));
469 extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
470 const char *, ...)
471 __attribute__ ((NORET_AND format (printf, 3, 4)));
472 extern void ext2_warning (struct super_block *, const char *, const char *, ...)
473 __attribute__ ((format (printf, 3, 4)));
474 extern void ext2_put_super (struct super_block *);
475 extern void ext2_write_super (struct super_block *);
476 extern int ext2_remount (struct super_block *, int *, char *);
477 extern struct super_block * ext2_read_super (struct super_block *,void *,int);
478 extern int init_ext2_fs(void);
479 extern void ext2_statfs (struct super_block *, struct statfs *, int);
480
481
482 extern void ext2_truncate (struct inode *);
483
484
485
486
487
488
489 extern struct inode_operations ext2_dir_inode_operations;
490
491
492 extern struct inode_operations ext2_file_inode_operations;
493
494
495 extern struct inode_operations ext2_symlink_inode_operations;
496
497 #endif
498
499 #endif