19 #include <linux/module.h>
20 #include <linux/string.h>
22 #include <linux/slab.h>
26 #include <linux/random.h>
34 #include <asm/uaccess.h>
61 ext2_sync_super(sb, es, 1);
70 sb->
s_id,
function, &vaf);
75 panic(
"EXT2-fs: panic from previous error\n");
78 "error: remounting filesystem read-only");
94 printk(
"%sEXT2-fs (%s): %pV\n", prefix, sb->
s_id, &vaf);
110 "warning: updating to rev %d because of "
111 "new feature flag, running e2fsck is recommended",
141 spin_unlock(&sbi->
s_lock);
142 ext2_sync_super(sb, es, 1);
145 for (i = 0; i < db_count; i++)
178 static void ext2_destroy_inode(
struct inode *inode)
183 static void init_once(
void *
foo)
188 #ifdef CONFIG_EXT2_FS_XATTR
195 static int init_inodecache(
void)
202 if (ext2_inode_cachep ==
NULL)
207 static void destroy_inodecache(
void)
217 static int ext2_show_options(
struct seq_file *seq,
struct dentry *root)
222 unsigned long def_mount_opts;
250 seq_puts(seq,
",errors=remount-ro");
264 #ifdef CONFIG_EXT2_FS_XATTR
273 #ifdef CONFIG_EXT2_FS_POSIX_ACL
283 #if defined(CONFIG_QUOTA)
291 #if defined(CONFIG_EXT2_FS_XIP)
299 spin_unlock(&sbi->
s_lock);
309 .alloc_inode = ext2_alloc_inode,
310 .destroy_inode = ext2_destroy_inode,
313 .put_super = ext2_put_super,
314 .sync_fs = ext2_sync_fs,
315 .freeze_fs = ext2_freeze,
316 .unfreeze_fs = ext2_unfreeze,
317 .statfs = ext2_statfs,
318 .remount_fs = ext2_remount,
319 .show_options = ext2_show_options,
321 .quota_read = ext2_quota_read,
322 .quota_write = ext2_quota_write,
326 static struct inode *ext2_nfs_get_inode(
struct super_block *sb,
333 if (ino >
le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
343 return ERR_CAST(inode);
353 int fh_len,
int fh_type)
360 int fh_len,
int fh_type)
367 .fh_to_dentry = ext2_fh_to_dentry,
368 .fh_to_parent = ext2_fh_to_parent,
372 static unsigned long get_sb_block(
void **
data)
374 unsigned long sb_block;
375 char *
options = (
char *) *data;
377 if (!options ||
strncmp(options,
"sb=", 3) != 0)
381 if (*options && *options !=
',') {
382 printk(
"EXT2-fs: Invalid sb specification: %s\n",
388 *data = (
void *) options;
435 static int parse_options(
char *options,
struct super_block *sb)
447 while ((p =
strsep (&options,
",")) !=
NULL) {
470 if (!uid_valid(uid)) {
481 if (!gid_valid(gid)) {
524 #ifdef CONFIG_EXT2_FS_XATTR
538 #ifdef CONFIG_EXT2_FS_POSIX_ACL
549 "(no)acl options not supported");
553 #ifdef CONFIG_EXT2_FS_XIP
560 #if defined(CONFIG_QUOTA)
574 "quota operations not supported");
595 static int ext2_setup_super (
struct super_block * sb,
604 "error: revision level too high, "
605 "forcing read-only mode");
612 "warning: mounting unchecked fs, "
613 "running e2fsck is recommended");
616 "warning: mounting fs with errors, "
617 "running e2fsck is recommended");
622 "warning: maximal mount count reached, "
623 "running e2fsck is recommended");
628 "warning: checktime reached, "
629 "running e2fsck is recommended");
635 "bpg=%lu, ipg=%lu, mo=%04lx]",
645 static int ext2_check_descriptors(
struct super_block *sb)
654 ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i);
660 last_block = first_block +
667 "Block bitmap for group %d"
668 " not in group (block %lu)!",
676 "Inode bitmap for group %d"
677 " not in group (block %lu)!",
686 "Inode table for group %d"
687 " not in group (block %lu)!",
700 static loff_t ext2_max_size(
int bits)
713 upper_limit = (1
LL << 32) - 1;
716 upper_limit >>= (bits - 9);
722 meta_blocks += 1 + (1
LL << (bits-2));
724 meta_blocks += 1 + (1
LL << (bits-2)) + (1
LL << (2*(bits-2)));
726 upper_limit -= meta_blocks;
727 upper_limit <<=
bits;
730 res += 1
LL << (2*(
bits-2));
731 res += 1
LL << (3*(
bits-2));
733 if (res > upper_limit)
736 if (res > MAX_LFS_FILESIZE)
737 res = MAX_LFS_FILESIZE;
742 static unsigned long descriptor_loc(
struct super_block *sb,
743 unsigned long logic_sb_block,
747 unsigned long bg, first_meta_bg;
754 return (logic_sb_block + nr + 1);
759 return ext2_group_first_block_no(sb, bg) + has_super;
762 static int ext2_fill_super(
struct super_block *sb,
void *data,
int silent)
764 struct buffer_head * bh;
769 unsigned long sb_block = get_sb_block(&data);
770 unsigned long logic_sb_block;
772 unsigned long def_mount_opts;
814 logic_sb_block = (sb_block*
BLOCK_SIZE) / blocksize;
817 logic_sb_block = sb_block;
820 if (!(bh = sb_bread(sb, logic_sb_block))) {
839 if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
843 #ifdef CONFIG_EXT2_FS_XATTR
844 if (def_mount_opts & EXT2_DEFM_XATTR_USER)
847 #ifdef CONFIG_EXT2_FS_POSIX_ACL
848 if (def_mount_opts & EXT2_DEFM_ACL)
864 if (!parse_options((
char *) data, sb))
879 "warning: feature flags set on rev 0 fs, "
880 "running e2fsck is recommended");
889 "unsupported optional features (%x)",
896 "unsupported optional features (%x)",
906 "error: unsupported blocksize for xip");
916 "error: bad blocksize %d", blocksize);
920 logic_sb_block = (sb_block*
BLOCK_SIZE) / blocksize;
922 bh = sb_bread(sb, logic_sb_block);
925 "superblock on 2nd try");
949 "error: unsupported inode size: %d",
992 "error: fragsize %lu != blocksize %lu"
993 "(not supported yet)",
1000 "error: #blocks per group too big: %lu",
1006 "error: #fragments per group too big: %lu",
1012 "error: #inodes per group too big: %lu",
1033 goto failed_mount_group_desc;
1035 for (i = 0; i < db_count; i++) {
1036 block = descriptor_loc(sb, logic_sb_block, i);
1039 for (j = 0; j <
i; j++)
1042 "error: unable to read group descriptors");
1043 goto failed_mount_group_desc;
1046 if (!ext2_check_descriptors (sb)) {
1086 sb->
s_op = &ext2_sops;
1097 ret = PTR_ERR(root);
1114 "warning: mounting ext3 filesystem as ext2");
1123 "error: can't find an ext2 filesystem on dev %s.",
1131 for (i = 0; i < db_count; i++)
1133 failed_mount_group_desc:
1146 static void ext2_clear_super_error(
struct super_block *sb)
1148 struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
1150 if (buffer_write_io_error(sbh)) {
1160 "previous I/O error to superblock detected\n");
1161 clear_buffer_write_io_error(sbh);
1162 set_buffer_uptodate(sbh);
1169 ext2_clear_super_error(sb);
1170 spin_lock(&EXT2_SB(sb)->s_lock);
1175 spin_unlock(&EXT2_SB(sb)->s_lock);
1191 static int ext2_sync_fs(
struct super_block *sb,
int wait)
1207 spin_unlock(&sbi->
s_lock);
1208 ext2_sync_super(sb, es, wait);
1222 ext2_sync_fs(sb, 1);
1228 spin_unlock(&sbi->
s_lock);
1229 ext2_sync_super(sb, sbi->
s_es, 1);
1245 ext2_sync_fs(sb, 1);
1248 static int ext2_remount (
struct super_block * sb,
int *
flags,
char * data)
1254 unsigned long old_sb_flags;
1268 if (!parse_options(data, sb)) {
1281 "warning: unsupported blocksize for xip");
1289 "xip flag with busy inodes while remounting");
1294 spin_unlock(&sbi->
s_lock);
1297 if (*flags & MS_RDONLY) {
1300 spin_unlock(&sbi->
s_lock);
1310 spin_unlock(&sbi->
s_lock);
1312 err = dquot_suspend(sb, -1);
1318 ext2_sync_super(sb, es, 1);
1324 "warning: couldn't remount RDWR because of "
1325 "unsupported optional features (%x).",
1336 if (!ext2_setup_super (sb, es, 0))
1338 spin_unlock(&sbi->
s_lock);
1351 spin_unlock(&sbi->
s_lock);
1367 unsigned long i, overhead = 0;
1417 buf->
f_fsid.
val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
1418 spin_unlock(&sbi->
s_lock);
1423 int flags,
const char *dev_name,
void *data)
1425 return mount_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
1435 size_t len, loff_t off)
1437 struct inode *inode = sb_dqopt(sb)->files[
type];
1443 struct buffer_head tmp_bh;
1444 struct buffer_head *bh;
1445 loff_t i_size = i_size_read(inode);
1449 if (off+len > i_size)
1452 while (toread > 0) {
1461 if (!buffer_mapped(&tmp_bh))
1464 bh = sb_bread(sb, tmp_bh.b_blocknr);
1467 memcpy(data, bh->b_data+offset, tocopy);
1480 const char *data,
size_t len, loff_t off)
1482 struct inode *inode = sb_dqopt(sb)->files[
type];
1487 size_t towrite = len;
1488 struct buffer_head tmp_bh;
1489 struct buffer_head *bh;
1491 while (towrite > 0) {
1500 bh = sb_bread(sb, tmp_bh.b_blocknr);
1502 bh = sb_getblk(sb, tmp_bh.b_blocknr);
1508 memcpy(bh->b_data+offset, data, tocopy);
1510 set_buffer_uptodate(bh);
1522 if (inode->
i_size < off+len-towrite)
1523 i_size_write(inode, off+len-towrite);
1526 mark_inode_dirty(inode);
1527 return len - towrite;
1535 .mount = ext2_mount,
1540 static int __init init_ext2_fs(
void)
1545 err = init_inodecache();
1553 destroy_inodecache();
1559 static void __exit exit_ext2_fs(
void)
1562 destroy_inodecache();