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