/* * This must be called with sbi->s_lock held.
*/ void ext2_update_dynamic_rev(struct super_block *sb)
{ struct ext2_super_block *es = EXT2_SB(sb)->s_es;
if (le32_to_cpu(es->s_rev_level) > EXT2_GOOD_OLD_REV) return;
ext2_msg(sb, KERN_WARNING, "warning: updating to rev %d because of " "new feature flag, running e2fsck is recommended",
EXT2_DYNAMIC_REV);
es->s_first_ino = cpu_to_le32(EXT2_GOOD_OLD_FIRST_INO);
es->s_inode_size = cpu_to_le16(EXT2_GOOD_OLD_INODE_SIZE);
es->s_rev_level = cpu_to_le32(EXT2_DYNAMIC_REV); /* leave es->s_feature_*compat flags alone */ /* es->s_uuid will be set by e2fsck if empty */
/* * The rest of the superblock fields should be zero, and if not it * means they are likely already in use, so leave them alone. We * can leave it up to e2fsck to clean up any inconsistencies there.
*/
}
#ifdef CONFIG_QUOTA staticint ext2_quota_off(struct super_block *sb, int type);
staticvoid ext2_quota_off_umount(struct super_block *sb)
{ int type;
for (type = 0; type < MAXQUOTAS; type++)
ext2_quota_off(sb, type);
} #else staticinlinevoid ext2_quota_off_umount(struct super_block *sb)
{
} #endif
staticvoid ext2_put_super (struct super_block * sb)
{ int db_count; int i; struct ext2_sb_info *sbi = EXT2_SB(sb);
staticvoid destroy_inodecache(void)
{ /* * Make sure all delayed rcu free inodes are flushed before we * destroy cache.
*/
rcu_barrier();
kmem_cache_destroy(ext2_inode_cachep);
}
if (ino < EXT2_FIRST_INO(sb) && ino != EXT2_ROOT_INO) return ERR_PTR(-ESTALE); if (ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) return ERR_PTR(-ESTALE);
/* * ext2_iget isn't quite right if the inode is currently unallocated! * However ext2_iget currently does appropriate checks to handle stale * inodes so everything is OK.
*/
inode = ext2_iget(sb, ino); if (IS_ERR(inode)) return ERR_CAST(inode); if (generation && inode->i_generation != generation) { /* we didn't find the right inode.. */
iput(inode); return ERR_PTR(-ESTALE);
} return inode;
}
staticstruct dentry *ext2_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
{ return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
ext2_nfs_get_inode);
}
staticstruct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
{ return generic_fh_to_parent(sb, fid, fh_len, fh_type,
ext2_nfs_get_inode);
}
switch (opt) { case Opt_bsd_df:
ctx_clear_mount_opt(ctx, EXT2_MOUNT_MINIX_DF); break; case Opt_minix_df:
ctx_set_mount_opt(ctx, EXT2_MOUNT_MINIX_DF); break; case Opt_grpid:
ctx_set_mount_opt(ctx, EXT2_MOUNT_GRPID); break; case Opt_nogrpid:
ctx_clear_mount_opt(ctx, EXT2_MOUNT_GRPID); break; case Opt_resuid:
ctx->s_resuid = result.uid;
ctx->spec |= EXT2_SPEC_s_resuid; break; case Opt_resgid:
ctx->s_resgid = result.gid;
ctx->spec |= EXT2_SPEC_s_resgid; break; case Opt_sb: /* Note that this is silently ignored on remount */
ctx->s_sb_block = result.uint_32; break; case Opt_errors:
ctx_clear_mount_opt(ctx, EXT2_MOUNT_ERRORS_MASK);
ctx_set_mount_opt(ctx, result.uint_32); break; case Opt_nouid32:
ctx_set_mount_opt(ctx, EXT2_MOUNT_NO_UID32); break; case Opt_debug:
ctx_set_mount_opt(ctx, EXT2_MOUNT_DEBUG); break; case Opt_oldalloc:
ctx_set_mount_opt(ctx, EXT2_MOUNT_OLDALLOC); break; case Opt_orlov:
ctx_clear_mount_opt(ctx, EXT2_MOUNT_OLDALLOC); break; case Opt_nobh:
ext2_msg_fc(fc, KERN_INFO, "nobh option not supported\n"); break; #ifdef CONFIG_EXT2_FS_XATTR case Opt_user_xattr: if (!result.negated)
ctx_set_mount_opt(ctx, EXT2_MOUNT_XATTR_USER); else
ctx_clear_mount_opt(ctx, EXT2_MOUNT_XATTR_USER); break; #else case Opt_user_xattr:
ext2_msg_fc(fc, KERN_INFO, "(no)user_xattr options not supported"); break; #endif #ifdef CONFIG_EXT2_FS_POSIX_ACL case Opt_acl: if (!result.negated)
ctx_set_mount_opt(ctx, EXT2_MOUNT_POSIX_ACL); else
ctx_clear_mount_opt(ctx, EXT2_MOUNT_POSIX_ACL); break; #else case Opt_acl:
ext2_msg_fc(fc, KERN_INFO, "(no)acl options not supported"); break; #endif case Opt_xip:
ext2_msg_fc(fc, KERN_INFO, "use dax instead of xip");
ctx_set_mount_opt(ctx, EXT2_MOUNT_XIP);
fallthrough; case Opt_dax: #ifdef CONFIG_FS_DAX
ext2_msg_fc(fc, KERN_WARNING, "DAX enabled. Warning: DAX support in ext2 driver is deprecated" " and will be removed at the end of 2025. Please use ext4 driver instead.");
ctx_set_mount_opt(ctx, EXT2_MOUNT_DAX); #else
ext2_msg_fc(fc, KERN_INFO, "dax option not supported"); #endif break;
#ifdefined(CONFIG_QUOTA) case Opt_quota: case Opt_usrquota:
ctx_set_mount_opt(ctx, EXT2_MOUNT_USRQUOTA); break;
case Opt_grpquota:
ctx_set_mount_opt(ctx, EXT2_MOUNT_GRPQUOTA); break; #else case Opt_quota: case Opt_usrquota: case Opt_grpquota:
ext2_msg_fc(fc, KERN_INFO, "quota operations not supported"); break; #endif case Opt_reservation: if (!result.negated) {
ctx_set_mount_opt(ctx, EXT2_MOUNT_RESERVATION);
ext2_msg_fc(fc, KERN_INFO, "reservations ON");
} else {
ctx_clear_mount_opt(ctx, EXT2_MOUNT_RESERVATION);
ext2_msg_fc(fc, KERN_INFO, "reservations OFF");
} break; case Opt_ignore: break; default: return -EINVAL;
} return 0;
}
staticint ext2_setup_super (struct super_block * sb, struct ext2_super_block * es, int read_only)
{ int res = 0; struct ext2_sb_info *sbi = EXT2_SB(sb);
if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
ext2_msg(sb, KERN_ERR, "error: revision level too high, " "forcing read-only mode");
res = SB_RDONLY;
} if (read_only) return res; if (!(sbi->s_mount_state & EXT2_VALID_FS))
ext2_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, " "running e2fsck is recommended"); elseif ((sbi->s_mount_state & EXT2_ERROR_FS))
ext2_msg(sb, KERN_WARNING, "warning: mounting fs with errors, " "running e2fsck is recommended"); elseif ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
le16_to_cpu(es->s_mnt_count) >=
(unsignedshort) (__s16) le16_to_cpu(es->s_max_mnt_count))
ext2_msg(sb, KERN_WARNING, "warning: maximal mount count reached, " "running e2fsck is recommended"); elseif (le32_to_cpu(es->s_checkinterval) &&
(le32_to_cpu(es->s_lastcheck) +
le32_to_cpu(es->s_checkinterval) <=
ktime_get_real_seconds()))
ext2_msg(sb, KERN_WARNING, "warning: checktime reached, " "running e2fsck is recommended"); if (!le16_to_cpu(es->s_max_mnt_count))
es->s_max_mnt_count = cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
le16_add_cpu(&es->s_mnt_count, 1); if (test_opt (sb, DEBUG))
ext2_msg(sb, KERN_INFO, "%s, %s, bs=%lu, gc=%lu, " "bpg=%lu, ipg=%lu, mo=%04lx]",
EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
sbi->s_groups_count,
EXT2_BLOCKS_PER_GROUP(sb),
EXT2_INODES_PER_GROUP(sb),
sbi->s_mount_opt); return res;
}
for (i = 0; i < sbi->s_groups_count; i++) { struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i);
ext2_fsblk_t last_block = ext2_group_last_block_no(sb, i);
if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
le32_to_cpu(gdp->bg_block_bitmap) > last_block)
{
ext2_error (sb, "ext2_check_descriptors", "Block bitmap for group %d" " not in group (block %lu)!",
i, (unsignedlong) le32_to_cpu(gdp->bg_block_bitmap)); return 0;
} if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
{
ext2_error (sb, "ext2_check_descriptors", "Inode bitmap for group %d" " not in group (block %lu)!",
i, (unsignedlong) le32_to_cpu(gdp->bg_inode_bitmap)); return 0;
} if (le32_to_cpu(gdp->bg_inode_table) < first_block ||
le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group - 1 >
last_block)
{
ext2_error (sb, "ext2_check_descriptors", "Inode table for group %d" " not in group (block %lu)!",
i, (unsignedlong) le32_to_cpu(gdp->bg_inode_table)); return 0;
}
} return 1;
}
/* * Maximal file size. There is a direct, and {,double-,triple-}indirect * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. * We need to be 1 filesystem block less than the 2^32 sector limit.
*/ static loff_t ext2_max_size(int bits)
{
loff_t res = EXT2_NDIR_BLOCKS; int meta_blocks; unsignedint upper_limit; unsignedint ppb = 1 << (bits-2);
/* This is calculated to be the largest file size for a * dense, file such that the total number of * sectors in the file, including data and all indirect blocks, * does not exceed 2^32 -1 * __u32 i_blocks representing the total number of * 512 bytes blocks of the file
*/
upper_limit = (1LL << 32) - 1;
/* total blocks in file system block size */
upper_limit >>= (bits - 9);
/* Compute how many blocks we can address by block tree */
res += 1LL << (bits-2);
res += 1LL << (2*(bits-2));
res += 1LL << (3*(bits-2)); /* Compute how many metadata blocks are needed */
meta_blocks = 1;
meta_blocks += 1 + ppb;
meta_blocks += 1 + ppb + ppb * ppb; /* Does block tree limit file size? */ if (res + meta_blocks <= upper_limit) goto check_lfs;
res = upper_limit; /* How many metadata blocks are needed for addressing upper_limit? */
upper_limit -= EXT2_NDIR_BLOCKS; /* indirect blocks */
meta_blocks = 1;
upper_limit -= ppb; /* double indirect blocks */ if (upper_limit < ppb * ppb) {
meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb);
res -= meta_blocks; goto check_lfs;
}
meta_blocks += 1 + ppb;
upper_limit -= ppb * ppb; /* tripple indirect blocks for the rest */
meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb) +
DIV_ROUND_UP(upper_limit, ppb*ppb);
res -= meta_blocks;
check_lfs:
res <<= bits; if (res > MAX_LFS_FILESIZE)
res = MAX_LFS_FILESIZE;
/* * Set all mount options either from defaults on disk, or from parsed * options. Parsed/specified options override on-disk defaults.
*/ staticvoid ext2_set_options(struct fs_context *fc, struct ext2_sb_info *sbi)
{ struct ext2_fs_context *ctx = fc->fs_private; struct ext2_super_block *es = sbi->s_es; unsignedlong def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
/* Copy parsed mount options to sbi */
sbi->s_mount_opt = ctx->vals_s_mount_opt;
/* Use in-superblock defaults only if not specified during parsing */ if (!ctx_parsed_mount_opt(ctx, EXT2_MOUNT_DEBUG) &&
def_mount_opts & EXT2_DEFM_DEBUG)
set_opt(sbi->s_mount_opt, DEBUG);
if (!ctx_parsed_mount_opt(ctx, EXT2_MOUNT_GRPID) &&
def_mount_opts & EXT2_DEFM_BSDGROUPS)
set_opt(sbi->s_mount_opt, GRPID);
if (!ctx_parsed_mount_opt(ctx, EXT2_MOUNT_NO_UID32) &&
def_mount_opts & EXT2_DEFM_UID16)
set_opt(sbi->s_mount_opt, NO_UID32);
/* * See what the current blocksize for the device is, and * use that as the blocksize. Otherwise (or if the blocksize * is smaller than the default) use the default. * This is important for devices that have a hardware * sectorsize that is larger than the default.
*/
blocksize = sb_min_blocksize(sb, BLOCK_SIZE); if (!blocksize) {
ext2_msg(sb, KERN_ERR, "error: unable to set blocksize"); goto failed_sbi;
}
/* * If the superblock doesn't start on a hardware sector boundary, * calculate the offset.
*/ if (blocksize != BLOCK_SIZE) {
logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
offset = (sb_block*BLOCK_SIZE) % blocksize;
} else {
logic_sb_block = sb_block;
}
if (!(bh = sb_bread(sb, logic_sb_block))) {
ext2_msg(sb, KERN_ERR, "error: unable to read superblock"); goto failed_sbi;
} /* * Note: s_es must be initialized as soon as possible because * some ext2 macro-instructions depend on its value
*/
es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
sbi->s_es = es;
sb->s_magic = le16_to_cpu(es->s_magic);
if (sb->s_magic != EXT2_SUPER_MAGIC) goto cantfind_ext2;
if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
(EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
EXT2_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
EXT2_HAS_INCOMPAT_FEATURE(sb, ~0U)))
ext2_msg(sb, KERN_WARNING, "warning: feature flags set on rev 0 fs, " "running e2fsck is recommended"); /* * Check feature flags regardless of the revision level, since we * previously didn't change the revision level when setting the flags, * so there is a chance incompat flags are set on a rev 0 filesystem.
*/
features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP); if (features) {
ext2_msg(sb, KERN_ERR, "error: couldn't mount because of " "unsupported optional features (%x)",
le32_to_cpu(features)); goto failed_mount;
} if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of " "unsupported optional features (%x)",
le32_to_cpu(features)); goto failed_mount;
}
if (sbi->s_blocks_per_group > sb->s_blocksize * 8) {
ext2_msg(sb, KERN_ERR, "error: #blocks per group too big: %lu",
sbi->s_blocks_per_group); goto failed_mount;
} /* At least inode table, bitmaps, and sb have to fit in one group */ if (sbi->s_blocks_per_group <= sbi->s_itb_per_group + 3) {
ext2_msg(sb, KERN_ERR, "error: #blocks per group smaller than metadata size: %lu <= %lu",
sbi->s_blocks_per_group, sbi->s_inodes_per_group + 3); goto failed_mount;
} if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
sbi->s_inodes_per_group > sb->s_blocksize * 8) {
ext2_msg(sb, KERN_ERR, "error: invalid #inodes per group: %lu",
sbi->s_inodes_per_group); goto failed_mount;
} if (sb_bdev_nr_blocks(sb) < le32_to_cpu(es->s_blocks_count)) {
ext2_msg(sb, KERN_ERR, "bad geometry: block count %u exceeds size of device (%u blocks)",
le32_to_cpu(es->s_blocks_count),
(unsigned)sb_bdev_nr_blocks(sb)); goto failed_mount;
}
sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
le32_to_cpu(es->s_first_data_block) - 1)
/ EXT2_BLOCKS_PER_GROUP(sb)) + 1; if ((u64)sbi->s_groups_count * sbi->s_inodes_per_group !=
le32_to_cpu(es->s_inodes_count)) {
ext2_msg(sb, KERN_ERR, "error: invalid #inodes: %u vs computed %llu",
le32_to_cpu(es->s_inodes_count),
(u64)sbi->s_groups_count * sbi->s_inodes_per_group); goto failed_mount;
}
db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
EXT2_DESC_PER_BLOCK(sb);
sbi->s_group_desc = kvmalloc_array(db_count, sizeof(struct buffer_head *),
GFP_KERNEL); if (sbi->s_group_desc == NULL) {
ret = -ENOMEM;
ext2_msg(sb, KERN_ERR, "error: not enough memory"); goto failed_mount;
}
bgl_lock_init(sbi->s_blockgroup_lock);
sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL); if (!sbi->s_debts) {
ret = -ENOMEM;
ext2_msg(sb, KERN_ERR, "error: not enough memory"); goto failed_mount_group_desc;
} for (i = 0; i < db_count; i++) {
block = descriptor_loc(sb, logic_sb_block, i);
sbi->s_group_desc[i] = sb_bread(sb, block); if (!sbi->s_group_desc[i]) { for (j = 0; j < i; j++)
brelse (sbi->s_group_desc[j]);
ext2_msg(sb, KERN_ERR, "error: unable to read group descriptors"); goto failed_mount_group_desc;
}
} if (!ext2_check_descriptors (sb)) {
ext2_msg(sb, KERN_ERR, "group descriptors corrupted"); goto failed_mount2;
}
sbi->s_gdb_count = db_count;
get_random_bytes(&sbi->s_next_generation, sizeof(u32));
spin_lock_init(&sbi->s_next_gen_lock);
/* per filesystem reservation list head & lock */
spin_lock_init(&sbi->s_rsv_window_lock);
sbi->s_rsv_window_root = RB_ROOT; /* * Add a single, static dummy reservation to the start of the * reservation window list --- it gives us a placeholder for * append-at-start-of-list which makes the allocation logic * _much_ simpler.
*/
sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
sbi->s_rsv_window_head.rsv_alloc_hit = 0;
sbi->s_rsv_window_head.rsv_goal_size = 0;
ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
err = percpu_counter_init(&sbi->s_freeblocks_counter,
ext2_count_free_blocks(sb), GFP_KERNEL); if (!err) {
err = percpu_counter_init(&sbi->s_freeinodes_counter,
ext2_count_free_inodes(sb), GFP_KERNEL);
} if (!err) {
err = percpu_counter_init(&sbi->s_dirs_counter,
ext2_count_dirs(sb), GFP_KERNEL);
} if (err) {
ret = err;
ext2_msg(sb, KERN_ERR, "error: insufficient memory"); goto failed_mount3;
}
#ifdef CONFIG_EXT2_FS_XATTR
sbi->s_ea_block_cache = ext2_xattr_create_cache(); if (!sbi->s_ea_block_cache) {
ret = -ENOMEM;
ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache"); goto failed_mount3;
} #endif /* * set up enough so that it can read an inode
*/
sb->s_op = &ext2_sops;
sb->s_export_op = &ext2_export_ops;
sb->s_xattr = ext2_xattr_handlers;
if (buffer_write_io_error(sbh)) { /* * Oh, dear. A previous attempt to write the * superblock failed. This could happen because the * USB device was yanked out. Or it could happen to * be a transient write error and maybe the block will * be remapped. Nothing we can do but to retry the * write and hope for the best.
*/
ext2_msg(sb, KERN_ERR, "previous I/O error to superblock detected");
clear_buffer_write_io_error(sbh);
set_buffer_uptodate(sbh);
}
}
void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es, int wait)
{
ext2_clear_super_error(sb);
spin_lock(&EXT2_SB(sb)->s_lock);
es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
es->s_wtime = cpu_to_le32(ktime_get_real_seconds()); /* unlock before we do IO */
spin_unlock(&EXT2_SB(sb)->s_lock);
mark_buffer_dirty(EXT2_SB(sb)->s_sbh); if (wait)
sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
}
/* * In the second extended file system, it is not necessary to * write the super block since we use a mapping of the * disk super block in a buffer. * * However, this function is still used to set the fs valid * flags to 0. We need to set this flag to 0 since the fs * may have been checked while mounted and e2fsck may have * set s_state to EXT2_VALID_FS after some corrections.
*/ staticint ext2_sync_fs(struct super_block *sb, int wait)
{ struct ext2_sb_info *sbi = EXT2_SB(sb); struct ext2_super_block *es = EXT2_SB(sb)->s_es;
/* * Write quota structures to quota file, sync_blockdev() will write * them to disk later
*/
dquot_writeback_dquots(sb, -1);
/* * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared * because we have unattached inodes and thus filesystem is not fully * consistent.
*/ if (atomic_long_read(&sb->s_remove_count)) {
ext2_sync_fs(sb, 1); return 0;
} /* Set EXT2_FS_VALID flag */
spin_lock(&sbi->s_lock);
sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
spin_unlock(&sbi->s_lock);
ext2_sync_super(sb, sbi->s_es, 1);
return 0;
}
staticint ext2_unfreeze(struct super_block *sb)
{ /* Just write sb to clear EXT2_VALID_FS flag */
ext2_write_super(sb);
return 0;
}
staticvoid ext2_write_super(struct super_block *sb)
{ if (!sb_rdonly(sb))
ext2_sync_fs(sb, 1);
}
spin_lock(&sbi->s_lock);
es = sbi->s_es; if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
ext2_msg(sb, KERN_WARNING, "warning: refusing change of " "dax flag with busy inodes while remounting");
new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
} if ((bool)(flags & SB_RDONLY) == sb_rdonly(sb)) goto out_set; if (flags & SB_RDONLY) { if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
!(sbi->s_mount_state & EXT2_VALID_FS)) goto out_set;
/* * OK, we are remounting a valid rw partition rdonly, so set * the rdonly flag and then mark the partition as valid again.
*/
es->s_state = cpu_to_le16(sbi->s_mount_state);
es->s_mtime = cpu_to_le32(ktime_get_real_seconds());
spin_unlock(&sbi->s_lock);
err = dquot_suspend(sb, -1); if (err < 0) return err;
ext2_sync_super(sb, es, 1);
} else {
__le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
~EXT2_FEATURE_RO_COMPAT_SUPP); if (ret) {
spin_unlock(&sbi->s_lock);
ext2_msg(sb, KERN_WARNING, "warning: couldn't remount RDWR because of " "unsupported optional features (%x).",
le32_to_cpu(ret)); return -EROFS;
} /* * Mounting a RDONLY partition read-write, so reread and * store the current valid flag. (It may have been changed * by e2fsck since we originally mounted the partition.)
*/
sbi->s_mount_state = le16_to_cpu(es->s_state); if (!ext2_setup_super (sb, es, 0))
sb->s_flags &= ~SB_RDONLY;
spin_unlock(&sbi->s_lock);
if (test_opt (sb, MINIX_DF))
sbi->s_overhead_last = 0; elseif (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) { unsignedlong i, overhead = 0;
smp_rmb();
/* * Compute the overhead (FS structures). This is constant * for a given filesystem unless the number of block groups * changes so we cache the previous value until it does.
*/
/* * All of the blocks before first_data_block are * overhead
*/
overhead = le32_to_cpu(es->s_first_data_block);
/* * Add the overhead attributed to the superblock and * block group descriptors. If the sparse superblocks * feature is turned on, then not all groups have this.
*/ for (i = 0; i < sbi->s_groups_count; i++)
overhead += ext2_bg_has_super(sb, i) +
ext2_bg_num_gdb(sb, i);
/* * Every block group has an inode bitmap, a block * bitmap, and an inode table.
*/
overhead += (sbi->s_groups_count *
(2 + sbi->s_itb_per_group));
sbi->s_overhead_last = overhead;
smp_wmb();
sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
}
/* Read data from quotafile - avoid pagecache and such because we cannot afford * acquiring the locks... As quota files are never truncated and quota code * itself serializes the operations (and no one else should touch the files)
* we don't have to be afraid of races */ static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
size_t len, loff_t off)
{ struct inode *inode = sb_dqopt(sb)->files[type];
sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb); int err = 0; int offset = off & (sb->s_blocksize - 1); int tocopy;
size_t toread; struct buffer_head tmp_bh; struct buffer_head *bh;
loff_t i_size = i_size_read(inode);
if (off > i_size) return 0; if (off+len > i_size)
len = i_size-off;
toread = len; while (toread > 0) {
tocopy = min_t(size_t, sb->s_blocksize - offset, toread);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.