2 * linux/fs/ext4/super.c
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
11 * linux/fs/minix/inode.c
13 * Copyright (C) 1991, 1992 Linus Torvalds
15 * Big-endian to little-endian byte-swapping/bitmaps by
16 * David S. Miller (davem@caip.rutgers.edu), 1995
19 #include <linux/module.h>
20 #include <linux/string.h>
22 #include <linux/time.h>
23 #include <linux/jbd2.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/blkdev.h>
27 #include <linux/parser.h>
28 #include <linux/smp_lock.h>
29 #include <linux/buffer_head.h>
30 #include <linux/exportfs.h>
31 #include <linux/vfs.h>
32 #include <linux/random.h>
33 #include <linux/mount.h>
34 #include <linux/namei.h>
35 #include <linux/quotaops.h>
36 #include <linux/seq_file.h>
37 #include <linux/proc_fs.h>
38 #include <linux/marker.h>
39 #include <linux/log2.h>
40 #include <linux/crc16.h>
41 #include <asm/uaccess.h>
44 #include "ext4_jbd2.h"
50 struct proc_dir_entry *ext4_proc_root;
52 static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
53 unsigned long journal_devnum);
54 static int ext4_create_journal(struct super_block *, struct ext4_super_block *,
56 static void ext4_commit_super(struct super_block *sb,
57 struct ext4_super_block *es, int sync);
58 static void ext4_mark_recovery_complete(struct super_block *sb,
59 struct ext4_super_block *es);
60 static void ext4_clear_journal_err(struct super_block *sb,
61 struct ext4_super_block *es);
62 static int ext4_sync_fs(struct super_block *sb, int wait);
63 static const char *ext4_decode_error(struct super_block *sb, int errno,
65 static int ext4_remount(struct super_block *sb, int *flags, char *data);
66 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
67 static void ext4_unlockfs(struct super_block *sb);
68 static void ext4_write_super(struct super_block *sb);
69 static void ext4_write_super_lockfs(struct super_block *sb);
72 ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
73 struct ext4_group_desc *bg)
75 return le32_to_cpu(bg->bg_block_bitmap_lo) |
76 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
77 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
80 ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
81 struct ext4_group_desc *bg)
83 return le32_to_cpu(bg->bg_inode_bitmap_lo) |
84 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
85 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
88 ext4_fsblk_t ext4_inode_table(struct super_block *sb,
89 struct ext4_group_desc *bg)
91 return le32_to_cpu(bg->bg_inode_table_lo) |
92 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
93 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
96 void ext4_block_bitmap_set(struct super_block *sb,
97 struct ext4_group_desc *bg, ext4_fsblk_t blk)
99 bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
100 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
101 bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
104 void ext4_inode_bitmap_set(struct super_block *sb,
105 struct ext4_group_desc *bg, ext4_fsblk_t blk)
107 bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
108 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
109 bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
112 void ext4_inode_table_set(struct super_block *sb,
113 struct ext4_group_desc *bg, ext4_fsblk_t blk)
115 bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
116 if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
117 bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
121 * Wrappers for jbd2_journal_start/end.
123 * The only special thing we need to do here is to make sure that all
124 * journal_end calls result in the superblock being marked dirty, so
125 * that sync() will call the filesystem's write_super callback if
128 handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
132 if (sb->s_flags & MS_RDONLY)
133 return ERR_PTR(-EROFS);
135 /* Special case here: if the journal has aborted behind our
136 * backs (eg. EIO in the commit thread), then we still need to
137 * take the FS itself readonly cleanly. */
138 journal = EXT4_SB(sb)->s_journal;
139 if (is_journal_aborted(journal)) {
140 ext4_abort(sb, __func__,
141 "Detected aborted journal");
142 return ERR_PTR(-EROFS);
145 return jbd2_journal_start(journal, nblocks);
149 * The only special thing we need to do here is to make sure that all
150 * jbd2_journal_stop calls result in the superblock being marked dirty, so
151 * that sync() will call the filesystem's write_super callback if
154 int __ext4_journal_stop(const char *where, handle_t *handle)
156 struct super_block *sb;
160 sb = handle->h_transaction->t_journal->j_private;
162 rc = jbd2_journal_stop(handle);
167 __ext4_std_error(sb, where, err);
171 void ext4_journal_abort_handle(const char *caller, const char *err_fn,
172 struct buffer_head *bh, handle_t *handle, int err)
175 const char *errstr = ext4_decode_error(NULL, err, nbuf);
178 BUFFER_TRACE(bh, "abort");
183 if (is_handle_aborted(handle))
186 printk(KERN_ERR "%s: aborting transaction: %s in %s\n",
187 caller, errstr, err_fn);
189 jbd2_journal_abort_handle(handle);
192 /* Deal with the reporting of failure conditions on a filesystem such as
193 * inconsistencies detected or read IO failures.
195 * On ext2, we can store the error state of the filesystem in the
196 * superblock. That is not possible on ext4, because we may have other
197 * write ordering constraints on the superblock which prevent us from
198 * writing it out straight away; and given that the journal is about to
199 * be aborted, we can't rely on the current, or future, transactions to
200 * write out the superblock safely.
202 * We'll just use the jbd2_journal_abort() error code to record an error in
203 * the journal instead. On recovery, the journal will compain about
204 * that error until we've noted it down and cleared it.
207 static void ext4_handle_error(struct super_block *sb)
209 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
211 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
212 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
214 if (sb->s_flags & MS_RDONLY)
217 if (!test_opt(sb, ERRORS_CONT)) {
218 journal_t *journal = EXT4_SB(sb)->s_journal;
220 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
222 jbd2_journal_abort(journal, -EIO);
224 if (test_opt(sb, ERRORS_RO)) {
225 printk(KERN_CRIT "Remounting filesystem read-only\n");
226 sb->s_flags |= MS_RDONLY;
228 ext4_commit_super(sb, es, 1);
229 if (test_opt(sb, ERRORS_PANIC))
230 panic("EXT4-fs (device %s): panic forced after error\n",
234 void ext4_error(struct super_block *sb, const char *function,
235 const char *fmt, ...)
240 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
245 ext4_handle_error(sb);
248 static const char *ext4_decode_error(struct super_block *sb, int errno,
255 errstr = "IO failure";
258 errstr = "Out of memory";
261 if (!sb || EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT)
262 errstr = "Journal has aborted";
264 errstr = "Readonly filesystem";
267 /* If the caller passed in an extra buffer for unknown
268 * errors, textualise them now. Else we just return
271 /* Check for truncated error codes... */
272 if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
281 /* __ext4_std_error decodes expected errors from journaling functions
282 * automatically and invokes the appropriate error response. */
284 void __ext4_std_error(struct super_block *sb, const char *function, int errno)
289 /* Special case: if the error is EROFS, and we're not already
290 * inside a transaction, then there's really no point in logging
292 if (errno == -EROFS && journal_current_handle() == NULL &&
293 (sb->s_flags & MS_RDONLY))
296 errstr = ext4_decode_error(sb, errno, nbuf);
297 printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n",
298 sb->s_id, function, errstr);
300 ext4_handle_error(sb);
304 * ext4_abort is a much stronger failure handler than ext4_error. The
305 * abort function may be used to deal with unrecoverable failures such
306 * as journal IO errors or ENOMEM at a critical moment in log management.
308 * We unconditionally force the filesystem into an ABORT|READONLY state,
309 * unless the error response on the fs has been set to panic in which
310 * case we take the easy way out and panic immediately.
313 void ext4_abort(struct super_block *sb, const char *function,
314 const char *fmt, ...)
318 printk(KERN_CRIT "ext4_abort called.\n");
321 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
326 if (test_opt(sb, ERRORS_PANIC))
327 panic("EXT4-fs panic from previous error\n");
329 if (sb->s_flags & MS_RDONLY)
332 printk(KERN_CRIT "Remounting filesystem read-only\n");
333 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
334 sb->s_flags |= MS_RDONLY;
335 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
336 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
339 void ext4_warning(struct super_block *sb, const char *function,
340 const char *fmt, ...)
345 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ",
352 void ext4_update_dynamic_rev(struct super_block *sb)
354 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
356 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
359 ext4_warning(sb, __func__,
360 "updating to rev %d because of new feature flag, "
361 "running e2fsck is recommended",
364 es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
365 es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
366 es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
367 /* leave es->s_feature_*compat flags alone */
368 /* es->s_uuid will be set by e2fsck if empty */
371 * The rest of the superblock fields should be zero, and if not it
372 * means they are likely already in use, so leave them alone. We
373 * can leave it up to e2fsck to clean up any inconsistencies there.
377 int ext4_update_compat_feature(handle_t *handle,
378 struct super_block *sb, __u32 compat)
381 if (!EXT4_HAS_COMPAT_FEATURE(sb, compat)) {
382 err = ext4_journal_get_write_access(handle,
386 EXT4_SET_COMPAT_FEATURE(sb, compat);
389 BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
390 "call ext4_journal_dirty_met adata");
391 err = ext4_journal_dirty_metadata(handle,
397 int ext4_update_rocompat_feature(handle_t *handle,
398 struct super_block *sb, __u32 rocompat)
401 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, rocompat)) {
402 err = ext4_journal_get_write_access(handle,
406 EXT4_SET_RO_COMPAT_FEATURE(sb, rocompat);
409 BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
410 "call ext4_journal_dirty_met adata");
411 err = ext4_journal_dirty_metadata(handle,
417 int ext4_update_incompat_feature(handle_t *handle,
418 struct super_block *sb, __u32 incompat)
421 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, incompat)) {
422 err = ext4_journal_get_write_access(handle,
426 EXT4_SET_INCOMPAT_FEATURE(sb, incompat);
429 BUFFER_TRACE(EXT4_SB(sb)->s_sbh,
430 "call ext4_journal_dirty_met adata");
431 err = ext4_journal_dirty_metadata(handle,
438 * Open the external journal device
440 static struct block_device *ext4_blkdev_get(dev_t dev)
442 struct block_device *bdev;
443 char b[BDEVNAME_SIZE];
445 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
451 printk(KERN_ERR "EXT4: failed to open journal device %s: %ld\n",
452 __bdevname(dev, b), PTR_ERR(bdev));
457 * Release the journal device
459 static int ext4_blkdev_put(struct block_device *bdev)
462 return blkdev_put(bdev);
465 static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
467 struct block_device *bdev;
470 bdev = sbi->journal_bdev;
472 ret = ext4_blkdev_put(bdev);
473 sbi->journal_bdev = NULL;
478 static inline struct inode *orphan_list_entry(struct list_head *l)
480 return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
483 static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
487 printk(KERN_ERR "sb orphan head is %d\n",
488 le32_to_cpu(sbi->s_es->s_last_orphan));
490 printk(KERN_ERR "sb_info orphan list:\n");
491 list_for_each(l, &sbi->s_orphan) {
492 struct inode *inode = orphan_list_entry(l);
494 "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
495 inode->i_sb->s_id, inode->i_ino, inode,
496 inode->i_mode, inode->i_nlink,
501 static void ext4_put_super(struct super_block *sb)
503 struct ext4_sb_info *sbi = EXT4_SB(sb);
504 struct ext4_super_block *es = sbi->s_es;
508 ext4_ext_release(sb);
509 ext4_xattr_put_super(sb);
510 jbd2_journal_destroy(sbi->s_journal);
511 sbi->s_journal = NULL;
512 if (!(sb->s_flags & MS_RDONLY)) {
513 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
514 es->s_state = cpu_to_le16(sbi->s_mount_state);
515 BUFFER_TRACE(sbi->s_sbh, "marking dirty");
516 mark_buffer_dirty(sbi->s_sbh);
517 ext4_commit_super(sb, es, 1);
520 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
521 remove_proc_entry(sb->s_id, ext4_proc_root);
524 for (i = 0; i < sbi->s_gdb_count; i++)
525 brelse(sbi->s_group_desc[i]);
526 kfree(sbi->s_group_desc);
527 kfree(sbi->s_flex_groups);
528 percpu_counter_destroy(&sbi->s_freeblocks_counter);
529 percpu_counter_destroy(&sbi->s_freeinodes_counter);
530 percpu_counter_destroy(&sbi->s_dirs_counter);
531 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
534 for (i = 0; i < MAXQUOTAS; i++)
535 kfree(sbi->s_qf_names[i]);
538 /* Debugging code just in case the in-memory inode orphan list
539 * isn't empty. The on-disk one can be non-empty if we've
540 * detected an error and taken the fs readonly, but the
541 * in-memory list had better be clean by this point. */
542 if (!list_empty(&sbi->s_orphan))
543 dump_orphan_list(sb, sbi);
544 J_ASSERT(list_empty(&sbi->s_orphan));
546 invalidate_bdev(sb->s_bdev);
547 if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
549 * Invalidate the journal device's buffers. We don't want them
550 * floating about in memory - the physical journal device may
551 * hotswapped, and it breaks the `ro-after' testing code.
553 sync_blockdev(sbi->journal_bdev);
554 invalidate_bdev(sbi->journal_bdev);
555 ext4_blkdev_remove(sbi);
557 sb->s_fs_info = NULL;
562 static struct kmem_cache *ext4_inode_cachep;
565 * Called inside transaction, so use GFP_NOFS
567 static struct inode *ext4_alloc_inode(struct super_block *sb)
569 struct ext4_inode_info *ei;
571 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
574 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
575 ei->i_acl = EXT4_ACL_NOT_CACHED;
576 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
578 ei->vfs_inode.i_version = 1;
579 ei->vfs_inode.i_data.writeback_index = 0;
580 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
581 INIT_LIST_HEAD(&ei->i_prealloc_list);
582 spin_lock_init(&ei->i_prealloc_lock);
583 jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode);
584 ei->i_reserved_data_blocks = 0;
585 ei->i_reserved_meta_blocks = 0;
586 ei->i_allocated_meta_blocks = 0;
587 ei->i_delalloc_reserved_flag = 0;
588 spin_lock_init(&(ei->i_block_reservation_lock));
589 return &ei->vfs_inode;
592 static void ext4_destroy_inode(struct inode *inode)
594 if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
595 printk("EXT4 Inode %p: orphan list check failed!\n",
597 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
598 EXT4_I(inode), sizeof(struct ext4_inode_info),
602 kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
605 static void init_once(void *foo)
607 struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
609 INIT_LIST_HEAD(&ei->i_orphan);
610 #ifdef CONFIG_EXT4DEV_FS_XATTR
611 init_rwsem(&ei->xattr_sem);
613 init_rwsem(&ei->i_data_sem);
614 inode_init_once(&ei->vfs_inode);
617 static int init_inodecache(void)
619 ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
620 sizeof(struct ext4_inode_info),
621 0, (SLAB_RECLAIM_ACCOUNT|
624 if (ext4_inode_cachep == NULL)
629 static void destroy_inodecache(void)
631 kmem_cache_destroy(ext4_inode_cachep);
634 static void ext4_clear_inode(struct inode *inode)
636 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
637 if (EXT4_I(inode)->i_acl &&
638 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
639 posix_acl_release(EXT4_I(inode)->i_acl);
640 EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
642 if (EXT4_I(inode)->i_default_acl &&
643 EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
644 posix_acl_release(EXT4_I(inode)->i_default_acl);
645 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
648 ext4_discard_preallocations(inode);
649 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
650 &EXT4_I(inode)->jinode);
653 static inline void ext4_show_quota_options(struct seq_file *seq,
654 struct super_block *sb)
656 #if defined(CONFIG_QUOTA)
657 struct ext4_sb_info *sbi = EXT4_SB(sb);
659 if (sbi->s_jquota_fmt)
660 seq_printf(seq, ",jqfmt=%s",
661 (sbi->s_jquota_fmt == QFMT_VFS_OLD) ? "vfsold" : "vfsv0");
663 if (sbi->s_qf_names[USRQUOTA])
664 seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
666 if (sbi->s_qf_names[GRPQUOTA])
667 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
669 if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA)
670 seq_puts(seq, ",usrquota");
672 if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)
673 seq_puts(seq, ",grpquota");
679 * - it's set to a non-default value OR
680 * - if the per-sb default is different from the global default
682 static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
685 unsigned long def_mount_opts;
686 struct super_block *sb = vfs->mnt_sb;
687 struct ext4_sb_info *sbi = EXT4_SB(sb);
688 struct ext4_super_block *es = sbi->s_es;
690 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
691 def_errors = le16_to_cpu(es->s_errors);
693 if (sbi->s_sb_block != 1)
694 seq_printf(seq, ",sb=%llu", sbi->s_sb_block);
695 if (test_opt(sb, MINIX_DF))
696 seq_puts(seq, ",minixdf");
697 if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS))
698 seq_puts(seq, ",grpid");
699 if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS))
700 seq_puts(seq, ",nogrpid");
701 if (sbi->s_resuid != EXT4_DEF_RESUID ||
702 le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) {
703 seq_printf(seq, ",resuid=%u", sbi->s_resuid);
705 if (sbi->s_resgid != EXT4_DEF_RESGID ||
706 le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {
707 seq_printf(seq, ",resgid=%u", sbi->s_resgid);
709 if (test_opt(sb, ERRORS_RO)) {
710 if (def_errors == EXT4_ERRORS_PANIC ||
711 def_errors == EXT4_ERRORS_CONTINUE) {
712 seq_puts(seq, ",errors=remount-ro");
715 if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
716 seq_puts(seq, ",errors=continue");
717 if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
718 seq_puts(seq, ",errors=panic");
719 if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16))
720 seq_puts(seq, ",nouid32");
721 if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG))
722 seq_puts(seq, ",debug");
723 if (test_opt(sb, OLDALLOC))
724 seq_puts(seq, ",oldalloc");
725 #ifdef CONFIG_EXT4DEV_FS_XATTR
726 if (test_opt(sb, XATTR_USER) &&
727 !(def_mount_opts & EXT4_DEFM_XATTR_USER))
728 seq_puts(seq, ",user_xattr");
729 if (!test_opt(sb, XATTR_USER) &&
730 (def_mount_opts & EXT4_DEFM_XATTR_USER)) {
731 seq_puts(seq, ",nouser_xattr");
734 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
735 if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL))
736 seq_puts(seq, ",acl");
737 if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
738 seq_puts(seq, ",noacl");
740 if (!test_opt(sb, RESERVATION))
741 seq_puts(seq, ",noreservation");
742 if (sbi->s_commit_interval) {
743 seq_printf(seq, ",commit=%u",
744 (unsigned) (sbi->s_commit_interval / HZ));
747 * We're changing the default of barrier mount option, so
748 * let's always display its mount state so it's clear what its
751 seq_puts(seq, ",barrier=");
752 seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
753 if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
754 seq_puts(seq, ",journal_async_commit");
755 if (test_opt(sb, NOBH))
756 seq_puts(seq, ",nobh");
757 if (!test_opt(sb, EXTENTS))
758 seq_puts(seq, ",noextents");
759 if (test_opt(sb, I_VERSION))
760 seq_puts(seq, ",i_version");
761 if (!test_opt(sb, DELALLOC))
762 seq_puts(seq, ",nodelalloc");
766 seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
768 * journal mode get enabled in different ways
769 * So just print the value even if we didn't specify it
771 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
772 seq_puts(seq, ",data=journal");
773 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
774 seq_puts(seq, ",data=ordered");
775 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
776 seq_puts(seq, ",data=writeback");
778 if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
779 seq_printf(seq, ",inode_readahead_blks=%u",
780 sbi->s_inode_readahead_blks);
782 ext4_show_quota_options(seq, sb);
787 static struct inode *ext4_nfs_get_inode(struct super_block *sb,
788 u64 ino, u32 generation)
792 if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
793 return ERR_PTR(-ESTALE);
794 if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
795 return ERR_PTR(-ESTALE);
797 /* iget isn't really right if the inode is currently unallocated!!
799 * ext4_read_inode will return a bad_inode if the inode had been
800 * deleted, so we should be safe.
802 * Currently we don't know the generation for parent directory, so
803 * a generation of 0 means "accept any"
805 inode = ext4_iget(sb, ino);
807 return ERR_CAST(inode);
808 if (generation && inode->i_generation != generation) {
810 return ERR_PTR(-ESTALE);
816 static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
817 int fh_len, int fh_type)
819 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
823 static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
824 int fh_len, int fh_type)
826 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
831 #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
832 #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
834 static int ext4_dquot_initialize(struct inode *inode, int type);
835 static int ext4_dquot_drop(struct inode *inode);
836 static int ext4_write_dquot(struct dquot *dquot);
837 static int ext4_acquire_dquot(struct dquot *dquot);
838 static int ext4_release_dquot(struct dquot *dquot);
839 static int ext4_mark_dquot_dirty(struct dquot *dquot);
840 static int ext4_write_info(struct super_block *sb, int type);
841 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
842 char *path, int remount);
843 static int ext4_quota_on_mount(struct super_block *sb, int type);
844 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
845 size_t len, loff_t off);
846 static ssize_t ext4_quota_write(struct super_block *sb, int type,
847 const char *data, size_t len, loff_t off);
849 static struct dquot_operations ext4_quota_operations = {
850 .initialize = ext4_dquot_initialize,
851 .drop = ext4_dquot_drop,
852 .alloc_space = dquot_alloc_space,
853 .alloc_inode = dquot_alloc_inode,
854 .free_space = dquot_free_space,
855 .free_inode = dquot_free_inode,
856 .transfer = dquot_transfer,
857 .write_dquot = ext4_write_dquot,
858 .acquire_dquot = ext4_acquire_dquot,
859 .release_dquot = ext4_release_dquot,
860 .mark_dirty = ext4_mark_dquot_dirty,
861 .write_info = ext4_write_info
864 static struct quotactl_ops ext4_qctl_operations = {
865 .quota_on = ext4_quota_on,
866 .quota_off = vfs_quota_off,
867 .quota_sync = vfs_quota_sync,
868 .get_info = vfs_get_dqinfo,
869 .set_info = vfs_set_dqinfo,
870 .get_dqblk = vfs_get_dqblk,
871 .set_dqblk = vfs_set_dqblk
875 static const struct super_operations ext4_sops = {
876 .alloc_inode = ext4_alloc_inode,
877 .destroy_inode = ext4_destroy_inode,
878 .write_inode = ext4_write_inode,
879 .dirty_inode = ext4_dirty_inode,
880 .delete_inode = ext4_delete_inode,
881 .put_super = ext4_put_super,
882 .write_super = ext4_write_super,
883 .sync_fs = ext4_sync_fs,
884 .write_super_lockfs = ext4_write_super_lockfs,
885 .unlockfs = ext4_unlockfs,
886 .statfs = ext4_statfs,
887 .remount_fs = ext4_remount,
888 .clear_inode = ext4_clear_inode,
889 .show_options = ext4_show_options,
891 .quota_read = ext4_quota_read,
892 .quota_write = ext4_quota_write,
896 static const struct export_operations ext4_export_ops = {
897 .fh_to_dentry = ext4_fh_to_dentry,
898 .fh_to_parent = ext4_fh_to_parent,
899 .get_parent = ext4_get_parent,
903 Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
904 Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
905 Opt_nouid32, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov,
906 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
907 Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh,
908 Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev,
909 Opt_journal_checksum, Opt_journal_async_commit,
910 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
911 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
912 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
913 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
914 Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version,
915 Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc,
916 Opt_inode_readahead_blks
919 static match_table_t tokens = {
920 {Opt_bsd_df, "bsddf"},
921 {Opt_minix_df, "minixdf"},
922 {Opt_grpid, "grpid"},
923 {Opt_grpid, "bsdgroups"},
924 {Opt_nogrpid, "nogrpid"},
925 {Opt_nogrpid, "sysvgroups"},
926 {Opt_resgid, "resgid=%u"},
927 {Opt_resuid, "resuid=%u"},
929 {Opt_err_cont, "errors=continue"},
930 {Opt_err_panic, "errors=panic"},
931 {Opt_err_ro, "errors=remount-ro"},
932 {Opt_nouid32, "nouid32"},
933 {Opt_nocheck, "nocheck"},
934 {Opt_nocheck, "check=none"},
935 {Opt_debug, "debug"},
936 {Opt_oldalloc, "oldalloc"},
937 {Opt_orlov, "orlov"},
938 {Opt_user_xattr, "user_xattr"},
939 {Opt_nouser_xattr, "nouser_xattr"},
941 {Opt_noacl, "noacl"},
942 {Opt_reservation, "reservation"},
943 {Opt_noreservation, "noreservation"},
944 {Opt_noload, "noload"},
947 {Opt_commit, "commit=%u"},
948 {Opt_journal_update, "journal=update"},
949 {Opt_journal_inum, "journal=%u"},
950 {Opt_journal_dev, "journal_dev=%u"},
951 {Opt_journal_checksum, "journal_checksum"},
952 {Opt_journal_async_commit, "journal_async_commit"},
953 {Opt_abort, "abort"},
954 {Opt_data_journal, "data=journal"},
955 {Opt_data_ordered, "data=ordered"},
956 {Opt_data_writeback, "data=writeback"},
957 {Opt_offusrjquota, "usrjquota="},
958 {Opt_usrjquota, "usrjquota=%s"},
959 {Opt_offgrpjquota, "grpjquota="},
960 {Opt_grpjquota, "grpjquota=%s"},
961 {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
962 {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
963 {Opt_grpquota, "grpquota"},
964 {Opt_noquota, "noquota"},
965 {Opt_quota, "quota"},
966 {Opt_usrquota, "usrquota"},
967 {Opt_barrier, "barrier=%u"},
968 {Opt_extents, "extents"},
969 {Opt_noextents, "noextents"},
970 {Opt_i_version, "i_version"},
971 {Opt_mballoc, "mballoc"},
972 {Opt_nomballoc, "nomballoc"},
973 {Opt_stripe, "stripe=%u"},
974 {Opt_resize, "resize"},
975 {Opt_delalloc, "delalloc"},
976 {Opt_nodelalloc, "nodelalloc"},
977 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
981 static ext4_fsblk_t get_sb_block(void **data)
983 ext4_fsblk_t sb_block;
984 char *options = (char *) *data;
986 if (!options || strncmp(options, "sb=", 3) != 0)
987 return 1; /* Default location */
989 /*todo: use simple_strtoll with >32bit ext4 */
990 sb_block = simple_strtoul(options, &options, 0);
991 if (*options && *options != ',') {
992 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
998 *data = (void *) options;
1002 static int parse_options(char *options, struct super_block *sb,
1003 unsigned int *inum, unsigned long *journal_devnum,
1004 ext4_fsblk_t *n_blocks_count, int is_remount)
1006 struct ext4_sb_info *sbi = EXT4_SB(sb);
1008 substring_t args[MAX_OPT_ARGS];
1015 ext4_fsblk_t last_block;
1020 while ((p = strsep(&options, ",")) != NULL) {
1025 token = match_token(p, tokens, args);
1028 clear_opt(sbi->s_mount_opt, MINIX_DF);
1031 set_opt(sbi->s_mount_opt, MINIX_DF);
1034 set_opt(sbi->s_mount_opt, GRPID);
1037 clear_opt(sbi->s_mount_opt, GRPID);
1040 if (match_int(&args[0], &option))
1042 sbi->s_resuid = option;
1045 if (match_int(&args[0], &option))
1047 sbi->s_resgid = option;
1050 /* handled by get_sb_block() instead of here */
1051 /* *sb_block = match_int(&args[0]); */
1054 clear_opt(sbi->s_mount_opt, ERRORS_CONT);
1055 clear_opt(sbi->s_mount_opt, ERRORS_RO);
1056 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
1059 clear_opt(sbi->s_mount_opt, ERRORS_CONT);
1060 clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
1061 set_opt(sbi->s_mount_opt, ERRORS_RO);
1064 clear_opt(sbi->s_mount_opt, ERRORS_RO);
1065 clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
1066 set_opt(sbi->s_mount_opt, ERRORS_CONT);
1069 set_opt(sbi->s_mount_opt, NO_UID32);
1072 clear_opt(sbi->s_mount_opt, CHECK);
1075 set_opt(sbi->s_mount_opt, DEBUG);
1078 set_opt(sbi->s_mount_opt, OLDALLOC);
1081 clear_opt(sbi->s_mount_opt, OLDALLOC);
1083 #ifdef CONFIG_EXT4DEV_FS_XATTR
1084 case Opt_user_xattr:
1085 set_opt(sbi->s_mount_opt, XATTR_USER);
1087 case Opt_nouser_xattr:
1088 clear_opt(sbi->s_mount_opt, XATTR_USER);
1091 case Opt_user_xattr:
1092 case Opt_nouser_xattr:
1093 printk(KERN_ERR "EXT4 (no)user_xattr options "
1097 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
1099 set_opt(sbi->s_mount_opt, POSIX_ACL);
1102 clear_opt(sbi->s_mount_opt, POSIX_ACL);
1107 printk(KERN_ERR "EXT4 (no)acl options "
1111 case Opt_reservation:
1112 set_opt(sbi->s_mount_opt, RESERVATION);
1114 case Opt_noreservation:
1115 clear_opt(sbi->s_mount_opt, RESERVATION);
1117 case Opt_journal_update:
1119 /* Eventually we will want to be able to create
1120 a journal file here. For now, only allow the
1121 user to specify an existing inode to be the
1124 printk(KERN_ERR "EXT4-fs: cannot specify "
1125 "journal on remount\n");
1128 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
1130 case Opt_journal_inum:
1132 printk(KERN_ERR "EXT4-fs: cannot specify "
1133 "journal on remount\n");
1136 if (match_int(&args[0], &option))
1140 case Opt_journal_dev:
1142 printk(KERN_ERR "EXT4-fs: cannot specify "
1143 "journal on remount\n");
1146 if (match_int(&args[0], &option))
1148 *journal_devnum = option;
1150 case Opt_journal_checksum:
1151 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
1153 case Opt_journal_async_commit:
1154 set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT);
1155 set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
1158 set_opt(sbi->s_mount_opt, NOLOAD);
1161 if (match_int(&args[0], &option))
1166 option = JBD2_DEFAULT_MAX_COMMIT_AGE;
1167 sbi->s_commit_interval = HZ * option;
1169 case Opt_data_journal:
1170 data_opt = EXT4_MOUNT_JOURNAL_DATA;
1172 case Opt_data_ordered:
1173 data_opt = EXT4_MOUNT_ORDERED_DATA;
1175 case Opt_data_writeback:
1176 data_opt = EXT4_MOUNT_WRITEBACK_DATA;
1179 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
1182 "EXT4-fs: cannot change data "
1183 "mode on remount\n");
1187 sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS;
1188 sbi->s_mount_opt |= data_opt;
1198 if ((sb_any_quota_enabled(sb) ||
1199 sb_any_quota_suspended(sb)) &&
1200 !sbi->s_qf_names[qtype]) {
1202 "EXT4-fs: Cannot change journaled "
1203 "quota options when quota turned on.\n");
1206 qname = match_strdup(&args[0]);
1209 "EXT4-fs: not enough memory for "
1210 "storing quotafile name.\n");
1213 if (sbi->s_qf_names[qtype] &&
1214 strcmp(sbi->s_qf_names[qtype], qname)) {
1216 "EXT4-fs: %s quota file already "
1217 "specified.\n", QTYPE2NAME(qtype));
1221 sbi->s_qf_names[qtype] = qname;
1222 if (strchr(sbi->s_qf_names[qtype], '/')) {
1224 "EXT4-fs: quotafile must be on "
1225 "filesystem root.\n");
1226 kfree(sbi->s_qf_names[qtype]);
1227 sbi->s_qf_names[qtype] = NULL;
1230 set_opt(sbi->s_mount_opt, QUOTA);
1232 case Opt_offusrjquota:
1235 case Opt_offgrpjquota:
1238 if ((sb_any_quota_enabled(sb) ||
1239 sb_any_quota_suspended(sb)) &&
1240 sbi->s_qf_names[qtype]) {
1241 printk(KERN_ERR "EXT4-fs: Cannot change "
1242 "journaled quota options when "
1243 "quota turned on.\n");
1247 * The space will be released later when all options
1248 * are confirmed to be correct
1250 sbi->s_qf_names[qtype] = NULL;
1252 case Opt_jqfmt_vfsold:
1253 qfmt = QFMT_VFS_OLD;
1255 case Opt_jqfmt_vfsv0:
1258 if ((sb_any_quota_enabled(sb) ||
1259 sb_any_quota_suspended(sb)) &&
1260 sbi->s_jquota_fmt != qfmt) {
1261 printk(KERN_ERR "EXT4-fs: Cannot change "
1262 "journaled quota options when "
1263 "quota turned on.\n");
1266 sbi->s_jquota_fmt = qfmt;
1270 set_opt(sbi->s_mount_opt, QUOTA);
1271 set_opt(sbi->s_mount_opt, USRQUOTA);
1274 set_opt(sbi->s_mount_opt, QUOTA);
1275 set_opt(sbi->s_mount_opt, GRPQUOTA);
1278 if (sb_any_quota_enabled(sb)) {
1279 printk(KERN_ERR "EXT4-fs: Cannot change quota "
1280 "options when quota turned on.\n");
1283 clear_opt(sbi->s_mount_opt, QUOTA);
1284 clear_opt(sbi->s_mount_opt, USRQUOTA);
1285 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1292 "EXT4-fs: quota options not supported.\n");
1296 case Opt_offusrjquota:
1297 case Opt_offgrpjquota:
1298 case Opt_jqfmt_vfsold:
1299 case Opt_jqfmt_vfsv0:
1301 "EXT4-fs: journaled quota options not "
1308 set_opt(sbi->s_mount_opt, ABORT);
1311 if (match_int(&args[0], &option))
1314 set_opt(sbi->s_mount_opt, BARRIER);
1316 clear_opt(sbi->s_mount_opt, BARRIER);
1322 printk("EXT4-fs: resize option only available "
1326 if (match_int(&args[0], &option) != 0)
1328 *n_blocks_count = option;
1331 set_opt(sbi->s_mount_opt, NOBH);
1334 clear_opt(sbi->s_mount_opt, NOBH);
1337 if (!EXT4_HAS_INCOMPAT_FEATURE(sb,
1338 EXT4_FEATURE_INCOMPAT_EXTENTS)) {
1339 ext4_warning(sb, __func__,
1340 "extents feature not enabled "
1341 "on this filesystem, use tune2fs\n");
1344 set_opt(sbi->s_mount_opt, EXTENTS);
1348 * When e2fsprogs support resizing an already existing
1349 * ext3 file system to greater than 2**32 we need to
1350 * add support to block allocator to handle growing
1351 * already existing block mapped inode so that blocks
1352 * allocated for them fall within 2**32
1354 last_block = ext4_blocks_count(sbi->s_es) - 1;
1355 if (last_block > 0xffffffffULL) {
1356 printk(KERN_ERR "EXT4-fs: Filesystem too "
1357 "large to mount with "
1358 "-o noextents options\n");
1361 clear_opt(sbi->s_mount_opt, EXTENTS);
1364 set_opt(sbi->s_mount_opt, I_VERSION);
1365 sb->s_flags |= MS_I_VERSION;
1367 case Opt_nodelalloc:
1368 clear_opt(sbi->s_mount_opt, DELALLOC);
1371 if (match_int(&args[0], &option))
1375 sbi->s_stripe = option;
1378 set_opt(sbi->s_mount_opt, DELALLOC);
1380 case Opt_inode_readahead_blks:
1381 if (match_int(&args[0], &option))
1383 if (option < 0 || option > (1 << 30))
1385 sbi->s_inode_readahead_blks = option;
1389 "EXT4-fs: Unrecognized mount option \"%s\" "
1390 "or missing value\n", p);
1395 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1396 if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) &&
1397 sbi->s_qf_names[USRQUOTA])
1398 clear_opt(sbi->s_mount_opt, USRQUOTA);
1400 if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) &&
1401 sbi->s_qf_names[GRPQUOTA])
1402 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1404 if ((sbi->s_qf_names[USRQUOTA] &&
1405 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
1406 (sbi->s_qf_names[GRPQUOTA] &&
1407 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
1408 printk(KERN_ERR "EXT4-fs: old and new quota "
1409 "format mixing.\n");
1413 if (!sbi->s_jquota_fmt) {
1414 printk(KERN_ERR "EXT4-fs: journaled quota format "
1415 "not specified.\n");
1419 if (sbi->s_jquota_fmt) {
1420 printk(KERN_ERR "EXT4-fs: journaled quota format "
1421 "specified with no journaling "
1430 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1433 struct ext4_sb_info *sbi = EXT4_SB(sb);
1436 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
1437 printk(KERN_ERR "EXT4-fs warning: revision level too high, "
1438 "forcing read-only mode\n");
1443 if (!(sbi->s_mount_state & EXT4_VALID_FS))
1444 printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, "
1445 "running e2fsck is recommended\n");
1446 else if ((sbi->s_mount_state & EXT4_ERROR_FS))
1448 "EXT4-fs warning: mounting fs with errors, "
1449 "running e2fsck is recommended\n");
1450 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
1451 le16_to_cpu(es->s_mnt_count) >=
1452 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
1454 "EXT4-fs warning: maximal mount count reached, "
1455 "running e2fsck is recommended\n");
1456 else if (le32_to_cpu(es->s_checkinterval) &&
1457 (le32_to_cpu(es->s_lastcheck) +
1458 le32_to_cpu(es->s_checkinterval) <= get_seconds()))
1460 "EXT4-fs warning: checktime reached, "
1461 "running e2fsck is recommended\n");
1463 /* @@@ We _will_ want to clear the valid bit if we find
1464 * inconsistencies, to force a fsck at reboot. But for
1465 * a plain journaled filesystem we can keep it set as
1468 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1470 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1471 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1472 le16_add_cpu(&es->s_mnt_count, 1);
1473 es->s_mtime = cpu_to_le32(get_seconds());
1474 ext4_update_dynamic_rev(sb);
1475 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1477 ext4_commit_super(sb, es, 1);
1478 if (test_opt(sb, DEBUG))
1479 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%lu, "
1480 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
1482 sbi->s_groups_count,
1483 EXT4_BLOCKS_PER_GROUP(sb),
1484 EXT4_INODES_PER_GROUP(sb),
1487 printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n",
1488 sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" :
1489 "external", EXT4_SB(sb)->s_journal->j_devname);
1493 static int ext4_fill_flex_info(struct super_block *sb)
1495 struct ext4_sb_info *sbi = EXT4_SB(sb);
1496 struct ext4_group_desc *gdp = NULL;
1497 struct buffer_head *bh;
1498 ext4_group_t flex_group_count;
1499 ext4_group_t flex_group;
1500 int groups_per_flex = 0;
1501 __u64 block_bitmap = 0;
1504 if (!sbi->s_es->s_log_groups_per_flex) {
1505 sbi->s_log_groups_per_flex = 0;
1509 sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
1510 groups_per_flex = 1 << sbi->s_log_groups_per_flex;
1512 /* We allocate both existing and potentially added groups */
1513 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
1514 ((sbi->s_es->s_reserved_gdt_blocks +1 ) <<
1515 EXT4_DESC_PER_BLOCK_BITS(sb))) /
1517 sbi->s_flex_groups = kzalloc(flex_group_count *
1518 sizeof(struct flex_groups), GFP_KERNEL);
1519 if (sbi->s_flex_groups == NULL) {
1520 printk(KERN_ERR "EXT4-fs: not enough memory for "
1521 "%lu flex groups\n", flex_group_count);
1525 gdp = ext4_get_group_desc(sb, 1, &bh);
1526 block_bitmap = ext4_block_bitmap(sb, gdp) - 1;
1528 for (i = 0; i < sbi->s_groups_count; i++) {
1529 gdp = ext4_get_group_desc(sb, i, &bh);
1531 flex_group = ext4_flex_group(sbi, i);
1532 sbi->s_flex_groups[flex_group].free_inodes +=
1533 le16_to_cpu(gdp->bg_free_inodes_count);
1534 sbi->s_flex_groups[flex_group].free_blocks +=
1535 le16_to_cpu(gdp->bg_free_blocks_count);
1543 __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
1544 struct ext4_group_desc *gdp)
1548 if (sbi->s_es->s_feature_ro_compat &
1549 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
1550 int offset = offsetof(struct ext4_group_desc, bg_checksum);
1551 __le32 le_group = cpu_to_le32(block_group);
1553 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
1554 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
1555 crc = crc16(crc, (__u8 *)gdp, offset);
1556 offset += sizeof(gdp->bg_checksum); /* skip checksum */
1557 /* for checksum of struct ext4_group_desc do the rest...*/
1558 if ((sbi->s_es->s_feature_incompat &
1559 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
1560 offset < le16_to_cpu(sbi->s_es->s_desc_size))
1561 crc = crc16(crc, (__u8 *)gdp + offset,
1562 le16_to_cpu(sbi->s_es->s_desc_size) -
1566 return cpu_to_le16(crc);
1569 int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
1570 struct ext4_group_desc *gdp)
1572 if ((sbi->s_es->s_feature_ro_compat &
1573 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) &&
1574 (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp)))
1580 /* Called at mount-time, super-block is locked */
1581 static int ext4_check_descriptors(struct super_block *sb)
1583 struct ext4_sb_info *sbi = EXT4_SB(sb);
1584 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
1585 ext4_fsblk_t last_block;
1586 ext4_fsblk_t block_bitmap;
1587 ext4_fsblk_t inode_bitmap;
1588 ext4_fsblk_t inode_table;
1589 int flexbg_flag = 0;
1592 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
1595 ext4_debug("Checking group descriptors");
1597 for (i = 0; i < sbi->s_groups_count; i++) {
1598 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1600 if (i == sbi->s_groups_count - 1 || flexbg_flag)
1601 last_block = ext4_blocks_count(sbi->s_es) - 1;
1603 last_block = first_block +
1604 (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1606 block_bitmap = ext4_block_bitmap(sb, gdp);
1607 if (block_bitmap < first_block || block_bitmap > last_block) {
1608 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1609 "Block bitmap for group %lu not in group "
1610 "(block %llu)!", i, block_bitmap);
1613 inode_bitmap = ext4_inode_bitmap(sb, gdp);
1614 if (inode_bitmap < first_block || inode_bitmap > last_block) {
1615 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1616 "Inode bitmap for group %lu not in group "
1617 "(block %llu)!", i, inode_bitmap);
1620 inode_table = ext4_inode_table(sb, gdp);
1621 if (inode_table < first_block ||
1622 inode_table + sbi->s_itb_per_group - 1 > last_block) {
1623 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1624 "Inode table for group %lu not in group "
1625 "(block %llu)!", i, inode_table);
1628 spin_lock(sb_bgl_lock(sbi, i));
1629 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1630 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1631 "Checksum for group %lu failed (%u!=%u)\n",
1632 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
1633 gdp)), le16_to_cpu(gdp->bg_checksum));
1634 if (!(sb->s_flags & MS_RDONLY)) {
1635 spin_unlock(sb_bgl_lock(sbi, i));
1639 spin_unlock(sb_bgl_lock(sbi, i));
1641 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1644 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
1645 sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
1649 /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
1650 * the superblock) which were deleted from all directories, but held open by
1651 * a process at the time of a crash. We walk the list and try to delete these
1652 * inodes at recovery time (only with a read-write filesystem).
1654 * In order to keep the orphan inode chain consistent during traversal (in
1655 * case of crash during recovery), we link each inode into the superblock
1656 * orphan list_head and handle it the same way as an inode deletion during
1657 * normal operation (which journals the operations for us).
1659 * We only do an iget() and an iput() on each inode, which is very safe if we
1660 * accidentally point at an in-use or already deleted inode. The worst that
1661 * can happen in this case is that we get a "bit already cleared" message from
1662 * ext4_free_inode(). The only reason we would point at a wrong inode is if
1663 * e2fsck was run on this filesystem, and it must have already done the orphan
1664 * inode cleanup for us, so we can safely abort without any further action.
1666 static void ext4_orphan_cleanup(struct super_block *sb,
1667 struct ext4_super_block *es)
1669 unsigned int s_flags = sb->s_flags;
1670 int nr_orphans = 0, nr_truncates = 0;
1674 if (!es->s_last_orphan) {
1675 jbd_debug(4, "no orphan inodes to clean up\n");
1679 if (bdev_read_only(sb->s_bdev)) {
1680 printk(KERN_ERR "EXT4-fs: write access "
1681 "unavailable, skipping orphan cleanup.\n");
1685 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
1686 if (es->s_last_orphan)
1687 jbd_debug(1, "Errors on filesystem, "
1688 "clearing orphan list.\n");
1689 es->s_last_orphan = 0;
1690 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
1694 if (s_flags & MS_RDONLY) {
1695 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n",
1697 sb->s_flags &= ~MS_RDONLY;
1700 /* Needed for iput() to work correctly and not trash data */
1701 sb->s_flags |= MS_ACTIVE;
1702 /* Turn on quotas so that they are updated correctly */
1703 for (i = 0; i < MAXQUOTAS; i++) {
1704 if (EXT4_SB(sb)->s_qf_names[i]) {
1705 int ret = ext4_quota_on_mount(sb, i);
1708 "EXT4-fs: Cannot turn on journaled "
1709 "quota: error %d\n", ret);
1714 while (es->s_last_orphan) {
1715 struct inode *inode;
1717 inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
1718 if (IS_ERR(inode)) {
1719 es->s_last_orphan = 0;
1723 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1725 if (inode->i_nlink) {
1727 "%s: truncating inode %lu to %lld bytes\n",
1728 __func__, inode->i_ino, inode->i_size);
1729 jbd_debug(2, "truncating inode %lu to %lld bytes\n",
1730 inode->i_ino, inode->i_size);
1731 ext4_truncate(inode);
1735 "%s: deleting unreferenced inode %lu\n",
1736 __func__, inode->i_ino);
1737 jbd_debug(2, "deleting unreferenced inode %lu\n",
1741 iput(inode); /* The delete magic happens here! */
1744 #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
1747 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n",
1748 sb->s_id, PLURAL(nr_orphans));
1750 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n",
1751 sb->s_id, PLURAL(nr_truncates));
1753 /* Turn quotas off */
1754 for (i = 0; i < MAXQUOTAS; i++) {
1755 if (sb_dqopt(sb)->files[i])
1756 vfs_quota_off(sb, i, 0);
1759 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1762 * Maximal extent format file size.
1763 * Resulting logical blkno at s_maxbytes must fit in our on-disk
1764 * extent format containers, within a sector_t, and within i_blocks
1765 * in the vfs. ext4 inode has 48 bits of i_block in fsblock units,
1766 * so that won't be a limiting factor.
1768 * Note, this does *not* consider any metadata overhead for vfs i_blocks.
1770 static loff_t ext4_max_size(int blkbits)
1773 loff_t upper_limit = MAX_LFS_FILESIZE;
1775 /* small i_blocks in vfs inode? */
1776 if (sizeof(blkcnt_t) < sizeof(u64)) {
1778 * CONFIG_LSF is not enabled implies the inode
1779 * i_block represent total blocks in 512 bytes
1780 * 32 == size of vfs inode i_blocks * 8
1782 upper_limit = (1LL << 32) - 1;
1784 /* total blocks in file system block size */
1785 upper_limit >>= (blkbits - 9);
1786 upper_limit <<= blkbits;
1789 /* 32-bit extent-start container, ee_block */
1794 /* Sanity check against vm- & vfs- imposed limits */
1795 if (res > upper_limit)
1802 * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
1803 * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
1804 * We need to be 1 filesystem block less than the 2^48 sector limit.
1806 static loff_t ext4_max_bitmap_size(int bits)
1808 loff_t res = EXT4_NDIR_BLOCKS;
1811 /* This is calculated to be the largest file size for a
1812 * dense, bitmapped file such that the total number of
1813 * sectors in the file, including data and all indirect blocks,
1814 * does not exceed 2^48 -1
1815 * __u32 i_blocks_lo and _u16 i_blocks_high representing the
1816 * total number of 512 bytes blocks of the file
1819 if (sizeof(blkcnt_t) < sizeof(u64)) {
1821 * CONFIG_LSF is not enabled implies the inode
1822 * i_block represent total blocks in 512 bytes
1823 * 32 == size of vfs inode i_blocks * 8
1825 upper_limit = (1LL << 32) - 1;
1827 /* total blocks in file system block size */
1828 upper_limit >>= (bits - 9);
1832 * We use 48 bit ext4_inode i_blocks
1833 * With EXT4_HUGE_FILE_FL set the i_blocks
1834 * represent total number of blocks in
1835 * file system block size
1837 upper_limit = (1LL << 48) - 1;
1841 /* indirect blocks */
1843 /* double indirect blocks */
1844 meta_blocks += 1 + (1LL << (bits-2));
1845 /* tripple indirect blocks */
1846 meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
1848 upper_limit -= meta_blocks;
1849 upper_limit <<= bits;
1851 res += 1LL << (bits-2);
1852 res += 1LL << (2*(bits-2));
1853 res += 1LL << (3*(bits-2));
1855 if (res > upper_limit)
1858 if (res > MAX_LFS_FILESIZE)
1859 res = MAX_LFS_FILESIZE;
1864 static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1865 ext4_fsblk_t logical_sb_block, int nr)
1867 struct ext4_sb_info *sbi = EXT4_SB(sb);
1868 ext4_group_t bg, first_meta_bg;
1871 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
1873 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
1875 return logical_sb_block + nr + 1;
1876 bg = sbi->s_desc_per_block * nr;
1877 if (ext4_bg_has_super(sb, bg))
1879 return (has_super + ext4_group_first_block_no(sb, bg));
1883 * ext4_get_stripe_size: Get the stripe size.
1884 * @sbi: In memory super block info
1886 * If we have specified it via mount option, then
1887 * use the mount option value. If the value specified at mount time is
1888 * greater than the blocks per group use the super block value.
1889 * If the super block value is greater than blocks per group return 0.
1890 * Allocator needs it be less than blocks per group.
1893 static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
1895 unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
1896 unsigned long stripe_width =
1897 le32_to_cpu(sbi->s_es->s_raid_stripe_width);
1899 if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
1900 return sbi->s_stripe;
1902 if (stripe_width <= sbi->s_blocks_per_group)
1903 return stripe_width;
1905 if (stride <= sbi->s_blocks_per_group)
1911 static int ext4_fill_super(struct super_block *sb, void *data, int silent)
1912 __releases(kernel_lock)
1913 __acquires(kernel_lock)
1916 struct buffer_head *bh;
1917 struct ext4_super_block *es = NULL;
1918 struct ext4_sb_info *sbi;
1920 ext4_fsblk_t sb_block = get_sb_block(&data);
1921 ext4_fsblk_t logical_sb_block;
1922 unsigned long offset = 0;
1923 unsigned int journal_inum = 0;
1924 unsigned long journal_devnum = 0;
1925 unsigned long def_mount_opts;
1937 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
1940 sb->s_fs_info = sbi;
1941 sbi->s_mount_opt = 0;
1942 sbi->s_resuid = EXT4_DEF_RESUID;
1943 sbi->s_resgid = EXT4_DEF_RESGID;
1944 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
1945 sbi->s_sb_block = sb_block;
1949 /* Cleanup superblock name */
1950 for (cp = sb->s_id; (cp = strchr(cp, '/'));)
1953 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
1955 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
1960 * The ext4 superblock will not be buffer aligned for other than 1kB
1961 * block sizes. We need to calculate the offset from buffer start.
1963 if (blocksize != EXT4_MIN_BLOCK_SIZE) {
1964 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
1965 offset = do_div(logical_sb_block, blocksize);
1967 logical_sb_block = sb_block;
1970 if (!(bh = sb_bread(sb, logical_sb_block))) {
1971 printk(KERN_ERR "EXT4-fs: unable to read superblock\n");
1975 * Note: s_es must be initialized as soon as possible because
1976 * some ext4 macro-instructions depend on its value
1978 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
1980 sb->s_magic = le16_to_cpu(es->s_magic);
1981 if (sb->s_magic != EXT4_SUPER_MAGIC)
1984 /* Set defaults before we parse the mount options */
1985 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
1986 if (def_mount_opts & EXT4_DEFM_DEBUG)
1987 set_opt(sbi->s_mount_opt, DEBUG);
1988 if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
1989 set_opt(sbi->s_mount_opt, GRPID);
1990 if (def_mount_opts & EXT4_DEFM_UID16)
1991 set_opt(sbi->s_mount_opt, NO_UID32);
1992 #ifdef CONFIG_EXT4DEV_FS_XATTR
1993 if (def_mount_opts & EXT4_DEFM_XATTR_USER)
1994 set_opt(sbi->s_mount_opt, XATTR_USER);
1996 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
1997 if (def_mount_opts & EXT4_DEFM_ACL)
1998 set_opt(sbi->s_mount_opt, POSIX_ACL);
2000 if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
2001 sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
2002 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
2003 sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
2004 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
2005 sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA;
2007 if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
2008 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
2009 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
2010 set_opt(sbi->s_mount_opt, ERRORS_CONT);
2012 set_opt(sbi->s_mount_opt, ERRORS_RO);
2014 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
2015 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
2017 set_opt(sbi->s_mount_opt, RESERVATION);
2018 set_opt(sbi->s_mount_opt, BARRIER);
2021 * turn on extents feature by default in ext4 filesystem
2022 * only if feature flag already set by mkfs or tune2fs.
2023 * Use -o noextents to turn it off
2025 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
2026 set_opt(sbi->s_mount_opt, EXTENTS);
2028 ext4_warning(sb, __func__,
2029 "extents feature not enabled on this filesystem, "
2033 * enable delayed allocation by default
2034 * Use -o nodelalloc to turn it off
2036 set_opt(sbi->s_mount_opt, DELALLOC);
2039 if (!parse_options((char *) data, sb, &journal_inum, &journal_devnum,
2043 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2044 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2046 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
2047 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
2048 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
2049 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
2051 "EXT4-fs warning: feature flags set on rev 0 fs, "
2052 "running e2fsck is recommended\n");
2055 * Since ext4 is still considered development code, we require
2056 * that the TEST_FILESYS flag in s->flags be set.
2058 if (!(le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS)) {
2059 printk(KERN_WARNING "EXT4-fs: %s: not marked "
2060 "OK to use with test code.\n", sb->s_id);
2065 * Check feature flags regardless of the revision level, since we
2066 * previously didn't change the revision level when setting the flags,
2067 * so there is a chance incompat flags are set on a rev 0 filesystem.
2069 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
2071 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of "
2072 "unsupported optional features (%x).\n",
2073 sb->s_id, le32_to_cpu(features));
2076 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
2077 if (!(sb->s_flags & MS_RDONLY) && features) {
2078 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of "
2079 "unsupported optional features (%x).\n",
2080 sb->s_id, le32_to_cpu(features));
2083 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
2085 * Large file size enabled file system can only be
2086 * mount if kernel is build with CONFIG_LSF
2088 if (sizeof(root->i_blocks) < sizeof(u64) &&
2089 !(sb->s_flags & MS_RDONLY)) {
2090 printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge "
2091 "files cannot be mounted read-write "
2092 "without CONFIG_LSF.\n", sb->s_id);
2096 blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
2098 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
2099 blocksize > EXT4_MAX_BLOCK_SIZE) {
2101 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n",
2102 blocksize, sb->s_id);
2106 if (sb->s_blocksize != blocksize) {
2108 /* Validate the filesystem blocksize */
2109 if (!sb_set_blocksize(sb, blocksize)) {
2110 printk(KERN_ERR "EXT4-fs: bad block size %d.\n",
2116 logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
2117 offset = do_div(logical_sb_block, blocksize);
2118 bh = sb_bread(sb, logical_sb_block);
2121 "EXT4-fs: Can't read superblock on 2nd try.\n");
2124 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
2126 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
2128 "EXT4-fs: Magic mismatch, very weird !\n");
2133 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits);
2134 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits);
2136 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
2137 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
2138 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
2140 sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
2141 sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
2142 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
2143 (!is_power_of_2(sbi->s_inode_size)) ||
2144 (sbi->s_inode_size > blocksize)) {
2146 "EXT4-fs: unsupported inode size: %d\n",
2150 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
2151 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
2153 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
2154 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
2155 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
2156 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
2157 !is_power_of_2(sbi->s_desc_size)) {
2159 "EXT4-fs: unsupported descriptor size %lu\n",
2164 sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
2165 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
2166 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
2167 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
2169 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
2170 if (sbi->s_inodes_per_block == 0)
2172 sbi->s_itb_per_group = sbi->s_inodes_per_group /
2173 sbi->s_inodes_per_block;
2174 sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
2176 sbi->s_mount_state = le16_to_cpu(es->s_state);
2177 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
2178 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
2179 for (i = 0; i < 4; i++)
2180 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
2181 sbi->s_def_hash_version = es->s_def_hash_version;
2183 if (sbi->s_blocks_per_group > blocksize * 8) {
2185 "EXT4-fs: #blocks per group too big: %lu\n",
2186 sbi->s_blocks_per_group);
2189 if (sbi->s_inodes_per_group > blocksize * 8) {
2191 "EXT4-fs: #inodes per group too big: %lu\n",
2192 sbi->s_inodes_per_group);
2196 if (ext4_blocks_count(es) >
2197 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
2198 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
2199 " too large to mount safely\n", sb->s_id);
2200 if (sizeof(sector_t) < 8)
2201 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not "
2206 if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
2209 /* ensure blocks_count calculation below doesn't sign-extend */
2210 if (ext4_blocks_count(es) + EXT4_BLOCKS_PER_GROUP(sb) <
2211 le32_to_cpu(es->s_first_data_block) + 1) {
2212 printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu, "
2213 "first data block %u, blocks per group %lu\n",
2214 ext4_blocks_count(es),
2215 le32_to_cpu(es->s_first_data_block),
2216 EXT4_BLOCKS_PER_GROUP(sb));
2219 blocks_count = (ext4_blocks_count(es) -
2220 le32_to_cpu(es->s_first_data_block) +
2221 EXT4_BLOCKS_PER_GROUP(sb) - 1);
2222 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
2223 sbi->s_groups_count = blocks_count;
2224 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
2225 EXT4_DESC_PER_BLOCK(sb);
2226 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
2228 if (sbi->s_group_desc == NULL) {
2229 printk(KERN_ERR "EXT4-fs: not enough memory\n");
2234 sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
2237 proc_create_data("inode_readahead_blks", 0644, sbi->s_proc,
2239 &sbi->s_inode_readahead_blks);
2241 bgl_lock_init(&sbi->s_blockgroup_lock);
2243 for (i = 0; i < db_count; i++) {
2244 block = descriptor_loc(sb, logical_sb_block, i);
2245 sbi->s_group_desc[i] = sb_bread(sb, block);
2246 if (!sbi->s_group_desc[i]) {
2247 printk(KERN_ERR "EXT4-fs: "
2248 "can't read group descriptor %d\n", i);
2253 if (!ext4_check_descriptors(sb)) {
2254 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n");
2257 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
2258 if (!ext4_fill_flex_info(sb)) {
2260 "EXT4-fs: unable to initialize "
2261 "flex_bg meta info!\n");
2265 sbi->s_gdb_count = db_count;
2266 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
2267 spin_lock_init(&sbi->s_next_gen_lock);
2269 err = percpu_counter_init(&sbi->s_freeblocks_counter,
2270 ext4_count_free_blocks(sb));
2272 err = percpu_counter_init(&sbi->s_freeinodes_counter,
2273 ext4_count_free_inodes(sb));
2276 err = percpu_counter_init(&sbi->s_dirs_counter,
2277 ext4_count_dirs(sb));
2280 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2283 printk(KERN_ERR "EXT4-fs: insufficient memory\n");
2287 sbi->s_stripe = ext4_get_stripe_size(sbi);
2290 * set up enough so that it can read an inode
2292 sb->s_op = &ext4_sops;
2293 sb->s_export_op = &ext4_export_ops;
2294 sb->s_xattr = ext4_xattr_handlers;
2296 sb->s_qcop = &ext4_qctl_operations;
2297 sb->dq_op = &ext4_quota_operations;
2299 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
2303 needs_recovery = (es->s_last_orphan != 0 ||
2304 EXT4_HAS_INCOMPAT_FEATURE(sb,
2305 EXT4_FEATURE_INCOMPAT_RECOVER));
2308 * The first inode we look at is the journal inode. Don't try
2309 * root first: it may be modified in the journal!
2311 if (!test_opt(sb, NOLOAD) &&
2312 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
2313 if (ext4_load_journal(sb, es, journal_devnum))
2315 if (!(sb->s_flags & MS_RDONLY) &&
2316 EXT4_SB(sb)->s_journal->j_failed_commit) {
2317 printk(KERN_CRIT "EXT4-fs error (device %s): "
2318 "ext4_fill_super: Journal transaction "
2319 "%u is corrupt\n", sb->s_id,
2320 EXT4_SB(sb)->s_journal->j_failed_commit);
2321 if (test_opt(sb, ERRORS_RO)) {
2323 "Mounting filesystem read-only\n");
2324 sb->s_flags |= MS_RDONLY;
2325 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2326 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2328 if (test_opt(sb, ERRORS_PANIC)) {
2329 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2330 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2331 ext4_commit_super(sb, es, 1);
2333 "EXT4-fs (device %s): mount failed\n",
2338 } else if (journal_inum) {
2339 if (ext4_create_journal(sb, es, journal_inum))
2344 "ext4: No journal on filesystem on %s\n",
2349 if (ext4_blocks_count(es) > 0xffffffffULL &&
2350 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
2351 JBD2_FEATURE_INCOMPAT_64BIT)) {
2352 printk(KERN_ERR "ext4: Failed to set 64-bit journal feature\n");
2356 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
2357 jbd2_journal_set_features(sbi->s_journal,
2358 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2359 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2360 } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
2361 jbd2_journal_set_features(sbi->s_journal,
2362 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
2363 jbd2_journal_clear_features(sbi->s_journal, 0, 0,
2364 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2366 jbd2_journal_clear_features(sbi->s_journal,
2367 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
2368 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
2371 /* We have now updated the journal if required, so we can
2372 * validate the data journaling mode. */
2373 switch (test_opt(sb, DATA_FLAGS)) {
2375 /* No mode set, assume a default based on the journal
2376 * capabilities: ORDERED_DATA if the journal can
2377 * cope, else JOURNAL_DATA
2379 if (jbd2_journal_check_available_features
2380 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))
2381 set_opt(sbi->s_mount_opt, ORDERED_DATA);
2383 set_opt(sbi->s_mount_opt, JOURNAL_DATA);
2386 case EXT4_MOUNT_ORDERED_DATA:
2387 case EXT4_MOUNT_WRITEBACK_DATA:
2388 if (!jbd2_journal_check_available_features
2389 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
2390 printk(KERN_ERR "EXT4-fs: Journal does not support "
2391 "requested data journaling mode\n");
2398 if (test_opt(sb, NOBH)) {
2399 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
2400 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - "
2401 "its supported only with writeback mode\n");
2402 clear_opt(sbi->s_mount_opt, NOBH);
2406 * The jbd2_journal_load will have done any necessary log recovery,
2407 * so we can safely mount the rest of the filesystem now.
2410 root = ext4_iget(sb, EXT4_ROOT_INO);
2412 printk(KERN_ERR "EXT4-fs: get root inode failed\n");
2413 ret = PTR_ERR(root);
2416 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
2418 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
2421 sb->s_root = d_alloc_root(root);
2423 printk(KERN_ERR "EXT4-fs: get root dentry failed\n");
2429 ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY);
2431 /* determine the minimum size of new large inodes, if present */
2432 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
2433 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2434 EXT4_GOOD_OLD_INODE_SIZE;
2435 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
2436 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
2437 if (sbi->s_want_extra_isize <
2438 le16_to_cpu(es->s_want_extra_isize))
2439 sbi->s_want_extra_isize =
2440 le16_to_cpu(es->s_want_extra_isize);
2441 if (sbi->s_want_extra_isize <
2442 le16_to_cpu(es->s_min_extra_isize))
2443 sbi->s_want_extra_isize =
2444 le16_to_cpu(es->s_min_extra_isize);
2447 /* Check if enough inode space is available */
2448 if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
2449 sbi->s_inode_size) {
2450 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2451 EXT4_GOOD_OLD_INODE_SIZE;
2452 printk(KERN_INFO "EXT4-fs: required extra inode space not"
2457 * akpm: core read_super() calls in here with the superblock locked.
2458 * That deadlocks, because orphan cleanup needs to lock the superblock
2459 * in numerous places. Here we just pop the lock - it's relatively
2460 * harmless, because we are now ready to accept write_super() requests,
2461 * and aviro says that's the only reason for hanging onto the
2464 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
2465 ext4_orphan_cleanup(sb, es);
2466 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
2468 printk(KERN_INFO "EXT4-fs: recovery complete.\n");
2469 ext4_mark_recovery_complete(sb, es);
2470 printk(KERN_INFO "EXT4-fs: mounted filesystem with %s data mode.\n",
2471 test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ? "journal":
2472 test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
2475 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
2476 printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - "
2477 "requested data journaling mode\n");
2478 clear_opt(sbi->s_mount_opt, DELALLOC);
2479 } else if (test_opt(sb, DELALLOC))
2480 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
2483 err = ext4_mb_init(sb, needs_recovery);
2485 printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n",
2495 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n",
2500 jbd2_journal_destroy(sbi->s_journal);
2501 sbi->s_journal = NULL;
2503 percpu_counter_destroy(&sbi->s_freeblocks_counter);
2504 percpu_counter_destroy(&sbi->s_freeinodes_counter);
2505 percpu_counter_destroy(&sbi->s_dirs_counter);
2506 percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
2508 for (i = 0; i < db_count; i++)
2509 brelse(sbi->s_group_desc[i]);
2510 kfree(sbi->s_group_desc);
2513 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
2514 remove_proc_entry(sb->s_id, ext4_proc_root);
2517 for (i = 0; i < MAXQUOTAS; i++)
2518 kfree(sbi->s_qf_names[i]);
2520 ext4_blkdev_remove(sbi);
2523 sb->s_fs_info = NULL;
2530 * Setup any per-fs journal parameters now. We'll do this both on
2531 * initial mount, once the journal has been initialised but before we've
2532 * done any recovery; and again on any subsequent remount.
2534 static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
2536 struct ext4_sb_info *sbi = EXT4_SB(sb);
2538 if (sbi->s_commit_interval)
2539 journal->j_commit_interval = sbi->s_commit_interval;
2540 /* We could also set up an ext4-specific default for the commit
2541 * interval here, but for now we'll just fall back to the jbd
2544 spin_lock(&journal->j_state_lock);
2545 if (test_opt(sb, BARRIER))
2546 journal->j_flags |= JBD2_BARRIER;
2548 journal->j_flags &= ~JBD2_BARRIER;
2549 spin_unlock(&journal->j_state_lock);
2552 static journal_t *ext4_get_journal(struct super_block *sb,
2553 unsigned int journal_inum)
2555 struct inode *journal_inode;
2558 /* First, test for the existence of a valid inode on disk. Bad
2559 * things happen if we iget() an unused inode, as the subsequent
2560 * iput() will try to delete it. */
2562 journal_inode = ext4_iget(sb, journal_inum);
2563 if (IS_ERR(journal_inode)) {
2564 printk(KERN_ERR "EXT4-fs: no journal found.\n");
2567 if (!journal_inode->i_nlink) {
2568 make_bad_inode(journal_inode);
2569 iput(journal_inode);
2570 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n");
2574 jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
2575 journal_inode, journal_inode->i_size);
2576 if (!S_ISREG(journal_inode->i_mode)) {
2577 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
2578 iput(journal_inode);
2582 journal = jbd2_journal_init_inode(journal_inode);
2584 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n");
2585 iput(journal_inode);
2588 journal->j_private = sb;
2589 ext4_init_journal_params(sb, journal);
2593 static journal_t *ext4_get_dev_journal(struct super_block *sb,
2596 struct buffer_head *bh;
2600 int hblock, blocksize;
2601 ext4_fsblk_t sb_block;
2602 unsigned long offset;
2603 struct ext4_super_block *es;
2604 struct block_device *bdev;
2606 bdev = ext4_blkdev_get(j_dev);
2610 if (bd_claim(bdev, sb)) {
2612 "EXT4: failed to claim external journal device.\n");
2617 blocksize = sb->s_blocksize;
2618 hblock = bdev_hardsect_size(bdev);
2619 if (blocksize < hblock) {
2621 "EXT4-fs: blocksize too small for journal device.\n");
2625 sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
2626 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
2627 set_blocksize(bdev, blocksize);
2628 if (!(bh = __bread(bdev, sb_block, blocksize))) {
2629 printk(KERN_ERR "EXT4-fs: couldn't read superblock of "
2630 "external journal\n");
2634 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
2635 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
2636 !(le32_to_cpu(es->s_feature_incompat) &
2637 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
2638 printk(KERN_ERR "EXT4-fs: external journal has "
2639 "bad superblock\n");
2644 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
2645 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n");
2650 len = ext4_blocks_count(es);
2651 start = sb_block + 1;
2652 brelse(bh); /* we're done with the superblock */
2654 journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
2655 start, len, blocksize);
2657 printk(KERN_ERR "EXT4-fs: failed to create device journal\n");
2660 journal->j_private = sb;
2661 ll_rw_block(READ, 1, &journal->j_sb_buffer);
2662 wait_on_buffer(journal->j_sb_buffer);
2663 if (!buffer_uptodate(journal->j_sb_buffer)) {
2664 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n");
2667 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
2668 printk(KERN_ERR "EXT4-fs: External journal has more than one "
2669 "user (unsupported) - %d\n",
2670 be32_to_cpu(journal->j_superblock->s_nr_users));
2673 EXT4_SB(sb)->journal_bdev = bdev;
2674 ext4_init_journal_params(sb, journal);
2677 jbd2_journal_destroy(journal);
2679 ext4_blkdev_put(bdev);
2683 static int ext4_load_journal(struct super_block *sb,
2684 struct ext4_super_block *es,
2685 unsigned long journal_devnum)
2688 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
2691 int really_read_only;
2693 if (journal_devnum &&
2694 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
2695 printk(KERN_INFO "EXT4-fs: external journal device major/minor "
2696 "numbers have changed\n");
2697 journal_dev = new_decode_dev(journal_devnum);
2699 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
2701 really_read_only = bdev_read_only(sb->s_bdev);
2704 * Are we loading a blank journal or performing recovery after a
2705 * crash? For recovery, we need to check in advance whether we
2706 * can get read-write access to the device.
2709 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
2710 if (sb->s_flags & MS_RDONLY) {
2711 printk(KERN_INFO "EXT4-fs: INFO: recovery "
2712 "required on readonly filesystem.\n");
2713 if (really_read_only) {
2714 printk(KERN_ERR "EXT4-fs: write access "
2715 "unavailable, cannot proceed.\n");
2718 printk(KERN_INFO "EXT4-fs: write access will "
2719 "be enabled during recovery.\n");
2723 if (journal_inum && journal_dev) {
2724 printk(KERN_ERR "EXT4-fs: filesystem has both journal "
2725 "and inode journals!\n");
2730 if (!(journal = ext4_get_journal(sb, journal_inum)))
2733 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
2737 if (journal->j_flags & JBD2_BARRIER)
2738 printk(KERN_INFO "EXT4-fs: barriers enabled\n");
2740 printk(KERN_INFO "EXT4-fs: barriers disabled\n");
2742 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
2743 err = jbd2_journal_update_format(journal);
2745 printk(KERN_ERR "EXT4-fs: error updating journal.\n");
2746 jbd2_journal_destroy(journal);
2751 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
2752 err = jbd2_journal_wipe(journal, !really_read_only);
2754 err = jbd2_journal_load(journal);
2757 printk(KERN_ERR "EXT4-fs: error loading journal.\n");
2758 jbd2_journal_destroy(journal);
2762 EXT4_SB(sb)->s_journal = journal;
2763 ext4_clear_journal_err(sb, es);
2765 if (journal_devnum &&
2766 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
2767 es->s_journal_dev = cpu_to_le32(journal_devnum);
2770 /* Make sure we flush the recovery flag to disk. */
2771 ext4_commit_super(sb, es, 1);
2777 static int ext4_create_journal(struct super_block *sb,
2778 struct ext4_super_block *es,
2779 unsigned int journal_inum)
2784 if (sb->s_flags & MS_RDONLY) {
2785 printk(KERN_ERR "EXT4-fs: readonly filesystem when trying to "
2786 "create journal.\n");
2790 journal = ext4_get_journal(sb, journal_inum);
2794 printk(KERN_INFO "EXT4-fs: creating new journal on inode %u\n",
2797 err = jbd2_journal_create(journal);
2799 printk(KERN_ERR "EXT4-fs: error creating journal.\n");
2800 jbd2_journal_destroy(journal);
2804 EXT4_SB(sb)->s_journal = journal;
2806 ext4_update_dynamic_rev(sb);
2807 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2808 EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL);
2810 es->s_journal_inum = cpu_to_le32(journal_inum);
2813 /* Make sure we flush the recovery flag to disk. */
2814 ext4_commit_super(sb, es, 1);
2819 static void ext4_commit_super(struct super_block *sb,
2820 struct ext4_super_block *es, int sync)
2822 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
2826 if (buffer_write_io_error(sbh)) {
2828 * Oh, dear. A previous attempt to write the
2829 * superblock failed. This could happen because the
2830 * USB device was yanked out. Or it could happen to
2831 * be a transient write error and maybe the block will
2832 * be remapped. Nothing we can do but to retry the
2833 * write and hope for the best.
2835 printk(KERN_ERR "ext4: previous I/O error to "
2836 "superblock detected for %s.\n", sb->s_id);
2837 clear_buffer_write_io_error(sbh);
2838 set_buffer_uptodate(sbh);
2840 es->s_wtime = cpu_to_le32(get_seconds());
2841 ext4_free_blocks_count_set(es, ext4_count_free_blocks(sb));
2842 es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
2843 BUFFER_TRACE(sbh, "marking dirty");
2844 mark_buffer_dirty(sbh);
2846 sync_dirty_buffer(sbh);
2847 if (buffer_write_io_error(sbh)) {
2848 printk(KERN_ERR "ext4: I/O error while writing "
2849 "superblock for %s.\n", sb->s_id);
2850 clear_buffer_write_io_error(sbh);
2851 set_buffer_uptodate(sbh);
2858 * Have we just finished recovery? If so, and if we are mounting (or
2859 * remounting) the filesystem readonly, then we will end up with a
2860 * consistent fs on disk. Record that fact.
2862 static void ext4_mark_recovery_complete(struct super_block *sb,
2863 struct ext4_super_block *es)
2865 journal_t *journal = EXT4_SB(sb)->s_journal;
2867 jbd2_journal_lock_updates(journal);
2868 jbd2_journal_flush(journal);
2870 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
2871 sb->s_flags & MS_RDONLY) {
2872 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2874 ext4_commit_super(sb, es, 1);
2877 jbd2_journal_unlock_updates(journal);
2881 * If we are mounting (or read-write remounting) a filesystem whose journal
2882 * has recorded an error from a previous lifetime, move that error to the
2883 * main filesystem now.
2885 static void ext4_clear_journal_err(struct super_block *sb,
2886 struct ext4_super_block *es)
2892 journal = EXT4_SB(sb)->s_journal;
2895 * Now check for any error status which may have been recorded in the
2896 * journal by a prior ext4_error() or ext4_abort()
2899 j_errno = jbd2_journal_errno(journal);
2903 errstr = ext4_decode_error(sb, j_errno, nbuf);
2904 ext4_warning(sb, __func__, "Filesystem error recorded "
2905 "from previous mount: %s", errstr);
2906 ext4_warning(sb, __func__, "Marking fs in need of "
2907 "filesystem check.");
2909 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2910 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2911 ext4_commit_super(sb, es, 1);
2913 jbd2_journal_clear_err(journal);
2918 * Force the running and committing transactions to commit,
2919 * and wait on the commit.
2921 int ext4_force_commit(struct super_block *sb)
2926 if (sb->s_flags & MS_RDONLY)
2929 journal = EXT4_SB(sb)->s_journal;
2931 ret = ext4_journal_force_commit(journal);
2936 * Ext4 always journals updates to the superblock itself, so we don't
2937 * have to propagate any other updates to the superblock on disk at this
2938 * point. Just start an async writeback to get the buffers on their way
2941 * This implicitly triggers the writebehind on sync().
2944 static void ext4_write_super(struct super_block *sb)
2946 if (mutex_trylock(&sb->s_lock) != 0)
2951 static int ext4_sync_fs(struct super_block *sb, int wait)
2955 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait);
2957 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
2959 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target);
2965 * LVM calls this function before a (read-only) snapshot is created. This
2966 * gives us a chance to flush the journal completely and mark the fs clean.
2968 static void ext4_write_super_lockfs(struct super_block *sb)
2972 if (!(sb->s_flags & MS_RDONLY)) {
2973 journal_t *journal = EXT4_SB(sb)->s_journal;
2975 /* Now we set up the journal barrier. */
2976 jbd2_journal_lock_updates(journal);
2977 jbd2_journal_flush(journal);
2979 /* Journal blocked and flushed, clear needs_recovery flag. */
2980 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2981 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
2986 * Called by LVM after the snapshot is done. We need to reset the RECOVER
2987 * flag here, even though the filesystem is not technically dirty yet.
2989 static void ext4_unlockfs(struct super_block *sb)
2991 if (!(sb->s_flags & MS_RDONLY)) {
2993 /* Reser the needs_recovery flag before the fs is unlocked. */
2994 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2995 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
2997 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3001 static int ext4_remount(struct super_block *sb, int *flags, char *data)
3003 struct ext4_super_block *es;
3004 struct ext4_sb_info *sbi = EXT4_SB(sb);
3005 ext4_fsblk_t n_blocks_count = 0;
3006 unsigned long old_sb_flags;
3007 struct ext4_mount_options old_opts;
3014 /* Store the original options */
3015 old_sb_flags = sb->s_flags;
3016 old_opts.s_mount_opt = sbi->s_mount_opt;
3017 old_opts.s_resuid = sbi->s_resuid;
3018 old_opts.s_resgid = sbi->s_resgid;
3019 old_opts.s_commit_interval = sbi->s_commit_interval;
3021 old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
3022 for (i = 0; i < MAXQUOTAS; i++)
3023 old_opts.s_qf_names[i] = sbi->s_qf_names[i];
3027 * Allow the "check" option to be passed as a remount option.
3029 if (!parse_options(data, sb, NULL, NULL, &n_blocks_count, 1)) {
3034 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3035 ext4_abort(sb, __func__, "Abort forced by user");
3037 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3038 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3042 ext4_init_journal_params(sb, sbi->s_journal);
3044 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
3045 n_blocks_count > ext4_blocks_count(es)) {
3046 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) {
3051 if (*flags & MS_RDONLY) {
3053 * First of all, the unconditional stuff we have to do
3054 * to disable replay of the journal when we next remount
3056 sb->s_flags |= MS_RDONLY;
3059 * OK, test if we are remounting a valid rw partition
3060 * readonly, and if so set the rdonly flag and then
3061 * mark the partition as valid again.
3063 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
3064 (sbi->s_mount_state & EXT4_VALID_FS))
3065 es->s_state = cpu_to_le16(sbi->s_mount_state);
3068 * We have to unlock super so that we can wait for
3072 ext4_mark_recovery_complete(sb, es);
3076 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3077 ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
3078 printk(KERN_WARNING "EXT4-fs: %s: couldn't "
3079 "remount RDWR because of unsupported "
3080 "optional features (%x).\n",
3081 sb->s_id, le32_to_cpu(ret));
3087 * Make sure the group descriptor checksums
3088 * are sane. If they aren't, refuse to
3091 for (g = 0; g < sbi->s_groups_count; g++) {
3092 struct ext4_group_desc *gdp =
3093 ext4_get_group_desc(sb, g, NULL);
3095 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
3097 "EXT4-fs: ext4_remount: "
3098 "Checksum for group %lu failed (%u!=%u)\n",
3099 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
3100 le16_to_cpu(gdp->bg_checksum));
3107 * If we have an unprocessed orphan list hanging
3108 * around from a previously readonly bdev mount,
3109 * require a full umount/remount for now.
3111 if (es->s_last_orphan) {
3112 printk(KERN_WARNING "EXT4-fs: %s: couldn't "
3113 "remount RDWR because of unprocessed "
3114 "orphan inode list. Please "
3115 "umount/remount instead.\n",
3122 * Mounting a RDONLY partition read-write, so reread
3123 * and store the current valid flag. (It may have
3124 * been changed by e2fsck since we originally mounted
3127 ext4_clear_journal_err(sb, es);
3128 sbi->s_mount_state = le16_to_cpu(es->s_state);
3129 if ((err = ext4_group_extend(sb, es, n_blocks_count)))
3131 if (!ext4_setup_super(sb, es, 0))
3132 sb->s_flags &= ~MS_RDONLY;
3136 /* Release old quota file names */
3137 for (i = 0; i < MAXQUOTAS; i++)
3138 if (old_opts.s_qf_names[i] &&
3139 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
3140 kfree(old_opts.s_qf_names[i]);
3144 sb->s_flags = old_sb_flags;
3145 sbi->s_mount_opt = old_opts.s_mount_opt;
3146 sbi->s_resuid = old_opts.s_resuid;
3147 sbi->s_resgid = old_opts.s_resgid;
3148 sbi->s_commit_interval = old_opts.s_commit_interval;
3150 sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
3151 for (i = 0; i < MAXQUOTAS; i++) {
3152 if (sbi->s_qf_names[i] &&
3153 old_opts.s_qf_names[i] != sbi->s_qf_names[i])
3154 kfree(sbi->s_qf_names[i]);
3155 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
3161 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3163 struct super_block *sb = dentry->d_sb;
3164 struct ext4_sb_info *sbi = EXT4_SB(sb);
3165 struct ext4_super_block *es = sbi->s_es;
3168 if (test_opt(sb, MINIX_DF)) {
3169 sbi->s_overhead_last = 0;
3170 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
3171 ext4_group_t ngroups = sbi->s_groups_count, i;
3172 ext4_fsblk_t overhead = 0;
3176 * Compute the overhead (FS structures). This is constant
3177 * for a given filesystem unless the number of block groups
3178 * changes so we cache the previous value until it does.
3182 * All of the blocks before first_data_block are
3185 overhead = le32_to_cpu(es->s_first_data_block);
3188 * Add the overhead attributed to the superblock and
3189 * block group descriptors. If the sparse superblocks
3190 * feature is turned on, then not all groups have this.
3192 for (i = 0; i < ngroups; i++) {
3193 overhead += ext4_bg_has_super(sb, i) +
3194 ext4_bg_num_gdb(sb, i);
3199 * Every block group has an inode bitmap, a block
3200 * bitmap, and an inode table.
3202 overhead += ngroups * (2 + sbi->s_itb_per_group);
3203 sbi->s_overhead_last = overhead;
3205 sbi->s_blocks_last = ext4_blocks_count(es);
3208 buf->f_type = EXT4_SUPER_MAGIC;
3209 buf->f_bsize = sb->s_blocksize;
3210 buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last;
3211 buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) -
3212 percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter);
3213 ext4_free_blocks_count_set(es, buf->f_bfree);
3214 buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
3215 if (buf->f_bfree < ext4_r_blocks_count(es))
3217 buf->f_files = le32_to_cpu(es->s_inodes_count);
3218 buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
3219 es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
3220 buf->f_namelen = EXT4_NAME_LEN;
3221 fsid = le64_to_cpup((void *)es->s_uuid) ^
3222 le64_to_cpup((void *)es->s_uuid + sizeof(u64));
3223 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
3224 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
3228 /* Helper function for writing quotas on sync - we need to start transaction before quota file
3229 * is locked for write. Otherwise the are possible deadlocks:
3230 * Process 1 Process 2
3231 * ext4_create() quota_sync()
3232 * jbd2_journal_start() write_dquot()
3233 * DQUOT_INIT() down(dqio_mutex)
3234 * down(dqio_mutex) jbd2_journal_start()
3240 static inline struct inode *dquot_to_inode(struct dquot *dquot)
3242 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
3245 static int ext4_dquot_initialize(struct inode *inode, int type)
3250 /* We may create quota structure so we need to reserve enough blocks */
3251 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_INIT_BLOCKS(inode->i_sb));
3253 return PTR_ERR(handle);
3254 ret = dquot_initialize(inode, type);
3255 err = ext4_journal_stop(handle);
3261 static int ext4_dquot_drop(struct inode *inode)
3266 /* We may delete quota structure so we need to reserve enough blocks */
3267 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
3268 if (IS_ERR(handle)) {
3270 * We call dquot_drop() anyway to at least release references
3271 * to quota structures so that umount does not hang.
3274 return PTR_ERR(handle);
3276 ret = dquot_drop(inode);
3277 err = ext4_journal_stop(handle);
3283 static int ext4_write_dquot(struct dquot *dquot)
3287 struct inode *inode;
3289 inode = dquot_to_inode(dquot);
3290 handle = ext4_journal_start(inode,
3291 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
3293 return PTR_ERR(handle);
3294 ret = dquot_commit(dquot);
3295 err = ext4_journal_stop(handle);
3301 static int ext4_acquire_dquot(struct dquot *dquot)
3306 handle = ext4_journal_start(dquot_to_inode(dquot),
3307 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
3309 return PTR_ERR(handle);
3310 ret = dquot_acquire(dquot);
3311 err = ext4_journal_stop(handle);
3317 static int ext4_release_dquot(struct dquot *dquot)
3322 handle = ext4_journal_start(dquot_to_inode(dquot),
3323 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
3324 if (IS_ERR(handle)) {
3325 /* Release dquot anyway to avoid endless cycle in dqput() */
3326 dquot_release(dquot);
3327 return PTR_ERR(handle);
3329 ret = dquot_release(dquot);
3330 err = ext4_journal_stop(handle);
3336 static int ext4_mark_dquot_dirty(struct dquot *dquot)
3338 /* Are we journaling quotas? */
3339 if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
3340 EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
3341 dquot_mark_dquot_dirty(dquot);
3342 return ext4_write_dquot(dquot);
3344 return dquot_mark_dquot_dirty(dquot);
3348 static int ext4_write_info(struct super_block *sb, int type)
3353 /* Data block + inode block */
3354 handle = ext4_journal_start(sb->s_root->d_inode, 2);
3356 return PTR_ERR(handle);
3357 ret = dquot_commit_info(sb, type);
3358 err = ext4_journal_stop(handle);
3365 * Turn on quotas during mount time - we need to find
3366 * the quota file and such...
3368 static int ext4_quota_on_mount(struct super_block *sb, int type)
3370 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
3371 EXT4_SB(sb)->s_jquota_fmt, type);
3375 * Standard function to be called on quota_on
3377 static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3378 char *path, int remount)
3381 struct nameidata nd;
3383 if (!test_opt(sb, QUOTA))
3385 /* When remounting, no checks are needed and in fact, path is NULL */
3387 return vfs_quota_on(sb, type, format_id, path, remount);
3389 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
3393 /* Quotafile not on the same filesystem? */
3394 if (nd.path.mnt->mnt_sb != sb) {
3398 /* Journaling quota? */
3399 if (EXT4_SB(sb)->s_qf_names[type]) {
3400 /* Quotafile not in fs root? */
3401 if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode)
3403 "EXT4-fs: Quota file not on filesystem root. "
3404 "Journaled quota will not work.\n");
3408 * When we journal data on quota file, we have to flush journal to see
3409 * all updates to the file when we bypass pagecache...
3411 if (ext4_should_journal_data(nd.path.dentry->d_inode)) {
3413 * We don't need to lock updates but journal_flush() could
3414 * otherwise be livelocked...
3416 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
3417 jbd2_journal_flush(EXT4_SB(sb)->s_journal);
3418 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3421 err = vfs_quota_on_path(sb, type, format_id, &nd.path);
3426 /* Read data from quotafile - avoid pagecache and such because we cannot afford
3427 * acquiring the locks... As quota files are never truncated and quota code
3428 * itself serializes the operations (and noone else should touch the files)
3429 * we don't have to be afraid of races */
3430 static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
3431 size_t len, loff_t off)
3433 struct inode *inode = sb_dqopt(sb)->files[type];
3434 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
3436 int offset = off & (sb->s_blocksize - 1);
3439 struct buffer_head *bh;
3440 loff_t i_size = i_size_read(inode);
3444 if (off+len > i_size)
3447 while (toread > 0) {
3448 tocopy = sb->s_blocksize - offset < toread ?
3449 sb->s_blocksize - offset : toread;
3450 bh = ext4_bread(NULL, inode, blk, 0, &err);
3453 if (!bh) /* A hole? */
3454 memset(data, 0, tocopy);
3456 memcpy(data, bh->b_data+offset, tocopy);
3466 /* Write to quotafile (we know the transaction is already started and has
3467 * enough credits) */
3468 static ssize_t ext4_quota_write(struct super_block *sb, int type,
3469 const char *data, size_t len, loff_t off)
3471 struct inode *inode = sb_dqopt(sb)->files[type];
3472 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
3474 int offset = off & (sb->s_blocksize - 1);
3476 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
3477 size_t towrite = len;
3478 struct buffer_head *bh;
3479 handle_t *handle = journal_current_handle();
3482 printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)"
3483 " cancelled because transaction is not started.\n",
3484 (unsigned long long)off, (unsigned long long)len);
3487 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
3488 while (towrite > 0) {
3489 tocopy = sb->s_blocksize - offset < towrite ?
3490 sb->s_blocksize - offset : towrite;
3491 bh = ext4_bread(handle, inode, blk, 1, &err);
3494 if (journal_quota) {
3495 err = ext4_journal_get_write_access(handle, bh);
3502 memcpy(bh->b_data+offset, data, tocopy);
3503 flush_dcache_page(bh->b_page);
3506 err = ext4_journal_dirty_metadata(handle, bh);
3508 /* Always do at least ordered writes for quotas */
3509 err = ext4_jbd2_file_inode(handle, inode);
3510 mark_buffer_dirty(bh);
3521 if (len == towrite) {
3522 mutex_unlock(&inode->i_mutex);
3525 if (inode->i_size < off+len-towrite) {
3526 i_size_write(inode, off+len-towrite);
3527 EXT4_I(inode)->i_disksize = inode->i_size;
3529 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
3530 ext4_mark_inode_dirty(handle, inode);
3531 mutex_unlock(&inode->i_mutex);
3532 return len - towrite;
3537 static int ext4_get_sb(struct file_system_type *fs_type,
3538 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
3540 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
3543 #ifdef CONFIG_PROC_FS
3544 static int ext4_ui_proc_show(struct seq_file *m, void *v)
3546 unsigned int *p = m->private;
3548 seq_printf(m, "%u\n", *p);
3552 static int ext4_ui_proc_open(struct inode *inode, struct file *file)
3554 return single_open(file, ext4_ui_proc_show, PDE(inode)->data);
3557 static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
3558 size_t cnt, loff_t *ppos)
3560 unsigned int *p = PDE(file->f_path.dentry->d_inode)->data;
3562 unsigned long value;
3564 if (cnt >= sizeof(str))
3566 if (copy_from_user(str, buf, cnt))
3568 value = simple_strtol(str, NULL, 0);
3575 const struct file_operations ext4_ui_proc_fops = {
3576 .owner = THIS_MODULE,
3577 .open = ext4_ui_proc_open,
3579 .llseek = seq_lseek,
3580 .release = single_release,
3581 .write = ext4_ui_proc_write,
3585 static struct file_system_type ext4dev_fs_type = {
3586 .owner = THIS_MODULE,
3588 .get_sb = ext4_get_sb,
3589 .kill_sb = kill_block_super,
3590 .fs_flags = FS_REQUIRES_DEV,
3593 static int __init init_ext4_fs(void)
3597 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
3598 err = init_ext4_mballoc();
3602 err = init_ext4_xattr();
3605 err = init_inodecache();
3608 err = register_filesystem(&ext4dev_fs_type);
3613 destroy_inodecache();
3617 exit_ext4_mballoc();
3621 static void __exit exit_ext4_fs(void)
3623 unregister_filesystem(&ext4dev_fs_type);
3624 destroy_inodecache();
3626 exit_ext4_mballoc();
3627 remove_proc_entry("fs/ext4", NULL);
3630 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
3631 MODULE_DESCRIPTION("Fourth Extended Filesystem with extents");
3632 MODULE_LICENSE("GPL");
3633 module_init(init_ext4_fs)
3634 module_exit(exit_ext4_fs)