Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 1992, 1993, 1994, 1995
0004  * Remy Card (card@masi.ibp.fr)
0005  * Laboratoire MASI - Institut Blaise Pascal
0006  * Universite Pierre et Marie Curie (Paris VI)
0007  *
0008  *  from
0009  *
0010  *  linux/include/linux/minix_fs.h
0011  *
0012  *  Copyright (C) 1991, 1992  Linus Torvalds
0013  */
0014 #include <linux/fs.h>
0015 #include <linux/ext2_fs.h>
0016 #include <linux/blockgroup_lock.h>
0017 #include <linux/percpu_counter.h>
0018 #include <linux/rbtree.h>
0019 #include <linux/mm.h>
0020 #include <linux/highmem.h>
0021 
0022 /* XXX Here for now... not interested in restructing headers JUST now */
0023 
0024 /* data type for block offset of block group */
0025 typedef int ext2_grpblk_t;
0026 
0027 /* data type for filesystem-wide blocks number */
0028 typedef unsigned long ext2_fsblk_t;
0029 
0030 #define E2FSBLK "%lu"
0031 
0032 struct ext2_reserve_window {
0033     ext2_fsblk_t        _rsv_start; /* First byte reserved */
0034     ext2_fsblk_t        _rsv_end;   /* Last byte reserved or 0 */
0035 };
0036 
0037 struct ext2_reserve_window_node {
0038     struct rb_node      rsv_node;
0039     __u32           rsv_goal_size;
0040     __u32           rsv_alloc_hit;
0041     struct ext2_reserve_window  rsv_window;
0042 };
0043 
0044 struct ext2_block_alloc_info {
0045     /* information about reservation window */
0046     struct ext2_reserve_window_node rsv_window_node;
0047     /*
0048      * was i_next_alloc_block in ext2_inode_info
0049      * is the logical (file-relative) number of the
0050      * most-recently-allocated block in this file.
0051      * We use this for detecting linearly ascending allocation requests.
0052      */
0053     __u32           last_alloc_logical_block;
0054     /*
0055      * Was i_next_alloc_goal in ext2_inode_info
0056      * is the *physical* companion to i_next_alloc_block.
0057      * it is the physical block number of the block which was most-recently
0058      * allocated to this file.  This gives us the goal (target) for the next
0059      * allocation when we detect linearly ascending requests.
0060      */
0061     ext2_fsblk_t        last_alloc_physical_block;
0062 };
0063 
0064 #define rsv_start rsv_window._rsv_start
0065 #define rsv_end rsv_window._rsv_end
0066 
0067 struct mb_cache;
0068 
0069 /*
0070  * second extended-fs super-block data in memory
0071  */
0072 struct ext2_sb_info {
0073     unsigned long s_frag_size;  /* Size of a fragment in bytes */
0074     unsigned long s_frags_per_block;/* Number of fragments per block */
0075     unsigned long s_inodes_per_block;/* Number of inodes per block */
0076     unsigned long s_frags_per_group;/* Number of fragments in a group */
0077     unsigned long s_blocks_per_group;/* Number of blocks in a group */
0078     unsigned long s_inodes_per_group;/* Number of inodes in a group */
0079     unsigned long s_itb_per_group;  /* Number of inode table blocks per group */
0080     unsigned long s_gdb_count;  /* Number of group descriptor blocks */
0081     unsigned long s_desc_per_block; /* Number of group descriptors per block */
0082     unsigned long s_groups_count;   /* Number of groups in the fs */
0083     unsigned long s_overhead_last;  /* Last calculated overhead */
0084     unsigned long s_blocks_last;    /* Last seen block count */
0085     struct buffer_head * s_sbh; /* Buffer containing the super block */
0086     struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
0087     struct buffer_head ** s_group_desc;
0088     unsigned long  s_mount_opt;
0089     unsigned long s_sb_block;
0090     kuid_t s_resuid;
0091     kgid_t s_resgid;
0092     unsigned short s_mount_state;
0093     unsigned short s_pad;
0094     int s_addr_per_block_bits;
0095     int s_desc_per_block_bits;
0096     int s_inode_size;
0097     int s_first_ino;
0098     spinlock_t s_next_gen_lock;
0099     u32 s_next_generation;
0100     unsigned long s_dir_count;
0101     u8 *s_debts;
0102     struct percpu_counter s_freeblocks_counter;
0103     struct percpu_counter s_freeinodes_counter;
0104     struct percpu_counter s_dirs_counter;
0105     struct blockgroup_lock *s_blockgroup_lock;
0106     /* root of the per fs reservation window tree */
0107     spinlock_t s_rsv_window_lock;
0108     struct rb_root s_rsv_window_root;
0109     struct ext2_reserve_window_node s_rsv_window_head;
0110     /*
0111      * s_lock protects against concurrent modifications of s_mount_state,
0112      * s_blocks_last, s_overhead_last and the content of superblock's
0113      * buffer pointed to by sbi->s_es.
0114      *
0115      * Note: It is used in ext2_show_options() to provide a consistent view
0116      * of the mount options.
0117      */
0118     spinlock_t s_lock;
0119     struct mb_cache *s_ea_block_cache;
0120     struct dax_device *s_daxdev;
0121     u64 s_dax_part_off;
0122 };
0123 
0124 static inline spinlock_t *
0125 sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
0126 {
0127     return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
0128 }
0129 
0130 /*
0131  * Define EXT2FS_DEBUG to produce debug messages
0132  */
0133 #undef EXT2FS_DEBUG
0134 
0135 /*
0136  * Define EXT2_RESERVATION to reserve data blocks for expanding files
0137  */
0138 #define EXT2_DEFAULT_RESERVE_BLOCKS     8
0139 /*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
0140 #define EXT2_MAX_RESERVE_BLOCKS         1027
0141 #define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
0142 /*
0143  * The second extended file system version
0144  */
0145 #define EXT2FS_DATE     "95/08/09"
0146 #define EXT2FS_VERSION      "0.5b"
0147 
0148 /*
0149  * Debug code
0150  */
0151 #ifdef EXT2FS_DEBUG
0152 #   define ext2_debug(f, a...)  { \
0153                     printk ("EXT2-fs DEBUG (%s, %d): %s:", \
0154                         __FILE__, __LINE__, __func__); \
0155                     printk (f, ## a); \
0156                     }
0157 #else
0158 #   define ext2_debug(f, a...)  /**/
0159 #endif
0160 
0161 /*
0162  * Special inode numbers
0163  */
0164 #define EXT2_BAD_INO         1  /* Bad blocks inode */
0165 #define EXT2_ROOT_INO        2  /* Root inode */
0166 #define EXT2_BOOT_LOADER_INO     5  /* Boot loader inode */
0167 #define EXT2_UNDEL_DIR_INO   6  /* Undelete directory inode */
0168 
0169 /* First non-reserved inode for old ext2 filesystems */
0170 #define EXT2_GOOD_OLD_FIRST_INO 11
0171 
0172 static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
0173 {
0174     return sb->s_fs_info;
0175 }
0176 
0177 /*
0178  * Macro-instructions used to manage several block sizes
0179  */
0180 #define EXT2_MIN_BLOCK_SIZE     1024
0181 #define EXT2_MAX_BLOCK_SIZE     4096
0182 #define EXT2_MIN_BLOCK_LOG_SIZE       10
0183 #define EXT2_BLOCK_SIZE(s)      ((s)->s_blocksize)
0184 #define EXT2_ADDR_PER_BLOCK(s)      (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
0185 #define EXT2_BLOCK_SIZE_BITS(s)     ((s)->s_blocksize_bits)
0186 #define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_addr_per_block_bits)
0187 #define EXT2_INODE_SIZE(s)      (EXT2_SB(s)->s_inode_size)
0188 #define EXT2_FIRST_INO(s)       (EXT2_SB(s)->s_first_ino)
0189 
0190 /*
0191  * Macro-instructions used to manage fragments
0192  */
0193 #define EXT2_MIN_FRAG_SIZE      1024
0194 #define EXT2_MAX_FRAG_SIZE      4096
0195 #define EXT2_MIN_FRAG_LOG_SIZE        10
0196 #define EXT2_FRAG_SIZE(s)       (EXT2_SB(s)->s_frag_size)
0197 #define EXT2_FRAGS_PER_BLOCK(s)     (EXT2_SB(s)->s_frags_per_block)
0198 
0199 /*
0200  * Structure of a blocks group descriptor
0201  */
0202 struct ext2_group_desc
0203 {
0204     __le32  bg_block_bitmap;        /* Blocks bitmap block */
0205     __le32  bg_inode_bitmap;        /* Inodes bitmap block */
0206     __le32  bg_inode_table;     /* Inodes table block */
0207     __le16  bg_free_blocks_count;   /* Free blocks count */
0208     __le16  bg_free_inodes_count;   /* Free inodes count */
0209     __le16  bg_used_dirs_count; /* Directories count */
0210     __le16  bg_pad;
0211     __le32  bg_reserved[3];
0212 };
0213 
0214 /*
0215  * Macro-instructions used to manage group descriptors
0216  */
0217 #define EXT2_BLOCKS_PER_GROUP(s)    (EXT2_SB(s)->s_blocks_per_group)
0218 #define EXT2_DESC_PER_BLOCK(s)      (EXT2_SB(s)->s_desc_per_block)
0219 #define EXT2_INODES_PER_GROUP(s)    (EXT2_SB(s)->s_inodes_per_group)
0220 #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
0221 
0222 /*
0223  * Constants relative to the data blocks
0224  */
0225 #define EXT2_NDIR_BLOCKS        12
0226 #define EXT2_IND_BLOCK          EXT2_NDIR_BLOCKS
0227 #define EXT2_DIND_BLOCK         (EXT2_IND_BLOCK + 1)
0228 #define EXT2_TIND_BLOCK         (EXT2_DIND_BLOCK + 1)
0229 #define EXT2_N_BLOCKS           (EXT2_TIND_BLOCK + 1)
0230 
0231 /*
0232  * Inode flags (GETFLAGS/SETFLAGS)
0233  */
0234 #define EXT2_SECRM_FL           FS_SECRM_FL /* Secure deletion */
0235 #define EXT2_UNRM_FL            FS_UNRM_FL  /* Undelete */
0236 #define EXT2_COMPR_FL           FS_COMPR_FL /* Compress file */
0237 #define EXT2_SYNC_FL            FS_SYNC_FL  /* Synchronous updates */
0238 #define EXT2_IMMUTABLE_FL       FS_IMMUTABLE_FL /* Immutable file */
0239 #define EXT2_APPEND_FL          FS_APPEND_FL    /* writes to file may only append */
0240 #define EXT2_NODUMP_FL          FS_NODUMP_FL    /* do not dump file */
0241 #define EXT2_NOATIME_FL         FS_NOATIME_FL   /* do not update atime */
0242 /* Reserved for compression usage... */
0243 #define EXT2_DIRTY_FL           FS_DIRTY_FL
0244 #define EXT2_COMPRBLK_FL        FS_COMPRBLK_FL  /* One or more compressed clusters */
0245 #define EXT2_NOCOMP_FL          FS_NOCOMP_FL    /* Don't compress */
0246 #define EXT2_ECOMPR_FL          FS_ECOMPR_FL    /* Compression error */
0247 /* End compression flags --- maybe not all used */  
0248 #define EXT2_BTREE_FL           FS_BTREE_FL /* btree format dir */
0249 #define EXT2_INDEX_FL           FS_INDEX_FL /* hash-indexed directory */
0250 #define EXT2_IMAGIC_FL          FS_IMAGIC_FL    /* AFS directory */
0251 #define EXT2_JOURNAL_DATA_FL        FS_JOURNAL_DATA_FL /* Reserved for ext3 */
0252 #define EXT2_NOTAIL_FL          FS_NOTAIL_FL    /* file tail should not be merged */
0253 #define EXT2_DIRSYNC_FL         FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
0254 #define EXT2_TOPDIR_FL          FS_TOPDIR_FL    /* Top of directory hierarchies*/
0255 #define EXT2_RESERVED_FL        FS_RESERVED_FL  /* reserved for ext2 lib */
0256 
0257 #define EXT2_FL_USER_VISIBLE        FS_FL_USER_VISIBLE  /* User visible flags */
0258 #define EXT2_FL_USER_MODIFIABLE     FS_FL_USER_MODIFIABLE   /* User modifiable flags */
0259 
0260 /* Flags that should be inherited by new inodes from their parent. */
0261 #define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
0262                EXT2_SYNC_FL | EXT2_NODUMP_FL |\
0263                EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
0264                EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
0265                EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
0266 
0267 /* Flags that are appropriate for regular files (all but dir-specific ones). */
0268 #define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
0269 
0270 /* Flags that are appropriate for non-directories/regular files. */
0271 #define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
0272 
0273 /* Mask out flags that are inappropriate for the given type of inode. */
0274 static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
0275 {
0276     if (S_ISDIR(mode))
0277         return flags;
0278     else if (S_ISREG(mode))
0279         return flags & EXT2_REG_FLMASK;
0280     else
0281         return flags & EXT2_OTHER_FLMASK;
0282 }
0283 
0284 /*
0285  * ioctl commands
0286  */
0287 #define EXT2_IOC_GETVERSION     FS_IOC_GETVERSION
0288 #define EXT2_IOC_SETVERSION     FS_IOC_SETVERSION
0289 #define EXT2_IOC_GETRSVSZ       _IOR('f', 5, long)
0290 #define EXT2_IOC_SETRSVSZ       _IOW('f', 6, long)
0291 
0292 /*
0293  * ioctl commands in 32 bit emulation
0294  */
0295 #define EXT2_IOC32_GETVERSION       FS_IOC32_GETVERSION
0296 #define EXT2_IOC32_SETVERSION       FS_IOC32_SETVERSION
0297 
0298 /*
0299  * Structure of an inode on the disk
0300  */
0301 struct ext2_inode {
0302     __le16  i_mode;     /* File mode */
0303     __le16  i_uid;      /* Low 16 bits of Owner Uid */
0304     __le32  i_size;     /* Size in bytes */
0305     __le32  i_atime;    /* Access time */
0306     __le32  i_ctime;    /* Creation time */
0307     __le32  i_mtime;    /* Modification time */
0308     __le32  i_dtime;    /* Deletion Time */
0309     __le16  i_gid;      /* Low 16 bits of Group Id */
0310     __le16  i_links_count;  /* Links count */
0311     __le32  i_blocks;   /* Blocks count */
0312     __le32  i_flags;    /* File flags */
0313     union {
0314         struct {
0315             __le32  l_i_reserved1;
0316         } linux1;
0317         struct {
0318             __le32  h_i_translator;
0319         } hurd1;
0320         struct {
0321             __le32  m_i_reserved1;
0322         } masix1;
0323     } osd1;             /* OS dependent 1 */
0324     __le32  i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
0325     __le32  i_generation;   /* File version (for NFS) */
0326     __le32  i_file_acl; /* File ACL */
0327     __le32  i_dir_acl;  /* Directory ACL */
0328     __le32  i_faddr;    /* Fragment address */
0329     union {
0330         struct {
0331             __u8    l_i_frag;   /* Fragment number */
0332             __u8    l_i_fsize;  /* Fragment size */
0333             __u16   i_pad1;
0334             __le16  l_i_uid_high;   /* these 2 fields    */
0335             __le16  l_i_gid_high;   /* were reserved2[0] */
0336             __u32   l_i_reserved2;
0337         } linux2;
0338         struct {
0339             __u8    h_i_frag;   /* Fragment number */
0340             __u8    h_i_fsize;  /* Fragment size */
0341             __le16  h_i_mode_high;
0342             __le16  h_i_uid_high;
0343             __le16  h_i_gid_high;
0344             __le32  h_i_author;
0345         } hurd2;
0346         struct {
0347             __u8    m_i_frag;   /* Fragment number */
0348             __u8    m_i_fsize;  /* Fragment size */
0349             __u16   m_pad1;
0350             __u32   m_i_reserved2[2];
0351         } masix2;
0352     } osd2;             /* OS dependent 2 */
0353 };
0354 
0355 #define i_size_high i_dir_acl
0356 
0357 #define i_reserved1 osd1.linux1.l_i_reserved1
0358 #define i_frag      osd2.linux2.l_i_frag
0359 #define i_fsize     osd2.linux2.l_i_fsize
0360 #define i_uid_low   i_uid
0361 #define i_gid_low   i_gid
0362 #define i_uid_high  osd2.linux2.l_i_uid_high
0363 #define i_gid_high  osd2.linux2.l_i_gid_high
0364 #define i_reserved2 osd2.linux2.l_i_reserved2
0365 
0366 /*
0367  * File system states
0368  */
0369 #define EXT2_VALID_FS           0x0001  /* Unmounted cleanly */
0370 #define EXT2_ERROR_FS           0x0002  /* Errors detected */
0371 #define EFSCORRUPTED            EUCLEAN /* Filesystem is corrupted */
0372 
0373 /*
0374  * Mount flags
0375  */
0376 #define EXT2_MOUNT_OLDALLOC     0x000002  /* Don't use the new Orlov allocator */
0377 #define EXT2_MOUNT_GRPID        0x000004  /* Create files with directory's group */
0378 #define EXT2_MOUNT_DEBUG        0x000008  /* Some debugging messages */
0379 #define EXT2_MOUNT_ERRORS_CONT      0x000010  /* Continue on errors */
0380 #define EXT2_MOUNT_ERRORS_RO        0x000020  /* Remount fs ro on errors */
0381 #define EXT2_MOUNT_ERRORS_PANIC     0x000040  /* Panic on errors */
0382 #define EXT2_MOUNT_MINIX_DF     0x000080  /* Mimics the Minix statfs */
0383 #define EXT2_MOUNT_NOBH         0x000100  /* No buffer_heads */
0384 #define EXT2_MOUNT_NO_UID32     0x000200  /* Disable 32-bit UIDs */
0385 #define EXT2_MOUNT_XATTR_USER       0x004000  /* Extended user attributes */
0386 #define EXT2_MOUNT_POSIX_ACL        0x008000  /* POSIX Access Control Lists */
0387 #define EXT2_MOUNT_XIP          0x010000  /* Obsolete, use DAX */
0388 #define EXT2_MOUNT_USRQUOTA     0x020000  /* user quota */
0389 #define EXT2_MOUNT_GRPQUOTA     0x040000  /* group quota */
0390 #define EXT2_MOUNT_RESERVATION      0x080000  /* Preallocation */
0391 #define EXT2_MOUNT_DAX          0x100000  /* Direct Access */
0392 
0393 
0394 #define clear_opt(o, opt)       o &= ~EXT2_MOUNT_##opt
0395 #define set_opt(o, opt)         o |= EXT2_MOUNT_##opt
0396 #define test_opt(sb, opt)       (EXT2_SB(sb)->s_mount_opt & \
0397                      EXT2_MOUNT_##opt)
0398 /*
0399  * Maximal mount counts between two filesystem checks
0400  */
0401 #define EXT2_DFL_MAX_MNT_COUNT      20  /* Allow 20 mounts */
0402 #define EXT2_DFL_CHECKINTERVAL      0   /* Don't use interval check */
0403 
0404 /*
0405  * Behaviour when detecting errors
0406  */
0407 #define EXT2_ERRORS_CONTINUE        1   /* Continue execution */
0408 #define EXT2_ERRORS_RO          2   /* Remount fs read-only */
0409 #define EXT2_ERRORS_PANIC       3   /* Panic */
0410 #define EXT2_ERRORS_DEFAULT     EXT2_ERRORS_CONTINUE
0411 
0412 /*
0413  * Structure of the super block
0414  */
0415 struct ext2_super_block {
0416     __le32  s_inodes_count;     /* Inodes count */
0417     __le32  s_blocks_count;     /* Blocks count */
0418     __le32  s_r_blocks_count;   /* Reserved blocks count */
0419     __le32  s_free_blocks_count;    /* Free blocks count */
0420     __le32  s_free_inodes_count;    /* Free inodes count */
0421     __le32  s_first_data_block; /* First Data Block */
0422     __le32  s_log_block_size;   /* Block size */
0423     __le32  s_log_frag_size;    /* Fragment size */
0424     __le32  s_blocks_per_group; /* # Blocks per group */
0425     __le32  s_frags_per_group;  /* # Fragments per group */
0426     __le32  s_inodes_per_group; /* # Inodes per group */
0427     __le32  s_mtime;        /* Mount time */
0428     __le32  s_wtime;        /* Write time */
0429     __le16  s_mnt_count;        /* Mount count */
0430     __le16  s_max_mnt_count;    /* Maximal mount count */
0431     __le16  s_magic;        /* Magic signature */
0432     __le16  s_state;        /* File system state */
0433     __le16  s_errors;       /* Behaviour when detecting errors */
0434     __le16  s_minor_rev_level;  /* minor revision level */
0435     __le32  s_lastcheck;        /* time of last check */
0436     __le32  s_checkinterval;    /* max. time between checks */
0437     __le32  s_creator_os;       /* OS */
0438     __le32  s_rev_level;        /* Revision level */
0439     __le16  s_def_resuid;       /* Default uid for reserved blocks */
0440     __le16  s_def_resgid;       /* Default gid for reserved blocks */
0441     /*
0442      * These fields are for EXT2_DYNAMIC_REV superblocks only.
0443      *
0444      * Note: the difference between the compatible feature set and
0445      * the incompatible feature set is that if there is a bit set
0446      * in the incompatible feature set that the kernel doesn't
0447      * know about, it should refuse to mount the filesystem.
0448      * 
0449      * e2fsck's requirements are more strict; if it doesn't know
0450      * about a feature in either the compatible or incompatible
0451      * feature set, it must abort and not try to meddle with
0452      * things it doesn't understand...
0453      */
0454     __le32  s_first_ino;        /* First non-reserved inode */
0455     __le16   s_inode_size;      /* size of inode structure */
0456     __le16  s_block_group_nr;   /* block group # of this superblock */
0457     __le32  s_feature_compat;   /* compatible feature set */
0458     __le32  s_feature_incompat;     /* incompatible feature set */
0459     __le32  s_feature_ro_compat;    /* readonly-compatible feature set */
0460     __u8    s_uuid[16];     /* 128-bit uuid for volume */
0461     char    s_volume_name[16];  /* volume name */
0462     char    s_last_mounted[64];     /* directory where last mounted */
0463     __le32  s_algorithm_usage_bitmap; /* For compression */
0464     /*
0465      * Performance hints.  Directory preallocation should only
0466      * happen if the EXT2_COMPAT_PREALLOC flag is on.
0467      */
0468     __u8    s_prealloc_blocks;  /* Nr of blocks to try to preallocate*/
0469     __u8    s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
0470     __u16   s_padding1;
0471     /*
0472      * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
0473      */
0474     __u8    s_journal_uuid[16]; /* uuid of journal superblock */
0475     __u32   s_journal_inum;     /* inode number of journal file */
0476     __u32   s_journal_dev;      /* device number of journal file */
0477     __u32   s_last_orphan;      /* start of list of inodes to delete */
0478     __u32   s_hash_seed[4];     /* HTREE hash seed */
0479     __u8    s_def_hash_version; /* Default hash version to use */
0480     __u8    s_reserved_char_pad;
0481     __u16   s_reserved_word_pad;
0482     __le32  s_default_mount_opts;
0483     __le32  s_first_meta_bg;    /* First metablock block group */
0484     __u32   s_reserved[190];    /* Padding to the end of the block */
0485 };
0486 
0487 /*
0488  * Codes for operating systems
0489  */
0490 #define EXT2_OS_LINUX       0
0491 #define EXT2_OS_HURD        1
0492 #define EXT2_OS_MASIX       2
0493 #define EXT2_OS_FREEBSD     3
0494 #define EXT2_OS_LITES       4
0495 
0496 /*
0497  * Revision levels
0498  */
0499 #define EXT2_GOOD_OLD_REV   0   /* The good old (original) format */
0500 #define EXT2_DYNAMIC_REV    1   /* V2 format w/ dynamic inode sizes */
0501 
0502 #define EXT2_CURRENT_REV    EXT2_GOOD_OLD_REV
0503 #define EXT2_MAX_SUPP_REV   EXT2_DYNAMIC_REV
0504 
0505 #define EXT2_GOOD_OLD_INODE_SIZE 128
0506 
0507 /*
0508  * Feature set definitions
0509  */
0510 
0511 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)            \
0512     ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
0513 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask)         \
0514     ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
0515 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)          \
0516     ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
0517 #define EXT2_SET_COMPAT_FEATURE(sb,mask)            \
0518     EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
0519 #define EXT2_SET_RO_COMPAT_FEATURE(sb,mask)         \
0520     EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
0521 #define EXT2_SET_INCOMPAT_FEATURE(sb,mask)          \
0522     EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
0523 #define EXT2_CLEAR_COMPAT_FEATURE(sb,mask)          \
0524     EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
0525 #define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask)           \
0526     EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
0527 #define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask)            \
0528     EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
0529 
0530 #define EXT2_FEATURE_COMPAT_DIR_PREALLOC    0x0001
0531 #define EXT2_FEATURE_COMPAT_IMAGIC_INODES   0x0002
0532 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL     0x0004
0533 #define EXT2_FEATURE_COMPAT_EXT_ATTR        0x0008
0534 #define EXT2_FEATURE_COMPAT_RESIZE_INO      0x0010
0535 #define EXT2_FEATURE_COMPAT_DIR_INDEX       0x0020
0536 #define EXT2_FEATURE_COMPAT_ANY         0xffffffff
0537 
0538 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
0539 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE   0x0002
0540 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR    0x0004
0541 #define EXT2_FEATURE_RO_COMPAT_ANY      0xffffffff
0542 
0543 #define EXT2_FEATURE_INCOMPAT_COMPRESSION   0x0001
0544 #define EXT2_FEATURE_INCOMPAT_FILETYPE      0x0002
0545 #define EXT3_FEATURE_INCOMPAT_RECOVER       0x0004
0546 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV   0x0008
0547 #define EXT2_FEATURE_INCOMPAT_META_BG       0x0010
0548 #define EXT2_FEATURE_INCOMPAT_ANY       0xffffffff
0549 
0550 #define EXT2_FEATURE_COMPAT_SUPP    EXT2_FEATURE_COMPAT_EXT_ATTR
0551 #define EXT2_FEATURE_INCOMPAT_SUPP  (EXT2_FEATURE_INCOMPAT_FILETYPE| \
0552                      EXT2_FEATURE_INCOMPAT_META_BG)
0553 #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
0554                      EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
0555                      EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
0556 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED  ~EXT2_FEATURE_RO_COMPAT_SUPP
0557 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED   ~EXT2_FEATURE_INCOMPAT_SUPP
0558 
0559 /*
0560  * Default values for user and/or group using reserved blocks
0561  */
0562 #define EXT2_DEF_RESUID     0
0563 #define EXT2_DEF_RESGID     0
0564 
0565 /*
0566  * Default mount options
0567  */
0568 #define EXT2_DEFM_DEBUG     0x0001
0569 #define EXT2_DEFM_BSDGROUPS 0x0002
0570 #define EXT2_DEFM_XATTR_USER    0x0004
0571 #define EXT2_DEFM_ACL       0x0008
0572 #define EXT2_DEFM_UID16     0x0010
0573     /* Not used by ext2, but reserved for use by ext3 */
0574 #define EXT3_DEFM_JMODE     0x0060 
0575 #define EXT3_DEFM_JMODE_DATA    0x0020
0576 #define EXT3_DEFM_JMODE_ORDERED 0x0040
0577 #define EXT3_DEFM_JMODE_WBACK   0x0060
0578 
0579 /*
0580  * Structure of a directory entry
0581  */
0582 
0583 struct ext2_dir_entry {
0584     __le32  inode;          /* Inode number */
0585     __le16  rec_len;        /* Directory entry length */
0586     __le16  name_len;       /* Name length */
0587     char    name[];         /* File name, up to EXT2_NAME_LEN */
0588 };
0589 
0590 /*
0591  * The new version of the directory entry.  Since EXT2 structures are
0592  * stored in intel byte order, and the name_len field could never be
0593  * bigger than 255 chars, it's safe to reclaim the extra byte for the
0594  * file_type field.
0595  */
0596 struct ext2_dir_entry_2 {
0597     __le32  inode;          /* Inode number */
0598     __le16  rec_len;        /* Directory entry length */
0599     __u8    name_len;       /* Name length */
0600     __u8    file_type;
0601     char    name[];         /* File name, up to EXT2_NAME_LEN */
0602 };
0603 
0604 /*
0605  * EXT2_DIR_PAD defines the directory entries boundaries
0606  *
0607  * NOTE: It must be a multiple of 4
0608  */
0609 #define EXT2_DIR_PAD            4
0610 #define EXT2_DIR_ROUND          (EXT2_DIR_PAD - 1)
0611 #define EXT2_DIR_REC_LEN(name_len)  (((name_len) + 8 + EXT2_DIR_ROUND) & \
0612                      ~EXT2_DIR_ROUND)
0613 #define EXT2_MAX_REC_LEN        ((1<<16)-1)
0614 
0615 static inline void verify_offsets(void)
0616 {
0617 #define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
0618     A(EXT2_SB_MAGIC_OFFSET, s_magic);
0619     A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
0620     A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
0621 #undef A
0622 }
0623 
0624 /*
0625  * ext2 mount options
0626  */
0627 struct ext2_mount_options {
0628     unsigned long s_mount_opt;
0629     kuid_t s_resuid;
0630     kgid_t s_resgid;
0631 };
0632 
0633 /*
0634  * second extended file system inode data in memory
0635  */
0636 struct ext2_inode_info {
0637     __le32  i_data[15];
0638     __u32   i_flags;
0639     __u32   i_faddr;
0640     __u8    i_frag_no;
0641     __u8    i_frag_size;
0642     __u16   i_state;
0643     __u32   i_file_acl;
0644     __u32   i_dir_acl;
0645     __u32   i_dtime;
0646 
0647     /*
0648      * i_block_group is the number of the block group which contains
0649      * this file's inode.  Constant across the lifetime of the inode,
0650      * it is used for making block allocation decisions - we try to
0651      * place a file's data blocks near its inode block, and new inodes
0652      * near to their parent directory's inode.
0653      */
0654     __u32   i_block_group;
0655 
0656     /* block reservation info */
0657     struct ext2_block_alloc_info *i_block_alloc_info;
0658 
0659     __u32   i_dir_start_lookup;
0660 #ifdef CONFIG_EXT2_FS_XATTR
0661     /*
0662      * Extended attributes can be read independently of the main file
0663      * data. Taking i_mutex even when reading would cause contention
0664      * between readers of EAs and writers of regular file data, so
0665      * instead we synchronize on xattr_sem when reading or changing
0666      * EAs.
0667      */
0668     struct rw_semaphore xattr_sem;
0669 #endif
0670     rwlock_t i_meta_lock;
0671 
0672     /*
0673      * truncate_mutex is for serialising ext2_truncate() against
0674      * ext2_getblock().  It also protects the internals of the inode's
0675      * reservation data structures: ext2_reserve_window and
0676      * ext2_reserve_window_node.
0677      */
0678     struct mutex truncate_mutex;
0679     struct inode    vfs_inode;
0680     struct list_head i_orphan;  /* unlinked but open inodes */
0681 #ifdef CONFIG_QUOTA
0682     struct dquot *i_dquot[MAXQUOTAS];
0683 #endif
0684 };
0685 
0686 /*
0687  * Inode dynamic state flags
0688  */
0689 #define EXT2_STATE_NEW          0x00000001 /* inode is newly created */
0690 
0691 
0692 /*
0693  * Function prototypes
0694  */
0695 
0696 /*
0697  * Ok, these declarations are also in <linux/kernel.h> but none of the
0698  * ext2 source programs needs to include it so they are duplicated here.
0699  */
0700 
0701 static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
0702 {
0703     return container_of(inode, struct ext2_inode_info, vfs_inode);
0704 }
0705 
0706 /* balloc.c */
0707 extern int ext2_bg_has_super(struct super_block *sb, int group);
0708 extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
0709 extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
0710 extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
0711                 unsigned long *, int *);
0712 extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
0713                  unsigned int count);
0714 extern void ext2_free_blocks (struct inode *, unsigned long,
0715                   unsigned long);
0716 extern unsigned long ext2_count_free_blocks (struct super_block *);
0717 extern unsigned long ext2_count_dirs (struct super_block *);
0718 extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
0719                             unsigned int block_group,
0720                             struct buffer_head ** bh);
0721 extern void ext2_discard_reservation (struct inode *);
0722 extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
0723 extern void ext2_init_block_alloc_info(struct inode *);
0724 extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
0725 
0726 /* dir.c */
0727 extern int ext2_add_link (struct dentry *, struct inode *);
0728 extern int ext2_inode_by_name(struct inode *dir,
0729                   const struct qstr *child, ino_t *ino);
0730 extern int ext2_make_empty(struct inode *, struct inode *);
0731 extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
0732                         struct page **, void **res_page_addr);
0733 extern int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page,
0734                  char *kaddr);
0735 extern int ext2_empty_dir (struct inode *);
0736 extern struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct page **p, void **pa);
0737 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, void *,
0738               struct inode *, int);
0739 static inline void ext2_put_page(struct page *page, void *page_addr)
0740 {
0741     kunmap_local(page_addr);
0742     put_page(page);
0743 }
0744 
0745 /* ialloc.c */
0746 extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
0747 extern void ext2_free_inode (struct inode *);
0748 extern unsigned long ext2_count_free_inodes (struct super_block *);
0749 extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
0750 
0751 /* inode.c */
0752 extern struct inode *ext2_iget (struct super_block *, unsigned long);
0753 extern int ext2_write_inode (struct inode *, struct writeback_control *);
0754 extern void ext2_evict_inode(struct inode *);
0755 extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
0756 extern int ext2_setattr (struct user_namespace *, struct dentry *, struct iattr *);
0757 extern int ext2_getattr (struct user_namespace *, const struct path *,
0758              struct kstat *, u32, unsigned int);
0759 extern void ext2_set_inode_flags(struct inode *inode);
0760 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
0761                u64 start, u64 len);
0762 
0763 /* ioctl.c */
0764 extern int ext2_fileattr_get(struct dentry *dentry, struct fileattr *fa);
0765 extern int ext2_fileattr_set(struct user_namespace *mnt_userns,
0766                  struct dentry *dentry, struct fileattr *fa);
0767 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
0768 extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
0769 
0770 /* namei.c */
0771 struct dentry *ext2_get_parent(struct dentry *child);
0772 
0773 /* super.c */
0774 extern __printf(3, 4)
0775 void ext2_error(struct super_block *, const char *, const char *, ...);
0776 extern __printf(3, 4)
0777 void ext2_msg(struct super_block *, const char *, const char *, ...);
0778 extern void ext2_update_dynamic_rev (struct super_block *sb);
0779 extern void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
0780                 int wait);
0781 
0782 /*
0783  * Inodes and files operations
0784  */
0785 
0786 /* dir.c */
0787 extern const struct file_operations ext2_dir_operations;
0788 
0789 /* file.c */
0790 extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
0791               int datasync);
0792 extern const struct inode_operations ext2_file_inode_operations;
0793 extern const struct file_operations ext2_file_operations;
0794 
0795 /* inode.c */
0796 extern void ext2_set_file_ops(struct inode *inode);
0797 extern const struct address_space_operations ext2_aops;
0798 extern const struct iomap_ops ext2_iomap_ops;
0799 
0800 /* namei.c */
0801 extern const struct inode_operations ext2_dir_inode_operations;
0802 extern const struct inode_operations ext2_special_inode_operations;
0803 
0804 /* symlink.c */
0805 extern const struct inode_operations ext2_fast_symlink_inode_operations;
0806 extern const struct inode_operations ext2_symlink_inode_operations;
0807 
0808 static inline ext2_fsblk_t
0809 ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
0810 {
0811     return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
0812         le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
0813 }
0814 
0815 static inline ext2_fsblk_t
0816 ext2_group_last_block_no(struct super_block *sb, unsigned long group_no)
0817 {
0818     struct ext2_sb_info *sbi = EXT2_SB(sb);
0819 
0820     if (group_no == sbi->s_groups_count - 1)
0821         return le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
0822     else
0823         return ext2_group_first_block_no(sb, group_no) +
0824             EXT2_BLOCKS_PER_GROUP(sb) - 1;
0825 }
0826 
0827 #define ext2_set_bit    __test_and_set_bit_le
0828 #define ext2_clear_bit  __test_and_clear_bit_le
0829 #define ext2_test_bit   test_bit_le
0830 #define ext2_find_first_zero_bit    find_first_zero_bit_le
0831 #define ext2_find_next_zero_bit     find_next_zero_bit_le