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>
28 struct file_system_type reiserfs_fs_type;
30 const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
31 const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
32 const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
34 int is_reiserfs_3_5 (struct reiserfs_super_block * rs)
36 return !strncmp (rs->s_v1.s_magic, reiserfs_3_5_magic_string,
37 strlen (reiserfs_3_5_magic_string));
41 int is_reiserfs_3_6 (struct reiserfs_super_block * rs)
43 return !strncmp (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
44 strlen (reiserfs_3_6_magic_string));
48 int is_reiserfs_jr (struct reiserfs_super_block * rs)
50 return !strncmp (rs->s_v1.s_magic, reiserfs_jr_magic_string,
51 strlen (reiserfs_jr_magic_string));
55 static int is_any_reiserfs_magic_string (struct reiserfs_super_block * rs)
57 return (is_reiserfs_3_5 (rs) || is_reiserfs_3_6 (rs) ||
61 static int reiserfs_remount (struct super_block * s, int * flags, char * data);
62 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf);
64 static void reiserfs_sync_fs (struct super_block * s)
66 if (!(s->s_flags & MS_RDONLY)) {
67 struct reiserfs_transaction_handle th;
68 reiserfs_write_lock(s);
69 journal_begin(&th, s, 1);
70 journal_end_sync(&th, s, 1);
71 reiserfs_flush_old_commits(s);
73 reiserfs_write_unlock(s);
77 static void reiserfs_write_super(struct super_block *s)
82 static void reiserfs_write_super_lockfs (struct super_block * s)
84 struct reiserfs_transaction_handle th ;
85 reiserfs_write_lock(s);
86 if (!(s->s_flags & MS_RDONLY)) {
87 journal_begin(&th, s, 1) ;
88 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
89 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
90 reiserfs_block_writes(&th) ;
91 journal_end_sync(&th, s, 1) ;
94 reiserfs_write_unlock(s);
97 void reiserfs_unlockfs(struct super_block *s) {
98 reiserfs_allow_writes(s) ;
101 extern const struct key MAX_KEY;
104 /* this is used to delete "save link" when there are no items of a
105 file it points to. It can either happen if unlink is completed but
106 "save unlink" removal, or if file has both unlink and truncate
107 pending and as unlink completes first (because key of "save link"
108 protecting unlink is bigger that a key lf "save link" which
109 protects truncate), so there left no items to make truncate
111 static void remove_save_link_only (struct super_block * s, struct key * key, int oid_free)
113 struct reiserfs_transaction_handle th;
115 /* we are going to do one balancing */
116 journal_begin (&th, s, JOURNAL_PER_BALANCE_CNT);
118 reiserfs_delete_solid_item (&th, NULL, key);
120 /* removals are protected by direct items */
121 reiserfs_release_objectid (&th, le32_to_cpu (key->k_objectid));
123 journal_end (&th, s, JOURNAL_PER_BALANCE_CNT);
127 /* look for uncompleted unlinks and truncates and complete them */
128 static void finish_unfinished (struct super_block * s)
130 INITIALIZE_PATH (path);
131 struct cpu_key max_cpu_key, obj_key;
132 struct key save_link_key;
134 struct item_head * ih;
135 struct buffer_head * bh;
139 struct inode * inode;
143 /* compose key to look for "save" links */
144 max_cpu_key.version = KEY_FORMAT_3_5;
145 max_cpu_key.on_disk_key = MAX_KEY;
146 max_cpu_key.key_length = 3;
149 REISERFS_SB(s)->s_is_unlinked_ok = 1;
151 retval = search_item (s, &max_cpu_key, &path);
152 if (retval != ITEM_NOT_FOUND) {
153 reiserfs_warning (s, "vs-2140: finish_unfinished: search_by_key returned %d",
158 bh = get_last_bh (&path);
159 item_pos = get_item_pos (&path);
160 if (item_pos != B_NR_ITEMS (bh)) {
161 reiserfs_warning (s, "vs-2060: finish_unfinished: wrong position found");
165 ih = B_N_PITEM_HEAD (bh, item_pos);
167 if (le32_to_cpu (ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
168 /* there are no "save" links anymore */
171 save_link_key = ih->ih_key;
172 if (is_indirect_le_ih (ih))
177 /* reiserfs_iget needs k_dirid and k_objectid only */
178 item = B_I_PITEM (bh, ih);
179 obj_key.on_disk_key.k_dir_id = le32_to_cpu (*(__u32 *)item);
180 obj_key.on_disk_key.k_objectid = le32_to_cpu (ih->ih_key.k_objectid);
181 obj_key.on_disk_key.u.k_offset_v1.k_offset = 0;
182 obj_key.on_disk_key.u.k_offset_v1.k_uniqueness = 0;
186 inode = reiserfs_iget (s, &obj_key);
188 /* the unlink almost completed, it just did not manage to remove
189 "save" link and release objectid */
190 reiserfs_warning (s, "vs-2180: finish_unfinished: iget failed for %K",
192 remove_save_link_only (s, &save_link_key, 1);
196 if (!truncate && inode->i_nlink) {
197 /* file is not unlinked */
198 reiserfs_warning (s, "vs-2185: finish_unfinished: file %K is not unlinked",
200 remove_save_link_only (s, &save_link_key, 0);
204 if (truncate && S_ISDIR (inode->i_mode) ) {
205 /* We got a truncate request for a dir which is impossible.
206 The only imaginable way is to execute unfinished truncate request
207 then boot into old kernel, remove the file and create dir with
209 reiserfs_warning(s, "green-2101: impossible truncate on a directory %k. Please report", INODE_PKEY (inode));
210 remove_save_link_only (s, &save_link_key, 0);
217 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
218 /* not completed truncate found. New size was committed together
220 reiserfs_info (s, "Truncating %k to %Ld ..",
221 INODE_PKEY (inode), inode->i_size);
222 reiserfs_truncate_file (inode, 0/*don't update modification time*/);
223 remove_save_link (inode, truncate);
225 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
226 /* not completed unlink (rmdir) found */
227 reiserfs_info (s, "Removing %k..", INODE_PKEY (inode));
228 /* removal gets completed in iput */
235 REISERFS_SB(s)->s_is_unlinked_ok = 0;
239 reiserfs_info (s, "There were %d uncompleted unlinks/truncates. "
240 "Completed\n", done);
243 /* to protect file being unlinked from getting lost we "safe" link files
244 being unlinked. This link will be deleted in the same transaction with last
245 item of file. mounting the filesytem we scan all these links and remove
246 files which almost got lost */
247 void add_save_link (struct reiserfs_transaction_handle * th,
248 struct inode * inode, int truncate)
250 INITIALIZE_PATH (path);
256 /* file can only get one "save link" of each kind */
258 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ),
259 "saved link already exists for truncated inode %lx",
260 ( long ) inode -> i_ino );
262 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ),
263 "saved link already exists for unlinked inode %lx",
264 ( long ) inode -> i_ino );
266 /* setup key of "save" link */
267 key.version = KEY_FORMAT_3_5;
268 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
269 key.on_disk_key.k_objectid = inode->i_ino;
271 /* unlink, rmdir, rename */
272 set_cpu_key_k_offset (&key, 1 + inode->i_sb->s_blocksize);
273 set_cpu_key_k_type (&key, TYPE_DIRECT);
275 /* item head of "safe" link */
276 make_le_item_head (&ih, &key, key.version, 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
277 4/*length*/, 0xffff/*free space*/);
280 if (S_ISDIR (inode->i_mode))
281 reiserfs_warning(inode->i_sb, "green-2102: Adding a truncate savelink for a directory %k! Please report", INODE_PKEY(inode));
282 set_cpu_key_k_offset (&key, 1);
283 set_cpu_key_k_type (&key, TYPE_INDIRECT);
285 /* item head of "safe" link */
286 make_le_item_head (&ih, &key, key.version, 1, TYPE_INDIRECT,
287 4/*length*/, 0/*free space*/);
291 /* look for its place in the tree */
292 retval = search_item (inode->i_sb, &key, &path);
293 if (retval != ITEM_NOT_FOUND) {
294 if ( retval != -ENOSPC )
295 reiserfs_warning (inode->i_sb, "vs-2100: add_save_link:"
296 "search_by_key (%K) returned %d", &key, retval);
301 /* body of "save" link */
302 link = INODE_PKEY (inode)->k_dir_id;
304 /* put "save" link inot tree, don't charge quota to anyone */
305 retval = reiserfs_insert_item (th, &path, &key, &ih, NULL, (char *)&link);
307 if (retval != -ENOSPC)
308 reiserfs_warning (inode->i_sb, "vs-2120: add_save_link: insert_item returned %d",
312 REISERFS_I(inode) -> i_flags |= i_link_saved_truncate_mask;
314 REISERFS_I(inode) -> i_flags |= i_link_saved_unlink_mask;
319 /* this opens transaction unlike add_save_link */
320 void remove_save_link (struct inode * inode, int truncate)
322 struct reiserfs_transaction_handle th;
326 /* we are going to do one balancing only */
327 journal_begin (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
329 /* setup key of "save" link */
330 key.k_dir_id = cpu_to_le32 (MAX_KEY_OBJECTID);
331 key.k_objectid = INODE_PKEY (inode)->k_objectid;
333 /* unlink, rmdir, rename */
334 set_le_key_k_offset (KEY_FORMAT_3_5, &key,
335 1 + inode->i_sb->s_blocksize);
336 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_DIRECT);
339 set_le_key_k_offset (KEY_FORMAT_3_5, &key, 1);
340 set_le_key_k_type (KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
344 ( REISERFS_I(inode) -> i_flags & i_link_saved_truncate_mask ) ) ||
346 ( REISERFS_I(inode) -> i_flags & i_link_saved_unlink_mask ) ) )
347 /* don't take quota bytes from anywhere */
348 reiserfs_delete_solid_item (&th, NULL, &key);
350 reiserfs_release_objectid (&th, inode->i_ino);
351 REISERFS_I(inode) -> i_flags &= ~i_link_saved_unlink_mask;
353 REISERFS_I(inode) -> i_flags &= ~i_link_saved_truncate_mask;
355 journal_end (&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
359 static void reiserfs_put_super (struct super_block * s)
362 struct reiserfs_transaction_handle th ;
364 if (REISERFS_SB(s)->xattr_root) {
365 d_invalidate (REISERFS_SB(s)->xattr_root);
366 dput (REISERFS_SB(s)->xattr_root);
369 if (REISERFS_SB(s)->priv_root) {
370 d_invalidate (REISERFS_SB(s)->priv_root);
371 dput (REISERFS_SB(s)->priv_root);
374 /* change file system state to current state if it was mounted with read-write permissions */
375 if (!(s->s_flags & MS_RDONLY)) {
376 journal_begin(&th, s, 10) ;
377 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
378 set_sb_umount_state( SB_DISK_SUPER_BLOCK(s), REISERFS_SB(s)->s_mount_state );
379 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
382 /* note, journal_release checks for readonly mount, and can decide not
383 ** to do a journal_end
385 journal_release(&th, s) ;
387 for (i = 0; i < SB_BMAP_NR (s); i ++)
388 brelse (SB_AP_BITMAP (s)[i].bh);
390 vfree (SB_AP_BITMAP (s));
392 brelse (SB_BUFFER_WITH_SB (s));
394 print_statistics (s);
396 if (REISERFS_SB(s)->s_kmallocs != 0) {
397 reiserfs_warning (s, "vs-2004: reiserfs_put_super: allocated memory left %d",
398 REISERFS_SB(s)->s_kmallocs);
401 if (REISERFS_SB(s)->reserved_blocks != 0) {
402 reiserfs_warning (s, "green-2005: reiserfs_put_super: reserved blocks left %d",
403 REISERFS_SB(s)->reserved_blocks);
406 reiserfs_proc_info_done( s );
414 static kmem_cache_t * reiserfs_inode_cachep;
416 static struct inode *reiserfs_alloc_inode(struct super_block *sb)
418 struct reiserfs_inode_info *ei;
419 ei = (struct reiserfs_inode_info *)kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
422 return &ei->vfs_inode;
425 static void reiserfs_destroy_inode(struct inode *inode)
427 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
430 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
432 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *) foo;
434 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
435 SLAB_CTOR_CONSTRUCTOR) {
436 INIT_LIST_HEAD(&ei->i_prealloc_list) ;
437 inode_init_once(&ei->vfs_inode);
438 ei->i_acl_access = NULL;
439 ei->i_acl_default = NULL;
443 static int init_inodecache(void)
445 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
446 sizeof(struct reiserfs_inode_info),
447 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
449 if (reiserfs_inode_cachep == NULL)
454 static void destroy_inodecache(void)
456 if (kmem_cache_destroy(reiserfs_inode_cachep))
457 reiserfs_warning (NULL, "reiserfs_inode_cache: not all structures were freed");
460 /* we don't mark inodes dirty, we just log them */
461 static void reiserfs_dirty_inode (struct inode * inode) {
462 struct reiserfs_transaction_handle th ;
464 if (inode->i_sb->s_flags & MS_RDONLY) {
465 reiserfs_warning(inode->i_sb, "clm-6006: writing inode %lu on readonly FS",
469 reiserfs_write_lock(inode->i_sb);
471 /* this is really only used for atime updates, so they don't have
472 ** to be included in O_SYNC or fsync
474 journal_begin(&th, inode->i_sb, 1) ;
475 reiserfs_update_sd (&th, inode);
476 journal_end(&th, inode->i_sb, 1) ;
477 reiserfs_write_unlock(inode->i_sb);
480 static void reiserfs_clear_inode (struct inode *inode)
482 struct posix_acl *acl;
484 acl = REISERFS_I(inode)->i_acl_access;
485 if (acl && !IS_ERR (acl))
486 posix_acl_release (acl);
487 REISERFS_I(inode)->i_acl_access = NULL;
489 acl = REISERFS_I(inode)->i_acl_default;
490 if (acl && !IS_ERR (acl))
491 posix_acl_release (acl);
492 REISERFS_I(inode)->i_acl_default = NULL;
495 struct super_operations reiserfs_sops =
497 .alloc_inode = reiserfs_alloc_inode,
498 .destroy_inode = reiserfs_destroy_inode,
499 .write_inode = reiserfs_write_inode,
500 .dirty_inode = reiserfs_dirty_inode,
501 .delete_inode = reiserfs_delete_inode,
502 .clear_inode = reiserfs_clear_inode,
503 .put_super = reiserfs_put_super,
504 .write_super = reiserfs_write_super,
505 .write_super_lockfs = reiserfs_write_super_lockfs,
506 .unlockfs = reiserfs_unlockfs,
507 .statfs = reiserfs_statfs,
508 .remount_fs = reiserfs_remount,
512 static struct export_operations reiserfs_export_ops = {
513 .encode_fh = reiserfs_encode_fh,
514 .decode_fh = reiserfs_decode_fh,
515 .get_parent = reiserfs_get_parent,
516 .get_dentry = reiserfs_get_dentry,
519 /* this struct is used in reiserfs_getopt () for containing the value for those
520 mount options that have values rather than being toggles. */
523 int setmask; /* bitmask which is to set on mount_options bitmask when this
524 value is found, 0 is no bits are to be changed. */
525 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
526 value is found, 0 is no bits are to be changed. This is
527 applied BEFORE setmask */
531 /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
535 int arg_required; /* 0 if argument is not required, not 0 otherwise */
536 const arg_desc_t * values; /* list of values accepted by an option */
537 int setmask; /* bitmask which is to set on mount_options bitmask when this
538 value is found, 0 is no bits are to be changed. */
539 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
540 value is found, 0 is no bits are to be changed. This is
541 applied BEFORE setmask */
544 /* possible values for -o data= */
545 static const arg_desc_t logging_mode[] = {
546 {"ordered", 1<<REISERFS_DATA_ORDERED, (1<<REISERFS_DATA_LOG|1<<REISERFS_DATA_WRITEBACK)},
547 {"journal", 1<<REISERFS_DATA_LOG, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_WRITEBACK)},
548 {"writeback", 1<<REISERFS_DATA_WRITEBACK, (1<<REISERFS_DATA_ORDERED|1<<REISERFS_DATA_LOG)},
552 /* possible values for "-o block-allocator=" and bits which are to be set in
553 s_mount_opt of reiserfs specific part of in-core super block */
554 static const arg_desc_t balloc[] = {
555 {"noborder", 1<<REISERFS_NO_BORDER, 0},
556 {"border", 0, 1<<REISERFS_NO_BORDER},
557 {"no_unhashed_relocation", 1<<REISERFS_NO_UNHASHED_RELOCATION, 0},
558 {"hashed_relocation", 1<<REISERFS_HASHED_RELOCATION, 0},
559 {"test4", 1<<REISERFS_TEST4, 0},
560 {"notest4", 0, 1<<REISERFS_TEST4},
564 static const arg_desc_t tails[] = {
565 {"on", 1<<REISERFS_LARGETAIL, 1<<REISERFS_SMALLTAIL},
566 {"off", 0, (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
567 {"small", 1<<REISERFS_SMALLTAIL, 1<<REISERFS_LARGETAIL},
571 int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k.
572 There might be broken applications that are
573 confused by this. Use nolargeio mount option
574 to get usual i/o size = PAGE_SIZE.
577 /* proceed only one option from a list *cur - string containing of mount options
578 opts - array of options which are accepted
579 opt_arg - if option is found and requires an argument and if it is specifed
580 in the input - pointer to the argument is stored here
581 bit_flags - if option requires to set a certain bit - it is set here
582 return -1 if unknown option is found, opt->arg_required otherwise */
583 static int reiserfs_getopt ( struct super_block * s, char ** cur, opt_desc_t * opts, char ** opt_arg,
584 unsigned long * bit_flags)
593 const opt_desc_t * opt;
594 const arg_desc_t * arg;
599 /* assume argument cannot contain commas */
600 *cur = strchr (p, ',');
606 if ( !strncmp (p, "alloc=", 6) ) {
607 /* Ugly special case, probably we should redo options parser so that
608 it can understand several arguments for some options, also so that
609 it can fill several bitfields with option values. */
610 if ( reiserfs_parse_alloc_options( s, p + 6) ) {
618 /* for every option in the list */
619 for (opt = opts; opt->option_name; opt ++) {
620 if (!strncmp (p, opt->option_name, strlen (opt->option_name))) {
622 *bit_flags &= ~opt->clrmask;
623 *bit_flags |= opt->setmask;
628 if (!opt->option_name) {
629 reiserfs_warning (s, "unknown mount option \"%s\"", p);
633 p += strlen (opt->option_name);
636 if (!opt->arg_required) {
637 reiserfs_warning (s, "the option \"%s\" does not require an argument",
644 if (opt->arg_required) {
645 reiserfs_warning (s, "the option \"%s\" requires an argument", opt->option_name);
650 reiserfs_warning (s, "head of option \"%s\" is only correct", opt->option_name);
654 /* move to the argument, or to next option if argument is not required */
657 if ( opt->arg_required && !strlen (p) ) {
658 /* this catches "option=," */
659 reiserfs_warning (s, "empty argument for \"%s\"", opt->option_name);
664 /* *=NULLopt_arg contains pointer to argument */
666 return opt->arg_required;
669 /* values possible for this option are listed in opt->values */
670 for (arg = opt->values; arg->value; arg ++) {
671 if (!strcmp (p, arg->value)) {
673 *bit_flags &= ~arg->clrmask;
674 *bit_flags |= arg->setmask;
676 return opt->arg_required;
680 reiserfs_warning (s, "bad value \"%s\" for option \"%s\"", p, opt->option_name);
684 /* returns 0 if something is wrong in option string, 1 - otherwise */
685 static int reiserfs_parse_options (struct super_block * s, char * options, /* string given via mount's -o */
686 unsigned long * mount_options,
687 /* after the parsing phase, contains the
688 collection of bitflags defining what
689 mount options were selected. */
690 unsigned long * blocks, /* strtol-ed from NNN of resize=NNN */
692 unsigned int * commit_max_age)
697 opt_desc_t opts[] = {
698 /* Compatibility stuff, so that -o notail for old setups still work */
699 {"tails", .arg_required = 't', .values = tails},
700 {"notail", .clrmask = (1<<REISERFS_LARGETAIL)|(1<<REISERFS_SMALLTAIL)},
701 {"conv", .setmask = 1<<REISERFS_CONVERT},
702 {"attrs", .setmask = 1<<REISERFS_ATTRS},
703 {"noattrs", .clrmask = 1<<REISERFS_ATTRS},
704 {"user_xattr", .setmask = 1<<REISERFS_XATTRS_USER},
705 {"nouser_xattr",.clrmask = 1<<REISERFS_XATTRS_USER},
706 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
707 {"acl", .setmask = 1<<REISERFS_POSIXACL},
708 {"noacl", .clrmask = 1<<REISERFS_POSIXACL},
710 {"nolog",}, /* This is unsupported */
711 {"replayonly", .setmask = 1<<REPLAYONLY},
712 {"block-allocator", .arg_required = 'a', .values = balloc},
713 {"data", .arg_required = 'd', .values = logging_mode},
714 {"resize", .arg_required = 'r', .values = NULL},
715 {"jdev", .arg_required = 'j', .values = NULL},
716 {"nolargeio", .arg_required = 'w', .values = NULL},
717 {"commit", .arg_required = 'c', .values = NULL},
724 if (!options || !*options)
725 /* use default configuration: create tails, journaling on, no
726 conversion to newest format */
729 for (pos = options; pos; ) {
730 c = reiserfs_getopt (s, &pos, opts, &arg, mount_options);
732 /* wrong option is given */
740 *blocks = simple_strtoul (arg, &p, 0);
742 /* NNN does not look like a number */
743 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg);
750 unsigned long val = simple_strtoul (arg, &p, 0);
751 /* commit=NNN (time in seconds) */
752 if ( *p != '\0' || val >= (unsigned int)-1) {
753 reiserfs_warning (s, "reiserfs_parse_options: bad value %s", arg); return 0;
755 *commit_max_age = (unsigned int)val;
760 int val = simple_strtoul (arg, &p, 0);
763 reiserfs_warning (s, "reiserfs_parse_options: non-numeric value %s for nolargeio option", arg);
767 reiserfs_default_io_size = PAGE_SIZE;
769 reiserfs_default_io_size = 128 * 1024;
773 if (arg && *arg && jdev_name) {
774 if ( *jdev_name ) { //Hm, already assigned?
775 reiserfs_warning (s, "reiserfs_parse_options: journal device was already specified to be %s", *jdev_name);
786 static void switch_data_mode(struct super_block *s, unsigned long mode) {
787 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
788 (1 << REISERFS_DATA_ORDERED) |
789 (1 << REISERFS_DATA_WRITEBACK));
790 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
793 static void handle_data_mode(struct super_block *s, unsigned long mount_options)
795 if (mount_options & (1 << REISERFS_DATA_LOG)) {
796 if (!reiserfs_data_log(s)) {
797 switch_data_mode(s, REISERFS_DATA_LOG);
798 reiserfs_info (s, "switching to journaled data mode\n");
800 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
801 if (!reiserfs_data_ordered(s)) {
802 switch_data_mode(s, REISERFS_DATA_ORDERED);
803 reiserfs_info (s, "switching to ordered data mode\n");
805 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
806 if (!reiserfs_data_writeback(s)) {
807 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
808 reiserfs_info (s, "switching to writeback data mode\n");
813 static void handle_attrs( struct super_block *s )
815 struct reiserfs_super_block * rs;
817 if( reiserfs_attrs( s ) ) {
818 rs = SB_DISK_SUPER_BLOCK (s);
819 if( old_format_only(s) ) {
820 reiserfs_warning(s, "reiserfs: cannot support attributes on 3.5.x disk format" );
821 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
824 if( !( le32_to_cpu( rs -> s_flags ) & reiserfs_attrs_cleared ) ) {
825 reiserfs_warning(s, "reiserfs: cannot support attributes until flag is set in super-block" );
826 REISERFS_SB(s) -> s_mount_opt &= ~ ( 1 << REISERFS_ATTRS );
831 static int reiserfs_remount (struct super_block * s, int * mount_flags, char * arg)
833 struct reiserfs_super_block * rs;
834 struct reiserfs_transaction_handle th ;
835 unsigned long blocks;
836 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
837 unsigned long safe_mask = 0;
838 unsigned int commit_max_age = (unsigned int)-1;
840 rs = SB_DISK_SUPER_BLOCK (s);
842 if (!reiserfs_parse_options(s, arg, &mount_options, &blocks, NULL, &commit_max_age))
847 /* Add options that are safe here */
848 safe_mask |= 1 << REISERFS_SMALLTAIL;
849 safe_mask |= 1 << REISERFS_LARGETAIL;
850 safe_mask |= 1 << REISERFS_NO_BORDER;
851 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
852 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
853 safe_mask |= 1 << REISERFS_TEST4;
854 safe_mask |= 1 << REISERFS_ATTRS;
855 safe_mask |= 1 << REISERFS_XATTRS_USER;
856 safe_mask |= 1 << REISERFS_POSIXACL;
858 /* Update the bitmask, taking care to keep
859 * the bits we're not allowed to change here */
860 REISERFS_SB(s)->s_mount_opt = (REISERFS_SB(s)->s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
862 if(commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
863 SB_JOURNAL_MAX_COMMIT_AGE(s) = commit_max_age;
864 SB_JOURNAL_MAX_TRANS_AGE(s) = commit_max_age;
866 else if(commit_max_age == 0)
868 /* 0 means restore defaults. */
869 SB_JOURNAL_MAX_COMMIT_AGE(s) = SB_JOURNAL_DEFAULT_MAX_COMMIT_AGE(s);
870 SB_JOURNAL_MAX_TRANS_AGE(s) = JOURNAL_MAX_TRANS_AGE;
874 int rc = reiserfs_resize(s, blocks);
879 if (*mount_flags & MS_RDONLY) {
880 reiserfs_xattr_init (s, *mount_flags);
881 /* remount read-only */
882 if (s->s_flags & MS_RDONLY)
883 /* it is read-only already */
885 /* try to remount file system with read-only permissions */
886 if (sb_umount_state(rs) == REISERFS_VALID_FS || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
890 journal_begin(&th, s, 10) ;
891 /* Mounting a rw partition read-only. */
892 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
893 set_sb_umount_state( rs, REISERFS_SB(s)->s_mount_state );
894 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
896 /* remount read-write */
897 if (!(s->s_flags & MS_RDONLY)) {
898 reiserfs_xattr_init (s, *mount_flags);
899 return 0; /* We are read-write already */
902 handle_data_mode(s, mount_options);
903 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs) ;
904 s->s_flags &= ~MS_RDONLY ; /* now it is safe to call journal_begin */
905 journal_begin(&th, s, 10) ;
907 /* Mount a partition which is read-only, read-write */
908 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
909 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
910 s->s_flags &= ~MS_RDONLY;
911 set_sb_umount_state( rs, REISERFS_ERROR_FS );
912 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
913 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
914 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS ;
916 /* this will force a full flush of all journal lists */
917 SB_JOURNAL(s)->j_must_wait = 1 ;
918 journal_end(&th, s, 10) ;
921 if (!( *mount_flags & MS_RDONLY ) ) {
922 finish_unfinished( s );
923 reiserfs_xattr_init (s, *mount_flags);
929 /* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
930 * @sb - superblock for this filesystem
931 * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
933 * This routine counts how many free bits there are, finding the first zero
934 * as a side effect. Could also be implemented as a loop of test_bit() calls, or
935 * a loop of find_first_zero_bit() calls. This implementation is similar to
936 * find_first_zero_bit(), but doesn't return after it finds the first bit.
937 * Should only be called on fs mount, but should be fairly efficient anyways.
939 * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
940 * will * invariably occupt block 0 represented in the bitmap. The only
941 * exception to this is when free_count also == 0, since there will be no
942 * free blocks at all.
945 static void load_bitmap_info_data (struct super_block *sb,
946 struct reiserfs_bitmap_info *bi)
948 unsigned long *cur = (unsigned long *)bi->bh->b_data;
950 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
952 /* No need to scan if all 0's or all 1's.
953 * Since we're only counting 0's, we can simply ignore all 1's */
955 if (bi->first_zero_hint == 0) {
956 bi->first_zero_hint = ((char *)cur - bi->bh->b_data) << 3;
958 bi->free_count += sizeof(unsigned long)*8;
959 } else if (*cur != ~0L) {
961 for (b = 0; b < sizeof(unsigned long)*8; b++) {
962 if (!reiserfs_test_le_bit (b, cur)) {
964 if (bi->first_zero_hint == 0)
965 bi->first_zero_hint =
966 (((char *)cur - bi->bh->b_data) << 3) + b;
973 #ifdef CONFIG_REISERFS_CHECK
974 // This outputs a lot of unneded info on big FSes
975 // reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
976 // bi->bh->b_blocknr, bi->free_count);
980 static int read_bitmaps (struct super_block * s)
984 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
985 if (SB_AP_BITMAP (s) == 0)
987 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
988 for (i = 0, bmap_nr = REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
989 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
990 SB_AP_BITMAP (s)[i].bh = sb_getblk(s, bmap_nr);
991 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
992 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
994 for (i = 0; i < SB_BMAP_NR(s); i++) {
995 wait_on_buffer(SB_AP_BITMAP (s)[i].bh);
996 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
997 reiserfs_warning(s,"sh-2029: reiserfs read_bitmaps: "
998 "bitmap block (#%lu) reading failed",
999 SB_AP_BITMAP(s)[i].bh->b_blocknr);
1000 for (i = 0; i < SB_BMAP_NR(s); i++)
1001 brelse(SB_AP_BITMAP(s)[i].bh);
1002 vfree(SB_AP_BITMAP(s));
1003 SB_AP_BITMAP(s) = NULL;
1006 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
1011 static int read_old_bitmaps (struct super_block * s)
1014 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK(s);
1015 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
1017 /* read true bitmap */
1018 SB_AP_BITMAP (s) = vmalloc (sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1019 if (SB_AP_BITMAP (s) == 0)
1022 memset (SB_AP_BITMAP (s), 0, sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1024 for (i = 0; i < sb_bmap_nr(rs); i ++) {
1025 SB_AP_BITMAP (s)[i].bh = sb_bread (s, bmp1 + i);
1026 if (!SB_AP_BITMAP (s)[i].bh)
1028 load_bitmap_info_data (s, SB_AP_BITMAP (s) + i);
1034 void check_bitmap (struct super_block * s)
1040 while (i < SB_BLOCK_COUNT (s)) {
1041 buf = SB_AP_BITMAP (s)[i / (s->s_blocksize * 8)].bh->b_data;
1042 if (!reiserfs_test_le_bit (i % (s->s_blocksize * 8), buf))
1047 if (free != SB_FREE_BLOCKS (s))
1048 reiserfs_warning (s,"vs-4000: check_bitmap: %d free blocks, must be %d",
1049 free, SB_FREE_BLOCKS (s));
1052 static int read_super_block (struct super_block * s, int offset)
1054 struct buffer_head * bh;
1055 struct reiserfs_super_block * rs;
1059 bh = sb_bread (s, offset / s->s_blocksize);
1061 reiserfs_warning (s, "sh-2006: read_super_block: "
1062 "bread failed (dev %s, block %lu, size %lu)",
1063 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1067 rs = (struct reiserfs_super_block *)bh->b_data;
1068 if (!is_any_reiserfs_magic_string (rs)) {
1074 // ok, reiserfs signature (old or new) found in at the given offset
1076 fs_blocksize = sb_blocksize(rs);
1078 sb_set_blocksize (s, fs_blocksize);
1080 bh = sb_bread (s, offset / s->s_blocksize);
1082 reiserfs_warning (s, "sh-2007: read_super_block: "
1083 "bread failed (dev %s, block %lu, size %lu)\n",
1084 reiserfs_bdevname (s), offset / s->s_blocksize, s->s_blocksize);
1088 rs = (struct reiserfs_super_block *)bh->b_data;
1089 if (sb_blocksize(rs) != s->s_blocksize) {
1090 reiserfs_warning (s, "sh-2011: read_super_block: "
1091 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1092 reiserfs_bdevname (s), (unsigned long long)bh->b_blocknr, s->s_blocksize);
1097 if ( rs->s_v1.s_root_block == -1 ) {
1099 reiserfs_warning (s, "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1100 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1101 "get newer reiserfsprogs package");
1105 SB_BUFFER_WITH_SB (s) = bh;
1106 SB_DISK_SUPER_BLOCK (s) = rs;
1108 if (is_reiserfs_jr (rs)) {
1109 /* magic is of non-standard journal filesystem, look at s_version to
1110 find which format is in use */
1111 if (sb_version(rs) == REISERFS_VERSION_2)
1112 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.6\""
1113 " with non-standard journal");
1114 else if (sb_version(rs) == REISERFS_VERSION_1)
1115 reiserfs_warning (s, "read_super_block: found reiserfs format \"3.5\""
1116 " with non-standard journal");
1118 reiserfs_warning (s, "sh-2012: read_super_block: found unknown "
1119 "format \"%u\" of reiserfs with non-standard magic",
1125 /* s_version of standard format may contain incorrect information,
1126 so we just look at the magic string */
1127 reiserfs_info (s, "found reiserfs format \"%s\" with standard journal\n",
1128 is_reiserfs_3_5 (rs) ? "3.5" : "3.6");
1130 s->s_op = &reiserfs_sops;
1131 s->s_export_op = &reiserfs_export_ops;
1133 /* new format is limited by the 32 bit wide i_blocks field, want to
1134 ** be one full block below that.
1136 s->s_maxbytes = (512LL << 32) - s->s_blocksize ;
1142 /* after journal replay, reread all bitmap and super blocks */
1143 static int reread_meta_blocks(struct super_block *s) {
1145 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))) ;
1146 wait_on_buffer(SB_BUFFER_WITH_SB(s)) ;
1147 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1148 reiserfs_warning (s, "reread_meta_blocks, error reading the super") ;
1152 for (i = 0; i < SB_BMAP_NR(s) ; i++) {
1153 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh)) ;
1154 wait_on_buffer(SB_AP_BITMAP(s)[i].bh) ;
1155 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1156 reiserfs_warning (s, "reread_meta_blocks, error reading bitmap block number %d at %llu",
1157 i, (unsigned long long)SB_AP_BITMAP(s)[i].bh->b_blocknr) ;
1166 /////////////////////////////////////////////////////
1167 // hash detection stuff
1170 // if root directory is empty - we set default - Yura's - hash and
1172 // FIXME: we look for only one name in a directory. If tea and yura
1173 // bith have the same value - we ask user to send report to the
1175 __u32 find_hash_out (struct super_block * s)
1178 struct inode * inode;
1180 INITIALIZE_PATH (path);
1181 struct reiserfs_dir_entry de;
1182 __u32 hash = DEFAULT_HASH;
1184 inode = s->s_root->d_inode;
1186 do { // Some serious "goto"-hater was there ;)
1187 u32 teahash, r5hash, yurahash;
1189 make_cpu_key (&key, inode, ~0, TYPE_DIRENTRY, 3);
1190 retval = search_by_entry_key (s, &key, &path, &de);
1191 if (retval == IO_ERROR) {
1195 if (retval == NAME_NOT_FOUND)
1197 set_de_name_and_namelen (&de);
1198 if (deh_offset( &(de.de_deh[de.de_entry_num]) ) == DOT_DOT_OFFSET) {
1199 /* allow override in this case */
1200 if (reiserfs_rupasov_hash(s)) {
1203 reiserfs_warning(s,"FS seems to be empty, autodetect "
1204 "is using the default hash");
1207 r5hash=GET_HASH_VALUE (r5_hash (de.de_name, de.de_namelen));
1208 teahash=GET_HASH_VALUE (keyed_hash (de.de_name, de.de_namelen));
1209 yurahash=GET_HASH_VALUE (yura_hash (de.de_name, de.de_namelen));
1210 if ( ( (teahash == r5hash) && (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) ) ||
1211 ( (teahash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ||
1212 ( (r5hash == yurahash) && (yurahash == GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])))) ) ) {
1213 reiserfs_warning(s,"Unable to automatically detect hash function. "
1214 "Please mount with -o hash={tea,rupasov,r5}",
1215 reiserfs_bdevname (s));
1219 if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == yurahash)
1221 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == teahash)
1223 else if (GET_HASH_VALUE( deh_offset(&(de.de_deh[de.de_entry_num])) ) == r5hash)
1226 reiserfs_warning (s,"Unrecognised hash function");
1235 // finds out which hash names are sorted with
1236 static int what_hash (struct super_block * s)
1240 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1242 /* reiserfs_hash_detect() == true if any of the hash mount options
1243 ** were used. We must check them to make sure the user isn't
1244 ** using a bad hash value
1246 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1247 code = find_hash_out (s);
1249 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1250 /* detection has found the hash, and we must check against the
1253 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1254 reiserfs_warning (s, "Error, %s hash detected, "
1255 "unable to force rupasov hash", reiserfs_hashname(code)) ;
1257 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1258 reiserfs_warning (s, "Error, %s hash detected, "
1259 "unable to force tea hash", reiserfs_hashname(code)) ;
1261 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1262 reiserfs_warning (s, "Error, %s hash detected, "
1263 "unable to force r5 hash", reiserfs_hashname(code)) ;
1267 /* find_hash_out was not called or could not determine the hash */
1268 if (reiserfs_rupasov_hash(s)) {
1270 } else if (reiserfs_tea_hash(s)) {
1272 } else if (reiserfs_r5_hash(s)) {
1277 /* if we are mounted RW, and we have a new valid hash code, update
1280 if (code != UNSET_HASH &&
1281 !(s->s_flags & MS_RDONLY) &&
1282 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1283 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1288 // return pointer to appropriate function
1289 static hashf_t hash_function (struct super_block * s)
1291 switch (what_hash (s)) {
1293 reiserfs_info (s, "Using tea hash to sort names\n");
1296 reiserfs_info (s, "Using rupasov hash to sort names\n");
1299 reiserfs_info (s, "Using r5 hash to sort names\n");
1305 // this is used to set up correct value for old partitions
1306 int function2code (hashf_t func)
1308 if (func == keyed_hash)
1310 if (func == yura_hash)
1312 if (func == r5_hash)
1315 BUG() ; // should never happen
1320 #define SWARN(silent, s, ...) \
1322 reiserfs_warning (s, __VA_ARGS__)
1324 static int reiserfs_fill_super (struct super_block * s, void * data, int silent)
1326 struct inode *root_inode;
1328 struct reiserfs_transaction_handle th ;
1330 unsigned long blocks;
1331 unsigned int commit_max_age = 0;
1332 int jinit_done = 0 ;
1333 struct reiserfs_iget_args args ;
1334 struct reiserfs_super_block * rs;
1336 struct reiserfs_sb_info *sbi;
1337 int errval = -EINVAL;
1339 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1345 memset (sbi, 0, sizeof (struct reiserfs_sb_info));
1346 /* Set default values for options: non-aggressive tails */
1347 REISERFS_SB(s)->s_mount_opt = ( 1 << REISERFS_SMALLTAIL );
1348 /* no preallocation minimum, be smart in
1349 reiserfs_file_write instead */
1350 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1351 /* Preallocate by 16 blocks (17-1) at once */
1352 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1353 /* Initialize the rwsem for xattr dir */
1354 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
1356 /* setup default block allocator options */
1357 reiserfs_init_alloc_options(s);
1360 if (reiserfs_parse_options (s, (char *) data, &(sbi->s_mount_opt), &blocks, &jdev_name, &commit_max_age) == 0) {
1365 SWARN (silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1366 "for remount only");
1370 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1371 if (!read_super_block (s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1373 /* try new format (64-th 1k block), which can contain reiserfs super block */
1374 else if (read_super_block (s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1375 SWARN(silent, s, "sh-2021: reiserfs_fill_super: can not find reiserfs on %s", reiserfs_bdevname (s));
1379 rs = SB_DISK_SUPER_BLOCK (s);
1380 /* Let's do basic sanity check to verify that underlying device is not
1381 smaller than the filesystem. If the check fails then abort and scream,
1382 because bad stuff will happen otherwise. */
1383 if ( s->s_bdev && s->s_bdev->bd_inode && i_size_read(s->s_bdev->bd_inode) < sb_block_count(rs)*sb_blocksize(rs)) {
1384 SWARN (silent, s, "Filesystem on %s cannot be mounted because it is bigger than the device", reiserfs_bdevname(s));
1385 SWARN(silent, s, "You may need to run fsck or increase size of your LVM partition");
1386 SWARN(silent, s, "Or may be you forgot to reboot after fdisk when it told you to");
1390 sbi->s_mount_state = SB_REISERFS_STATE(s);
1391 sbi->s_mount_state = REISERFS_VALID_FS ;
1393 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1394 SWARN(silent, s, "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1397 #ifdef CONFIG_REISERFS_CHECK
1398 SWARN (silent, s, "CONFIG_REISERFS_CHECK is set ON");
1399 SWARN (silent, s, "- it is slow mode for debugging.");
1402 /* make data=ordered the default */
1403 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1404 !reiserfs_data_writeback(s))
1406 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1409 if (reiserfs_data_log(s)) {
1410 reiserfs_info (s, "using journaled data mode\n");
1411 } else if (reiserfs_data_ordered(s)) {
1412 reiserfs_info (s, "using ordered data mode\n");
1414 reiserfs_info (s, "using writeback data mode\n");
1417 // set_device_ro(s->s_dev, 1) ;
1418 if( journal_init(s, jdev_name, old_format, commit_max_age) ) {
1419 SWARN(silent, s, "sh-2022: reiserfs_fill_super: unable to initialize journal space") ;
1422 jinit_done = 1 ; /* once this is set, journal_release must be called
1423 ** if we error out of the mount
1426 if (reread_meta_blocks(s)) {
1427 SWARN(silent, s, "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init") ;
1431 if (replay_only (s))
1434 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1435 SWARN(silent, s, "clm-7000: Detected readonly device, marking FS readonly") ;
1436 s->s_flags |= MS_RDONLY ;
1438 args.objectid = REISERFS_ROOT_OBJECTID ;
1439 args.dirid = REISERFS_ROOT_PARENT_OBJECTID ;
1440 root_inode = iget5_locked (s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, reiserfs_init_locked_inode, (void *)(&args));
1442 SWARN(silent, s, "jmacd-10: reiserfs_fill_super: get root inode failed");
1446 if (root_inode->i_state & I_NEW) {
1447 reiserfs_read_locked_inode(root_inode, &args);
1448 unlock_new_inode(root_inode);
1451 s->s_root = d_alloc_root(root_inode);
1457 // define and initialize hash function
1458 sbi->s_hash_function = hash_function (s);
1459 if (sbi->s_hash_function == NULL) {
1465 if (is_reiserfs_3_5 (rs) || (is_reiserfs_jr (rs) && SB_VERSION (s) == REISERFS_VERSION_1))
1466 set_bit(REISERFS_3_5, &(sbi->s_properties));
1468 set_bit(REISERFS_3_6, &(sbi->s_properties));
1470 if (!(s->s_flags & MS_RDONLY)) {
1472 journal_begin(&th, s, 1) ;
1473 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1) ;
1475 set_sb_umount_state( rs, REISERFS_ERROR_FS );
1476 set_sb_fs_state (rs, 0);
1478 if (old_format_only(s)) {
1479 /* filesystem of format 3.5 either with standard or non-standard
1481 if (convert_reiserfs (s)) {
1482 /* and -o conv is given */
1484 reiserfs_info (s,"converting 3.5 filesystem to the 3.6 format") ;
1486 if (is_reiserfs_3_5 (rs))
1487 /* put magic string of 3.6 format. 2.2 will not be able to
1488 mount this filesystem anymore */
1489 memcpy (rs->s_v1.s_magic, reiserfs_3_6_magic_string,
1490 sizeof (reiserfs_3_6_magic_string));
1492 set_sb_version(rs,REISERFS_VERSION_2);
1493 reiserfs_convert_objectid_map_v1(s) ;
1494 set_bit(REISERFS_3_6, &(sbi->s_properties));
1495 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1496 } else if (!silent){
1497 reiserfs_info (s, "using 3.5.x disk format\n") ;
1501 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB (s));
1502 journal_end(&th, s, 1) ;
1504 if (reiserfs_xattr_init (s, s->s_flags)) {
1510 /* look for files which were to be removed in previous session */
1511 finish_unfinished (s);
1513 if ( old_format_only(s) && !silent) {
1514 reiserfs_info (s, "using 3.5.x disk format\n") ;
1517 if (reiserfs_xattr_init (s, s->s_flags)) {
1523 // mark hash in super block: it could be unset. overwrite should be ok
1524 set_sb_hash_function_code( rs, function2code(sbi->s_hash_function ) );
1528 reiserfs_proc_info_init( s );
1530 init_waitqueue_head (&(sbi->s_wait));
1531 sbi->bitmap_lock = SPIN_LOCK_UNLOCKED;
1536 if (jinit_done) { /* kill the commit thread, free journal ram */
1537 journal_release_error(NULL, s) ;
1539 if (SB_DISK_SUPER_BLOCK (s)) {
1540 for (j = 0; j < SB_BMAP_NR (s); j ++) {
1541 if (SB_AP_BITMAP (s))
1542 brelse (SB_AP_BITMAP (s)[j].bh);
1544 if (SB_AP_BITMAP (s))
1545 vfree (SB_AP_BITMAP (s));
1547 if (SB_BUFFER_WITH_SB (s))
1548 brelse(SB_BUFFER_WITH_SB (s));
1554 s->s_fs_info = NULL;
1559 static int reiserfs_statfs (struct super_block * s, struct kstatfs * buf)
1561 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (s);
1563 buf->f_namelen = (REISERFS_MAX_NAME (s->s_blocksize));
1564 buf->f_bfree = sb_free_blocks(rs);
1565 buf->f_bavail = buf->f_bfree;
1566 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1567 buf->f_bsize = s->s_blocksize;
1568 /* changed to accommodate gcc folks.*/
1569 buf->f_type = REISERFS_SUPER_MAGIC;
1573 static struct super_block*
1574 get_super_block (struct file_system_type *fs_type, int flags,
1575 const char *dev_name, void *data)
1577 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
1581 init_reiserfs_fs ( void )
1585 if ((ret = init_inodecache ())) {
1589 if ((ret = reiserfs_xattr_register_handlers ()))
1590 goto failed_reiserfs_xattr_register_handlers;
1592 reiserfs_proc_info_global_init ();
1593 reiserfs_proc_register_global ("version", reiserfs_global_version_in_proc);
1595 ret = register_filesystem (& reiserfs_fs_type);
1601 reiserfs_xattr_unregister_handlers ();
1603 failed_reiserfs_xattr_register_handlers:
1604 reiserfs_proc_unregister_global ("version");
1605 reiserfs_proc_info_global_done ();
1606 destroy_inodecache ();
1612 exit_reiserfs_fs ( void )
1614 reiserfs_xattr_unregister_handlers ();
1615 reiserfs_proc_unregister_global ("version");
1616 reiserfs_proc_info_global_done ();
1617 unregister_filesystem (& reiserfs_fs_type);
1618 destroy_inodecache ();
1621 struct file_system_type reiserfs_fs_type = {
1622 .owner = THIS_MODULE,
1624 .get_sb = get_super_block,
1625 .kill_sb = kill_block_super,
1626 .fs_flags = FS_REQUIRES_DEV,
1629 MODULE_DESCRIPTION ("ReiserFS journaled filesystem");
1630 MODULE_AUTHOR ("Hans Reiser <reiser@namesys.com>");
1631 MODULE_LICENSE ("GPL");
1633 module_init (init_reiserfs_fs);
1634 module_exit (exit_reiserfs_fs);