blob: a443aa2771fffbdc254a6a663d2b5fc622616090 [file] [log] [blame]
Theodore Ts'o50e1e101997-04-26 13:58:21 +00001/*
2 * linux/include/linux/ext2_fs.h
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * from
10 *
11 * linux/include/linux/minix_fs.h
12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */
15
16#ifndef _LINUX_EXT2_FS_H
17#define _LINUX_EXT2_FS_H
18
19#include <linux/types.h>
20
21/*
22 * The second extended filesystem constants/structures
23 */
24
25/*
26 * Define EXT2FS_DEBUG to produce debug messages
27 */
28#undef EXT2FS_DEBUG
29
30/*
31 * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
32 */
33#define EXT2_PREALLOCATE
34
35/*
36 * The second extended file system version
37 */
38#define EXT2FS_DATE "95/08/09"
39#define EXT2FS_VERSION "0.5b"
40
41/*
42 * Debug code
43 */
44#ifdef EXT2FS_DEBUG
45# define ext2_debug(f, a...) { \
46 printk ("EXT2-fs DEBUG (%s, %d): %s:", \
47 __FILE__, __LINE__, __FUNCTION__); \
48 printk (f, ## a); \
49 }
50#else
51# define ext2_debug(f, a...) /**/
52#endif
53
54/*
55 * Special inodes numbers
56 */
57#define EXT2_BAD_INO 1 /* Bad blocks inode */
58#define EXT2_ROOT_INO 2 /* Root inode */
59#define EXT2_ACL_IDX_INO 3 /* ACL inode */
60#define EXT2_ACL_DATA_INO 4 /* ACL inode */
61#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
62#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
63#define EXT2_FIRST_INO 11 /* First non reserved inode */
64
65/*
66 * The second extended file system magic number
67 */
68#define EXT2_SUPER_MAGIC 0xEF53
69
70/*
71 * Maximal count of links to a file
72 */
73#define EXT2_LINK_MAX 32000
74
75/*
76 * Macro-instructions used to manage several block sizes
77 */
78#define EXT2_MIN_BLOCK_SIZE 1024
79#define EXT2_MAX_BLOCK_SIZE 4096
80#define EXT2_MIN_BLOCK_LOG_SIZE 10
81#ifdef __KERNEL__
82# define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
83#else
84# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
85#endif
86#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
87#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
88#ifdef __KERNEL__
89# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
90#else
91# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
92#endif
93#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode))
94#ifdef __KERNEL__
95#define EXT2_ADDR_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_addr_per_block_bits)
96#define EXT2_INODES_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_inodes_per_block_bits)
97#endif
98
99/*
100 * Macro-instructions used to manage fragments
101 */
102#define EXT2_MIN_FRAG_SIZE 1024
103#define EXT2_MAX_FRAG_SIZE 4096
104#define EXT2_MIN_FRAG_LOG_SIZE 10
105#ifdef __KERNEL__
106# define EXT2_FRAG_SIZE(s) ((s)->u.ext2_sb.s_frag_size)
107# define EXT2_FRAGS_PER_BLOCK(s) ((s)->u.ext2_sb.s_frags_per_block)
108#else
109# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
110# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
111#endif
112
113/*
114 * ACL structures
115 */
116struct ext2_acl_header /* Header of Access Control Lists */
117{
118 __u32 aclh_size;
119 __u32 aclh_file_count;
120 __u32 aclh_acle_count;
121 __u32 aclh_first_acle;
122};
123
124struct ext2_acl_entry /* Access Control List Entry */
125{
126 __u32 acle_size;
127 __u16 acle_perms; /* Access permissions */
128 __u16 acle_type; /* Type of entry */
129 __u16 acle_tag; /* User or group identity */
130 __u16 acle_pad1;
131 __u32 acle_next; /* Pointer on next entry for the */
132 /* same inode or on next free entry */
133};
134
135/*
136 * Structure of a blocks group descriptor
137 */
138struct ext2_group_desc
139{
140 __u32 bg_block_bitmap; /* Blocks bitmap block */
141 __u32 bg_inode_bitmap; /* Inodes bitmap block */
142 __u32 bg_inode_table; /* Inodes table block */
143 __u16 bg_free_blocks_count; /* Free blocks count */
144 __u16 bg_free_inodes_count; /* Free inodes count */
145 __u16 bg_used_dirs_count; /* Directories count */
146 __u16 bg_pad;
147 __u32 bg_reserved[3];
148};
149
150/*
151 * Macro-instructions used to manage group descriptors
152 */
153#ifdef __KERNEL__
154# define EXT2_BLOCKS_PER_GROUP(s) ((s)->u.ext2_sb.s_blocks_per_group)
155# define EXT2_DESC_PER_BLOCK(s) ((s)->u.ext2_sb.s_desc_per_block)
156# define EXT2_INODES_PER_GROUP(s) ((s)->u.ext2_sb.s_inodes_per_group)
157# define EXT2_DESC_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_desc_per_block_bits)
158#else
159# define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
160# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
161# define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
162#endif
163
164/*
165 * Constants relative to the data blocks
166 */
167#define EXT2_NDIR_BLOCKS 12
168#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
169#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
170#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
171#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
172
173/*
174 * Inode flags
175 */
176#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
177#define EXT2_UNRM_FL 0x00000002 /* Undelete */
178#define EXT2_COMPR_FL 0x00000004 /* Compress file */
179#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
180#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
181#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
182#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
183
184/*
185 * ioctl commands
186 */
187#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
188#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
189#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
190#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
191
192/*
193 * Structure of an inode on the disk
194 */
195struct ext2_inode {
196 __u16 i_mode; /* File mode */
197 __u16 i_uid; /* Owner Uid */
198 __u32 i_size; /* Size in bytes */
199 __u32 i_atime; /* Access time */
200 __u32 i_ctime; /* Creation time */
201 __u32 i_mtime; /* Modification time */
202 __u32 i_dtime; /* Deletion Time */
203 __u16 i_gid; /* Group Id */
204 __u16 i_links_count; /* Links count */
205 __u32 i_blocks; /* Blocks count */
206 __u32 i_flags; /* File flags */
207 union {
208 struct {
209 __u32 l_i_reserved1;
210 } linux1;
211 struct {
212 __u32 h_i_translator;
213 } hurd1;
214 struct {
215 __u32 m_i_reserved1;
216 } masix1;
217 } osd1; /* OS dependent 1 */
218 __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
219 __u32 i_version; /* File version (for NFS) */
220 __u32 i_file_acl; /* File ACL */
221 __u32 i_dir_acl; /* Directory ACL */
222 __u32 i_faddr; /* Fragment address */
223 union {
224 struct {
225 __u8 l_i_frag; /* Fragment number */
226 __u8 l_i_fsize; /* Fragment size */
227 __u16 i_pad1;
228 __u32 l_i_reserved2[2];
229 } linux2;
230 struct {
231 __u8 h_i_frag; /* Fragment number */
232 __u8 h_i_fsize; /* Fragment size */
233 __u16 h_i_mode_high;
234 __u16 h_i_uid_high;
235 __u16 h_i_gid_high;
236 __u32 h_i_author;
237 } hurd2;
238 struct {
239 __u8 m_i_frag; /* Fragment number */
240 __u8 m_i_fsize; /* Fragment size */
241 __u16 m_pad1;
242 __u32 m_i_reserved2[2];
243 } masix2;
244 } osd2; /* OS dependent 2 */
245};
246
247#if defined(__KERNEL__) || defined(__linux__)
248#define i_reserved1 osd1.linux1.l_i_reserved1
249#define i_frag osd2.linux2.l_i_frag
250#define i_fsize osd2.linux2.l_i_fsize
251#define i_reserved2 osd2.linux2.l_i_reserved2
252#endif
253
254#ifdef __hurd__
255#define i_translator osd1.hurd1.h_i_translator
256#define i_frag osd2.hurd2.h_i_frag;
257#define i_fsize osd2.hurd2.h_i_fsize;
258#define i_uid_high osd2.hurd2.h_i_uid_high
259#define i_gid_high osd2.hurd2.h_i_gid_high
260#define i_author osd2.hurd2.h_i_author
261#endif
262
263#ifdef __masix__
264#define i_reserved1 osd1.masix1.m_i_reserved1
265#define i_frag osd2.masix2.m_i_frag
266#define i_fsize osd2.masix2.m_i_fsize
267#define i_reserved2 osd2.masix2.m_i_reserved2
268#endif
269
270/*
271 * File system states
272 */
273#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
274#define EXT2_ERROR_FS 0x0002 /* Errors detected */
275
276/*
277 * Mount flags
278 */
279#define EXT2_MOUNT_CHECK_NORMAL 0x0001 /* Do some more checks */
280#define EXT2_MOUNT_CHECK_STRICT 0x0002 /* Do again more checks */
281#define EXT2_MOUNT_CHECK (EXT2_MOUNT_CHECK_NORMAL | \
282 EXT2_MOUNT_CHECK_STRICT)
283#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
284#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
285#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
286#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
287#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
288#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
289
290#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
291#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
292#define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
293 EXT2_MOUNT_##opt)
294/*
295 * Maximal mount counts between two filesystem checks
296 */
297#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
298#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
299
300/*
301 * Behaviour when detecting errors
302 */
303#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
304#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
305#define EXT2_ERRORS_PANIC 3 /* Panic */
306#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
307
308/*
309 * Structure of the super block
310 */
311struct ext2_super_block {
312 __u32 s_inodes_count; /* Inodes count */
313 __u32 s_blocks_count; /* Blocks count */
314 __u32 s_r_blocks_count; /* Reserved blocks count */
315 __u32 s_free_blocks_count; /* Free blocks count */
316 __u32 s_free_inodes_count; /* Free inodes count */
317 __u32 s_first_data_block; /* First Data Block */
318 __u32 s_log_block_size; /* Block size */
319 __s32 s_log_frag_size; /* Fragment size */
320 __u32 s_blocks_per_group; /* # Blocks per group */
321 __u32 s_frags_per_group; /* # Fragments per group */
322 __u32 s_inodes_per_group; /* # Inodes per group */
323 __u32 s_mtime; /* Mount time */
324 __u32 s_wtime; /* Write time */
325 __u16 s_mnt_count; /* Mount count */
326 __s16 s_max_mnt_count; /* Maximal mount count */
327 __u16 s_magic; /* Magic signature */
328 __u16 s_state; /* File system state */
329 __u16 s_errors; /* Behaviour when detecting errors */
330 __u16 s_pad;
331 __u32 s_lastcheck; /* time of last check */
332 __u32 s_checkinterval; /* max. time between checks */
333 __u32 s_creator_os; /* OS */
334 __u32 s_rev_level; /* Revision level */
335 __u16 s_def_resuid; /* Default uid for reserved blocks */
336 __u16 s_def_resgid; /* Default gid for reserved blocks */
337 __u32 s_reserved[235]; /* Padding to the end of the block */
338};
339
340/*
341 * Codes for operating systems
342 */
343#define EXT2_OS_LINUX 0
344#define EXT2_OS_HURD 1
345#define EXT2_OS_MASIX 2
346#define EXT2_OS_FREEBSD 3
347#define EXT2_OS_LITES 4
348
349/*
350 * Revision levels
351 */
352#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
353
354#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
355
356/*
357 * Default values for user and/or group using reserved blocks
358 */
359#define EXT2_DEF_RESUID 0
360#define EXT2_DEF_RESGID 0
361
362/*
363 * Structure of a directory entry
364 */
365#define EXT2_NAME_LEN 255
366
367struct ext2_dir_entry {
368 __u32 inode; /* Inode number */
369 __u16 rec_len; /* Directory entry length */
370 __u16 name_len; /* Name length */
371 char name[EXT2_NAME_LEN]; /* File name */
372};
373
374/*
375 * EXT2_DIR_PAD defines the directory entries boundaries
376 *
377 * NOTE: It must be a multiple of 4
378 */
379#define EXT2_DIR_PAD 4
380#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
381#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
382 ~EXT2_DIR_ROUND)
383
384#ifdef __KERNEL__
385/*
386 * Function prototypes
387 */
388
389/*
390 * Ok, these declarations are also in <linux/kernel.h> but none of the
391 * ext2 source programs needs to include it so they are duplicated here.
392 */
393#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
394# define NORET_TYPE __volatile__
395# define ATTRIB_NORET /**/
396# define NORET_AND /**/
397#else
398# define NORET_TYPE /**/
399# define ATTRIB_NORET __attribute__((noreturn))
400# define NORET_AND noreturn,
401#endif
402
403/* acl.c */
404extern int ext2_permission (struct inode *, int);
405
406/* balloc.c */
407extern int ext2_new_block (struct super_block *, unsigned long,
408 __u32 *, __u32 *);
409extern void ext2_free_blocks (struct super_block *, unsigned long,
410 unsigned long);
411extern unsigned long ext2_count_free_blocks (struct super_block *);
412extern void ext2_check_blocks_bitmap (struct super_block *);
413
414/* bitmap.c */
415extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
416
417/* dir.c */
418extern int ext2_check_dir_entry (const char *, struct inode *,
419 struct ext2_dir_entry *, struct buffer_head *,
420 unsigned long);
421
422/* file.c */
423extern int ext2_read (struct inode *, struct file *, char *, int);
424extern int ext2_write (struct inode *, struct file *, char *, int);
425
426/* fsync.c */
427extern int ext2_sync_file (struct inode *, struct file *);
428
429/* ialloc.c */
430extern struct inode * ext2_new_inode (const struct inode *, int);
431extern void ext2_free_inode (struct inode *);
432extern unsigned long ext2_count_free_inodes (struct super_block *);
433extern void ext2_check_inodes_bitmap (struct super_block *);
434
435/* inode.c */
436extern int ext2_bmap (struct inode *, int);
437
438extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
439extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
440
441extern int ext2_getcluster (struct inode * inode, long block);
442extern void ext2_read_inode (struct inode *);
443extern void ext2_write_inode (struct inode *);
444extern void ext2_put_inode (struct inode *);
445extern int ext2_sync_inode (struct inode *);
446extern void ext2_discard_prealloc (struct inode *);
447
448/* ioctl.c */
449extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
450 unsigned long);
451
452/* namei.c */
453extern void ext2_release (struct inode *, struct file *);
454extern int ext2_lookup (struct inode *,const char *, int, struct inode **);
455extern int ext2_create (struct inode *,const char *, int, int,
456 struct inode **);
457extern int ext2_mkdir (struct inode *, const char *, int, int);
458extern int ext2_rmdir (struct inode *, const char *, int);
459extern int ext2_unlink (struct inode *, const char *, int);
460extern int ext2_symlink (struct inode *, const char *, int, const char *);
461extern int ext2_link (struct inode *, struct inode *, const char *, int);
462extern int ext2_mknod (struct inode *, const char *, int, int, int);
463extern int ext2_rename (struct inode *, const char *, int,
464 struct inode *, const char *, int);
465
466/* super.c */
467extern void ext2_error (struct super_block *, const char *, const char *, ...)
468 __attribute__ ((format (printf, 3, 4)));
469extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
470 const char *, ...)
471 __attribute__ ((NORET_AND format (printf, 3, 4)));
472extern void ext2_warning (struct super_block *, const char *, const char *, ...)
473 __attribute__ ((format (printf, 3, 4)));
474extern void ext2_put_super (struct super_block *);
475extern void ext2_write_super (struct super_block *);
476extern int ext2_remount (struct super_block *, int *, char *);
477extern struct super_block * ext2_read_super (struct super_block *,void *,int);
478extern void ext2_statfs (struct super_block *, struct statfs *, int);
479
480/* truncate.c */
481extern void ext2_truncate (struct inode *);
482
483/*
484 * Inodes and files operations
485 */
486
487/* dir.c */
488extern struct inode_operations ext2_dir_inode_operations;
489
490/* file.c */
491extern struct inode_operations ext2_file_inode_operations;
492
493/* symlink.c */
494extern struct inode_operations ext2_symlink_inode_operations;
495
496#endif /* __KERNEL__ */
497
498#endif /* _LINUX_EXT2_FS_H */