2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
4 * Trivial changes by Alan Cox to add the LFS fixes
7 * Rights granted to Hans Reiser to redistribute under other terms providing
8 * he accepts all liability including but not limited to patent, fitness
9 * for purpose, and direct or indirect claims arising from failure to perform.
14 #include <linux/module.h>
15 #include <linux/vmalloc.h>
16 #include <linux/time.h>
17 #include <asm/uaccess.h>
18 #include <linux/reiserfs_fs.h>
19 #include <linux/reiserfs_acl.h>
20 #include <linux/reiserfs_xattr.h>
21 #include <linux/smp_lock.h>
22 #include <linux/init.h>
23 #include <linux/blkdev.h>
24 #include <linux/buffer_head.h>
25 #include <linux/vfs.h>
26 #include <linux/mnt_namespace.h>
27 #include <linux/mount.h>
28 #include <linux/namei.h>
29 #include <linux/quotaops.h>
31 struct file_system_type reiserfs_fs_type;
33 static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
34 static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
35 static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
37 int is_reiserfs_3_5(struct reiserfs_super_block *rs)
39 return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
40 strlen(reiserfs_3_5_magic_string));
43 int is_reiserfs_3_6(struct reiserfs_super_block *rs)
45 return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
46 strlen(reiserfs_3_6_magic_string));
49 int is_reiserfs_jr(struct reiserfs_super_block *rs)
51 return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
52 strlen(reiserfs_jr_magic_string));
55 static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
57 return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
61 static int reiserfs_remount(struct super_block *s, int *flags, char *data);
62 static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
64 static int reiserfs_sync_fs(struct super_block *s, int wait)
66 if (!(s->s_flags & MS_RDONLY)) {
67 struct reiserfs_transaction_handle th;
68 reiserfs_write_lock(s);
69 if (!journal_begin(&th, s, 1))
70 if (!journal_end_sync(&th, s, 1))
71 reiserfs_flush_old_commits(s);
72 s->s_dirt = 0; /* Even if it's not true.
73 * We'll loop forever in sync_supers otherwise */
74 reiserfs_write_unlock(s);
81 static void reiserfs_write_super(struct super_block *s)
83 reiserfs_sync_fs(s, 1);
86 static void reiserfs_write_super_lockfs(struct super_block *s)
88 struct reiserfs_transaction_handle th;
89 reiserfs_write_lock(s);
90 if (!(s->s_flags & MS_RDONLY)) {
91 int err = journal_begin(&th, s, 1);
93 reiserfs_block_writes(&th);
95 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
97 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
98 reiserfs_block_writes(&th);
99 journal_end_sync(&th, s, 1);
103 reiserfs_write_unlock(s);
106 static void reiserfs_unlockfs(struct super_block *s)
108 reiserfs_allow_writes(s);
111 extern const struct in_core_key MAX_IN_CORE_KEY;
113 /* this is used to delete "save link" when there are no items of a
114 file it points to. It can either happen if unlink is completed but
115 "save unlink" removal, or if file has both unlink and truncate
116 pending and as unlink completes first (because key of "save link"
117 protecting unlink is bigger that a key lf "save link" which
118 protects truncate), so there left no items to make truncate
120 static int remove_save_link_only(struct super_block *s,
121 struct reiserfs_key *key, int oid_free)
123 struct reiserfs_transaction_handle th;
126 /* we are going to do one balancing */
127 err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
131 reiserfs_delete_solid_item(&th, NULL, key);
133 /* removals are protected by direct items */
134 reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
136 return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
140 static int reiserfs_quota_on_mount(struct super_block *, int);
143 /* look for uncompleted unlinks and truncates and complete them */
144 static int finish_unfinished(struct super_block *s)
146 INITIALIZE_PATH(path);
147 struct cpu_key max_cpu_key, obj_key;
148 struct reiserfs_key save_link_key;
150 struct item_head *ih;
151 struct buffer_head *bh;
162 /* compose key to look for "save" links */
163 max_cpu_key.version = KEY_FORMAT_3_5;
164 max_cpu_key.on_disk_key.k_dir_id = ~0U;
165 max_cpu_key.on_disk_key.k_objectid = ~0U;
166 set_cpu_key_k_offset(&max_cpu_key, ~0U);
167 max_cpu_key.key_length = 3;
170 /* Needed for iput() to work correctly and not trash data */
171 if (s->s_flags & MS_ACTIVE) {
175 s->s_flags |= MS_ACTIVE;
177 /* Turn on quotas so that they are updated correctly */
178 for (i = 0; i < MAXQUOTAS; i++) {
179 if (REISERFS_SB(s)->s_qf_names[i]) {
180 int ret = reiserfs_quota_on_mount(s, i);
183 "reiserfs: cannot turn on journalled quota: error %d",
190 REISERFS_SB(s)->s_is_unlinked_ok = 1;
192 retval = search_item(s, &max_cpu_key, &path);
193 if (retval != ITEM_NOT_FOUND) {
195 "vs-2140: finish_unfinished: search_by_key returned %d",
200 bh = get_last_bh(&path);
201 item_pos = get_item_pos(&path);
202 if (item_pos != B_NR_ITEMS(bh)) {
204 "vs-2060: finish_unfinished: wrong position found");
208 ih = B_N_PITEM_HEAD(bh, item_pos);
210 if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
211 /* there are no "save" links anymore */
214 save_link_key = ih->ih_key;
215 if (is_indirect_le_ih(ih))
220 /* reiserfs_iget needs k_dirid and k_objectid only */
221 item = B_I_PITEM(bh, ih);
222 obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
223 obj_key.on_disk_key.k_objectid =
224 le32_to_cpu(ih->ih_key.k_objectid);
225 obj_key.on_disk_key.k_offset = 0;
226 obj_key.on_disk_key.k_type = 0;
230 inode = reiserfs_iget(s, &obj_key);
232 /* the unlink almost completed, it just did not manage to remove
233 "save" link and release objectid */
235 "vs-2180: finish_unfinished: iget failed for %K",
237 retval = remove_save_link_only(s, &save_link_key, 1);
241 if (!truncate && inode->i_nlink) {
242 /* file is not unlinked */
244 "vs-2185: finish_unfinished: file %K is not unlinked",
246 retval = remove_save_link_only(s, &save_link_key, 0);
251 if (truncate && S_ISDIR(inode->i_mode)) {
252 /* We got a truncate request for a dir which is impossible.
253 The only imaginable way is to execute unfinished truncate request
254 then boot into old kernel, remove the file and create dir with
257 "green-2101: impossible truncate on a directory %k. Please report",
259 retval = remove_save_link_only(s, &save_link_key, 0);
266 REISERFS_I(inode)->i_flags |=
267 i_link_saved_truncate_mask;
268 /* not completed truncate found. New size was committed together
270 reiserfs_info(s, "Truncating %k to %Ld ..",
271 INODE_PKEY(inode), inode->i_size);
272 reiserfs_truncate_file(inode,
274 /*don't update modification time */
276 retval = remove_save_link(inode, truncate);
278 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
279 /* not completed unlink (rmdir) found */
280 reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
281 /* removal gets completed in iput */
289 REISERFS_SB(s)->s_is_unlinked_ok = 0;
292 /* Turn quotas off */
293 for (i = 0; i < MAXQUOTAS; i++) {
294 if (sb_dqopt(s)->files[i])
295 vfs_quota_off_mount(s, i);
298 /* Restore the flag back */
299 s->s_flags &= ~MS_ACTIVE;
303 reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
304 "Completed\n", done);
308 /* to protect file being unlinked from getting lost we "safe" link files
309 being unlinked. This link will be deleted in the same transaction with last
310 item of file. mounting the filesytem we scan all these links and remove
311 files which almost got lost */
312 void add_save_link(struct reiserfs_transaction_handle *th,
313 struct inode *inode, int truncate)
315 INITIALIZE_PATH(path);
321 BUG_ON(!th->t_trans_id);
323 /* file can only get one "save link" of each kind */
325 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
326 "saved link already exists for truncated inode %lx",
329 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
330 "saved link already exists for unlinked inode %lx",
333 /* setup key of "save" link */
334 key.version = KEY_FORMAT_3_5;
335 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
336 key.on_disk_key.k_objectid = inode->i_ino;
338 /* unlink, rmdir, rename */
339 set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
340 set_cpu_key_k_type(&key, TYPE_DIRECT);
342 /* item head of "safe" link */
343 make_le_item_head(&ih, &key, key.version,
344 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
345 4 /*length */ , 0xffff /*free space */ );
348 if (S_ISDIR(inode->i_mode))
349 reiserfs_warning(inode->i_sb,
350 "green-2102: Adding a truncate savelink for a directory %k! Please report",
352 set_cpu_key_k_offset(&key, 1);
353 set_cpu_key_k_type(&key, TYPE_INDIRECT);
355 /* item head of "safe" link */
356 make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
357 4 /*length */ , 0 /*free space */ );
361 /* look for its place in the tree */
362 retval = search_item(inode->i_sb, &key, &path);
363 if (retval != ITEM_NOT_FOUND) {
364 if (retval != -ENOSPC)
365 reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
366 "search_by_key (%K) returned %d", &key,
372 /* body of "save" link */
373 link = INODE_PKEY(inode)->k_dir_id;
375 /* put "save" link inot tree, don't charge quota to anyone */
377 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
379 if (retval != -ENOSPC)
380 reiserfs_warning(inode->i_sb,
381 "vs-2120: add_save_link: insert_item returned %d",
385 REISERFS_I(inode)->i_flags |=
386 i_link_saved_truncate_mask;
388 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
392 /* this opens transaction unlike add_save_link */
393 int remove_save_link(struct inode *inode, int truncate)
395 struct reiserfs_transaction_handle th;
396 struct reiserfs_key key;
399 /* we are going to do one balancing only */
400 err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
404 /* setup key of "save" link */
405 key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
406 key.k_objectid = INODE_PKEY(inode)->k_objectid;
408 /* unlink, rmdir, rename */
409 set_le_key_k_offset(KEY_FORMAT_3_5, &key,
410 1 + inode->i_sb->s_blocksize);
411 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
414 set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
415 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
419 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
421 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
422 /* don't take quota bytes from anywhere */
423 reiserfs_delete_solid_item(&th, NULL, &key);
425 reiserfs_release_objectid(&th, inode->i_ino);
426 REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
428 REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
430 return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
433 static void reiserfs_kill_sb(struct super_block *s)
435 if (REISERFS_SB(s)) {
436 if (REISERFS_SB(s)->xattr_root) {
437 d_invalidate(REISERFS_SB(s)->xattr_root);
438 dput(REISERFS_SB(s)->xattr_root);
439 REISERFS_SB(s)->xattr_root = NULL;
442 if (REISERFS_SB(s)->priv_root) {
443 d_invalidate(REISERFS_SB(s)->priv_root);
444 dput(REISERFS_SB(s)->priv_root);
445 REISERFS_SB(s)->priv_root = NULL;
452 static void reiserfs_put_super(struct super_block *s)
454 struct reiserfs_transaction_handle th;
457 /* change file system state to current state if it was mounted with read-write permissions */
458 if (!(s->s_flags & MS_RDONLY)) {
459 if (!journal_begin(&th, s, 10)) {
460 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
462 set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
463 REISERFS_SB(s)->s_mount_state);
464 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
468 /* note, journal_release checks for readonly mount, and can decide not
469 ** to do a journal_end
471 journal_release(&th, s);
473 reiserfs_free_bitmap_cache(s);
475 brelse(SB_BUFFER_WITH_SB(s));
479 if (REISERFS_SB(s)->reserved_blocks != 0) {
481 "green-2005: reiserfs_put_super: reserved blocks left %d",
482 REISERFS_SB(s)->reserved_blocks);
485 reiserfs_proc_info_done(s);
493 static struct kmem_cache *reiserfs_inode_cachep;
495 static struct inode *reiserfs_alloc_inode(struct super_block *sb)
497 struct reiserfs_inode_info *ei;
498 ei = (struct reiserfs_inode_info *)
499 kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
502 return &ei->vfs_inode;
505 static void reiserfs_destroy_inode(struct inode *inode)
507 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
510 static void init_once(void *foo, struct kmem_cache * cachep, unsigned long flags)
512 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
514 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
515 SLAB_CTOR_CONSTRUCTOR) {
516 INIT_LIST_HEAD(&ei->i_prealloc_list);
517 inode_init_once(&ei->vfs_inode);
518 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
519 ei->i_acl_access = NULL;
520 ei->i_acl_default = NULL;
525 static int init_inodecache(void)
527 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
529 reiserfs_inode_info),
530 0, (SLAB_RECLAIM_ACCOUNT|
533 if (reiserfs_inode_cachep == NULL)
538 static void destroy_inodecache(void)
540 kmem_cache_destroy(reiserfs_inode_cachep);
543 /* we don't mark inodes dirty, we just log them */
544 static void reiserfs_dirty_inode(struct inode *inode)
546 struct reiserfs_transaction_handle th;
549 if (inode->i_sb->s_flags & MS_RDONLY) {
550 reiserfs_warning(inode->i_sb,
551 "clm-6006: writing inode %lu on readonly FS",
555 reiserfs_write_lock(inode->i_sb);
557 /* this is really only used for atime updates, so they don't have
558 ** to be included in O_SYNC or fsync
560 err = journal_begin(&th, inode->i_sb, 1);
562 reiserfs_write_unlock(inode->i_sb);
565 reiserfs_update_sd(&th, inode);
566 journal_end(&th, inode->i_sb, 1);
567 reiserfs_write_unlock(inode->i_sb);
570 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
571 static void reiserfs_clear_inode(struct inode *inode)
573 struct posix_acl *acl;
575 acl = REISERFS_I(inode)->i_acl_access;
576 if (acl && !IS_ERR(acl))
577 posix_acl_release(acl);
578 REISERFS_I(inode)->i_acl_access = NULL;
580 acl = REISERFS_I(inode)->i_acl_default;
581 if (acl && !IS_ERR(acl))
582 posix_acl_release(acl);
583 REISERFS_I(inode)->i_acl_default = NULL;
586 #define reiserfs_clear_inode NULL
590 static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
592 static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
596 static struct super_operations reiserfs_sops = {
597 .alloc_inode = reiserfs_alloc_inode,
598 .destroy_inode = reiserfs_destroy_inode,
599 .write_inode = reiserfs_write_inode,
600 .dirty_inode = reiserfs_dirty_inode,
601 .delete_inode = reiserfs_delete_inode,
602 .clear_inode = reiserfs_clear_inode,
603 .put_super = reiserfs_put_super,
604 .write_super = reiserfs_write_super,
605 .sync_fs = reiserfs_sync_fs,
606 .write_super_lockfs = reiserfs_write_super_lockfs,
607 .unlockfs = reiserfs_unlockfs,
608 .statfs = reiserfs_statfs,
609 .remount_fs = reiserfs_remount,
611 .quota_read = reiserfs_quota_read,
612 .quota_write = reiserfs_quota_write,
617 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
619 static int reiserfs_dquot_initialize(struct inode *, int);
620 static int reiserfs_dquot_drop(struct inode *);
621 static int reiserfs_write_dquot(struct dquot *);
622 static int reiserfs_acquire_dquot(struct dquot *);
623 static int reiserfs_release_dquot(struct dquot *);
624 static int reiserfs_mark_dquot_dirty(struct dquot *);
625 static int reiserfs_write_info(struct super_block *, int);
626 static int reiserfs_quota_on(struct super_block *, int, int, char *);
628 static struct dquot_operations reiserfs_quota_operations = {
629 .initialize = reiserfs_dquot_initialize,
630 .drop = reiserfs_dquot_drop,
631 .alloc_space = dquot_alloc_space,
632 .alloc_inode = dquot_alloc_inode,
633 .free_space = dquot_free_space,
634 .free_inode = dquot_free_inode,
635 .transfer = dquot_transfer,
636 .write_dquot = reiserfs_write_dquot,
637 .acquire_dquot = reiserfs_acquire_dquot,
638 .release_dquot = reiserfs_release_dquot,
639 .mark_dirty = reiserfs_mark_dquot_dirty,
640 .write_info = reiserfs_write_info,
643 static struct quotactl_ops reiserfs_qctl_operations = {
644 .quota_on = reiserfs_quota_on,
645 .quota_off = vfs_quota_off,
646 .quota_sync = vfs_quota_sync,
647 .get_info = vfs_get_dqinfo,
648 .set_info = vfs_set_dqinfo,
649 .get_dqblk = vfs_get_dqblk,
650 .set_dqblk = vfs_set_dqblk,
654 static struct export_operations reiserfs_export_ops = {
655 .encode_fh = reiserfs_encode_fh,
656 .decode_fh = reiserfs_decode_fh,
657 .get_parent = reiserfs_get_parent,
658 .get_dentry = reiserfs_get_dentry,
661 /* this struct is used in reiserfs_getopt () for containing the value for those
662 mount options that have values rather than being toggles. */
665 int setmask; /* bitmask which is to set on mount_options bitmask when this
666 value is found, 0 is no bits are to be changed. */
667 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
668 value is found, 0 is no bits are to be changed. This is
669 applied BEFORE setmask */
672 /* Set this bit in arg_required to allow empty arguments */
673 #define REISERFS_OPT_ALLOWEMPTY 31
675 /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
679 int arg_required; /* 0 if argument is not required, not 0 otherwise */
680 const arg_desc_t *values; /* list of values accepted by an option */
681 int setmask; /* bitmask which is to set on mount_options bitmask when this
682 value is found, 0 is no bits are to be changed. */
683 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
684 value is found, 0 is no bits are to be changed. This is
685 applied BEFORE setmask */
688 /* possible values for -o data= */
689 static const arg_desc_t logging_mode[] = {
690 {"ordered", 1 << REISERFS_DATA_ORDERED,
691 (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
692 {"journal", 1 << REISERFS_DATA_LOG,
693 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
694 {"writeback", 1 << REISERFS_DATA_WRITEBACK,
695 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
699 /* possible values for -o barrier= */
700 static const arg_desc_t barrier_mode[] = {
701 {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
702 {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
706 /* possible values for "-o block-allocator=" and bits which are to be set in
707 s_mount_opt of reiserfs specific part of in-core super block */
708 static const arg_desc_t balloc[] = {
709 {"noborder", 1 << REISERFS_NO_BORDER, 0},
710 {"border", 0, 1 << REISERFS_NO_BORDER},
711 {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
712 {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
713 {"test4", 1 << REISERFS_TEST4, 0},
714 {"notest4", 0, 1 << REISERFS_TEST4},
718 static const arg_desc_t tails[] = {
719 {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
720 {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
721 {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
725 static const arg_desc_t error_actions[] = {
726 {"panic", 1 << REISERFS_ERROR_PANIC,
727 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
728 {"ro-remount", 1 << REISERFS_ERROR_RO,
729 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
730 #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
731 {"continue", 1 << REISERFS_ERROR_CONTINUE,
732 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
737 /* proceed only one option from a list *cur - string containing of mount options
738 opts - array of options which are accepted
739 opt_arg - if option is found and requires an argument and if it is specifed
740 in the input - pointer to the argument is stored here
741 bit_flags - if option requires to set a certain bit - it is set here
742 return -1 if unknown option is found, opt->arg_required otherwise */
743 static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
744 char **opt_arg, unsigned long *bit_flags)
753 const opt_desc_t *opt;
754 const arg_desc_t *arg;
758 /* assume argument cannot contain commas */
759 *cur = strchr(p, ',');
765 if (!strncmp(p, "alloc=", 6)) {
766 /* Ugly special case, probably we should redo options parser so that
767 it can understand several arguments for some options, also so that
768 it can fill several bitfields with option values. */
769 if (reiserfs_parse_alloc_options(s, p + 6)) {
776 /* for every option in the list */
777 for (opt = opts; opt->option_name; opt++) {
778 if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
781 (1 << REISERFS_UNSUPPORTED_OPT))
782 reiserfs_warning(s, "%s not supported.",
785 *bit_flags &= ~opt->clrmask;
787 (1 << REISERFS_UNSUPPORTED_OPT))
788 reiserfs_warning(s, "%s not supported.",
791 *bit_flags |= opt->setmask;
796 if (!opt->option_name) {
797 reiserfs_warning(s, "unknown mount option \"%s\"", p);
801 p += strlen(opt->option_name);
804 if (!opt->arg_required) {
806 "the option \"%s\" does not require an argument",
813 if (opt->arg_required) {
815 "the option \"%s\" requires an argument",
821 reiserfs_warning(s, "head of option \"%s\" is only correct",
826 /* move to the argument, or to next option if argument is not required */
829 if (opt->arg_required
830 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
832 /* this catches "option=," if not allowed */
833 reiserfs_warning(s, "empty argument for \"%s\"",
839 /* *=NULLopt_arg contains pointer to argument */
841 return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
844 /* values possible for this option are listed in opt->values */
845 for (arg = opt->values; arg->value; arg++) {
846 if (!strcmp(p, arg->value)) {
848 *bit_flags &= ~arg->clrmask;
849 *bit_flags |= arg->setmask;
851 return opt->arg_required;
855 reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
860 /* returns 0 if something is wrong in option string, 1 - otherwise */
861 static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
862 unsigned long *mount_options,
863 /* after the parsing phase, contains the
864 collection of bitflags defining what
865 mount options were selected. */
866 unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
868 unsigned int *commit_max_age)
873 opt_desc_t opts[] = {
874 /* Compatibility stuff, so that -o notail for old setups still work */
875 {"tails",.arg_required = 't',.values = tails},
877 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
878 {"conv",.setmask = 1 << REISERFS_CONVERT},
879 {"attrs",.setmask = 1 << REISERFS_ATTRS},
880 {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
881 #ifdef CONFIG_REISERFS_FS_XATTR
882 {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
883 {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
885 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
886 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
888 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
889 {"acl",.setmask = 1 << REISERFS_POSIXACL},
890 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
892 {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
893 {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
895 {.option_name = "nolog"},
896 {"replayonly",.setmask = 1 << REPLAYONLY},
897 {"block-allocator",.arg_required = 'a',.values = balloc},
898 {"data",.arg_required = 'd',.values = logging_mode},
899 {"barrier",.arg_required = 'b',.values = barrier_mode},
900 {"resize",.arg_required = 'r',.values = NULL},
901 {"jdev",.arg_required = 'j',.values = NULL},
902 {"nolargeio",.arg_required = 'w',.values = NULL},
903 {"commit",.arg_required = 'c',.values = NULL},
904 {"usrquota",.setmask = 1 << REISERFS_QUOTA},
905 {"grpquota",.setmask = 1 << REISERFS_QUOTA},
906 {"noquota",.clrmask = 1 << REISERFS_QUOTA},
907 {"errors",.arg_required = 'e',.values = error_actions},
908 {"usrjquota",.arg_required =
909 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
910 {"grpjquota",.arg_required =
911 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
912 {"jqfmt",.arg_required = 'f',.values = NULL},
913 {.option_name = NULL}
917 if (!options || !*options)
918 /* use default configuration: create tails, journaling on, no
919 conversion to newest format */
922 for (pos = options; pos;) {
923 c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
925 /* wrong option is given */
932 /* "resize=NNN" or "resize=auto" */
934 if (!strcmp(arg, "auto")) {
935 /* From JFS code, to auto-get the size. */
937 s->s_bdev->bd_inode->i_size >> s->
940 *blocks = simple_strtoul(arg, &p, 0);
942 /* NNN does not look like a number */
944 "reiserfs_parse_options: bad value %s",
953 unsigned long val = simple_strtoul(arg, &p, 0);
954 /* commit=NNN (time in seconds) */
955 if (*p != '\0' || val >= (unsigned int)-1) {
957 "reiserfs_parse_options: bad value %s",
961 *commit_max_age = (unsigned int)val;
965 reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported");
970 if (arg && *arg && jdev_name) {
971 if (*jdev_name) { //Hm, already assigned?
973 "reiserfs_parse_options: journal device was already specified to be %s",
981 if (c == 'u' || c == 'g') {
982 int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
984 if (sb_any_quota_enabled(s)) {
986 "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
989 if (*arg) { /* Some filename specified? */
990 if (REISERFS_SB(s)->s_qf_names[qtype]
991 && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
994 "reiserfs_parse_options: %s quota file already specified.",
998 if (strchr(arg, '/')) {
1000 "reiserfs_parse_options: quotafile must be on filesystem root.");
1003 REISERFS_SB(s)->s_qf_names[qtype] =
1004 kmalloc(strlen(arg) + 1, GFP_KERNEL);
1005 if (!REISERFS_SB(s)->s_qf_names[qtype]) {
1007 "reiserfs_parse_options: not enough memory for storing quotafile name.");
1010 strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
1011 *mount_options |= 1 << REISERFS_QUOTA;
1013 kfree(REISERFS_SB(s)->s_qf_names[qtype]);
1014 REISERFS_SB(s)->s_qf_names[qtype] = NULL;
1018 if (!strcmp(arg, "vfsold"))
1019 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
1020 else if (!strcmp(arg, "vfsv0"))
1021 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
1024 "reiserfs_parse_options: unknown quota format specified.");
1029 if (c == 'u' || c == 'g' || c == 'f') {
1031 "reiserfs_parse_options: journalled quota options not supported.");
1038 if (!REISERFS_SB(s)->s_jquota_fmt
1039 && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
1040 || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
1042 "reiserfs_parse_options: journalled quota format not specified.");
1045 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
1046 if (!(*mount_options & (1 << REISERFS_QUOTA))
1047 && sb_any_quota_enabled(s)) {
1049 "reiserfs_parse_options: quota options must be present when quota is turned on.");
1057 static void switch_data_mode(struct super_block *s, unsigned long mode)
1059 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
1060 (1 << REISERFS_DATA_ORDERED) |
1061 (1 << REISERFS_DATA_WRITEBACK));
1062 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
1065 static void handle_data_mode(struct super_block *s, unsigned long mount_options)
1067 if (mount_options & (1 << REISERFS_DATA_LOG)) {
1068 if (!reiserfs_data_log(s)) {
1069 switch_data_mode(s, REISERFS_DATA_LOG);
1070 reiserfs_info(s, "switching to journaled data mode\n");
1072 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
1073 if (!reiserfs_data_ordered(s)) {
1074 switch_data_mode(s, REISERFS_DATA_ORDERED);
1075 reiserfs_info(s, "switching to ordered data mode\n");
1077 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
1078 if (!reiserfs_data_writeback(s)) {
1079 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
1080 reiserfs_info(s, "switching to writeback data mode\n");
1085 static void handle_barrier_mode(struct super_block *s, unsigned long bits)
1087 int flush = (1 << REISERFS_BARRIER_FLUSH);
1088 int none = (1 << REISERFS_BARRIER_NONE);
1089 int all_barrier = flush | none;
1091 if (bits & all_barrier) {
1092 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1094 REISERFS_SB(s)->s_mount_opt |= flush;
1095 printk("reiserfs: enabling write barrier flush mode\n");
1096 } else if (bits & none) {
1097 REISERFS_SB(s)->s_mount_opt |= none;
1098 printk("reiserfs: write barriers turned off\n");
1103 static void handle_attrs(struct super_block *s)
1105 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1107 if (reiserfs_attrs(s)) {
1108 if (old_format_only(s)) {
1110 "reiserfs: cannot support attributes on 3.5.x disk format");
1111 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1114 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1116 "reiserfs: cannot support attributes until flag is set in super-block");
1117 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1122 static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1124 struct reiserfs_super_block *rs;
1125 struct reiserfs_transaction_handle th;
1126 unsigned long blocks;
1127 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1128 unsigned long safe_mask = 0;
1129 unsigned int commit_max_age = (unsigned int)-1;
1130 struct reiserfs_journal *journal = SB_JOURNAL(s);
1136 rs = SB_DISK_SUPER_BLOCK(s);
1138 if (!reiserfs_parse_options
1139 (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
1141 for (i = 0; i < MAXQUOTAS; i++) {
1142 kfree(REISERFS_SB(s)->s_qf_names[i]);
1143 REISERFS_SB(s)->s_qf_names[i] = NULL;
1151 /* Add options that are safe here */
1152 safe_mask |= 1 << REISERFS_SMALLTAIL;
1153 safe_mask |= 1 << REISERFS_LARGETAIL;
1154 safe_mask |= 1 << REISERFS_NO_BORDER;
1155 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
1156 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
1157 safe_mask |= 1 << REISERFS_TEST4;
1158 safe_mask |= 1 << REISERFS_ATTRS;
1159 safe_mask |= 1 << REISERFS_XATTRS_USER;
1160 safe_mask |= 1 << REISERFS_POSIXACL;
1161 safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
1162 safe_mask |= 1 << REISERFS_BARRIER_NONE;
1163 safe_mask |= 1 << REISERFS_ERROR_RO;
1164 safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
1165 safe_mask |= 1 << REISERFS_ERROR_PANIC;
1166 safe_mask |= 1 << REISERFS_QUOTA;
1168 /* Update the bitmask, taking care to keep
1169 * the bits we're not allowed to change here */
1170 REISERFS_SB(s)->s_mount_opt =
1172 s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
1174 if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
1175 journal->j_max_commit_age = commit_max_age;
1176 journal->j_max_trans_age = commit_max_age;
1177 } else if (commit_max_age == 0) {
1178 /* 0 means restore defaults. */
1179 journal->j_max_commit_age = journal->j_default_max_commit_age;
1180 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
1184 int rc = reiserfs_resize(s, blocks);
1189 if (*mount_flags & MS_RDONLY) {
1190 reiserfs_xattr_init(s, *mount_flags);
1191 /* remount read-only */
1192 if (s->s_flags & MS_RDONLY)
1193 /* it is read-only already */
1195 /* try to remount file system with read-only permissions */
1196 if (sb_umount_state(rs) == REISERFS_VALID_FS
1197 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1201 err = journal_begin(&th, s, 10);
1205 /* Mounting a rw partition read-only. */
1206 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1207 set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
1208 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1210 /* remount read-write */
1211 if (!(s->s_flags & MS_RDONLY)) {
1212 reiserfs_xattr_init(s, *mount_flags);
1213 return 0; /* We are read-write already */
1216 if (reiserfs_is_journal_aborted(journal))
1217 return journal->j_errno;
1219 handle_data_mode(s, mount_options);
1220 handle_barrier_mode(s, mount_options);
1221 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1222 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
1223 err = journal_begin(&th, s, 10);
1227 /* Mount a partition which is read-only, read-write */
1228 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1229 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1230 s->s_flags &= ~MS_RDONLY;
1231 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1232 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1233 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1234 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
1236 /* this will force a full flush of all journal lists */
1237 SB_JOURNAL(s)->j_must_wait = 1;
1238 err = journal_end(&th, s, 10);
1243 if (!(*mount_flags & MS_RDONLY)) {
1244 finish_unfinished(s);
1245 reiserfs_xattr_init(s, *mount_flags);
1251 static int read_super_block(struct super_block *s, int offset)
1253 struct buffer_head *bh;
1254 struct reiserfs_super_block *rs;
1257 bh = sb_bread(s, offset / s->s_blocksize);
1259 reiserfs_warning(s, "sh-2006: read_super_block: "
1260 "bread failed (dev %s, block %lu, size %lu)",
1261 reiserfs_bdevname(s), offset / s->s_blocksize,
1266 rs = (struct reiserfs_super_block *)bh->b_data;
1267 if (!is_any_reiserfs_magic_string(rs)) {
1272 // ok, reiserfs signature (old or new) found in at the given offset
1274 fs_blocksize = sb_blocksize(rs);
1276 sb_set_blocksize(s, fs_blocksize);
1278 bh = sb_bread(s, offset / s->s_blocksize);
1280 reiserfs_warning(s, "sh-2007: read_super_block: "
1281 "bread failed (dev %s, block %lu, size %lu)\n",
1282 reiserfs_bdevname(s), offset / s->s_blocksize,
1287 rs = (struct reiserfs_super_block *)bh->b_data;
1288 if (sb_blocksize(rs) != s->s_blocksize) {
1289 reiserfs_warning(s, "sh-2011: read_super_block: "
1290 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1291 reiserfs_bdevname(s),
1292 (unsigned long long)bh->b_blocknr,
1298 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1301 "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1302 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1303 "get newer reiserfsprogs package");
1307 SB_BUFFER_WITH_SB(s) = bh;
1308 SB_DISK_SUPER_BLOCK(s) = rs;
1310 if (is_reiserfs_jr(rs)) {
1311 /* magic is of non-standard journal filesystem, look at s_version to
1312 find which format is in use */
1313 if (sb_version(rs) == REISERFS_VERSION_2)
1315 "read_super_block: found reiserfs format \"3.6\""
1316 " with non-standard journal");
1317 else if (sb_version(rs) == REISERFS_VERSION_1)
1319 "read_super_block: found reiserfs format \"3.5\""
1320 " with non-standard journal");
1323 "sh-2012: read_super_block: found unknown "
1324 "format \"%u\" of reiserfs with non-standard magic",
1329 /* s_version of standard format may contain incorrect information,
1330 so we just look at the magic string */
1332 "found reiserfs format \"%s\" with standard journal\n",
1333 is_reiserfs_3_5(rs) ? "3.5" : "3.6");
1335 s->s_op = &reiserfs_sops;
1336 s->s_export_op = &reiserfs_export_ops;
1338 s->s_qcop = &reiserfs_qctl_operations;
1339 s->dq_op = &reiserfs_quota_operations;
1342 /* new format is limited by the 32 bit wide i_blocks field, want to
1343 ** be one full block below that.
1345 s->s_maxbytes = (512LL << 32) - s->s_blocksize;
1349 /* after journal replay, reread all bitmap and super blocks */
1350 static int reread_meta_blocks(struct super_block *s)
1352 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1353 wait_on_buffer(SB_BUFFER_WITH_SB(s));
1354 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1356 "reread_meta_blocks, error reading the super");
1363 /////////////////////////////////////////////////////
1364 // hash detection stuff
1366 // if root directory is empty - we set default - Yura's - hash and
1368 // FIXME: we look for only one name in a directory. If tea and yura
1369 // bith have the same value - we ask user to send report to the
1371 static __u32 find_hash_out(struct super_block *s)
1374 struct inode *inode;
1376 INITIALIZE_PATH(path);
1377 struct reiserfs_dir_entry de;
1378 __u32 hash = DEFAULT_HASH;
1380 inode = s->s_root->d_inode;
1382 do { // Some serious "goto"-hater was there ;)
1383 u32 teahash, r5hash, yurahash;
1385 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1386 retval = search_by_entry_key(s, &key, &path, &de);
1387 if (retval == IO_ERROR) {
1391 if (retval == NAME_NOT_FOUND)
1393 set_de_name_and_namelen(&de);
1394 if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
1395 /* allow override in this case */
1396 if (reiserfs_rupasov_hash(s)) {
1399 reiserfs_warning(s, "FS seems to be empty, autodetect "
1400 "is using the default hash");
1403 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
1404 teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
1405 yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
1406 if (((teahash == r5hash)
1408 (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
1409 == r5hash)) || ((teahash == yurahash)
1411 GET_HASH_VALUE(deh_offset
1416 || ((r5hash == yurahash)
1418 GET_HASH_VALUE(deh_offset
1419 (&(de.de_deh[de.de_entry_num])))))) {
1421 "Unable to automatically detect hash function. "
1422 "Please mount with -o hash={tea,rupasov,r5}",
1423 reiserfs_bdevname(s));
1427 if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
1430 else if (GET_HASH_VALUE
1431 (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
1433 else if (GET_HASH_VALUE
1434 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1437 reiserfs_warning(s, "Unrecognised hash function");
1446 // finds out which hash names are sorted with
1447 static int what_hash(struct super_block *s)
1451 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1453 /* reiserfs_hash_detect() == true if any of the hash mount options
1454 ** were used. We must check them to make sure the user isn't
1455 ** using a bad hash value
1457 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1458 code = find_hash_out(s);
1460 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1461 /* detection has found the hash, and we must check against the
1464 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1465 reiserfs_warning(s, "Error, %s hash detected, "
1466 "unable to force rupasov hash",
1467 reiserfs_hashname(code));
1469 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1470 reiserfs_warning(s, "Error, %s hash detected, "
1471 "unable to force tea hash",
1472 reiserfs_hashname(code));
1474 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1475 reiserfs_warning(s, "Error, %s hash detected, "
1476 "unable to force r5 hash",
1477 reiserfs_hashname(code));
1481 /* find_hash_out was not called or could not determine the hash */
1482 if (reiserfs_rupasov_hash(s)) {
1484 } else if (reiserfs_tea_hash(s)) {
1486 } else if (reiserfs_r5_hash(s)) {
1491 /* if we are mounted RW, and we have a new valid hash code, update
1494 if (code != UNSET_HASH &&
1495 !(s->s_flags & MS_RDONLY) &&
1496 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1497 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1502 // return pointer to appropriate function
1503 static hashf_t hash_function(struct super_block *s)
1505 switch (what_hash(s)) {
1507 reiserfs_info(s, "Using tea hash to sort names\n");
1510 reiserfs_info(s, "Using rupasov hash to sort names\n");
1513 reiserfs_info(s, "Using r5 hash to sort names\n");
1519 // this is used to set up correct value for old partitions
1520 static int function2code(hashf_t func)
1522 if (func == keyed_hash)
1524 if (func == yura_hash)
1526 if (func == r5_hash)
1529 BUG(); // should never happen
1534 #define SWARN(silent, s, ...) \
1536 reiserfs_warning (s, __VA_ARGS__)
1538 static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1540 struct inode *root_inode;
1541 struct reiserfs_transaction_handle th;
1543 unsigned long blocks;
1544 unsigned int commit_max_age = 0;
1546 struct reiserfs_iget_args args;
1547 struct reiserfs_super_block *rs;
1549 struct reiserfs_sb_info *sbi;
1550 int errval = -EINVAL;
1552 sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1558 /* Set default values for options: non-aggressive tails, RO on errors */
1559 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1560 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1561 /* no preallocation minimum, be smart in
1562 reiserfs_file_write instead */
1563 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1564 /* Preallocate by 16 blocks (17-1) at once */
1565 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1566 /* Initialize the rwsem for xattr dir */
1567 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
1569 /* setup default block allocator options */
1570 reiserfs_init_alloc_options(s);
1573 if (reiserfs_parse_options
1574 (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
1575 &commit_max_age) == 0) {
1580 SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1581 "for remount only");
1585 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1586 if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1588 /* try new format (64-th 1k block), which can contain reiserfs super block */
1589 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1591 "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
1592 reiserfs_bdevname(s));
1596 rs = SB_DISK_SUPER_BLOCK(s);
1597 /* Let's do basic sanity check to verify that underlying device is not
1598 smaller than the filesystem. If the check fails then abort and scream,
1599 because bad stuff will happen otherwise. */
1600 if (s->s_bdev && s->s_bdev->bd_inode
1601 && i_size_read(s->s_bdev->bd_inode) <
1602 sb_block_count(rs) * sb_blocksize(rs)) {
1604 "Filesystem on %s cannot be mounted because it is bigger than the device",
1605 reiserfs_bdevname(s));
1607 "You may need to run fsck or increase size of your LVM partition");
1609 "Or may be you forgot to reboot after fdisk when it told you to");
1613 sbi->s_mount_state = SB_REISERFS_STATE(s);
1614 sbi->s_mount_state = REISERFS_VALID_FS;
1616 if ((errval = reiserfs_init_bitmap_cache(s))) {
1618 "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1622 #ifdef CONFIG_REISERFS_CHECK
1623 SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
1624 SWARN(silent, s, "- it is slow mode for debugging.");
1627 /* make data=ordered the default */
1628 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1629 !reiserfs_data_writeback(s)) {
1630 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1633 if (reiserfs_data_log(s)) {
1634 reiserfs_info(s, "using journaled data mode\n");
1635 } else if (reiserfs_data_ordered(s)) {
1636 reiserfs_info(s, "using ordered data mode\n");
1638 reiserfs_info(s, "using writeback data mode\n");
1640 if (reiserfs_barrier_flush(s)) {
1641 printk("reiserfs: using flush barriers\n");
1643 // set_device_ro(s->s_dev, 1) ;
1644 if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1646 "sh-2022: reiserfs_fill_super: unable to initialize journal space");
1649 jinit_done = 1; /* once this is set, journal_release must be called
1650 ** if we error out of the mount
1653 if (reread_meta_blocks(s)) {
1655 "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
1662 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1664 "clm-7000: Detected readonly device, marking FS readonly");
1665 s->s_flags |= MS_RDONLY;
1667 args.objectid = REISERFS_ROOT_OBJECTID;
1668 args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
1670 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1671 reiserfs_init_locked_inode, (void *)(&args));
1674 "jmacd-10: reiserfs_fill_super: get root inode failed");
1678 if (root_inode->i_state & I_NEW) {
1679 reiserfs_read_locked_inode(root_inode, &args);
1680 unlock_new_inode(root_inode);
1683 s->s_root = d_alloc_root(root_inode);
1688 // define and initialize hash function
1689 sbi->s_hash_function = hash_function(s);
1690 if (sbi->s_hash_function == NULL) {
1696 if (is_reiserfs_3_5(rs)
1697 || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
1698 set_bit(REISERFS_3_5, &(sbi->s_properties));
1699 else if (old_format)
1700 set_bit(REISERFS_OLD_FORMAT, &(sbi->s_properties));
1702 set_bit(REISERFS_3_6, &(sbi->s_properties));
1704 if (!(s->s_flags & MS_RDONLY)) {
1706 errval = journal_begin(&th, s, 1);
1712 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1714 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1715 set_sb_fs_state(rs, 0);
1717 if (old_format_only(s)) {
1718 /* filesystem of format 3.5 either with standard or non-standard
1720 if (convert_reiserfs(s)) {
1721 /* and -o conv is given */
1724 "converting 3.5 filesystem to the 3.6 format");
1726 if (is_reiserfs_3_5(rs))
1727 /* put magic string of 3.6 format. 2.2 will not be able to
1728 mount this filesystem anymore */
1729 memcpy(rs->s_v1.s_magic,
1730 reiserfs_3_6_magic_string,
1732 (reiserfs_3_6_magic_string));
1734 set_sb_version(rs, REISERFS_VERSION_2);
1735 reiserfs_convert_objectid_map_v1(s);
1736 set_bit(REISERFS_3_6, &(sbi->s_properties));
1737 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1738 } else if (!silent) {
1739 reiserfs_info(s, "using 3.5.x disk format\n");
1743 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1744 errval = journal_end(&th, s, 1);
1751 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1757 /* look for files which were to be removed in previous session */
1758 finish_unfinished(s);
1760 if (old_format_only(s) && !silent) {
1761 reiserfs_info(s, "using 3.5.x disk format\n");
1764 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1770 // mark hash in super block: it could be unset. overwrite should be ok
1771 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
1775 reiserfs_proc_info_init(s);
1777 init_waitqueue_head(&(sbi->s_wait));
1778 spin_lock_init(&sbi->bitmap_lock);
1783 if (jinit_done) { /* kill the commit thread, free journal ram */
1784 journal_release_error(NULL, s);
1787 reiserfs_free_bitmap_cache(s);
1788 if (SB_BUFFER_WITH_SB(s))
1789 brelse(SB_BUFFER_WITH_SB(s));
1793 for (j = 0; j < MAXQUOTAS; j++) {
1794 kfree(sbi->s_qf_names[j]);
1795 sbi->s_qf_names[j] = NULL;
1801 s->s_fs_info = NULL;
1805 static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1807 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
1809 buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
1810 buf->f_bfree = sb_free_blocks(rs);
1811 buf->f_bavail = buf->f_bfree;
1812 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1813 buf->f_bsize = dentry->d_sb->s_blocksize;
1814 /* changed to accommodate gcc folks. */
1815 buf->f_type = REISERFS_SUPER_MAGIC;
1820 static int reiserfs_dquot_initialize(struct inode *inode, int type)
1822 struct reiserfs_transaction_handle th;
1825 /* We may create quota structure so we need to reserve enough blocks */
1826 reiserfs_write_lock(inode->i_sb);
1828 journal_begin(&th, inode->i_sb,
1829 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1832 ret = dquot_initialize(inode, type);
1834 journal_end(&th, inode->i_sb,
1835 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1839 reiserfs_write_unlock(inode->i_sb);
1843 static int reiserfs_dquot_drop(struct inode *inode)
1845 struct reiserfs_transaction_handle th;
1848 /* We may delete quota structure so we need to reserve enough blocks */
1849 reiserfs_write_lock(inode->i_sb);
1851 journal_begin(&th, inode->i_sb,
1852 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1855 ret = dquot_drop(inode);
1857 journal_end(&th, inode->i_sb,
1858 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1862 reiserfs_write_unlock(inode->i_sb);
1866 static int reiserfs_write_dquot(struct dquot *dquot)
1868 struct reiserfs_transaction_handle th;
1871 reiserfs_write_lock(dquot->dq_sb);
1873 journal_begin(&th, dquot->dq_sb,
1874 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1877 ret = dquot_commit(dquot);
1879 journal_end(&th, dquot->dq_sb,
1880 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1884 reiserfs_write_unlock(dquot->dq_sb);
1888 static int reiserfs_acquire_dquot(struct dquot *dquot)
1890 struct reiserfs_transaction_handle th;
1893 reiserfs_write_lock(dquot->dq_sb);
1895 journal_begin(&th, dquot->dq_sb,
1896 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
1899 ret = dquot_acquire(dquot);
1901 journal_end(&th, dquot->dq_sb,
1902 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
1906 reiserfs_write_unlock(dquot->dq_sb);
1910 static int reiserfs_release_dquot(struct dquot *dquot)
1912 struct reiserfs_transaction_handle th;
1915 reiserfs_write_lock(dquot->dq_sb);
1917 journal_begin(&th, dquot->dq_sb,
1918 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
1921 ret = dquot_release(dquot);
1923 journal_end(&th, dquot->dq_sb,
1924 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
1928 reiserfs_write_unlock(dquot->dq_sb);
1932 static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
1934 /* Are we journalling quotas? */
1935 if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
1936 REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
1937 dquot_mark_dquot_dirty(dquot);
1938 return reiserfs_write_dquot(dquot);
1940 return dquot_mark_dquot_dirty(dquot);
1943 static int reiserfs_write_info(struct super_block *sb, int type)
1945 struct reiserfs_transaction_handle th;
1948 /* Data block + inode block */
1949 reiserfs_write_lock(sb);
1950 ret = journal_begin(&th, sb, 2);
1953 ret = dquot_commit_info(sb, type);
1954 err = journal_end(&th, sb, 2);
1958 reiserfs_write_unlock(sb);
1963 * Turn on quotas during mount time - we need to find the quota file and such...
1965 static int reiserfs_quota_on_mount(struct super_block *sb, int type)
1967 return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
1968 REISERFS_SB(sb)->s_jquota_fmt, type);
1972 * Standard function to be called on quota_on
1974 static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
1978 struct nameidata nd;
1980 if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
1982 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
1985 /* Quotafile not on the same filesystem? */
1986 if (nd.mnt->mnt_sb != sb) {
1990 /* We must not pack tails for quota files on reiserfs for quota IO to work */
1991 if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
1992 reiserfs_warning(sb,
1993 "reiserfs: Quota file must have tail packing disabled.");
1997 /* Not journalling quota? No more tests needed... */
1998 if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
1999 !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
2001 return vfs_quota_on(sb, type, format_id, path);
2003 /* Quotafile not of fs root? */
2004 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2005 reiserfs_warning(sb,
2006 "reiserfs: Quota file not on filesystem root. "
2007 "Journalled quota will not work.");
2009 return vfs_quota_on(sb, type, format_id, path);
2012 /* Read data from quotafile - avoid pagecache and such because we cannot afford
2013 * acquiring the locks... As quota files are never truncated and quota code
2014 * itself serializes the operations (and noone else should touch the files)
2015 * we don't have to be afraid of races */
2016 static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2017 size_t len, loff_t off)
2019 struct inode *inode = sb_dqopt(sb)->files[type];
2020 unsigned long blk = off >> sb->s_blocksize_bits;
2021 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2023 struct buffer_head tmp_bh, *bh;
2024 loff_t i_size = i_size_read(inode);
2028 if (off + len > i_size)
2031 while (toread > 0) {
2033 sb->s_blocksize - offset <
2034 toread ? sb->s_blocksize - offset : toread;
2036 /* Quota files are without tails so we can safely use this function */
2037 reiserfs_write_lock(sb);
2038 err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
2039 reiserfs_write_unlock(sb);
2042 if (!buffer_mapped(&tmp_bh)) /* A hole? */
2043 memset(data, 0, tocopy);
2045 bh = sb_bread(sb, tmp_bh.b_blocknr);
2048 memcpy(data, bh->b_data + offset, tocopy);
2059 /* Write to quotafile (we know the transaction is already started and has
2060 * enough credits) */
2061 static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2062 const char *data, size_t len, loff_t off)
2064 struct inode *inode = sb_dqopt(sb)->files[type];
2065 unsigned long blk = off >> sb->s_blocksize_bits;
2066 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2067 int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
2068 size_t towrite = len;
2069 struct buffer_head tmp_bh, *bh;
2071 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
2072 while (towrite > 0) {
2073 tocopy = sb->s_blocksize - offset < towrite ?
2074 sb->s_blocksize - offset : towrite;
2076 err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
2079 if (offset || tocopy != sb->s_blocksize)
2080 bh = sb_bread(sb, tmp_bh.b_blocknr);
2082 bh = sb_getblk(sb, tmp_bh.b_blocknr);
2088 memcpy(bh->b_data + offset, data, tocopy);
2089 flush_dcache_page(bh->b_page);
2090 set_buffer_uptodate(bh);
2092 reiserfs_prepare_for_journal(sb, bh, 1);
2093 journal_mark_dirty(current->journal_info, sb, bh);
2095 reiserfs_add_ordered_list(inode, bh);
2105 if (inode->i_size < off + len - towrite)
2106 i_size_write(inode, off + len - towrite);
2108 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2109 mark_inode_dirty(inode);
2110 mutex_unlock(&inode->i_mutex);
2111 return len - towrite;
2116 static int get_super_block(struct file_system_type *fs_type,
2117 int flags, const char *dev_name,
2118 void *data, struct vfsmount *mnt)
2120 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super,
2124 static int __init init_reiserfs_fs(void)
2128 if ((ret = init_inodecache())) {
2132 if ((ret = reiserfs_xattr_register_handlers()))
2133 goto failed_reiserfs_xattr_register_handlers;
2135 reiserfs_proc_info_global_init();
2136 reiserfs_proc_register_global("version",
2137 reiserfs_global_version_in_proc);
2139 ret = register_filesystem(&reiserfs_fs_type);
2145 reiserfs_xattr_unregister_handlers();
2147 failed_reiserfs_xattr_register_handlers:
2148 reiserfs_proc_unregister_global("version");
2149 reiserfs_proc_info_global_done();
2150 destroy_inodecache();
2155 static void __exit exit_reiserfs_fs(void)
2157 reiserfs_xattr_unregister_handlers();
2158 reiserfs_proc_unregister_global("version");
2159 reiserfs_proc_info_global_done();
2160 unregister_filesystem(&reiserfs_fs_type);
2161 destroy_inodecache();
2164 struct file_system_type reiserfs_fs_type = {
2165 .owner = THIS_MODULE,
2167 .get_sb = get_super_block,
2168 .kill_sb = reiserfs_kill_sb,
2169 .fs_flags = FS_REQUIRES_DEV,
2172 MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2173 MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2174 MODULE_LICENSE("GPL");
2176 module_init(init_reiserfs_fs);
2177 module_exit(exit_reiserfs_fs);