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