blob: ef5e5414e7a83eb9b4295bbaba5464410b11e030 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/config.h>
15#include <linux/module.h>
16#include <linux/vmalloc.h>
17#include <linux/time.h>
18#include <asm/uaccess.h>
19#include <linux/reiserfs_fs.h>
20#include <linux/reiserfs_acl.h>
21#include <linux/reiserfs_xattr.h>
22#include <linux/smp_lock.h>
23#include <linux/init.h>
24#include <linux/blkdev.h>
25#include <linux/buffer_head.h>
26#include <linux/vfs.h>
27#include <linux/namespace.h>
28#include <linux/mount.h>
29#include <linux/namei.h>
30#include <linux/quotaops.h>
31
32struct file_system_type reiserfs_fs_type;
33
34static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
35static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
36static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
37
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038int is_reiserfs_3_5(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040 return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
41 strlen(reiserfs_3_5_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070044int is_reiserfs_3_6(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070046 return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
47 strlen(reiserfs_3_6_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070050int is_reiserfs_jr(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070052 return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
53 strlen(reiserfs_jr_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070056static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070058 return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
59 is_reiserfs_jr(rs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070062static int reiserfs_remount(struct super_block *s, int *flags, char *data);
63static int reiserfs_statfs(struct super_block *s, struct kstatfs *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070065static int reiserfs_sync_fs(struct super_block *s, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070067 if (!(s->s_flags & MS_RDONLY)) {
68 struct reiserfs_transaction_handle th;
69 reiserfs_write_lock(s);
70 if (!journal_begin(&th, s, 1))
71 if (!journal_end_sync(&th, s, 1))
72 reiserfs_flush_old_commits(s);
73 s->s_dirt = 0; /* Even if it's not true.
74 * We'll loop forever in sync_supers otherwise */
75 reiserfs_write_unlock(s);
76 } else {
77 s->s_dirt = 0;
78 }
79 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static void reiserfs_write_super(struct super_block *s)
83{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070084 reiserfs_sync_fs(s, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070087static void reiserfs_write_super_lockfs(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070089 struct reiserfs_transaction_handle th;
90 reiserfs_write_lock(s);
91 if (!(s->s_flags & MS_RDONLY)) {
92 int err = journal_begin(&th, s, 1);
93 if (err) {
94 reiserfs_block_writes(&th);
95 } else {
96 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
97 1);
98 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
99 reiserfs_block_writes(&th);
100 journal_end_sync(&th, s, 1);
101 }
102 }
103 s->s_dirt = 0;
104 reiserfs_write_unlock(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700107static void reiserfs_unlockfs(struct super_block *s)
108{
109 reiserfs_allow_writes(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700112extern const struct in_core_key MAX_IN_CORE_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/* this is used to delete "save link" when there are no items of a
115 file it points to. It can either happen if unlink is completed but
116 "save unlink" removal, or if file has both unlink and truncate
117 pending and as unlink completes first (because key of "save link"
118 protecting unlink is bigger that a key lf "save link" which
119 protects truncate), so there left no items to make truncate
120 completion on */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700121static int remove_save_link_only(struct super_block *s,
122 struct reiserfs_key *key, int oid_free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700124 struct reiserfs_transaction_handle th;
125 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700127 /* we are going to do one balancing */
128 err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
129 if (err)
130 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700132 reiserfs_delete_solid_item(&th, NULL, key);
133 if (oid_free)
134 /* removals are protected by direct items */
135 reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
136
137 return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef CONFIG_QUOTA
141static int reiserfs_quota_on_mount(struct super_block *, int);
142#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/* look for uncompleted unlinks and truncates and complete them */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700145static int finish_unfinished(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700147 INITIALIZE_PATH(path);
148 struct cpu_key max_cpu_key, obj_key;
149 struct reiserfs_key save_link_key;
150 int retval = 0;
151 struct item_head *ih;
152 struct buffer_head *bh;
153 int item_pos;
154 char *item;
155 int done;
156 struct inode *inode;
157 int truncate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700159 int i;
160 int ms_active_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700162
163 /* compose key to look for "save" links */
164 max_cpu_key.version = KEY_FORMAT_3_5;
165 max_cpu_key.on_disk_key.k_dir_id = ~0U;
166 max_cpu_key.on_disk_key.k_objectid = ~0U;
167 set_cpu_key_k_offset(&max_cpu_key, ~0U);
168 max_cpu_key.key_length = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700171 /* Needed for iput() to work correctly and not trash data */
172 if (s->s_flags & MS_ACTIVE) {
173 ms_active_set = 0;
174 } else {
175 ms_active_set = 1;
176 s->s_flags |= MS_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700178 /* Turn on quotas so that they are updated correctly */
179 for (i = 0; i < MAXQUOTAS; i++) {
180 if (REISERFS_SB(s)->s_qf_names[i]) {
181 int ret = reiserfs_quota_on_mount(s, i);
182 if (ret < 0)
183 reiserfs_warning(s,
184 "reiserfs: cannot turn on journalled quota: error %d",
185 ret);
186 }
187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700190 done = 0;
191 REISERFS_SB(s)->s_is_unlinked_ok = 1;
192 while (!retval) {
193 retval = search_item(s, &max_cpu_key, &path);
194 if (retval != ITEM_NOT_FOUND) {
195 reiserfs_warning(s,
196 "vs-2140: finish_unfinished: search_by_key returned %d",
197 retval);
198 break;
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700201 bh = get_last_bh(&path);
202 item_pos = get_item_pos(&path);
203 if (item_pos != B_NR_ITEMS(bh)) {
204 reiserfs_warning(s,
205 "vs-2060: finish_unfinished: wrong position found");
206 break;
207 }
208 item_pos--;
209 ih = B_N_PITEM_HEAD(bh, item_pos);
210
211 if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
212 /* there are no "save" links anymore */
213 break;
214
215 save_link_key = ih->ih_key;
216 if (is_indirect_le_ih(ih))
217 truncate = 1;
218 else
219 truncate = 0;
220
221 /* reiserfs_iget needs k_dirid and k_objectid only */
222 item = B_I_PITEM(bh, ih);
223 obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
224 obj_key.on_disk_key.k_objectid =
225 le32_to_cpu(ih->ih_key.k_objectid);
226 obj_key.on_disk_key.k_offset = 0;
227 obj_key.on_disk_key.k_type = 0;
228
229 pathrelse(&path);
230
231 inode = reiserfs_iget(s, &obj_key);
232 if (!inode) {
233 /* the unlink almost completed, it just did not manage to remove
234 "save" link and release objectid */
235 reiserfs_warning(s,
236 "vs-2180: finish_unfinished: iget failed for %K",
237 &obj_key);
238 retval = remove_save_link_only(s, &save_link_key, 1);
239 continue;
240 }
241
242 if (!truncate && inode->i_nlink) {
243 /* file is not unlinked */
244 reiserfs_warning(s,
245 "vs-2185: finish_unfinished: file %K is not unlinked",
246 &obj_key);
247 retval = remove_save_link_only(s, &save_link_key, 0);
248 continue;
249 }
250 DQUOT_INIT(inode);
251
252 if (truncate && S_ISDIR(inode->i_mode)) {
253 /* We got a truncate request for a dir which is impossible.
254 The only imaginable way is to execute unfinished truncate request
255 then boot into old kernel, remove the file and create dir with
256 the same key. */
257 reiserfs_warning(s,
258 "green-2101: impossible truncate on a directory %k. Please report",
259 INODE_PKEY(inode));
260 retval = remove_save_link_only(s, &save_link_key, 0);
261 truncate = 0;
262 iput(inode);
263 continue;
264 }
265
266 if (truncate) {
267 REISERFS_I(inode)->i_flags |=
268 i_link_saved_truncate_mask;
269 /* not completed truncate found. New size was committed together
270 with "save" link */
271 reiserfs_info(s, "Truncating %k to %Ld ..",
272 INODE_PKEY(inode), inode->i_size);
273 reiserfs_truncate_file(inode,
274 0
275 /*don't update modification time */
276 );
277 retval = remove_save_link(inode, truncate);
278 } else {
279 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
280 /* not completed unlink (rmdir) found */
281 reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
282 /* removal gets completed in iput */
283 retval = 0;
284 }
285
286 iput(inode);
287 printk("done\n");
288 done++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700290 REISERFS_SB(s)->s_is_unlinked_ok = 0;
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700293 /* Turn quotas off */
294 for (i = 0; i < MAXQUOTAS; i++) {
295 if (sb_dqopt(s)->files[i])
296 vfs_quota_off_mount(s, i);
297 }
298 if (ms_active_set)
299 /* Restore the flag back */
300 s->s_flags &= ~MS_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700302 pathrelse(&path);
303 if (done)
304 reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
305 "Completed\n", done);
306 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/* to protect file being unlinked from getting lost we "safe" link files
310 being unlinked. This link will be deleted in the same transaction with last
311 item of file. mounting the filesytem we scan all these links and remove
312 files which almost got lost */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700313void add_save_link(struct reiserfs_transaction_handle *th,
314 struct inode *inode, int truncate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700316 INITIALIZE_PATH(path);
317 int retval;
318 struct cpu_key key;
319 struct item_head ih;
320 __le32 link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700322 BUG_ON(!th->t_trans_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700324 /* file can only get one "save link" of each kind */
325 RFALSE(truncate &&
326 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
327 "saved link already exists for truncated inode %lx",
328 (long)inode->i_ino);
329 RFALSE(!truncate &&
330 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
331 "saved link already exists for unlinked inode %lx",
332 (long)inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700334 /* setup key of "save" link */
335 key.version = KEY_FORMAT_3_5;
336 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
337 key.on_disk_key.k_objectid = inode->i_ino;
338 if (!truncate) {
339 /* unlink, rmdir, rename */
340 set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
341 set_cpu_key_k_type(&key, TYPE_DIRECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700343 /* item head of "safe" link */
344 make_le_item_head(&ih, &key, key.version,
345 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
346 4 /*length */ , 0xffff /*free space */ );
347 } else {
348 /* truncate */
349 if (S_ISDIR(inode->i_mode))
350 reiserfs_warning(inode->i_sb,
351 "green-2102: Adding a truncate savelink for a directory %k! Please report",
352 INODE_PKEY(inode));
353 set_cpu_key_k_offset(&key, 1);
354 set_cpu_key_k_type(&key, TYPE_INDIRECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700356 /* item head of "safe" link */
357 make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
358 4 /*length */ , 0 /*free space */ );
359 }
360 key.key_length = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700362 /* look for its place in the tree */
363 retval = search_item(inode->i_sb, &key, &path);
364 if (retval != ITEM_NOT_FOUND) {
365 if (retval != -ENOSPC)
366 reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
367 "search_by_key (%K) returned %d", &key,
368 retval);
369 pathrelse(&path);
370 return;
371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700373 /* body of "save" link */
374 link = INODE_PKEY(inode)->k_dir_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700376 /* put "save" link inot tree, don't charge quota to anyone */
377 retval =
378 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
379 if (retval) {
380 if (retval != -ENOSPC)
381 reiserfs_warning(inode->i_sb,
382 "vs-2120: add_save_link: insert_item returned %d",
383 retval);
384 } else {
385 if (truncate)
386 REISERFS_I(inode)->i_flags |=
387 i_link_saved_truncate_mask;
388 else
389 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393/* this opens transaction unlike add_save_link */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700394int remove_save_link(struct inode *inode, int truncate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700396 struct reiserfs_transaction_handle th;
397 struct reiserfs_key key;
398 int err;
399
400 /* we are going to do one balancing only */
401 err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
402 if (err)
403 return err;
404
405 /* setup key of "save" link */
406 key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
407 key.k_objectid = INODE_PKEY(inode)->k_objectid;
408 if (!truncate) {
409 /* unlink, rmdir, rename */
410 set_le_key_k_offset(KEY_FORMAT_3_5, &key,
411 1 + inode->i_sb->s_blocksize);
412 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
413 } else {
414 /* truncate */
415 set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
416 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
417 }
418
419 if ((truncate &&
420 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
421 (!truncate &&
422 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
423 /* don't take quota bytes from anywhere */
424 reiserfs_delete_solid_item(&th, NULL, &key);
425 if (!truncate) {
426 reiserfs_release_objectid(&th, inode->i_ino);
427 REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
428 } else
429 REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
430
431 return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700434static void reiserfs_put_super(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700436 int i;
437 struct reiserfs_transaction_handle th;
438 th.t_trans_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700440 if (REISERFS_SB(s)->xattr_root) {
441 d_invalidate(REISERFS_SB(s)->xattr_root);
442 dput(REISERFS_SB(s)->xattr_root);
443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700445 if (REISERFS_SB(s)->priv_root) {
446 d_invalidate(REISERFS_SB(s)->priv_root);
447 dput(REISERFS_SB(s)->priv_root);
448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700450 /* change file system state to current state if it was mounted with read-write permissions */
451 if (!(s->s_flags & MS_RDONLY)) {
452 if (!journal_begin(&th, s, 10)) {
453 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
454 1);
455 set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
456 REISERFS_SB(s)->s_mount_state);
457 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
458 }
459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700461 /* note, journal_release checks for readonly mount, and can decide not
462 ** to do a journal_end
463 */
464 journal_release(&th, s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700466 for (i = 0; i < SB_BMAP_NR(s); i++)
467 brelse(SB_AP_BITMAP(s)[i].bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700469 vfree(SB_AP_BITMAP(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700471 brelse(SB_BUFFER_WITH_SB(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700473 print_statistics(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700475 if (REISERFS_SB(s)->reserved_blocks != 0) {
476 reiserfs_warning(s,
477 "green-2005: reiserfs_put_super: reserved blocks left %d",
478 REISERFS_SB(s)->reserved_blocks);
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700481 reiserfs_proc_info_done(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700483 kfree(s->s_fs_info);
484 s->s_fs_info = NULL;
485
486 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700489static kmem_cache_t *reiserfs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491static struct inode *reiserfs_alloc_inode(struct super_block *sb)
492{
493 struct reiserfs_inode_info *ei;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700494 ei = (struct reiserfs_inode_info *)
495 kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (!ei)
497 return NULL;
498 return &ei->vfs_inode;
499}
500
501static void reiserfs_destroy_inode(struct inode *inode)
502{
503 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
504}
505
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700506static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700508 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700510 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 SLAB_CTOR_CONSTRUCTOR) {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700512 INIT_LIST_HEAD(&ei->i_prealloc_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 inode_init_once(&ei->vfs_inode);
514 ei->i_acl_access = NULL;
515 ei->i_acl_default = NULL;
516 }
517}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519static int init_inodecache(void)
520{
521 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700522 sizeof(struct
523 reiserfs_inode_info),
524 0, SLAB_RECLAIM_ACCOUNT,
525 init_once, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (reiserfs_inode_cachep == NULL)
527 return -ENOMEM;
528 return 0;
529}
530
531static void destroy_inodecache(void)
532{
533 if (kmem_cache_destroy(reiserfs_inode_cachep))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700534 reiserfs_warning(NULL,
535 "reiserfs_inode_cache: not all structures were freed");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
538/* we don't mark inodes dirty, we just log them */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700539static void reiserfs_dirty_inode(struct inode *inode)
540{
541 struct reiserfs_transaction_handle th;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700543 int err = 0;
544 if (inode->i_sb->s_flags & MS_RDONLY) {
545 reiserfs_warning(inode->i_sb,
546 "clm-6006: writing inode %lu on readonly FS",
547 inode->i_ino);
548 return;
549 }
550 reiserfs_write_lock(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700552 /* this is really only used for atime updates, so they don't have
553 ** to be included in O_SYNC or fsync
554 */
555 err = journal_begin(&th, inode->i_sb, 1);
556 if (err) {
557 reiserfs_write_unlock(inode->i_sb);
558 return;
559 }
560 reiserfs_update_sd(&th, inode);
561 journal_end(&th, inode->i_sb, 1);
562 reiserfs_write_unlock(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700565static void reiserfs_clear_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700567 struct posix_acl *acl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700569 acl = REISERFS_I(inode)->i_acl_access;
570 if (acl && !IS_ERR(acl))
571 posix_acl_release(acl);
572 REISERFS_I(inode)->i_acl_access = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700574 acl = REISERFS_I(inode)->i_acl_default;
575 if (acl && !IS_ERR(acl))
576 posix_acl_release(acl);
577 REISERFS_I(inode)->i_acl_default = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
580#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700581static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
582 size_t, loff_t);
583static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
584 loff_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#endif
586
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700587static struct super_operations reiserfs_sops = {
588 .alloc_inode = reiserfs_alloc_inode,
589 .destroy_inode = reiserfs_destroy_inode,
590 .write_inode = reiserfs_write_inode,
591 .dirty_inode = reiserfs_dirty_inode,
592 .delete_inode = reiserfs_delete_inode,
593 .clear_inode = reiserfs_clear_inode,
594 .put_super = reiserfs_put_super,
595 .write_super = reiserfs_write_super,
596 .sync_fs = reiserfs_sync_fs,
597 .write_super_lockfs = reiserfs_write_super_lockfs,
598 .unlockfs = reiserfs_unlockfs,
599 .statfs = reiserfs_statfs,
600 .remount_fs = reiserfs_remount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700602 .quota_read = reiserfs_quota_read,
603 .quota_write = reiserfs_quota_write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#endif
605};
606
607#ifdef CONFIG_QUOTA
608#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
609
610static int reiserfs_dquot_initialize(struct inode *, int);
611static int reiserfs_dquot_drop(struct inode *);
612static int reiserfs_write_dquot(struct dquot *);
613static int reiserfs_acquire_dquot(struct dquot *);
614static int reiserfs_release_dquot(struct dquot *);
615static int reiserfs_mark_dquot_dirty(struct dquot *);
616static int reiserfs_write_info(struct super_block *, int);
617static int reiserfs_quota_on(struct super_block *, int, int, char *);
618
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700619static struct dquot_operations reiserfs_quota_operations = {
620 .initialize = reiserfs_dquot_initialize,
621 .drop = reiserfs_dquot_drop,
622 .alloc_space = dquot_alloc_space,
623 .alloc_inode = dquot_alloc_inode,
624 .free_space = dquot_free_space,
625 .free_inode = dquot_free_inode,
626 .transfer = dquot_transfer,
627 .write_dquot = reiserfs_write_dquot,
628 .acquire_dquot = reiserfs_acquire_dquot,
629 .release_dquot = reiserfs_release_dquot,
630 .mark_dirty = reiserfs_mark_dquot_dirty,
631 .write_info = reiserfs_write_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632};
633
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700634static struct quotactl_ops reiserfs_qctl_operations = {
635 .quota_on = reiserfs_quota_on,
636 .quota_off = vfs_quota_off,
637 .quota_sync = vfs_quota_sync,
638 .get_info = vfs_get_dqinfo,
639 .set_info = vfs_set_dqinfo,
640 .get_dqblk = vfs_get_dqblk,
641 .set_dqblk = vfs_set_dqblk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642};
643#endif
644
645static struct export_operations reiserfs_export_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700646 .encode_fh = reiserfs_encode_fh,
647 .decode_fh = reiserfs_decode_fh,
648 .get_parent = reiserfs_get_parent,
649 .get_dentry = reiserfs_get_dentry,
650};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652/* this struct is used in reiserfs_getopt () for containing the value for those
653 mount options that have values rather than being toggles. */
654typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700655 char *value;
656 int setmask; /* bitmask which is to set on mount_options bitmask when this
657 value is found, 0 is no bits are to be changed. */
658 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
659 value is found, 0 is no bits are to be changed. This is
660 applied BEFORE setmask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661} arg_desc_t;
662
663/* Set this bit in arg_required to allow empty arguments */
664#define REISERFS_OPT_ALLOWEMPTY 31
665
666/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
667 mount options */
668typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700669 char *option_name;
670 int arg_required; /* 0 if argument is not required, not 0 otherwise */
671 const arg_desc_t *values; /* list of values accepted by an option */
672 int setmask; /* bitmask which is to set on mount_options bitmask when this
673 value is found, 0 is no bits are to be changed. */
674 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
675 value is found, 0 is no bits are to be changed. This is
676 applied BEFORE setmask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677} opt_desc_t;
678
679/* possible values for -o data= */
680static const arg_desc_t logging_mode[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700681 {"ordered", 1 << REISERFS_DATA_ORDERED,
682 (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
683 {"journal", 1 << REISERFS_DATA_LOG,
684 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
685 {"writeback", 1 << REISERFS_DATA_WRITEBACK,
686 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
687 {NULL, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688};
689
690/* possible values for -o barrier= */
691static const arg_desc_t barrier_mode[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700692 {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
693 {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
694 {NULL, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695};
696
697/* possible values for "-o block-allocator=" and bits which are to be set in
698 s_mount_opt of reiserfs specific part of in-core super block */
699static const arg_desc_t balloc[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700700 {"noborder", 1 << REISERFS_NO_BORDER, 0},
701 {"border", 0, 1 << REISERFS_NO_BORDER},
702 {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
703 {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
704 {"test4", 1 << REISERFS_TEST4, 0},
705 {"notest4", 0, 1 << REISERFS_TEST4},
706 {NULL, 0, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707};
708
709static const arg_desc_t tails[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700710 {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
711 {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
712 {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
713 {NULL, 0, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714};
715
716static const arg_desc_t error_actions[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700717 {"panic", 1 << REISERFS_ERROR_PANIC,
718 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
719 {"ro-remount", 1 << REISERFS_ERROR_RO,
720 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700722 {"continue", 1 << REISERFS_ERROR_CONTINUE,
723 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700725 {NULL, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726};
727
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700728int reiserfs_default_io_size = 128 * 1024; /* Default recommended I/O size is 128k.
729 There might be broken applications that are
730 confused by this. Use nolargeio mount option
731 to get usual i/o size = PAGE_SIZE.
732 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734/* proceed only one option from a list *cur - string containing of mount options
735 opts - array of options which are accepted
736 opt_arg - if option is found and requires an argument and if it is specifed
737 in the input - pointer to the argument is stored here
738 bit_flags - if option requires to set a certain bit - it is set here
739 return -1 if unknown option is found, opt->arg_required otherwise */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700740static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
741 char **opt_arg, unsigned long *bit_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700743 char *p;
744 /* foo=bar,
745 ^ ^ ^
746 | | +-- option_end
747 | +-- arg_start
748 +-- option_start
749 */
750 const opt_desc_t *opt;
751 const arg_desc_t *arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700753 p = *cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700755 /* assume argument cannot contain commas */
756 *cur = strchr(p, ',');
757 if (*cur) {
758 *(*cur) = '\0';
759 (*cur)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700762 if (!strncmp(p, "alloc=", 6)) {
763 /* Ugly special case, probably we should redo options parser so that
764 it can understand several arguments for some options, also so that
765 it can fill several bitfields with option values. */
766 if (reiserfs_parse_alloc_options(s, p + 6)) {
767 return -1;
768 } else {
769 return 0;
770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700772
773 /* for every option in the list */
774 for (opt = opts; opt->option_name; opt++) {
775 if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
776 if (bit_flags) {
777 if (opt->clrmask ==
778 (1 << REISERFS_UNSUPPORTED_OPT))
779 reiserfs_warning(s, "%s not supported.",
780 p);
781 else
782 *bit_flags &= ~opt->clrmask;
783 if (opt->setmask ==
784 (1 << REISERFS_UNSUPPORTED_OPT))
785 reiserfs_warning(s, "%s not supported.",
786 p);
787 else
788 *bit_flags |= opt->setmask;
789 }
790 break;
791 }
792 }
793 if (!opt->option_name) {
794 reiserfs_warning(s, "unknown mount option \"%s\"", p);
795 return -1;
796 }
797
798 p += strlen(opt->option_name);
799 switch (*p) {
800 case '=':
801 if (!opt->arg_required) {
802 reiserfs_warning(s,
803 "the option \"%s\" does not require an argument",
804 opt->option_name);
805 return -1;
806 }
807 break;
808
809 case 0:
810 if (opt->arg_required) {
811 reiserfs_warning(s,
812 "the option \"%s\" requires an argument",
813 opt->option_name);
814 return -1;
815 }
816 break;
817 default:
818 reiserfs_warning(s, "head of option \"%s\" is only correct",
819 opt->option_name);
820 return -1;
821 }
822
823 /* move to the argument, or to next option if argument is not required */
824 p++;
825
826 if (opt->arg_required
827 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
828 && !strlen(p)) {
829 /* this catches "option=," if not allowed */
830 reiserfs_warning(s, "empty argument for \"%s\"",
831 opt->option_name);
832 return -1;
833 }
834
835 if (!opt->values) {
836 /* *=NULLopt_arg contains pointer to argument */
837 *opt_arg = p;
838 return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
839 }
840
841 /* values possible for this option are listed in opt->values */
842 for (arg = opt->values; arg->value; arg++) {
843 if (!strcmp(p, arg->value)) {
844 if (bit_flags) {
845 *bit_flags &= ~arg->clrmask;
846 *bit_flags |= arg->setmask;
847 }
848 return opt->arg_required;
849 }
850 }
851
852 reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
853 opt->option_name);
854 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
857/* returns 0 if something is wrong in option string, 1 - otherwise */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700858static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
859 unsigned long *mount_options,
860 /* after the parsing phase, contains the
861 collection of bitflags defining what
862 mount options were selected. */
863 unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
864 char **jdev_name,
865 unsigned int *commit_max_age)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700867 int c;
868 char *arg = NULL;
869 char *pos;
870 opt_desc_t opts[] = {
871 /* Compatibility stuff, so that -o notail for old setups still work */
872 {"tails",.arg_required = 't',.values = tails},
873 {"notail",.clrmask =
874 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
875 {"conv",.setmask = 1 << REISERFS_CONVERT},
876 {"attrs",.setmask = 1 << REISERFS_ATTRS},
877 {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878#ifdef CONFIG_REISERFS_FS_XATTR
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700879 {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
880 {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881#else
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700882 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
883 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884#endif
885#ifdef CONFIG_REISERFS_FS_POSIX_ACL
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700886 {"acl",.setmask = 1 << REISERFS_POSIXACL},
887 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888#else
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700889 {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
890 {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700892 {"nolog",}, /* This is unsupported */
893 {"replayonly",.setmask = 1 << REPLAYONLY},
894 {"block-allocator",.arg_required = 'a',.values = balloc},
895 {"data",.arg_required = 'd',.values = logging_mode},
896 {"barrier",.arg_required = 'b',.values = barrier_mode},
897 {"resize",.arg_required = 'r',.values = NULL},
898 {"jdev",.arg_required = 'j',.values = NULL},
899 {"nolargeio",.arg_required = 'w',.values = NULL},
900 {"commit",.arg_required = 'c',.values = NULL},
901 {"usrquota",.setmask = 1 << REISERFS_QUOTA},
902 {"grpquota",.setmask = 1 << REISERFS_QUOTA},
903 {"noquota",.clrmask = 1 << REISERFS_QUOTA},
904 {"errors",.arg_required = 'e',.values = error_actions},
905 {"usrjquota",.arg_required =
906 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
907 {"grpjquota",.arg_required =
908 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
909 {"jqfmt",.arg_required = 'f',.values = NULL},
910 {NULL,}
911 };
912
913 *blocks = 0;
914 if (!options || !*options)
915 /* use default configuration: create tails, journaling on, no
916 conversion to newest format */
917 return 1;
918
919 for (pos = options; pos;) {
920 c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
921 if (c == -1)
922 /* wrong option is given */
923 return 0;
924
925 if (c == 'r') {
926 char *p;
927
928 p = NULL;
929 /* "resize=NNN" or "resize=auto" */
930
931 if (!strcmp(arg, "auto")) {
932 /* From JFS code, to auto-get the size. */
933 *blocks =
934 s->s_bdev->bd_inode->i_size >> s->
935 s_blocksize_bits;
936 } else {
937 *blocks = simple_strtoul(arg, &p, 0);
938 if (*p != '\0') {
939 /* NNN does not look like a number */
940 reiserfs_warning(s,
941 "reiserfs_parse_options: bad value %s",
942 arg);
943 return 0;
944 }
945 }
946 }
947
948 if (c == 'c') {
949 char *p = NULL;
950 unsigned long val = simple_strtoul(arg, &p, 0);
951 /* commit=NNN (time in seconds) */
952 if (*p != '\0' || val >= (unsigned int)-1) {
953 reiserfs_warning(s,
954 "reiserfs_parse_options: bad value %s",
955 arg);
956 return 0;
957 }
958 *commit_max_age = (unsigned int)val;
959 }
960
961 if (c == 'w') {
962 char *p = NULL;
963 int val = simple_strtoul(arg, &p, 0);
964
965 if (*p != '\0') {
966 reiserfs_warning(s,
967 "reiserfs_parse_options: non-numeric value %s for nolargeio option",
968 arg);
969 return 0;
970 }
971 if (val)
972 reiserfs_default_io_size = PAGE_SIZE;
973 else
974 reiserfs_default_io_size = 128 * 1024;
975 }
976
977 if (c == 'j') {
978 if (arg && *arg && jdev_name) {
979 if (*jdev_name) { //Hm, already assigned?
980 reiserfs_warning(s,
981 "reiserfs_parse_options: journal device was already specified to be %s",
982 *jdev_name);
983 return 0;
984 }
985 *jdev_name = arg;
986 }
987 }
988#ifdef CONFIG_QUOTA
989 if (c == 'u' || c == 'g') {
990 int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
991
992 if (sb_any_quota_enabled(s)) {
993 reiserfs_warning(s,
994 "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
995 return 0;
996 }
997 if (*arg) { /* Some filename specified? */
998 if (REISERFS_SB(s)->s_qf_names[qtype]
999 && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
1000 arg)) {
1001 reiserfs_warning(s,
1002 "reiserfs_parse_options: %s quota file already specified.",
1003 QTYPE2NAME(qtype));
1004 return 0;
1005 }
1006 if (strchr(arg, '/')) {
1007 reiserfs_warning(s,
1008 "reiserfs_parse_options: quotafile must be on filesystem root.");
1009 return 0;
1010 }
1011 REISERFS_SB(s)->s_qf_names[qtype] =
1012 kmalloc(strlen(arg) + 1, GFP_KERNEL);
1013 if (!REISERFS_SB(s)->s_qf_names[qtype]) {
1014 reiserfs_warning(s,
1015 "reiserfs_parse_options: not enough memory for storing quotafile name.");
1016 return 0;
1017 }
1018 strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
1019 *mount_options |= 1 << REISERFS_QUOTA;
1020 } else {
James Lamanna833d3042005-10-30 15:00:16 -08001021 kfree(REISERFS_SB(s)->s_qf_names[qtype]);
1022 REISERFS_SB(s)->s_qf_names[qtype] = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001023 }
1024 }
1025 if (c == 'f') {
1026 if (!strcmp(arg, "vfsold"))
1027 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
1028 else if (!strcmp(arg, "vfsv0"))
1029 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
1030 else {
1031 reiserfs_warning(s,
1032 "reiserfs_parse_options: unknown quota format specified.");
1033 return 0;
1034 }
1035 }
1036#else
1037 if (c == 'u' || c == 'g' || c == 'f') {
1038 reiserfs_warning(s,
1039 "reiserfs_parse_options: journalled quota options not supported.");
1040 return 0;
1041 }
1042#endif
1043 }
1044
1045#ifdef CONFIG_QUOTA
1046 if (!REISERFS_SB(s)->s_jquota_fmt
1047 && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
1048 || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
1049 reiserfs_warning(s,
1050 "reiserfs_parse_options: journalled quota format not specified.");
1051 return 0;
1052 }
1053 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
1054 if (!(*mount_options & (1 << REISERFS_QUOTA))
1055 && sb_any_quota_enabled(s)) {
1056 reiserfs_warning(s,
1057 "reiserfs_parse_options: quota options must be present when quota is turned on.");
1058 return 0;
1059 }
1060#endif
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001065static void switch_data_mode(struct super_block *s, unsigned long mode)
1066{
1067 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
1068 (1 << REISERFS_DATA_ORDERED) |
1069 (1 << REISERFS_DATA_WRITEBACK));
1070 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
1073static void handle_data_mode(struct super_block *s, unsigned long mount_options)
1074{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001075 if (mount_options & (1 << REISERFS_DATA_LOG)) {
1076 if (!reiserfs_data_log(s)) {
1077 switch_data_mode(s, REISERFS_DATA_LOG);
1078 reiserfs_info(s, "switching to journaled data mode\n");
1079 }
1080 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
1081 if (!reiserfs_data_ordered(s)) {
1082 switch_data_mode(s, REISERFS_DATA_ORDERED);
1083 reiserfs_info(s, "switching to ordered data mode\n");
1084 }
1085 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
1086 if (!reiserfs_data_writeback(s)) {
1087 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
1088 reiserfs_info(s, "switching to writeback data mode\n");
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001093static void handle_barrier_mode(struct super_block *s, unsigned long bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001095 int flush = (1 << REISERFS_BARRIER_FLUSH);
1096 int none = (1 << REISERFS_BARRIER_NONE);
1097 int all_barrier = flush | none;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001099 if (bits & all_barrier) {
1100 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1101 if (bits & flush) {
1102 REISERFS_SB(s)->s_mount_opt |= flush;
1103 printk("reiserfs: enabling write barrier flush mode\n");
1104 } else if (bits & none) {
1105 REISERFS_SB(s)->s_mount_opt |= none;
1106 printk("reiserfs: write barriers turned off\n");
1107 }
1108 }
1109}
1110
1111static void handle_attrs(struct super_block *s)
1112{
1113 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1114
1115 if (reiserfs_attrs(s)) {
1116 if (old_format_only(s)) {
1117 reiserfs_warning(s,
1118 "reiserfs: cannot support attributes on 3.5.x disk format");
1119 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 return;
1121 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001122 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1123 reiserfs_warning(s,
1124 "reiserfs: cannot support attributes until flag is set in super-block");
1125 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001127 } else if (le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared) {
Vitaly Fertmand35c6022006-02-03 03:04:01 -08001128 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ATTRS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130}
1131
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001132static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001134 struct reiserfs_super_block *rs;
1135 struct reiserfs_transaction_handle th;
1136 unsigned long blocks;
1137 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1138 unsigned long safe_mask = 0;
1139 unsigned int commit_max_age = (unsigned int)-1;
1140 struct reiserfs_journal *journal = SB_JOURNAL(s);
1141 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001143 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144#endif
1145
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001146 rs = SB_DISK_SUPER_BLOCK(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001148 if (!reiserfs_parse_options
1149 (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150#ifdef CONFIG_QUOTA
James Lamanna833d3042005-10-30 15:00:16 -08001151 for (i = 0; i < MAXQUOTAS; i++) {
1152 kfree(REISERFS_SB(s)->s_qf_names[i]);
1153 REISERFS_SB(s)->s_qf_names[i] = NULL;
1154 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001155#endif
1156 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001159 handle_attrs(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001161 /* Add options that are safe here */
1162 safe_mask |= 1 << REISERFS_SMALLTAIL;
1163 safe_mask |= 1 << REISERFS_LARGETAIL;
1164 safe_mask |= 1 << REISERFS_NO_BORDER;
1165 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
1166 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
1167 safe_mask |= 1 << REISERFS_TEST4;
1168 safe_mask |= 1 << REISERFS_ATTRS;
1169 safe_mask |= 1 << REISERFS_XATTRS_USER;
1170 safe_mask |= 1 << REISERFS_POSIXACL;
1171 safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
1172 safe_mask |= 1 << REISERFS_BARRIER_NONE;
1173 safe_mask |= 1 << REISERFS_ERROR_RO;
1174 safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
1175 safe_mask |= 1 << REISERFS_ERROR_PANIC;
1176 safe_mask |= 1 << REISERFS_QUOTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001178 /* Update the bitmask, taking care to keep
1179 * the bits we're not allowed to change here */
1180 REISERFS_SB(s)->s_mount_opt =
1181 (REISERFS_SB(s)->
1182 s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001184 if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
1185 journal->j_max_commit_age = commit_max_age;
1186 journal->j_max_trans_age = commit_max_age;
1187 } else if (commit_max_age == 0) {
1188 /* 0 means restore defaults. */
1189 journal->j_max_commit_age = journal->j_default_max_commit_age;
1190 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
1191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001193 if (blocks) {
1194 int rc = reiserfs_resize(s, blocks);
1195 if (rc != 0)
1196 return rc;
1197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001199 if (*mount_flags & MS_RDONLY) {
1200 reiserfs_xattr_init(s, *mount_flags);
1201 /* remount read-only */
1202 if (s->s_flags & MS_RDONLY)
1203 /* it is read-only already */
1204 return 0;
1205 /* try to remount file system with read-only permissions */
1206 if (sb_umount_state(rs) == REISERFS_VALID_FS
1207 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1208 return 0;
1209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001211 err = journal_begin(&th, s, 10);
1212 if (err)
1213 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001215 /* Mounting a rw partition read-only. */
1216 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1217 set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
1218 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1219 } else {
1220 /* remount read-write */
1221 if (!(s->s_flags & MS_RDONLY)) {
1222 reiserfs_xattr_init(s, *mount_flags);
1223 return 0; /* We are read-write already */
1224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001226 if (reiserfs_is_journal_aborted(journal))
1227 return journal->j_errno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001229 handle_data_mode(s, mount_options);
1230 handle_barrier_mode(s, mount_options);
1231 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1232 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
1233 err = journal_begin(&th, s, 10);
1234 if (err)
1235 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001237 /* Mount a partition which is read-only, read-write */
1238 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1239 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1240 s->s_flags &= ~MS_RDONLY;
1241 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1242 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1243 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1244 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
1245 }
1246 /* this will force a full flush of all journal lists */
1247 SB_JOURNAL(s)->j_must_wait = 1;
1248 err = journal_end(&th, s, 10);
1249 if (err)
1250 return err;
1251 s->s_dirt = 0;
1252
1253 if (!(*mount_flags & MS_RDONLY)) {
1254 finish_unfinished(s);
1255 reiserfs_xattr_init(s, *mount_flags);
1256 }
1257
1258 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
1261/* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
1262 * @sb - superblock for this filesystem
1263 * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
1264 *
1265 * This routine counts how many free bits there are, finding the first zero
1266 * as a side effect. Could also be implemented as a loop of test_bit() calls, or
1267 * a loop of find_first_zero_bit() calls. This implementation is similar to
1268 * find_first_zero_bit(), but doesn't return after it finds the first bit.
1269 * Should only be called on fs mount, but should be fairly efficient anyways.
1270 *
1271 * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
1272 * will * invariably occupt block 0 represented in the bitmap. The only
1273 * exception to this is when free_count also == 0, since there will be no
1274 * free blocks at all.
1275 */
1276
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001277static void load_bitmap_info_data(struct super_block *sb,
1278 struct reiserfs_bitmap_info *bi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001280 unsigned long *cur = (unsigned long *)bi->bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001282 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001284 /* No need to scan if all 0's or all 1's.
1285 * Since we're only counting 0's, we can simply ignore all 1's */
1286 if (*cur == 0) {
1287 if (bi->first_zero_hint == 0) {
1288 bi->first_zero_hint =
1289 ((char *)cur - bi->bh->b_data) << 3;
1290 }
1291 bi->free_count += sizeof(unsigned long) * 8;
1292 } else if (*cur != ~0L) {
1293 int b;
1294 for (b = 0; b < sizeof(unsigned long) * 8; b++) {
1295 if (!reiserfs_test_le_bit(b, cur)) {
1296 bi->free_count++;
1297 if (bi->first_zero_hint == 0)
1298 bi->first_zero_hint =
1299 (((char *)cur -
1300 bi->bh->b_data) << 3) + b;
1301 }
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001304 cur++;
1305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307#ifdef CONFIG_REISERFS_CHECK
1308// This outputs a lot of unneded info on big FSes
1309// reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001310// bi->bh->b_blocknr, bi->free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311#endif
1312}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001314static int read_bitmaps(struct super_block *s)
1315{
1316 int i, bmap_nr;
1317
1318 SB_AP_BITMAP(s) =
1319 vmalloc(sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1320 if (SB_AP_BITMAP(s) == 0)
1321 return 1;
1322 memset(SB_AP_BITMAP(s), 0,
1323 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1324 for (i = 0, bmap_nr =
1325 REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
1326 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
1327 SB_AP_BITMAP(s)[i].bh = sb_getblk(s, bmap_nr);
1328 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
1329 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001331 for (i = 0; i < SB_BMAP_NR(s); i++) {
1332 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1333 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1334 reiserfs_warning(s, "sh-2029: reiserfs read_bitmaps: "
1335 "bitmap block (#%lu) reading failed",
1336 SB_AP_BITMAP(s)[i].bh->b_blocknr);
1337 for (i = 0; i < SB_BMAP_NR(s); i++)
1338 brelse(SB_AP_BITMAP(s)[i].bh);
1339 vfree(SB_AP_BITMAP(s));
1340 SB_AP_BITMAP(s) = NULL;
1341 return 1;
1342 }
1343 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1344 }
1345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001348static int read_old_bitmaps(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001350 int i;
1351 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1352 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001354 /* read true bitmap */
1355 SB_AP_BITMAP(s) =
1356 vmalloc(sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1357 if (SB_AP_BITMAP(s) == 0)
1358 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001360 memset(SB_AP_BITMAP(s), 0,
1361 sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001363 for (i = 0; i < sb_bmap_nr(rs); i++) {
1364 SB_AP_BITMAP(s)[i].bh = sb_bread(s, bmp1 + i);
1365 if (!SB_AP_BITMAP(s)[i].bh)
1366 return 1;
1367 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001373static int read_super_block(struct super_block *s, int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001375 struct buffer_head *bh;
1376 struct reiserfs_super_block *rs;
1377 int fs_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001379 bh = sb_bread(s, offset / s->s_blocksize);
1380 if (!bh) {
1381 reiserfs_warning(s, "sh-2006: read_super_block: "
1382 "bread failed (dev %s, block %lu, size %lu)",
1383 reiserfs_bdevname(s), offset / s->s_blocksize,
1384 s->s_blocksize);
1385 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001388 rs = (struct reiserfs_super_block *)bh->b_data;
1389 if (!is_any_reiserfs_magic_string(rs)) {
1390 brelse(bh);
1391 return 1;
1392 }
1393 //
1394 // ok, reiserfs signature (old or new) found in at the given offset
1395 //
1396 fs_blocksize = sb_blocksize(rs);
1397 brelse(bh);
1398 sb_set_blocksize(s, fs_blocksize);
1399
1400 bh = sb_bread(s, offset / s->s_blocksize);
1401 if (!bh) {
1402 reiserfs_warning(s, "sh-2007: read_super_block: "
1403 "bread failed (dev %s, block %lu, size %lu)\n",
1404 reiserfs_bdevname(s), offset / s->s_blocksize,
1405 s->s_blocksize);
1406 return 1;
1407 }
1408
1409 rs = (struct reiserfs_super_block *)bh->b_data;
1410 if (sb_blocksize(rs) != s->s_blocksize) {
1411 reiserfs_warning(s, "sh-2011: read_super_block: "
1412 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1413 reiserfs_bdevname(s),
1414 (unsigned long long)bh->b_blocknr,
1415 s->s_blocksize);
1416 brelse(bh);
1417 return 1;
1418 }
1419
1420 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1421 brelse(bh);
1422 reiserfs_warning(s,
1423 "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1424 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1425 "get newer reiserfsprogs package");
1426 return 1;
1427 }
1428
1429 SB_BUFFER_WITH_SB(s) = bh;
1430 SB_DISK_SUPER_BLOCK(s) = rs;
1431
1432 if (is_reiserfs_jr(rs)) {
1433 /* magic is of non-standard journal filesystem, look at s_version to
1434 find which format is in use */
1435 if (sb_version(rs) == REISERFS_VERSION_2)
1436 reiserfs_warning(s,
1437 "read_super_block: found reiserfs format \"3.6\""
1438 " with non-standard journal");
1439 else if (sb_version(rs) == REISERFS_VERSION_1)
1440 reiserfs_warning(s,
1441 "read_super_block: found reiserfs format \"3.5\""
1442 " with non-standard journal");
1443 else {
1444 reiserfs_warning(s,
1445 "sh-2012: read_super_block: found unknown "
1446 "format \"%u\" of reiserfs with non-standard magic",
1447 sb_version(rs));
1448 return 1;
1449 }
1450 } else
1451 /* s_version of standard format may contain incorrect information,
1452 so we just look at the magic string */
1453 reiserfs_info(s,
1454 "found reiserfs format \"%s\" with standard journal\n",
1455 is_reiserfs_3_5(rs) ? "3.5" : "3.6");
1456
1457 s->s_op = &reiserfs_sops;
1458 s->s_export_op = &reiserfs_export_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001460 s->s_qcop = &reiserfs_qctl_operations;
1461 s->dq_op = &reiserfs_quota_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462#endif
1463
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001464 /* new format is limited by the 32 bit wide i_blocks field, want to
1465 ** be one full block below that.
1466 */
1467 s->s_maxbytes = (512LL << 32) - s->s_blocksize;
1468 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469}
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471/* after journal replay, reread all bitmap and super blocks */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001472static int reread_meta_blocks(struct super_block *s)
1473{
1474 int i;
1475 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1476 wait_on_buffer(SB_BUFFER_WITH_SB(s));
1477 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1478 reiserfs_warning(s,
1479 "reread_meta_blocks, error reading the super");
1480 return 1;
1481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001483 for (i = 0; i < SB_BMAP_NR(s); i++) {
1484 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh));
1485 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1486 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1487 reiserfs_warning(s,
1488 "reread_meta_blocks, error reading bitmap block number %d at %llu",
1489 i,
1490 (unsigned long long)SB_AP_BITMAP(s)[i].
1491 bh->b_blocknr);
1492 return 1;
1493 }
1494 }
1495 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497}
1498
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499/////////////////////////////////////////////////////
1500// hash detection stuff
1501
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502// if root directory is empty - we set default - Yura's - hash and
1503// warn about it
1504// FIXME: we look for only one name in a directory. If tea and yura
1505// bith have the same value - we ask user to send report to the
1506// mailing list
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001507static __u32 find_hash_out(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001509 int retval;
1510 struct inode *inode;
1511 struct cpu_key key;
1512 INITIALIZE_PATH(path);
1513 struct reiserfs_dir_entry de;
1514 __u32 hash = DEFAULT_HASH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001516 inode = s->s_root->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001518 do { // Some serious "goto"-hater was there ;)
1519 u32 teahash, r5hash, yurahash;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001521 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1522 retval = search_by_entry_key(s, &key, &path, &de);
1523 if (retval == IO_ERROR) {
1524 pathrelse(&path);
1525 return UNSET_HASH;
1526 }
1527 if (retval == NAME_NOT_FOUND)
1528 de.de_entry_num--;
1529 set_de_name_and_namelen(&de);
1530 if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
1531 /* allow override in this case */
1532 if (reiserfs_rupasov_hash(s)) {
1533 hash = YURA_HASH;
1534 }
1535 reiserfs_warning(s, "FS seems to be empty, autodetect "
1536 "is using the default hash");
1537 break;
1538 }
1539 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
1540 teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
1541 yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
1542 if (((teahash == r5hash)
1543 &&
1544 (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
1545 == r5hash)) || ((teahash == yurahash)
1546 && (yurahash ==
1547 GET_HASH_VALUE(deh_offset
1548 (&
1549 (de.
1550 de_deh[de.
1551 de_entry_num])))))
1552 || ((r5hash == yurahash)
1553 && (yurahash ==
1554 GET_HASH_VALUE(deh_offset
1555 (&(de.de_deh[de.de_entry_num])))))) {
1556 reiserfs_warning(s,
1557 "Unable to automatically detect hash function. "
1558 "Please mount with -o hash={tea,rupasov,r5}",
1559 reiserfs_bdevname(s));
1560 hash = UNSET_HASH;
1561 break;
1562 }
1563 if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
1564 yurahash)
1565 hash = YURA_HASH;
1566 else if (GET_HASH_VALUE
1567 (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
1568 hash = TEA_HASH;
1569 else if (GET_HASH_VALUE
1570 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1571 hash = R5_HASH;
1572 else {
1573 reiserfs_warning(s, "Unrecognised hash function");
1574 hash = UNSET_HASH;
1575 }
1576 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001578 pathrelse(&path);
1579 return hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582// finds out which hash names are sorted with
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001583static int what_hash(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001585 __u32 code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001587 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001589 /* reiserfs_hash_detect() == true if any of the hash mount options
1590 ** were used. We must check them to make sure the user isn't
1591 ** using a bad hash value
1592 */
1593 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1594 code = find_hash_out(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001596 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1597 /* detection has found the hash, and we must check against the
1598 ** mount options
1599 */
1600 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1601 reiserfs_warning(s, "Error, %s hash detected, "
1602 "unable to force rupasov hash",
1603 reiserfs_hashname(code));
1604 code = UNSET_HASH;
1605 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1606 reiserfs_warning(s, "Error, %s hash detected, "
1607 "unable to force tea hash",
1608 reiserfs_hashname(code));
1609 code = UNSET_HASH;
1610 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1611 reiserfs_warning(s, "Error, %s hash detected, "
1612 "unable to force r5 hash",
1613 reiserfs_hashname(code));
1614 code = UNSET_HASH;
1615 }
1616 } else {
1617 /* find_hash_out was not called or could not determine the hash */
1618 if (reiserfs_rupasov_hash(s)) {
1619 code = YURA_HASH;
1620 } else if (reiserfs_tea_hash(s)) {
1621 code = TEA_HASH;
1622 } else if (reiserfs_r5_hash(s)) {
1623 code = R5_HASH;
1624 }
1625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001627 /* if we are mounted RW, and we have a new valid hash code, update
1628 ** the super
1629 */
1630 if (code != UNSET_HASH &&
1631 !(s->s_flags & MS_RDONLY) &&
1632 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1633 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1634 }
1635 return code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
1638// return pointer to appropriate function
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001639static hashf_t hash_function(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001641 switch (what_hash(s)) {
1642 case TEA_HASH:
1643 reiserfs_info(s, "Using tea hash to sort names\n");
1644 return keyed_hash;
1645 case YURA_HASH:
1646 reiserfs_info(s, "Using rupasov hash to sort names\n");
1647 return yura_hash;
1648 case R5_HASH:
1649 reiserfs_info(s, "Using r5 hash to sort names\n");
1650 return r5_hash;
1651 }
1652 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
1655// this is used to set up correct value for old partitions
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001656static int function2code(hashf_t func)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001658 if (func == keyed_hash)
1659 return TEA_HASH;
1660 if (func == yura_hash)
1661 return YURA_HASH;
1662 if (func == r5_hash)
1663 return R5_HASH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001665 BUG(); // should never happen
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001667 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
1670#define SWARN(silent, s, ...) \
1671 if (!(silent)) \
1672 reiserfs_warning (s, __VA_ARGS__)
1673
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001674static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001676 struct inode *root_inode;
1677 int j;
1678 struct reiserfs_transaction_handle th;
1679 int old_format = 0;
1680 unsigned long blocks;
1681 unsigned int commit_max_age = 0;
1682 int jinit_done = 0;
1683 struct reiserfs_iget_args args;
1684 struct reiserfs_super_block *rs;
1685 char *jdev_name;
1686 struct reiserfs_sb_info *sbi;
1687 int errval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001689 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1690 if (!sbi) {
1691 errval = -ENOMEM;
1692 goto error;
1693 }
1694 s->s_fs_info = sbi;
1695 memset(sbi, 0, sizeof(struct reiserfs_sb_info));
1696 /* Set default values for options: non-aggressive tails, RO on errors */
1697 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1698 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1699 /* no preallocation minimum, be smart in
1700 reiserfs_file_write instead */
1701 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1702 /* Preallocate by 16 blocks (17-1) at once */
1703 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1704 /* Initialize the rwsem for xattr dir */
1705 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001707 /* setup default block allocator options */
1708 reiserfs_init_alloc_options(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001710 jdev_name = NULL;
1711 if (reiserfs_parse_options
1712 (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
1713 &commit_max_age) == 0) {
1714 goto error;
1715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001717 if (blocks) {
1718 SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1719 "for remount only");
1720 goto error;
1721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001723 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1724 if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1725 old_format = 1;
1726 /* try new format (64-th 1k block), which can contain reiserfs super block */
1727 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1728 SWARN(silent, s,
1729 "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
1730 reiserfs_bdevname(s));
1731 goto error;
1732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001734 rs = SB_DISK_SUPER_BLOCK(s);
1735 /* Let's do basic sanity check to verify that underlying device is not
1736 smaller than the filesystem. If the check fails then abort and scream,
1737 because bad stuff will happen otherwise. */
1738 if (s->s_bdev && s->s_bdev->bd_inode
1739 && i_size_read(s->s_bdev->bd_inode) <
1740 sb_block_count(rs) * sb_blocksize(rs)) {
1741 SWARN(silent, s,
1742 "Filesystem on %s cannot be mounted because it is bigger than the device",
1743 reiserfs_bdevname(s));
1744 SWARN(silent, s,
1745 "You may need to run fsck or increase size of your LVM partition");
1746 SWARN(silent, s,
1747 "Or may be you forgot to reboot after fdisk when it told you to");
1748 goto error;
1749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001751 sbi->s_mount_state = SB_REISERFS_STATE(s);
1752 sbi->s_mount_state = REISERFS_VALID_FS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001754 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1755 SWARN(silent, s,
1756 "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1757 goto error;
1758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759#ifdef CONFIG_REISERFS_CHECK
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001760 SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
1761 SWARN(silent, s, "- it is slow mode for debugging.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762#endif
1763
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001764 /* make data=ordered the default */
1765 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1766 !reiserfs_data_writeback(s)) {
1767 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 }
1769
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001770 if (reiserfs_data_log(s)) {
1771 reiserfs_info(s, "using journaled data mode\n");
1772 } else if (reiserfs_data_ordered(s)) {
1773 reiserfs_info(s, "using ordered data mode\n");
1774 } else {
1775 reiserfs_info(s, "using writeback data mode\n");
1776 }
1777 if (reiserfs_barrier_flush(s)) {
1778 printk("reiserfs: using flush barriers\n");
1779 }
1780 // set_device_ro(s->s_dev, 1) ;
1781 if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1782 SWARN(silent, s,
1783 "sh-2022: reiserfs_fill_super: unable to initialize journal space");
1784 goto error;
1785 } else {
1786 jinit_done = 1; /* once this is set, journal_release must be called
1787 ** if we error out of the mount
1788 */
1789 }
1790 if (reread_meta_blocks(s)) {
1791 SWARN(silent, s,
1792 "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
1793 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
1795
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001796 if (replay_only(s))
1797 goto error;
1798
1799 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1800 SWARN(silent, s,
1801 "clm-7000: Detected readonly device, marking FS readonly");
1802 s->s_flags |= MS_RDONLY;
1803 }
1804 args.objectid = REISERFS_ROOT_OBJECTID;
1805 args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
1806 root_inode =
1807 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1808 reiserfs_init_locked_inode, (void *)(&args));
1809 if (!root_inode) {
1810 SWARN(silent, s,
1811 "jmacd-10: reiserfs_fill_super: get root inode failed");
1812 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 }
1814
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001815 if (root_inode->i_state & I_NEW) {
1816 reiserfs_read_locked_inode(root_inode, &args);
1817 unlock_new_inode(root_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 }
1819
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001820 s->s_root = d_alloc_root(root_inode);
1821 if (!s->s_root) {
1822 iput(root_inode);
1823 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001825 // define and initialize hash function
1826 sbi->s_hash_function = hash_function(s);
1827 if (sbi->s_hash_function == NULL) {
1828 dput(s->s_root);
1829 s->s_root = NULL;
1830 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001832
1833 if (is_reiserfs_3_5(rs)
1834 || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
1835 set_bit(REISERFS_3_5, &(sbi->s_properties));
1836 else
1837 set_bit(REISERFS_3_6, &(sbi->s_properties));
1838
1839 if (!(s->s_flags & MS_RDONLY)) {
1840
1841 errval = journal_begin(&th, s, 1);
1842 if (errval) {
1843 dput(s->s_root);
1844 s->s_root = NULL;
1845 goto error;
1846 }
1847 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1848
1849 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1850 set_sb_fs_state(rs, 0);
1851
1852 if (old_format_only(s)) {
1853 /* filesystem of format 3.5 either with standard or non-standard
1854 journal */
1855 if (convert_reiserfs(s)) {
1856 /* and -o conv is given */
1857 if (!silent)
1858 reiserfs_info(s,
1859 "converting 3.5 filesystem to the 3.6 format");
1860
1861 if (is_reiserfs_3_5(rs))
1862 /* put magic string of 3.6 format. 2.2 will not be able to
1863 mount this filesystem anymore */
1864 memcpy(rs->s_v1.s_magic,
1865 reiserfs_3_6_magic_string,
1866 sizeof
1867 (reiserfs_3_6_magic_string));
1868
1869 set_sb_version(rs, REISERFS_VERSION_2);
1870 reiserfs_convert_objectid_map_v1(s);
1871 set_bit(REISERFS_3_6, &(sbi->s_properties));
1872 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1873 } else if (!silent) {
1874 reiserfs_info(s, "using 3.5.x disk format\n");
1875 }
1876 }
1877
1878 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1879 errval = journal_end(&th, s, 1);
1880 if (errval) {
1881 dput(s->s_root);
1882 s->s_root = NULL;
1883 goto error;
1884 }
1885
1886 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1887 dput(s->s_root);
1888 s->s_root = NULL;
1889 goto error;
1890 }
1891
1892 /* look for files which were to be removed in previous session */
1893 finish_unfinished(s);
1894 } else {
1895 if (old_format_only(s) && !silent) {
1896 reiserfs_info(s, "using 3.5.x disk format\n");
1897 }
1898
1899 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1900 dput(s->s_root);
1901 s->s_root = NULL;
1902 goto error;
1903 }
1904 }
1905 // mark hash in super block: it could be unset. overwrite should be ok
1906 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
1907
1908 handle_attrs(s);
1909
1910 reiserfs_proc_info_init(s);
1911
1912 init_waitqueue_head(&(sbi->s_wait));
1913 spin_lock_init(&sbi->bitmap_lock);
1914
1915 return (0);
1916
1917 error:
1918 if (jinit_done) { /* kill the commit thread, free journal ram */
1919 journal_release_error(NULL, s);
1920 }
1921 if (SB_DISK_SUPER_BLOCK(s)) {
1922 for (j = 0; j < SB_BMAP_NR(s); j++) {
1923 if (SB_AP_BITMAP(s))
1924 brelse(SB_AP_BITMAP(s)[j].bh);
1925 }
James Lamannaea0e0a42005-09-10 00:27:16 -07001926 vfree(SB_AP_BITMAP(s));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001927 }
1928 if (SB_BUFFER_WITH_SB(s))
1929 brelse(SB_BUFFER_WITH_SB(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001931 for (j = 0; j < MAXQUOTAS; j++) {
James Lamanna833d3042005-10-30 15:00:16 -08001932 kfree(sbi->s_qf_names[j]);
1933 sbi->s_qf_names[j] = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935#endif
James Lamanna833d3042005-10-30 15:00:16 -08001936 kfree(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001938 s->s_fs_info = NULL;
1939 return errval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001942static int reiserfs_statfs(struct super_block *s, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001944 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1945
1946 buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
1947 buf->f_bfree = sb_free_blocks(rs);
1948 buf->f_bavail = buf->f_bfree;
1949 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
1950 buf->f_bsize = s->s_blocksize;
1951 /* changed to accommodate gcc folks. */
1952 buf->f_type = REISERFS_SUPER_MAGIC;
1953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954}
1955
1956#ifdef CONFIG_QUOTA
1957static int reiserfs_dquot_initialize(struct inode *inode, int type)
1958{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001959 struct reiserfs_transaction_handle th;
1960 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001962 /* We may create quota structure so we need to reserve enough blocks */
1963 reiserfs_write_lock(inode->i_sb);
1964 ret =
1965 journal_begin(&th, inode->i_sb,
1966 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1967 if (ret)
1968 goto out;
1969 ret = dquot_initialize(inode, type);
1970 err =
1971 journal_end(&th, inode->i_sb,
1972 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1973 if (!ret && err)
1974 ret = err;
1975 out:
1976 reiserfs_write_unlock(inode->i_sb);
1977 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
1980static int reiserfs_dquot_drop(struct inode *inode)
1981{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001982 struct reiserfs_transaction_handle th;
1983 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001985 /* We may delete quota structure so we need to reserve enough blocks */
1986 reiserfs_write_lock(inode->i_sb);
1987 ret =
1988 journal_begin(&th, inode->i_sb,
1989 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1990 if (ret)
1991 goto out;
1992 ret = dquot_drop(inode);
1993 err =
1994 journal_end(&th, inode->i_sb,
1995 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1996 if (!ret && err)
1997 ret = err;
1998 out:
1999 reiserfs_write_unlock(inode->i_sb);
2000 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003static int reiserfs_write_dquot(struct dquot *dquot)
2004{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002005 struct reiserfs_transaction_handle th;
2006 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002008 reiserfs_write_lock(dquot->dq_sb);
2009 ret =
2010 journal_begin(&th, dquot->dq_sb,
2011 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
2012 if (ret)
2013 goto out;
2014 ret = dquot_commit(dquot);
2015 err =
2016 journal_end(&th, dquot->dq_sb,
2017 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
2018 if (!ret && err)
2019 ret = err;
2020 out:
2021 reiserfs_write_unlock(dquot->dq_sb);
2022 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023}
2024
2025static int reiserfs_acquire_dquot(struct dquot *dquot)
2026{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002027 struct reiserfs_transaction_handle th;
2028 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002030 reiserfs_write_lock(dquot->dq_sb);
2031 ret =
2032 journal_begin(&th, dquot->dq_sb,
2033 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2034 if (ret)
2035 goto out;
2036 ret = dquot_acquire(dquot);
2037 err =
2038 journal_end(&th, dquot->dq_sb,
2039 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2040 if (!ret && err)
2041 ret = err;
2042 out:
2043 reiserfs_write_unlock(dquot->dq_sb);
2044 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
2047static int reiserfs_release_dquot(struct dquot *dquot)
2048{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002049 struct reiserfs_transaction_handle th;
2050 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002052 reiserfs_write_lock(dquot->dq_sb);
2053 ret =
2054 journal_begin(&th, dquot->dq_sb,
2055 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2056 if (ret)
2057 goto out;
2058 ret = dquot_release(dquot);
2059 err =
2060 journal_end(&th, dquot->dq_sb,
2061 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2062 if (!ret && err)
2063 ret = err;
2064 out:
2065 reiserfs_write_unlock(dquot->dq_sb);
2066 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
2069static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
2070{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002071 /* Are we journalling quotas? */
2072 if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
2073 REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
2074 dquot_mark_dquot_dirty(dquot);
2075 return reiserfs_write_dquot(dquot);
2076 } else
2077 return dquot_mark_dquot_dirty(dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
2080static int reiserfs_write_info(struct super_block *sb, int type)
2081{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002082 struct reiserfs_transaction_handle th;
2083 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002085 /* Data block + inode block */
2086 reiserfs_write_lock(sb);
2087 ret = journal_begin(&th, sb, 2);
2088 if (ret)
2089 goto out;
2090 ret = dquot_commit_info(sb, type);
2091 err = journal_end(&th, sb, 2);
2092 if (!ret && err)
2093 ret = err;
2094 out:
2095 reiserfs_write_unlock(sb);
2096 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
2099/*
Christoph Hellwig84de8562005-06-23 00:09:16 -07002100 * Turn on quotas during mount time - we need to find the quota file and such...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 */
2102static int reiserfs_quota_on_mount(struct super_block *sb, int type)
2103{
Christoph Hellwig84de8562005-06-23 00:09:16 -07002104 return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002105 REISERFS_SB(sb)->s_jquota_fmt, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Standard function to be called on quota_on
2110 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002111static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2112 char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002114 int err;
2115 struct nameidata nd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002117 if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
2118 return -EINVAL;
2119 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
2120 if (err)
2121 return err;
2122 /* Quotafile not on the same filesystem? */
2123 if (nd.mnt->mnt_sb != sb) {
2124 path_release(&nd);
2125 return -EXDEV;
2126 }
2127 /* We must not pack tails for quota files on reiserfs for quota IO to work */
2128 if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
2129 reiserfs_warning(sb,
2130 "reiserfs: Quota file must have tail packing disabled.");
2131 path_release(&nd);
2132 return -EINVAL;
2133 }
2134 /* Not journalling quota? No more tests needed... */
2135 if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
2136 !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
2137 path_release(&nd);
2138 return vfs_quota_on(sb, type, format_id, path);
2139 }
2140 /* Quotafile not of fs root? */
2141 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2142 reiserfs_warning(sb,
2143 "reiserfs: Quota file not on filesystem root. "
2144 "Journalled quota will not work.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 path_release(&nd);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002146 return vfs_quota_on(sb, type, format_id, path);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/* Read data from quotafile - avoid pagecache and such because we cannot afford
2150 * acquiring the locks... As quota files are never truncated and quota code
2151 * itself serializes the operations (and noone else should touch the files)
2152 * we don't have to be afraid of races */
2153static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2154 size_t len, loff_t off)
2155{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002156 struct inode *inode = sb_dqopt(sb)->files[type];
2157 unsigned long blk = off >> sb->s_blocksize_bits;
2158 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2159 size_t toread;
2160 struct buffer_head tmp_bh, *bh;
2161 loff_t i_size = i_size_read(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002163 if (off > i_size)
2164 return 0;
2165 if (off + len > i_size)
2166 len = i_size - off;
2167 toread = len;
2168 while (toread > 0) {
2169 tocopy =
2170 sb->s_blocksize - offset <
2171 toread ? sb->s_blocksize - offset : toread;
2172 tmp_bh.b_state = 0;
2173 /* Quota files are without tails so we can safely use this function */
2174 reiserfs_write_lock(sb);
2175 err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
2176 reiserfs_write_unlock(sb);
2177 if (err)
2178 return err;
2179 if (!buffer_mapped(&tmp_bh)) /* A hole? */
2180 memset(data, 0, tocopy);
2181 else {
2182 bh = sb_bread(sb, tmp_bh.b_blocknr);
2183 if (!bh)
2184 return -EIO;
2185 memcpy(data, bh->b_data + offset, tocopy);
2186 brelse(bh);
2187 }
2188 offset = 0;
2189 toread -= tocopy;
2190 data += tocopy;
2191 blk++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002193 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/* Write to quotafile (we know the transaction is already started and has
2197 * enough credits) */
2198static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2199 const char *data, size_t len, loff_t off)
2200{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002201 struct inode *inode = sb_dqopt(sb)->files[type];
2202 unsigned long blk = off >> sb->s_blocksize_bits;
2203 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2204 int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
2205 size_t towrite = len;
2206 struct buffer_head tmp_bh, *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08002208 mutex_lock(&inode->i_mutex);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002209 while (towrite > 0) {
2210 tocopy = sb->s_blocksize - offset < towrite ?
2211 sb->s_blocksize - offset : towrite;
2212 tmp_bh.b_state = 0;
2213 err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
2214 if (err)
2215 goto out;
2216 if (offset || tocopy != sb->s_blocksize)
2217 bh = sb_bread(sb, tmp_bh.b_blocknr);
2218 else
2219 bh = sb_getblk(sb, tmp_bh.b_blocknr);
2220 if (!bh) {
2221 err = -EIO;
2222 goto out;
2223 }
2224 lock_buffer(bh);
2225 memcpy(bh->b_data + offset, data, tocopy);
2226 flush_dcache_page(bh->b_page);
2227 set_buffer_uptodate(bh);
2228 unlock_buffer(bh);
2229 reiserfs_prepare_for_journal(sb, bh, 1);
2230 journal_mark_dirty(current->journal_info, sb, bh);
2231 if (!journal_quota)
2232 reiserfs_add_ordered_list(inode, bh);
2233 brelse(bh);
2234 offset = 0;
2235 towrite -= tocopy;
2236 data += tocopy;
2237 blk++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002239 out:
2240 if (len == towrite)
2241 return err;
2242 if (inode->i_size < off + len - towrite)
2243 i_size_write(inode, off + len - towrite);
2244 inode->i_version++;
2245 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2246 mark_inode_dirty(inode);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08002247 mutex_unlock(&inode->i_mutex);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002248 return len - towrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251#endif
2252
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002253static struct super_block *get_super_block(struct file_system_type *fs_type,
2254 int flags, const char *dev_name,
2255 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
2258}
2259
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002260static int __init init_reiserfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261{
2262 int ret;
2263
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002264 if ((ret = init_inodecache())) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 return ret;
2266 }
2267
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002268 if ((ret = reiserfs_xattr_register_handlers()))
2269 goto failed_reiserfs_xattr_register_handlers;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002271 reiserfs_proc_info_global_init();
2272 reiserfs_proc_register_global("version",
2273 reiserfs_global_version_in_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002275 ret = register_filesystem(&reiserfs_fs_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 if (ret == 0) {
2278 return 0;
2279 }
2280
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002281 reiserfs_xattr_unregister_handlers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002283 failed_reiserfs_xattr_register_handlers:
2284 reiserfs_proc_unregister_global("version");
2285 reiserfs_proc_info_global_done();
2286 destroy_inodecache();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
2288 return ret;
2289}
2290
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002291static void __exit exit_reiserfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002293 reiserfs_xattr_unregister_handlers();
2294 reiserfs_proc_unregister_global("version");
2295 reiserfs_proc_info_global_done();
2296 unregister_filesystem(&reiserfs_fs_type);
2297 destroy_inodecache();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300struct file_system_type reiserfs_fs_type = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002301 .owner = THIS_MODULE,
2302 .name = "reiserfs",
2303 .get_sb = get_super_block,
2304 .kill_sb = kill_block_super,
2305 .fs_flags = FS_REQUIRES_DEV,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306};
2307
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002308MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2309MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2310MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002312module_init(init_reiserfs_fs);
2313module_exit(exit_reiserfs_fs);