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/smp_lock.h>
21 #include <linux/init.h>
22 #include <linux/blkdev.h>
23 #include <linux/buffer_head.h>
24 #include <linux/vfs.h>
26 struct file_system_type reiserfs_fs_type;
28 const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
29 const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
30 const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
32 int is_reiserfs_3_5 (struct reiserfs_super_block * rs)
34 return !strncmp (rs->s_v1.s_magic, reiserfs_3_5_magic_string,
35 strlen (reiserfs_3_5_magic_string));
39 int is_reiserfs_3_6 (struct reiserfs_super_block * rs)
41 return !strncmp (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
42 strlen (reiserfs_3_6_magic_string));
46 int is_reiserfs_jr (struct reiserfs_super_block * rs)
48 return !strncmp (rs->s_v1.s_magic, reiserfs_jr_magic_string,
49 strlen (reiserfs_jr_magic_string));
53 static int is_any_reiserfs_magic_string (struct reiserfs_super_block * rs)
55 return (is_reiserfs_3_5 (rs) || is_reiserfs_3_6 (rs) ||
59 static int reiserfs_remount (struct super_block * s, int * flags, char * data);
60 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf);
62 static void reiserfs_sync_fs (struct super_block * s)
64 if (!(s->s_flags & MS_RDONLY)) {
65 struct reiserfs_transaction_handle th;
66 reiserfs_write_lock(s);
67 journal_begin(&th, s, 1);
68 journal_end_sync(&th, s, 1);
69 reiserfs_flush_old_commits(s);
71 reiserfs_write_unlock(s);
75 static void reiserfs_write_super(struct super_block *s)
80 static void reiserfs_write_super_lockfs (struct super_block * s)
82 struct reiserfs_transaction_handle th ;
83 reiserfs_write_lock(s);
84 if (!(s->s_flags & MS_RDONLY)) {
85 journal_begin(&th, s, 1) ;
86 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
87 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
88 reiserfs_block_writes(&th) ;
89 journal_end_sync(&th, s, 1) ;
92 reiserfs_write_unlock(s);
95 void reiserfs_unlockfs(struct super_block *s) {
96 reiserfs_allow_writes(s) ;
99 extern const struct key MAX_KEY;
102 /* this is used to delete "save link" when there are no items of a
103 file it points to. It can either happen if unlink is completed but
104 "save unlink" removal, or if file has both unlink and truncate
105 pending and as unlink completes first (because key of "save link"
106 protecting unlink is bigger that a key lf "save link" which
107 protects truncate), so there left no items to make truncate
109 static void remove_save_link_only (struct super_block * s, struct key * key, int oid_free)
111 struct reiserfs_transaction_handle th;
113 /* we are going to do one balancing */
114 journal_begin (&th, s, JOURNAL_PER_BALANCE_CNT);
116 reiserfs_delete_solid_item (&th, key);
118 /* removals are protected by direct items */
119 reiserfs_release_objectid (&th, le32_to_cpu (key->k_objectid));
121 journal_end (&th, s, JOURNAL_PER_BALANCE_CNT);
125 /* look for uncompleted unlinks and truncates and complete them */
126 static void finish_unfinished (struct super_block * s)
128 INITIALIZE_PATH (path);
129 struct cpu_key max_cpu_key, obj_key;
130 struct key save_link_key;
132 struct item_head * ih;
133 struct buffer_head * bh;
137 struct inode * inode;
141 /* compose key to look for "save" links */
142 max_cpu_key.version = KEY_FORMAT_3_5;
143 max_cpu_key.on_disk_key = MAX_KEY;
144 max_cpu_key.key_length = 3;
147 REISERFS_SB(s)->s_is_unlinked_ok = 1;
149 retval = search_item (s, &max_cpu_key, &path);
150 if (retval != ITEM_NOT_FOUND) {
151 reiserfs_warning ("vs-2140: finish_unfinished: search_by_key returned %d\n",
156 bh = get_last_bh (&path);
157 item_pos = get_item_pos (&path);
158 if (item_pos != B_NR_ITEMS (bh)) {
159 reiserfs_warning ("vs-2060: finish_unfinished: wrong position found\n");
163 ih = B_N_PITEM_HEAD (bh, item_pos);
165 if (le32_to_cpu (ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
166 /* there are no "save" links anymore */
169 save_link_key = ih->ih_key;
170 if (is_indirect_le_ih (ih))
175 /* reiserfs_iget needs k_dirid and k_objectid only */
176 item = B_I_PITEM (bh, ih);
177 obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__u32 *)item);
178 obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid);
179 obj_key.on_disk_key.u.k_offset_v1.k_offset = 0;
180 obj_key.on_disk_key.u.k_offset_v1.k_uniqueness = 0;
184 inode = reiserfs_iget (s, &obj_key);
186 /* the unlink almost completed, it just did not manage to remove
187 "save" link and release objectid */
188 reiserfs_warning ("vs-2180: finish_unfinished: iget failed for %K\n",
190 remove_save_link_only (s, &save_link_key, 1);
194 if (!truncate && inode->i_nlink) {
195 /* file is not unlinked */
196 reiserfs_warning ("vs-2185: finish_unfinished: file %K is not unlinked\n",
198 remove_save_link_only (s, &save_link_key, 0);
202 if (truncate && S_ISDIR (inode->i_mode) ) {
203 /* We got a truncate request for a dir which is impossible.
204 The only imaginable way is to execute unfinished truncate request
205 then boot into old kernel, remove the file and create dir with
207 reiserfs_warning("green-2101: impossible truncate on a directory %k. Please report\n", INODE_PKEY (inode));
208 remove_save_link_only (s, &save_link_key, 0);
215 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
216 /* not completed truncate found. New size was committed together
218 reiserfs_warning ("Truncating %k to %Ld ..",
219 INODE_PKEY (inode), inode->i_size);
220 reiserfs_truncate_file (inode, 0/*don't update modification time*/);
221 remove_save_link (inode, truncate);
223 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
224 /* not completed unlink (rmdir) found */
225 reiserfs_warning ("Removing %k..", INODE_PKEY (inode));
226 /* removal gets completed in iput */
233 REISERFS_SB(s)->s_is_unlinked_ok = 0;
237 reiserfs_warning ("There were %d uncompleted unlinks/truncates. "
238 "Completed\n", done);
241 /* to protect file being unlinked from getting lost we "safe" link files
242 being unlinked. This link will be deleted in the same transaction with last
243 item of file. mounting the filesytem we scan all these links and remove
244 files which almost got lost */
245 void add_save_link (struct reiserfs_transaction_handle * th,
246 struct inode * inode, int truncate)
248 INITIALIZE_PATH (path);
254 /* file can only get one "save link" of each kind */
256 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ),
257 "saved link already exists for truncated inode %lx",
258 ( long ) inode -> i_ino );
260 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ),
261 "saved link already exists for unlinked inode %lx",
262 ( long ) inode -> i_ino );
264 /* setup key of "save" link */
265 key.version = KEY_FORMAT_3_5;
266 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
267 key.on_disk_key.k_objectid = inode->i_ino;
269 /* unlink, rmdir, rename */
270 set_cpu_key_k_offset (&key, 1 + inode->i_sb->s_blocksize);
271 set_cpu_key_k_type (&key, TYPE_DIRECT);
273 /* item head of "safe" link */
274 make_le_item_head (&ih, &key, key.version, 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
275 4/*length*/, 0xffff/*free space*/);
278 if (S_ISDIR (inode->i_mode))
279 reiserfs_warning("green-2102: Adding a truncate savelink for a directory %k! Please report\n", INODE_PKEY(inode));
280 set_cpu_key_k_offset (&key, 1);
281 set_cpu_key_k_type (&key, TYPE_INDIRECT);
283 /* item head of "safe" link */
284 make_le_item_head (&ih, &key, key.version, 1, TYPE_INDIRECT,
285 4/*length*/, 0/*free space*/);
289 /* look for its place in the tree */
290 retval = search_item (inode->i_sb, &key, &path);
291 if (retval != ITEM_NOT_FOUND) {
292 if ( retval != -ENOSPC )
293 reiserfs_warning ("vs-2100: add_save_link:"
294 "search_by_key (%K) returned %d\n", &key, retval);
299 /* body of "save" link */
300 link = INODE_PKEY (inode)->k_dir_id;
302 /* put "save" link inot tree */
303 retval = reiserfs_insert_item (th, &path, &key, &ih, (char *)&link);
305 if (retval != -ENOSPC)
306 reiserfs_warning ("vs-2120: add_save_link: insert_item returned %d\n",
310 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
312 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
317 /* this opens transaction unlike add_save_link */
318 void remove_save_link (struct inode * inode, int truncate)
320 struct reiserfs_transaction_handle th;
324 /* we are going to do one balancing only */
325 journal_begin (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
327 /* setup key of "save" link */
328 key.k_dir_id = cpu_to_le32 (MAX_KEY_OBJECTID);
329 key.k_objectid = INODE_PKEY (inode)->k_objectid;
331 /* unlink, rmdir, rename */
332 set_le_key_k_offset (KEY_FORMAT_3_5, &key,
333 1 + inode->i_sb->s_blocksize);
334 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_DIRECT);
337 set_le_key_k_offset (KEY_FORMAT_3_5, &key, 1);
338 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
342 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ) ) ||
344 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ) ) )
345 reiserfs_delete_solid_item (&th, &key);
347 reiserfs_release_objectid (&th, inode->i_ino);
348 REISERFS_I(inode) -> i_flags &= ~i_link_saved_unlink_mask;
350 REISERFS_I(inode) -> i_flags &= ~i_link_saved_truncate_mask;
352 journal_end (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
356 static void reiserfs_put_super (struct super_block * s)
359 struct reiserfs_transaction_handle th ;
361 /* change file system state to current state if it was mounted with read-write permissions */
362 if (!(s->s_flags & MS_RDONLY)) {
363 journal_begin(&th, s, 10) ;
364 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
365 set_sb_umount_state( SB_DISK_SUPER_BLOCK(s), REISERFS_SB(s)->s_mount_state );
366 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
369 /* note, journal_release checks for readonly mount, and can decide not
370 ** to do a journal_end
372 journal_release(&th, s) ;
374 for (i = 0; i < SB_BMAP_NR (s); i ++)
375 brelse (SB_AP_BITMAP (s)[i].bh);
377 vfree (SB_AP_BITMAP (s));
379 brelse (SB_BUFFER_WITH_SB (s));
381 print_statistics (s);
383 if (REISERFS_SB(s)->s_kmallocs != 0) {
384 reiserfs_warning ("vs-2004: reiserfs_put_super: allocated memory left %d\n",
385 REISERFS_SB(s)->s_kmallocs);
388 if (REISERFS_SB(s)->reserved_blocks != 0) {
389 reiserfs_warning ("green-2005: reiserfs_put_super: reserved blocks left %d\n",
390 REISERFS_SB(s)->reserved_blocks);
393 reiserfs_proc_info_done( s );
401 static kmem_cache_t * reiserfs_inode_cachep;
403 static struct inode *reiserfs_alloc_inode(struct super_block *sb)
405 struct reiserfs_inode_info *ei;
406 ei = (struct reiserfs_inode_info *)kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
409 return &ei->vfs_inode;
412 static void reiserfs_destroy_inode(struct inode *inode)
414 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
417 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
419 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *) foo;
421 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
422 SLAB_CTOR_CONSTRUCTOR) {
423 INIT_LIST_HEAD(&ei->i_prealloc_list) ;
424 inode_init_once(&ei->vfs_inode);
428 static int init_inodecache(void)
430 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
431 sizeof(struct reiserfs_inode_info),
432 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
434 if (reiserfs_inode_cachep == NULL)
439 static void destroy_inodecache(void)
441 if (kmem_cache_destroy(reiserfs_inode_cachep))
442 printk(KERN_INFO "reiserfs_inode_cache: not all structures were freed\n");
445 /* we don't mark inodes dirty, we just log them */
446 static void reiserfs_dirty_inode (struct inode * inode) {
447 struct reiserfs_transaction_handle th ;
449 if (inode->i_sb->s_flags & MS_RDONLY) {
450 reiserfs_warning("clm-6006: writing inode %lu on readonly FS\n",
454 reiserfs_write_lock(inode->i_sb);
456 /* this is really only used for atime updates, so they don't have
457 ** to be included in O_SYNC or fsync
459 journal_begin(&th, inode->i_sb, 1) ;
460 reiserfs_update_sd (&th, inode);
461 journal_end(&th, inode->i_sb, 1) ;
462 reiserfs_write_unlock(inode->i_sb);
465 struct super_operations reiserfs_sops =
467 .alloc_inode = reiserfs_alloc_inode,
468 .destroy_inode = reiserfs_destroy_inode,
469 .write_inode = reiserfs_write_inode,
470 .dirty_inode = reiserfs_dirty_inode,
471 .delete_inode = reiserfs_delete_inode,
472 .put_super = reiserfs_put_super,
473 .write_super = reiserfs_write_super,
474 .write_super_lockfs = reiserfs_write_super_lockfs,
475 .unlockfs = reiserfs_unlockfs,
476 .statfs = reiserfs_statfs,
477 .remount_fs = reiserfs_remount,
481 static struct export_operations reiserfs_export_ops = {
482 .encode_fh = reiserfs_encode_fh,
483 .decode_fh = reiserfs_decode_fh,
484 .get_parent = reiserfs_get_parent,
485 .get_dentry = reiserfs_get_dentry,
488 /* this struct is used in reiserfs_getopt () for containing the value for those
489 mount options that have values rather than being toggles. */
492 int setmask; /* bitmask which is to set on mount_options bitmask when this
493 value is found, 0 is no bits are to be changed. */
494 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
495 value is found, 0 is no bits are to be changed. This is
496 applied BEFORE setmask */
500 /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
504 int arg_required; /* 0 if argument is not required, not 0 otherwise */
505 const arg_desc_t * values; /* list of values accepted by an option */
506 int setmask; /* bitmask which is to set on mount_options bitmask when this
507 value is found, 0 is no bits are to be changed. */
508 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
509 value is found, 0 is no bits are to be changed. This is
510 applied BEFORE setmask */
513 /* possible values for -o data= */
514 static const arg_desc_t logging_mode[] = {
515 {"ordered", 1<<REISERFS_DATA_ORDERED, (1<<REISERFS_DATA_LOG|1<<REISERFS_DATA_WRITEBACK)},
516 {"journal", 1<<REISERFS_DATA_LOG, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_WRITEBACK)},
517 {"writeback", 1<<REISERFS_DATA_WRITEBACK, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_LOG)},
521 /* possible values for "-o block-allocator=" and bits which are to be set in
522 s_mount_opt of reiserfs specific part of in-core super block */
523 static const arg_desc_t balloc[] = {
524 {"noborder", 1<<REISERFS_NO_BORDER, 0},
525 {"border", 0, 1<<REISERFS_NO_BORDER},
526 {"no_unhashed_relocation", 1<<REISERFS_NO_UNHASHED_RELOCATION, 0},
527 {"hashed_relocation", 1<<REISERFS_HASHED_RELOCATION, 0},
528 {"test4", 1<<REISERFS_TEST4, 0},
529 {"notest4", 0, 1<<REISERFS_TEST4},
533 static const arg_desc_t tails[] = {
534 {"on", 1<<REISERFS_LARGETAIL, 1<<REISERFS_SMALLTAIL},
535 {"off", 0, (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
536 {"small", 1<<REISERFS_SMALLTAIL, 1<<REISERFS_LARGETAIL},
540 int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k.
541 There might be broken applications that are
542 confused by this. Use nolargeio mount option
543 to get usual i/o size = PAGE_SIZE.
546 /* proceed only one option from a list *cur - string containing of mount options
547 opts - array of options which are accepted
548 opt_arg - if option is found and requires an argument and if it is specifed
549 in the input - pointer to the argument is stored here
550 bit_flags - if option requires to set a certain bit - it is set here
551 return -1 if unknown option is found, opt->arg_required otherwise */
552 static int reiserfs_getopt ( struct super_block * s, char ** cur, opt_desc_t * opts, char ** opt_arg,
553 unsigned long * bit_flags)
562 const opt_desc_t * opt;
563 const arg_desc_t * arg;
568 /* assume argument cannot contain commas */
569 *cur = strchr (p, ',');
575 if ( !strncmp (p, "alloc=", 6) ) {
576 /* Ugly special case, probably we should redo options parser so that
577 it can understand several arguments for some options, also so that
578 it can fill several bitfields with option values. */
579 if ( reiserfs_parse_alloc_options( s, p + 6) ) {
587 /* for every option in the list */
588 for (opt = opts; opt->option_name; opt ++) {
589 if (!strncmp (p, opt->option_name, strlen (opt->option_name))) {
591 *bit_flags &= ~opt->clrmask;
592 *bit_flags |= opt->setmask;
597 if (!opt->option_name) {
598 printk ("reiserfs_getopt: unknown option \"%s\"\n", p);
602 p += strlen (opt->option_name);
605 if (!opt->arg_required) {
606 printk ("reiserfs_getopt: the option \"%s\" does not require an argument\n",
613 if (opt->arg_required) {
614 printk ("reiserfs_getopt: the option \"%s\" requires an argument\n", opt->option_name);
619 printk ("reiserfs_getopt: head of option \"%s\" is only correct\n", opt->option_name);
623 /* move to the argument, or to next option if argument is not required */
626 if ( opt->arg_required && !strlen (p) ) {
627 /* this catches "option=," */
628 printk ("reiserfs_getopt: empty argument for \"%s\"\n", opt->option_name);
633 /* *=NULLopt_arg contains pointer to argument */
635 return opt->arg_required;
638 /* values possible for this option are listed in opt->values */
639 for (arg = opt->values; arg->value; arg ++) {
640 if (!strcmp (p, arg->value)) {
642 *bit_flags &= ~arg->clrmask;
643 *bit_flags |= arg->setmask;
645 return opt->arg_required;
649 printk ("reiserfs_getopt: bad value \"%s\" for option \"%s\"\n", p, opt->option_name);
653 /* returns 0 if something is wrong in option string, 1 - otherwise */
654 static int reiserfs_parse_options (struct super_block * s, char * options, /* string given via mount's -o */
655 unsigned long * mount_options,
656 /* after the parsing phase, contains the
657 collection of bitflags defining what
658 mount options were selected. */
659 unsigned long * blocks, /* strtol-ed from NNN of resize=NNN */
661 unsigned int * commit_max_age)
666 opt_desc_t opts[] = {
667 {"tails", 't', tails, 0, 0}, /* Compatibility stuff, so that -o notail for old setups still work */
668 {"notail", 0, 0, 0, (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
669 {"conv", 0, 0, 1<<REISERFS_CONVERT, 0},
670 {"attrs", 0, 0, 1<<REISERFS_ATTRS, 0},
671 {"noattrs", 0, 0, 0, 1<<REISERFS_ATTRS},
672 {"nolog", 0, 0, 0, 0}, /* This is unsupported */
673 {"replayonly", 0, 0, 1<<REPLAYONLY, 0},
674 {"block-allocator", 'a', balloc, 0, 0},
675 {"data", 'd', logging_mode, 0, 0},
676 {"resize", 'r', 0, 0, 0},
677 {"jdev", 'j', 0, 0, 0},
678 {"nolargeio", 'w', 0, 0, 0},
679 {"commit", 'c', 0, 0, 0},
684 if (!options || !*options)
685 /* use default configuration: create tails, journaling on, no
686 conversion to newest format */
689 for (pos = options; pos; ) {
690 c = reiserfs_getopt (s, &pos, opts, &arg, mount_options);
692 /* wrong option is given */
700 *blocks = simple_strtoul (arg, &p, 0);
702 /* NNN does not look like a number */
703 printk ("reiserfs_parse_options: bad value %s\n", arg);
710 int val = simple_strtoul (arg, &p, 0);
711 /* commit=NNN (time in seconds) */
712 if ( *p != '\0' || val < 0) {
713 printk ("reiserfs_parse_options: bad value %s\n", arg);
716 *commit_max_age = val;
721 int val = simple_strtoul (arg, &p, 0);
724 printk ("reiserfs_parse_options: non-numeric value %s for nolargeio option\n", arg);
728 reiserfs_default_io_size = PAGE_SIZE;
730 reiserfs_default_io_size = 128 * 1024;
734 if (arg && *arg && jdev_name) {
735 if ( *jdev_name ) { //Hm, already assigned?
736 printk("reiserfs_parse_options: journal device was already specified to be %s\n", *jdev_name);
747 static void switch_data_mode(struct super_block *s, unsigned long mode) {
748 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
749 (1 << REISERFS_DATA_ORDERED) |
750 (1 << REISERFS_DATA_WRITEBACK));
751 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
754 static void handle_data_mode(struct super_block *s, unsigned long mount_options)
756 if (mount_options & (1 << REISERFS_DATA_LOG)) {
757 if (!reiserfs_data_log(s)) {
758 switch_data_mode(s, REISERFS_DATA_LOG);
759 printk("reiserfs: switching to journaled data mode\n");
761 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
762 if (!reiserfs_data_ordered(s)) {
763 switch_data_mode(s, REISERFS_DATA_ORDERED);
764 printk("reiserfs: switching to ordered data mode\n");
766 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
767 if (!reiserfs_data_writeback(s)) {
768 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
769 printk("reiserfs: switching to writeback data mode\n");
774 static void handle_attrs( struct super_block *s )
776 struct reiserfs_super_block * rs;
778 if( reiserfs_attrs( s ) ) {
779 rs = SB_DISK_SUPER_BLOCK (s);
780 if( old_format_only(s) ) {
781 reiserfs_warning( "reiserfs: cannot support attributes on 3.5.x disk format\n" );
782 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
785 if( !( le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared ) ) {
786 reiserfs_warning( "reiserfs: cannot support attributes until flag is set in super-block\n" );
787 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
792 static int reiserfs_remount (struct super_block * s, int * mount_flags, char * arg)
794 struct reiserfs_super_block * rs;
795 struct reiserfs_transaction_handle th ;
796 unsigned long blocks;
797 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
798 unsigned long safe_mask = 0;
799 unsigned int commit_max_age = 0;
801 rs = SB_DISK_SUPER_BLOCK (s);
803 if (!reiserfs_parse_options(s, arg, &mount_options, &blocks, NULL, &commit_max_age))
808 /* Add options that are safe here */
809 safe_mask |= 1 << REISERFS_SMALLTAIL;
810 safe_mask |= 1 << REISERFS_LARGETAIL;
811 safe_mask |= 1 << REISERFS_NO_BORDER;
812 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
813 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
814 safe_mask |= 1 << REISERFS_TEST4;
815 safe_mask |= 1 << REISERFS_ATTRS;
817 /* Update the bitmask, taking care to keep
818 * the bits we're not allowed to change here */
819 REISERFS_SB(s)->s_mount_opt = (REISERFS_SB(s)->s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
821 if(commit_max_age != 0) {
822 SB_JOURNAL_MAX_COMMIT_AGE(s) = commit_max_age;
823 SB_JOURNAL_MAX_TRANS_AGE(s) = commit_max_age;
827 /* 0 means restore defaults. */
828 SB_JOURNAL_MAX_COMMIT_AGE(s) = SB_JOURNAL_DEFAULT_MAX_COMMIT_AGE(s);
829 SB_JOURNAL_MAX_TRANS_AGE(s) = JOURNAL_MAX_TRANS_AGE;
833 int rc = reiserfs_resize(s, blocks);
838 if (*mount_flags & MS_RDONLY) {
839 /* remount read-only */
840 if (s->s_flags & MS_RDONLY)
841 /* it is read-only already */
843 /* try to remount file system with read-only permissions */
844 if (sb_umount_state(rs) == REISERFS_VALID_FS || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
848 journal_begin(&th, s, 10) ;
849 /* Mounting a rw partition read-only. */
850 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
851 set_sb_umount_state( rs, REISERFS_SB(s)->s_mount_state );
852 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
854 /* remount read-write */
855 if (!(s->s_flags & MS_RDONLY))
856 return 0; /* We are read-write already */
858 handle_data_mode(s, mount_options);
859 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs) ;
860 s->s_flags &= ~MS_RDONLY ; /* now it is safe to call journal_begin */
861 journal_begin(&th, s, 10) ;
863 /* Mount a partition which is read-only, read-write */
864 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
865 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
866 s->s_flags &= ~MS_RDONLY;
867 set_sb_umount_state( rs, REISERFS_ERROR_FS );
868 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
869 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
870 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS ;
872 /* this will force a full flush of all journal lists */
873 SB_JOURNAL(s)->j_must_wait = 1 ;
874 journal_end(&th, s, 10) ;
877 if (!( *mount_flags & MS_RDONLY ) )
878 finish_unfinished( s );
883 /* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
884 * @sb - superblock for this filesystem
885 * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
887 * This routine counts how many free bits there are, finding the first zero
888 * as a side effect. Could also be implemented as a loop of test_bit() calls, or
889 * a loop of find_first_zero_bit() calls. This implementation is similar to
890 * find_first_zero_bit(), but doesn't return after it finds the first bit.
891 * Should only be called on fs mount, but should be fairly efficient anyways.
893 * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
894 * will * invariably occupt block 0 represented in the bitmap. The only
895 * exception to this is when free_count also == 0, since there will be no
896 * free blocks at all.
899 static void load_bitmap_info_data (struct super_block *sb,
900 struct reiserfs_bitmap_info *bi)
902 unsigned long *cur = (unsigned long *)bi->bh->b_data;
904 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
906 /* No need to scan if all 0's or all 1's.
907 * Since we're only counting 0's, we can simply ignore all 1's */
909 if (bi->first_zero_hint == 0) {
910 bi->first_zero_hint = ((char *)cur - bi->bh->b_data) << 3;
912 bi->free_count += sizeof(unsigned long)*8;
913 } else if (*cur != ~0L) {
915 for (b = 0; b < sizeof(unsigned long)*8; b++) {
916 if (!reiserfs_test_le_bit (b, cur)) {
918 if (bi->first_zero_hint == 0)
919 bi->first_zero_hint =
920 (((char *)cur - bi->bh->b_data) << 3) + b;
927 #ifdef CONFIG_REISERFS_CHECK
928 // This outputs a lot of unneded info on big FSes
929 // reiserfs_warning ("bitmap loaded from block %d: %d free blocks\n",
930 // bi->bh->b_blocknr, bi->free_count);
934 static int read_bitmaps (struct super_block * s)
938 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
939 if (SB_AP_BITMAP (s) == 0)
941 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
942 for (i = 0, bmap_nr = REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
943 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
944 SB_AP_BITMAP (s)[i].bh = sb_getblk(s, bmap_nr);
945 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
946 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
948 for (i = 0; i < SB_BMAP_NR(s); i++) {
949 wait_on_buffer(SB_AP_BITMAP (s)[i].bh);
950 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
951 reiserfs_warning("sh-2029: reiserfs read_bitmaps: "
952 "bitmap block (#%lu) reading failed\n",
953 SB_AP_BITMAP(s)[i].bh->b_blocknr);
954 for (i = 0; i < SB_BMAP_NR(s); i++)
955 brelse(SB_AP_BITMAP(s)[i].bh);
956 vfree(SB_AP_BITMAP(s));
957 SB_AP_BITMAP(s) = NULL;
960 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
965 static int read_old_bitmaps (struct super_block * s)
968 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK(s);
969 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
971 /* read true bitmap */
972 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
973 if (SB_AP_BITMAP (s) == 0)
976 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
978 for (i = 0; i < sb_bmap_nr(rs); i ++) {
979 SB_AP_BITMAP (s)[i].bh = sb_bread (s, bmp1 + i);
980 if (!SB_AP_BITMAP (s)[i].bh)
982 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
988 void check_bitmap (struct super_block * s)
994 while (i < SB_BLOCK_COUNT (s)) {
995 buf = SB_AP_BITMAP (s)[i / (s->s_blocksize * 8)].bh->b_data;
996 if (!reiserfs_test_le_bit (i % (s->s_blocksize * 8), buf))
1001 if (free != SB_FREE_BLOCKS (s))
1002 reiserfs_warning ("vs-4000: check_bitmap: %d free blocks, must be %d\n",
1003 free, SB_FREE_BLOCKS (s));
1006 static int read_super_block (struct super_block * s, int offset)
1008 struct buffer_head * bh;
1009 struct reiserfs_super_block * rs;
1013 bh = sb_bread (s, offset / s->s_blocksize);
1015 printk ("sh-2006: read_super_block: "
1016 "bread failed (dev %s, block %lu, size %lu)\n",
1017 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1021 rs = (struct reiserfs_super_block *)bh->b_data;
1022 if (!is_any_reiserfs_magic_string (rs)) {
1028 // ok, reiserfs signature (old or new) found in at the given offset
1030 fs_blocksize = sb_blocksize(rs);
1032 sb_set_blocksize (s, fs_blocksize);
1034 bh = sb_bread (s, offset / s->s_blocksize);
1036 printk("sh-2007: read_super_block: "
1037 "bread failed (dev %s, block %lu, size %lu)\n",
1038 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1042 rs = (struct reiserfs_super_block *)bh->b_data;
1043 if (sb_blocksize(rs) != s->s_blocksize) {
1044 printk ("sh-2011: read_super_block: "
1045 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1046 reiserfs_bdevname (s), (unsigned long long)bh->b_blocknr, s->s_blocksize);
1051 if ( rs->s_v1.s_root_block == -1 ) {
1053 printk("dev %s: Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1054 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1055 "get newer reiserfsprogs package\n", reiserfs_bdevname (s));
1059 SB_BUFFER_WITH_SB (s) = bh;
1060 SB_DISK_SUPER_BLOCK (s) = rs;
1062 if (is_reiserfs_jr (rs)) {
1063 /* magic is of non-standard journal filesystem, look at s_version to
1064 find which format is in use */
1065 if (sb_version(rs) == REISERFS_VERSION_2)
1066 printk ("read_super_block: found reiserfs format \"3.6\" "
1067 "with non-standard journal\n");
1068 else if (sb_version(rs) == REISERFS_VERSION_1)
1069 printk ("read_super_block: found reiserfs format \"3.5\" "
1070 "with non-standard journal\n");
1072 printk ("sh-2012: read_super_block: found unknown format \"%u\" "
1073 "of reiserfs with non-standard magic\n", sb_version(rs));
1078 /* s_version of standard format may contain incorrect information,
1079 so we just look at the magic string */
1080 printk ("found reiserfs format \"%s\" with standard journal\n",
1081 is_reiserfs_3_5 (rs) ? "3.5" : "3.6");
1083 s->s_op = &reiserfs_sops;
1084 s->s_export_op = &reiserfs_export_ops;
1086 /* new format is limited by the 32 bit wide i_blocks field, want to
1087 ** be one full block below that.
1089 s->s_maxbytes = (512LL << 32) - s->s_blocksize ;
1095 /* after journal replay, reread all bitmap and super blocks */
1096 static int reread_meta_blocks(struct super_block *s) {
1098 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))) ;
1099 wait_on_buffer(SB_BUFFER_WITH_SB(s)) ;
1100 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1101 printk("reread_meta_blocks, error reading the super\n") ;
1105 for (i = 0; i < SB_BMAP_NR(s) ; i++) {
1106 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh)) ;
1107 wait_on_buffer(SB_AP_BITMAP(s)[i].bh) ;
1108 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1109 printk("reread_meta_blocks, error reading bitmap block number %d at %llu\n",
1110 i, (unsigned long long)SB_AP_BITMAP(s)[i].bh->b_blocknr) ;
1119 /////////////////////////////////////////////////////
1120 // hash detection stuff
1123 // if root directory is empty - we set default - Yura's - hash and
1125 // FIXME: we look for only one name in a directory. If tea and yura
1126 // bith have the same value - we ask user to send report to the
1128 __u32 find_hash_out (struct super_block * s)
1131 struct inode * inode;
1133 INITIALIZE_PATH (path);
1134 struct reiserfs_dir_entry de;
1135 __u32 hash = DEFAULT_HASH;
1137 inode = s->s_root->d_inode;
1139 do { // Some serious "goto"-hater was there ;)
1140 u32 teahash, r5hash, yurahash;
1142 make_cpu_key (&key, inode, ~0, TYPE_DIRENTRY, 3);
1143 retval = search_by_entry_key (s, &key, &path, &de);
1144 if (retval == IO_ERROR) {
1148 if (retval == NAME_NOT_FOUND)
1150 set_de_name_and_namelen (&de);
1151 if (deh_offset( &(de.de_deh[de.de_entry_num]) ) == DOT_DOT_OFFSET) {
1152 /* allow override in this case */
1153 if (reiserfs_rupasov_hash(s)) {
1156 reiserfs_warning("reiserfs: FS seems to be empty, autodetect "
1157 "is using the default hash\n");
1160 r5hash=GET_HASH_VALUE (r5_hash (de.de_name, de.de_namelen));
1161 teahash=GET_HASH_VALUE (keyed_hash (de.de_name, de.de_namelen));
1162 yurahash=GET_HASH_VALUE (yura_hash (de.de_name, de.de_namelen));
1163 if ( ( (teahash == r5hash) && (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) ) ||
1164 ( (teahash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ||
1165 ( (r5hash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ) {
1166 reiserfs_warning("reiserfs: Unable to automatically detect hash"
1167 "function for device %s\n"
1168 "please mount with -o hash={tea,rupasov,r5}\n", reiserfs_bdevname (s));
1172 if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == yurahash)
1174 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == teahash)
1176 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == r5hash)
1179 reiserfs_warning("reiserfs: Unrecognised hash function for "
1180 "device %s\n", reiserfs_bdevname (s));
1189 // finds out which hash names are sorted with
1190 static int what_hash (struct super_block * s)
1194 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1196 /* reiserfs_hash_detect() == true if any of the hash mount options
1197 ** were used. We must check them to make sure the user isn't
1198 ** using a bad hash value
1200 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1201 code = find_hash_out (s);
1203 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1204 /* detection has found the hash, and we must check against the
1207 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1208 printk("REISERFS: Error, %s hash detected, "
1209 "unable to force rupasov hash\n", reiserfs_hashname(code)) ;
1211 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1212 printk("REISERFS: Error, %s hash detected, "
1213 "unable to force tea hash\n", reiserfs_hashname(code)) ;
1215 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1216 printk("REISERFS: Error, %s hash detected, "
1217 "unable to force r5 hash\n", reiserfs_hashname(code)) ;
1221 /* find_hash_out was not called or could not determine the hash */
1222 if (reiserfs_rupasov_hash(s)) {
1224 } else if (reiserfs_tea_hash(s)) {
1226 } else if (reiserfs_r5_hash(s)) {
1231 /* if we are mounted RW, and we have a new valid hash code, update
1234 if (code != UNSET_HASH &&
1235 !(s->s_flags & MS_RDONLY) &&
1236 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1237 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1242 // return pointer to appropriate function
1243 static hashf_t hash_function (struct super_block * s)
1245 switch (what_hash (s)) {
1247 reiserfs_warning ("Using tea hash to sort names\n");
1250 reiserfs_warning ("Using rupasov hash to sort names\n");
1253 reiserfs_warning ("Using r5 hash to sort names\n");
1259 // this is used to set up correct value for old partitions
1260 int function2code (hashf_t func)
1262 if (func == keyed_hash)
1264 if (func == yura_hash)
1266 if (func == r5_hash)
1269 BUG() ; // should never happen
1274 #define SPRINTK(silent, ...) \
1278 static int reiserfs_fill_super (struct super_block * s, void * data, int silent)
1280 struct inode *root_inode;
1282 struct reiserfs_transaction_handle th ;
1284 unsigned long blocks;
1285 unsigned int commit_max_age = 0;
1286 int jinit_done = 0 ;
1287 struct reiserfs_iget_args args ;
1288 struct reiserfs_super_block * rs;
1290 struct reiserfs_sb_info *sbi;
1291 int errval = -EINVAL;
1293 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1299 memset (sbi, 0, sizeof (struct reiserfs_sb_info));
1300 /* Set default values for options: non-aggressive tails */
1301 REISERFS_SB(s)->s_mount_opt = ( 1 << REISERFS_SMALLTAIL );
1302 /* default block allocator option: skip_busy */
1303 REISERFS_SB(s)->s_alloc_options.bits = ( 1 << 5);
1304 /* If file grew past 4 blocks, start preallocation blocks for it. */
1305 REISERFS_SB(s)->s_alloc_options.preallocmin = 4;
1306 /* Preallocate by 16 blocks (17-1) at once */
1307 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1310 if (reiserfs_parse_options (s, (char *) data, &(sbi->s_mount_opt), &blocks, &jdev_name, &commit_max_age) == 0) {
1315 SPRINTK(silent, "jmacd-7: reiserfs_fill_super: resize option for remount only\n");
1319 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1320 if (!read_super_block (s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1322 /* try new format (64-th 1k block), which can contain reiserfs super block */
1323 else if (read_super_block (s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1324 SPRINTK(silent, "sh-2021: reiserfs_fill_super: can not find reiserfs on %s\n", reiserfs_bdevname (s));
1328 rs = SB_DISK_SUPER_BLOCK (s);
1329 /* Let's do basic sanity check to verify that underlying device is not
1330 smaller than the filesystem. If the check fails then abort and scream,
1331 because bad stuff will happen otherwise. */
1332 if ( s->s_bdev && s->s_bdev->bd_inode && i_size_read(s->s_bdev->bd_inode) < sb_block_count(rs)*sb_blocksize(rs)) {
1333 SPRINTK(silent, "Filesystem on %s cannot be mounted because it is bigger than the device\n", reiserfs_bdevname(s));
1334 SPRINTK(silent, "You may need to run fsck or increase size of your LVM partition\n");
1335 SPRINTK(silent, "Or may be you forgot to reboot after fdisk when it told you to\n");
1339 sbi->s_mount_state = SB_REISERFS_STATE(s);
1340 sbi->s_mount_state = REISERFS_VALID_FS ;
1342 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1343 SPRINTK(silent, "jmacd-8: reiserfs_fill_super: unable to read bitmap\n");
1346 #ifdef CONFIG_REISERFS_CHECK
1347 SPRINTK(silent, "reiserfs:warning: CONFIG_REISERFS_CHECK is set ON\n");
1348 SPRINTK(silent, "reiserfs:warning: - it is slow mode for debugging.\n");
1351 /* make data=ordered the default */
1352 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1353 !reiserfs_data_writeback(s))
1355 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1358 if (reiserfs_data_log(s)) {
1359 printk("reiserfs: using journaled data mode\n");
1360 } else if (reiserfs_data_ordered(s)) {
1361 printk("reiserfs: using ordered data mode\n");
1363 printk("reiserfs: using writeback data mode\n");
1366 // set_device_ro(s->s_dev, 1) ;
1367 if( journal_init(s, jdev_name, old_format, commit_max_age) ) {
1368 SPRINTK(silent, "sh-2022: reiserfs_fill_super: unable to initialize journal space\n") ;
1371 jinit_done = 1 ; /* once this is set, journal_release must be called
1372 ** if we error out of the mount
1375 if (reread_meta_blocks(s)) {
1376 SPRINTK(silent, "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init\n") ;
1380 if (replay_only (s))
1383 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1384 SPRINTK(silent, "clm-7000: Detected readonly device, marking FS readonly\n") ;
1385 s->s_flags |= MS_RDONLY ;
1387 args.objectid = REISERFS_ROOT_OBJECTID ;
1388 args.dirid = REISERFS_ROOT_PARENT_OBJECTID ;
1389 root_inode = iget5_locked (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
1391 SPRINTK(silent, "jmacd-10: reiserfs_fill_super: get root inode failed\n");
1395 if (root_inode->i_state & I_NEW) {
1396 reiserfs_read_locked_inode(root_inode, &args);
1397 unlock_new_inode(root_inode);
1400 s->s_root = d_alloc_root(root_inode);
1406 // define and initialize hash function
1407 sbi->s_hash_function = hash_function (s);
1408 if (sbi->s_hash_function == NULL) {
1414 if (is_reiserfs_3_5 (rs) || (is_reiserfs_jr (rs) && SB_VERSION (s) == REISERFS_VERSION_1))
1415 set_bit(REISERFS_3_5, &(sbi->s_properties));
1417 set_bit(REISERFS_3_6, &(sbi->s_properties));
1419 if (!(s->s_flags & MS_RDONLY)) {
1421 journal_begin(&th, s, 1) ;
1422 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
1424 set_sb_umount_state( rs, REISERFS_ERROR_FS );
1425 set_sb_fs_state (rs, 0);
1427 if (old_format_only(s)) {
1428 /* filesystem of format 3.5 either with standard or non-standard
1430 if (convert_reiserfs (s)) {
1431 /* and -o conv is given */
1433 reiserfs_warning ("reiserfs: converting 3.5 filesystem to the 3.6 format\n") ;
1435 if (is_reiserfs_3_5 (rs))
1436 /* put magic string of 3.6 format. 2.2 will not be able to
1437 mount this filesystem anymore */
1438 memcpy (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
1439 sizeof (reiserfs_3_6_magic_string));
1441 set_sb_version(rs,REISERFS_VERSION_2);
1442 reiserfs_convert_objectid_map_v1(s) ;
1443 set_bit(REISERFS_3_6, &(sbi->s_properties));
1444 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1445 } else if (!silent){
1446 reiserfs_warning("reiserfs: using 3.5.x disk format\n") ;
1450 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
1451 journal_end(&th, s, 1) ;
1453 /* look for files which were to be removed in previous session */
1454 finish_unfinished (s);
1456 if ( old_format_only(s) && !silent) {
1457 reiserfs_warning("reiserfs: using 3.5.x disk format\n") ;
1460 // mark hash in super block: it could be unset. overwrite should be ok
1461 set_sb_hash_function_code( rs, function2code(sbi->s_hash_function ) );
1465 reiserfs_proc_info_init( s );
1467 init_waitqueue_head (&(sbi->s_wait));
1468 sbi->bitmap_lock = SPIN_LOCK_UNLOCKED;
1473 if (jinit_done) { /* kill the commit thread, free journal ram */
1474 journal_release_error(NULL, s) ;
1476 if (SB_DISK_SUPER_BLOCK (s)) {
1477 for (j = 0; j < SB_BMAP_NR (s); j ++) {
1478 if (SB_AP_BITMAP (s))
1479 brelse (SB_AP_BITMAP (s)[j].bh);
1481 if (SB_AP_BITMAP (s))
1482 vfree (SB_AP_BITMAP (s));
1484 if (SB_BUFFER_WITH_SB (s))
1485 brelse(SB_BUFFER_WITH_SB (s));
1491 s->s_fs_info = NULL;
1496 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf)
1498 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
1500 buf->f_namelen = (REISERFS_MAX_NAME (s->s_blocksize));
1501 buf->f_bfree = sb_free_blocks(rs);
1502 buf->f_bavail = buf->f_bfree;
1503 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1504 buf->f_bsize = s->s_blocksize;
1505 /* changed to accommodate gcc folks.*/
1506 buf->f_type = REISERFS_SUPER_MAGIC;
1510 static struct super_block*
1511 get_super_block (struct file_system_type *fs_type, int flags,
1512 const char *dev_name, void *data)
1514 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
1518 init_reiserfs_fs ( void )
1522 if ((ret = init_inodecache ())) {
1526 reiserfs_proc_info_global_init ();
1527 reiserfs_proc_register_global ("version", reiserfs_global_version_in_proc);
1529 ret = register_filesystem (& reiserfs_fs_type);
1535 reiserfs_proc_unregister_global ("version");
1536 reiserfs_proc_info_global_done ();
1537 destroy_inodecache ();
1543 exit_reiserfs_fs ( void )
1545 reiserfs_proc_unregister_global ("version");
1546 reiserfs_proc_info_global_done ();
1547 unregister_filesystem (& reiserfs_fs_type);
1548 destroy_inodecache ();
1551 struct file_system_type reiserfs_fs_type = {
1552 .owner = THIS_MODULE,
1554 .get_sb = get_super_block,
1555 .kill_sb = kill_block_super,
1556 .fs_flags = FS_REQUIRES_DEV,
1559 MODULE_DESCRIPTION ("ReiserFS journaled filesystem");
1560 MODULE_AUTHOR ("Hans Reiser <reiser@namesys.com>");
1561 MODULE_LICENSE ("GPL");
1563 module_init (init_reiserfs_fs);
1564 module_exit (exit_reiserfs_fs);