~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/reiserfs/super.c

Version: ~ [ linux-5.3-rc4 ] ~ [ linux-5.2.8 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.66 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.138 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.71 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp