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