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/03/10"
51 #define EXT2FS_VERSION "0.5"
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 0x0001
194 #define EXT2_UNRM_FL 0x0002
195 #define EXT2_COMPR_FL 0x0004
196 #define EXT2_SYNC_FL 0x0008
197
198
199
200
201 #define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
202 #define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
203 #define EXT2_IOC_GETVERSION _IOR('v', 1, long)
204 #define EXT2_IOC_SETVERSION _IOW('v', 2, long)
205
206
207
208
209 struct ext2_inode {
210 unsigned short i_mode;
211 unsigned short i_uid;
212 unsigned long i_size;
213 unsigned long i_atime;
214 unsigned long i_ctime;
215 unsigned long i_mtime;
216 unsigned long i_dtime;
217 unsigned short i_gid;
218 unsigned short i_links_count;
219 unsigned long i_blocks;
220 unsigned long i_flags;
221 unsigned long i_reserved1;
222 unsigned long i_block[EXT2_N_BLOCKS];
223 unsigned long i_version;
224 unsigned long i_file_acl;
225 unsigned long i_dir_acl;
226 unsigned long i_faddr;
227 unsigned char i_frag;
228 unsigned char i_fsize;
229 unsigned short i_pad1;
230 unsigned long i_reserved2[2];
231 };
232
233
234
235
236 #define EXT2_VALID_FS 0x0001
237 #define EXT2_ERROR_FS 0x0002
238
239
240
241
242 #define EXT2_MOUNT_CHECK_NORMAL 0x0001
243 #define EXT2_MOUNT_CHECK_STRICT 0x0002
244 #define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
245 EXT2_MOUNT_CHECK_STRICT)
246 #define EXT2_MOUNT_GRPID 0x0004
247 #define EXT2_MOUNT_DEBUG 0x0008
248 #define EXT2_MOUNT_ERRORS_CONT 0x0010
249 #define EXT2_MOUNT_ERRORS_RO 0x0020
250 #define EXT2_MOUNT_ERRORS_PANIC 0x0040
251
252 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
253 #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
254 #define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
255 EXT2_MOUNT_##opt)
256
257
258
259 #define EXT2_DFL_MAX_MNT_COUNT 20
260 #define EXT2_DFL_CHECKINTERVAL 0
261
262
263
264
265 #define EXT2_ERRORS_CONTINUE 1
266 #define EXT2_ERRORS_RO 2
267 #define EXT2_ERRORS_PANIC 3
268 #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
269
270
271
272
273 struct ext2_super_block {
274 unsigned long s_inodes_count;
275 unsigned long s_blocks_count;
276 unsigned long s_r_blocks_count;
277 unsigned long s_free_blocks_count;
278 unsigned long s_free_inodes_count;
279 unsigned long s_first_data_block;
280 unsigned long s_log_block_size;
281 long s_log_frag_size;
282 unsigned long s_blocks_per_group;
283 unsigned long s_frags_per_group;
284 unsigned long s_inodes_per_group;
285 unsigned long s_mtime;
286 unsigned long s_wtime;
287 unsigned short s_mnt_count;
288 short s_max_mnt_count;
289 unsigned short s_magic;
290 unsigned short s_state;
291 unsigned short s_errors;
292 unsigned short s_pad;
293 unsigned long s_lastcheck;
294 unsigned long s_checkinterval;
295 unsigned long s_reserved[238];
296 };
297
298
299
300
301 #define EXT2_NAME_LEN 255
302
303 struct ext2_dir_entry {
304 unsigned long inode;
305 unsigned short rec_len;
306 unsigned short name_len;
307 char name[EXT2_NAME_LEN];
308 };
309
310
311
312
313
314
315 #define EXT2_DIR_PAD 4
316 #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
317 #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
318 ~EXT2_DIR_ROUND)
319
320 #ifdef __KERNEL__
321
322
323
324
325
326
327
328
329 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
330 # define NORET_TYPE __volatile__
331 # define ATTRIB_NORET
332 # define NORET_AND
333 #else
334 # define NORET_TYPE
335 # define ATTRIB_NORET __attribute__((noreturn))
336 # define NORET_AND noreturn,
337 #endif
338
339
340 extern int ext2_permission (struct inode *, int);
341
342
343 extern int ext2_new_block (struct super_block *, unsigned long,
344 unsigned long *, unsigned long *);
345 extern void ext2_free_blocks (struct super_block *, unsigned long,
346 unsigned long);
347 extern unsigned long ext2_count_free_blocks (struct super_block *);
348 extern void ext2_check_blocks_bitmap (struct super_block *);
349
350
351 extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
352
353
354 extern int ext2_check_dir_entry (char *, struct inode *,
355 struct ext2_dir_entry *, struct buffer_head *,
356 unsigned long);
357
358
359 extern int ext2_read (struct inode *, struct file *, char *, int);
360 extern int ext2_write (struct inode *, struct file *, char *, int);
361
362
363 extern int ext2_sync_file (struct inode *, struct file *);
364
365
366 extern struct inode * ext2_new_inode (const struct inode *, int);
367 extern void ext2_free_inode (struct inode *);
368 extern unsigned long ext2_count_free_inodes (struct super_block *);
369 extern void ext2_check_inodes_bitmap (struct super_block *);
370
371
372 extern int ext2_bmap (struct inode *, int);
373
374 extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
375 extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
376
377 extern int ext2_getcluster (struct inode * inode, long block);
378 extern void ext2_read_inode (struct inode *);
379 extern void ext2_write_inode (struct inode *);
380 extern void ext2_put_inode (struct inode *);
381 extern int ext2_sync_inode (struct inode *);
382 extern void ext2_discard_prealloc (struct inode *);
383
384
385 extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
386 unsigned long);
387
388
389 extern int ext2_open (struct inode *, struct file *);
390 extern void ext2_release (struct inode *, struct file *);
391 extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
392 extern int ext2_create (struct inode *,const char *, int, int,
393 struct inode **);
394 extern int ext2_mkdir (struct inode *, const char *, int, int);
395 extern int ext2_rmdir (struct inode *, const char *, int);
396 extern int ext2_unlink (struct inode *, const char *, int);
397 extern int ext2_symlink (struct inode *, const char *, int, const char *);
398 extern int ext2_link (struct inode *, struct inode *, const char *, int);
399 extern int ext2_mknod (struct inode *, const char *, int, int, int);
400 extern int ext2_rename (struct inode *, const char *, int,
401 struct inode *, const char *, int);
402
403
404 extern void ext2_error (struct super_block *, const char *, const char *, ...)
405 __attribute__ ((format (printf, 3, 4)));
406 extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
407 const char *, ...)
408 __attribute__ ((NORET_AND format (printf, 3, 4)));
409 extern void ext2_warning (struct super_block *, const char *, const char *, ...)
410 __attribute__ ((format (printf, 3, 4)));
411 extern void ext2_put_super (struct super_block *);
412 extern void ext2_write_super (struct super_block *);
413 extern int ext2_remount (struct super_block *, int *, char *);
414 extern struct super_block * ext2_read_super (struct super_block *,void *,int);
415 extern void ext2_statfs (struct super_block *, struct statfs *);
416
417
418 extern void ext2_truncate (struct inode *);
419
420
421
422
423
424
425 extern struct inode_operations ext2_dir_inode_operations;
426
427
428 extern struct inode_operations ext2_file_inode_operations;
429
430
431 extern struct inode_operations ext2_symlink_inode_operations;
432
433 #endif
434
435 #endif