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/08/24"
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 #ifdef __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 long s_reserved[236];
353 };
354
355 #define EXT2_OS_LINUX 0
356 #define EXT2_OS_HURD 1
357 #define EXT2_OS_MASIX 2
358
359 #define EXT2_CURRENT_REV 0
360
361
362
363
364 #define EXT2_NAME_LEN 255
365
366 struct ext2_dir_entry {
367 unsigned long inode;
368 unsigned short rec_len;
369 unsigned short name_len;
370 char name[EXT2_NAME_LEN];
371 };
372
373
374
375
376
377
378 #define EXT2_DIR_PAD 4
379 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
380 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
381 ~EXT2_DIR_ROUND)
382
383 #ifdef __KERNEL__
384
385
386
387
388
389
390
391
392 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
393 # define NORET_TYPE __volatile__
394 # define ATTRIB_NORET
395 # define NORET_AND
396 #else
397 # define NORET_TYPE
398 # define ATTRIB_NORET __attribute__((noreturn))
399 # define NORET_AND noreturn,
400 #endif
401
402
403 extern int ext2_permission (struct inode *, int);
404
405
406 extern int ext2_new_block (struct super_block *, unsigned long,
407 unsigned long *, unsigned long *);
408 extern void ext2_free_blocks (struct super_block *, unsigned long,
409 unsigned long);
410 extern unsigned long ext2_count_free_blocks (struct super_block *);
411 extern void ext2_check_blocks_bitmap (struct super_block *);
412
413
414 extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
415
416
417 extern int ext2_check_dir_entry (char *, struct inode *,
418 struct ext2_dir_entry *, struct buffer_head *,
419 unsigned long);
420
421
422 extern int ext2_read (struct inode *, struct file *, char *, int);
423 extern int ext2_write (struct inode *, struct file *, char *, int);
424
425
426 extern int ext2_sync_file (struct inode *, struct file *);
427
428
429 extern struct inode * ext2_new_inode (const struct inode *, int);
430 extern void ext2_free_inode (struct inode *);
431 extern unsigned long ext2_count_free_inodes (struct super_block *);
432 extern void ext2_check_inodes_bitmap (struct super_block *);
433
434
435 extern int ext2_bmap (struct inode *, int);
436
437 extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
438 extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
439
440 extern int ext2_getcluster (struct inode * inode, long block);
441 extern void ext2_read_inode (struct inode *);
442 extern void ext2_write_inode (struct inode *);
443 extern void ext2_put_inode (struct inode *);
444 extern int ext2_sync_inode (struct inode *);
445 extern void ext2_discard_prealloc (struct inode *);
446
447
448 extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
449 unsigned long);
450
451
452 extern void ext2_release (struct inode *, struct file *);
453 extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
454 extern int ext2_create (struct inode *,const char *, int, int,
455 struct inode **);
456 extern int ext2_mkdir (struct inode *, const char *, int, int);
457 extern int ext2_rmdir (struct inode *, const char *, int);
458 extern int ext2_unlink (struct inode *, const char *, int);
459 extern int ext2_symlink (struct inode *, const char *, int, const char *);
460 extern int ext2_link (struct inode *, struct inode *, const char *, int);
461 extern int ext2_mknod (struct inode *, const char *, int, int, int);
462 extern int ext2_rename (struct inode *, const char *, int,
463 struct inode *, const char *, int);
464
465
466 extern void ext2_error (struct super_block *, const char *, const char *, ...)
467 __attribute__ ((format (printf, 3, 4)));
468 extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
469 const char *, ...)
470 __attribute__ ((NORET_AND format (printf, 3, 4)));
471 extern void ext2_warning (struct super_block *, const char *, const char *, ...)
472 __attribute__ ((format (printf, 3, 4)));
473 extern void ext2_put_super (struct super_block *);
474 extern void ext2_write_super (struct super_block *);
475 extern int ext2_remount (struct super_block *, int *, char *);
476 extern struct super_block * ext2_read_super (struct super_block *,void *,int);
477 extern void ext2_statfs (struct super_block *, struct statfs *);
478
479
480 extern void ext2_truncate (struct inode *);
481
482
483
484
485
486
487 extern struct inode_operations ext2_dir_inode_operations;
488
489
490 extern struct inode_operations ext2_file_inode_operations;
491
492
493 extern struct inode_operations ext2_symlink_inode_operations;
494
495 #endif
496
497 #endif