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