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