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/config.h>
15 #include <linux/module.h>
16 #include <linux/vmalloc.h>
17 #include <linux/time.h>
18 #include <asm/uaccess.h>
19 #include <linux/reiserfs_fs.h>
20 #include <linux/reiserfs_acl.h>
21 #include <linux/reiserfs_xattr.h>
22 #include <linux/smp_lock.h>
23 #include <linux/init.h>
24 #include <linux/blkdev.h>
25 #include <linux/buffer_head.h>
26 #include <linux/vfs.h>
27 #include <linux/namespace.h>
29 struct file_system_type reiserfs_fs_type;
31 const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
32 const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
33 const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
35 int is_reiserfs_3_5 (struct reiserfs_super_block * rs)
37 return !strncmp (rs->s_v1.s_magic, reiserfs_3_5_magic_string,
38 strlen (reiserfs_3_5_magic_string));
42 int is_reiserfs_3_6 (struct reiserfs_super_block * rs)
44 return !strncmp (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
45 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));
56 static int is_any_reiserfs_magic_string (struct reiserfs_super_block * rs)
58 return (is_reiserfs_3_5 (rs) || is_reiserfs_3_6 (rs) ||
62 static int reiserfs_remount (struct super_block * s, int * flags, char * data);
63 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf);
65 static void reiserfs_sync_fs (struct super_block * s)
67 if (!(s->s_flags & MS_RDONLY)) {
68 struct reiserfs_transaction_handle th;
69 reiserfs_write_lock(s);
70 if (!journal_begin(&th, s, 1))
71 if (!journal_end_sync(&th, s, 1))
72 reiserfs_flush_old_commits(s);
73 s->s_dirt = 0; /* Even if it's not true.
74 * We'll loop forever in sync_supers otherwise */
75 reiserfs_write_unlock(s);
81 static void reiserfs_write_super(struct super_block *s)
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), 1);
96 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
97 reiserfs_block_writes(&th) ;
98 journal_end_sync(&th, s, 1) ;
102 reiserfs_write_unlock(s);
105 void reiserfs_unlockfs(struct super_block *s) {
106 reiserfs_allow_writes(s) ;
109 extern const struct reiserfs_key MAX_KEY;
112 /* this is used to delete "save link" when there are no items of a
113 file it points to. It can either happen if unlink is completed but
114 "save unlink" removal, or if file has both unlink and truncate
115 pending and as unlink completes first (because key of "save link"
116 protecting unlink is bigger that a key lf "save link" which
117 protects truncate), so there left no items to make truncate
119 static int remove_save_link_only (struct super_block * s, struct reiserfs_key * key, int oid_free)
121 struct reiserfs_transaction_handle th;
124 /* we are going to do one balancing */
125 err = journal_begin (&th, s, JOURNAL_PER_BALANCE_CNT);
129 reiserfs_delete_solid_item (&th, NULL, key);
131 /* removals are protected by direct items */
132 reiserfs_release_objectid (&th, le32_to_cpu (key->k_objectid));
134 return journal_end (&th, s, JOURNAL_PER_BALANCE_CNT);
138 /* look for uncompleted unlinks and truncates and complete them */
139 static int finish_unfinished (struct super_block * s)
141 INITIALIZE_PATH (path);
142 struct cpu_key max_cpu_key, obj_key;
143 struct reiserfs_key save_link_key;
145 struct item_head * ih;
146 struct buffer_head * bh;
150 struct inode * inode;
154 /* compose key to look for "save" links */
155 max_cpu_key.version = KEY_FORMAT_3_5;
156 max_cpu_key.on_disk_key = MAX_KEY;
157 max_cpu_key.key_length = 3;
160 REISERFS_SB(s)->s_is_unlinked_ok = 1;
162 retval = search_item (s, &max_cpu_key, &path);
163 if (retval != ITEM_NOT_FOUND) {
164 reiserfs_warning (s, "vs-2140: finish_unfinished: search_by_key returned %d",
169 bh = get_last_bh (&path);
170 item_pos = get_item_pos (&path);
171 if (item_pos != B_NR_ITEMS (bh)) {
172 reiserfs_warning (s, "vs-2060: finish_unfinished: wrong position found");
176 ih = B_N_PITEM_HEAD (bh, item_pos);
178 if (le32_to_cpu (ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
179 /* there are no "save" links anymore */
182 save_link_key = ih->ih_key;
183 if (is_indirect_le_ih (ih))
188 /* reiserfs_iget needs k_dirid and k_objectid only */
189 item = B_I_PITEM (bh, ih);
190 obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__u32 *)item);
191 obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid);
192 obj_key.on_disk_key.u.k_offset_v1.k_offset = 0;
193 obj_key.on_disk_key.u.k_offset_v1.k_uniqueness = 0;
197 inode = reiserfs_iget (s, &obj_key);
199 /* the unlink almost completed, it just did not manage to remove
200 "save" link and release objectid */
201 reiserfs_warning (s, "vs-2180: finish_unfinished: iget failed for %K",
203 retval = remove_save_link_only (s, &save_link_key, 1);
207 if (!truncate && inode->i_nlink) {
208 /* file is not unlinked */
209 reiserfs_warning (s, "vs-2185: finish_unfinished: file %K is not unlinked",
211 retval = remove_save_link_only (s, &save_link_key, 0);
215 if (truncate && S_ISDIR (inode->i_mode) ) {
216 /* We got a truncate request for a dir which is impossible.
217 The only imaginable way is to execute unfinished truncate request
218 then boot into old kernel, remove the file and create dir with
220 reiserfs_warning(s, "green-2101: impossible truncate on a directory %k. Please report", INODE_PKEY (inode));
221 retval = remove_save_link_only (s, &save_link_key, 0);
228 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
229 /* not completed truncate found. New size was committed together
231 reiserfs_info (s, "Truncating %k to %Ld ..",
232 INODE_PKEY (inode), inode->i_size);
233 reiserfs_truncate_file (inode, 0/*don't update modification time*/);
234 retval = remove_save_link (inode, truncate);
236 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
237 /* not completed unlink (rmdir) found */
238 reiserfs_info (s, "Removing %k..", INODE_PKEY (inode));
239 /* removal gets completed in iput */
247 REISERFS_SB(s)->s_is_unlinked_ok = 0;
251 reiserfs_info (s, "There were %d uncompleted unlinks/truncates. "
252 "Completed\n", done);
256 /* to protect file being unlinked from getting lost we "safe" link files
257 being unlinked. This link will be deleted in the same transaction with last
258 item of file. mounting the filesytem we scan all these links and remove
259 files which almost got lost */
260 void add_save_link (struct reiserfs_transaction_handle * th,
261 struct inode * inode, int truncate)
263 INITIALIZE_PATH (path);
269 BUG_ON (!th->t_trans_id);
271 /* file can only get one "save link" of each kind */
273 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ),
274 "saved link already exists for truncated inode %lx",
275 ( long ) inode -> i_ino );
277 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ),
278 "saved link already exists for unlinked inode %lx",
279 ( long ) inode -> i_ino );
281 /* setup key of "save" link */
282 key.version = KEY_FORMAT_3_5;
283 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
284 key.on_disk_key.k_objectid = inode->i_ino;
286 /* unlink, rmdir, rename */
287 set_cpu_key_k_offset (&key, 1 + inode->i_sb->s_blocksize);
288 set_cpu_key_k_type (&key, TYPE_DIRECT);
290 /* item head of "safe" link */
291 make_le_item_head (&ih, &key, key.version, 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
292 4/*length*/, 0xffff/*free space*/);
295 if (S_ISDIR (inode->i_mode))
296 reiserfs_warning(inode->i_sb, "green-2102: Adding a truncate savelink for a directory %k! Please report", INODE_PKEY(inode));
297 set_cpu_key_k_offset (&key, 1);
298 set_cpu_key_k_type (&key, TYPE_INDIRECT);
300 /* item head of "safe" link */
301 make_le_item_head (&ih, &key, key.version, 1, TYPE_INDIRECT,
302 4/*length*/, 0/*free space*/);
306 /* look for its place in the tree */
307 retval = search_item (inode->i_sb, &key, &path);
308 if (retval != ITEM_NOT_FOUND) {
309 if ( retval != -ENOSPC )
310 reiserfs_warning (inode->i_sb, "vs-2100: add_save_link:"
311 "search_by_key (%K) returned %d", &key, retval);
316 /* body of "save" link */
317 link = INODE_PKEY (inode)->k_dir_id;
319 /* put "save" link inot tree, don't charge quota to anyone */
320 retval = reiserfs_insert_item (th, &path, &key, &ih, NULL, (char *)&link);
322 if (retval != -ENOSPC)
323 reiserfs_warning (inode->i_sb, "vs-2120: add_save_link: insert_item returned %d",
327 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
329 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
334 /* this opens transaction unlike add_save_link */
335 int remove_save_link (struct inode * inode, int truncate)
337 struct reiserfs_transaction_handle th;
338 struct reiserfs_key key;
341 /* we are going to do one balancing only */
342 err = journal_begin (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
346 /* setup key of "save" link */
347 key.k_dir_id = cpu_to_le32 (MAX_KEY_OBJECTID);
348 key.k_objectid = INODE_PKEY (inode)->k_objectid;
350 /* unlink, rmdir, rename */
351 set_le_key_k_offset (KEY_FORMAT_3_5, &key,
352 1 + inode->i_sb->s_blocksize);
353 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_DIRECT);
356 set_le_key_k_offset (KEY_FORMAT_3_5, &key, 1);
357 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
361 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ) ) ||
363 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ) ) )
364 /* don't take quota bytes from anywhere */
365 reiserfs_delete_solid_item (&th, NULL, &key);
367 reiserfs_release_objectid (&th, inode->i_ino);
368 REISERFS_I(inode) -> i_flags &= ~i_link_saved_unlink_mask;
370 REISERFS_I(inode) -> i_flags &= ~i_link_saved_truncate_mask;
372 return journal_end (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
376 static void reiserfs_put_super (struct super_block * s)
379 struct reiserfs_transaction_handle th ;
382 if (REISERFS_SB(s)->xattr_root) {
383 d_invalidate (REISERFS_SB(s)->xattr_root);
384 dput (REISERFS_SB(s)->xattr_root);
387 if (REISERFS_SB(s)->priv_root) {
388 d_invalidate (REISERFS_SB(s)->priv_root);
389 dput (REISERFS_SB(s)->priv_root);
392 /* change file system state to current state if it was mounted with read-write permissions */
393 if (!(s->s_flags & MS_RDONLY)) {
394 if (!journal_begin(&th, s, 10)) {
395 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
396 set_sb_umount_state( SB_DISK_SUPER_BLOCK(s), REISERFS_SB(s)->s_mount_state );
397 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
401 /* note, journal_release checks for readonly mount, and can decide not
402 ** to do a journal_end
404 journal_release(&th, s) ;
406 for (i = 0; i < SB_BMAP_NR (s); i ++)
407 brelse (SB_AP_BITMAP (s)[i].bh);
409 vfree (SB_AP_BITMAP (s));
411 brelse (SB_BUFFER_WITH_SB (s));
413 print_statistics (s);
415 if (REISERFS_SB(s)->s_kmallocs != 0) {
416 reiserfs_warning (s, "vs-2004: reiserfs_put_super: allocated memory left %d",
417 REISERFS_SB(s)->s_kmallocs);
420 if (REISERFS_SB(s)->reserved_blocks != 0) {
421 reiserfs_warning (s, "green-2005: reiserfs_put_super: reserved blocks left %d",
422 REISERFS_SB(s)->reserved_blocks);
425 reiserfs_proc_info_done( s );
433 static kmem_cache_t * reiserfs_inode_cachep;
435 static struct inode *reiserfs_alloc_inode(struct super_block *sb)
437 struct reiserfs_inode_info *ei;
438 ei = (struct reiserfs_inode_info *)kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
441 return &ei->vfs_inode;
444 static void reiserfs_destroy_inode(struct inode *inode)
446 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
449 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
451 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *) foo;
453 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
454 SLAB_CTOR_CONSTRUCTOR) {
455 INIT_LIST_HEAD(&ei->i_prealloc_list) ;
456 inode_init_once(&ei->vfs_inode);
457 ei->i_acl_access = NULL;
458 ei->i_acl_default = NULL;
462 static int init_inodecache(void)
464 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
465 sizeof(struct reiserfs_inode_info),
466 0, SLAB_RECLAIM_ACCOUNT,
468 if (reiserfs_inode_cachep == NULL)
473 static void destroy_inodecache(void)
475 if (kmem_cache_destroy(reiserfs_inode_cachep))
476 reiserfs_warning (NULL, "reiserfs_inode_cache: not all structures were freed");
479 /* we don't mark inodes dirty, we just log them */
480 static void reiserfs_dirty_inode (struct inode * inode) {
481 struct reiserfs_transaction_handle th ;
484 if (inode->i_sb->s_flags & MS_RDONLY) {
485 reiserfs_warning(inode->i_sb, "clm-6006: writing inode %lu on readonly FS",
489 reiserfs_write_lock(inode->i_sb);
491 /* this is really only used for atime updates, so they don't have
492 ** to be included in O_SYNC or fsync
494 err = journal_begin(&th, inode->i_sb, 1) ;
496 reiserfs_write_unlock (inode->i_sb);
499 reiserfs_update_sd (&th, inode);
500 journal_end(&th, inode->i_sb, 1) ;
501 reiserfs_write_unlock(inode->i_sb);
504 static void reiserfs_clear_inode (struct inode *inode)
506 struct posix_acl *acl;
508 acl = REISERFS_I(inode)->i_acl_access;
509 if (acl && !IS_ERR (acl))
510 posix_acl_release (acl);
511 REISERFS_I(inode)->i_acl_access = NULL;
513 acl = REISERFS_I(inode)->i_acl_default;
514 if (acl && !IS_ERR (acl))
515 posix_acl_release (acl);
516 REISERFS_I(inode)->i_acl_default = NULL;
519 struct super_operations reiserfs_sops =
521 .alloc_inode = reiserfs_alloc_inode,
522 .destroy_inode = reiserfs_destroy_inode,
523 .write_inode = reiserfs_write_inode,
524 .dirty_inode = reiserfs_dirty_inode,
525 .delete_inode = reiserfs_delete_inode,
526 .clear_inode = reiserfs_clear_inode,
527 .put_super = reiserfs_put_super,
528 .write_super = reiserfs_write_super,
529 .write_super_lockfs = reiserfs_write_super_lockfs,
530 .unlockfs = reiserfs_unlockfs,
531 .statfs = reiserfs_statfs,
532 .remount_fs = reiserfs_remount,
536 static struct export_operations reiserfs_export_ops = {
537 .encode_fh = reiserfs_encode_fh,
538 .decode_fh = reiserfs_decode_fh,
539 .get_parent = reiserfs_get_parent,
540 .get_dentry = reiserfs_get_dentry,
543 /* this struct is used in reiserfs_getopt () for containing the value for those
544 mount options that have values rather than being toggles. */
547 int setmask; /* bitmask which is to set on mount_options bitmask when this
548 value is found, 0 is no bits are to be changed. */
549 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
550 value is found, 0 is no bits are to be changed. This is
551 applied BEFORE setmask */
555 /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
559 int arg_required; /* 0 if argument is not required, not 0 otherwise */
560 const arg_desc_t * values; /* list of values accepted by an option */
561 int setmask; /* bitmask which is to set on mount_options bitmask when this
562 value is found, 0 is no bits are to be changed. */
563 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
564 value is found, 0 is no bits are to be changed. This is
565 applied BEFORE setmask */
568 /* possible values for -o data= */
569 static const arg_desc_t logging_mode[] = {
570 {"ordered", 1<<REISERFS_DATA_ORDERED, (1<<REISERFS_DATA_LOG|1<<REISERFS_DATA_WRITEBACK)},
571 {"journal", 1<<REISERFS_DATA_LOG, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_WRITEBACK)},
572 {"writeback", 1<<REISERFS_DATA_WRITEBACK, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_LOG)},
576 /* possible values for -o barrier= */
577 static const arg_desc_t barrier_mode[] = {
578 {"none", 1<<REISERFS_BARRIER_NONE, 1<<REISERFS_BARRIER_FLUSH},
579 {"flush", 1<<REISERFS_BARRIER_FLUSH, 1<<REISERFS_BARRIER_NONE},
583 /* possible values for "-o block-allocator=" and bits which are to be set in
584 s_mount_opt of reiserfs specific part of in-core super block */
585 static const arg_desc_t balloc[] = {
586 {"noborder", 1<<REISERFS_NO_BORDER, 0},
587 {"border", 0, 1<<REISERFS_NO_BORDER},
588 {"no_unhashed_relocation", 1<<REISERFS_NO_UNHASHED_RELOCATION, 0},
589 {"hashed_relocation", 1<<REISERFS_HASHED_RELOCATION, 0},
590 {"test4", 1<<REISERFS_TEST4, 0},
591 {"notest4", 0, 1<<REISERFS_TEST4},
595 static const arg_desc_t tails[] = {
596 {"on", 1<<REISERFS_LARGETAIL, 1<<REISERFS_SMALLTAIL},
597 {"off", 0, (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
598 {"small", 1<<REISERFS_SMALLTAIL, 1<<REISERFS_LARGETAIL},
602 static const arg_desc_t error_actions[] = {
603 {"panic", 1 << REISERFS_ERROR_PANIC,
604 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
605 {"ro-remount", 1 << REISERFS_ERROR_RO,
606 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
607 #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
608 {"continue", 1 << REISERFS_ERROR_CONTINUE,
609 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
614 int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k.
615 There might be broken applications that are
616 confused by this. Use nolargeio mount option
617 to get usual i/o size = PAGE_SIZE.
620 /* proceed only one option from a list *cur - string containing of mount options
621 opts - array of options which are accepted
622 opt_arg - if option is found and requires an argument and if it is specifed
623 in the input - pointer to the argument is stored here
624 bit_flags - if option requires to set a certain bit - it is set here
625 return -1 if unknown option is found, opt->arg_required otherwise */
626 static int reiserfs_getopt ( struct super_block * s, char ** cur, opt_desc_t * opts, char ** opt_arg,
627 unsigned long * bit_flags)
636 const opt_desc_t * opt;
637 const arg_desc_t * arg;
642 /* assume argument cannot contain commas */
643 *cur = strchr (p, ',');
649 if ( !strncmp (p, "alloc=", 6) ) {
650 /* Ugly special case, probably we should redo options parser so that
651 it can understand several arguments for some options, also so that
652 it can fill several bitfields with option values. */
653 if ( reiserfs_parse_alloc_options( s, p + 6) ) {
661 /* for every option in the list */
662 for (opt = opts; opt->option_name; opt ++) {
663 if (!strncmp (p, opt->option_name, strlen (opt->option_name))) {
665 if (opt->clrmask == (1 << REISERFS_UNSUPPORTED_OPT))
666 reiserfs_warning (s, "%s not supported.", p);
668 *bit_flags &= ~opt->clrmask;
669 if (opt->setmask == (1 << REISERFS_UNSUPPORTED_OPT))
670 reiserfs_warning (s, "%s not supported.", p);
672 *bit_flags |= opt->setmask;
677 if (!opt->option_name) {
678 reiserfs_warning (s, "unknown mount option \"%s\"", p);
682 p += strlen (opt->option_name);
685 if (!opt->arg_required) {
686 reiserfs_warning (s, "the option \"%s\" does not require an argument",
693 if (opt->arg_required) {
694 reiserfs_warning (s, "the option \"%s\" requires an argument", opt->option_name);
699 reiserfs_warning (s, "head of option \"%s\" is only correct", opt->option_name);
703 /* move to the argument, or to next option if argument is not required */
706 if ( opt->arg_required && !strlen (p) ) {
707 /* this catches "option=," */
708 reiserfs_warning (s, "empty argument for \"%s\"", opt->option_name);
713 /* *=NULLopt_arg contains pointer to argument */
715 return opt->arg_required;
718 /* values possible for this option are listed in opt->values */
719 for (arg = opt->values; arg->value; arg ++) {
720 if (!strcmp (p, arg->value)) {
722 *bit_flags &= ~arg->clrmask;
723 *bit_flags |= arg->setmask;
725 return opt->arg_required;
729 reiserfs_warning (s, "bad value \"%s\" for option \"%s\"", p, opt->option_name);
733 /* returns 0 if something is wrong in option string, 1 - otherwise */
734 static int reiserfs_parse_options (struct super_block * s, char * options, /* string given via mount's -o */
735 unsigned long * mount_options,
736 /* after the parsing phase, contains the
737 collection of bitflags defining what
738 mount options were selected. */
739 unsigned long * blocks, /* strtol-ed from NNN of resize=NNN */
741 unsigned int * commit_max_age)
746 opt_desc_t opts[] = {
747 /* Compatibility stuff, so that -o notail for old setups still work */
748 {"tails", .arg_required = 't', .values = tails},
749 {"notail", .clrmask = (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
750 {"conv", .setmask = 1<<REISERFS_CONVERT},
751 {"attrs", .setmask = 1<<REISERFS_ATTRS},
752 {"noattrs", .clrmask = 1<<REISERFS_ATTRS},
753 #ifdef CONFIG_REISERFS_FS_XATTR
754 {"user_xattr", .setmask = 1<<REISERFS_XATTRS_USER},
755 {"nouser_xattr",.clrmask = 1<<REISERFS_XATTRS_USER},
757 {"user_xattr", .setmask = 1<<REISERFS_UNSUPPORTED_OPT},
758 {"nouser_xattr",.clrmask = 1<<REISERFS_UNSUPPORTED_OPT},
760 {"tagxid", .setmask = 1<<REISERFS_TAGXID},
761 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
762 {"acl", .setmask = 1<<REISERFS_POSIXACL},
763 {"noacl", .clrmask = 1<<REISERFS_POSIXACL},
765 {"acl", .setmask = 1<<REISERFS_UNSUPPORTED_OPT},
766 {"noacl", .clrmask = 1<<REISERFS_UNSUPPORTED_OPT},
768 {"nolog",}, /* This is unsupported */
769 {"replayonly", .setmask = 1<<REPLAYONLY},
770 {"block-allocator", .arg_required = 'a', .values = balloc},
771 {"data", .arg_required = 'd', .values = logging_mode},
772 {"barrier", .arg_required = 'b', .values = barrier_mode},
773 {"resize", .arg_required = 'r', .values = NULL},
774 {"jdev", .arg_required = 'j', .values = NULL},
775 {"nolargeio", .arg_required = 'w', .values = NULL},
776 {"commit", .arg_required = 'c', .values = NULL},
779 {"errors", .arg_required = 'e', .values = error_actions},
784 if (!options || !*options)
785 /* use default configuration: create tails, journaling on, no
786 conversion to newest format */
789 for (pos = options; pos; ) {
790 c = reiserfs_getopt (s, &pos, opts, &arg, mount_options);
792 /* wrong option is given */
800 *blocks = simple_strtoul (arg, &p, 0);
802 /* NNN does not look like a number */
803 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg);
810 unsigned long val = simple_strtoul (arg, &p, 0);
811 /* commit=NNN (time in seconds) */
812 if ( *p != '\0' || val >= (unsigned int)-1) {
813 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg); return 0;
815 *commit_max_age = (unsigned int)val;
820 int val = simple_strtoul (arg, &p, 0);
823 reiserfs_warning (s, "reiserfs_parse_options: non-numeric value %s for nolargeio option", arg);
827 reiserfs_default_io_size = PAGE_SIZE;
829 reiserfs_default_io_size = 128 * 1024;
833 if (arg && *arg && jdev_name) {
834 if ( *jdev_name ) { //Hm, already assigned?
835 reiserfs_warning (s, "reiserfs_parse_options: journal device was already specified to be %s", *jdev_name);
846 static void switch_data_mode(struct super_block *s, unsigned long mode) {
847 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
848 (1 << REISERFS_DATA_ORDERED) |
849 (1 << REISERFS_DATA_WRITEBACK));
850 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
853 static void handle_data_mode(struct super_block *s, unsigned long mount_options)
855 if (mount_options & (1 << REISERFS_DATA_LOG)) {
856 if (!reiserfs_data_log(s)) {
857 switch_data_mode(s, REISERFS_DATA_LOG);
858 reiserfs_info (s, "switching to journaled data mode\n");
860 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
861 if (!reiserfs_data_ordered(s)) {
862 switch_data_mode(s, REISERFS_DATA_ORDERED);
863 reiserfs_info (s, "switching to ordered data mode\n");
865 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
866 if (!reiserfs_data_writeback(s)) {
867 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
868 reiserfs_info (s, "switching to writeback data mode\n");
873 static void handle_barrier_mode(struct super_block *s, unsigned long bits) {
874 int flush = (1 << REISERFS_BARRIER_FLUSH);
875 int none = (1 << REISERFS_BARRIER_NONE);
876 int all_barrier = flush | none;
878 if (bits & all_barrier) {
879 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
881 REISERFS_SB(s)->s_mount_opt |= flush;
882 printk("reiserfs: enabling write barrier flush mode\n");
883 } else if (bits & none) {
884 REISERFS_SB(s)->s_mount_opt |= none;
885 printk("reiserfs: write barriers turned off\n");
890 static void handle_attrs( struct super_block *s )
892 struct reiserfs_super_block * rs;
894 if( reiserfs_attrs( s ) ) {
895 rs = SB_DISK_SUPER_BLOCK (s);
896 if( old_format_only(s) ) {
897 reiserfs_warning(s, "reiserfs: cannot support attributes on 3.5.x disk format" );
898 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
901 if( !( le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared ) ) {
902 reiserfs_warning(s, "reiserfs: cannot support attributes until flag is set in super-block" );
903 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
908 static int reiserfs_remount (struct super_block * s, int * mount_flags, char * arg)
910 struct reiserfs_super_block * rs;
911 struct reiserfs_transaction_handle th ;
912 unsigned long blocks;
913 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
914 unsigned long safe_mask = 0;
915 unsigned int commit_max_age = (unsigned int)-1;
916 struct reiserfs_journal *journal = SB_JOURNAL(s);
919 rs = SB_DISK_SUPER_BLOCK (s);
921 if (!reiserfs_parse_options(s, arg, &mount_options, &blocks, NULL, &commit_max_age))
926 /* Add options that are safe here */
927 safe_mask |= 1 << REISERFS_SMALLTAIL;
928 safe_mask |= 1 << REISERFS_LARGETAIL;
929 safe_mask |= 1 << REISERFS_NO_BORDER;
930 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
931 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
932 safe_mask |= 1 << REISERFS_TEST4;
933 safe_mask |= 1 << REISERFS_ATTRS;
934 safe_mask |= 1 << REISERFS_XATTRS_USER;
935 safe_mask |= 1 << REISERFS_POSIXACL;
936 safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
937 safe_mask |= 1 << REISERFS_BARRIER_NONE;
938 safe_mask |= 1 << REISERFS_ERROR_RO;
939 safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
940 safe_mask |= 1 << REISERFS_ERROR_PANIC;
942 /* Update the bitmask, taking care to keep
943 * the bits we're not allowed to change here */
944 REISERFS_SB(s)->s_mount_opt = (REISERFS_SB(s)->s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
946 if(commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
947 journal->j_max_commit_age = commit_max_age;
948 journal->j_max_trans_age = commit_max_age;
950 else if(commit_max_age == 0)
952 /* 0 means restore defaults. */
953 journal->j_max_commit_age = journal->j_default_max_commit_age;
954 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
958 int rc = reiserfs_resize(s, blocks);
963 if (*mount_flags & MS_RDONLY) {
964 reiserfs_xattr_init (s, *mount_flags);
965 /* remount read-only */
966 if (s->s_flags & MS_RDONLY)
967 /* it is read-only already */
969 /* try to remount file system with read-only permissions */
970 if (sb_umount_state(rs) == REISERFS_VALID_FS || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
974 err = journal_begin(&th, s, 10) ;
978 /* Mounting a rw partition read-only. */
979 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
980 set_sb_umount_state( rs, REISERFS_SB(s)->s_mount_state );
981 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
983 /* remount read-write */
984 if (!(s->s_flags & MS_RDONLY)) {
985 reiserfs_xattr_init (s, *mount_flags);
986 return 0; /* We are read-write already */
989 if (reiserfs_is_journal_aborted (journal))
990 return journal->j_errno;
992 handle_data_mode(s, mount_options);
993 handle_barrier_mode(s, mount_options);
994 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs) ;
995 s->s_flags &= ~MS_RDONLY ; /* now it is safe to call journal_begin */
996 err = journal_begin(&th, s, 10) ;
1000 /* Mount a partition which is read-only, read-write */
1001 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
1002 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1003 s->s_flags &= ~MS_RDONLY;
1004 set_sb_umount_state( rs, REISERFS_ERROR_FS );
1005 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1006 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
1007 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS ;
1009 /* this will force a full flush of all journal lists */
1010 SB_JOURNAL(s)->j_must_wait = 1 ;
1011 err = journal_end(&th, s, 10) ;
1016 if (!( *mount_flags & MS_RDONLY ) ) {
1017 finish_unfinished( s );
1018 reiserfs_xattr_init (s, *mount_flags);
1024 /* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
1025 * @sb - superblock for this filesystem
1026 * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
1028 * This routine counts how many free bits there are, finding the first zero
1029 * as a side effect. Could also be implemented as a loop of test_bit() calls, or
1030 * a loop of find_first_zero_bit() calls. This implementation is similar to
1031 * find_first_zero_bit(), but doesn't return after it finds the first bit.
1032 * Should only be called on fs mount, but should be fairly efficient anyways.
1034 * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
1035 * will * invariably occupt block 0 represented in the bitmap. The only
1036 * exception to this is when free_count also == 0, since there will be no
1037 * free blocks at all.
1040 static void load_bitmap_info_data (struct super_block *sb,
1041 struct reiserfs_bitmap_info *bi)
1043 unsigned long *cur = (unsigned long *)bi->bh->b_data;
1045 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
1047 /* No need to scan if all 0's or all 1's.
1048 * Since we're only counting 0's, we can simply ignore all 1's */
1050 if (bi->first_zero_hint == 0) {
1051 bi->first_zero_hint = ((char *)cur - bi->bh->b_data) << 3;
1053 bi->free_count += sizeof(unsigned long)*8;
1054 } else if (*cur != ~0L) {
1056 for (b = 0; b < sizeof(unsigned long)*8; b++) {
1057 if (!reiserfs_test_le_bit (b, cur)) {
1059 if (bi->first_zero_hint == 0)
1060 bi->first_zero_hint =
1061 (((char *)cur - bi->bh->b_data) << 3) + b;
1068 #ifdef CONFIG_REISERFS_CHECK
1069 // This outputs a lot of unneded info on big FSes
1070 // reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
1071 // bi->bh->b_blocknr, bi->free_count);
1075 static int read_bitmaps (struct super_block * s)
1079 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1080 if (SB_AP_BITMAP (s) == 0)
1082 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1083 for (i = 0, bmap_nr = REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
1084 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
1085 SB_AP_BITMAP (s)[i].bh = sb_getblk(s, bmap_nr);
1086 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
1087 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
1089 for (i = 0; i < SB_BMAP_NR(s); i++) {
1090 wait_on_buffer(SB_AP_BITMAP (s)[i].bh);
1091 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1092 reiserfs_warning(s,"sh-2029: reiserfs read_bitmaps: "
1093 "bitmap block (#%lu) reading failed",
1094 SB_AP_BITMAP(s)[i].bh->b_blocknr);
1095 for (i = 0; i < SB_BMAP_NR(s); i++)
1096 brelse(SB_AP_BITMAP(s)[i].bh);
1097 vfree(SB_AP_BITMAP(s));
1098 SB_AP_BITMAP(s) = NULL;
1101 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
1106 static int read_old_bitmaps (struct super_block * s)
1109 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK(s);
1110 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
1112 /* read true bitmap */
1113 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1114 if (SB_AP_BITMAP (s) == 0)
1117 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1119 for (i = 0; i < sb_bmap_nr(rs); i ++) {
1120 SB_AP_BITMAP (s)[i].bh = sb_bread (s, bmp1 + i);
1121 if (!SB_AP_BITMAP (s)[i].bh)
1123 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
1129 void check_bitmap (struct super_block * s)
1135 while (i < SB_BLOCK_COUNT (s)) {
1136 buf = SB_AP_BITMAP (s)[i / (s->s_blocksize * 8)].bh->b_data;
1137 if (!reiserfs_test_le_bit (i % (s->s_blocksize * 8), buf))
1142 if (free != SB_FREE_BLOCKS (s))
1143 reiserfs_warning (s,"vs-4000: check_bitmap: %d free blocks, must be %d",
1144 free, SB_FREE_BLOCKS (s));
1147 static int read_super_block (struct super_block * s, int offset)
1149 struct buffer_head * bh;
1150 struct reiserfs_super_block * rs;
1154 bh = sb_bread (s, offset / s->s_blocksize);
1156 reiserfs_warning (s, "sh-2006: read_super_block: "
1157 "bread failed (dev %s, block %lu, size %lu)",
1158 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1162 rs = (struct reiserfs_super_block *)bh->b_data;
1163 if (!is_any_reiserfs_magic_string (rs)) {
1169 // ok, reiserfs signature (old or new) found in at the given offset
1171 fs_blocksize = sb_blocksize(rs);
1173 sb_set_blocksize (s, fs_blocksize);
1175 bh = sb_bread (s, offset / s->s_blocksize);
1177 reiserfs_warning (s, "sh-2007: read_super_block: "
1178 "bread failed (dev %s, block %lu, size %lu)\n",
1179 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1183 rs = (struct reiserfs_super_block *)bh->b_data;
1184 if (sb_blocksize(rs) != s->s_blocksize) {
1185 reiserfs_warning (s, "sh-2011: read_super_block: "
1186 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1187 reiserfs_bdevname (s), (unsigned long long)bh->b_blocknr, s->s_blocksize);
1192 if ( rs->s_v1.s_root_block == -1 ) {
1194 reiserfs_warning (s, "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1195 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1196 "get newer reiserfsprogs package");
1200 SB_BUFFER_WITH_SB (s) = bh;
1201 SB_DISK_SUPER_BLOCK (s) = rs;
1203 if (is_reiserfs_jr (rs)) {
1204 /* magic is of non-standard journal filesystem, look at s_version to
1205 find which format is in use */
1206 if (sb_version(rs) == REISERFS_VERSION_2)
1207 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.6\""
1208 " with non-standard journal");
1209 else if (sb_version(rs) == REISERFS_VERSION_1)
1210 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.5\""
1211 " with non-standard journal");
1213 reiserfs_warning (s, "sh-2012: read_super_block: found unknown "
1214 "format \"%u\" of reiserfs with non-standard magic",
1220 /* s_version of standard format may contain incorrect information,
1221 so we just look at the magic string */
1222 reiserfs_info (s, "found reiserfs format \"%s\" with standard journal\n",
1223 is_reiserfs_3_5 (rs) ? "3.5" : "3.6");
1225 s->s_op = &reiserfs_sops;
1226 s->s_export_op = &reiserfs_export_ops;
1228 /* new format is limited by the 32 bit wide i_blocks field, want to
1229 ** be one full block below that.
1231 s->s_maxbytes = (512LL << 32) - s->s_blocksize ;
1237 /* after journal replay, reread all bitmap and super blocks */
1238 static int reread_meta_blocks(struct super_block *s) {
1240 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))) ;
1241 wait_on_buffer(SB_BUFFER_WITH_SB(s)) ;
1242 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1243 reiserfs_warning (s, "reread_meta_blocks, error reading the super") ;
1247 for (i = 0; i < SB_BMAP_NR(s) ; i++) {
1248 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh)) ;
1249 wait_on_buffer(SB_AP_BITMAP(s)[i].bh) ;
1250 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1251 reiserfs_warning (s, "reread_meta_blocks, error reading bitmap block number %d at %llu",
1252 i, (unsigned long long)SB_AP_BITMAP(s)[i].bh->b_blocknr) ;
1261 /////////////////////////////////////////////////////
1262 // hash detection stuff
1265 // if root directory is empty - we set default - Yura's - hash and
1267 // FIXME: we look for only one name in a directory. If tea and yura
1268 // bith have the same value - we ask user to send report to the
1270 __u32 find_hash_out (struct super_block * s)
1273 struct inode * inode;
1275 INITIALIZE_PATH (path);
1276 struct reiserfs_dir_entry de;
1277 __u32 hash = DEFAULT_HASH;
1279 inode = s->s_root->d_inode;
1281 do { // Some serious "goto"-hater was there ;)
1282 u32 teahash, r5hash, yurahash;
1284 make_cpu_key (&key, inode, ~0, TYPE_DIRENTRY, 3);
1285 retval = search_by_entry_key (s, &key, &path, &de);
1286 if (retval == IO_ERROR) {
1290 if (retval == NAME_NOT_FOUND)
1292 set_de_name_and_namelen (&de);
1293 if (deh_offset( &(de.de_deh[de.de_entry_num]) ) == DOT_DOT_OFFSET) {
1294 /* allow override in this case */
1295 if (reiserfs_rupasov_hash(s)) {
1298 reiserfs_warning(s,"FS seems to be empty, autodetect "
1299 "is using the default hash");
1302 r5hash=GET_HASH_VALUE (r5_hash (de.de_name, de.de_namelen));
1303 teahash=GET_HASH_VALUE (keyed_hash (de.de_name, de.de_namelen));
1304 yurahash=GET_HASH_VALUE (yura_hash (de.de_name, de.de_namelen));
1305 if ( ( (teahash == r5hash) && (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) ) ||
1306 ( (teahash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ||
1307 ( (r5hash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ) {
1308 reiserfs_warning(s,"Unable to automatically detect hash function. "
1309 "Please mount with -o hash={tea,rupasov,r5}",
1310 reiserfs_bdevname (s));
1314 if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == yurahash)
1316 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == teahash)
1318 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == r5hash)
1321 reiserfs_warning (s,"Unrecognised hash function");
1330 // finds out which hash names are sorted with
1331 static int what_hash (struct super_block * s)
1335 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1337 /* reiserfs_hash_detect() == true if any of the hash mount options
1338 ** were used. We must check them to make sure the user isn't
1339 ** using a bad hash value
1341 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1342 code = find_hash_out (s);
1344 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1345 /* detection has found the hash, and we must check against the
1348 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1349 reiserfs_warning (s, "Error, %s hash detected, "
1350 "unable to force rupasov hash", reiserfs_hashname(code)) ;
1352 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1353 reiserfs_warning (s, "Error, %s hash detected, "
1354 "unable to force tea hash", reiserfs_hashname(code)) ;
1356 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1357 reiserfs_warning (s, "Error, %s hash detected, "
1358 "unable to force r5 hash", reiserfs_hashname(code)) ;
1362 /* find_hash_out was not called or could not determine the hash */
1363 if (reiserfs_rupasov_hash(s)) {
1365 } else if (reiserfs_tea_hash(s)) {
1367 } else if (reiserfs_r5_hash(s)) {
1372 /* if we are mounted RW, and we have a new valid hash code, update
1375 if (code != UNSET_HASH &&
1376 !(s->s_flags & MS_RDONLY) &&
1377 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1378 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1383 // return pointer to appropriate function
1384 static hashf_t hash_function (struct super_block * s)
1386 switch (what_hash (s)) {
1388 reiserfs_info (s, "Using tea hash to sort names\n");
1391 reiserfs_info (s, "Using rupasov hash to sort names\n");
1394 reiserfs_info (s, "Using r5 hash to sort names\n");
1400 // this is used to set up correct value for old partitions
1401 int function2code (hashf_t func)
1403 if (func == keyed_hash)
1405 if (func == yura_hash)
1407 if (func == r5_hash)
1410 BUG() ; // should never happen
1415 #define SWARN(silent, s, ...) \
1417 reiserfs_warning (s, __VA_ARGS__)
1419 static int reiserfs_fill_super (struct super_block * s, void * data, int silent)
1421 struct inode *root_inode;
1423 struct reiserfs_transaction_handle th ;
1425 unsigned long blocks;
1426 unsigned int commit_max_age = 0;
1427 int jinit_done = 0 ;
1428 struct reiserfs_iget_args args ;
1429 struct reiserfs_super_block * rs;
1431 struct reiserfs_sb_info *sbi;
1432 int errval = -EINVAL;
1434 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1440 memset (sbi, 0, sizeof (struct reiserfs_sb_info));
1441 /* Set default values for options: non-aggressive tails, RO on errors */
1442 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1443 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1444 /* no preallocation minimum, be smart in
1445 reiserfs_file_write instead */
1446 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1447 /* Preallocate by 16 blocks (17-1) at once */
1448 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1449 /* Initialize the rwsem for xattr dir */
1450 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
1452 /* setup default block allocator options */
1453 reiserfs_init_alloc_options(s);
1456 if (reiserfs_parse_options (s, (char *) data, &(sbi->s_mount_opt), &blocks, &jdev_name, &commit_max_age) == 0) {
1461 SWARN (silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1462 "for remount only");
1466 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1467 if (!read_super_block (s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1469 /* try new format (64-th 1k block), which can contain reiserfs super block */
1470 else if (read_super_block (s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1471 SWARN(silent, s, "sh-2021: reiserfs_fill_super: can not find reiserfs on %s", reiserfs_bdevname (s));
1475 rs = SB_DISK_SUPER_BLOCK (s);
1476 /* Let's do basic sanity check to verify that underlying device is not
1477 smaller than the filesystem. If the check fails then abort and scream,
1478 because bad stuff will happen otherwise. */
1479 if ( s->s_bdev && s->s_bdev->bd_inode && i_size_read(s->s_bdev->bd_inode) < sb_block_count(rs)*sb_blocksize(rs)) {
1480 SWARN (silent, s, "Filesystem on %s cannot be mounted because it is bigger than the device", reiserfs_bdevname(s));
1481 SWARN(silent, s, "You may need to run fsck or increase size of your LVM partition");
1482 SWARN(silent, s, "Or may be you forgot to reboot after fdisk when it told you to");
1486 sbi->s_mount_state = SB_REISERFS_STATE(s);
1487 sbi->s_mount_state = REISERFS_VALID_FS ;
1489 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1490 SWARN(silent, s, "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1493 #ifdef CONFIG_REISERFS_CHECK
1494 SWARN (silent, s, "CONFIG_REISERFS_CHECK is set ON");
1495 SWARN (silent, s, "- it is slow mode for debugging.");
1498 /* make data=ordered the default */
1499 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1500 !reiserfs_data_writeback(s))
1502 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1505 if (reiserfs_data_log(s)) {
1506 reiserfs_info (s, "using journaled data mode\n");
1507 } else if (reiserfs_data_ordered(s)) {
1508 reiserfs_info (s, "using ordered data mode\n");
1510 reiserfs_info (s, "using writeback data mode\n");
1512 if (reiserfs_barrier_flush(s)) {
1513 printk("reiserfs: using flush barriers\n");
1516 // set_device_ro(s->s_dev, 1) ;
1517 if( journal_init(s, jdev_name, old_format, commit_max_age) ) {
1518 SWARN(silent, s, "sh-2022: reiserfs_fill_super: unable to initialize journal space") ;
1521 jinit_done = 1 ; /* once this is set, journal_release must be called
1522 ** if we error out of the mount
1525 if (reread_meta_blocks(s)) {
1526 SWARN(silent, s, "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init") ;
1530 if (replay_only (s))
1533 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1534 SWARN(silent, s, "clm-7000: Detected readonly device, marking FS readonly") ;
1535 s->s_flags |= MS_RDONLY ;
1537 args.objectid = REISERFS_ROOT_OBJECTID ;
1538 args.dirid = REISERFS_ROOT_PARENT_OBJECTID ;
1539 root_inode = iget5_locked (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
1541 SWARN(silent, s, "jmacd-10: reiserfs_fill_super: get root inode failed");
1545 if (root_inode->i_state & I_NEW) {
1546 reiserfs_read_locked_inode(root_inode, &args);
1547 unlock_new_inode(root_inode);
1550 s->s_root = d_alloc_root(root_inode);
1556 // define and initialize hash function
1557 sbi->s_hash_function = hash_function (s);
1558 if (sbi->s_hash_function == NULL) {
1564 if (is_reiserfs_3_5 (rs) || (is_reiserfs_jr (rs) && SB_VERSION (s) == REISERFS_VERSION_1))
1565 set_bit(REISERFS_3_5, &(sbi->s_properties));
1567 set_bit(REISERFS_3_6, &(sbi->s_properties));
1569 if (!(s->s_flags & MS_RDONLY)) {
1571 errval = journal_begin(&th, s, 1) ;
1577 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
1579 set_sb_umount_state( rs, REISERFS_ERROR_FS );
1580 set_sb_fs_state (rs, 0);
1582 if (old_format_only(s)) {
1583 /* filesystem of format 3.5 either with standard or non-standard
1585 if (convert_reiserfs (s)) {
1586 /* and -o conv is given */
1588 reiserfs_info (s,"converting 3.5 filesystem to the 3.6 format") ;
1590 if (is_reiserfs_3_5 (rs))
1591 /* put magic string of 3.6 format. 2.2 will not be able to
1592 mount this filesystem anymore */
1593 memcpy (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
1594 sizeof (reiserfs_3_6_magic_string));
1596 set_sb_version(rs,REISERFS_VERSION_2);
1597 reiserfs_convert_objectid_map_v1(s) ;
1598 set_bit(REISERFS_3_6, &(sbi->s_properties));
1599 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1600 } else if (!silent){
1601 reiserfs_info (s, "using 3.5.x disk format\n") ;
1605 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
1606 errval = journal_end(&th, s, 1) ;
1613 if ((errval = reiserfs_xattr_init (s, s->s_flags))) {
1619 /* look for files which were to be removed in previous session */
1620 finish_unfinished (s);
1622 if ( old_format_only(s) && !silent) {
1623 reiserfs_info (s, "using 3.5.x disk format\n") ;
1626 if ((errval = reiserfs_xattr_init (s, s->s_flags))) {
1632 // mark hash in super block: it could be unset. overwrite should be ok
1633 set_sb_hash_function_code( rs, function2code(sbi->s_hash_function ) );
1637 reiserfs_proc_info_init( s );
1639 init_waitqueue_head (&(sbi->s_wait));
1640 sbi->bitmap_lock = SPIN_LOCK_UNLOCKED;
1645 if (jinit_done) { /* kill the commit thread, free journal ram */
1646 journal_release_error(NULL, s) ;
1648 if (SB_DISK_SUPER_BLOCK (s)) {
1649 for (j = 0; j < SB_BMAP_NR (s); j ++) {
1650 if (SB_AP_BITMAP (s))
1651 brelse (SB_AP_BITMAP (s)[j].bh);
1653 if (SB_AP_BITMAP (s))
1654 vfree (SB_AP_BITMAP (s));
1656 if (SB_BUFFER_WITH_SB (s))
1657 brelse(SB_BUFFER_WITH_SB (s));
1663 s->s_fs_info = NULL;
1668 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf)
1670 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
1672 buf->f_namelen = (REISERFS_MAX_NAME (s->s_blocksize));
1673 buf->f_bfree = sb_free_blocks(rs);
1674 buf->f_bavail = buf->f_bfree;
1675 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1676 buf->f_bsize = s->s_blocksize;
1677 /* changed to accommodate gcc folks.*/
1678 buf->f_type = REISERFS_SUPER_MAGIC;
1682 static struct super_block*
1683 get_super_block (struct file_system_type *fs_type, int flags,
1684 const char *dev_name, void *data)
1686 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
1690 init_reiserfs_fs ( void )
1694 if ((ret = init_inodecache ())) {
1698 if ((ret = reiserfs_xattr_register_handlers ()))
1699 goto failed_reiserfs_xattr_register_handlers;
1701 reiserfs_proc_info_global_init ();
1702 reiserfs_proc_register_global ("version", reiserfs_global_version_in_proc);
1704 ret = register_filesystem (& reiserfs_fs_type);
1710 reiserfs_xattr_unregister_handlers ();
1712 failed_reiserfs_xattr_register_handlers:
1713 reiserfs_proc_unregister_global ("version");
1714 reiserfs_proc_info_global_done ();
1715 destroy_inodecache ();
1721 exit_reiserfs_fs ( void )
1723 reiserfs_xattr_unregister_handlers ();
1724 reiserfs_proc_unregister_global ("version");
1725 reiserfs_proc_info_global_done ();
1726 unregister_filesystem (& reiserfs_fs_type);
1727 destroy_inodecache ();
1730 struct file_system_type reiserfs_fs_type = {
1731 .owner = THIS_MODULE,
1733 .get_sb = get_super_block,
1734 .kill_sb = kill_block_super,
1735 .fs_flags = FS_REQUIRES_DEV,
1738 MODULE_DESCRIPTION ("ReiserFS journaled filesystem");
1739 MODULE_AUTHOR ("Hans Reiser <reiser@namesys.com>");
1740 MODULE_LICENSE ("GPL");
1742 module_init (init_reiserfs_fs);
1743 module_exit (exit_reiserfs_fs);