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