2 * linux/fs/ext3/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/blkdev.h>
21 #include <linux/parser.h>
22 #include <linux/exportfs.h>
23 #include <linux/statfs.h>
24 #include <linux/random.h>
25 #include <linux/mount.h>
26 #include <linux/quotaops.h>
27 #include <linux/seq_file.h>
28 #include <linux/log2.h>
29 #include <linux/cleancache.h>
31 #include <asm/uaccess.h>
33 #define CREATE_TRACE_POINTS
40 #ifdef CONFIG_EXT3_DEFAULTS_TO_ORDERED
41 #define EXT3_MOUNT_DEFAULT_DATA_MODE EXT3_MOUNT_ORDERED_DATA
43 #define EXT3_MOUNT_DEFAULT_DATA_MODE EXT3_MOUNT_WRITEBACK_DATA
46 static int ext3_load_journal(struct super_block
*, struct ext3_super_block
*,
47 unsigned long journal_devnum
);
48 static int ext3_create_journal(struct super_block
*, struct ext3_super_block
*,
50 static int ext3_commit_super(struct super_block
*sb
,
51 struct ext3_super_block
*es
,
53 static void ext3_mark_recovery_complete(struct super_block
* sb
,
54 struct ext3_super_block
* es
);
55 static void ext3_clear_journal_err(struct super_block
* sb
,
56 struct ext3_super_block
* es
);
57 static int ext3_sync_fs(struct super_block
*sb
, int wait
);
58 static const char *ext3_decode_error(struct super_block
* sb
, int errno
,
60 static int ext3_remount (struct super_block
* sb
, int * flags
, char * data
);
61 static int ext3_statfs (struct dentry
* dentry
, struct kstatfs
* buf
);
62 static int ext3_unfreeze(struct super_block
*sb
);
63 static int ext3_freeze(struct super_block
*sb
);
66 * Wrappers for journal_start/end.
68 handle_t
*ext3_journal_start_sb(struct super_block
*sb
, int nblocks
)
72 if (sb
->s_flags
& MS_RDONLY
)
73 return ERR_PTR(-EROFS
);
75 /* Special case here: if the journal has aborted behind our
76 * backs (eg. EIO in the commit thread), then we still need to
77 * take the FS itself readonly cleanly. */
78 journal
= EXT3_SB(sb
)->s_journal
;
79 if (is_journal_aborted(journal
)) {
80 ext3_abort(sb
, __func__
,
81 "Detected aborted journal");
82 return ERR_PTR(-EROFS
);
85 return journal_start(journal
, nblocks
);
88 int __ext3_journal_stop(const char *where
, handle_t
*handle
)
90 struct super_block
*sb
;
94 sb
= handle
->h_transaction
->t_journal
->j_private
;
96 rc
= journal_stop(handle
);
101 __ext3_std_error(sb
, where
, err
);
105 void ext3_journal_abort_handle(const char *caller
, const char *err_fn
,
106 struct buffer_head
*bh
, handle_t
*handle
, int err
)
109 const char *errstr
= ext3_decode_error(NULL
, err
, nbuf
);
112 BUFFER_TRACE(bh
, "abort");
117 if (is_handle_aborted(handle
))
120 printk(KERN_ERR
"EXT3-fs: %s: aborting transaction: %s in %s\n",
121 caller
, errstr
, err_fn
);
123 journal_abort_handle(handle
);
126 void ext3_msg(struct super_block
*sb
, const char *prefix
,
127 const char *fmt
, ...)
129 struct va_format vaf
;
137 printk("%sEXT3-fs (%s): %pV\n", prefix
, sb
->s_id
, &vaf
);
142 /* Deal with the reporting of failure conditions on a filesystem such as
143 * inconsistencies detected or read IO failures.
145 * On ext2, we can store the error state of the filesystem in the
146 * superblock. That is not possible on ext3, because we may have other
147 * write ordering constraints on the superblock which prevent us from
148 * writing it out straight away; and given that the journal is about to
149 * be aborted, we can't rely on the current, or future, transactions to
150 * write out the superblock safely.
152 * We'll just use the journal_abort() error code to record an error in
153 * the journal instead. On recovery, the journal will complain about
154 * that error until we've noted it down and cleared it.
157 static void ext3_handle_error(struct super_block
*sb
)
159 struct ext3_super_block
*es
= EXT3_SB(sb
)->s_es
;
161 EXT3_SB(sb
)->s_mount_state
|= EXT3_ERROR_FS
;
162 es
->s_state
|= cpu_to_le16(EXT3_ERROR_FS
);
164 if (sb
->s_flags
& MS_RDONLY
)
167 if (!test_opt (sb
, ERRORS_CONT
)) {
168 journal_t
*journal
= EXT3_SB(sb
)->s_journal
;
170 set_opt(EXT3_SB(sb
)->s_mount_opt
, ABORT
);
172 journal_abort(journal
, -EIO
);
174 if (test_opt (sb
, ERRORS_RO
)) {
175 ext3_msg(sb
, KERN_CRIT
,
176 "error: remounting filesystem read-only");
178 * Make sure updated value of ->s_mount_state will be visible
179 * before ->s_flags update.
182 sb
->s_flags
|= MS_RDONLY
;
184 ext3_commit_super(sb
, es
, 1);
185 if (test_opt(sb
, ERRORS_PANIC
))
186 panic("EXT3-fs (%s): panic forced after error\n",
190 void ext3_error(struct super_block
*sb
, const char *function
,
191 const char *fmt
, ...)
193 struct va_format vaf
;
201 printk(KERN_CRIT
"EXT3-fs error (device %s): %s: %pV\n",
202 sb
->s_id
, function
, &vaf
);
206 ext3_handle_error(sb
);
209 static const char *ext3_decode_error(struct super_block
* sb
, int errno
,
216 errstr
= "IO failure";
219 errstr
= "Out of memory";
222 if (!sb
|| EXT3_SB(sb
)->s_journal
->j_flags
& JFS_ABORT
)
223 errstr
= "Journal has aborted";
225 errstr
= "Readonly filesystem";
228 /* If the caller passed in an extra buffer for unknown
229 * errors, textualise them now. Else we just return
232 /* Check for truncated error codes... */
233 if (snprintf(nbuf
, 16, "error %d", -errno
) >= 0)
242 /* __ext3_std_error decodes expected errors from journaling functions
243 * automatically and invokes the appropriate error response. */
245 void __ext3_std_error (struct super_block
* sb
, const char * function
,
251 /* Special case: if the error is EROFS, and we're not already
252 * inside a transaction, then there's really no point in logging
254 if (errno
== -EROFS
&& journal_current_handle() == NULL
&&
255 (sb
->s_flags
& MS_RDONLY
))
258 errstr
= ext3_decode_error(sb
, errno
, nbuf
);
259 ext3_msg(sb
, KERN_CRIT
, "error in %s: %s", function
, errstr
);
261 ext3_handle_error(sb
);
265 * ext3_abort is a much stronger failure handler than ext3_error. The
266 * abort function may be used to deal with unrecoverable failures such
267 * as journal IO errors or ENOMEM at a critical moment in log management.
269 * We unconditionally force the filesystem into an ABORT|READONLY state,
270 * unless the error response on the fs has been set to panic in which
271 * case we take the easy way out and panic immediately.
274 void ext3_abort(struct super_block
*sb
, const char *function
,
275 const char *fmt
, ...)
277 struct va_format vaf
;
285 printk(KERN_CRIT
"EXT3-fs (%s): error: %s: %pV\n",
286 sb
->s_id
, function
, &vaf
);
290 if (test_opt(sb
, ERRORS_PANIC
))
291 panic("EXT3-fs: panic from previous error\n");
293 if (sb
->s_flags
& MS_RDONLY
)
296 ext3_msg(sb
, KERN_CRIT
,
297 "error: remounting filesystem read-only");
298 EXT3_SB(sb
)->s_mount_state
|= EXT3_ERROR_FS
;
299 set_opt(EXT3_SB(sb
)->s_mount_opt
, ABORT
);
301 * Make sure updated value of ->s_mount_state will be visible
302 * before ->s_flags update.
305 sb
->s_flags
|= MS_RDONLY
;
307 if (EXT3_SB(sb
)->s_journal
)
308 journal_abort(EXT3_SB(sb
)->s_journal
, -EIO
);
311 void ext3_warning(struct super_block
*sb
, const char *function
,
312 const char *fmt
, ...)
314 struct va_format vaf
;
322 printk(KERN_WARNING
"EXT3-fs (%s): warning: %s: %pV\n",
323 sb
->s_id
, function
, &vaf
);
328 void ext3_update_dynamic_rev(struct super_block
*sb
)
330 struct ext3_super_block
*es
= EXT3_SB(sb
)->s_es
;
332 if (le32_to_cpu(es
->s_rev_level
) > EXT3_GOOD_OLD_REV
)
335 ext3_msg(sb
, KERN_WARNING
,
336 "warning: updating to rev %d because of "
337 "new feature flag, running e2fsck is recommended",
340 es
->s_first_ino
= cpu_to_le32(EXT3_GOOD_OLD_FIRST_INO
);
341 es
->s_inode_size
= cpu_to_le16(EXT3_GOOD_OLD_INODE_SIZE
);
342 es
->s_rev_level
= cpu_to_le32(EXT3_DYNAMIC_REV
);
343 /* leave es->s_feature_*compat flags alone */
344 /* es->s_uuid will be set by e2fsck if empty */
347 * The rest of the superblock fields should be zero, and if not it
348 * means they are likely already in use, so leave them alone. We
349 * can leave it up to e2fsck to clean up any inconsistencies there.
354 * Open the external journal device
356 static struct block_device
*ext3_blkdev_get(dev_t dev
, struct super_block
*sb
)
358 struct block_device
*bdev
;
359 char b
[BDEVNAME_SIZE
];
361 bdev
= blkdev_get_by_dev(dev
, FMODE_READ
|FMODE_WRITE
|FMODE_EXCL
, sb
);
367 ext3_msg(sb
, KERN_ERR
, "error: failed to open journal device %s: %ld",
368 __bdevname(dev
, b
), PTR_ERR(bdev
));
374 * Release the journal device
376 static void ext3_blkdev_put(struct block_device
*bdev
)
378 blkdev_put(bdev
, FMODE_READ
|FMODE_WRITE
|FMODE_EXCL
);
381 static void ext3_blkdev_remove(struct ext3_sb_info
*sbi
)
383 struct block_device
*bdev
;
384 bdev
= sbi
->journal_bdev
;
386 ext3_blkdev_put(bdev
);
387 sbi
->journal_bdev
= NULL
;
391 static inline struct inode
*orphan_list_entry(struct list_head
*l
)
393 return &list_entry(l
, struct ext3_inode_info
, i_orphan
)->vfs_inode
;
396 static void dump_orphan_list(struct super_block
*sb
, struct ext3_sb_info
*sbi
)
400 ext3_msg(sb
, KERN_ERR
, "error: sb orphan head is %d",
401 le32_to_cpu(sbi
->s_es
->s_last_orphan
));
403 ext3_msg(sb
, KERN_ERR
, "sb_info orphan list:");
404 list_for_each(l
, &sbi
->s_orphan
) {
405 struct inode
*inode
= orphan_list_entry(l
);
406 ext3_msg(sb
, KERN_ERR
, " "
407 "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
408 inode
->i_sb
->s_id
, inode
->i_ino
, inode
,
409 inode
->i_mode
, inode
->i_nlink
,
414 static void ext3_put_super (struct super_block
* sb
)
416 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
417 struct ext3_super_block
*es
= sbi
->s_es
;
420 dquot_disable(sb
, -1, DQUOT_USAGE_ENABLED
| DQUOT_LIMITS_ENABLED
);
421 ext3_xattr_put_super(sb
);
422 err
= journal_destroy(sbi
->s_journal
);
423 sbi
->s_journal
= NULL
;
425 ext3_abort(sb
, __func__
, "Couldn't clean up the journal");
427 if (!(sb
->s_flags
& MS_RDONLY
)) {
428 EXT3_CLEAR_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
429 es
->s_state
= cpu_to_le16(sbi
->s_mount_state
);
430 BUFFER_TRACE(sbi
->s_sbh
, "marking dirty");
431 mark_buffer_dirty(sbi
->s_sbh
);
432 ext3_commit_super(sb
, es
, 1);
435 for (i
= 0; i
< sbi
->s_gdb_count
; i
++)
436 brelse(sbi
->s_group_desc
[i
]);
437 kfree(sbi
->s_group_desc
);
438 percpu_counter_destroy(&sbi
->s_freeblocks_counter
);
439 percpu_counter_destroy(&sbi
->s_freeinodes_counter
);
440 percpu_counter_destroy(&sbi
->s_dirs_counter
);
443 for (i
= 0; i
< MAXQUOTAS
; i
++)
444 kfree(sbi
->s_qf_names
[i
]);
447 /* Debugging code just in case the in-memory inode orphan list
448 * isn't empty. The on-disk one can be non-empty if we've
449 * detected an error and taken the fs readonly, but the
450 * in-memory list had better be clean by this point. */
451 if (!list_empty(&sbi
->s_orphan
))
452 dump_orphan_list(sb
, sbi
);
453 J_ASSERT(list_empty(&sbi
->s_orphan
));
455 invalidate_bdev(sb
->s_bdev
);
456 if (sbi
->journal_bdev
&& sbi
->journal_bdev
!= sb
->s_bdev
) {
458 * Invalidate the journal device's buffers. We don't want them
459 * floating about in memory - the physical journal device may
460 * hotswapped, and it breaks the `ro-after' testing code.
462 sync_blockdev(sbi
->journal_bdev
);
463 invalidate_bdev(sbi
->journal_bdev
);
464 ext3_blkdev_remove(sbi
);
466 sb
->s_fs_info
= NULL
;
467 kfree(sbi
->s_blockgroup_lock
);
471 static struct kmem_cache
*ext3_inode_cachep
;
474 * Called inside transaction, so use GFP_NOFS
476 static struct inode
*ext3_alloc_inode(struct super_block
*sb
)
478 struct ext3_inode_info
*ei
;
480 ei
= kmem_cache_alloc(ext3_inode_cachep
, GFP_NOFS
);
483 ei
->i_block_alloc_info
= NULL
;
484 ei
->vfs_inode
.i_version
= 1;
485 atomic_set(&ei
->i_datasync_tid
, 0);
486 atomic_set(&ei
->i_sync_tid
, 0);
487 return &ei
->vfs_inode
;
490 static int ext3_drop_inode(struct inode
*inode
)
492 int drop
= generic_drop_inode(inode
);
494 trace_ext3_drop_inode(inode
, drop
);
498 static void ext3_i_callback(struct rcu_head
*head
)
500 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
501 kmem_cache_free(ext3_inode_cachep
, EXT3_I(inode
));
504 static void ext3_destroy_inode(struct inode
*inode
)
506 if (!list_empty(&(EXT3_I(inode
)->i_orphan
))) {
507 printk("EXT3 Inode %p: orphan list check failed!\n",
509 print_hex_dump(KERN_INFO
, "", DUMP_PREFIX_ADDRESS
, 16, 4,
510 EXT3_I(inode
), sizeof(struct ext3_inode_info
),
514 call_rcu(&inode
->i_rcu
, ext3_i_callback
);
517 static void init_once(void *foo
)
519 struct ext3_inode_info
*ei
= (struct ext3_inode_info
*) foo
;
521 INIT_LIST_HEAD(&ei
->i_orphan
);
522 #ifdef CONFIG_EXT3_FS_XATTR
523 init_rwsem(&ei
->xattr_sem
);
525 mutex_init(&ei
->truncate_mutex
);
526 inode_init_once(&ei
->vfs_inode
);
529 static int init_inodecache(void)
531 ext3_inode_cachep
= kmem_cache_create("ext3_inode_cache",
532 sizeof(struct ext3_inode_info
),
533 0, (SLAB_RECLAIM_ACCOUNT
|
536 if (ext3_inode_cachep
== NULL
)
541 static void destroy_inodecache(void)
544 * Make sure all delayed rcu free inodes are flushed before we
548 kmem_cache_destroy(ext3_inode_cachep
);
551 static inline void ext3_show_quota_options(struct seq_file
*seq
, struct super_block
*sb
)
553 #if defined(CONFIG_QUOTA)
554 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
556 if (sbi
->s_jquota_fmt
) {
559 switch (sbi
->s_jquota_fmt
) {
570 seq_printf(seq
, ",jqfmt=%s", fmtname
);
573 if (sbi
->s_qf_names
[USRQUOTA
])
574 seq_printf(seq
, ",usrjquota=%s", sbi
->s_qf_names
[USRQUOTA
]);
576 if (sbi
->s_qf_names
[GRPQUOTA
])
577 seq_printf(seq
, ",grpjquota=%s", sbi
->s_qf_names
[GRPQUOTA
]);
579 if (test_opt(sb
, USRQUOTA
))
580 seq_puts(seq
, ",usrquota");
582 if (test_opt(sb
, GRPQUOTA
))
583 seq_puts(seq
, ",grpquota");
587 static char *data_mode_string(unsigned long mode
)
590 case EXT3_MOUNT_JOURNAL_DATA
:
592 case EXT3_MOUNT_ORDERED_DATA
:
594 case EXT3_MOUNT_WRITEBACK_DATA
:
602 * - it's set to a non-default value OR
603 * - if the per-sb default is different from the global default
605 static int ext3_show_options(struct seq_file
*seq
, struct dentry
*root
)
607 struct super_block
*sb
= root
->d_sb
;
608 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
609 struct ext3_super_block
*es
= sbi
->s_es
;
610 unsigned long def_mount_opts
;
612 def_mount_opts
= le32_to_cpu(es
->s_default_mount_opts
);
614 if (sbi
->s_sb_block
!= 1)
615 seq_printf(seq
, ",sb=%lu", sbi
->s_sb_block
);
616 if (test_opt(sb
, MINIX_DF
))
617 seq_puts(seq
, ",minixdf");
618 if (test_opt(sb
, GRPID
))
619 seq_puts(seq
, ",grpid");
620 if (!test_opt(sb
, GRPID
) && (def_mount_opts
& EXT3_DEFM_BSDGROUPS
))
621 seq_puts(seq
, ",nogrpid");
622 if (!uid_eq(sbi
->s_resuid
, make_kuid(&init_user_ns
, EXT3_DEF_RESUID
)) ||
623 le16_to_cpu(es
->s_def_resuid
) != EXT3_DEF_RESUID
) {
624 seq_printf(seq
, ",resuid=%u",
625 from_kuid_munged(&init_user_ns
, sbi
->s_resuid
));
627 if (!gid_eq(sbi
->s_resgid
, make_kgid(&init_user_ns
, EXT3_DEF_RESGID
)) ||
628 le16_to_cpu(es
->s_def_resgid
) != EXT3_DEF_RESGID
) {
629 seq_printf(seq
, ",resgid=%u",
630 from_kgid_munged(&init_user_ns
, sbi
->s_resgid
));
632 if (test_opt(sb
, ERRORS_RO
)) {
633 int def_errors
= le16_to_cpu(es
->s_errors
);
635 if (def_errors
== EXT3_ERRORS_PANIC
||
636 def_errors
== EXT3_ERRORS_CONTINUE
) {
637 seq_puts(seq
, ",errors=remount-ro");
640 if (test_opt(sb
, ERRORS_CONT
))
641 seq_puts(seq
, ",errors=continue");
642 if (test_opt(sb
, ERRORS_PANIC
))
643 seq_puts(seq
, ",errors=panic");
644 if (test_opt(sb
, NO_UID32
))
645 seq_puts(seq
, ",nouid32");
646 if (test_opt(sb
, DEBUG
))
647 seq_puts(seq
, ",debug");
648 #ifdef CONFIG_EXT3_FS_XATTR
649 if (test_opt(sb
, XATTR_USER
))
650 seq_puts(seq
, ",user_xattr");
651 if (!test_opt(sb
, XATTR_USER
) &&
652 (def_mount_opts
& EXT3_DEFM_XATTR_USER
)) {
653 seq_puts(seq
, ",nouser_xattr");
656 #ifdef CONFIG_EXT3_FS_POSIX_ACL
657 if (test_opt(sb
, POSIX_ACL
))
658 seq_puts(seq
, ",acl");
659 if (!test_opt(sb
, POSIX_ACL
) && (def_mount_opts
& EXT3_DEFM_ACL
))
660 seq_puts(seq
, ",noacl");
662 if (!test_opt(sb
, RESERVATION
))
663 seq_puts(seq
, ",noreservation");
664 if (sbi
->s_commit_interval
) {
665 seq_printf(seq
, ",commit=%u",
666 (unsigned) (sbi
->s_commit_interval
/ HZ
));
670 * Always display barrier state so it's clear what the status is.
672 seq_puts(seq
, ",barrier=");
673 seq_puts(seq
, test_opt(sb
, BARRIER
) ? "1" : "0");
674 seq_printf(seq
, ",data=%s", data_mode_string(test_opt(sb
, DATA_FLAGS
)));
675 if (test_opt(sb
, DATA_ERR_ABORT
))
676 seq_puts(seq
, ",data_err=abort");
678 if (test_opt(sb
, NOLOAD
))
679 seq_puts(seq
, ",norecovery");
681 ext3_show_quota_options(seq
, sb
);
687 static struct inode
*ext3_nfs_get_inode(struct super_block
*sb
,
688 u64 ino
, u32 generation
)
692 if (ino
< EXT3_FIRST_INO(sb
) && ino
!= EXT3_ROOT_INO
)
693 return ERR_PTR(-ESTALE
);
694 if (ino
> le32_to_cpu(EXT3_SB(sb
)->s_es
->s_inodes_count
))
695 return ERR_PTR(-ESTALE
);
697 /* iget isn't really right if the inode is currently unallocated!!
699 * ext3_read_inode will return a bad_inode if the inode had been
700 * deleted, so we should be safe.
702 * Currently we don't know the generation for parent directory, so
703 * a generation of 0 means "accept any"
705 inode
= ext3_iget(sb
, ino
);
707 return ERR_CAST(inode
);
708 if (generation
&& inode
->i_generation
!= generation
) {
710 return ERR_PTR(-ESTALE
);
716 static struct dentry
*ext3_fh_to_dentry(struct super_block
*sb
, struct fid
*fid
,
717 int fh_len
, int fh_type
)
719 return generic_fh_to_dentry(sb
, fid
, fh_len
, fh_type
,
723 static struct dentry
*ext3_fh_to_parent(struct super_block
*sb
, struct fid
*fid
,
724 int fh_len
, int fh_type
)
726 return generic_fh_to_parent(sb
, fid
, fh_len
, fh_type
,
731 * Try to release metadata pages (indirect blocks, directories) which are
732 * mapped via the block device. Since these pages could have journal heads
733 * which would prevent try_to_free_buffers() from freeing them, we must use
734 * jbd layer's try_to_free_buffers() function to release them.
736 static int bdev_try_to_free_page(struct super_block
*sb
, struct page
*page
,
739 journal_t
*journal
= EXT3_SB(sb
)->s_journal
;
741 WARN_ON(PageChecked(page
));
742 if (!page_has_buffers(page
))
745 return journal_try_to_free_buffers(journal
, page
,
747 return try_to_free_buffers(page
);
751 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
752 #define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
754 static int ext3_write_dquot(struct dquot
*dquot
);
755 static int ext3_acquire_dquot(struct dquot
*dquot
);
756 static int ext3_release_dquot(struct dquot
*dquot
);
757 static int ext3_mark_dquot_dirty(struct dquot
*dquot
);
758 static int ext3_write_info(struct super_block
*sb
, int type
);
759 static int ext3_quota_on(struct super_block
*sb
, int type
, int format_id
,
761 static int ext3_quota_on_mount(struct super_block
*sb
, int type
);
762 static ssize_t
ext3_quota_read(struct super_block
*sb
, int type
, char *data
,
763 size_t len
, loff_t off
);
764 static ssize_t
ext3_quota_write(struct super_block
*sb
, int type
,
765 const char *data
, size_t len
, loff_t off
);
767 static const struct dquot_operations ext3_quota_operations
= {
768 .write_dquot
= ext3_write_dquot
,
769 .acquire_dquot
= ext3_acquire_dquot
,
770 .release_dquot
= ext3_release_dquot
,
771 .mark_dirty
= ext3_mark_dquot_dirty
,
772 .write_info
= ext3_write_info
,
773 .alloc_dquot
= dquot_alloc
,
774 .destroy_dquot
= dquot_destroy
,
777 static const struct quotactl_ops ext3_qctl_operations
= {
778 .quota_on
= ext3_quota_on
,
779 .quota_off
= dquot_quota_off
,
780 .quota_sync
= dquot_quota_sync
,
781 .get_info
= dquot_get_dqinfo
,
782 .set_info
= dquot_set_dqinfo
,
783 .get_dqblk
= dquot_get_dqblk
,
784 .set_dqblk
= dquot_set_dqblk
788 static const struct super_operations ext3_sops
= {
789 .alloc_inode
= ext3_alloc_inode
,
790 .destroy_inode
= ext3_destroy_inode
,
791 .write_inode
= ext3_write_inode
,
792 .dirty_inode
= ext3_dirty_inode
,
793 .drop_inode
= ext3_drop_inode
,
794 .evict_inode
= ext3_evict_inode
,
795 .put_super
= ext3_put_super
,
796 .sync_fs
= ext3_sync_fs
,
797 .freeze_fs
= ext3_freeze
,
798 .unfreeze_fs
= ext3_unfreeze
,
799 .statfs
= ext3_statfs
,
800 .remount_fs
= ext3_remount
,
801 .show_options
= ext3_show_options
,
803 .quota_read
= ext3_quota_read
,
804 .quota_write
= ext3_quota_write
,
806 .bdev_try_to_free_page
= bdev_try_to_free_page
,
809 static const struct export_operations ext3_export_ops
= {
810 .fh_to_dentry
= ext3_fh_to_dentry
,
811 .fh_to_parent
= ext3_fh_to_parent
,
812 .get_parent
= ext3_get_parent
,
816 Opt_bsd_df
, Opt_minix_df
, Opt_grpid
, Opt_nogrpid
,
817 Opt_resgid
, Opt_resuid
, Opt_sb
, Opt_err_cont
, Opt_err_panic
, Opt_err_ro
,
818 Opt_nouid32
, Opt_nocheck
, Opt_debug
, Opt_oldalloc
, Opt_orlov
,
819 Opt_user_xattr
, Opt_nouser_xattr
, Opt_acl
, Opt_noacl
,
820 Opt_reservation
, Opt_noreservation
, Opt_noload
, Opt_nobh
, Opt_bh
,
821 Opt_commit
, Opt_journal_update
, Opt_journal_inum
, Opt_journal_dev
,
822 Opt_abort
, Opt_data_journal
, Opt_data_ordered
, Opt_data_writeback
,
823 Opt_data_err_abort
, Opt_data_err_ignore
,
824 Opt_usrjquota
, Opt_grpjquota
, Opt_offusrjquota
, Opt_offgrpjquota
,
825 Opt_jqfmt_vfsold
, Opt_jqfmt_vfsv0
, Opt_jqfmt_vfsv1
, Opt_quota
,
826 Opt_noquota
, Opt_ignore
, Opt_barrier
, Opt_nobarrier
, Opt_err
,
827 Opt_resize
, Opt_usrquota
, Opt_grpquota
830 static const match_table_t tokens
= {
831 {Opt_bsd_df
, "bsddf"},
832 {Opt_minix_df
, "minixdf"},
833 {Opt_grpid
, "grpid"},
834 {Opt_grpid
, "bsdgroups"},
835 {Opt_nogrpid
, "nogrpid"},
836 {Opt_nogrpid
, "sysvgroups"},
837 {Opt_resgid
, "resgid=%u"},
838 {Opt_resuid
, "resuid=%u"},
840 {Opt_err_cont
, "errors=continue"},
841 {Opt_err_panic
, "errors=panic"},
842 {Opt_err_ro
, "errors=remount-ro"},
843 {Opt_nouid32
, "nouid32"},
844 {Opt_nocheck
, "nocheck"},
845 {Opt_nocheck
, "check=none"},
846 {Opt_debug
, "debug"},
847 {Opt_oldalloc
, "oldalloc"},
848 {Opt_orlov
, "orlov"},
849 {Opt_user_xattr
, "user_xattr"},
850 {Opt_nouser_xattr
, "nouser_xattr"},
852 {Opt_noacl
, "noacl"},
853 {Opt_reservation
, "reservation"},
854 {Opt_noreservation
, "noreservation"},
855 {Opt_noload
, "noload"},
856 {Opt_noload
, "norecovery"},
859 {Opt_commit
, "commit=%u"},
860 {Opt_journal_update
, "journal=update"},
861 {Opt_journal_inum
, "journal=%u"},
862 {Opt_journal_dev
, "journal_dev=%u"},
863 {Opt_abort
, "abort"},
864 {Opt_data_journal
, "data=journal"},
865 {Opt_data_ordered
, "data=ordered"},
866 {Opt_data_writeback
, "data=writeback"},
867 {Opt_data_err_abort
, "data_err=abort"},
868 {Opt_data_err_ignore
, "data_err=ignore"},
869 {Opt_offusrjquota
, "usrjquota="},
870 {Opt_usrjquota
, "usrjquota=%s"},
871 {Opt_offgrpjquota
, "grpjquota="},
872 {Opt_grpjquota
, "grpjquota=%s"},
873 {Opt_jqfmt_vfsold
, "jqfmt=vfsold"},
874 {Opt_jqfmt_vfsv0
, "jqfmt=vfsv0"},
875 {Opt_jqfmt_vfsv1
, "jqfmt=vfsv1"},
876 {Opt_grpquota
, "grpquota"},
877 {Opt_noquota
, "noquota"},
878 {Opt_quota
, "quota"},
879 {Opt_usrquota
, "usrquota"},
880 {Opt_barrier
, "barrier=%u"},
881 {Opt_barrier
, "barrier"},
882 {Opt_nobarrier
, "nobarrier"},
883 {Opt_resize
, "resize"},
887 static ext3_fsblk_t
get_sb_block(void **data
, struct super_block
*sb
)
889 ext3_fsblk_t sb_block
;
890 char *options
= (char *) *data
;
892 if (!options
|| strncmp(options
, "sb=", 3) != 0)
893 return 1; /* Default location */
895 /*todo: use simple_strtoll with >32bit ext3 */
896 sb_block
= simple_strtoul(options
, &options
, 0);
897 if (*options
&& *options
!= ',') {
898 ext3_msg(sb
, KERN_ERR
, "error: invalid sb specification: %s",
904 *data
= (void *) options
;
909 static int set_qf_name(struct super_block
*sb
, int qtype
, substring_t
*args
)
911 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
914 if (sb_any_quota_loaded(sb
) &&
915 !sbi
->s_qf_names
[qtype
]) {
916 ext3_msg(sb
, KERN_ERR
,
917 "Cannot change journaled "
918 "quota options when quota turned on");
921 qname
= match_strdup(args
);
923 ext3_msg(sb
, KERN_ERR
,
924 "Not enough memory for storing quotafile name");
927 if (sbi
->s_qf_names
[qtype
]) {
928 int same
= !strcmp(sbi
->s_qf_names
[qtype
], qname
);
932 ext3_msg(sb
, KERN_ERR
,
933 "%s quota file already specified",
938 if (strchr(qname
, '/')) {
939 ext3_msg(sb
, KERN_ERR
,
940 "quotafile must be on filesystem root");
944 sbi
->s_qf_names
[qtype
] = qname
;
945 set_opt(sbi
->s_mount_opt
, QUOTA
);
949 static int clear_qf_name(struct super_block
*sb
, int qtype
) {
951 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
953 if (sb_any_quota_loaded(sb
) &&
954 sbi
->s_qf_names
[qtype
]) {
955 ext3_msg(sb
, KERN_ERR
, "Cannot change journaled quota options"
956 " when quota turned on");
959 if (sbi
->s_qf_names
[qtype
]) {
960 kfree(sbi
->s_qf_names
[qtype
]);
961 sbi
->s_qf_names
[qtype
] = NULL
;
967 static int parse_options (char *options
, struct super_block
*sb
,
968 unsigned int *inum
, unsigned long *journal_devnum
,
969 ext3_fsblk_t
*n_blocks_count
, int is_remount
)
971 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
973 substring_t args
[MAX_OPT_ARGS
];
985 while ((p
= strsep (&options
, ",")) != NULL
) {
990 * Initialize args struct so we know whether arg was
991 * found; some options take optional arguments.
993 args
[0].to
= args
[0].from
= NULL
;
994 token
= match_token(p
, tokens
, args
);
997 clear_opt (sbi
->s_mount_opt
, MINIX_DF
);
1000 set_opt (sbi
->s_mount_opt
, MINIX_DF
);
1003 set_opt (sbi
->s_mount_opt
, GRPID
);
1006 clear_opt (sbi
->s_mount_opt
, GRPID
);
1009 if (match_int(&args
[0], &option
))
1011 uid
= make_kuid(current_user_ns(), option
);
1012 if (!uid_valid(uid
)) {
1013 ext3_msg(sb
, KERN_ERR
, "Invalid uid value %d", option
);
1017 sbi
->s_resuid
= uid
;
1020 if (match_int(&args
[0], &option
))
1022 gid
= make_kgid(current_user_ns(), option
);
1023 if (!gid_valid(gid
)) {
1024 ext3_msg(sb
, KERN_ERR
, "Invalid gid value %d", option
);
1027 sbi
->s_resgid
= gid
;
1030 /* handled by get_sb_block() instead of here */
1031 /* *sb_block = match_int(&args[0]); */
1034 clear_opt (sbi
->s_mount_opt
, ERRORS_CONT
);
1035 clear_opt (sbi
->s_mount_opt
, ERRORS_RO
);
1036 set_opt (sbi
->s_mount_opt
, ERRORS_PANIC
);
1039 clear_opt (sbi
->s_mount_opt
, ERRORS_CONT
);
1040 clear_opt (sbi
->s_mount_opt
, ERRORS_PANIC
);
1041 set_opt (sbi
->s_mount_opt
, ERRORS_RO
);
1044 clear_opt (sbi
->s_mount_opt
, ERRORS_RO
);
1045 clear_opt (sbi
->s_mount_opt
, ERRORS_PANIC
);
1046 set_opt (sbi
->s_mount_opt
, ERRORS_CONT
);
1049 set_opt (sbi
->s_mount_opt
, NO_UID32
);
1052 clear_opt (sbi
->s_mount_opt
, CHECK
);
1055 set_opt (sbi
->s_mount_opt
, DEBUG
);
1058 ext3_msg(sb
, KERN_WARNING
,
1059 "Ignoring deprecated oldalloc option");
1062 ext3_msg(sb
, KERN_WARNING
,
1063 "Ignoring deprecated orlov option");
1065 #ifdef CONFIG_EXT3_FS_XATTR
1066 case Opt_user_xattr
:
1067 set_opt (sbi
->s_mount_opt
, XATTR_USER
);
1069 case Opt_nouser_xattr
:
1070 clear_opt (sbi
->s_mount_opt
, XATTR_USER
);
1073 case Opt_user_xattr
:
1074 case Opt_nouser_xattr
:
1075 ext3_msg(sb
, KERN_INFO
,
1076 "(no)user_xattr options not supported");
1079 #ifdef CONFIG_EXT3_FS_POSIX_ACL
1081 set_opt(sbi
->s_mount_opt
, POSIX_ACL
);
1084 clear_opt(sbi
->s_mount_opt
, POSIX_ACL
);
1089 ext3_msg(sb
, KERN_INFO
,
1090 "(no)acl options not supported");
1093 case Opt_reservation
:
1094 set_opt(sbi
->s_mount_opt
, RESERVATION
);
1096 case Opt_noreservation
:
1097 clear_opt(sbi
->s_mount_opt
, RESERVATION
);
1099 case Opt_journal_update
:
1101 /* Eventually we will want to be able to create
1102 a journal file here. For now, only allow the
1103 user to specify an existing inode to be the
1106 ext3_msg(sb
, KERN_ERR
, "error: cannot specify "
1107 "journal on remount");
1110 set_opt (sbi
->s_mount_opt
, UPDATE_JOURNAL
);
1112 case Opt_journal_inum
:
1114 ext3_msg(sb
, KERN_ERR
, "error: cannot specify "
1115 "journal on remount");
1118 if (match_int(&args
[0], &option
))
1122 case Opt_journal_dev
:
1124 ext3_msg(sb
, KERN_ERR
, "error: cannot specify "
1125 "journal on remount");
1128 if (match_int(&args
[0], &option
))
1130 *journal_devnum
= option
;
1133 set_opt (sbi
->s_mount_opt
, NOLOAD
);
1136 if (match_int(&args
[0], &option
))
1141 option
= JBD_DEFAULT_MAX_COMMIT_AGE
;
1142 sbi
->s_commit_interval
= HZ
* option
;
1144 case Opt_data_journal
:
1145 data_opt
= EXT3_MOUNT_JOURNAL_DATA
;
1147 case Opt_data_ordered
:
1148 data_opt
= EXT3_MOUNT_ORDERED_DATA
;
1150 case Opt_data_writeback
:
1151 data_opt
= EXT3_MOUNT_WRITEBACK_DATA
;
1154 if (test_opt(sb
, DATA_FLAGS
) == data_opt
)
1156 ext3_msg(sb
, KERN_ERR
,
1157 "error: cannot change "
1158 "data mode on remount. The filesystem "
1159 "is mounted in data=%s mode and you "
1160 "try to remount it in data=%s mode.",
1161 data_mode_string(test_opt(sb
,
1163 data_mode_string(data_opt
));
1166 clear_opt(sbi
->s_mount_opt
, DATA_FLAGS
);
1167 sbi
->s_mount_opt
|= data_opt
;
1170 case Opt_data_err_abort
:
1171 set_opt(sbi
->s_mount_opt
, DATA_ERR_ABORT
);
1173 case Opt_data_err_ignore
:
1174 clear_opt(sbi
->s_mount_opt
, DATA_ERR_ABORT
);
1178 if (!set_qf_name(sb
, USRQUOTA
, &args
[0]))
1182 if (!set_qf_name(sb
, GRPQUOTA
, &args
[0]))
1185 case Opt_offusrjquota
:
1186 if (!clear_qf_name(sb
, USRQUOTA
))
1189 case Opt_offgrpjquota
:
1190 if (!clear_qf_name(sb
, GRPQUOTA
))
1193 case Opt_jqfmt_vfsold
:
1194 qfmt
= QFMT_VFS_OLD
;
1196 case Opt_jqfmt_vfsv0
:
1199 case Opt_jqfmt_vfsv1
:
1202 if (sb_any_quota_loaded(sb
) &&
1203 sbi
->s_jquota_fmt
!= qfmt
) {
1204 ext3_msg(sb
, KERN_ERR
, "error: cannot change "
1205 "journaled quota options when "
1206 "quota turned on.");
1209 sbi
->s_jquota_fmt
= qfmt
;
1213 set_opt(sbi
->s_mount_opt
, QUOTA
);
1214 set_opt(sbi
->s_mount_opt
, USRQUOTA
);
1217 set_opt(sbi
->s_mount_opt
, QUOTA
);
1218 set_opt(sbi
->s_mount_opt
, GRPQUOTA
);
1221 if (sb_any_quota_loaded(sb
)) {
1222 ext3_msg(sb
, KERN_ERR
, "error: cannot change "
1223 "quota options when quota turned on.");
1226 clear_opt(sbi
->s_mount_opt
, QUOTA
);
1227 clear_opt(sbi
->s_mount_opt
, USRQUOTA
);
1228 clear_opt(sbi
->s_mount_opt
, GRPQUOTA
);
1234 ext3_msg(sb
, KERN_ERR
,
1235 "error: quota options not supported.");
1239 case Opt_offusrjquota
:
1240 case Opt_offgrpjquota
:
1241 case Opt_jqfmt_vfsold
:
1242 case Opt_jqfmt_vfsv0
:
1243 case Opt_jqfmt_vfsv1
:
1244 ext3_msg(sb
, KERN_ERR
,
1245 "error: journaled quota options not "
1252 set_opt(sbi
->s_mount_opt
, ABORT
);
1255 clear_opt(sbi
->s_mount_opt
, BARRIER
);
1259 if (match_int(&args
[0], &option
))
1262 option
= 1; /* No argument, default to 1 */
1264 set_opt(sbi
->s_mount_opt
, BARRIER
);
1266 clear_opt(sbi
->s_mount_opt
, BARRIER
);
1272 ext3_msg(sb
, KERN_ERR
,
1273 "error: resize option only available "
1277 if (match_int(&args
[0], &option
) != 0)
1279 *n_blocks_count
= option
;
1282 ext3_msg(sb
, KERN_WARNING
,
1283 "warning: ignoring deprecated nobh option");
1286 ext3_msg(sb
, KERN_WARNING
,
1287 "warning: ignoring deprecated bh option");
1290 ext3_msg(sb
, KERN_ERR
,
1291 "error: unrecognized mount option \"%s\" "
1292 "or missing value", p
);
1297 if (sbi
->s_qf_names
[USRQUOTA
] || sbi
->s_qf_names
[GRPQUOTA
]) {
1298 if (test_opt(sb
, USRQUOTA
) && sbi
->s_qf_names
[USRQUOTA
])
1299 clear_opt(sbi
->s_mount_opt
, USRQUOTA
);
1300 if (test_opt(sb
, GRPQUOTA
) && sbi
->s_qf_names
[GRPQUOTA
])
1301 clear_opt(sbi
->s_mount_opt
, GRPQUOTA
);
1303 if (test_opt(sb
, GRPQUOTA
) || test_opt(sb
, USRQUOTA
)) {
1304 ext3_msg(sb
, KERN_ERR
, "error: old and new quota "
1309 if (!sbi
->s_jquota_fmt
) {
1310 ext3_msg(sb
, KERN_ERR
, "error: journaled quota format "
1315 if (sbi
->s_jquota_fmt
) {
1316 ext3_msg(sb
, KERN_ERR
, "error: journaled quota format "
1317 "specified with no journaling "
1326 static int ext3_setup_super(struct super_block
*sb
, struct ext3_super_block
*es
,
1329 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
1332 if (le32_to_cpu(es
->s_rev_level
) > EXT3_MAX_SUPP_REV
) {
1333 ext3_msg(sb
, KERN_ERR
,
1334 "error: revision level too high, "
1335 "forcing read-only mode");
1340 if (!(sbi
->s_mount_state
& EXT3_VALID_FS
))
1341 ext3_msg(sb
, KERN_WARNING
,
1342 "warning: mounting unchecked fs, "
1343 "running e2fsck is recommended");
1344 else if ((sbi
->s_mount_state
& EXT3_ERROR_FS
))
1345 ext3_msg(sb
, KERN_WARNING
,
1346 "warning: mounting fs with errors, "
1347 "running e2fsck is recommended");
1348 else if ((__s16
) le16_to_cpu(es
->s_max_mnt_count
) > 0 &&
1349 le16_to_cpu(es
->s_mnt_count
) >=
1350 le16_to_cpu(es
->s_max_mnt_count
))
1351 ext3_msg(sb
, KERN_WARNING
,
1352 "warning: maximal mount count reached, "
1353 "running e2fsck is recommended");
1354 else if (le32_to_cpu(es
->s_checkinterval
) &&
1355 (le32_to_cpu(es
->s_lastcheck
) +
1356 le32_to_cpu(es
->s_checkinterval
) <= get_seconds()))
1357 ext3_msg(sb
, KERN_WARNING
,
1358 "warning: checktime reached, "
1359 "running e2fsck is recommended");
1361 /* @@@ We _will_ want to clear the valid bit if we find
1362 inconsistencies, to force a fsck at reboot. But for
1363 a plain journaled filesystem we can keep it set as
1364 valid forever! :) */
1365 es
->s_state
&= cpu_to_le16(~EXT3_VALID_FS
);
1367 if (!le16_to_cpu(es
->s_max_mnt_count
))
1368 es
->s_max_mnt_count
= cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT
);
1369 le16_add_cpu(&es
->s_mnt_count
, 1);
1370 es
->s_mtime
= cpu_to_le32(get_seconds());
1371 ext3_update_dynamic_rev(sb
);
1372 EXT3_SET_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
1374 ext3_commit_super(sb
, es
, 1);
1375 if (test_opt(sb
, DEBUG
))
1376 ext3_msg(sb
, KERN_INFO
, "[bs=%lu, gc=%lu, "
1377 "bpg=%lu, ipg=%lu, mo=%04lx]",
1379 sbi
->s_groups_count
,
1380 EXT3_BLOCKS_PER_GROUP(sb
),
1381 EXT3_INODES_PER_GROUP(sb
),
1384 if (EXT3_SB(sb
)->s_journal
->j_inode
== NULL
) {
1385 char b
[BDEVNAME_SIZE
];
1386 ext3_msg(sb
, KERN_INFO
, "using external journal on %s",
1387 bdevname(EXT3_SB(sb
)->s_journal
->j_dev
, b
));
1389 ext3_msg(sb
, KERN_INFO
, "using internal journal");
1391 cleancache_init_fs(sb
);
1395 /* Called at mount-time, super-block is locked */
1396 static int ext3_check_descriptors(struct super_block
*sb
)
1398 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
1401 ext3_debug ("Checking group descriptors");
1403 for (i
= 0; i
< sbi
->s_groups_count
; i
++) {
1404 struct ext3_group_desc
*gdp
= ext3_get_group_desc(sb
, i
, NULL
);
1405 ext3_fsblk_t first_block
= ext3_group_first_block_no(sb
, i
);
1406 ext3_fsblk_t last_block
;
1408 if (i
== sbi
->s_groups_count
- 1)
1409 last_block
= le32_to_cpu(sbi
->s_es
->s_blocks_count
) - 1;
1411 last_block
= first_block
+
1412 (EXT3_BLOCKS_PER_GROUP(sb
) - 1);
1414 if (le32_to_cpu(gdp
->bg_block_bitmap
) < first_block
||
1415 le32_to_cpu(gdp
->bg_block_bitmap
) > last_block
)
1417 ext3_error (sb
, "ext3_check_descriptors",
1418 "Block bitmap for group %d"
1419 " not in group (block %lu)!",
1421 le32_to_cpu(gdp
->bg_block_bitmap
));
1424 if (le32_to_cpu(gdp
->bg_inode_bitmap
) < first_block
||
1425 le32_to_cpu(gdp
->bg_inode_bitmap
) > last_block
)
1427 ext3_error (sb
, "ext3_check_descriptors",
1428 "Inode bitmap for group %d"
1429 " not in group (block %lu)!",
1431 le32_to_cpu(gdp
->bg_inode_bitmap
));
1434 if (le32_to_cpu(gdp
->bg_inode_table
) < first_block
||
1435 le32_to_cpu(gdp
->bg_inode_table
) + sbi
->s_itb_per_group
- 1 >
1438 ext3_error (sb
, "ext3_check_descriptors",
1439 "Inode table for group %d"
1440 " not in group (block %lu)!",
1442 le32_to_cpu(gdp
->bg_inode_table
));
1447 sbi
->s_es
->s_free_blocks_count
=cpu_to_le32(ext3_count_free_blocks(sb
));
1448 sbi
->s_es
->s_free_inodes_count
=cpu_to_le32(ext3_count_free_inodes(sb
));
1453 /* ext3_orphan_cleanup() walks a singly-linked list of inodes (starting at
1454 * the superblock) which were deleted from all directories, but held open by
1455 * a process at the time of a crash. We walk the list and try to delete these
1456 * inodes at recovery time (only with a read-write filesystem).
1458 * In order to keep the orphan inode chain consistent during traversal (in
1459 * case of crash during recovery), we link each inode into the superblock
1460 * orphan list_head and handle it the same way as an inode deletion during
1461 * normal operation (which journals the operations for us).
1463 * We only do an iget() and an iput() on each inode, which is very safe if we
1464 * accidentally point at an in-use or already deleted inode. The worst that
1465 * can happen in this case is that we get a "bit already cleared" message from
1466 * ext3_free_inode(). The only reason we would point at a wrong inode is if
1467 * e2fsck was run on this filesystem, and it must have already done the orphan
1468 * inode cleanup for us, so we can safely abort without any further action.
1470 static void ext3_orphan_cleanup (struct super_block
* sb
,
1471 struct ext3_super_block
* es
)
1473 unsigned int s_flags
= sb
->s_flags
;
1474 int nr_orphans
= 0, nr_truncates
= 0;
1478 if (!es
->s_last_orphan
) {
1479 jbd_debug(4, "no orphan inodes to clean up\n");
1483 if (bdev_read_only(sb
->s_bdev
)) {
1484 ext3_msg(sb
, KERN_ERR
, "error: write access "
1485 "unavailable, skipping orphan cleanup.");
1489 /* Check if feature set allows readwrite operations */
1490 if (EXT3_HAS_RO_COMPAT_FEATURE(sb
, ~EXT3_FEATURE_RO_COMPAT_SUPP
)) {
1491 ext3_msg(sb
, KERN_INFO
, "Skipping orphan cleanup due to "
1492 "unknown ROCOMPAT features");
1496 if (EXT3_SB(sb
)->s_mount_state
& EXT3_ERROR_FS
) {
1497 /* don't clear list on RO mount w/ errors */
1498 if (es
->s_last_orphan
&& !(s_flags
& MS_RDONLY
)) {
1499 jbd_debug(1, "Errors on filesystem, "
1500 "clearing orphan list.\n");
1501 es
->s_last_orphan
= 0;
1503 jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
1507 if (s_flags
& MS_RDONLY
) {
1508 ext3_msg(sb
, KERN_INFO
, "orphan cleanup on readonly fs");
1509 sb
->s_flags
&= ~MS_RDONLY
;
1512 /* Needed for iput() to work correctly and not trash data */
1513 sb
->s_flags
|= MS_ACTIVE
;
1514 /* Turn on quotas so that they are updated correctly */
1515 for (i
= 0; i
< MAXQUOTAS
; i
++) {
1516 if (EXT3_SB(sb
)->s_qf_names
[i
]) {
1517 int ret
= ext3_quota_on_mount(sb
, i
);
1519 ext3_msg(sb
, KERN_ERR
,
1520 "error: cannot turn on journaled "
1526 while (es
->s_last_orphan
) {
1527 struct inode
*inode
;
1529 inode
= ext3_orphan_get(sb
, le32_to_cpu(es
->s_last_orphan
));
1530 if (IS_ERR(inode
)) {
1531 es
->s_last_orphan
= 0;
1535 list_add(&EXT3_I(inode
)->i_orphan
, &EXT3_SB(sb
)->s_orphan
);
1536 dquot_initialize(inode
);
1537 if (inode
->i_nlink
) {
1539 "%s: truncating inode %lu to %Ld bytes\n",
1540 __func__
, inode
->i_ino
, inode
->i_size
);
1541 jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
1542 inode
->i_ino
, inode
->i_size
);
1543 ext3_truncate(inode
);
1547 "%s: deleting unreferenced inode %lu\n",
1548 __func__
, inode
->i_ino
);
1549 jbd_debug(2, "deleting unreferenced inode %lu\n",
1553 iput(inode
); /* The delete magic happens here! */
1556 #define PLURAL(x) (x), ((x)==1) ? "" : "s"
1559 ext3_msg(sb
, KERN_INFO
, "%d orphan inode%s deleted",
1560 PLURAL(nr_orphans
));
1562 ext3_msg(sb
, KERN_INFO
, "%d truncate%s cleaned up",
1563 PLURAL(nr_truncates
));
1565 /* Turn quotas off */
1566 for (i
= 0; i
< MAXQUOTAS
; i
++) {
1567 if (sb_dqopt(sb
)->files
[i
])
1568 dquot_quota_off(sb
, i
);
1571 sb
->s_flags
= s_flags
; /* Restore MS_RDONLY status */
1575 * Maximal file size. There is a direct, and {,double-,triple-}indirect
1576 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
1577 * We need to be 1 filesystem block less than the 2^32 sector limit.
1579 static loff_t
ext3_max_size(int bits
)
1581 loff_t res
= EXT3_NDIR_BLOCKS
;
1585 /* This is calculated to be the largest file size for a
1586 * dense, file such that the total number of
1587 * sectors in the file, including data and all indirect blocks,
1588 * does not exceed 2^32 -1
1589 * __u32 i_blocks representing the total number of
1590 * 512 bytes blocks of the file
1592 upper_limit
= (1LL << 32) - 1;
1594 /* total blocks in file system block size */
1595 upper_limit
>>= (bits
- 9);
1598 /* indirect blocks */
1600 /* double indirect blocks */
1601 meta_blocks
+= 1 + (1LL << (bits
-2));
1602 /* tripple indirect blocks */
1603 meta_blocks
+= 1 + (1LL << (bits
-2)) + (1LL << (2*(bits
-2)));
1605 upper_limit
-= meta_blocks
;
1606 upper_limit
<<= bits
;
1608 res
+= 1LL << (bits
-2);
1609 res
+= 1LL << (2*(bits
-2));
1610 res
+= 1LL << (3*(bits
-2));
1612 if (res
> upper_limit
)
1615 if (res
> MAX_LFS_FILESIZE
)
1616 res
= MAX_LFS_FILESIZE
;
1621 static ext3_fsblk_t
descriptor_loc(struct super_block
*sb
,
1622 ext3_fsblk_t logic_sb_block
,
1625 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
1626 unsigned long bg
, first_meta_bg
;
1629 first_meta_bg
= le32_to_cpu(sbi
->s_es
->s_first_meta_bg
);
1631 if (!EXT3_HAS_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_META_BG
) ||
1633 return (logic_sb_block
+ nr
+ 1);
1634 bg
= sbi
->s_desc_per_block
* nr
;
1635 if (ext3_bg_has_super(sb
, bg
))
1637 return (has_super
+ ext3_group_first_block_no(sb
, bg
));
1641 static int ext3_fill_super (struct super_block
*sb
, void *data
, int silent
)
1643 struct buffer_head
* bh
;
1644 struct ext3_super_block
*es
= NULL
;
1645 struct ext3_sb_info
*sbi
;
1647 ext3_fsblk_t sb_block
= get_sb_block(&data
, sb
);
1648 ext3_fsblk_t logic_sb_block
;
1649 unsigned long offset
= 0;
1650 unsigned int journal_inum
= 0;
1651 unsigned long journal_devnum
= 0;
1652 unsigned long def_mount_opts
;
1663 sbi
= kzalloc(sizeof(*sbi
), GFP_KERNEL
);
1667 sbi
->s_blockgroup_lock
=
1668 kzalloc(sizeof(struct blockgroup_lock
), GFP_KERNEL
);
1669 if (!sbi
->s_blockgroup_lock
) {
1673 sb
->s_fs_info
= sbi
;
1674 sbi
->s_sb_block
= sb_block
;
1676 blocksize
= sb_min_blocksize(sb
, EXT3_MIN_BLOCK_SIZE
);
1678 ext3_msg(sb
, KERN_ERR
, "error: unable to set blocksize");
1683 * The ext3 superblock will not be buffer aligned for other than 1kB
1684 * block sizes. We need to calculate the offset from buffer start.
1686 if (blocksize
!= EXT3_MIN_BLOCK_SIZE
) {
1687 logic_sb_block
= (sb_block
* EXT3_MIN_BLOCK_SIZE
) / blocksize
;
1688 offset
= (sb_block
* EXT3_MIN_BLOCK_SIZE
) % blocksize
;
1690 logic_sb_block
= sb_block
;
1693 if (!(bh
= sb_bread(sb
, logic_sb_block
))) {
1694 ext3_msg(sb
, KERN_ERR
, "error: unable to read superblock");
1698 * Note: s_es must be initialized as soon as possible because
1699 * some ext3 macro-instructions depend on its value
1701 es
= (struct ext3_super_block
*) (bh
->b_data
+ offset
);
1703 sb
->s_magic
= le16_to_cpu(es
->s_magic
);
1704 if (sb
->s_magic
!= EXT3_SUPER_MAGIC
)
1707 /* Set defaults before we parse the mount options */
1708 def_mount_opts
= le32_to_cpu(es
->s_default_mount_opts
);
1709 if (def_mount_opts
& EXT3_DEFM_DEBUG
)
1710 set_opt(sbi
->s_mount_opt
, DEBUG
);
1711 if (def_mount_opts
& EXT3_DEFM_BSDGROUPS
)
1712 set_opt(sbi
->s_mount_opt
, GRPID
);
1713 if (def_mount_opts
& EXT3_DEFM_UID16
)
1714 set_opt(sbi
->s_mount_opt
, NO_UID32
);
1715 #ifdef CONFIG_EXT3_FS_XATTR
1716 if (def_mount_opts
& EXT3_DEFM_XATTR_USER
)
1717 set_opt(sbi
->s_mount_opt
, XATTR_USER
);
1719 #ifdef CONFIG_EXT3_FS_POSIX_ACL
1720 if (def_mount_opts
& EXT3_DEFM_ACL
)
1721 set_opt(sbi
->s_mount_opt
, POSIX_ACL
);
1723 if ((def_mount_opts
& EXT3_DEFM_JMODE
) == EXT3_DEFM_JMODE_DATA
)
1724 set_opt(sbi
->s_mount_opt
, JOURNAL_DATA
);
1725 else if ((def_mount_opts
& EXT3_DEFM_JMODE
) == EXT3_DEFM_JMODE_ORDERED
)
1726 set_opt(sbi
->s_mount_opt
, ORDERED_DATA
);
1727 else if ((def_mount_opts
& EXT3_DEFM_JMODE
) == EXT3_DEFM_JMODE_WBACK
)
1728 set_opt(sbi
->s_mount_opt
, WRITEBACK_DATA
);
1730 if (le16_to_cpu(sbi
->s_es
->s_errors
) == EXT3_ERRORS_PANIC
)
1731 set_opt(sbi
->s_mount_opt
, ERRORS_PANIC
);
1732 else if (le16_to_cpu(sbi
->s_es
->s_errors
) == EXT3_ERRORS_CONTINUE
)
1733 set_opt(sbi
->s_mount_opt
, ERRORS_CONT
);
1735 set_opt(sbi
->s_mount_opt
, ERRORS_RO
);
1737 sbi
->s_resuid
= make_kuid(&init_user_ns
, le16_to_cpu(es
->s_def_resuid
));
1738 sbi
->s_resgid
= make_kgid(&init_user_ns
, le16_to_cpu(es
->s_def_resgid
));
1740 /* enable barriers by default */
1741 set_opt(sbi
->s_mount_opt
, BARRIER
);
1742 set_opt(sbi
->s_mount_opt
, RESERVATION
);
1744 if (!parse_options ((char *) data
, sb
, &journal_inum
, &journal_devnum
,
1748 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
1749 (test_opt(sb
, POSIX_ACL
) ? MS_POSIXACL
: 0);
1751 if (le32_to_cpu(es
->s_rev_level
) == EXT3_GOOD_OLD_REV
&&
1752 (EXT3_HAS_COMPAT_FEATURE(sb
, ~0U) ||
1753 EXT3_HAS_RO_COMPAT_FEATURE(sb
, ~0U) ||
1754 EXT3_HAS_INCOMPAT_FEATURE(sb
, ~0U)))
1755 ext3_msg(sb
, KERN_WARNING
,
1756 "warning: feature flags set on rev 0 fs, "
1757 "running e2fsck is recommended");
1759 * Check feature flags regardless of the revision level, since we
1760 * previously didn't change the revision level when setting the flags,
1761 * so there is a chance incompat flags are set on a rev 0 filesystem.
1763 features
= EXT3_HAS_INCOMPAT_FEATURE(sb
, ~EXT3_FEATURE_INCOMPAT_SUPP
);
1765 ext3_msg(sb
, KERN_ERR
,
1766 "error: couldn't mount because of unsupported "
1767 "optional features (%x)", le32_to_cpu(features
));
1770 features
= EXT3_HAS_RO_COMPAT_FEATURE(sb
, ~EXT3_FEATURE_RO_COMPAT_SUPP
);
1771 if (!(sb
->s_flags
& MS_RDONLY
) && features
) {
1772 ext3_msg(sb
, KERN_ERR
,
1773 "error: couldn't mount RDWR because of unsupported "
1774 "optional features (%x)", le32_to_cpu(features
));
1777 blocksize
= BLOCK_SIZE
<< le32_to_cpu(es
->s_log_block_size
);
1779 if (blocksize
< EXT3_MIN_BLOCK_SIZE
||
1780 blocksize
> EXT3_MAX_BLOCK_SIZE
) {
1781 ext3_msg(sb
, KERN_ERR
,
1782 "error: couldn't mount because of unsupported "
1783 "filesystem blocksize %d", blocksize
);
1787 hblock
= bdev_logical_block_size(sb
->s_bdev
);
1788 if (sb
->s_blocksize
!= blocksize
) {
1790 * Make sure the blocksize for the filesystem is larger
1791 * than the hardware sectorsize for the machine.
1793 if (blocksize
< hblock
) {
1794 ext3_msg(sb
, KERN_ERR
,
1795 "error: fsblocksize %d too small for "
1796 "hardware sectorsize %d", blocksize
, hblock
);
1801 if (!sb_set_blocksize(sb
, blocksize
)) {
1802 ext3_msg(sb
, KERN_ERR
,
1803 "error: bad blocksize %d", blocksize
);
1806 logic_sb_block
= (sb_block
* EXT3_MIN_BLOCK_SIZE
) / blocksize
;
1807 offset
= (sb_block
* EXT3_MIN_BLOCK_SIZE
) % blocksize
;
1808 bh
= sb_bread(sb
, logic_sb_block
);
1810 ext3_msg(sb
, KERN_ERR
,
1811 "error: can't read superblock on 2nd try");
1814 es
= (struct ext3_super_block
*)(bh
->b_data
+ offset
);
1816 if (es
->s_magic
!= cpu_to_le16(EXT3_SUPER_MAGIC
)) {
1817 ext3_msg(sb
, KERN_ERR
,
1818 "error: magic mismatch");
1823 sb
->s_maxbytes
= ext3_max_size(sb
->s_blocksize_bits
);
1825 if (le32_to_cpu(es
->s_rev_level
) == EXT3_GOOD_OLD_REV
) {
1826 sbi
->s_inode_size
= EXT3_GOOD_OLD_INODE_SIZE
;
1827 sbi
->s_first_ino
= EXT3_GOOD_OLD_FIRST_INO
;
1829 sbi
->s_inode_size
= le16_to_cpu(es
->s_inode_size
);
1830 sbi
->s_first_ino
= le32_to_cpu(es
->s_first_ino
);
1831 if ((sbi
->s_inode_size
< EXT3_GOOD_OLD_INODE_SIZE
) ||
1832 (!is_power_of_2(sbi
->s_inode_size
)) ||
1833 (sbi
->s_inode_size
> blocksize
)) {
1834 ext3_msg(sb
, KERN_ERR
,
1835 "error: unsupported inode size: %d",
1840 sbi
->s_frag_size
= EXT3_MIN_FRAG_SIZE
<<
1841 le32_to_cpu(es
->s_log_frag_size
);
1842 if (blocksize
!= sbi
->s_frag_size
) {
1843 ext3_msg(sb
, KERN_ERR
,
1844 "error: fragsize %lu != blocksize %u (unsupported)",
1845 sbi
->s_frag_size
, blocksize
);
1848 sbi
->s_frags_per_block
= 1;
1849 sbi
->s_blocks_per_group
= le32_to_cpu(es
->s_blocks_per_group
);
1850 sbi
->s_frags_per_group
= le32_to_cpu(es
->s_frags_per_group
);
1851 sbi
->s_inodes_per_group
= le32_to_cpu(es
->s_inodes_per_group
);
1852 if (EXT3_INODE_SIZE(sb
) == 0 || EXT3_INODES_PER_GROUP(sb
) == 0)
1854 sbi
->s_inodes_per_block
= blocksize
/ EXT3_INODE_SIZE(sb
);
1855 if (sbi
->s_inodes_per_block
== 0)
1857 sbi
->s_itb_per_group
= sbi
->s_inodes_per_group
/
1858 sbi
->s_inodes_per_block
;
1859 sbi
->s_desc_per_block
= blocksize
/ sizeof(struct ext3_group_desc
);
1861 sbi
->s_mount_state
= le16_to_cpu(es
->s_state
);
1862 sbi
->s_addr_per_block_bits
= ilog2(EXT3_ADDR_PER_BLOCK(sb
));
1863 sbi
->s_desc_per_block_bits
= ilog2(EXT3_DESC_PER_BLOCK(sb
));
1864 for (i
=0; i
< 4; i
++)
1865 sbi
->s_hash_seed
[i
] = le32_to_cpu(es
->s_hash_seed
[i
]);
1866 sbi
->s_def_hash_version
= es
->s_def_hash_version
;
1867 i
= le32_to_cpu(es
->s_flags
);
1868 if (i
& EXT2_FLAGS_UNSIGNED_HASH
)
1869 sbi
->s_hash_unsigned
= 3;
1870 else if ((i
& EXT2_FLAGS_SIGNED_HASH
) == 0) {
1871 #ifdef __CHAR_UNSIGNED__
1872 es
->s_flags
|= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH
);
1873 sbi
->s_hash_unsigned
= 3;
1875 es
->s_flags
|= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH
);
1879 if (sbi
->s_blocks_per_group
> blocksize
* 8) {
1880 ext3_msg(sb
, KERN_ERR
,
1881 "#blocks per group too big: %lu",
1882 sbi
->s_blocks_per_group
);
1885 if (sbi
->s_frags_per_group
> blocksize
* 8) {
1886 ext3_msg(sb
, KERN_ERR
,
1887 "error: #fragments per group too big: %lu",
1888 sbi
->s_frags_per_group
);
1891 if (sbi
->s_inodes_per_group
> blocksize
* 8) {
1892 ext3_msg(sb
, KERN_ERR
,
1893 "error: #inodes per group too big: %lu",
1894 sbi
->s_inodes_per_group
);
1898 err
= generic_check_addressable(sb
->s_blocksize_bits
,
1899 le32_to_cpu(es
->s_blocks_count
));
1901 ext3_msg(sb
, KERN_ERR
,
1902 "error: filesystem is too large to mount safely");
1903 if (sizeof(sector_t
) < 8)
1904 ext3_msg(sb
, KERN_ERR
,
1905 "error: CONFIG_LBDAF not enabled");
1910 if (EXT3_BLOCKS_PER_GROUP(sb
) == 0)
1912 sbi
->s_groups_count
= ((le32_to_cpu(es
->s_blocks_count
) -
1913 le32_to_cpu(es
->s_first_data_block
) - 1)
1914 / EXT3_BLOCKS_PER_GROUP(sb
)) + 1;
1915 db_count
= DIV_ROUND_UP(sbi
->s_groups_count
, EXT3_DESC_PER_BLOCK(sb
));
1916 sbi
->s_group_desc
= kmalloc(db_count
* sizeof (struct buffer_head
*),
1918 if (sbi
->s_group_desc
== NULL
) {
1919 ext3_msg(sb
, KERN_ERR
,
1920 "error: not enough memory");
1925 bgl_lock_init(sbi
->s_blockgroup_lock
);
1927 for (i
= 0; i
< db_count
; i
++) {
1928 block
= descriptor_loc(sb
, logic_sb_block
, i
);
1929 sbi
->s_group_desc
[i
] = sb_bread(sb
, block
);
1930 if (!sbi
->s_group_desc
[i
]) {
1931 ext3_msg(sb
, KERN_ERR
,
1932 "error: can't read group descriptor %d", i
);
1937 if (!ext3_check_descriptors (sb
)) {
1938 ext3_msg(sb
, KERN_ERR
,
1939 "error: group descriptors corrupted");
1942 sbi
->s_gdb_count
= db_count
;
1943 get_random_bytes(&sbi
->s_next_generation
, sizeof(u32
));
1944 spin_lock_init(&sbi
->s_next_gen_lock
);
1946 /* per fileystem reservation list head & lock */
1947 spin_lock_init(&sbi
->s_rsv_window_lock
);
1948 sbi
->s_rsv_window_root
= RB_ROOT
;
1949 /* Add a single, static dummy reservation to the start of the
1950 * reservation window list --- it gives us a placeholder for
1951 * append-at-start-of-list which makes the allocation logic
1952 * _much_ simpler. */
1953 sbi
->s_rsv_window_head
.rsv_start
= EXT3_RESERVE_WINDOW_NOT_ALLOCATED
;
1954 sbi
->s_rsv_window_head
.rsv_end
= EXT3_RESERVE_WINDOW_NOT_ALLOCATED
;
1955 sbi
->s_rsv_window_head
.rsv_alloc_hit
= 0;
1956 sbi
->s_rsv_window_head
.rsv_goal_size
= 0;
1957 ext3_rsv_window_add(sb
, &sbi
->s_rsv_window_head
);
1960 * set up enough so that it can read an inode
1962 sb
->s_op
= &ext3_sops
;
1963 sb
->s_export_op
= &ext3_export_ops
;
1964 sb
->s_xattr
= ext3_xattr_handlers
;
1966 sb
->s_qcop
= &ext3_qctl_operations
;
1967 sb
->dq_op
= &ext3_quota_operations
;
1969 memcpy(sb
->s_uuid
, es
->s_uuid
, sizeof(es
->s_uuid
));
1970 INIT_LIST_HEAD(&sbi
->s_orphan
); /* unlinked but open files */
1971 mutex_init(&sbi
->s_orphan_lock
);
1972 mutex_init(&sbi
->s_resize_lock
);
1976 needs_recovery
= (es
->s_last_orphan
!= 0 ||
1977 EXT3_HAS_INCOMPAT_FEATURE(sb
,
1978 EXT3_FEATURE_INCOMPAT_RECOVER
));
1981 * The first inode we look at is the journal inode. Don't try
1982 * root first: it may be modified in the journal!
1984 if (!test_opt(sb
, NOLOAD
) &&
1985 EXT3_HAS_COMPAT_FEATURE(sb
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
1986 if (ext3_load_journal(sb
, es
, journal_devnum
))
1988 } else if (journal_inum
) {
1989 if (ext3_create_journal(sb
, es
, journal_inum
))
1993 ext3_msg(sb
, KERN_ERR
,
1994 "error: no journal found. "
1995 "mounting ext3 over ext2?");
1998 err
= percpu_counter_init(&sbi
->s_freeblocks_counter
,
1999 ext3_count_free_blocks(sb
));
2001 err
= percpu_counter_init(&sbi
->s_freeinodes_counter
,
2002 ext3_count_free_inodes(sb
));
2005 err
= percpu_counter_init(&sbi
->s_dirs_counter
,
2006 ext3_count_dirs(sb
));
2009 ext3_msg(sb
, KERN_ERR
, "error: insufficient memory");
2014 /* We have now updated the journal if required, so we can
2015 * validate the data journaling mode. */
2016 switch (test_opt(sb
, DATA_FLAGS
)) {
2018 /* No mode set, assume a default based on the journal
2019 capabilities: ORDERED_DATA if the journal can
2020 cope, else JOURNAL_DATA */
2021 if (journal_check_available_features
2022 (sbi
->s_journal
, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE
))
2023 set_opt(sbi
->s_mount_opt
, DEFAULT_DATA_MODE
);
2025 set_opt(sbi
->s_mount_opt
, JOURNAL_DATA
);
2028 case EXT3_MOUNT_ORDERED_DATA
:
2029 case EXT3_MOUNT_WRITEBACK_DATA
:
2030 if (!journal_check_available_features
2031 (sbi
->s_journal
, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE
)) {
2032 ext3_msg(sb
, KERN_ERR
,
2033 "error: journal does not support "
2034 "requested data journaling mode");
2042 * The journal_load will have done any necessary log recovery,
2043 * so we can safely mount the rest of the filesystem now.
2046 root
= ext3_iget(sb
, EXT3_ROOT_INO
);
2048 ext3_msg(sb
, KERN_ERR
, "error: get root inode failed");
2049 ret
= PTR_ERR(root
);
2052 if (!S_ISDIR(root
->i_mode
) || !root
->i_blocks
|| !root
->i_size
) {
2054 ext3_msg(sb
, KERN_ERR
, "error: corrupt root inode, run e2fsck");
2057 sb
->s_root
= d_make_root(root
);
2059 ext3_msg(sb
, KERN_ERR
, "error: get root dentry failed");
2064 if (ext3_setup_super(sb
, es
, sb
->s_flags
& MS_RDONLY
))
2065 sb
->s_flags
|= MS_RDONLY
;
2067 EXT3_SB(sb
)->s_mount_state
|= EXT3_ORPHAN_FS
;
2068 ext3_orphan_cleanup(sb
, es
);
2069 EXT3_SB(sb
)->s_mount_state
&= ~EXT3_ORPHAN_FS
;
2070 if (needs_recovery
) {
2071 ext3_mark_recovery_complete(sb
, es
);
2072 ext3_msg(sb
, KERN_INFO
, "recovery complete");
2074 ext3_msg(sb
, KERN_INFO
, "mounted filesystem with %s data mode",
2075 test_opt(sb
,DATA_FLAGS
) == EXT3_MOUNT_JOURNAL_DATA
? "journal":
2076 test_opt(sb
,DATA_FLAGS
) == EXT3_MOUNT_ORDERED_DATA
? "ordered":
2083 ext3_msg(sb
, KERN_INFO
,
2084 "error: can't find ext3 filesystem on dev %s.",
2089 percpu_counter_destroy(&sbi
->s_freeblocks_counter
);
2090 percpu_counter_destroy(&sbi
->s_freeinodes_counter
);
2091 percpu_counter_destroy(&sbi
->s_dirs_counter
);
2092 journal_destroy(sbi
->s_journal
);
2094 for (i
= 0; i
< db_count
; i
++)
2095 brelse(sbi
->s_group_desc
[i
]);
2096 kfree(sbi
->s_group_desc
);
2099 for (i
= 0; i
< MAXQUOTAS
; i
++)
2100 kfree(sbi
->s_qf_names
[i
]);
2102 ext3_blkdev_remove(sbi
);
2105 sb
->s_fs_info
= NULL
;
2106 kfree(sbi
->s_blockgroup_lock
);
2112 * Setup any per-fs journal parameters now. We'll do this both on
2113 * initial mount, once the journal has been initialised but before we've
2114 * done any recovery; and again on any subsequent remount.
2116 static void ext3_init_journal_params(struct super_block
*sb
, journal_t
*journal
)
2118 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
2120 if (sbi
->s_commit_interval
)
2121 journal
->j_commit_interval
= sbi
->s_commit_interval
;
2122 /* We could also set up an ext3-specific default for the commit
2123 * interval here, but for now we'll just fall back to the jbd
2126 spin_lock(&journal
->j_state_lock
);
2127 if (test_opt(sb
, BARRIER
))
2128 journal
->j_flags
|= JFS_BARRIER
;
2130 journal
->j_flags
&= ~JFS_BARRIER
;
2131 if (test_opt(sb
, DATA_ERR_ABORT
))
2132 journal
->j_flags
|= JFS_ABORT_ON_SYNCDATA_ERR
;
2134 journal
->j_flags
&= ~JFS_ABORT_ON_SYNCDATA_ERR
;
2135 spin_unlock(&journal
->j_state_lock
);
2138 static journal_t
*ext3_get_journal(struct super_block
*sb
,
2139 unsigned int journal_inum
)
2141 struct inode
*journal_inode
;
2144 /* First, test for the existence of a valid inode on disk. Bad
2145 * things happen if we iget() an unused inode, as the subsequent
2146 * iput() will try to delete it. */
2148 journal_inode
= ext3_iget(sb
, journal_inum
);
2149 if (IS_ERR(journal_inode
)) {
2150 ext3_msg(sb
, KERN_ERR
, "error: no journal found");
2153 if (!journal_inode
->i_nlink
) {
2154 make_bad_inode(journal_inode
);
2155 iput(journal_inode
);
2156 ext3_msg(sb
, KERN_ERR
, "error: journal inode is deleted");
2160 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
2161 journal_inode
, journal_inode
->i_size
);
2162 if (!S_ISREG(journal_inode
->i_mode
)) {
2163 ext3_msg(sb
, KERN_ERR
, "error: invalid journal inode");
2164 iput(journal_inode
);
2168 journal
= journal_init_inode(journal_inode
);
2170 ext3_msg(sb
, KERN_ERR
, "error: could not load journal inode");
2171 iput(journal_inode
);
2174 journal
->j_private
= sb
;
2175 ext3_init_journal_params(sb
, journal
);
2179 static journal_t
*ext3_get_dev_journal(struct super_block
*sb
,
2182 struct buffer_head
* bh
;
2186 int hblock
, blocksize
;
2187 ext3_fsblk_t sb_block
;
2188 unsigned long offset
;
2189 struct ext3_super_block
* es
;
2190 struct block_device
*bdev
;
2192 bdev
= ext3_blkdev_get(j_dev
, sb
);
2196 blocksize
= sb
->s_blocksize
;
2197 hblock
= bdev_logical_block_size(bdev
);
2198 if (blocksize
< hblock
) {
2199 ext3_msg(sb
, KERN_ERR
,
2200 "error: blocksize too small for journal device");
2204 sb_block
= EXT3_MIN_BLOCK_SIZE
/ blocksize
;
2205 offset
= EXT3_MIN_BLOCK_SIZE
% blocksize
;
2206 set_blocksize(bdev
, blocksize
);
2207 if (!(bh
= __bread(bdev
, sb_block
, blocksize
))) {
2208 ext3_msg(sb
, KERN_ERR
, "error: couldn't read superblock of "
2209 "external journal");
2213 es
= (struct ext3_super_block
*) (bh
->b_data
+ offset
);
2214 if ((le16_to_cpu(es
->s_magic
) != EXT3_SUPER_MAGIC
) ||
2215 !(le32_to_cpu(es
->s_feature_incompat
) &
2216 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV
)) {
2217 ext3_msg(sb
, KERN_ERR
, "error: external journal has "
2223 if (memcmp(EXT3_SB(sb
)->s_es
->s_journal_uuid
, es
->s_uuid
, 16)) {
2224 ext3_msg(sb
, KERN_ERR
, "error: journal UUID does not match");
2229 len
= le32_to_cpu(es
->s_blocks_count
);
2230 start
= sb_block
+ 1;
2231 brelse(bh
); /* we're done with the superblock */
2233 journal
= journal_init_dev(bdev
, sb
->s_bdev
,
2234 start
, len
, blocksize
);
2236 ext3_msg(sb
, KERN_ERR
,
2237 "error: failed to create device journal");
2240 journal
->j_private
= sb
;
2241 if (!bh_uptodate_or_lock(journal
->j_sb_buffer
)) {
2242 if (bh_submit_read(journal
->j_sb_buffer
)) {
2243 ext3_msg(sb
, KERN_ERR
, "I/O error on journal device");
2247 if (be32_to_cpu(journal
->j_superblock
->s_nr_users
) != 1) {
2248 ext3_msg(sb
, KERN_ERR
,
2249 "error: external journal has more than one "
2250 "user (unsupported) - %d",
2251 be32_to_cpu(journal
->j_superblock
->s_nr_users
));
2254 EXT3_SB(sb
)->journal_bdev
= bdev
;
2255 ext3_init_journal_params(sb
, journal
);
2258 journal_destroy(journal
);
2260 ext3_blkdev_put(bdev
);
2264 static int ext3_load_journal(struct super_block
*sb
,
2265 struct ext3_super_block
*es
,
2266 unsigned long journal_devnum
)
2269 unsigned int journal_inum
= le32_to_cpu(es
->s_journal_inum
);
2272 int really_read_only
;
2274 if (journal_devnum
&&
2275 journal_devnum
!= le32_to_cpu(es
->s_journal_dev
)) {
2276 ext3_msg(sb
, KERN_INFO
, "external journal device major/minor "
2277 "numbers have changed");
2278 journal_dev
= new_decode_dev(journal_devnum
);
2280 journal_dev
= new_decode_dev(le32_to_cpu(es
->s_journal_dev
));
2282 really_read_only
= bdev_read_only(sb
->s_bdev
);
2285 * Are we loading a blank journal or performing recovery after a
2286 * crash? For recovery, we need to check in advance whether we
2287 * can get read-write access to the device.
2290 if (EXT3_HAS_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
)) {
2291 if (sb
->s_flags
& MS_RDONLY
) {
2292 ext3_msg(sb
, KERN_INFO
,
2293 "recovery required on readonly filesystem");
2294 if (really_read_only
) {
2295 ext3_msg(sb
, KERN_ERR
, "error: write access "
2296 "unavailable, cannot proceed");
2299 ext3_msg(sb
, KERN_INFO
,
2300 "write access will be enabled during recovery");
2304 if (journal_inum
&& journal_dev
) {
2305 ext3_msg(sb
, KERN_ERR
, "error: filesystem has both journal "
2306 "and inode journals");
2311 if (!(journal
= ext3_get_journal(sb
, journal_inum
)))
2314 if (!(journal
= ext3_get_dev_journal(sb
, journal_dev
)))
2318 if (!(journal
->j_flags
& JFS_BARRIER
))
2319 printk(KERN_INFO
"EXT3-fs: barriers not enabled\n");
2321 if (!really_read_only
&& test_opt(sb
, UPDATE_JOURNAL
)) {
2322 err
= journal_update_format(journal
);
2324 ext3_msg(sb
, KERN_ERR
, "error updating journal");
2325 journal_destroy(journal
);
2330 if (!EXT3_HAS_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
))
2331 err
= journal_wipe(journal
, !really_read_only
);
2333 err
= journal_load(journal
);
2336 ext3_msg(sb
, KERN_ERR
, "error loading journal");
2337 journal_destroy(journal
);
2341 EXT3_SB(sb
)->s_journal
= journal
;
2342 ext3_clear_journal_err(sb
, es
);
2344 if (!really_read_only
&& journal_devnum
&&
2345 journal_devnum
!= le32_to_cpu(es
->s_journal_dev
)) {
2346 es
->s_journal_dev
= cpu_to_le32(journal_devnum
);
2348 /* Make sure we flush the recovery flag to disk. */
2349 ext3_commit_super(sb
, es
, 1);
2355 static int ext3_create_journal(struct super_block
*sb
,
2356 struct ext3_super_block
*es
,
2357 unsigned int journal_inum
)
2362 if (sb
->s_flags
& MS_RDONLY
) {
2363 ext3_msg(sb
, KERN_ERR
,
2364 "error: readonly filesystem when trying to "
2369 journal
= ext3_get_journal(sb
, journal_inum
);
2373 ext3_msg(sb
, KERN_INFO
, "creating new journal on inode %u",
2376 err
= journal_create(journal
);
2378 ext3_msg(sb
, KERN_ERR
, "error creating journal");
2379 journal_destroy(journal
);
2383 EXT3_SB(sb
)->s_journal
= journal
;
2385 ext3_update_dynamic_rev(sb
);
2386 EXT3_SET_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
2387 EXT3_SET_COMPAT_FEATURE(sb
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
);
2389 es
->s_journal_inum
= cpu_to_le32(journal_inum
);
2391 /* Make sure we flush the recovery flag to disk. */
2392 ext3_commit_super(sb
, es
, 1);
2397 static int ext3_commit_super(struct super_block
*sb
,
2398 struct ext3_super_block
*es
,
2401 struct buffer_head
*sbh
= EXT3_SB(sb
)->s_sbh
;
2407 if (buffer_write_io_error(sbh
)) {
2409 * Oh, dear. A previous attempt to write the
2410 * superblock failed. This could happen because the
2411 * USB device was yanked out. Or it could happen to
2412 * be a transient write error and maybe the block will
2413 * be remapped. Nothing we can do but to retry the
2414 * write and hope for the best.
2416 ext3_msg(sb
, KERN_ERR
, "previous I/O error to "
2417 "superblock detected");
2418 clear_buffer_write_io_error(sbh
);
2419 set_buffer_uptodate(sbh
);
2422 * If the file system is mounted read-only, don't update the
2423 * superblock write time. This avoids updating the superblock
2424 * write time when we are mounting the root file system
2425 * read/only but we need to replay the journal; at that point,
2426 * for people who are east of GMT and who make their clock
2427 * tick in localtime for Windows bug-for-bug compatibility,
2428 * the clock is set in the future, and this will cause e2fsck
2429 * to complain and force a full file system check.
2431 if (!(sb
->s_flags
& MS_RDONLY
))
2432 es
->s_wtime
= cpu_to_le32(get_seconds());
2433 es
->s_free_blocks_count
= cpu_to_le32(ext3_count_free_blocks(sb
));
2434 es
->s_free_inodes_count
= cpu_to_le32(ext3_count_free_inodes(sb
));
2435 BUFFER_TRACE(sbh
, "marking dirty");
2436 mark_buffer_dirty(sbh
);
2438 error
= sync_dirty_buffer(sbh
);
2439 if (buffer_write_io_error(sbh
)) {
2440 ext3_msg(sb
, KERN_ERR
, "I/O error while writing "
2442 clear_buffer_write_io_error(sbh
);
2443 set_buffer_uptodate(sbh
);
2451 * Have we just finished recovery? If so, and if we are mounting (or
2452 * remounting) the filesystem readonly, then we will end up with a
2453 * consistent fs on disk. Record that fact.
2455 static void ext3_mark_recovery_complete(struct super_block
* sb
,
2456 struct ext3_super_block
* es
)
2458 journal_t
*journal
= EXT3_SB(sb
)->s_journal
;
2460 journal_lock_updates(journal
);
2461 if (journal_flush(journal
) < 0)
2464 if (EXT3_HAS_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
) &&
2465 sb
->s_flags
& MS_RDONLY
) {
2466 EXT3_CLEAR_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
2467 ext3_commit_super(sb
, es
, 1);
2471 journal_unlock_updates(journal
);
2475 * If we are mounting (or read-write remounting) a filesystem whose journal
2476 * has recorded an error from a previous lifetime, move that error to the
2477 * main filesystem now.
2479 static void ext3_clear_journal_err(struct super_block
*sb
,
2480 struct ext3_super_block
*es
)
2486 journal
= EXT3_SB(sb
)->s_journal
;
2489 * Now check for any error status which may have been recorded in the
2490 * journal by a prior ext3_error() or ext3_abort()
2493 j_errno
= journal_errno(journal
);
2497 errstr
= ext3_decode_error(sb
, j_errno
, nbuf
);
2498 ext3_warning(sb
, __func__
, "Filesystem error recorded "
2499 "from previous mount: %s", errstr
);
2500 ext3_warning(sb
, __func__
, "Marking fs in need of "
2501 "filesystem check.");
2503 EXT3_SB(sb
)->s_mount_state
|= EXT3_ERROR_FS
;
2504 es
->s_state
|= cpu_to_le16(EXT3_ERROR_FS
);
2505 ext3_commit_super (sb
, es
, 1);
2507 journal_clear_err(journal
);
2512 * Force the running and committing transactions to commit,
2513 * and wait on the commit.
2515 int ext3_force_commit(struct super_block
*sb
)
2520 if (sb
->s_flags
& MS_RDONLY
)
2523 journal
= EXT3_SB(sb
)->s_journal
;
2524 ret
= ext3_journal_force_commit(journal
);
2528 static int ext3_sync_fs(struct super_block
*sb
, int wait
)
2532 trace_ext3_sync_fs(sb
, wait
);
2534 * Writeback quota in non-journalled quota case - journalled quota has
2537 dquot_writeback_dquots(sb
, -1);
2538 if (journal_start_commit(EXT3_SB(sb
)->s_journal
, &target
)) {
2540 log_wait_commit(EXT3_SB(sb
)->s_journal
, target
);
2546 * LVM calls this function before a (read-only) snapshot is created. This
2547 * gives us a chance to flush the journal completely and mark the fs clean.
2549 static int ext3_freeze(struct super_block
*sb
)
2554 if (!(sb
->s_flags
& MS_RDONLY
)) {
2555 journal
= EXT3_SB(sb
)->s_journal
;
2557 /* Now we set up the journal barrier. */
2558 journal_lock_updates(journal
);
2561 * We don't want to clear needs_recovery flag when we failed
2562 * to flush the journal.
2564 error
= journal_flush(journal
);
2568 /* Journal blocked and flushed, clear needs_recovery flag. */
2569 EXT3_CLEAR_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
2570 error
= ext3_commit_super(sb
, EXT3_SB(sb
)->s_es
, 1);
2577 journal_unlock_updates(journal
);
2582 * Called by LVM after the snapshot is done. We need to reset the RECOVER
2583 * flag here, even though the filesystem is not technically dirty yet.
2585 static int ext3_unfreeze(struct super_block
*sb
)
2587 if (!(sb
->s_flags
& MS_RDONLY
)) {
2588 /* Reser the needs_recovery flag before the fs is unlocked. */
2589 EXT3_SET_INCOMPAT_FEATURE(sb
, EXT3_FEATURE_INCOMPAT_RECOVER
);
2590 ext3_commit_super(sb
, EXT3_SB(sb
)->s_es
, 1);
2591 journal_unlock_updates(EXT3_SB(sb
)->s_journal
);
2596 static int ext3_remount (struct super_block
* sb
, int * flags
, char * data
)
2598 struct ext3_super_block
* es
;
2599 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
2600 ext3_fsblk_t n_blocks_count
= 0;
2601 unsigned long old_sb_flags
;
2602 struct ext3_mount_options old_opts
;
2603 int enable_quota
= 0;
2609 /* Store the original options */
2610 old_sb_flags
= sb
->s_flags
;
2611 old_opts
.s_mount_opt
= sbi
->s_mount_opt
;
2612 old_opts
.s_resuid
= sbi
->s_resuid
;
2613 old_opts
.s_resgid
= sbi
->s_resgid
;
2614 old_opts
.s_commit_interval
= sbi
->s_commit_interval
;
2616 old_opts
.s_jquota_fmt
= sbi
->s_jquota_fmt
;
2617 for (i
= 0; i
< MAXQUOTAS
; i
++)
2618 if (sbi
->s_qf_names
[i
]) {
2619 old_opts
.s_qf_names
[i
] = kstrdup(sbi
->s_qf_names
[i
],
2621 if (!old_opts
.s_qf_names
[i
]) {
2624 for (j
= 0; j
< i
; j
++)
2625 kfree(old_opts
.s_qf_names
[j
]);
2629 old_opts
.s_qf_names
[i
] = NULL
;
2633 * Allow the "check" option to be passed as a remount option.
2635 if (!parse_options(data
, sb
, NULL
, NULL
, &n_blocks_count
, 1)) {
2640 if (test_opt(sb
, ABORT
))
2641 ext3_abort(sb
, __func__
, "Abort forced by user");
2643 sb
->s_flags
= (sb
->s_flags
& ~MS_POSIXACL
) |
2644 (test_opt(sb
, POSIX_ACL
) ? MS_POSIXACL
: 0);
2648 ext3_init_journal_params(sb
, sbi
->s_journal
);
2650 if ((*flags
& MS_RDONLY
) != (sb
->s_flags
& MS_RDONLY
) ||
2651 n_blocks_count
> le32_to_cpu(es
->s_blocks_count
)) {
2652 if (test_opt(sb
, ABORT
)) {
2657 if (*flags
& MS_RDONLY
) {
2658 err
= dquot_suspend(sb
, -1);
2663 * First of all, the unconditional stuff we have to do
2664 * to disable replay of the journal when we next remount
2666 sb
->s_flags
|= MS_RDONLY
;
2669 * OK, test if we are remounting a valid rw partition
2670 * readonly, and if so set the rdonly flag and then
2671 * mark the partition as valid again.
2673 if (!(es
->s_state
& cpu_to_le16(EXT3_VALID_FS
)) &&
2674 (sbi
->s_mount_state
& EXT3_VALID_FS
))
2675 es
->s_state
= cpu_to_le16(sbi
->s_mount_state
);
2677 ext3_mark_recovery_complete(sb
, es
);
2680 if ((ret
= EXT3_HAS_RO_COMPAT_FEATURE(sb
,
2681 ~EXT3_FEATURE_RO_COMPAT_SUPP
))) {
2682 ext3_msg(sb
, KERN_WARNING
,
2683 "warning: couldn't remount RDWR "
2684 "because of unsupported optional "
2685 "features (%x)", le32_to_cpu(ret
));
2691 * If we have an unprocessed orphan list hanging
2692 * around from a previously readonly bdev mount,
2693 * require a full umount & mount for now.
2695 if (es
->s_last_orphan
) {
2696 ext3_msg(sb
, KERN_WARNING
, "warning: couldn't "
2697 "remount RDWR because of unprocessed "
2698 "orphan inode list. Please "
2699 "umount & mount instead.");
2705 * Mounting a RDONLY partition read-write, so reread
2706 * and store the current valid flag. (It may have
2707 * been changed by e2fsck since we originally mounted
2710 ext3_clear_journal_err(sb
, es
);
2711 sbi
->s_mount_state
= le16_to_cpu(es
->s_state
);
2712 if ((err
= ext3_group_extend(sb
, es
, n_blocks_count
)))
2714 if (!ext3_setup_super (sb
, es
, 0))
2715 sb
->s_flags
&= ~MS_RDONLY
;
2720 /* Release old quota file names */
2721 for (i
= 0; i
< MAXQUOTAS
; i
++)
2722 kfree(old_opts
.s_qf_names
[i
]);
2725 dquot_resume(sb
, -1);
2728 sb
->s_flags
= old_sb_flags
;
2729 sbi
->s_mount_opt
= old_opts
.s_mount_opt
;
2730 sbi
->s_resuid
= old_opts
.s_resuid
;
2731 sbi
->s_resgid
= old_opts
.s_resgid
;
2732 sbi
->s_commit_interval
= old_opts
.s_commit_interval
;
2734 sbi
->s_jquota_fmt
= old_opts
.s_jquota_fmt
;
2735 for (i
= 0; i
< MAXQUOTAS
; i
++) {
2736 kfree(sbi
->s_qf_names
[i
]);
2737 sbi
->s_qf_names
[i
] = old_opts
.s_qf_names
[i
];
2743 static int ext3_statfs (struct dentry
* dentry
, struct kstatfs
* buf
)
2745 struct super_block
*sb
= dentry
->d_sb
;
2746 struct ext3_sb_info
*sbi
= EXT3_SB(sb
);
2747 struct ext3_super_block
*es
= sbi
->s_es
;
2750 if (test_opt(sb
, MINIX_DF
)) {
2751 sbi
->s_overhead_last
= 0;
2752 } else if (sbi
->s_blocks_last
!= le32_to_cpu(es
->s_blocks_count
)) {
2753 unsigned long ngroups
= sbi
->s_groups_count
, i
;
2754 ext3_fsblk_t overhead
= 0;
2758 * Compute the overhead (FS structures). This is constant
2759 * for a given filesystem unless the number of block groups
2760 * changes so we cache the previous value until it does.
2764 * All of the blocks before first_data_block are
2767 overhead
= le32_to_cpu(es
->s_first_data_block
);
2770 * Add the overhead attributed to the superblock and
2771 * block group descriptors. If the sparse superblocks
2772 * feature is turned on, then not all groups have this.
2774 for (i
= 0; i
< ngroups
; i
++) {
2775 overhead
+= ext3_bg_has_super(sb
, i
) +
2776 ext3_bg_num_gdb(sb
, i
);
2781 * Every block group has an inode bitmap, a block
2782 * bitmap, and an inode table.
2784 overhead
+= ngroups
* (2 + sbi
->s_itb_per_group
);
2785 sbi
->s_overhead_last
= overhead
;
2787 sbi
->s_blocks_last
= le32_to_cpu(es
->s_blocks_count
);
2790 buf
->f_type
= EXT3_SUPER_MAGIC
;
2791 buf
->f_bsize
= sb
->s_blocksize
;
2792 buf
->f_blocks
= le32_to_cpu(es
->s_blocks_count
) - sbi
->s_overhead_last
;
2793 buf
->f_bfree
= percpu_counter_sum_positive(&sbi
->s_freeblocks_counter
);
2794 buf
->f_bavail
= buf
->f_bfree
- le32_to_cpu(es
->s_r_blocks_count
);
2795 if (buf
->f_bfree
< le32_to_cpu(es
->s_r_blocks_count
))
2797 buf
->f_files
= le32_to_cpu(es
->s_inodes_count
);
2798 buf
->f_ffree
= percpu_counter_sum_positive(&sbi
->s_freeinodes_counter
);
2799 buf
->f_namelen
= EXT3_NAME_LEN
;
2800 fsid
= le64_to_cpup((void *)es
->s_uuid
) ^
2801 le64_to_cpup((void *)es
->s_uuid
+ sizeof(u64
));
2802 buf
->f_fsid
.val
[0] = fsid
& 0xFFFFFFFFUL
;
2803 buf
->f_fsid
.val
[1] = (fsid
>> 32) & 0xFFFFFFFFUL
;
2807 /* Helper function for writing quotas on sync - we need to start transaction before quota file
2808 * is locked for write. Otherwise the are possible deadlocks:
2809 * Process 1 Process 2
2810 * ext3_create() quota_sync()
2811 * journal_start() write_dquot()
2812 * dquot_initialize() down(dqio_mutex)
2813 * down(dqio_mutex) journal_start()
2819 static inline struct inode
*dquot_to_inode(struct dquot
*dquot
)
2821 return sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_id
.type
];
2824 static int ext3_write_dquot(struct dquot
*dquot
)
2828 struct inode
*inode
;
2830 inode
= dquot_to_inode(dquot
);
2831 handle
= ext3_journal_start(inode
,
2832 EXT3_QUOTA_TRANS_BLOCKS(dquot
->dq_sb
));
2834 return PTR_ERR(handle
);
2835 ret
= dquot_commit(dquot
);
2836 err
= ext3_journal_stop(handle
);
2842 static int ext3_acquire_dquot(struct dquot
*dquot
)
2847 handle
= ext3_journal_start(dquot_to_inode(dquot
),
2848 EXT3_QUOTA_INIT_BLOCKS(dquot
->dq_sb
));
2850 return PTR_ERR(handle
);
2851 ret
= dquot_acquire(dquot
);
2852 err
= ext3_journal_stop(handle
);
2858 static int ext3_release_dquot(struct dquot
*dquot
)
2863 handle
= ext3_journal_start(dquot_to_inode(dquot
),
2864 EXT3_QUOTA_DEL_BLOCKS(dquot
->dq_sb
));
2865 if (IS_ERR(handle
)) {
2866 /* Release dquot anyway to avoid endless cycle in dqput() */
2867 dquot_release(dquot
);
2868 return PTR_ERR(handle
);
2870 ret
= dquot_release(dquot
);
2871 err
= ext3_journal_stop(handle
);
2877 static int ext3_mark_dquot_dirty(struct dquot
*dquot
)
2879 /* Are we journaling quotas? */
2880 if (EXT3_SB(dquot
->dq_sb
)->s_qf_names
[USRQUOTA
] ||
2881 EXT3_SB(dquot
->dq_sb
)->s_qf_names
[GRPQUOTA
]) {
2882 dquot_mark_dquot_dirty(dquot
);
2883 return ext3_write_dquot(dquot
);
2885 return dquot_mark_dquot_dirty(dquot
);
2889 static int ext3_write_info(struct super_block
*sb
, int type
)
2894 /* Data block + inode block */
2895 handle
= ext3_journal_start(sb
->s_root
->d_inode
, 2);
2897 return PTR_ERR(handle
);
2898 ret
= dquot_commit_info(sb
, type
);
2899 err
= ext3_journal_stop(handle
);
2906 * Turn on quotas during mount time - we need to find
2907 * the quota file and such...
2909 static int ext3_quota_on_mount(struct super_block
*sb
, int type
)
2911 return dquot_quota_on_mount(sb
, EXT3_SB(sb
)->s_qf_names
[type
],
2912 EXT3_SB(sb
)->s_jquota_fmt
, type
);
2916 * Standard function to be called on quota_on
2918 static int ext3_quota_on(struct super_block
*sb
, int type
, int format_id
,
2923 if (!test_opt(sb
, QUOTA
))
2926 /* Quotafile not on the same filesystem? */
2927 if (path
->dentry
->d_sb
!= sb
)
2929 /* Journaling quota? */
2930 if (EXT3_SB(sb
)->s_qf_names
[type
]) {
2931 /* Quotafile not of fs root? */
2932 if (path
->dentry
->d_parent
!= sb
->s_root
)
2933 ext3_msg(sb
, KERN_WARNING
,
2934 "warning: Quota file not on filesystem root. "
2935 "Journaled quota will not work.");
2939 * When we journal data on quota file, we have to flush journal to see
2940 * all updates to the file when we bypass pagecache...
2942 if (ext3_should_journal_data(path
->dentry
->d_inode
)) {
2944 * We don't need to lock updates but journal_flush() could
2945 * otherwise be livelocked...
2947 journal_lock_updates(EXT3_SB(sb
)->s_journal
);
2948 err
= journal_flush(EXT3_SB(sb
)->s_journal
);
2949 journal_unlock_updates(EXT3_SB(sb
)->s_journal
);
2954 return dquot_quota_on(sb
, type
, format_id
, path
);
2957 /* Read data from quotafile - avoid pagecache and such because we cannot afford
2958 * acquiring the locks... As quota files are never truncated and quota code
2959 * itself serializes the operations (and no one else should touch the files)
2960 * we don't have to be afraid of races */
2961 static ssize_t
ext3_quota_read(struct super_block
*sb
, int type
, char *data
,
2962 size_t len
, loff_t off
)
2964 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
2965 sector_t blk
= off
>> EXT3_BLOCK_SIZE_BITS(sb
);
2967 int offset
= off
& (sb
->s_blocksize
- 1);
2970 struct buffer_head
*bh
;
2971 loff_t i_size
= i_size_read(inode
);
2975 if (off
+len
> i_size
)
2978 while (toread
> 0) {
2979 tocopy
= sb
->s_blocksize
- offset
< toread
?
2980 sb
->s_blocksize
- offset
: toread
;
2981 bh
= ext3_bread(NULL
, inode
, blk
, 0, &err
);
2984 if (!bh
) /* A hole? */
2985 memset(data
, 0, tocopy
);
2987 memcpy(data
, bh
->b_data
+offset
, tocopy
);
2997 /* Write to quotafile (we know the transaction is already started and has
2998 * enough credits) */
2999 static ssize_t
ext3_quota_write(struct super_block
*sb
, int type
,
3000 const char *data
, size_t len
, loff_t off
)
3002 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
3003 sector_t blk
= off
>> EXT3_BLOCK_SIZE_BITS(sb
);
3005 int offset
= off
& (sb
->s_blocksize
- 1);
3006 int journal_quota
= EXT3_SB(sb
)->s_qf_names
[type
] != NULL
;
3007 struct buffer_head
*bh
;
3008 handle_t
*handle
= journal_current_handle();
3011 ext3_msg(sb
, KERN_WARNING
,
3012 "warning: quota write (off=%llu, len=%llu)"
3013 " cancelled because transaction is not started.",
3014 (unsigned long long)off
, (unsigned long long)len
);
3019 * Since we account only one data block in transaction credits,
3020 * then it is impossible to cross a block boundary.
3022 if (sb
->s_blocksize
- offset
< len
) {
3023 ext3_msg(sb
, KERN_WARNING
, "Quota write (off=%llu, len=%llu)"
3024 " cancelled because not block aligned",
3025 (unsigned long long)off
, (unsigned long long)len
);
3028 bh
= ext3_bread(handle
, inode
, blk
, 1, &err
);
3031 if (journal_quota
) {
3032 err
= ext3_journal_get_write_access(handle
, bh
);
3039 memcpy(bh
->b_data
+offset
, data
, len
);
3040 flush_dcache_page(bh
->b_page
);
3043 err
= ext3_journal_dirty_metadata(handle
, bh
);
3045 /* Always do at least ordered writes for quotas */
3046 err
= ext3_journal_dirty_data(handle
, bh
);
3047 mark_buffer_dirty(bh
);
3053 if (inode
->i_size
< off
+ len
) {
3054 i_size_write(inode
, off
+ len
);
3055 EXT3_I(inode
)->i_disksize
= inode
->i_size
;
3058 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
3059 ext3_mark_inode_dirty(handle
, inode
);
3065 static struct dentry
*ext3_mount(struct file_system_type
*fs_type
,
3066 int flags
, const char *dev_name
, void *data
)
3068 return mount_bdev(fs_type
, flags
, dev_name
, data
, ext3_fill_super
);
3071 static struct file_system_type ext3_fs_type
= {
3072 .owner
= THIS_MODULE
,
3074 .mount
= ext3_mount
,
3075 .kill_sb
= kill_block_super
,
3076 .fs_flags
= FS_REQUIRES_DEV
,
3078 MODULE_ALIAS_FS("ext3");
3080 static int __init
init_ext3_fs(void)
3082 int err
= init_ext3_xattr();
3085 err
= init_inodecache();
3088 err
= register_filesystem(&ext3_fs_type
);
3093 destroy_inodecache();
3099 static void __exit
exit_ext3_fs(void)
3101 unregister_filesystem(&ext3_fs_type
);
3102 destroy_inodecache();
3106 MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
3107 MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions");
3108 MODULE_LICENSE("GPL");
3109 module_init(init_ext3_fs
)
3110 module_exit(exit_ext3_fs
)