blob: d9a17d0b124d3304654f24c430645a38b3e42f12 [file] [log] [blame]
Al Virof7699f22012-03-23 16:45:51 -04001/*
2 * Copyright (C) 1992, 1993, 1994, 1995
3 * Remy Card (card@masi.ibp.fr)
4 * Laboratoire MASI - Institut Blaise Pascal
5 * Universite Pierre et Marie Curie (Paris VI)
6 *
7 * from
8 *
9 * linux/include/linux/minix_fs.h
10 *
11 * Copyright (C) 1991, 1992 Linus Torvalds
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/fs.h>
14#include <linux/ext2_fs.h>
Al Virof7699f22012-03-23 16:45:51 -040015#include <linux/blockgroup_lock.h>
16#include <linux/percpu_counter.h>
17#include <linux/rbtree.h>
18
19/* XXX Here for now... not interested in restructing headers JUST now */
20
21/* data type for block offset of block group */
22typedef int ext2_grpblk_t;
23
24/* data type for filesystem-wide blocks number */
25typedef unsigned long ext2_fsblk_t;
26
27#define E2FSBLK "%lu"
28
29struct ext2_reserve_window {
30 ext2_fsblk_t _rsv_start; /* First byte reserved */
31 ext2_fsblk_t _rsv_end; /* Last byte reserved or 0 */
32};
33
34struct ext2_reserve_window_node {
35 struct rb_node rsv_node;
36 __u32 rsv_goal_size;
37 __u32 rsv_alloc_hit;
38 struct ext2_reserve_window rsv_window;
39};
40
41struct ext2_block_alloc_info {
42 /* information about reservation window */
43 struct ext2_reserve_window_node rsv_window_node;
44 /*
45 * was i_next_alloc_block in ext2_inode_info
46 * is the logical (file-relative) number of the
47 * most-recently-allocated block in this file.
48 * We use this for detecting linearly ascending allocation requests.
49 */
50 __u32 last_alloc_logical_block;
51 /*
52 * Was i_next_alloc_goal in ext2_inode_info
53 * is the *physical* companion to i_next_alloc_block.
54 * it the the physical block number of the block which was most-recentl
55 * allocated to this file. This give us the goal (target) for the next
56 * allocation when we detect linearly ascending requests.
57 */
58 ext2_fsblk_t last_alloc_physical_block;
59};
60
61#define rsv_start rsv_window._rsv_start
62#define rsv_end rsv_window._rsv_end
63
64/*
65 * second extended-fs super-block data in memory
66 */
67struct ext2_sb_info {
68 unsigned long s_frag_size; /* Size of a fragment in bytes */
69 unsigned long s_frags_per_block;/* Number of fragments per block */
70 unsigned long s_inodes_per_block;/* Number of inodes per block */
71 unsigned long s_frags_per_group;/* Number of fragments in a group */
72 unsigned long s_blocks_per_group;/* Number of blocks in a group */
73 unsigned long s_inodes_per_group;/* Number of inodes in a group */
74 unsigned long s_itb_per_group; /* Number of inode table blocks per group */
75 unsigned long s_gdb_count; /* Number of group descriptor blocks */
76 unsigned long s_desc_per_block; /* Number of group descriptors per block */
77 unsigned long s_groups_count; /* Number of groups in the fs */
78 unsigned long s_overhead_last; /* Last calculated overhead */
79 unsigned long s_blocks_last; /* Last seen block count */
80 struct buffer_head * s_sbh; /* Buffer containing the super block */
81 struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
82 struct buffer_head ** s_group_desc;
83 unsigned long s_mount_opt;
84 unsigned long s_sb_block;
Eric W. Biedermanb8a9f9e2012-02-07 15:39:12 -080085 kuid_t s_resuid;
86 kgid_t s_resgid;
Al Virof7699f22012-03-23 16:45:51 -040087 unsigned short s_mount_state;
88 unsigned short s_pad;
89 int s_addr_per_block_bits;
90 int s_desc_per_block_bits;
91 int s_inode_size;
92 int s_first_ino;
93 spinlock_t s_next_gen_lock;
94 u32 s_next_generation;
95 unsigned long s_dir_count;
96 u8 *s_debts;
97 struct percpu_counter s_freeblocks_counter;
98 struct percpu_counter s_freeinodes_counter;
99 struct percpu_counter s_dirs_counter;
100 struct blockgroup_lock *s_blockgroup_lock;
101 /* root of the per fs reservation window tree */
102 spinlock_t s_rsv_window_lock;
103 struct rb_root s_rsv_window_root;
104 struct ext2_reserve_window_node s_rsv_window_head;
105 /*
106 * s_lock protects against concurrent modifications of s_mount_state,
107 * s_blocks_last, s_overhead_last and the content of superblock's
108 * buffer pointed to by sbi->s_es.
109 *
110 * Note: It is used in ext2_show_options() to provide a consistent view
111 * of the mount options.
112 */
113 spinlock_t s_lock;
114};
115
116static inline spinlock_t *
117sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
118{
119 return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
120}
121
122/*
123 * Define EXT2FS_DEBUG to produce debug messages
124 */
125#undef EXT2FS_DEBUG
126
127/*
128 * Define EXT2_RESERVATION to reserve data blocks for expanding files
129 */
130#define EXT2_DEFAULT_RESERVE_BLOCKS 8
131/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
132#define EXT2_MAX_RESERVE_BLOCKS 1027
133#define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
134/*
135 * The second extended file system version
136 */
137#define EXT2FS_DATE "95/08/09"
138#define EXT2FS_VERSION "0.5b"
139
140/*
141 * Debug code
142 */
143#ifdef EXT2FS_DEBUG
144# define ext2_debug(f, a...) { \
145 printk ("EXT2-fs DEBUG (%s, %d): %s:", \
146 __FILE__, __LINE__, __func__); \
147 printk (f, ## a); \
148 }
149#else
150# define ext2_debug(f, a...) /**/
151#endif
152
153/*
154 * Special inode numbers
155 */
156#define EXT2_BAD_INO 1 /* Bad blocks inode */
157#define EXT2_ROOT_INO 2 /* Root inode */
158#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
159#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
160
161/* First non-reserved inode for old ext2 filesystems */
162#define EXT2_GOOD_OLD_FIRST_INO 11
163
164static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
165{
166 return sb->s_fs_info;
167}
168
169/*
170 * Macro-instructions used to manage several block sizes
171 */
172#define EXT2_MIN_BLOCK_SIZE 1024
173#define EXT2_MAX_BLOCK_SIZE 4096
174#define EXT2_MIN_BLOCK_LOG_SIZE 10
175#define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
176#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
177#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
178#define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_addr_per_block_bits)
179#define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
180#define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
181
182/*
183 * Macro-instructions used to manage fragments
184 */
185#define EXT2_MIN_FRAG_SIZE 1024
186#define EXT2_MAX_FRAG_SIZE 4096
187#define EXT2_MIN_FRAG_LOG_SIZE 10
188#define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size)
189#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block)
190
191/*
192 * Structure of a blocks group descriptor
193 */
194struct ext2_group_desc
195{
196 __le32 bg_block_bitmap; /* Blocks bitmap block */
197 __le32 bg_inode_bitmap; /* Inodes bitmap block */
198 __le32 bg_inode_table; /* Inodes table block */
199 __le16 bg_free_blocks_count; /* Free blocks count */
200 __le16 bg_free_inodes_count; /* Free inodes count */
201 __le16 bg_used_dirs_count; /* Directories count */
202 __le16 bg_pad;
203 __le32 bg_reserved[3];
204};
205
206/*
207 * Macro-instructions used to manage group descriptors
208 */
209#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
210#define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
211#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
212#define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
213
214/*
215 * Constants relative to the data blocks
216 */
217#define EXT2_NDIR_BLOCKS 12
218#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
219#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
220#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
221#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
222
223/*
224 * Inode flags (GETFLAGS/SETFLAGS)
225 */
226#define EXT2_SECRM_FL FS_SECRM_FL /* Secure deletion */
227#define EXT2_UNRM_FL FS_UNRM_FL /* Undelete */
228#define EXT2_COMPR_FL FS_COMPR_FL /* Compress file */
229#define EXT2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
230#define EXT2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
231#define EXT2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
232#define EXT2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
233#define EXT2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
234/* Reserved for compression usage... */
235#define EXT2_DIRTY_FL FS_DIRTY_FL
236#define EXT2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
237#define EXT2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
238#define EXT2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
239/* End compression flags --- maybe not all used */
240#define EXT2_BTREE_FL FS_BTREE_FL /* btree format dir */
241#define EXT2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
242#define EXT2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
243#define EXT2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
244#define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
245#define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
246#define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
247#define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
248
249#define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
250#define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
251
252/* Flags that should be inherited by new inodes from their parent. */
253#define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
254 EXT2_SYNC_FL | EXT2_NODUMP_FL |\
255 EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
256 EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
257 EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
258
259/* Flags that are appropriate for regular files (all but dir-specific ones). */
260#define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
261
262/* Flags that are appropriate for non-directories/regular files. */
263#define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
264
265/* Mask out flags that are inappropriate for the given type of inode. */
266static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
267{
268 if (S_ISDIR(mode))
269 return flags;
270 else if (S_ISREG(mode))
271 return flags & EXT2_REG_FLMASK;
272 else
273 return flags & EXT2_OTHER_FLMASK;
274}
275
276/*
277 * ioctl commands
278 */
279#define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS
280#define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS
281#define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
282#define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
283#define EXT2_IOC_GETRSVSZ _IOR('f', 5, long)
284#define EXT2_IOC_SETRSVSZ _IOW('f', 6, long)
285
286/*
287 * ioctl commands in 32 bit emulation
288 */
289#define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
290#define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
291#define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION
292#define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION
293
294/*
295 * Structure of an inode on the disk
296 */
297struct ext2_inode {
298 __le16 i_mode; /* File mode */
299 __le16 i_uid; /* Low 16 bits of Owner Uid */
300 __le32 i_size; /* Size in bytes */
301 __le32 i_atime; /* Access time */
302 __le32 i_ctime; /* Creation time */
303 __le32 i_mtime; /* Modification time */
304 __le32 i_dtime; /* Deletion Time */
305 __le16 i_gid; /* Low 16 bits of Group Id */
306 __le16 i_links_count; /* Links count */
307 __le32 i_blocks; /* Blocks count */
308 __le32 i_flags; /* File flags */
309 union {
310 struct {
311 __le32 l_i_reserved1;
312 } linux1;
313 struct {
314 __le32 h_i_translator;
315 } hurd1;
316 struct {
317 __le32 m_i_reserved1;
318 } masix1;
319 } osd1; /* OS dependent 1 */
320 __le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
321 __le32 i_generation; /* File version (for NFS) */
322 __le32 i_file_acl; /* File ACL */
323 __le32 i_dir_acl; /* Directory ACL */
324 __le32 i_faddr; /* Fragment address */
325 union {
326 struct {
327 __u8 l_i_frag; /* Fragment number */
328 __u8 l_i_fsize; /* Fragment size */
329 __u16 i_pad1;
330 __le16 l_i_uid_high; /* these 2 fields */
331 __le16 l_i_gid_high; /* were reserved2[0] */
332 __u32 l_i_reserved2;
333 } linux2;
334 struct {
335 __u8 h_i_frag; /* Fragment number */
336 __u8 h_i_fsize; /* Fragment size */
337 __le16 h_i_mode_high;
338 __le16 h_i_uid_high;
339 __le16 h_i_gid_high;
340 __le32 h_i_author;
341 } hurd2;
342 struct {
343 __u8 m_i_frag; /* Fragment number */
344 __u8 m_i_fsize; /* Fragment size */
345 __u16 m_pad1;
346 __u32 m_i_reserved2[2];
347 } masix2;
348 } osd2; /* OS dependent 2 */
349};
350
351#define i_size_high i_dir_acl
352
353#define i_reserved1 osd1.linux1.l_i_reserved1
354#define i_frag osd2.linux2.l_i_frag
355#define i_fsize osd2.linux2.l_i_fsize
356#define i_uid_low i_uid
357#define i_gid_low i_gid
358#define i_uid_high osd2.linux2.l_i_uid_high
359#define i_gid_high osd2.linux2.l_i_gid_high
360#define i_reserved2 osd2.linux2.l_i_reserved2
361
362/*
363 * File system states
364 */
365#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
366#define EXT2_ERROR_FS 0x0002 /* Errors detected */
367
368/*
369 * Mount flags
370 */
371#define EXT2_MOUNT_CHECK 0x000001 /* Do mount-time checks */
372#define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
373#define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
374#define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
375#define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
376#define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
377#define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
378#define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
379#define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
380#define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
381#define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
382#define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
383#define EXT2_MOUNT_XIP 0x010000 /* Execute in place */
384#define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
385#define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
386#define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
387
388
389#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
390#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
391#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
392 EXT2_MOUNT_##opt)
393/*
394 * Maximal mount counts between two filesystem checks
395 */
396#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
397#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
398
399/*
400 * Behaviour when detecting errors
401 */
402#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
403#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
404#define EXT2_ERRORS_PANIC 3 /* Panic */
405#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
406
407/*
408 * Structure of the super block
409 */
410struct ext2_super_block {
411 __le32 s_inodes_count; /* Inodes count */
412 __le32 s_blocks_count; /* Blocks count */
413 __le32 s_r_blocks_count; /* Reserved blocks count */
414 __le32 s_free_blocks_count; /* Free blocks count */
415 __le32 s_free_inodes_count; /* Free inodes count */
416 __le32 s_first_data_block; /* First Data Block */
417 __le32 s_log_block_size; /* Block size */
418 __le32 s_log_frag_size; /* Fragment size */
419 __le32 s_blocks_per_group; /* # Blocks per group */
420 __le32 s_frags_per_group; /* # Fragments per group */
421 __le32 s_inodes_per_group; /* # Inodes per group */
422 __le32 s_mtime; /* Mount time */
423 __le32 s_wtime; /* Write time */
424 __le16 s_mnt_count; /* Mount count */
425 __le16 s_max_mnt_count; /* Maximal mount count */
426 __le16 s_magic; /* Magic signature */
427 __le16 s_state; /* File system state */
428 __le16 s_errors; /* Behaviour when detecting errors */
429 __le16 s_minor_rev_level; /* minor revision level */
430 __le32 s_lastcheck; /* time of last check */
431 __le32 s_checkinterval; /* max. time between checks */
432 __le32 s_creator_os; /* OS */
433 __le32 s_rev_level; /* Revision level */
434 __le16 s_def_resuid; /* Default uid for reserved blocks */
435 __le16 s_def_resgid; /* Default gid for reserved blocks */
436 /*
437 * These fields are for EXT2_DYNAMIC_REV superblocks only.
438 *
439 * Note: the difference between the compatible feature set and
440 * the incompatible feature set is that if there is a bit set
441 * in the incompatible feature set that the kernel doesn't
442 * know about, it should refuse to mount the filesystem.
443 *
444 * e2fsck's requirements are more strict; if it doesn't know
445 * about a feature in either the compatible or incompatible
446 * feature set, it must abort and not try to meddle with
447 * things it doesn't understand...
448 */
449 __le32 s_first_ino; /* First non-reserved inode */
450 __le16 s_inode_size; /* size of inode structure */
451 __le16 s_block_group_nr; /* block group # of this superblock */
452 __le32 s_feature_compat; /* compatible feature set */
453 __le32 s_feature_incompat; /* incompatible feature set */
454 __le32 s_feature_ro_compat; /* readonly-compatible feature set */
455 __u8 s_uuid[16]; /* 128-bit uuid for volume */
456 char s_volume_name[16]; /* volume name */
457 char s_last_mounted[64]; /* directory where last mounted */
458 __le32 s_algorithm_usage_bitmap; /* For compression */
459 /*
460 * Performance hints. Directory preallocation should only
461 * happen if the EXT2_COMPAT_PREALLOC flag is on.
462 */
463 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
464 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
465 __u16 s_padding1;
466 /*
467 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
468 */
469 __u8 s_journal_uuid[16]; /* uuid of journal superblock */
470 __u32 s_journal_inum; /* inode number of journal file */
471 __u32 s_journal_dev; /* device number of journal file */
472 __u32 s_last_orphan; /* start of list of inodes to delete */
473 __u32 s_hash_seed[4]; /* HTREE hash seed */
474 __u8 s_def_hash_version; /* Default hash version to use */
475 __u8 s_reserved_char_pad;
476 __u16 s_reserved_word_pad;
477 __le32 s_default_mount_opts;
478 __le32 s_first_meta_bg; /* First metablock block group */
479 __u32 s_reserved[190]; /* Padding to the end of the block */
480};
481
482/*
483 * Codes for operating systems
484 */
485#define EXT2_OS_LINUX 0
486#define EXT2_OS_HURD 1
487#define EXT2_OS_MASIX 2
488#define EXT2_OS_FREEBSD 3
489#define EXT2_OS_LITES 4
490
491/*
492 * Revision levels
493 */
494#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
495#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
496
497#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
498#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
499
500#define EXT2_GOOD_OLD_INODE_SIZE 128
501
502/*
503 * Feature set definitions
504 */
505
506#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
507 ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
508#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
509 ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
510#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
511 ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
512#define EXT2_SET_COMPAT_FEATURE(sb,mask) \
513 EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
514#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
515 EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
516#define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
517 EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
518#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
519 EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
520#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
521 EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
522#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
523 EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
524
525#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
526#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
527#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
528#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
529#define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
530#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
531#define EXT2_FEATURE_COMPAT_ANY 0xffffffff
532
533#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
534#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
535#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
536#define EXT2_FEATURE_RO_COMPAT_ANY 0xffffffff
537
538#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
539#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
540#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
541#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
542#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
543#define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
544
545#define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
546#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
547 EXT2_FEATURE_INCOMPAT_META_BG)
548#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
549 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
550 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
551#define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
552#define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
553
554/*
555 * Default values for user and/or group using reserved blocks
556 */
557#define EXT2_DEF_RESUID 0
558#define EXT2_DEF_RESGID 0
559
560/*
561 * Default mount options
562 */
563#define EXT2_DEFM_DEBUG 0x0001
564#define EXT2_DEFM_BSDGROUPS 0x0002
565#define EXT2_DEFM_XATTR_USER 0x0004
566#define EXT2_DEFM_ACL 0x0008
567#define EXT2_DEFM_UID16 0x0010
568 /* Not used by ext2, but reserved for use by ext3 */
569#define EXT3_DEFM_JMODE 0x0060
570#define EXT3_DEFM_JMODE_DATA 0x0020
571#define EXT3_DEFM_JMODE_ORDERED 0x0040
572#define EXT3_DEFM_JMODE_WBACK 0x0060
573
574/*
575 * Structure of a directory entry
576 */
577
578struct ext2_dir_entry {
579 __le32 inode; /* Inode number */
580 __le16 rec_len; /* Directory entry length */
581 __le16 name_len; /* Name length */
582 char name[]; /* File name, up to EXT2_NAME_LEN */
583};
584
585/*
586 * The new version of the directory entry. Since EXT2 structures are
587 * stored in intel byte order, and the name_len field could never be
588 * bigger than 255 chars, it's safe to reclaim the extra byte for the
589 * file_type field.
590 */
591struct ext2_dir_entry_2 {
592 __le32 inode; /* Inode number */
593 __le16 rec_len; /* Directory entry length */
594 __u8 name_len; /* Name length */
595 __u8 file_type;
596 char name[]; /* File name, up to EXT2_NAME_LEN */
597};
598
599/*
600 * Ext2 directory file types. Only the low 3 bits are used. The
601 * other bits are reserved for now.
602 */
603enum {
604 EXT2_FT_UNKNOWN = 0,
605 EXT2_FT_REG_FILE = 1,
606 EXT2_FT_DIR = 2,
607 EXT2_FT_CHRDEV = 3,
608 EXT2_FT_BLKDEV = 4,
609 EXT2_FT_FIFO = 5,
610 EXT2_FT_SOCK = 6,
611 EXT2_FT_SYMLINK = 7,
612 EXT2_FT_MAX
613};
614
615/*
616 * EXT2_DIR_PAD defines the directory entries boundaries
617 *
618 * NOTE: It must be a multiple of 4
619 */
620#define EXT2_DIR_PAD 4
621#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
622#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
623 ~EXT2_DIR_ROUND)
624#define EXT2_MAX_REC_LEN ((1<<16)-1)
625
626static inline void verify_offsets(void)
627{
628#define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
629 A(EXT2_SB_MAGIC_OFFSET, s_magic);
630 A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
631 A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
632#undef A
633}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635/*
Jan Kara50a52232005-07-12 13:58:29 -0700636 * ext2 mount options
637 */
638struct ext2_mount_options {
639 unsigned long s_mount_opt;
Eric W. Biedermanb8a9f9e2012-02-07 15:39:12 -0800640 kuid_t s_resuid;
641 kgid_t s_resgid;
Jan Kara50a52232005-07-12 13:58:29 -0700642};
643
644/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 * second extended file system inode data in memory
646 */
647struct ext2_inode_info {
648 __le32 i_data[15];
649 __u32 i_flags;
650 __u32 i_faddr;
651 __u8 i_frag_no;
652 __u8 i_frag_size;
653 __u16 i_state;
654 __u32 i_file_acl;
655 __u32 i_dir_acl;
656 __u32 i_dtime;
657
658 /*
659 * i_block_group is the number of the block group which contains
660 * this file's inode. Constant across the lifetime of the inode,
Ali Gholami Rudi88164ff2009-03-30 16:49:27 +0430661 * it is used for making block allocation decisions - we try to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 * place a file's data blocks near its inode block, and new inodes
663 * near to their parent directory's inode.
664 */
665 __u32 i_block_group;
666
Martin J. Bligha686cd82007-10-16 23:30:46 -0700667 /* block reservation info */
668 struct ext2_block_alloc_info *i_block_alloc_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 __u32 i_dir_start_lookup;
671#ifdef CONFIG_EXT2_FS_XATTR
672 /*
673 * Extended attributes can be read independently of the main file
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800674 * data. Taking i_mutex even when reading would cause contention
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 * between readers of EAs and writers of regular file data, so
676 * instead we synchronize on xattr_sem when reading or changing
677 * EAs.
678 */
679 struct rw_semaphore xattr_sem;
680#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 rwlock_t i_meta_lock;
Martin J. Bligha686cd82007-10-16 23:30:46 -0700682
683 /*
684 * truncate_mutex is for serialising ext2_truncate() against
685 * ext2_getblock(). It also protects the internals of the inode's
686 * reservation data structures: ext2_reserve_window and
687 * ext2_reserve_window_node.
688 */
689 struct mutex truncate_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 struct inode vfs_inode;
Martin J. Bligha686cd82007-10-16 23:30:46 -0700691 struct list_head i_orphan; /* unlinked but open inodes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692};
693
694/*
695 * Inode dynamic state flags
696 */
697#define EXT2_STATE_NEW 0x00000001 /* inode is newly created */
698
699
700/*
701 * Function prototypes
702 */
703
704/*
705 * Ok, these declarations are also in <linux/kernel.h> but none of the
706 * ext2 source programs needs to include it so they are duplicated here.
707 */
708
709static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
710{
711 return container_of(inode, struct ext2_inode_info, vfs_inode);
712}
713
714/* balloc.c */
715extern int ext2_bg_has_super(struct super_block *sb, int group);
716extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
Martin J. Bligha686cd82007-10-16 23:30:46 -0700717extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
718extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
719 unsigned long *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720extern void ext2_free_blocks (struct inode *, unsigned long,
721 unsigned long);
722extern unsigned long ext2_count_free_blocks (struct super_block *);
723extern unsigned long ext2_count_dirs (struct super_block *);
724extern void ext2_check_blocks_bitmap (struct super_block *);
725extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
726 unsigned int block_group,
727 struct buffer_head ** bh);
Martin J. Bligha686cd82007-10-16 23:30:46 -0700728extern void ext2_discard_reservation (struct inode *);
729extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
730extern void ext2_init_block_alloc_info(struct inode *);
731extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733/* dir.c */
734extern int ext2_add_link (struct dentry *, struct inode *);
Al Viroa9885442008-08-24 07:28:39 -0400735extern ino_t ext2_inode_by_name(struct inode *, struct qstr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736extern int ext2_make_empty(struct inode *, struct inode *);
Al Viroa9885442008-08-24 07:28:39 -0400737extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct qstr *, struct page **);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
739extern int ext2_empty_dir (struct inode *);
740extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
Jan Kara39fe7552009-06-17 16:26:20 -0700741extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743/* ialloc.c */
Al Viro3ea40bc2011-07-26 02:46:18 -0400744extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745extern void ext2_free_inode (struct inode *);
746extern unsigned long ext2_count_free_inodes (struct super_block *);
747extern void ext2_check_inodes_bitmap (struct super_block *);
748extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
749
750/* inode.c */
David Howells52fcf702008-02-07 00:15:35 -0800751extern struct inode *ext2_iget (struct super_block *, unsigned long);
Christoph Hellwiga9185b42010-03-05 09:21:37 +0100752extern int ext2_write_inode (struct inode *, struct writeback_control *);
Al Viro72edc4d2010-06-04 23:32:28 -0400753extern void ext2_evict_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755extern int ext2_setattr (struct dentry *, struct iattr *);
756extern void ext2_set_inode_flags(struct inode *inode);
Jan Kara4f99ed62007-05-08 00:31:04 -0700757extern void ext2_get_inode_flags(struct ext2_inode_info *);
Josef Bacik68c9d702008-10-03 17:32:43 -0400758extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
759 u64 start, u64 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761/* ioctl.c */
Andi Kleen14f9f7b2008-02-06 01:40:10 -0800762extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
David Howellse322ff02006-08-29 19:06:20 +0100763extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Adrian Bunk2c221292006-03-24 03:15:53 -0800765/* namei.c */
766struct dentry *ext2_get_parent(struct dentry *child);
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768/* super.c */
Joe Perchesb9075fa2011-10-31 17:11:33 -0700769extern __printf(3, 4)
770void ext2_error(struct super_block *, const char *, const char *, ...);
771extern __printf(3, 4)
772void ext2_msg(struct super_block *, const char *, const char *, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773extern void ext2_update_dynamic_rev (struct super_block *sb);
774extern void ext2_write_super (struct super_block *);
775
776/*
777 * Inodes and files operations
778 */
779
780/* dir.c */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800781extern const struct file_operations ext2_dir_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783/* file.c */
Josef Bacik02c24a82011-07-16 20:44:56 -0400784extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
785 int datasync);
Arjan van de Ven754661f2007-02-12 00:55:38 -0800786extern const struct inode_operations ext2_file_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800787extern const struct file_operations ext2_file_operations;
788extern const struct file_operations ext2_xip_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790/* inode.c */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700791extern const struct address_space_operations ext2_aops;
792extern const struct address_space_operations ext2_aops_xip;
793extern const struct address_space_operations ext2_nobh_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795/* namei.c */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800796extern const struct inode_operations ext2_dir_inode_operations;
797extern const struct inode_operations ext2_special_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799/* symlink.c */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800800extern const struct inode_operations ext2_fast_symlink_inode_operations;
801extern const struct inode_operations ext2_symlink_inode_operations;
Tobias Poschwatta6454d1f2007-11-28 16:21:45 -0800802
803static inline ext2_fsblk_t
804ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
805{
806 return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
807 le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
808}
Akinobu Mitaf312eff2011-03-23 16:42:14 -0700809
810#define ext2_set_bit __test_and_set_bit_le
811#define ext2_clear_bit __test_and_clear_bit_le
812#define ext2_test_bit test_bit_le
813#define ext2_find_first_zero_bit find_first_zero_bit_le
814#define ext2_find_next_zero_bit find_next_zero_bit_le