linux/fs/reiserfs/super.c
<<
>>
Prefs
   1/*
   2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
   3 *
   4 * Trivial changes by Alan Cox to add the LFS fixes
   5 *
   6 * Trivial Changes:
   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.
  10 *
  11 * NO WARRANTY
  12 */
  13
  14#include <linux/module.h>
  15#include <linux/slab.h>
  16#include <linux/vmalloc.h>
  17#include <linux/time.h>
  18#include <asm/uaccess.h>
  19#include "reiserfs.h"
  20#include "acl.h"
  21#include "xattr.h"
  22#include <linux/init.h>
  23#include <linux/blkdev.h>
  24#include <linux/buffer_head.h>
  25#include <linux/exportfs.h>
  26#include <linux/quotaops.h>
  27#include <linux/vfs.h>
  28#include <linux/mount.h>
  29#include <linux/namei.h>
  30#include <linux/crc32.h>
  31#include <linux/seq_file.h>
  32
  33struct file_system_type reiserfs_fs_type;
  34
  35static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
  36static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
  37static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
  38
  39int is_reiserfs_3_5(struct reiserfs_super_block *rs)
  40{
  41        return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
  42                        strlen(reiserfs_3_5_magic_string));
  43}
  44
  45int is_reiserfs_3_6(struct reiserfs_super_block *rs)
  46{
  47        return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
  48                        strlen(reiserfs_3_6_magic_string));
  49}
  50
  51int is_reiserfs_jr(struct reiserfs_super_block *rs)
  52{
  53        return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
  54                        strlen(reiserfs_jr_magic_string));
  55}
  56
  57static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
  58{
  59        return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
  60                is_reiserfs_jr(rs));
  61}
  62
  63static int reiserfs_remount(struct super_block *s, int *flags, char *data);
  64static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
  65void show_alloc_options(struct seq_file *seq, struct super_block *s);
  66
  67static int reiserfs_sync_fs(struct super_block *s, int wait)
  68{
  69        struct reiserfs_transaction_handle th;
  70
  71        /*
  72         * Writeback quota in non-journalled quota case - journalled quota has
  73         * no dirty dquots
  74         */
  75        dquot_writeback_dquots(s, -1);
  76        reiserfs_write_lock(s);
  77        if (!journal_begin(&th, s, 1))
  78                if (!journal_end_sync(&th, s, 1))
  79                        reiserfs_flush_old_commits(s);
  80        reiserfs_write_unlock(s);
  81        return 0;
  82}
  83
  84static void flush_old_commits(struct work_struct *work)
  85{
  86        struct reiserfs_sb_info *sbi;
  87        struct super_block *s;
  88
  89        sbi = container_of(work, struct reiserfs_sb_info, old_work.work);
  90        s = sbi->s_journal->j_work_sb;
  91
  92        spin_lock(&sbi->old_work_lock);
  93        sbi->work_queued = 0;
  94        spin_unlock(&sbi->old_work_lock);
  95
  96        reiserfs_sync_fs(s, 1);
  97}
  98
  99void reiserfs_schedule_old_flush(struct super_block *s)
 100{
 101        struct reiserfs_sb_info *sbi = REISERFS_SB(s);
 102        unsigned long delay;
 103
 104        if (s->s_flags & MS_RDONLY)
 105                return;
 106
 107        spin_lock(&sbi->old_work_lock);
 108        if (!sbi->work_queued) {
 109                delay = msecs_to_jiffies(dirty_writeback_interval * 10);
 110                queue_delayed_work(system_long_wq, &sbi->old_work, delay);
 111                sbi->work_queued = 1;
 112        }
 113        spin_unlock(&sbi->old_work_lock);
 114}
 115
 116static void cancel_old_flush(struct super_block *s)
 117{
 118        struct reiserfs_sb_info *sbi = REISERFS_SB(s);
 119
 120        cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
 121        spin_lock(&sbi->old_work_lock);
 122        sbi->work_queued = 0;
 123        spin_unlock(&sbi->old_work_lock);
 124}
 125
 126static int reiserfs_freeze(struct super_block *s)
 127{
 128        struct reiserfs_transaction_handle th;
 129
 130        cancel_old_flush(s);
 131
 132        reiserfs_write_lock(s);
 133        if (!(s->s_flags & MS_RDONLY)) {
 134                int err = journal_begin(&th, s, 1);
 135                if (err) {
 136                        reiserfs_block_writes(&th);
 137                } else {
 138                        reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
 139                                                     1);
 140                        journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
 141                        reiserfs_block_writes(&th);
 142                        journal_end_sync(&th, s, 1);
 143                }
 144        }
 145        reiserfs_write_unlock(s);
 146        return 0;
 147}
 148
 149static int reiserfs_unfreeze(struct super_block *s)
 150{
 151        reiserfs_allow_writes(s);
 152        return 0;
 153}
 154
 155extern const struct in_core_key MAX_IN_CORE_KEY;
 156
 157/* this is used to delete "save link" when there are no items of a
 158   file it points to. It can either happen if unlink is completed but
 159   "save unlink" removal, or if file has both unlink and truncate
 160   pending and as unlink completes first (because key of "save link"
 161   protecting unlink is bigger that a key lf "save link" which
 162   protects truncate), so there left no items to make truncate
 163   completion on */
 164static int remove_save_link_only(struct super_block *s,
 165                                 struct reiserfs_key *key, int oid_free)
 166{
 167        struct reiserfs_transaction_handle th;
 168        int err;
 169
 170        /* we are going to do one balancing */
 171        err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
 172        if (err)
 173                return err;
 174
 175        reiserfs_delete_solid_item(&th, NULL, key);
 176        if (oid_free)
 177                /* removals are protected by direct items */
 178                reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
 179
 180        return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
 181}
 182
 183#ifdef CONFIG_QUOTA
 184static int reiserfs_quota_on_mount(struct super_block *, int);
 185#endif
 186
 187/* look for uncompleted unlinks and truncates and complete them */
 188static int finish_unfinished(struct super_block *s)
 189{
 190        INITIALIZE_PATH(path);
 191        struct cpu_key max_cpu_key, obj_key;
 192        struct reiserfs_key save_link_key, last_inode_key;
 193        int retval = 0;
 194        struct item_head *ih;
 195        struct buffer_head *bh;
 196        int item_pos;
 197        char *item;
 198        int done;
 199        struct inode *inode;
 200        int truncate;
 201#ifdef CONFIG_QUOTA
 202        int i;
 203        int ms_active_set;
 204        int quota_enabled[MAXQUOTAS];
 205#endif
 206
 207        /* compose key to look for "save" links */
 208        max_cpu_key.version = KEY_FORMAT_3_5;
 209        max_cpu_key.on_disk_key.k_dir_id = ~0U;
 210        max_cpu_key.on_disk_key.k_objectid = ~0U;
 211        set_cpu_key_k_offset(&max_cpu_key, ~0U);
 212        max_cpu_key.key_length = 3;
 213
 214        memset(&last_inode_key, 0, sizeof(last_inode_key));
 215
 216#ifdef CONFIG_QUOTA
 217        /* Needed for iput() to work correctly and not trash data */
 218        if (s->s_flags & MS_ACTIVE) {
 219                ms_active_set = 0;
 220        } else {
 221                ms_active_set = 1;
 222                s->s_flags |= MS_ACTIVE;
 223        }
 224        /* Turn on quotas so that they are updated correctly */
 225        for (i = 0; i < MAXQUOTAS; i++) {
 226                quota_enabled[i] = 1;
 227                if (REISERFS_SB(s)->s_qf_names[i]) {
 228                        int ret;
 229
 230                        if (sb_has_quota_active(s, i)) {
 231                                quota_enabled[i] = 0;
 232                                continue;
 233                        }
 234                        ret = reiserfs_quota_on_mount(s, i);
 235                        if (ret < 0)
 236                                reiserfs_warning(s, "reiserfs-2500",
 237                                                 "cannot turn on journaled "
 238                                                 "quota: error %d", ret);
 239                }
 240        }
 241#endif
 242
 243        done = 0;
 244        REISERFS_SB(s)->s_is_unlinked_ok = 1;
 245        while (!retval) {
 246                retval = search_item(s, &max_cpu_key, &path);
 247                if (retval != ITEM_NOT_FOUND) {
 248                        reiserfs_error(s, "vs-2140",
 249                                       "search_by_key returned %d", retval);
 250                        break;
 251                }
 252
 253                bh = get_last_bh(&path);
 254                item_pos = get_item_pos(&path);
 255                if (item_pos != B_NR_ITEMS(bh)) {
 256                        reiserfs_warning(s, "vs-2060",
 257                                         "wrong position found");
 258                        break;
 259                }
 260                item_pos--;
 261                ih = B_N_PITEM_HEAD(bh, item_pos);
 262
 263                if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
 264                        /* there are no "save" links anymore */
 265                        break;
 266
 267                save_link_key = ih->ih_key;
 268                if (is_indirect_le_ih(ih))
 269                        truncate = 1;
 270                else
 271                        truncate = 0;
 272
 273                /* reiserfs_iget needs k_dirid and k_objectid only */
 274                item = B_I_PITEM(bh, ih);
 275                obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
 276                obj_key.on_disk_key.k_objectid =
 277                    le32_to_cpu(ih->ih_key.k_objectid);
 278                obj_key.on_disk_key.k_offset = 0;
 279                obj_key.on_disk_key.k_type = 0;
 280
 281                pathrelse(&path);
 282
 283                inode = reiserfs_iget(s, &obj_key);
 284                if (!inode) {
 285                        /* the unlink almost completed, it just did not manage to remove
 286                           "save" link and release objectid */
 287                        reiserfs_warning(s, "vs-2180", "iget failed for %K",
 288                                         &obj_key);
 289                        retval = remove_save_link_only(s, &save_link_key, 1);
 290                        continue;
 291                }
 292
 293                if (!truncate && inode->i_nlink) {
 294                        /* file is not unlinked */
 295                        reiserfs_warning(s, "vs-2185",
 296                                         "file %K is not unlinked",
 297                                         &obj_key);
 298                        retval = remove_save_link_only(s, &save_link_key, 0);
 299                        continue;
 300                }
 301                reiserfs_write_unlock(s);
 302                dquot_initialize(inode);
 303                reiserfs_write_lock(s);
 304
 305                if (truncate && S_ISDIR(inode->i_mode)) {
 306                        /* We got a truncate request for a dir which is impossible.
 307                           The only imaginable way is to execute unfinished truncate request
 308                           then boot into old kernel, remove the file and create dir with
 309                           the same key. */
 310                        reiserfs_warning(s, "green-2101",
 311                                         "impossible truncate on a "
 312                                         "directory %k. Please report",
 313                                         INODE_PKEY(inode));
 314                        retval = remove_save_link_only(s, &save_link_key, 0);
 315                        truncate = 0;
 316                        iput(inode);
 317                        continue;
 318                }
 319
 320                if (truncate) {
 321                        REISERFS_I(inode)->i_flags |=
 322                            i_link_saved_truncate_mask;
 323                        /* not completed truncate found. New size was committed together
 324                           with "save" link */
 325                        reiserfs_info(s, "Truncating %k to %Ld ..",
 326                                      INODE_PKEY(inode), inode->i_size);
 327                        reiserfs_truncate_file(inode,
 328                                               0
 329                                               /*don't update modification time */
 330                                               );
 331                        retval = remove_save_link(inode, truncate);
 332                } else {
 333                        REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
 334                        /* not completed unlink (rmdir) found */
 335                        reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
 336                        if (memcmp(&last_inode_key, INODE_PKEY(inode),
 337                                        sizeof(last_inode_key))){
 338                                last_inode_key = *INODE_PKEY(inode);
 339                                /* removal gets completed in iput */
 340                                retval = 0;
 341                        } else {
 342                                reiserfs_warning(s, "super-2189", "Dead loop "
 343                                                 "in finish_unfinished "
 344                                                 "detected, just remove "
 345                                                 "save link\n");
 346                                retval = remove_save_link_only(s,
 347                                                        &save_link_key, 0);
 348                        }
 349                }
 350
 351                iput(inode);
 352                printk("done\n");
 353                done++;
 354        }
 355        REISERFS_SB(s)->s_is_unlinked_ok = 0;
 356
 357#ifdef CONFIG_QUOTA
 358        /* Turn quotas off */
 359        for (i = 0; i < MAXQUOTAS; i++) {
 360                if (sb_dqopt(s)->files[i] && quota_enabled[i])
 361                        dquot_quota_off(s, i);
 362        }
 363        if (ms_active_set)
 364                /* Restore the flag back */
 365                s->s_flags &= ~MS_ACTIVE;
 366#endif
 367        pathrelse(&path);
 368        if (done)
 369                reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
 370                              "Completed\n", done);
 371        return retval;
 372}
 373
 374/* to protect file being unlinked from getting lost we "safe" link files
 375   being unlinked. This link will be deleted in the same transaction with last
 376   item of file. mounting the filesystem we scan all these links and remove
 377   files which almost got lost */
 378void add_save_link(struct reiserfs_transaction_handle *th,
 379                   struct inode *inode, int truncate)
 380{
 381        INITIALIZE_PATH(path);
 382        int retval;
 383        struct cpu_key key;
 384        struct item_head ih;
 385        __le32 link;
 386
 387        BUG_ON(!th->t_trans_id);
 388
 389        /* file can only get one "save link" of each kind */
 390        RFALSE(truncate &&
 391               (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
 392               "saved link already exists for truncated inode %lx",
 393               (long)inode->i_ino);
 394        RFALSE(!truncate &&
 395               (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
 396               "saved link already exists for unlinked inode %lx",
 397               (long)inode->i_ino);
 398
 399        /* setup key of "save" link */
 400        key.version = KEY_FORMAT_3_5;
 401        key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
 402        key.on_disk_key.k_objectid = inode->i_ino;
 403        if (!truncate) {
 404                /* unlink, rmdir, rename */
 405                set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
 406                set_cpu_key_k_type(&key, TYPE_DIRECT);
 407
 408                /* item head of "safe" link */
 409                make_le_item_head(&ih, &key, key.version,
 410                                  1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
 411                                  4 /*length */ , 0xffff /*free space */ );
 412        } else {
 413                /* truncate */
 414                if (S_ISDIR(inode->i_mode))
 415                        reiserfs_warning(inode->i_sb, "green-2102",
 416                                         "Adding a truncate savelink for "
 417                                         "a directory %k! Please report",
 418                                         INODE_PKEY(inode));
 419                set_cpu_key_k_offset(&key, 1);
 420                set_cpu_key_k_type(&key, TYPE_INDIRECT);
 421
 422                /* item head of "safe" link */
 423                make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
 424                                  4 /*length */ , 0 /*free space */ );
 425        }
 426        key.key_length = 3;
 427
 428        /* look for its place in the tree */
 429        retval = search_item(inode->i_sb, &key, &path);
 430        if (retval != ITEM_NOT_FOUND) {
 431                if (retval != -ENOSPC)
 432                        reiserfs_error(inode->i_sb, "vs-2100",
 433                                       "search_by_key (%K) returned %d", &key,
 434                                       retval);
 435                pathrelse(&path);
 436                return;
 437        }
 438
 439        /* body of "save" link */
 440        link = INODE_PKEY(inode)->k_dir_id;
 441
 442        /* put "save" link into tree, don't charge quota to anyone */
 443        retval =
 444            reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
 445        if (retval) {
 446                if (retval != -ENOSPC)
 447                        reiserfs_error(inode->i_sb, "vs-2120",
 448                                       "insert_item returned %d", retval);
 449        } else {
 450                if (truncate)
 451                        REISERFS_I(inode)->i_flags |=
 452                            i_link_saved_truncate_mask;
 453                else
 454                        REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
 455        }
 456}
 457
 458/* this opens transaction unlike add_save_link */
 459int remove_save_link(struct inode *inode, int truncate)
 460{
 461        struct reiserfs_transaction_handle th;
 462        struct reiserfs_key key;
 463        int err;
 464
 465        /* we are going to do one balancing only */
 466        err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
 467        if (err)
 468                return err;
 469
 470        /* setup key of "save" link */
 471        key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
 472        key.k_objectid = INODE_PKEY(inode)->k_objectid;
 473        if (!truncate) {
 474                /* unlink, rmdir, rename */
 475                set_le_key_k_offset(KEY_FORMAT_3_5, &key,
 476                                    1 + inode->i_sb->s_blocksize);
 477                set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
 478        } else {
 479                /* truncate */
 480                set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
 481                set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
 482        }
 483
 484        if ((truncate &&
 485             (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
 486            (!truncate &&
 487             (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
 488                /* don't take quota bytes from anywhere */
 489                reiserfs_delete_solid_item(&th, NULL, &key);
 490        if (!truncate) {
 491                reiserfs_release_objectid(&th, inode->i_ino);
 492                REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
 493        } else
 494                REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
 495
 496        return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
 497}
 498
 499static void reiserfs_kill_sb(struct super_block *s)
 500{
 501        if (REISERFS_SB(s)) {
 502                /*
 503                 * Force any pending inode evictions to occur now. Any
 504                 * inodes to be removed that have extended attributes
 505                 * associated with them need to clean them up before
 506                 * we can release the extended attribute root dentries.
 507                 * shrink_dcache_for_umount will BUG if we don't release
 508                 * those before it's called so ->put_super is too late.
 509                 */
 510                shrink_dcache_sb(s);
 511
 512                dput(REISERFS_SB(s)->xattr_root);
 513                REISERFS_SB(s)->xattr_root = NULL;
 514                dput(REISERFS_SB(s)->priv_root);
 515                REISERFS_SB(s)->priv_root = NULL;
 516        }
 517
 518        kill_block_super(s);
 519}
 520
 521static void reiserfs_put_super(struct super_block *s)
 522{
 523        struct reiserfs_transaction_handle th;
 524        th.t_trans_id = 0;
 525
 526        dquot_disable(s, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
 527
 528        reiserfs_write_lock(s);
 529
 530        /* change file system state to current state if it was mounted with read-write permissions */
 531        if (!(s->s_flags & MS_RDONLY)) {
 532                if (!journal_begin(&th, s, 10)) {
 533                        reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
 534                                                     1);
 535                        set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
 536                                            REISERFS_SB(s)->s_mount_state);
 537                        journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
 538                }
 539        }
 540
 541        /* note, journal_release checks for readonly mount, and can decide not
 542         ** to do a journal_end
 543         */
 544        journal_release(&th, s);
 545
 546        reiserfs_free_bitmap_cache(s);
 547
 548        brelse(SB_BUFFER_WITH_SB(s));
 549
 550        print_statistics(s);
 551
 552        if (REISERFS_SB(s)->reserved_blocks != 0) {
 553                reiserfs_warning(s, "green-2005", "reserved blocks left %d",
 554                                 REISERFS_SB(s)->reserved_blocks);
 555        }
 556
 557        reiserfs_proc_info_done(s);
 558
 559        reiserfs_write_unlock(s);
 560        mutex_destroy(&REISERFS_SB(s)->lock);
 561        kfree(s->s_fs_info);
 562        s->s_fs_info = NULL;
 563}
 564
 565static struct kmem_cache *reiserfs_inode_cachep;
 566
 567static struct inode *reiserfs_alloc_inode(struct super_block *sb)
 568{
 569        struct reiserfs_inode_info *ei;
 570        ei = (struct reiserfs_inode_info *)
 571            kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
 572        if (!ei)
 573                return NULL;
 574        atomic_set(&ei->openers, 0);
 575        mutex_init(&ei->tailpack);
 576        return &ei->vfs_inode;
 577}
 578
 579static void reiserfs_i_callback(struct rcu_head *head)
 580{
 581        struct inode *inode = container_of(head, struct inode, i_rcu);
 582        kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
 583}
 584
 585static void reiserfs_destroy_inode(struct inode *inode)
 586{
 587        call_rcu(&inode->i_rcu, reiserfs_i_callback);
 588}
 589
 590static void init_once(void *foo)
 591{
 592        struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
 593
 594        INIT_LIST_HEAD(&ei->i_prealloc_list);
 595        inode_init_once(&ei->vfs_inode);
 596}
 597
 598static int init_inodecache(void)
 599{
 600        reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
 601                                                  sizeof(struct
 602                                                         reiserfs_inode_info),
 603                                                  0, (SLAB_RECLAIM_ACCOUNT|
 604                                                        SLAB_MEM_SPREAD),
 605                                                  init_once);
 606        if (reiserfs_inode_cachep == NULL)
 607                return -ENOMEM;
 608        return 0;
 609}
 610
 611static void destroy_inodecache(void)
 612{
 613        kmem_cache_destroy(reiserfs_inode_cachep);
 614}
 615
 616/* we don't mark inodes dirty, we just log them */
 617static void reiserfs_dirty_inode(struct inode *inode, int flags)
 618{
 619        struct reiserfs_transaction_handle th;
 620
 621        int err = 0;
 622        int lock_depth;
 623
 624        if (inode->i_sb->s_flags & MS_RDONLY) {
 625                reiserfs_warning(inode->i_sb, "clm-6006",
 626                                 "writing inode %lu on readonly FS",
 627                                 inode->i_ino);
 628                return;
 629        }
 630        lock_depth = reiserfs_write_lock_once(inode->i_sb);
 631
 632        /* this is really only used for atime updates, so they don't have
 633         ** to be included in O_SYNC or fsync
 634         */
 635        err = journal_begin(&th, inode->i_sb, 1);
 636        if (err)
 637                goto out;
 638
 639        reiserfs_update_sd(&th, inode);
 640        journal_end(&th, inode->i_sb, 1);
 641
 642out:
 643        reiserfs_write_unlock_once(inode->i_sb, lock_depth);
 644}
 645
 646static int reiserfs_show_options(struct seq_file *seq, struct dentry *root)
 647{
 648        struct super_block *s = root->d_sb;
 649        struct reiserfs_journal *journal = SB_JOURNAL(s);
 650        long opts = REISERFS_SB(s)->s_mount_opt;
 651
 652        if (opts & (1 << REISERFS_LARGETAIL))
 653                seq_puts(seq, ",tails=on");
 654        else if (!(opts & (1 << REISERFS_SMALLTAIL)))
 655                seq_puts(seq, ",notail");
 656        /* tails=small is default so we don't show it */
 657
 658        if (!(opts & (1 << REISERFS_BARRIER_FLUSH)))
 659                seq_puts(seq, ",barrier=none");
 660        /* barrier=flush is default so we don't show it */
 661
 662        if (opts & (1 << REISERFS_ERROR_CONTINUE))
 663                seq_puts(seq, ",errors=continue");
 664        else if (opts & (1 << REISERFS_ERROR_PANIC))
 665                seq_puts(seq, ",errors=panic");
 666        /* errors=ro is default so we don't show it */
 667
 668        if (opts & (1 << REISERFS_DATA_LOG))
 669                seq_puts(seq, ",data=journal");
 670        else if (opts & (1 << REISERFS_DATA_WRITEBACK))
 671                seq_puts(seq, ",data=writeback");
 672        /* data=ordered is default so we don't show it */
 673
 674        if (opts & (1 << REISERFS_ATTRS))
 675                seq_puts(seq, ",attrs");
 676
 677        if (opts & (1 << REISERFS_XATTRS_USER))
 678                seq_puts(seq, ",user_xattr");
 679
 680        if (opts & (1 << REISERFS_EXPOSE_PRIVROOT))
 681                seq_puts(seq, ",expose_privroot");
 682
 683        if (opts & (1 << REISERFS_POSIXACL))
 684                seq_puts(seq, ",acl");
 685
 686        if (REISERFS_SB(s)->s_jdev)
 687                seq_printf(seq, ",jdev=%s", REISERFS_SB(s)->s_jdev);
 688
 689        if (journal->j_max_commit_age != journal->j_default_max_commit_age)
 690                seq_printf(seq, ",commit=%d", journal->j_max_commit_age);
 691
 692#ifdef CONFIG_QUOTA
 693        if (REISERFS_SB(s)->s_qf_names[USRQUOTA])
 694                seq_printf(seq, ",usrjquota=%s", REISERFS_SB(s)->s_qf_names[USRQUOTA]);
 695        else if (opts & (1 << REISERFS_USRQUOTA))
 696                seq_puts(seq, ",usrquota");
 697        if (REISERFS_SB(s)->s_qf_names[GRPQUOTA])
 698                seq_printf(seq, ",grpjquota=%s", REISERFS_SB(s)->s_qf_names[GRPQUOTA]);
 699        else if (opts & (1 << REISERFS_GRPQUOTA))
 700                seq_puts(seq, ",grpquota");
 701        if (REISERFS_SB(s)->s_jquota_fmt) {
 702                if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_OLD)
 703                        seq_puts(seq, ",jqfmt=vfsold");
 704                else if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_V0)
 705                        seq_puts(seq, ",jqfmt=vfsv0");
 706        }
 707#endif
 708
 709        /* Block allocator options */
 710        if (opts & (1 << REISERFS_NO_BORDER))
 711                seq_puts(seq, ",block-allocator=noborder");
 712        if (opts & (1 << REISERFS_NO_UNHASHED_RELOCATION))
 713                seq_puts(seq, ",block-allocator=no_unhashed_relocation");
 714        if (opts & (1 << REISERFS_HASHED_RELOCATION))
 715                seq_puts(seq, ",block-allocator=hashed_relocation");
 716        if (opts & (1 << REISERFS_TEST4))
 717                seq_puts(seq, ",block-allocator=test4");
 718        show_alloc_options(seq, s);
 719        return 0;
 720}
 721
 722#ifdef CONFIG_QUOTA
 723static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
 724                                    size_t, loff_t);
 725static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
 726                                   loff_t);
 727#endif
 728
 729static const struct super_operations reiserfs_sops = {
 730        .alloc_inode = reiserfs_alloc_inode,
 731        .destroy_inode = reiserfs_destroy_inode,
 732        .write_inode = reiserfs_write_inode,
 733        .dirty_inode = reiserfs_dirty_inode,
 734        .evict_inode = reiserfs_evict_inode,
 735        .put_super = reiserfs_put_super,
 736        .sync_fs = reiserfs_sync_fs,
 737        .freeze_fs = reiserfs_freeze,
 738        .unfreeze_fs = reiserfs_unfreeze,
 739        .statfs = reiserfs_statfs,
 740        .remount_fs = reiserfs_remount,
 741        .show_options = reiserfs_show_options,
 742#ifdef CONFIG_QUOTA
 743        .quota_read = reiserfs_quota_read,
 744        .quota_write = reiserfs_quota_write,
 745#endif
 746};
 747
 748#ifdef CONFIG_QUOTA
 749#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
 750
 751static int reiserfs_write_dquot(struct dquot *);
 752static int reiserfs_acquire_dquot(struct dquot *);
 753static int reiserfs_release_dquot(struct dquot *);
 754static int reiserfs_mark_dquot_dirty(struct dquot *);
 755static int reiserfs_write_info(struct super_block *, int);
 756static int reiserfs_quota_on(struct super_block *, int, int, struct path *);
 757
 758static const struct dquot_operations reiserfs_quota_operations = {
 759        .write_dquot = reiserfs_write_dquot,
 760        .acquire_dquot = reiserfs_acquire_dquot,
 761        .release_dquot = reiserfs_release_dquot,
 762        .mark_dirty = reiserfs_mark_dquot_dirty,
 763        .write_info = reiserfs_write_info,
 764        .alloc_dquot    = dquot_alloc,
 765        .destroy_dquot  = dquot_destroy,
 766};
 767
 768static const struct quotactl_ops reiserfs_qctl_operations = {
 769        .quota_on = reiserfs_quota_on,
 770        .quota_off = dquot_quota_off,
 771        .quota_sync = dquot_quota_sync,
 772        .get_info = dquot_get_dqinfo,
 773        .set_info = dquot_set_dqinfo,
 774        .get_dqblk = dquot_get_dqblk,
 775        .set_dqblk = dquot_set_dqblk,
 776};
 777#endif
 778
 779static const struct export_operations reiserfs_export_ops = {
 780        .encode_fh = reiserfs_encode_fh,
 781        .fh_to_dentry = reiserfs_fh_to_dentry,
 782        .fh_to_parent = reiserfs_fh_to_parent,
 783        .get_parent = reiserfs_get_parent,
 784};
 785
 786/* this struct is used in reiserfs_getopt () for containing the value for those
 787   mount options that have values rather than being toggles. */
 788typedef struct {
 789        char *value;
 790        int setmask;            /* bitmask which is to set on mount_options bitmask when this
 791                                   value is found, 0 is no bits are to be changed. */
 792        int clrmask;            /* bitmask which is to clear on mount_options bitmask when  this
 793                                   value is found, 0 is no bits are to be changed. This is
 794                                   applied BEFORE setmask */
 795} arg_desc_t;
 796
 797/* Set this bit in arg_required to allow empty arguments */
 798#define REISERFS_OPT_ALLOWEMPTY 31
 799
 800/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
 801   mount options */
 802typedef struct {
 803        char *option_name;
 804        int arg_required;       /* 0 if argument is not required, not 0 otherwise */
 805        const arg_desc_t *values;       /* list of values accepted by an option */
 806        int setmask;            /* bitmask which is to set on mount_options bitmask when this
 807                                   value is found, 0 is no bits are to be changed. */
 808        int clrmask;            /* bitmask which is to clear on mount_options bitmask when  this
 809                                   value is found, 0 is no bits are to be changed. This is
 810                                   applied BEFORE setmask */
 811} opt_desc_t;
 812
 813/* possible values for -o data= */
 814static const arg_desc_t logging_mode[] = {
 815        {"ordered", 1 << REISERFS_DATA_ORDERED,
 816         (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
 817        {"journal", 1 << REISERFS_DATA_LOG,
 818         (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
 819        {"writeback", 1 << REISERFS_DATA_WRITEBACK,
 820         (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
 821        {.value = NULL}
 822};
 823
 824/* possible values for -o barrier= */
 825static const arg_desc_t barrier_mode[] = {
 826        {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
 827        {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
 828        {.value = NULL}
 829};
 830
 831/* possible values for "-o block-allocator=" and bits which are to be set in
 832   s_mount_opt of reiserfs specific part of in-core super block */
 833static const arg_desc_t balloc[] = {
 834        {"noborder", 1 << REISERFS_NO_BORDER, 0},
 835        {"border", 0, 1 << REISERFS_NO_BORDER},
 836        {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
 837        {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
 838        {"test4", 1 << REISERFS_TEST4, 0},
 839        {"notest4", 0, 1 << REISERFS_TEST4},
 840        {NULL, 0, 0}
 841};
 842
 843static const arg_desc_t tails[] = {
 844        {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
 845        {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
 846        {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
 847        {NULL, 0, 0}
 848};
 849
 850static const arg_desc_t error_actions[] = {
 851        {"panic", 1 << REISERFS_ERROR_PANIC,
 852         (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
 853        {"ro-remount", 1 << REISERFS_ERROR_RO,
 854         (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
 855#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
 856        {"continue", 1 << REISERFS_ERROR_CONTINUE,
 857         (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
 858#endif
 859        {NULL, 0, 0},
 860};
 861
 862/* proceed only one option from a list *cur - string containing of mount options
 863   opts - array of options which are accepted
 864   opt_arg - if option is found and requires an argument and if it is specifed
 865   in the input - pointer to the argument is stored here
 866   bit_flags - if option requires to set a certain bit - it is set here
 867   return -1 if unknown option is found, opt->arg_required otherwise */
 868static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
 869                           char **opt_arg, unsigned long *bit_flags)
 870{
 871        char *p;
 872        /* foo=bar,
 873           ^   ^  ^
 874           |   |  +-- option_end
 875           |   +-- arg_start
 876           +-- option_start
 877         */
 878        const opt_desc_t *opt;
 879        const arg_desc_t *arg;
 880
 881        p = *cur;
 882
 883        /* assume argument cannot contain commas */
 884        *cur = strchr(p, ',');
 885        if (*cur) {
 886                *(*cur) = '\0';
 887                (*cur)++;
 888        }
 889
 890        if (!strncmp(p, "alloc=", 6)) {
 891                /* Ugly special case, probably we should redo options parser so that
 892                   it can understand several arguments for some options, also so that
 893                   it can fill several bitfields with option values. */
 894                if (reiserfs_parse_alloc_options(s, p + 6)) {
 895                        return -1;
 896                } else {
 897                        return 0;
 898                }
 899        }
 900
 901        /* for every option in the list */
 902        for (opt = opts; opt->option_name; opt++) {
 903                if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
 904                        if (bit_flags) {
 905                                if (opt->clrmask ==
 906                                    (1 << REISERFS_UNSUPPORTED_OPT))
 907                                        reiserfs_warning(s, "super-6500",
 908                                                         "%s not supported.\n",
 909                                                         p);
 910                                else
 911                                        *bit_flags &= ~opt->clrmask;
 912                                if (opt->setmask ==
 913                                    (1 << REISERFS_UNSUPPORTED_OPT))
 914                                        reiserfs_warning(s, "super-6501",
 915                                                         "%s not supported.\n",
 916                                                         p);
 917                                else
 918                                        *bit_flags |= opt->setmask;
 919                        }
 920                        break;
 921                }
 922        }
 923        if (!opt->option_name) {
 924                reiserfs_warning(s, "super-6502",
 925                                 "unknown mount option \"%s\"", p);
 926                return -1;
 927        }
 928
 929        p += strlen(opt->option_name);
 930        switch (*p) {
 931        case '=':
 932                if (!opt->arg_required) {
 933                        reiserfs_warning(s, "super-6503",
 934                                         "the option \"%s\" does not "
 935                                         "require an argument\n",
 936                                         opt->option_name);
 937                        return -1;
 938                }
 939                break;
 940
 941        case 0:
 942                if (opt->arg_required) {
 943                        reiserfs_warning(s, "super-6504",
 944                                         "the option \"%s\" requires an "
 945                                         "argument\n", opt->option_name);
 946                        return -1;
 947                }
 948                break;
 949        default:
 950                reiserfs_warning(s, "super-6505",
 951                                 "head of option \"%s\" is only correct\n",
 952                                 opt->option_name);
 953                return -1;
 954        }
 955
 956        /* move to the argument, or to next option if argument is not required */
 957        p++;
 958
 959        if (opt->arg_required
 960            && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
 961            && !strlen(p)) {
 962                /* this catches "option=," if not allowed */
 963                reiserfs_warning(s, "super-6506",
 964                                 "empty argument for \"%s\"\n",
 965                                 opt->option_name);
 966                return -1;
 967        }
 968
 969        if (!opt->values) {
 970                /* *=NULLopt_arg contains pointer to argument */
 971                *opt_arg = p;
 972                return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
 973        }
 974
 975        /* values possible for this option are listed in opt->values */
 976        for (arg = opt->values; arg->value; arg++) {
 977                if (!strcmp(p, arg->value)) {
 978                        if (bit_flags) {
 979                                *bit_flags &= ~arg->clrmask;
 980                                *bit_flags |= arg->setmask;
 981                        }
 982                        return opt->arg_required;
 983                }
 984        }
 985
 986        reiserfs_warning(s, "super-6506",
 987                         "bad value \"%s\" for option \"%s\"\n", p,
 988                         opt->option_name);
 989        return -1;
 990}
 991
 992/* returns 0 if something is wrong in option string, 1 - otherwise */
 993static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
 994                                  unsigned long *mount_options,
 995                                  /* after the parsing phase, contains the
 996                                     collection of bitflags defining what
 997                                     mount options were selected. */
 998                                  unsigned long *blocks,        /* strtol-ed from NNN of resize=NNN */
 999                                  char **jdev_name,
1000                                  unsigned int *commit_max_age,
1001                                  char **qf_names,
1002                                  unsigned int *qfmt)
1003{
1004        int c;
1005        char *arg = NULL;
1006        char *pos;
1007        opt_desc_t opts[] = {
1008                /* Compatibility stuff, so that -o notail for old setups still work */
1009                {"tails",.arg_required = 't',.values = tails},
1010                {"notail",.clrmask =
1011                 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
1012                {"conv",.setmask = 1 << REISERFS_CONVERT},
1013                {"attrs",.setmask = 1 << REISERFS_ATTRS},
1014                {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
1015                {"expose_privroot", .setmask = 1 << REISERFS_EXPOSE_PRIVROOT},
1016#ifdef CONFIG_REISERFS_FS_XATTR
1017                {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
1018                {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
1019#else
1020                {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
1021                {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
1022#endif
1023#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1024                {"acl",.setmask = 1 << REISERFS_POSIXACL},
1025                {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
1026#else
1027                {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
1028                {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
1029#endif
1030                {.option_name = "nolog"},
1031                {"replayonly",.setmask = 1 << REPLAYONLY},
1032                {"block-allocator",.arg_required = 'a',.values = balloc},
1033                {"data",.arg_required = 'd',.values = logging_mode},
1034                {"barrier",.arg_required = 'b',.values = barrier_mode},
1035                {"resize",.arg_required = 'r',.values = NULL},
1036                {"jdev",.arg_required = 'j',.values = NULL},
1037                {"nolargeio",.arg_required = 'w',.values = NULL},
1038                {"commit",.arg_required = 'c',.values = NULL},
1039                {"usrquota",.setmask = 1 << REISERFS_USRQUOTA},
1040                {"grpquota",.setmask = 1 << REISERFS_GRPQUOTA},
1041                {"noquota",.clrmask = 1 << REISERFS_USRQUOTA | 1 << REISERFS_GRPQUOTA},
1042                {"errors",.arg_required = 'e',.values = error_actions},
1043                {"usrjquota",.arg_required =
1044                 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
1045                {"grpjquota",.arg_required =
1046                 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
1047                {"jqfmt",.arg_required = 'f',.values = NULL},
1048                {.option_name = NULL}
1049        };
1050
1051        *blocks = 0;
1052        if (!options || !*options)
1053                /* use default configuration: create tails, journaling on, no
1054                   conversion to newest format */
1055                return 1;
1056
1057        for (pos = options; pos;) {
1058                c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
1059                if (c == -1)
1060                        /* wrong option is given */
1061                        return 0;
1062
1063                if (c == 'r') {
1064                        char *p;
1065
1066                        p = NULL;
1067                        /* "resize=NNN" or "resize=auto" */
1068
1069                        if (!strcmp(arg, "auto")) {
1070                                /* From JFS code, to auto-get the size. */
1071                                *blocks =
1072                                    s->s_bdev->bd_inode->i_size >> s->
1073                                    s_blocksize_bits;
1074                        } else {
1075                                *blocks = simple_strtoul(arg, &p, 0);
1076                                if (*p != '\0') {
1077                                        /* NNN does not look like a number */
1078                                        reiserfs_warning(s, "super-6507",
1079                                                         "bad value %s for "
1080                                                         "-oresize\n", arg);
1081                                        return 0;
1082                                }
1083                        }
1084                }
1085
1086                if (c == 'c') {
1087                        char *p = NULL;
1088                        unsigned long val = simple_strtoul(arg, &p, 0);
1089                        /* commit=NNN (time in seconds) */
1090                        if (*p != '\0' || val >= (unsigned int)-1) {
1091                                reiserfs_warning(s, "super-6508",
1092                                                 "bad value %s for -ocommit\n",
1093                                                 arg);
1094                                return 0;
1095                        }
1096                        *commit_max_age = (unsigned int)val;
1097                }
1098
1099                if (c == 'w') {
1100                        reiserfs_warning(s, "super-6509", "nolargeio option "
1101                                         "is no longer supported");
1102                        return 0;
1103                }
1104
1105                if (c == 'j') {
1106                        if (arg && *arg && jdev_name) {
1107                                if (*jdev_name) {       //Hm, already assigned?
1108                                        reiserfs_warning(s, "super-6510",
1109                                                         "journal device was "
1110                                                         "already specified to "
1111                                                         "be %s", *jdev_name);
1112                                        return 0;
1113                                }
1114                                *jdev_name = arg;
1115                        }
1116                }
1117#ifdef CONFIG_QUOTA
1118                if (c == 'u' || c == 'g') {
1119                        int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
1120
1121                        if (sb_any_quota_loaded(s) &&
1122                            (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) {
1123                                reiserfs_warning(s, "super-6511",
1124                                                 "cannot change journaled "
1125                                                 "quota options when quota "
1126                                                 "turned on.");
1127                                return 0;
1128                        }
1129                        if (*arg) {     /* Some filename specified? */
1130                                if (REISERFS_SB(s)->s_qf_names[qtype]
1131                                    && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
1132                                              arg)) {
1133                                        reiserfs_warning(s, "super-6512",
1134                                                         "%s quota file "
1135                                                         "already specified.",
1136                                                         QTYPE2NAME(qtype));
1137                                        return 0;
1138                                }
1139                                if (strchr(arg, '/')) {
1140                                        reiserfs_warning(s, "super-6513",
1141                                                         "quotafile must be "
1142                                                         "on filesystem root.");
1143                                        return 0;
1144                                }
1145                                qf_names[qtype] =
1146                                    kmalloc(strlen(arg) + 1, GFP_KERNEL);
1147                                if (!qf_names[qtype]) {
1148                                        reiserfs_warning(s, "reiserfs-2502",
1149                                                         "not enough memory "
1150                                                         "for storing "
1151                                                         "quotafile name.");
1152                                        return 0;
1153                                }
1154                                strcpy(qf_names[qtype], arg);
1155                                if (qtype == USRQUOTA)
1156                                        *mount_options |= 1 << REISERFS_USRQUOTA;
1157                                else
1158                                        *mount_options |= 1 << REISERFS_GRPQUOTA;
1159                        } else {
1160                                if (qf_names[qtype] !=
1161                                    REISERFS_SB(s)->s_qf_names[qtype])
1162                                        kfree(qf_names[qtype]);
1163                                qf_names[qtype] = NULL;
1164                                if (qtype == USRQUOTA)
1165                                        *mount_options &= ~(1 << REISERFS_USRQUOTA);
1166                                else
1167                                        *mount_options &= ~(1 << REISERFS_GRPQUOTA);
1168                        }
1169                }
1170                if (c == 'f') {
1171                        if (!strcmp(arg, "vfsold"))
1172                                *qfmt = QFMT_VFS_OLD;
1173                        else if (!strcmp(arg, "vfsv0"))
1174                                *qfmt = QFMT_VFS_V0;
1175                        else {
1176                                reiserfs_warning(s, "super-6514",
1177                                                 "unknown quota format "
1178                                                 "specified.");
1179                                return 0;
1180                        }
1181                        if (sb_any_quota_loaded(s) &&
1182                            *qfmt != REISERFS_SB(s)->s_jquota_fmt) {
1183                                reiserfs_warning(s, "super-6515",
1184                                                 "cannot change journaled "
1185                                                 "quota options when quota "
1186                                                 "turned on.");
1187                                return 0;
1188                        }
1189                }
1190#else
1191                if (c == 'u' || c == 'g' || c == 'f') {
1192                        reiserfs_warning(s, "reiserfs-2503", "journaled "
1193                                         "quota options not supported.");
1194                        return 0;
1195                }
1196#endif
1197        }
1198
1199#ifdef CONFIG_QUOTA
1200        if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt
1201            && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) {
1202                reiserfs_warning(s, "super-6515",
1203                                 "journaled quota format not specified.");
1204                return 0;
1205        }
1206        if ((!(*mount_options & (1 << REISERFS_USRQUOTA)) &&
1207               sb_has_quota_loaded(s, USRQUOTA)) ||
1208            (!(*mount_options & (1 << REISERFS_GRPQUOTA)) &&
1209               sb_has_quota_loaded(s, GRPQUOTA))) {
1210                reiserfs_warning(s, "super-6516", "quota options must "
1211                                 "be present when quota is turned on.");
1212                return 0;
1213        }
1214#endif
1215
1216        return 1;
1217}
1218
1219static void switch_data_mode(struct super_block *s, unsigned long mode)
1220{
1221        REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
1222                                         (1 << REISERFS_DATA_ORDERED) |
1223                                         (1 << REISERFS_DATA_WRITEBACK));
1224        REISERFS_SB(s)->s_mount_opt |= (1 << mode);
1225}
1226
1227static void handle_data_mode(struct super_block *s, unsigned long mount_options)
1228{
1229        if (mount_options & (1 << REISERFS_DATA_LOG)) {
1230                if (!reiserfs_data_log(s)) {
1231                        switch_data_mode(s, REISERFS_DATA_LOG);
1232                        reiserfs_info(s, "switching to journaled data mode\n");
1233                }
1234        } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
1235                if (!reiserfs_data_ordered(s)) {
1236                        switch_data_mode(s, REISERFS_DATA_ORDERED);
1237                        reiserfs_info(s, "switching to ordered data mode\n");
1238                }
1239        } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
1240                if (!reiserfs_data_writeback(s)) {
1241                        switch_data_mode(s, REISERFS_DATA_WRITEBACK);
1242                        reiserfs_info(s, "switching to writeback data mode\n");
1243                }
1244        }
1245}
1246
1247static void handle_barrier_mode(struct super_block *s, unsigned long bits)
1248{
1249        int flush = (1 << REISERFS_BARRIER_FLUSH);
1250        int none = (1 << REISERFS_BARRIER_NONE);
1251        int all_barrier = flush | none;
1252
1253        if (bits & all_barrier) {
1254                REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1255                if (bits & flush) {
1256                        REISERFS_SB(s)->s_mount_opt |= flush;
1257                        printk("reiserfs: enabling write barrier flush mode\n");
1258                } else if (bits & none) {
1259                        REISERFS_SB(s)->s_mount_opt |= none;
1260                        printk("reiserfs: write barriers turned off\n");
1261                }
1262        }
1263}
1264
1265static void handle_attrs(struct super_block *s)
1266{
1267        struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1268
1269        if (reiserfs_attrs(s)) {
1270                if (old_format_only(s)) {
1271                        reiserfs_warning(s, "super-6517", "cannot support "
1272                                         "attributes on 3.5.x disk format");
1273                        REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1274                        return;
1275                }
1276                if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1277                        reiserfs_warning(s, "super-6518", "cannot support "
1278                                         "attributes until flag is set in "
1279                                         "super-block");
1280                        REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1281                }
1282        }
1283}
1284
1285#ifdef CONFIG_QUOTA
1286static void handle_quota_files(struct super_block *s, char **qf_names,
1287                               unsigned int *qfmt)
1288{
1289        int i;
1290
1291        for (i = 0; i < MAXQUOTAS; i++) {
1292                if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
1293                        kfree(REISERFS_SB(s)->s_qf_names[i]);
1294                REISERFS_SB(s)->s_qf_names[i] = qf_names[i];
1295        }
1296        if (*qfmt)
1297                REISERFS_SB(s)->s_jquota_fmt = *qfmt;
1298}
1299#endif
1300
1301static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1302{
1303        struct reiserfs_super_block *rs;
1304        struct reiserfs_transaction_handle th;
1305        unsigned long blocks;
1306        unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1307        unsigned long safe_mask = 0;
1308        unsigned int commit_max_age = (unsigned int)-1;
1309        struct reiserfs_journal *journal = SB_JOURNAL(s);
1310        char *new_opts = kstrdup(arg, GFP_KERNEL);
1311        int err;
1312        char *qf_names[MAXQUOTAS];
1313        unsigned int qfmt = 0;
1314#ifdef CONFIG_QUOTA
1315        int i;
1316#endif
1317
1318        reiserfs_write_lock(s);
1319
1320#ifdef CONFIG_QUOTA
1321        memcpy(qf_names, REISERFS_SB(s)->s_qf_names, sizeof(qf_names));
1322#endif
1323
1324        rs = SB_DISK_SUPER_BLOCK(s);
1325
1326        if (!reiserfs_parse_options
1327            (s, arg, &mount_options, &blocks, NULL, &commit_max_age,
1328            qf_names, &qfmt)) {
1329#ifdef CONFIG_QUOTA
1330                for (i = 0; i < MAXQUOTAS; i++)
1331                        if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
1332                                kfree(qf_names[i]);
1333#endif
1334                err = -EINVAL;
1335                goto out_unlock;
1336        }
1337#ifdef CONFIG_QUOTA
1338        handle_quota_files(s, qf_names, &qfmt);
1339#endif
1340
1341        handle_attrs(s);
1342
1343        /* Add options that are safe here */
1344        safe_mask |= 1 << REISERFS_SMALLTAIL;
1345        safe_mask |= 1 << REISERFS_LARGETAIL;
1346        safe_mask |= 1 << REISERFS_NO_BORDER;
1347        safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
1348        safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
1349        safe_mask |= 1 << REISERFS_TEST4;
1350        safe_mask |= 1 << REISERFS_ATTRS;
1351        safe_mask |= 1 << REISERFS_XATTRS_USER;
1352        safe_mask |= 1 << REISERFS_POSIXACL;
1353        safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
1354        safe_mask |= 1 << REISERFS_BARRIER_NONE;
1355        safe_mask |= 1 << REISERFS_ERROR_RO;
1356        safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
1357        safe_mask |= 1 << REISERFS_ERROR_PANIC;
1358        safe_mask |= 1 << REISERFS_USRQUOTA;
1359        safe_mask |= 1 << REISERFS_GRPQUOTA;
1360
1361        /* Update the bitmask, taking care to keep
1362         * the bits we're not allowed to change here */
1363        REISERFS_SB(s)->s_mount_opt =
1364            (REISERFS_SB(s)->
1365             s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
1366
1367        if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
1368                journal->j_max_commit_age = commit_max_age;
1369                journal->j_max_trans_age = commit_max_age;
1370        } else if (commit_max_age == 0) {
1371                /* 0 means restore defaults. */
1372                journal->j_max_commit_age = journal->j_default_max_commit_age;
1373                journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
1374        }
1375
1376        if (blocks) {
1377                err = reiserfs_resize(s, blocks);
1378                if (err != 0)
1379                        goto out_unlock;
1380        }
1381
1382        if (*mount_flags & MS_RDONLY) {
1383                reiserfs_xattr_init(s, *mount_flags);
1384                /* remount read-only */
1385                if (s->s_flags & MS_RDONLY)
1386                        /* it is read-only already */
1387                        goto out_ok;
1388
1389                /*
1390                 * Drop write lock. Quota will retake it when needed and lock
1391                 * ordering requires calling dquot_suspend() without it.
1392                 */
1393                reiserfs_write_unlock(s);
1394                err = dquot_suspend(s, -1);
1395                if (err < 0)
1396                        goto out_err;
1397                reiserfs_write_lock(s);
1398
1399                /* try to remount file system with read-only permissions */
1400                if (sb_umount_state(rs) == REISERFS_VALID_FS
1401                    || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1402                        goto out_ok;
1403                }
1404
1405                err = journal_begin(&th, s, 10);
1406                if (err)
1407                        goto out_unlock;
1408
1409                /* Mounting a rw partition read-only. */
1410                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1411                set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
1412                journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1413        } else {
1414                /* remount read-write */
1415                if (!(s->s_flags & MS_RDONLY)) {
1416                        reiserfs_xattr_init(s, *mount_flags);
1417                        goto out_ok;    /* We are read-write already */
1418                }
1419
1420                if (reiserfs_is_journal_aborted(journal)) {
1421                        err = journal->j_errno;
1422                        goto out_unlock;
1423                }
1424
1425                handle_data_mode(s, mount_options);
1426                handle_barrier_mode(s, mount_options);
1427                REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1428                s->s_flags &= ~MS_RDONLY;       /* now it is safe to call journal_begin */
1429                err = journal_begin(&th, s, 10);
1430                if (err)
1431                        goto out_unlock;
1432
1433                /* Mount a partition which is read-only, read-write */
1434                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1435                REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1436                s->s_flags &= ~MS_RDONLY;
1437                set_sb_umount_state(rs, REISERFS_ERROR_FS);
1438                if (!old_format_only(s))
1439                        set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
1440                /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1441                journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1442                REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
1443        }
1444        /* this will force a full flush of all journal lists */
1445        SB_JOURNAL(s)->j_must_wait = 1;
1446        err = journal_end(&th, s, 10);
1447        if (err)
1448                goto out_unlock;
1449
1450        if (!(*mount_flags & MS_RDONLY)) {
1451                /*
1452                 * Drop write lock. Quota will retake it when needed and lock
1453                 * ordering requires calling dquot_resume() without it.
1454                 */
1455                reiserfs_write_unlock(s);
1456                dquot_resume(s, -1);
1457                reiserfs_write_lock(s);
1458                finish_unfinished(s);
1459                reiserfs_xattr_init(s, *mount_flags);
1460        }
1461
1462out_ok:
1463        replace_mount_options(s, new_opts);
1464        reiserfs_write_unlock(s);
1465        return 0;
1466
1467out_unlock:
1468        reiserfs_write_unlock(s);
1469out_err:
1470        kfree(new_opts);
1471        return err;
1472}
1473
1474static int read_super_block(struct super_block *s, int offset)
1475{
1476        struct buffer_head *bh;
1477        struct reiserfs_super_block *rs;
1478        int fs_blocksize;
1479
1480        bh = sb_bread(s, offset / s->s_blocksize);
1481        if (!bh) {
1482                reiserfs_warning(s, "sh-2006",
1483                                 "bread failed (dev %s, block %lu, size %lu)",
1484                                 reiserfs_bdevname(s), offset / s->s_blocksize,
1485                                 s->s_blocksize);
1486                return 1;
1487        }
1488
1489        rs = (struct reiserfs_super_block *)bh->b_data;
1490        if (!is_any_reiserfs_magic_string(rs)) {
1491                brelse(bh);
1492                return 1;
1493        }
1494        //
1495        // ok, reiserfs signature (old or new) found in at the given offset
1496        //
1497        fs_blocksize = sb_blocksize(rs);
1498        brelse(bh);
1499        sb_set_blocksize(s, fs_blocksize);
1500
1501        bh = sb_bread(s, offset / s->s_blocksize);
1502        if (!bh) {
1503                reiserfs_warning(s, "sh-2007",
1504                                 "bread failed (dev %s, block %lu, size %lu)",
1505                                 reiserfs_bdevname(s), offset / s->s_blocksize,
1506                                 s->s_blocksize);
1507                return 1;
1508        }
1509
1510        rs = (struct reiserfs_super_block *)bh->b_data;
1511        if (sb_blocksize(rs) != s->s_blocksize) {
1512                reiserfs_warning(s, "sh-2011", "can't find a reiserfs "
1513                                 "filesystem on (dev %s, block %Lu, size %lu)",
1514                                 reiserfs_bdevname(s),
1515                                 (unsigned long long)bh->b_blocknr,
1516                                 s->s_blocksize);
1517                brelse(bh);
1518                return 1;
1519        }
1520
1521        if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1522                brelse(bh);
1523                reiserfs_warning(s, "super-6519", "Unfinished reiserfsck "
1524                                 "--rebuild-tree run detected. Please run\n"
1525                                 "reiserfsck --rebuild-tree and wait for a "
1526                                 "completion. If that fails\n"
1527                                 "get newer reiserfsprogs package");
1528                return 1;
1529        }
1530
1531        SB_BUFFER_WITH_SB(s) = bh;
1532        SB_DISK_SUPER_BLOCK(s) = rs;
1533
1534        if (is_reiserfs_jr(rs)) {
1535                /* magic is of non-standard journal filesystem, look at s_version to
1536                   find which format is in use */
1537                if (sb_version(rs) == REISERFS_VERSION_2)
1538                        reiserfs_info(s, "found reiserfs format \"3.6\""
1539                                      " with non-standard journal\n");
1540                else if (sb_version(rs) == REISERFS_VERSION_1)
1541                        reiserfs_info(s, "found reiserfs format \"3.5\""
1542                                      " with non-standard journal\n");
1543                else {
1544                        reiserfs_warning(s, "sh-2012", "found unknown "
1545                                         "format \"%u\" of reiserfs with "
1546                                         "non-standard magic", sb_version(rs));
1547                        return 1;
1548                }
1549        } else
1550                /* s_version of standard format may contain incorrect information,
1551                   so we just look at the magic string */
1552                reiserfs_info(s,
1553                              "found reiserfs format \"%s\" with standard journal\n",
1554                              is_reiserfs_3_5(rs) ? "3.5" : "3.6");
1555
1556        s->s_op = &reiserfs_sops;
1557        s->s_export_op = &reiserfs_export_ops;
1558#ifdef CONFIG_QUOTA
1559        s->s_qcop = &reiserfs_qctl_operations;
1560        s->dq_op = &reiserfs_quota_operations;
1561#endif
1562
1563        /* new format is limited by the 32 bit wide i_blocks field, want to
1564         ** be one full block below that.
1565         */
1566        s->s_maxbytes = (512LL << 32) - s->s_blocksize;
1567        return 0;
1568}
1569
1570/* after journal replay, reread all bitmap and super blocks */
1571static int reread_meta_blocks(struct super_block *s)
1572{
1573        ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1574        wait_on_buffer(SB_BUFFER_WITH_SB(s));
1575        if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1576                reiserfs_warning(s, "reiserfs-2504", "error reading the super");
1577                return 1;
1578        }
1579
1580        return 0;
1581}
1582
1583/////////////////////////////////////////////////////
1584// hash detection stuff
1585
1586// if root directory is empty - we set default - Yura's - hash and
1587// warn about it
1588// FIXME: we look for only one name in a directory. If tea and yura
1589// bith have the same value - we ask user to send report to the
1590// mailing list
1591static __u32 find_hash_out(struct super_block *s)
1592{
1593        int retval;
1594        struct inode *inode;
1595        struct cpu_key key;
1596        INITIALIZE_PATH(path);
1597        struct reiserfs_dir_entry de;
1598        __u32 hash = DEFAULT_HASH;
1599
1600        inode = s->s_root->d_inode;
1601
1602        do {                    // Some serious "goto"-hater was there ;)
1603                u32 teahash, r5hash, yurahash;
1604
1605                make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1606                retval = search_by_entry_key(s, &key, &path, &de);
1607                if (retval == IO_ERROR) {
1608                        pathrelse(&path);
1609                        return UNSET_HASH;
1610                }
1611                if (retval == NAME_NOT_FOUND)
1612                        de.de_entry_num--;
1613                set_de_name_and_namelen(&de);
1614                if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
1615                        /* allow override in this case */
1616                        if (reiserfs_rupasov_hash(s)) {
1617                                hash = YURA_HASH;
1618                        }
1619                        reiserfs_info(s, "FS seems to be empty, autodetect "
1620                                         "is using the default hash\n");
1621                        break;
1622                }
1623                r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
1624                teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
1625                yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
1626                if (((teahash == r5hash)
1627                     &&
1628                     (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
1629                      == r5hash)) || ((teahash == yurahash)
1630                                      && (yurahash ==
1631                                          GET_HASH_VALUE(deh_offset
1632                                                         (&
1633                                                          (de.
1634                                                           de_deh[de.
1635                                                                  de_entry_num])))))
1636                    || ((r5hash == yurahash)
1637                        && (yurahash ==
1638                            GET_HASH_VALUE(deh_offset
1639                                           (&(de.de_deh[de.de_entry_num])))))) {
1640                        reiserfs_warning(s, "reiserfs-2506", "Unable to "
1641                                         "automatically detect hash function. "
1642                                         "Please mount with -o "
1643                                         "hash={tea,rupasov,r5}");
1644                        hash = UNSET_HASH;
1645                        break;
1646                }
1647                if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
1648                    yurahash)
1649                        hash = YURA_HASH;
1650                else if (GET_HASH_VALUE
1651                         (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
1652                        hash = TEA_HASH;
1653                else if (GET_HASH_VALUE
1654                         (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1655                        hash = R5_HASH;
1656                else {
1657                        reiserfs_warning(s, "reiserfs-2506",
1658                                         "Unrecognised hash function");
1659                        hash = UNSET_HASH;
1660                }
1661        } while (0);
1662
1663        pathrelse(&path);
1664        return hash;
1665}
1666
1667// finds out which hash names are sorted with
1668static int what_hash(struct super_block *s)
1669{
1670        __u32 code;
1671
1672        code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
1673
1674        /* reiserfs_hash_detect() == true if any of the hash mount options
1675         ** were used.  We must check them to make sure the user isn't
1676         ** using a bad hash value
1677         */
1678        if (code == UNSET_HASH || reiserfs_hash_detect(s))
1679                code = find_hash_out(s);
1680
1681        if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1682                /* detection has found the hash, and we must check against the
1683                 ** mount options
1684                 */
1685                if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1686                        reiserfs_warning(s, "reiserfs-2507",
1687                                         "Error, %s hash detected, "
1688                                         "unable to force rupasov hash",
1689                                         reiserfs_hashname(code));
1690                        code = UNSET_HASH;
1691                } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1692                        reiserfs_warning(s, "reiserfs-2508",
1693                                         "Error, %s hash detected, "
1694                                         "unable to force tea hash",
1695                                         reiserfs_hashname(code));
1696                        code = UNSET_HASH;
1697                } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1698                        reiserfs_warning(s, "reiserfs-2509",
1699                                         "Error, %s hash detected, "
1700                                         "unable to force r5 hash",
1701                                         reiserfs_hashname(code));
1702                        code = UNSET_HASH;
1703                }
1704        } else {
1705                /* find_hash_out was not called or could not determine the hash */
1706                if (reiserfs_rupasov_hash(s)) {
1707                        code = YURA_HASH;
1708                } else if (reiserfs_tea_hash(s)) {
1709                        code = TEA_HASH;
1710                } else if (reiserfs_r5_hash(s)) {
1711                        code = R5_HASH;
1712                }
1713        }
1714
1715        /* if we are mounted RW, and we have a new valid hash code, update
1716         ** the super
1717         */
1718        if (code != UNSET_HASH &&
1719            !(s->s_flags & MS_RDONLY) &&
1720            code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1721                set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1722        }
1723        return code;
1724}
1725
1726// return pointer to appropriate function
1727static hashf_t hash_function(struct super_block *s)
1728{
1729        switch (what_hash(s)) {
1730        case TEA_HASH:
1731                reiserfs_info(s, "Using tea hash to sort names\n");
1732                return keyed_hash;
1733        case YURA_HASH:
1734                reiserfs_info(s, "Using rupasov hash to sort names\n");
1735                return yura_hash;
1736        case R5_HASH:
1737                reiserfs_info(s, "Using r5 hash to sort names\n");
1738                return r5_hash;
1739        }
1740        return NULL;
1741}
1742
1743// this is used to set up correct value for old partitions
1744static int function2code(hashf_t func)
1745{
1746        if (func == keyed_hash)
1747                return TEA_HASH;
1748        if (func == yura_hash)
1749                return YURA_HASH;
1750        if (func == r5_hash)
1751                return R5_HASH;
1752
1753        BUG();                  // should never happen
1754
1755        return 0;
1756}
1757
1758#define SWARN(silent, s, id, ...)                       \
1759        if (!(silent))                          \
1760                reiserfs_warning(s, id, __VA_ARGS__)
1761
1762static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1763{
1764        struct inode *root_inode;
1765        struct reiserfs_transaction_handle th;
1766        int old_format = 0;
1767        unsigned long blocks;
1768        unsigned int commit_max_age = 0;
1769        int jinit_done = 0;
1770        struct reiserfs_iget_args args;
1771        struct reiserfs_super_block *rs;
1772        char *jdev_name;
1773        struct reiserfs_sb_info *sbi;
1774        int errval = -EINVAL;
1775        char *qf_names[MAXQUOTAS] = {};
1776        unsigned int qfmt = 0;
1777
1778        save_mount_options(s, data);
1779
1780        sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1781        if (!sbi)
1782                return -ENOMEM;
1783        s->s_fs_info = sbi;
1784        /* Set default values for options: non-aggressive tails, RO on errors */
1785        sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1786        sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1787        sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
1788        /* no preallocation minimum, be smart in
1789           reiserfs_file_write instead */
1790        sbi->s_alloc_options.preallocmin = 0;
1791        /* Preallocate by 16 blocks (17-1) at once */
1792        sbi->s_alloc_options.preallocsize = 17;
1793        /* setup default block allocator options */
1794        reiserfs_init_alloc_options(s);
1795
1796        spin_lock_init(&sbi->old_work_lock);
1797        INIT_DELAYED_WORK(&sbi->old_work, flush_old_commits);
1798        mutex_init(&sbi->lock);
1799        sbi->lock_depth = -1;
1800
1801        jdev_name = NULL;
1802        if (reiserfs_parse_options
1803            (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
1804             &commit_max_age, qf_names, &qfmt) == 0) {
1805                goto error_unlocked;
1806        }
1807        if (jdev_name && jdev_name[0]) {
1808                sbi->s_jdev = kstrdup(jdev_name, GFP_KERNEL);
1809                if (!sbi->s_jdev) {
1810                        SWARN(silent, s, "", "Cannot allocate memory for "
1811                                "journal device name");
1812                        goto error;
1813                }
1814        }
1815#ifdef CONFIG_QUOTA
1816        handle_quota_files(s, qf_names, &qfmt);
1817#endif
1818
1819        if (blocks) {
1820                SWARN(silent, s, "jmacd-7", "resize option for remount only");
1821                goto error_unlocked;
1822        }
1823
1824        /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1825        if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1826                old_format = 1;
1827        /* try new format (64-th 1k block), which can contain reiserfs super block */
1828        else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1829                SWARN(silent, s, "sh-2021", "can not find reiserfs on %s",
1830                      reiserfs_bdevname(s));
1831                goto error_unlocked;
1832        }
1833
1834        rs = SB_DISK_SUPER_BLOCK(s);
1835        /* Let's do basic sanity check to verify that underlying device is not
1836           smaller than the filesystem. If the check fails then abort and scream,
1837           because bad stuff will happen otherwise. */
1838        if (s->s_bdev && s->s_bdev->bd_inode
1839            && i_size_read(s->s_bdev->bd_inode) <
1840            sb_block_count(rs) * sb_blocksize(rs)) {
1841                SWARN(silent, s, "", "Filesystem cannot be "
1842                      "mounted because it is bigger than the device");
1843                SWARN(silent, s, "", "You may need to run fsck "
1844                      "or increase size of your LVM partition");
1845                SWARN(silent, s, "", "Or may be you forgot to "
1846                      "reboot after fdisk when it told you to");
1847                goto error_unlocked;
1848        }
1849
1850        sbi->s_mount_state = SB_REISERFS_STATE(s);
1851        sbi->s_mount_state = REISERFS_VALID_FS;
1852
1853        if ((errval = reiserfs_init_bitmap_cache(s))) {
1854                SWARN(silent, s, "jmacd-8", "unable to read bitmap");
1855                goto error_unlocked;
1856        }
1857
1858        errval = -EINVAL;
1859#ifdef CONFIG_REISERFS_CHECK
1860        SWARN(silent, s, "", "CONFIG_REISERFS_CHECK is set ON");
1861        SWARN(silent, s, "", "- it is slow mode for debugging.");
1862#endif
1863
1864        /* make data=ordered the default */
1865        if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1866            !reiserfs_data_writeback(s)) {
1867                sbi->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1868        }
1869
1870        if (reiserfs_data_log(s)) {
1871                reiserfs_info(s, "using journaled data mode\n");
1872        } else if (reiserfs_data_ordered(s)) {
1873                reiserfs_info(s, "using ordered data mode\n");
1874        } else {
1875                reiserfs_info(s, "using writeback data mode\n");
1876        }
1877        if (reiserfs_barrier_flush(s)) {
1878                printk("reiserfs: using flush barriers\n");
1879        }
1880
1881        // set_device_ro(s->s_dev, 1) ;
1882        if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1883                SWARN(silent, s, "sh-2022",
1884                      "unable to initialize journal space");
1885                goto error_unlocked;
1886        } else {
1887                jinit_done = 1; /* once this is set, journal_release must be called
1888                                 ** if we error out of the mount
1889                                 */
1890        }
1891
1892        if (reread_meta_blocks(s)) {
1893                SWARN(silent, s, "jmacd-9",
1894                      "unable to reread meta blocks after journal init");
1895                goto error_unlocked;
1896        }
1897
1898        if (replay_only(s))
1899                goto error_unlocked;
1900
1901        if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1902                SWARN(silent, s, "clm-7000",
1903                      "Detected readonly device, marking FS readonly");
1904                s->s_flags |= MS_RDONLY;
1905        }
1906        args.objectid = REISERFS_ROOT_OBJECTID;
1907        args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
1908        root_inode =
1909            iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1910                         reiserfs_init_locked_inode, (void *)(&args));
1911        if (!root_inode) {
1912                SWARN(silent, s, "jmacd-10", "get root inode failed");
1913                goto error_unlocked;
1914        }
1915
1916        /*
1917         * This path assumed to be called with the BKL in the old times.
1918         * Now we have inherited the big reiserfs lock from it and many
1919         * reiserfs helpers called in the mount path and elsewhere require
1920         * this lock to be held even if it's not always necessary. Let's be
1921         * conservative and hold it early. The window can be reduced after
1922         * careful review of the code.
1923         */
1924        reiserfs_write_lock(s);
1925
1926        if (root_inode->i_state & I_NEW) {
1927                reiserfs_read_locked_inode(root_inode, &args);
1928                unlock_new_inode(root_inode);
1929        }
1930
1931        s->s_root = d_make_root(root_inode);
1932        if (!s->s_root)
1933                goto error;
1934        // define and initialize hash function
1935        sbi->s_hash_function = hash_function(s);
1936        if (sbi->s_hash_function == NULL) {
1937                dput(s->s_root);
1938                s->s_root = NULL;
1939                goto error;
1940        }
1941
1942        if (is_reiserfs_3_5(rs)
1943            || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
1944                set_bit(REISERFS_3_5, &(sbi->s_properties));
1945        else if (old_format)
1946                set_bit(REISERFS_OLD_FORMAT, &(sbi->s_properties));
1947        else
1948                set_bit(REISERFS_3_6, &(sbi->s_properties));
1949
1950        if (!(s->s_flags & MS_RDONLY)) {
1951
1952                errval = journal_begin(&th, s, 1);
1953                if (errval) {
1954                        dput(s->s_root);
1955                        s->s_root = NULL;
1956                        goto error;
1957                }
1958                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1959
1960                set_sb_umount_state(rs, REISERFS_ERROR_FS);
1961                set_sb_fs_state(rs, 0);
1962
1963                /* Clear out s_bmap_nr if it would wrap. We can handle this
1964                 * case, but older revisions can't. This will cause the
1965                 * file system to fail mount on those older implementations,
1966                 * avoiding corruption. -jeffm */
1967                if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
1968                    sb_bmap_nr(rs) != 0) {
1969                        reiserfs_warning(s, "super-2030", "This file system "
1970                                        "claims to use %u bitmap blocks in "
1971                                        "its super block, but requires %u. "
1972                                        "Clearing to zero.", sb_bmap_nr(rs),
1973                                        reiserfs_bmap_count(s));
1974
1975                        set_sb_bmap_nr(rs, 0);
1976                }
1977
1978                if (old_format_only(s)) {
1979                        /* filesystem of format 3.5 either with standard or non-standard
1980                           journal */
1981                        if (convert_reiserfs(s)) {
1982                                /* and -o conv is given */
1983                                if (!silent)
1984                                        reiserfs_info(s,
1985                                                      "converting 3.5 filesystem to the 3.6 format");
1986
1987                                if (is_reiserfs_3_5(rs))
1988                                        /* put magic string of 3.6 format. 2.2 will not be able to
1989                                           mount this filesystem anymore */
1990                                        memcpy(rs->s_v1.s_magic,
1991                                               reiserfs_3_6_magic_string,
1992                                               sizeof
1993                                               (reiserfs_3_6_magic_string));
1994
1995                                set_sb_version(rs, REISERFS_VERSION_2);
1996                                reiserfs_convert_objectid_map_v1(s);
1997                                set_bit(REISERFS_3_6, &(sbi->s_properties));
1998                                clear_bit(REISERFS_3_5, &(sbi->s_properties));
1999                        } else if (!silent) {
2000                                reiserfs_info(s, "using 3.5.x disk format\n");
2001                        }
2002                } else
2003                        set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
2004
2005
2006                journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
2007                errval = journal_end(&th, s, 1);
2008                if (errval) {
2009                        dput(s->s_root);
2010                        s->s_root = NULL;
2011                        goto error;
2012                }
2013
2014                if ((errval = reiserfs_lookup_privroot(s)) ||
2015                    (errval = reiserfs_xattr_init(s, s->s_flags))) {
2016                        dput(s->s_root);
2017                        s->s_root = NULL;
2018                        goto error;
2019                }
2020
2021                /* look for files which were to be removed in previous session */
2022                finish_unfinished(s);
2023        } else {
2024                if (old_format_only(s) && !silent) {
2025                        reiserfs_info(s, "using 3.5.x disk format\n");
2026                }
2027
2028                if ((errval = reiserfs_lookup_privroot(s)) ||
2029                    (errval = reiserfs_xattr_init(s, s->s_flags))) {
2030                        dput(s->s_root);
2031                        s->s_root = NULL;
2032                        goto error;
2033                }
2034        }
2035        // mark hash in super block: it could be unset. overwrite should be ok
2036        set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
2037
2038        handle_attrs(s);
2039
2040        reiserfs_proc_info_init(s);
2041
2042        init_waitqueue_head(&(sbi->s_wait));
2043        spin_lock_init(&sbi->bitmap_lock);
2044
2045        reiserfs_write_unlock(s);
2046
2047        return (0);
2048
2049error:
2050        reiserfs_write_unlock(s);
2051
2052error_unlocked:
2053        /* kill the commit thread, free journal ram */
2054        if (jinit_done) {
2055                reiserfs_write_lock(s);
2056                journal_release_error(NULL, s);
2057                reiserfs_write_unlock(s);
2058        }
2059
2060        cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
2061
2062        reiserfs_free_bitmap_cache(s);
2063        if (SB_BUFFER_WITH_SB(s))
2064                brelse(SB_BUFFER_WITH_SB(s));
2065#ifdef CONFIG_QUOTA
2066        {
2067                int j;
2068                for (j = 0; j < MAXQUOTAS; j++)
2069                        kfree(qf_names[j]);
2070        }
2071#endif
2072        kfree(sbi);
2073
2074        s->s_fs_info = NULL;
2075        return errval;
2076}
2077
2078static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
2079{
2080        struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
2081
2082        buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
2083        buf->f_bfree = sb_free_blocks(rs);
2084        buf->f_bavail = buf->f_bfree;
2085        buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
2086        buf->f_bsize = dentry->d_sb->s_blocksize;
2087        /* changed to accommodate gcc folks. */
2088        buf->f_type = REISERFS_SUPER_MAGIC;
2089        buf->f_fsid.val[0] = (u32)crc32_le(0, rs->s_uuid, sizeof(rs->s_uuid)/2);
2090        buf->f_fsid.val[1] = (u32)crc32_le(0, rs->s_uuid + sizeof(rs->s_uuid)/2,
2091                                sizeof(rs->s_uuid)/2);
2092
2093        return 0;
2094}
2095
2096#ifdef CONFIG_QUOTA
2097static int reiserfs_write_dquot(struct dquot *dquot)
2098{
2099        struct reiserfs_transaction_handle th;
2100        int ret, err;
2101
2102        reiserfs_write_lock(dquot->dq_sb);
2103        ret =
2104            journal_begin(&th, dquot->dq_sb,
2105                          REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
2106        if (ret)
2107                goto out;
2108        reiserfs_write_unlock(dquot->dq_sb);
2109        ret = dquot_commit(dquot);
2110        reiserfs_write_lock(dquot->dq_sb);
2111        err =
2112            journal_end(&th, dquot->dq_sb,
2113                        REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
2114        if (!ret && err)
2115                ret = err;
2116out:
2117        reiserfs_write_unlock(dquot->dq_sb);
2118        return ret;
2119}
2120
2121static int reiserfs_acquire_dquot(struct dquot *dquot)
2122{
2123        struct reiserfs_transaction_handle th;
2124        int ret, err;
2125
2126        reiserfs_write_lock(dquot->dq_sb);
2127        ret =
2128            journal_begin(&th, dquot->dq_sb,
2129                          REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2130        if (ret)
2131                goto out;
2132        reiserfs_write_unlock(dquot->dq_sb);
2133        ret = dquot_acquire(dquot);
2134        reiserfs_write_lock(dquot->dq_sb);
2135        err =
2136            journal_end(&th, dquot->dq_sb,
2137                        REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2138        if (!ret && err)
2139                ret = err;
2140out:
2141        reiserfs_write_unlock(dquot->dq_sb);
2142        return ret;
2143}
2144
2145static int reiserfs_release_dquot(struct dquot *dquot)
2146{
2147        struct reiserfs_transaction_handle th;
2148        int ret, err;
2149
2150        reiserfs_write_lock(dquot->dq_sb);
2151        ret =
2152            journal_begin(&th, dquot->dq_sb,
2153                          REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2154        reiserfs_write_unlock(dquot->dq_sb);
2155        if (ret) {
2156                /* Release dquot anyway to avoid endless cycle in dqput() */
2157                dquot_release(dquot);
2158                goto out;
2159        }
2160        ret = dquot_release(dquot);
2161        reiserfs_write_lock(dquot->dq_sb);
2162        err =
2163            journal_end(&th, dquot->dq_sb,
2164                        REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2165        if (!ret && err)
2166                ret = err;
2167        reiserfs_write_unlock(dquot->dq_sb);
2168out:
2169        return ret;
2170}
2171
2172static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
2173{
2174        /* Are we journaling quotas? */
2175        if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
2176            REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
2177                dquot_mark_dquot_dirty(dquot);
2178                return reiserfs_write_dquot(dquot);
2179        } else
2180                return dquot_mark_dquot_dirty(dquot);
2181}
2182
2183static int reiserfs_write_info(struct super_block *sb, int type)
2184{
2185        struct reiserfs_transaction_handle th;
2186        int ret, err;
2187
2188        /* Data block + inode block */
2189        reiserfs_write_lock(sb);
2190        ret = journal_begin(&th, sb, 2);
2191        if (ret)
2192                goto out;
2193        reiserfs_write_unlock(sb);
2194        ret = dquot_commit_info(sb, type);
2195        reiserfs_write_lock(sb);
2196        err = journal_end(&th, sb, 2);
2197        if (!ret && err)
2198                ret = err;
2199out:
2200        reiserfs_write_unlock(sb);
2201        return ret;
2202}
2203
2204/*
2205 * Turn on quotas during mount time - we need to find the quota file and such...
2206 */
2207static int reiserfs_quota_on_mount(struct super_block *sb, int type)
2208{
2209        return dquot_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
2210                                        REISERFS_SB(sb)->s_jquota_fmt, type);
2211}
2212
2213/*
2214 * Standard function to be called on quota_on
2215 */
2216static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2217                             struct path *path)
2218{
2219        int err;
2220        struct inode *inode;
2221        struct reiserfs_transaction_handle th;
2222        int opt = type == USRQUOTA ? REISERFS_USRQUOTA : REISERFS_GRPQUOTA;
2223
2224        reiserfs_write_lock(sb);
2225        if (!(REISERFS_SB(sb)->s_mount_opt & (1 << opt))) {
2226                err = -EINVAL;
2227                goto out;
2228        }
2229
2230        /* Quotafile not on the same filesystem? */
2231        if (path->dentry->d_sb != sb) {
2232                err = -EXDEV;
2233                goto out;
2234        }
2235        inode = path->dentry->d_inode;
2236        /* We must not pack tails for quota files on reiserfs for quota IO to work */
2237        if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
2238                err = reiserfs_unpack(inode, NULL);
2239                if (err) {
2240                        reiserfs_warning(sb, "super-6520",
2241                                "Unpacking tail of quota file failed"
2242                                " (%d). Cannot turn on quotas.", err);
2243                        err = -EINVAL;
2244                        goto out;
2245                }
2246                mark_inode_dirty(inode);
2247        }
2248        /* Journaling quota? */
2249        if (REISERFS_SB(sb)->s_qf_names[type]) {
2250                /* Quotafile not of fs root? */
2251                if (path->dentry->d_parent != sb->s_root)
2252                        reiserfs_warning(sb, "super-6521",
2253                                 "Quota file not on filesystem root. "
2254                                 "Journalled quota will not work.");
2255        }
2256
2257        /*
2258         * When we journal data on quota file, we have to flush journal to see
2259         * all updates to the file when we bypass pagecache...
2260         */
2261        if (reiserfs_file_data_log(inode)) {
2262                /* Just start temporary transaction and finish it */
2263                err = journal_begin(&th, sb, 1);
2264                if (err)
2265                        goto out;
2266                err = journal_end_sync(&th, sb, 1);
2267                if (err)
2268                        goto out;
2269        }
2270        reiserfs_write_unlock(sb);
2271        return dquot_quota_on(sb, type, format_id, path);
2272out:
2273        reiserfs_write_unlock(sb);
2274        return err;
2275}
2276
2277/* Read data from quotafile - avoid pagecache and such because we cannot afford
2278 * acquiring the locks... As quota files are never truncated and quota code
2279 * itself serializes the operations (and no one else should touch the files)
2280 * we don't have to be afraid of races */
2281static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2282                                   size_t len, loff_t off)
2283{
2284        struct inode *inode = sb_dqopt(sb)->files[type];
2285        unsigned long blk = off >> sb->s_blocksize_bits;
2286        int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2287        size_t toread;
2288        struct buffer_head tmp_bh, *bh;
2289        loff_t i_size = i_size_read(inode);
2290
2291        if (off > i_size)
2292                return 0;
2293        if (off + len > i_size)
2294                len = i_size - off;
2295        toread = len;
2296        while (toread > 0) {
2297                tocopy =
2298                    sb->s_blocksize - offset <
2299                    toread ? sb->s_blocksize - offset : toread;
2300                tmp_bh.b_state = 0;
2301                /* Quota files are without tails so we can safely use this function */
2302                reiserfs_write_lock(sb);
2303                err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
2304                reiserfs_write_unlock(sb);
2305                if (err)
2306                        return err;
2307                if (!buffer_mapped(&tmp_bh))    /* A hole? */
2308                        memset(data, 0, tocopy);
2309                else {
2310                        bh = sb_bread(sb, tmp_bh.b_blocknr);
2311                        if (!bh)
2312                                return -EIO;
2313                        memcpy(data, bh->b_data + offset, tocopy);
2314                        brelse(bh);
2315                }
2316                offset = 0;
2317                toread -= tocopy;
2318                data += tocopy;
2319                blk++;
2320        }
2321        return len;
2322}
2323
2324/* Write to quotafile (we know the transaction is already started and has
2325 * enough credits) */
2326static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2327                                    const char *data, size_t len, loff_t off)
2328{
2329        struct inode *inode = sb_dqopt(sb)->files[type];
2330        unsigned long blk = off >> sb->s_blocksize_bits;
2331        int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2332        int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
2333        size_t towrite = len;
2334        struct buffer_head tmp_bh, *bh;
2335
2336        if (!current->journal_info) {
2337                printk(KERN_WARNING "reiserfs: Quota write (off=%Lu, len=%Lu)"
2338                        " cancelled because transaction is not started.\n",
2339                        (unsigned long long)off, (unsigned long long)len);
2340                return -EIO;
2341        }
2342        while (towrite > 0) {
2343                tocopy = sb->s_blocksize - offset < towrite ?
2344                    sb->s_blocksize - offset : towrite;
2345                tmp_bh.b_state = 0;
2346                reiserfs_write_lock(sb);
2347                err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
2348                reiserfs_write_unlock(sb);
2349                if (err)
2350                        goto out;
2351                if (offset || tocopy != sb->s_blocksize)
2352                        bh = sb_bread(sb, tmp_bh.b_blocknr);
2353                else
2354                        bh = sb_getblk(sb, tmp_bh.b_blocknr);
2355                if (!bh) {
2356                        err = -EIO;
2357                        goto out;
2358                }
2359                lock_buffer(bh);
2360                memcpy(bh->b_data + offset, data, tocopy);
2361                flush_dcache_page(bh->b_page);
2362                set_buffer_uptodate(bh);
2363                unlock_buffer(bh);
2364                reiserfs_write_lock(sb);
2365                reiserfs_prepare_for_journal(sb, bh, 1);
2366                journal_mark_dirty(current->journal_info, sb, bh);
2367                if (!journal_quota)
2368                        reiserfs_add_ordered_list(inode, bh);
2369                reiserfs_write_unlock(sb);
2370                brelse(bh);
2371                offset = 0;
2372                towrite -= tocopy;
2373                data += tocopy;
2374                blk++;
2375        }
2376out:
2377        if (len == towrite)
2378                return err;
2379        if (inode->i_size < off + len - towrite)
2380                i_size_write(inode, off + len - towrite);
2381        inode->i_version++;
2382        inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2383        mark_inode_dirty(inode);
2384        return len - towrite;
2385}
2386
2387#endif
2388
2389static struct dentry *get_super_block(struct file_system_type *fs_type,
2390                           int flags, const char *dev_name,
2391                           void *data)
2392{
2393        return mount_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
2394}
2395
2396static int __init init_reiserfs_fs(void)
2397{
2398        int ret;
2399
2400        if ((ret = init_inodecache())) {
2401                return ret;
2402        }
2403
2404        reiserfs_proc_info_global_init();
2405
2406        ret = register_filesystem(&reiserfs_fs_type);
2407
2408        if (ret == 0) {
2409                return 0;
2410        }
2411
2412        reiserfs_proc_info_global_done();
2413        destroy_inodecache();
2414
2415        return ret;
2416}
2417
2418static void __exit exit_reiserfs_fs(void)
2419{
2420        reiserfs_proc_info_global_done();
2421        unregister_filesystem(&reiserfs_fs_type);
2422        destroy_inodecache();
2423}
2424
2425struct file_system_type reiserfs_fs_type = {
2426        .owner = THIS_MODULE,
2427        .name = "reiserfs",
2428        .mount = get_super_block,
2429        .kill_sb = reiserfs_kill_sb,
2430        .fs_flags = FS_REQUIRES_DEV,
2431};
2432
2433MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2434MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2435MODULE_LICENSE("GPL");
2436
2437module_init(init_reiserfs_fs);
2438module_exit(exit_reiserfs_fs);
2439
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.