blob: b40d4d64d598b83ce47b578ed487a7f282178605 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/vmalloc.h>
16#include <linux/time.h>
17#include <asm/uaccess.h>
18#include <linux/reiserfs_fs.h>
19#include <linux/reiserfs_acl.h>
20#include <linux/reiserfs_xattr.h>
21#include <linux/smp_lock.h>
22#include <linux/init.h>
23#include <linux/blkdev.h>
24#include <linux/buffer_head.h>
25#include <linux/vfs.h>
26#include <linux/namespace.h>
27#include <linux/mount.h>
28#include <linux/namei.h>
29#include <linux/quotaops.h>
30
31struct file_system_type reiserfs_fs_type;
32
33static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
34static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
35static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
36
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070037int is_reiserfs_3_5(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070039 return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
40 strlen(reiserfs_3_5_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070043int is_reiserfs_3_6(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070045 return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
46 strlen(reiserfs_3_6_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070049int is_reiserfs_jr(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070051 return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
52 strlen(reiserfs_jr_magic_string));
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070055static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070057 return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
58 is_reiserfs_jr(rs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070061static int reiserfs_remount(struct super_block *s, int *flags, char *data);
David Howells726c3342006-06-23 02:02:58 -070062static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070064static int reiserfs_sync_fs(struct super_block *s, int wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070066 if (!(s->s_flags & MS_RDONLY)) {
67 struct reiserfs_transaction_handle th;
68 reiserfs_write_lock(s);
69 if (!journal_begin(&th, s, 1))
70 if (!journal_end_sync(&th, s, 1))
71 reiserfs_flush_old_commits(s);
72 s->s_dirt = 0; /* Even if it's not true.
73 * We'll loop forever in sync_supers otherwise */
74 reiserfs_write_unlock(s);
75 } else {
76 s->s_dirt = 0;
77 }
78 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
81static void reiserfs_write_super(struct super_block *s)
82{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070083 reiserfs_sync_fs(s, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070086static void reiserfs_write_super_lockfs(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070088 struct reiserfs_transaction_handle th;
89 reiserfs_write_lock(s);
90 if (!(s->s_flags & MS_RDONLY)) {
91 int err = journal_begin(&th, s, 1);
92 if (err) {
93 reiserfs_block_writes(&th);
94 } else {
95 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
96 1);
97 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
98 reiserfs_block_writes(&th);
99 journal_end_sync(&th, s, 1);
100 }
101 }
102 s->s_dirt = 0;
103 reiserfs_write_unlock(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700106static void reiserfs_unlockfs(struct super_block *s)
107{
108 reiserfs_allow_writes(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700111extern const struct in_core_key MAX_IN_CORE_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113/* this is used to delete "save link" when there are no items of a
114 file it points to. It can either happen if unlink is completed but
115 "save unlink" removal, or if file has both unlink and truncate
116 pending and as unlink completes first (because key of "save link"
117 protecting unlink is bigger that a key lf "save link" which
118 protects truncate), so there left no items to make truncate
119 completion on */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700120static int remove_save_link_only(struct super_block *s,
121 struct reiserfs_key *key, int oid_free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700123 struct reiserfs_transaction_handle th;
124 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700126 /* we are going to do one balancing */
127 err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
128 if (err)
129 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700131 reiserfs_delete_solid_item(&th, NULL, key);
132 if (oid_free)
133 /* removals are protected by direct items */
134 reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
135
136 return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef CONFIG_QUOTA
140static int reiserfs_quota_on_mount(struct super_block *, int);
141#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/* look for uncompleted unlinks and truncates and complete them */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700144static int finish_unfinished(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700146 INITIALIZE_PATH(path);
147 struct cpu_key max_cpu_key, obj_key;
148 struct reiserfs_key save_link_key;
149 int retval = 0;
150 struct item_head *ih;
151 struct buffer_head *bh;
152 int item_pos;
153 char *item;
154 int done;
155 struct inode *inode;
156 int truncate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700158 int i;
159 int ms_active_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700161
162 /* compose key to look for "save" links */
163 max_cpu_key.version = KEY_FORMAT_3_5;
164 max_cpu_key.on_disk_key.k_dir_id = ~0U;
165 max_cpu_key.on_disk_key.k_objectid = ~0U;
166 set_cpu_key_k_offset(&max_cpu_key, ~0U);
167 max_cpu_key.key_length = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700170 /* Needed for iput() to work correctly and not trash data */
171 if (s->s_flags & MS_ACTIVE) {
172 ms_active_set = 0;
173 } else {
174 ms_active_set = 1;
175 s->s_flags |= MS_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700177 /* Turn on quotas so that they are updated correctly */
178 for (i = 0; i < MAXQUOTAS; i++) {
179 if (REISERFS_SB(s)->s_qf_names[i]) {
180 int ret = reiserfs_quota_on_mount(s, i);
181 if (ret < 0)
182 reiserfs_warning(s,
183 "reiserfs: cannot turn on journalled quota: error %d",
184 ret);
185 }
186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700189 done = 0;
190 REISERFS_SB(s)->s_is_unlinked_ok = 1;
191 while (!retval) {
192 retval = search_item(s, &max_cpu_key, &path);
193 if (retval != ITEM_NOT_FOUND) {
194 reiserfs_warning(s,
195 "vs-2140: finish_unfinished: search_by_key returned %d",
196 retval);
197 break;
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700200 bh = get_last_bh(&path);
201 item_pos = get_item_pos(&path);
202 if (item_pos != B_NR_ITEMS(bh)) {
203 reiserfs_warning(s,
204 "vs-2060: finish_unfinished: wrong position found");
205 break;
206 }
207 item_pos--;
208 ih = B_N_PITEM_HEAD(bh, item_pos);
209
210 if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
211 /* there are no "save" links anymore */
212 break;
213
214 save_link_key = ih->ih_key;
215 if (is_indirect_le_ih(ih))
216 truncate = 1;
217 else
218 truncate = 0;
219
220 /* reiserfs_iget needs k_dirid and k_objectid only */
221 item = B_I_PITEM(bh, ih);
222 obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
223 obj_key.on_disk_key.k_objectid =
224 le32_to_cpu(ih->ih_key.k_objectid);
225 obj_key.on_disk_key.k_offset = 0;
226 obj_key.on_disk_key.k_type = 0;
227
228 pathrelse(&path);
229
230 inode = reiserfs_iget(s, &obj_key);
231 if (!inode) {
232 /* the unlink almost completed, it just did not manage to remove
233 "save" link and release objectid */
234 reiserfs_warning(s,
235 "vs-2180: finish_unfinished: iget failed for %K",
236 &obj_key);
237 retval = remove_save_link_only(s, &save_link_key, 1);
238 continue;
239 }
240
241 if (!truncate && inode->i_nlink) {
242 /* file is not unlinked */
243 reiserfs_warning(s,
244 "vs-2185: finish_unfinished: file %K is not unlinked",
245 &obj_key);
246 retval = remove_save_link_only(s, &save_link_key, 0);
247 continue;
248 }
249 DQUOT_INIT(inode);
250
251 if (truncate && S_ISDIR(inode->i_mode)) {
252 /* We got a truncate request for a dir which is impossible.
253 The only imaginable way is to execute unfinished truncate request
254 then boot into old kernel, remove the file and create dir with
255 the same key. */
256 reiserfs_warning(s,
257 "green-2101: impossible truncate on a directory %k. Please report",
258 INODE_PKEY(inode));
259 retval = remove_save_link_only(s, &save_link_key, 0);
260 truncate = 0;
261 iput(inode);
262 continue;
263 }
264
265 if (truncate) {
266 REISERFS_I(inode)->i_flags |=
267 i_link_saved_truncate_mask;
268 /* not completed truncate found. New size was committed together
269 with "save" link */
270 reiserfs_info(s, "Truncating %k to %Ld ..",
271 INODE_PKEY(inode), inode->i_size);
272 reiserfs_truncate_file(inode,
273 0
274 /*don't update modification time */
275 );
276 retval = remove_save_link(inode, truncate);
277 } else {
278 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
279 /* not completed unlink (rmdir) found */
280 reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
281 /* removal gets completed in iput */
282 retval = 0;
283 }
284
285 iput(inode);
286 printk("done\n");
287 done++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700289 REISERFS_SB(s)->s_is_unlinked_ok = 0;
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700292 /* Turn quotas off */
293 for (i = 0; i < MAXQUOTAS; i++) {
294 if (sb_dqopt(s)->files[i])
295 vfs_quota_off_mount(s, i);
296 }
297 if (ms_active_set)
298 /* Restore the flag back */
299 s->s_flags &= ~MS_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700301 pathrelse(&path);
302 if (done)
303 reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
304 "Completed\n", done);
305 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308/* to protect file being unlinked from getting lost we "safe" link files
309 being unlinked. This link will be deleted in the same transaction with last
310 item of file. mounting the filesytem we scan all these links and remove
311 files which almost got lost */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700312void add_save_link(struct reiserfs_transaction_handle *th,
313 struct inode *inode, int truncate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700315 INITIALIZE_PATH(path);
316 int retval;
317 struct cpu_key key;
318 struct item_head ih;
319 __le32 link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700321 BUG_ON(!th->t_trans_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700323 /* file can only get one "save link" of each kind */
324 RFALSE(truncate &&
325 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
326 "saved link already exists for truncated inode %lx",
327 (long)inode->i_ino);
328 RFALSE(!truncate &&
329 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
330 "saved link already exists for unlinked inode %lx",
331 (long)inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700333 /* setup key of "save" link */
334 key.version = KEY_FORMAT_3_5;
335 key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
336 key.on_disk_key.k_objectid = inode->i_ino;
337 if (!truncate) {
338 /* unlink, rmdir, rename */
339 set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
340 set_cpu_key_k_type(&key, TYPE_DIRECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700342 /* item head of "safe" link */
343 make_le_item_head(&ih, &key, key.version,
344 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
345 4 /*length */ , 0xffff /*free space */ );
346 } else {
347 /* truncate */
348 if (S_ISDIR(inode->i_mode))
349 reiserfs_warning(inode->i_sb,
350 "green-2102: Adding a truncate savelink for a directory %k! Please report",
351 INODE_PKEY(inode));
352 set_cpu_key_k_offset(&key, 1);
353 set_cpu_key_k_type(&key, TYPE_INDIRECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700355 /* item head of "safe" link */
356 make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
357 4 /*length */ , 0 /*free space */ );
358 }
359 key.key_length = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700361 /* look for its place in the tree */
362 retval = search_item(inode->i_sb, &key, &path);
363 if (retval != ITEM_NOT_FOUND) {
364 if (retval != -ENOSPC)
365 reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
366 "search_by_key (%K) returned %d", &key,
367 retval);
368 pathrelse(&path);
369 return;
370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700372 /* body of "save" link */
373 link = INODE_PKEY(inode)->k_dir_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700375 /* put "save" link inot tree, don't charge quota to anyone */
376 retval =
377 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
378 if (retval) {
379 if (retval != -ENOSPC)
380 reiserfs_warning(inode->i_sb,
381 "vs-2120: add_save_link: insert_item returned %d",
382 retval);
383 } else {
384 if (truncate)
385 REISERFS_I(inode)->i_flags |=
386 i_link_saved_truncate_mask;
387 else
388 REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392/* this opens transaction unlike add_save_link */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700393int remove_save_link(struct inode *inode, int truncate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700395 struct reiserfs_transaction_handle th;
396 struct reiserfs_key key;
397 int err;
398
399 /* we are going to do one balancing only */
400 err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
401 if (err)
402 return err;
403
404 /* setup key of "save" link */
405 key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
406 key.k_objectid = INODE_PKEY(inode)->k_objectid;
407 if (!truncate) {
408 /* unlink, rmdir, rename */
409 set_le_key_k_offset(KEY_FORMAT_3_5, &key,
410 1 + inode->i_sb->s_blocksize);
411 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
412 } else {
413 /* truncate */
414 set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
415 set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
416 }
417
418 if ((truncate &&
419 (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
420 (!truncate &&
421 (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
422 /* don't take quota bytes from anywhere */
423 reiserfs_delete_solid_item(&th, NULL, &key);
424 if (!truncate) {
425 reiserfs_release_objectid(&th, inode->i_ino);
426 REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
427 } else
428 REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
429
430 return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700433static void reiserfs_put_super(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700435 int i;
436 struct reiserfs_transaction_handle th;
437 th.t_trans_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700439 if (REISERFS_SB(s)->xattr_root) {
440 d_invalidate(REISERFS_SB(s)->xattr_root);
441 dput(REISERFS_SB(s)->xattr_root);
442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700444 if (REISERFS_SB(s)->priv_root) {
445 d_invalidate(REISERFS_SB(s)->priv_root);
446 dput(REISERFS_SB(s)->priv_root);
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700449 /* change file system state to current state if it was mounted with read-write permissions */
450 if (!(s->s_flags & MS_RDONLY)) {
451 if (!journal_begin(&th, s, 10)) {
452 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
453 1);
454 set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
455 REISERFS_SB(s)->s_mount_state);
456 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
457 }
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700460 /* note, journal_release checks for readonly mount, and can decide not
461 ** to do a journal_end
462 */
463 journal_release(&th, s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700465 for (i = 0; i < SB_BMAP_NR(s); i++)
466 brelse(SB_AP_BITMAP(s)[i].bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700468 vfree(SB_AP_BITMAP(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700470 brelse(SB_BUFFER_WITH_SB(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700472 print_statistics(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700474 if (REISERFS_SB(s)->reserved_blocks != 0) {
475 reiserfs_warning(s,
476 "green-2005: reiserfs_put_super: reserved blocks left %d",
477 REISERFS_SB(s)->reserved_blocks);
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700480 reiserfs_proc_info_done(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700482 kfree(s->s_fs_info);
483 s->s_fs_info = NULL;
484
485 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700488static kmem_cache_t *reiserfs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490static struct inode *reiserfs_alloc_inode(struct super_block *sb)
491{
492 struct reiserfs_inode_info *ei;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700493 ei = (struct reiserfs_inode_info *)
494 kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (!ei)
496 return NULL;
497 return &ei->vfs_inode;
498}
499
500static void reiserfs_destroy_inode(struct inode *inode)
501{
502 kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
503}
504
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700505static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700507 struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700509 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 SLAB_CTOR_CONSTRUCTOR) {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700511 INIT_LIST_HEAD(&ei->i_prealloc_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 inode_init_once(&ei->vfs_inode);
513 ei->i_acl_access = NULL;
514 ei->i_acl_default = NULL;
515 }
516}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518static int init_inodecache(void)
519{
520 reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700521 sizeof(struct
522 reiserfs_inode_info),
Paul Jacksonfffb60f2006-03-24 03:16:06 -0800523 0, (SLAB_RECLAIM_ACCOUNT|
524 SLAB_MEM_SPREAD),
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700525 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{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -0700533 kmem_cache_destroy(reiserfs_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
535
536/* we don't mark inodes dirty, we just log them */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700537static void reiserfs_dirty_inode(struct inode *inode)
538{
539 struct reiserfs_transaction_handle th;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700541 int err = 0;
542 if (inode->i_sb->s_flags & MS_RDONLY) {
543 reiserfs_warning(inode->i_sb,
544 "clm-6006: writing inode %lu on readonly FS",
545 inode->i_ino);
546 return;
547 }
548 reiserfs_write_lock(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700550 /* this is really only used for atime updates, so they don't have
551 ** to be included in O_SYNC or fsync
552 */
553 err = journal_begin(&th, inode->i_sb, 1);
554 if (err) {
555 reiserfs_write_unlock(inode->i_sb);
556 return;
557 }
558 reiserfs_update_sd(&th, inode);
559 journal_end(&th, inode->i_sb, 1);
560 reiserfs_write_unlock(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700563static void reiserfs_clear_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700565 struct posix_acl *acl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700567 acl = REISERFS_I(inode)->i_acl_access;
568 if (acl && !IS_ERR(acl))
569 posix_acl_release(acl);
570 REISERFS_I(inode)->i_acl_access = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700572 acl = REISERFS_I(inode)->i_acl_default;
573 if (acl && !IS_ERR(acl))
574 posix_acl_release(acl);
575 REISERFS_I(inode)->i_acl_default = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
578#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700579static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
580 size_t, loff_t);
581static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
582 loff_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#endif
584
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700585static struct super_operations reiserfs_sops = {
586 .alloc_inode = reiserfs_alloc_inode,
587 .destroy_inode = reiserfs_destroy_inode,
588 .write_inode = reiserfs_write_inode,
589 .dirty_inode = reiserfs_dirty_inode,
590 .delete_inode = reiserfs_delete_inode,
591 .clear_inode = reiserfs_clear_inode,
592 .put_super = reiserfs_put_super,
593 .write_super = reiserfs_write_super,
594 .sync_fs = reiserfs_sync_fs,
595 .write_super_lockfs = reiserfs_write_super_lockfs,
596 .unlockfs = reiserfs_unlockfs,
597 .statfs = reiserfs_statfs,
598 .remount_fs = reiserfs_remount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700600 .quota_read = reiserfs_quota_read,
601 .quota_write = reiserfs_quota_write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#endif
603};
604
605#ifdef CONFIG_QUOTA
606#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
607
608static int reiserfs_dquot_initialize(struct inode *, int);
609static int reiserfs_dquot_drop(struct inode *);
610static int reiserfs_write_dquot(struct dquot *);
611static int reiserfs_acquire_dquot(struct dquot *);
612static int reiserfs_release_dquot(struct dquot *);
613static int reiserfs_mark_dquot_dirty(struct dquot *);
614static int reiserfs_write_info(struct super_block *, int);
615static int reiserfs_quota_on(struct super_block *, int, int, char *);
616
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700617static struct dquot_operations reiserfs_quota_operations = {
618 .initialize = reiserfs_dquot_initialize,
619 .drop = reiserfs_dquot_drop,
620 .alloc_space = dquot_alloc_space,
621 .alloc_inode = dquot_alloc_inode,
622 .free_space = dquot_free_space,
623 .free_inode = dquot_free_inode,
624 .transfer = dquot_transfer,
625 .write_dquot = reiserfs_write_dquot,
626 .acquire_dquot = reiserfs_acquire_dquot,
627 .release_dquot = reiserfs_release_dquot,
628 .mark_dirty = reiserfs_mark_dquot_dirty,
629 .write_info = reiserfs_write_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630};
631
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700632static struct quotactl_ops reiserfs_qctl_operations = {
633 .quota_on = reiserfs_quota_on,
634 .quota_off = vfs_quota_off,
635 .quota_sync = vfs_quota_sync,
636 .get_info = vfs_get_dqinfo,
637 .set_info = vfs_set_dqinfo,
638 .get_dqblk = vfs_get_dqblk,
639 .set_dqblk = vfs_set_dqblk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640};
641#endif
642
643static struct export_operations reiserfs_export_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700644 .encode_fh = reiserfs_encode_fh,
645 .decode_fh = reiserfs_decode_fh,
646 .get_parent = reiserfs_get_parent,
647 .get_dentry = reiserfs_get_dentry,
648};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650/* this struct is used in reiserfs_getopt () for containing the value for those
651 mount options that have values rather than being toggles. */
652typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700653 char *value;
654 int setmask; /* bitmask which is to set on mount_options bitmask when this
655 value is found, 0 is no bits are to be changed. */
656 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
657 value is found, 0 is no bits are to be changed. This is
658 applied BEFORE setmask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659} arg_desc_t;
660
661/* Set this bit in arg_required to allow empty arguments */
662#define REISERFS_OPT_ALLOWEMPTY 31
663
664/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
665 mount options */
666typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700667 char *option_name;
668 int arg_required; /* 0 if argument is not required, not 0 otherwise */
669 const arg_desc_t *values; /* list of values accepted by an option */
670 int setmask; /* bitmask which is to set on mount_options bitmask when this
671 value is found, 0 is no bits are to be changed. */
672 int clrmask; /* bitmask which is to clear on mount_options bitmask when this
673 value is found, 0 is no bits are to be changed. This is
674 applied BEFORE setmask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675} opt_desc_t;
676
677/* possible values for -o data= */
678static const arg_desc_t logging_mode[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700679 {"ordered", 1 << REISERFS_DATA_ORDERED,
680 (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
681 {"journal", 1 << REISERFS_DATA_LOG,
682 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
683 {"writeback", 1 << REISERFS_DATA_WRITEBACK,
684 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
Vladimir V. Savelievcd02b962006-03-25 03:07:15 -0800685 {.value = NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686};
687
688/* possible values for -o barrier= */
689static const arg_desc_t barrier_mode[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700690 {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
691 {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
Vladimir V. Savelievcd02b962006-03-25 03:07:15 -0800692 {.value = NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693};
694
695/* possible values for "-o block-allocator=" and bits which are to be set in
696 s_mount_opt of reiserfs specific part of in-core super block */
697static const arg_desc_t balloc[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700698 {"noborder", 1 << REISERFS_NO_BORDER, 0},
699 {"border", 0, 1 << REISERFS_NO_BORDER},
700 {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
701 {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
702 {"test4", 1 << REISERFS_TEST4, 0},
703 {"notest4", 0, 1 << REISERFS_TEST4},
704 {NULL, 0, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705};
706
707static const arg_desc_t tails[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700708 {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
709 {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
710 {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
711 {NULL, 0, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712};
713
714static const arg_desc_t error_actions[] = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700715 {"panic", 1 << REISERFS_ERROR_PANIC,
716 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
717 {"ro-remount", 1 << REISERFS_ERROR_RO,
718 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700720 {"continue", 1 << REISERFS_ERROR_CONTINUE,
721 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700723 {NULL, 0, 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724};
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726/* proceed only one option from a list *cur - string containing of mount options
727 opts - array of options which are accepted
728 opt_arg - if option is found and requires an argument and if it is specifed
729 in the input - pointer to the argument is stored here
730 bit_flags - if option requires to set a certain bit - it is set here
731 return -1 if unknown option is found, opt->arg_required otherwise */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700732static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
733 char **opt_arg, unsigned long *bit_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700735 char *p;
736 /* foo=bar,
737 ^ ^ ^
738 | | +-- option_end
739 | +-- arg_start
740 +-- option_start
741 */
742 const opt_desc_t *opt;
743 const arg_desc_t *arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700745 p = *cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700747 /* assume argument cannot contain commas */
748 *cur = strchr(p, ',');
749 if (*cur) {
750 *(*cur) = '\0';
751 (*cur)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700754 if (!strncmp(p, "alloc=", 6)) {
755 /* Ugly special case, probably we should redo options parser so that
756 it can understand several arguments for some options, also so that
757 it can fill several bitfields with option values. */
758 if (reiserfs_parse_alloc_options(s, p + 6)) {
759 return -1;
760 } else {
761 return 0;
762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700764
765 /* for every option in the list */
766 for (opt = opts; opt->option_name; opt++) {
767 if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
768 if (bit_flags) {
769 if (opt->clrmask ==
770 (1 << REISERFS_UNSUPPORTED_OPT))
771 reiserfs_warning(s, "%s not supported.",
772 p);
773 else
774 *bit_flags &= ~opt->clrmask;
775 if (opt->setmask ==
776 (1 << REISERFS_UNSUPPORTED_OPT))
777 reiserfs_warning(s, "%s not supported.",
778 p);
779 else
780 *bit_flags |= opt->setmask;
781 }
782 break;
783 }
784 }
785 if (!opt->option_name) {
786 reiserfs_warning(s, "unknown mount option \"%s\"", p);
787 return -1;
788 }
789
790 p += strlen(opt->option_name);
791 switch (*p) {
792 case '=':
793 if (!opt->arg_required) {
794 reiserfs_warning(s,
795 "the option \"%s\" does not require an argument",
796 opt->option_name);
797 return -1;
798 }
799 break;
800
801 case 0:
802 if (opt->arg_required) {
803 reiserfs_warning(s,
804 "the option \"%s\" requires an argument",
805 opt->option_name);
806 return -1;
807 }
808 break;
809 default:
810 reiserfs_warning(s, "head of option \"%s\" is only correct",
811 opt->option_name);
812 return -1;
813 }
814
815 /* move to the argument, or to next option if argument is not required */
816 p++;
817
818 if (opt->arg_required
819 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
820 && !strlen(p)) {
821 /* this catches "option=," if not allowed */
822 reiserfs_warning(s, "empty argument for \"%s\"",
823 opt->option_name);
824 return -1;
825 }
826
827 if (!opt->values) {
828 /* *=NULLopt_arg contains pointer to argument */
829 *opt_arg = p;
830 return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
831 }
832
833 /* values possible for this option are listed in opt->values */
834 for (arg = opt->values; arg->value; arg++) {
835 if (!strcmp(p, arg->value)) {
836 if (bit_flags) {
837 *bit_flags &= ~arg->clrmask;
838 *bit_flags |= arg->setmask;
839 }
840 return opt->arg_required;
841 }
842 }
843
844 reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
845 opt->option_name);
846 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849/* returns 0 if something is wrong in option string, 1 - otherwise */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700850static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
851 unsigned long *mount_options,
852 /* after the parsing phase, contains the
853 collection of bitflags defining what
854 mount options were selected. */
855 unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
856 char **jdev_name,
857 unsigned int *commit_max_age)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700859 int c;
860 char *arg = NULL;
861 char *pos;
862 opt_desc_t opts[] = {
863 /* Compatibility stuff, so that -o notail for old setups still work */
864 {"tails",.arg_required = 't',.values = tails},
865 {"notail",.clrmask =
866 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
867 {"conv",.setmask = 1 << REISERFS_CONVERT},
868 {"attrs",.setmask = 1 << REISERFS_ATTRS},
869 {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870#ifdef CONFIG_REISERFS_FS_XATTR
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700871 {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
872 {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873#else
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700874 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
875 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876#endif
877#ifdef CONFIG_REISERFS_FS_POSIX_ACL
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700878 {"acl",.setmask = 1 << REISERFS_POSIXACL},
879 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880#else
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700881 {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
882 {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883#endif
Vladimir V. Savelievcd02b962006-03-25 03:07:15 -0800884 {.option_name = "nolog"},
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700885 {"replayonly",.setmask = 1 << REPLAYONLY},
886 {"block-allocator",.arg_required = 'a',.values = balloc},
887 {"data",.arg_required = 'd',.values = logging_mode},
888 {"barrier",.arg_required = 'b',.values = barrier_mode},
889 {"resize",.arg_required = 'r',.values = NULL},
890 {"jdev",.arg_required = 'j',.values = NULL},
891 {"nolargeio",.arg_required = 'w',.values = NULL},
892 {"commit",.arg_required = 'c',.values = NULL},
893 {"usrquota",.setmask = 1 << REISERFS_QUOTA},
894 {"grpquota",.setmask = 1 << REISERFS_QUOTA},
895 {"noquota",.clrmask = 1 << REISERFS_QUOTA},
896 {"errors",.arg_required = 'e',.values = error_actions},
897 {"usrjquota",.arg_required =
898 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
899 {"grpjquota",.arg_required =
900 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
901 {"jqfmt",.arg_required = 'f',.values = NULL},
Vladimir V. Savelievcd02b962006-03-25 03:07:15 -0800902 {.option_name = NULL}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700903 };
904
905 *blocks = 0;
906 if (!options || !*options)
907 /* use default configuration: create tails, journaling on, no
908 conversion to newest format */
909 return 1;
910
911 for (pos = options; pos;) {
912 c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
913 if (c == -1)
914 /* wrong option is given */
915 return 0;
916
917 if (c == 'r') {
918 char *p;
919
920 p = NULL;
921 /* "resize=NNN" or "resize=auto" */
922
923 if (!strcmp(arg, "auto")) {
924 /* From JFS code, to auto-get the size. */
925 *blocks =
926 s->s_bdev->bd_inode->i_size >> s->
927 s_blocksize_bits;
928 } else {
929 *blocks = simple_strtoul(arg, &p, 0);
930 if (*p != '\0') {
931 /* NNN does not look like a number */
932 reiserfs_warning(s,
933 "reiserfs_parse_options: bad value %s",
934 arg);
935 return 0;
936 }
937 }
938 }
939
940 if (c == 'c') {
941 char *p = NULL;
942 unsigned long val = simple_strtoul(arg, &p, 0);
943 /* commit=NNN (time in seconds) */
944 if (*p != '\0' || val >= (unsigned int)-1) {
945 reiserfs_warning(s,
946 "reiserfs_parse_options: bad value %s",
947 arg);
948 return 0;
949 }
950 *commit_max_age = (unsigned int)val;
951 }
952
953 if (c == 'w') {
Adrian Bunk36b756f2006-09-27 01:50:50 -0700954 reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported");
955 return 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700956 }
957
958 if (c == 'j') {
959 if (arg && *arg && jdev_name) {
960 if (*jdev_name) { //Hm, already assigned?
961 reiserfs_warning(s,
962 "reiserfs_parse_options: journal device was already specified to be %s",
963 *jdev_name);
964 return 0;
965 }
966 *jdev_name = arg;
967 }
968 }
969#ifdef CONFIG_QUOTA
970 if (c == 'u' || c == 'g') {
971 int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
972
973 if (sb_any_quota_enabled(s)) {
974 reiserfs_warning(s,
975 "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
976 return 0;
977 }
978 if (*arg) { /* Some filename specified? */
979 if (REISERFS_SB(s)->s_qf_names[qtype]
980 && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
981 arg)) {
982 reiserfs_warning(s,
983 "reiserfs_parse_options: %s quota file already specified.",
984 QTYPE2NAME(qtype));
985 return 0;
986 }
987 if (strchr(arg, '/')) {
988 reiserfs_warning(s,
989 "reiserfs_parse_options: quotafile must be on filesystem root.");
990 return 0;
991 }
992 REISERFS_SB(s)->s_qf_names[qtype] =
993 kmalloc(strlen(arg) + 1, GFP_KERNEL);
994 if (!REISERFS_SB(s)->s_qf_names[qtype]) {
995 reiserfs_warning(s,
996 "reiserfs_parse_options: not enough memory for storing quotafile name.");
997 return 0;
998 }
999 strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
1000 *mount_options |= 1 << REISERFS_QUOTA;
1001 } else {
James Lamanna833d3042005-10-30 15:00:16 -08001002 kfree(REISERFS_SB(s)->s_qf_names[qtype]);
1003 REISERFS_SB(s)->s_qf_names[qtype] = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001004 }
1005 }
1006 if (c == 'f') {
1007 if (!strcmp(arg, "vfsold"))
1008 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
1009 else if (!strcmp(arg, "vfsv0"))
1010 REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
1011 else {
1012 reiserfs_warning(s,
1013 "reiserfs_parse_options: unknown quota format specified.");
1014 return 0;
1015 }
1016 }
1017#else
1018 if (c == 'u' || c == 'g' || c == 'f') {
1019 reiserfs_warning(s,
1020 "reiserfs_parse_options: journalled quota options not supported.");
1021 return 0;
1022 }
1023#endif
1024 }
1025
1026#ifdef CONFIG_QUOTA
1027 if (!REISERFS_SB(s)->s_jquota_fmt
1028 && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
1029 || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
1030 reiserfs_warning(s,
1031 "reiserfs_parse_options: journalled quota format not specified.");
1032 return 0;
1033 }
1034 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
1035 if (!(*mount_options & (1 << REISERFS_QUOTA))
1036 && sb_any_quota_enabled(s)) {
1037 reiserfs_warning(s,
1038 "reiserfs_parse_options: quota options must be present when quota is turned on.");
1039 return 0;
1040 }
1041#endif
1042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001046static void switch_data_mode(struct super_block *s, unsigned long mode)
1047{
1048 REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
1049 (1 << REISERFS_DATA_ORDERED) |
1050 (1 << REISERFS_DATA_WRITEBACK));
1051 REISERFS_SB(s)->s_mount_opt |= (1 << mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
1054static void handle_data_mode(struct super_block *s, unsigned long mount_options)
1055{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001056 if (mount_options & (1 << REISERFS_DATA_LOG)) {
1057 if (!reiserfs_data_log(s)) {
1058 switch_data_mode(s, REISERFS_DATA_LOG);
1059 reiserfs_info(s, "switching to journaled data mode\n");
1060 }
1061 } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
1062 if (!reiserfs_data_ordered(s)) {
1063 switch_data_mode(s, REISERFS_DATA_ORDERED);
1064 reiserfs_info(s, "switching to ordered data mode\n");
1065 }
1066 } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
1067 if (!reiserfs_data_writeback(s)) {
1068 switch_data_mode(s, REISERFS_DATA_WRITEBACK);
1069 reiserfs_info(s, "switching to writeback data mode\n");
1070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001074static void handle_barrier_mode(struct super_block *s, unsigned long bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001076 int flush = (1 << REISERFS_BARRIER_FLUSH);
1077 int none = (1 << REISERFS_BARRIER_NONE);
1078 int all_barrier = flush | none;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001080 if (bits & all_barrier) {
1081 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1082 if (bits & flush) {
1083 REISERFS_SB(s)->s_mount_opt |= flush;
1084 printk("reiserfs: enabling write barrier flush mode\n");
1085 } else if (bits & none) {
1086 REISERFS_SB(s)->s_mount_opt |= none;
1087 printk("reiserfs: write barriers turned off\n");
1088 }
1089 }
1090}
1091
1092static void handle_attrs(struct super_block *s)
1093{
1094 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1095
1096 if (reiserfs_attrs(s)) {
1097 if (old_format_only(s)) {
1098 reiserfs_warning(s,
1099 "reiserfs: cannot support attributes on 3.5.x disk format");
1100 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 return;
1102 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001103 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1104 reiserfs_warning(s,
1105 "reiserfs: cannot support attributes until flag is set in super-block");
1106 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 }
1108 }
1109}
1110
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001111static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001113 struct reiserfs_super_block *rs;
1114 struct reiserfs_transaction_handle th;
1115 unsigned long blocks;
1116 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1117 unsigned long safe_mask = 0;
1118 unsigned int commit_max_age = (unsigned int)-1;
1119 struct reiserfs_journal *journal = SB_JOURNAL(s);
1120 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001122 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123#endif
1124
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001125 rs = SB_DISK_SUPER_BLOCK(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001127 if (!reiserfs_parse_options
1128 (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129#ifdef CONFIG_QUOTA
James Lamanna833d3042005-10-30 15:00:16 -08001130 for (i = 0; i < MAXQUOTAS; i++) {
1131 kfree(REISERFS_SB(s)->s_qf_names[i]);
1132 REISERFS_SB(s)->s_qf_names[i] = NULL;
1133 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001134#endif
1135 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001138 handle_attrs(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001140 /* Add options that are safe here */
1141 safe_mask |= 1 << REISERFS_SMALLTAIL;
1142 safe_mask |= 1 << REISERFS_LARGETAIL;
1143 safe_mask |= 1 << REISERFS_NO_BORDER;
1144 safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
1145 safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
1146 safe_mask |= 1 << REISERFS_TEST4;
1147 safe_mask |= 1 << REISERFS_ATTRS;
1148 safe_mask |= 1 << REISERFS_XATTRS_USER;
1149 safe_mask |= 1 << REISERFS_POSIXACL;
1150 safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
1151 safe_mask |= 1 << REISERFS_BARRIER_NONE;
1152 safe_mask |= 1 << REISERFS_ERROR_RO;
1153 safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
1154 safe_mask |= 1 << REISERFS_ERROR_PANIC;
1155 safe_mask |= 1 << REISERFS_QUOTA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001157 /* Update the bitmask, taking care to keep
1158 * the bits we're not allowed to change here */
1159 REISERFS_SB(s)->s_mount_opt =
1160 (REISERFS_SB(s)->
1161 s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001163 if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
1164 journal->j_max_commit_age = commit_max_age;
1165 journal->j_max_trans_age = commit_max_age;
1166 } else if (commit_max_age == 0) {
1167 /* 0 means restore defaults. */
1168 journal->j_max_commit_age = journal->j_default_max_commit_age;
1169 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
1170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001172 if (blocks) {
1173 int rc = reiserfs_resize(s, blocks);
1174 if (rc != 0)
1175 return rc;
1176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001178 if (*mount_flags & MS_RDONLY) {
1179 reiserfs_xattr_init(s, *mount_flags);
1180 /* remount read-only */
1181 if (s->s_flags & MS_RDONLY)
1182 /* it is read-only already */
1183 return 0;
1184 /* try to remount file system with read-only permissions */
1185 if (sb_umount_state(rs) == REISERFS_VALID_FS
1186 || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
1187 return 0;
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001190 err = journal_begin(&th, s, 10);
1191 if (err)
1192 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001194 /* Mounting a rw partition read-only. */
1195 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1196 set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
1197 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1198 } else {
1199 /* remount read-write */
1200 if (!(s->s_flags & MS_RDONLY)) {
1201 reiserfs_xattr_init(s, *mount_flags);
1202 return 0; /* We are read-write already */
1203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001205 if (reiserfs_is_journal_aborted(journal))
1206 return journal->j_errno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001208 handle_data_mode(s, mount_options);
1209 handle_barrier_mode(s, mount_options);
1210 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1211 s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
1212 err = journal_begin(&th, s, 10);
1213 if (err)
1214 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001216 /* Mount a partition which is read-only, read-write */
1217 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1218 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1219 s->s_flags &= ~MS_RDONLY;
1220 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1221 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1222 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1223 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
1224 }
1225 /* this will force a full flush of all journal lists */
1226 SB_JOURNAL(s)->j_must_wait = 1;
1227 err = journal_end(&th, s, 10);
1228 if (err)
1229 return err;
1230 s->s_dirt = 0;
1231
1232 if (!(*mount_flags & MS_RDONLY)) {
1233 finish_unfinished(s);
1234 reiserfs_xattr_init(s, *mount_flags);
1235 }
1236
1237 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238}
1239
1240/* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
1241 * @sb - superblock for this filesystem
1242 * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
1243 *
1244 * This routine counts how many free bits there are, finding the first zero
1245 * as a side effect. Could also be implemented as a loop of test_bit() calls, or
1246 * a loop of find_first_zero_bit() calls. This implementation is similar to
1247 * find_first_zero_bit(), but doesn't return after it finds the first bit.
1248 * Should only be called on fs mount, but should be fairly efficient anyways.
1249 *
1250 * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
1251 * will * invariably occupt block 0 represented in the bitmap. The only
1252 * exception to this is when free_count also == 0, since there will be no
1253 * free blocks at all.
1254 */
1255
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001256static void load_bitmap_info_data(struct super_block *sb,
1257 struct reiserfs_bitmap_info *bi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001259 unsigned long *cur = (unsigned long *)bi->bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001261 while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001263 /* No need to scan if all 0's or all 1's.
1264 * Since we're only counting 0's, we can simply ignore all 1's */
1265 if (*cur == 0) {
1266 if (bi->first_zero_hint == 0) {
1267 bi->first_zero_hint =
1268 ((char *)cur - bi->bh->b_data) << 3;
1269 }
1270 bi->free_count += sizeof(unsigned long) * 8;
1271 } else if (*cur != ~0L) {
1272 int b;
1273 for (b = 0; b < sizeof(unsigned long) * 8; b++) {
1274 if (!reiserfs_test_le_bit(b, cur)) {
1275 bi->free_count++;
1276 if (bi->first_zero_hint == 0)
1277 bi->first_zero_hint =
1278 (((char *)cur -
1279 bi->bh->b_data) << 3) + b;
1280 }
1281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001283 cur++;
1284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286#ifdef CONFIG_REISERFS_CHECK
1287// This outputs a lot of unneded info on big FSes
1288// reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001289// bi->bh->b_blocknr, bi->free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290#endif
1291}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001293static int read_bitmaps(struct super_block *s)
1294{
1295 int i, bmap_nr;
1296
1297 SB_AP_BITMAP(s) =
1298 vmalloc(sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1299 if (SB_AP_BITMAP(s) == 0)
1300 return 1;
1301 memset(SB_AP_BITMAP(s), 0,
1302 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
1303 for (i = 0, bmap_nr =
1304 REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
1305 i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
1306 SB_AP_BITMAP(s)[i].bh = sb_getblk(s, bmap_nr);
1307 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
1308 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001310 for (i = 0; i < SB_BMAP_NR(s); i++) {
1311 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1312 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1313 reiserfs_warning(s, "sh-2029: reiserfs read_bitmaps: "
1314 "bitmap block (#%lu) reading failed",
1315 SB_AP_BITMAP(s)[i].bh->b_blocknr);
1316 for (i = 0; i < SB_BMAP_NR(s); i++)
1317 brelse(SB_AP_BITMAP(s)[i].bh);
1318 vfree(SB_AP_BITMAP(s));
1319 SB_AP_BITMAP(s) = NULL;
1320 return 1;
1321 }
1322 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1323 }
1324 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001327static int read_old_bitmaps(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001329 int i;
1330 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
1331 int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001333 /* read true bitmap */
1334 SB_AP_BITMAP(s) =
1335 vmalloc(sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
1336 if (SB_AP_BITMAP(s) == 0)
1337 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001339 memset(SB_AP_BITMAP(s), 0,
1340 sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001342 for (i = 0; i < sb_bmap_nr(rs); i++) {
1343 SB_AP_BITMAP(s)[i].bh = sb_bread(s, bmp1 + i);
1344 if (!SB_AP_BITMAP(s)[i].bh)
1345 return 1;
1346 load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
1347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001349 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001352static int read_super_block(struct super_block *s, int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001354 struct buffer_head *bh;
1355 struct reiserfs_super_block *rs;
1356 int fs_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001358 bh = sb_bread(s, offset / s->s_blocksize);
1359 if (!bh) {
1360 reiserfs_warning(s, "sh-2006: read_super_block: "
1361 "bread failed (dev %s, block %lu, size %lu)",
1362 reiserfs_bdevname(s), offset / s->s_blocksize,
1363 s->s_blocksize);
1364 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001367 rs = (struct reiserfs_super_block *)bh->b_data;
1368 if (!is_any_reiserfs_magic_string(rs)) {
1369 brelse(bh);
1370 return 1;
1371 }
1372 //
1373 // ok, reiserfs signature (old or new) found in at the given offset
1374 //
1375 fs_blocksize = sb_blocksize(rs);
1376 brelse(bh);
1377 sb_set_blocksize(s, fs_blocksize);
1378
1379 bh = sb_bread(s, offset / s->s_blocksize);
1380 if (!bh) {
1381 reiserfs_warning(s, "sh-2007: read_super_block: "
1382 "bread failed (dev %s, block %lu, size %lu)\n",
1383 reiserfs_bdevname(s), offset / s->s_blocksize,
1384 s->s_blocksize);
1385 return 1;
1386 }
1387
1388 rs = (struct reiserfs_super_block *)bh->b_data;
1389 if (sb_blocksize(rs) != s->s_blocksize) {
1390 reiserfs_warning(s, "sh-2011: read_super_block: "
1391 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
1392 reiserfs_bdevname(s),
1393 (unsigned long long)bh->b_blocknr,
1394 s->s_blocksize);
1395 brelse(bh);
1396 return 1;
1397 }
1398
1399 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1400 brelse(bh);
1401 reiserfs_warning(s,
1402 "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
1403 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
1404 "get newer reiserfsprogs package");
1405 return 1;
1406 }
1407
1408 SB_BUFFER_WITH_SB(s) = bh;
1409 SB_DISK_SUPER_BLOCK(s) = rs;
1410
1411 if (is_reiserfs_jr(rs)) {
1412 /* magic is of non-standard journal filesystem, look at s_version to
1413 find which format is in use */
1414 if (sb_version(rs) == REISERFS_VERSION_2)
1415 reiserfs_warning(s,
1416 "read_super_block: found reiserfs format \"3.6\""
1417 " with non-standard journal");
1418 else if (sb_version(rs) == REISERFS_VERSION_1)
1419 reiserfs_warning(s,
1420 "read_super_block: found reiserfs format \"3.5\""
1421 " with non-standard journal");
1422 else {
1423 reiserfs_warning(s,
1424 "sh-2012: read_super_block: found unknown "
1425 "format \"%u\" of reiserfs with non-standard magic",
1426 sb_version(rs));
1427 return 1;
1428 }
1429 } else
1430 /* s_version of standard format may contain incorrect information,
1431 so we just look at the magic string */
1432 reiserfs_info(s,
1433 "found reiserfs format \"%s\" with standard journal\n",
1434 is_reiserfs_3_5(rs) ? "3.5" : "3.6");
1435
1436 s->s_op = &reiserfs_sops;
1437 s->s_export_op = &reiserfs_export_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001439 s->s_qcop = &reiserfs_qctl_operations;
1440 s->dq_op = &reiserfs_quota_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441#endif
1442
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001443 /* new format is limited by the 32 bit wide i_blocks field, want to
1444 ** be one full block below that.
1445 */
1446 s->s_maxbytes = (512LL << 32) - s->s_blocksize;
1447 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450/* after journal replay, reread all bitmap and super blocks */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001451static int reread_meta_blocks(struct super_block *s)
1452{
1453 int i;
1454 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1455 wait_on_buffer(SB_BUFFER_WITH_SB(s));
1456 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1457 reiserfs_warning(s,
1458 "reread_meta_blocks, error reading the super");
1459 return 1;
1460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001462 for (i = 0; i < SB_BMAP_NR(s); i++) {
1463 ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh));
1464 wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
1465 if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
1466 reiserfs_warning(s,
1467 "reread_meta_blocks, error reading bitmap block number %d at %llu",
1468 i,
1469 (unsigned long long)SB_AP_BITMAP(s)[i].
1470 bh->b_blocknr);
1471 return 1;
1472 }
1473 }
1474 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476}
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478/////////////////////////////////////////////////////
1479// hash detection stuff
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481// if root directory is empty - we set default - Yura's - hash and
1482// warn about it
1483// FIXME: we look for only one name in a directory. If tea and yura
1484// bith have the same value - we ask user to send report to the
1485// mailing list
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001486static __u32 find_hash_out(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001488 int retval;
1489 struct inode *inode;
1490 struct cpu_key key;
1491 INITIALIZE_PATH(path);
1492 struct reiserfs_dir_entry de;
1493 __u32 hash = DEFAULT_HASH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001495 inode = s->s_root->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001497 do { // Some serious "goto"-hater was there ;)
1498 u32 teahash, r5hash, yurahash;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001500 make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
1501 retval = search_by_entry_key(s, &key, &path, &de);
1502 if (retval == IO_ERROR) {
1503 pathrelse(&path);
1504 return UNSET_HASH;
1505 }
1506 if (retval == NAME_NOT_FOUND)
1507 de.de_entry_num--;
1508 set_de_name_and_namelen(&de);
1509 if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
1510 /* allow override in this case */
1511 if (reiserfs_rupasov_hash(s)) {
1512 hash = YURA_HASH;
1513 }
1514 reiserfs_warning(s, "FS seems to be empty, autodetect "
1515 "is using the default hash");
1516 break;
1517 }
1518 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
1519 teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
1520 yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
1521 if (((teahash == r5hash)
1522 &&
1523 (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
1524 == r5hash)) || ((teahash == yurahash)
1525 && (yurahash ==
1526 GET_HASH_VALUE(deh_offset
1527 (&
1528 (de.
1529 de_deh[de.
1530 de_entry_num])))))
1531 || ((r5hash == yurahash)
1532 && (yurahash ==
1533 GET_HASH_VALUE(deh_offset
1534 (&(de.de_deh[de.de_entry_num])))))) {
1535 reiserfs_warning(s,
1536 "Unable to automatically detect hash function. "
1537 "Please mount with -o hash={tea,rupasov,r5}",
1538 reiserfs_bdevname(s));
1539 hash = UNSET_HASH;
1540 break;
1541 }
1542 if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
1543 yurahash)
1544 hash = YURA_HASH;
1545 else if (GET_HASH_VALUE
1546 (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
1547 hash = TEA_HASH;
1548 else if (GET_HASH_VALUE
1549 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1550 hash = R5_HASH;
1551 else {
1552 reiserfs_warning(s, "Unrecognised hash function");
1553 hash = UNSET_HASH;
1554 }
1555 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001557 pathrelse(&path);
1558 return hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
1561// finds out which hash names are sorted with
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001562static int what_hash(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001564 __u32 code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001566 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001568 /* reiserfs_hash_detect() == true if any of the hash mount options
1569 ** were used. We must check them to make sure the user isn't
1570 ** using a bad hash value
1571 */
1572 if (code == UNSET_HASH || reiserfs_hash_detect(s))
1573 code = find_hash_out(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001575 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1576 /* detection has found the hash, and we must check against the
1577 ** mount options
1578 */
1579 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1580 reiserfs_warning(s, "Error, %s hash detected, "
1581 "unable to force rupasov hash",
1582 reiserfs_hashname(code));
1583 code = UNSET_HASH;
1584 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1585 reiserfs_warning(s, "Error, %s hash detected, "
1586 "unable to force tea hash",
1587 reiserfs_hashname(code));
1588 code = UNSET_HASH;
1589 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1590 reiserfs_warning(s, "Error, %s hash detected, "
1591 "unable to force r5 hash",
1592 reiserfs_hashname(code));
1593 code = UNSET_HASH;
1594 }
1595 } else {
1596 /* find_hash_out was not called or could not determine the hash */
1597 if (reiserfs_rupasov_hash(s)) {
1598 code = YURA_HASH;
1599 } else if (reiserfs_tea_hash(s)) {
1600 code = TEA_HASH;
1601 } else if (reiserfs_r5_hash(s)) {
1602 code = R5_HASH;
1603 }
1604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001606 /* if we are mounted RW, and we have a new valid hash code, update
1607 ** the super
1608 */
1609 if (code != UNSET_HASH &&
1610 !(s->s_flags & MS_RDONLY) &&
1611 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1612 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1613 }
1614 return code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
1617// return pointer to appropriate function
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001618static hashf_t hash_function(struct super_block *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001620 switch (what_hash(s)) {
1621 case TEA_HASH:
1622 reiserfs_info(s, "Using tea hash to sort names\n");
1623 return keyed_hash;
1624 case YURA_HASH:
1625 reiserfs_info(s, "Using rupasov hash to sort names\n");
1626 return yura_hash;
1627 case R5_HASH:
1628 reiserfs_info(s, "Using r5 hash to sort names\n");
1629 return r5_hash;
1630 }
1631 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
1634// this is used to set up correct value for old partitions
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001635static int function2code(hashf_t func)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001637 if (func == keyed_hash)
1638 return TEA_HASH;
1639 if (func == yura_hash)
1640 return YURA_HASH;
1641 if (func == r5_hash)
1642 return R5_HASH;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001644 BUG(); // should never happen
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
1649#define SWARN(silent, s, ...) \
1650 if (!(silent)) \
1651 reiserfs_warning (s, __VA_ARGS__)
1652
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001653static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001655 struct inode *root_inode;
1656 int j;
1657 struct reiserfs_transaction_handle th;
1658 int old_format = 0;
1659 unsigned long blocks;
1660 unsigned int commit_max_age = 0;
1661 int jinit_done = 0;
1662 struct reiserfs_iget_args args;
1663 struct reiserfs_super_block *rs;
1664 char *jdev_name;
1665 struct reiserfs_sb_info *sbi;
1666 int errval = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001668 sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
1669 if (!sbi) {
1670 errval = -ENOMEM;
1671 goto error;
1672 }
1673 s->s_fs_info = sbi;
1674 memset(sbi, 0, sizeof(struct reiserfs_sb_info));
1675 /* Set default values for options: non-aggressive tails, RO on errors */
1676 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1677 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1678 /* no preallocation minimum, be smart in
1679 reiserfs_file_write instead */
1680 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1681 /* Preallocate by 16 blocks (17-1) at once */
1682 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1683 /* Initialize the rwsem for xattr dir */
1684 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001686 /* setup default block allocator options */
1687 reiserfs_init_alloc_options(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001689 jdev_name = NULL;
1690 if (reiserfs_parse_options
1691 (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
1692 &commit_max_age) == 0) {
1693 goto error;
1694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001696 if (blocks) {
1697 SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
1698 "for remount only");
1699 goto error;
1700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001702 /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
1703 if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
1704 old_format = 1;
1705 /* try new format (64-th 1k block), which can contain reiserfs super block */
1706 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1707 SWARN(silent, s,
1708 "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
1709 reiserfs_bdevname(s));
1710 goto error;
1711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001713 rs = SB_DISK_SUPER_BLOCK(s);
1714 /* Let's do basic sanity check to verify that underlying device is not
1715 smaller than the filesystem. If the check fails then abort and scream,
1716 because bad stuff will happen otherwise. */
1717 if (s->s_bdev && s->s_bdev->bd_inode
1718 && i_size_read(s->s_bdev->bd_inode) <
1719 sb_block_count(rs) * sb_blocksize(rs)) {
1720 SWARN(silent, s,
1721 "Filesystem on %s cannot be mounted because it is bigger than the device",
1722 reiserfs_bdevname(s));
1723 SWARN(silent, s,
1724 "You may need to run fsck or increase size of your LVM partition");
1725 SWARN(silent, s,
1726 "Or may be you forgot to reboot after fdisk when it told you to");
1727 goto error;
1728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001730 sbi->s_mount_state = SB_REISERFS_STATE(s);
1731 sbi->s_mount_state = REISERFS_VALID_FS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001733 if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
1734 SWARN(silent, s,
1735 "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1736 goto error;
1737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738#ifdef CONFIG_REISERFS_CHECK
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001739 SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
1740 SWARN(silent, s, "- it is slow mode for debugging.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741#endif
1742
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001743 /* make data=ordered the default */
1744 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1745 !reiserfs_data_writeback(s)) {
1746 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 }
1748
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001749 if (reiserfs_data_log(s)) {
1750 reiserfs_info(s, "using journaled data mode\n");
1751 } else if (reiserfs_data_ordered(s)) {
1752 reiserfs_info(s, "using ordered data mode\n");
1753 } else {
1754 reiserfs_info(s, "using writeback data mode\n");
1755 }
1756 if (reiserfs_barrier_flush(s)) {
1757 printk("reiserfs: using flush barriers\n");
1758 }
1759 // set_device_ro(s->s_dev, 1) ;
1760 if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1761 SWARN(silent, s,
1762 "sh-2022: reiserfs_fill_super: unable to initialize journal space");
1763 goto error;
1764 } else {
1765 jinit_done = 1; /* once this is set, journal_release must be called
1766 ** if we error out of the mount
1767 */
1768 }
1769 if (reread_meta_blocks(s)) {
1770 SWARN(silent, s,
1771 "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
1772 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
1774
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001775 if (replay_only(s))
1776 goto error;
1777
1778 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1779 SWARN(silent, s,
1780 "clm-7000: Detected readonly device, marking FS readonly");
1781 s->s_flags |= MS_RDONLY;
1782 }
1783 args.objectid = REISERFS_ROOT_OBJECTID;
1784 args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
1785 root_inode =
1786 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1787 reiserfs_init_locked_inode, (void *)(&args));
1788 if (!root_inode) {
1789 SWARN(silent, s,
1790 "jmacd-10: reiserfs_fill_super: get root inode failed");
1791 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 }
1793
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001794 if (root_inode->i_state & I_NEW) {
1795 reiserfs_read_locked_inode(root_inode, &args);
1796 unlock_new_inode(root_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 }
1798
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001799 s->s_root = d_alloc_root(root_inode);
1800 if (!s->s_root) {
1801 iput(root_inode);
1802 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001804 // define and initialize hash function
1805 sbi->s_hash_function = hash_function(s);
1806 if (sbi->s_hash_function == NULL) {
1807 dput(s->s_root);
1808 s->s_root = NULL;
1809 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001811
1812 if (is_reiserfs_3_5(rs)
1813 || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
1814 set_bit(REISERFS_3_5, &(sbi->s_properties));
1815 else
1816 set_bit(REISERFS_3_6, &(sbi->s_properties));
1817
1818 if (!(s->s_flags & MS_RDONLY)) {
1819
1820 errval = journal_begin(&th, s, 1);
1821 if (errval) {
1822 dput(s->s_root);
1823 s->s_root = NULL;
1824 goto error;
1825 }
1826 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
1827
1828 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1829 set_sb_fs_state(rs, 0);
1830
1831 if (old_format_only(s)) {
1832 /* filesystem of format 3.5 either with standard or non-standard
1833 journal */
1834 if (convert_reiserfs(s)) {
1835 /* and -o conv is given */
1836 if (!silent)
1837 reiserfs_info(s,
1838 "converting 3.5 filesystem to the 3.6 format");
1839
1840 if (is_reiserfs_3_5(rs))
1841 /* put magic string of 3.6 format. 2.2 will not be able to
1842 mount this filesystem anymore */
1843 memcpy(rs->s_v1.s_magic,
1844 reiserfs_3_6_magic_string,
1845 sizeof
1846 (reiserfs_3_6_magic_string));
1847
1848 set_sb_version(rs, REISERFS_VERSION_2);
1849 reiserfs_convert_objectid_map_v1(s);
1850 set_bit(REISERFS_3_6, &(sbi->s_properties));
1851 clear_bit(REISERFS_3_5, &(sbi->s_properties));
1852 } else if (!silent) {
1853 reiserfs_info(s, "using 3.5.x disk format\n");
1854 }
1855 }
1856
1857 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1858 errval = journal_end(&th, s, 1);
1859 if (errval) {
1860 dput(s->s_root);
1861 s->s_root = NULL;
1862 goto error;
1863 }
1864
1865 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1866 dput(s->s_root);
1867 s->s_root = NULL;
1868 goto error;
1869 }
1870
1871 /* look for files which were to be removed in previous session */
1872 finish_unfinished(s);
1873 } else {
1874 if (old_format_only(s) && !silent) {
1875 reiserfs_info(s, "using 3.5.x disk format\n");
1876 }
1877
1878 if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
1879 dput(s->s_root);
1880 s->s_root = NULL;
1881 goto error;
1882 }
1883 }
1884 // mark hash in super block: it could be unset. overwrite should be ok
1885 set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
1886
1887 handle_attrs(s);
1888
1889 reiserfs_proc_info_init(s);
1890
1891 init_waitqueue_head(&(sbi->s_wait));
1892 spin_lock_init(&sbi->bitmap_lock);
1893
1894 return (0);
1895
1896 error:
1897 if (jinit_done) { /* kill the commit thread, free journal ram */
1898 journal_release_error(NULL, s);
1899 }
1900 if (SB_DISK_SUPER_BLOCK(s)) {
1901 for (j = 0; j < SB_BMAP_NR(s); j++) {
1902 if (SB_AP_BITMAP(s))
1903 brelse(SB_AP_BITMAP(s)[j].bh);
1904 }
James Lamannaea0e0a42005-09-10 00:27:16 -07001905 vfree(SB_AP_BITMAP(s));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001906 }
1907 if (SB_BUFFER_WITH_SB(s))
1908 brelse(SB_BUFFER_WITH_SB(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909#ifdef CONFIG_QUOTA
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001910 for (j = 0; j < MAXQUOTAS; j++) {
James Lamanna833d3042005-10-30 15:00:16 -08001911 kfree(sbi->s_qf_names[j]);
1912 sbi->s_qf_names[j] = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914#endif
James Lamanna833d3042005-10-30 15:00:16 -08001915 kfree(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001917 s->s_fs_info = NULL;
1918 return errval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
David Howells726c3342006-06-23 02:02:58 -07001921static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922{
David Howells726c3342006-06-23 02:02:58 -07001923 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001924
1925 buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
1926 buf->f_bfree = sb_free_blocks(rs);
1927 buf->f_bavail = buf->f_bfree;
1928 buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
David Howells726c3342006-06-23 02:02:58 -07001929 buf->f_bsize = dentry->d_sb->s_blocksize;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001930 /* changed to accommodate gcc folks. */
1931 buf->f_type = REISERFS_SUPER_MAGIC;
1932 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
1935#ifdef CONFIG_QUOTA
1936static int reiserfs_dquot_initialize(struct inode *inode, int type)
1937{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001938 struct reiserfs_transaction_handle th;
1939 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001941 /* We may create quota structure so we need to reserve enough blocks */
1942 reiserfs_write_lock(inode->i_sb);
1943 ret =
1944 journal_begin(&th, inode->i_sb,
1945 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1946 if (ret)
1947 goto out;
1948 ret = dquot_initialize(inode, type);
1949 err =
1950 journal_end(&th, inode->i_sb,
1951 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1952 if (!ret && err)
1953 ret = err;
1954 out:
1955 reiserfs_write_unlock(inode->i_sb);
1956 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957}
1958
1959static int reiserfs_dquot_drop(struct inode *inode)
1960{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001961 struct reiserfs_transaction_handle th;
1962 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001964 /* We may delete quota structure so we need to reserve enough blocks */
1965 reiserfs_write_lock(inode->i_sb);
1966 ret =
1967 journal_begin(&th, inode->i_sb,
1968 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1969 if (ret)
1970 goto out;
1971 ret = dquot_drop(inode);
1972 err =
1973 journal_end(&th, inode->i_sb,
1974 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1975 if (!ret && err)
1976 ret = err;
1977 out:
1978 reiserfs_write_unlock(inode->i_sb);
1979 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
1982static int reiserfs_write_dquot(struct dquot *dquot)
1983{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001984 struct reiserfs_transaction_handle th;
1985 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001987 reiserfs_write_lock(dquot->dq_sb);
1988 ret =
1989 journal_begin(&th, dquot->dq_sb,
1990 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1991 if (ret)
1992 goto out;
1993 ret = dquot_commit(dquot);
1994 err =
1995 journal_end(&th, dquot->dq_sb,
1996 REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
1997 if (!ret && err)
1998 ret = err;
1999 out:
2000 reiserfs_write_unlock(dquot->dq_sb);
2001 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002}
2003
2004static int reiserfs_acquire_dquot(struct dquot *dquot)
2005{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002006 struct reiserfs_transaction_handle th;
2007 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002009 reiserfs_write_lock(dquot->dq_sb);
2010 ret =
2011 journal_begin(&th, dquot->dq_sb,
2012 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2013 if (ret)
2014 goto out;
2015 ret = dquot_acquire(dquot);
2016 err =
2017 journal_end(&th, dquot->dq_sb,
2018 REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2019 if (!ret && err)
2020 ret = err;
2021 out:
2022 reiserfs_write_unlock(dquot->dq_sb);
2023 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024}
2025
2026static int reiserfs_release_dquot(struct dquot *dquot)
2027{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002028 struct reiserfs_transaction_handle th;
2029 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002031 reiserfs_write_lock(dquot->dq_sb);
2032 ret =
2033 journal_begin(&th, dquot->dq_sb,
2034 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2035 if (ret)
2036 goto out;
2037 ret = dquot_release(dquot);
2038 err =
2039 journal_end(&th, dquot->dq_sb,
2040 REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2041 if (!ret && err)
2042 ret = err;
2043 out:
2044 reiserfs_write_unlock(dquot->dq_sb);
2045 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
2049{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002050 /* Are we journalling quotas? */
2051 if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
2052 REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
2053 dquot_mark_dquot_dirty(dquot);
2054 return reiserfs_write_dquot(dquot);
2055 } else
2056 return dquot_mark_dquot_dirty(dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059static int reiserfs_write_info(struct super_block *sb, int type)
2060{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002061 struct reiserfs_transaction_handle th;
2062 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002064 /* Data block + inode block */
2065 reiserfs_write_lock(sb);
2066 ret = journal_begin(&th, sb, 2);
2067 if (ret)
2068 goto out;
2069 ret = dquot_commit_info(sb, type);
2070 err = journal_end(&th, sb, 2);
2071 if (!ret && err)
2072 ret = err;
2073 out:
2074 reiserfs_write_unlock(sb);
2075 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076}
2077
2078/*
Christoph Hellwig84de8562005-06-23 00:09:16 -07002079 * Turn on quotas during mount time - we need to find the quota file and such...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 */
2081static int reiserfs_quota_on_mount(struct super_block *sb, int type)
2082{
Christoph Hellwig84de8562005-06-23 00:09:16 -07002083 return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002084 REISERFS_SB(sb)->s_jquota_fmt, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
2086
2087/*
2088 * Standard function to be called on quota_on
2089 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002090static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2091 char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002093 int err;
2094 struct nameidata nd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002096 if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
2097 return -EINVAL;
2098 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
2099 if (err)
2100 return err;
2101 /* Quotafile not on the same filesystem? */
2102 if (nd.mnt->mnt_sb != sb) {
2103 path_release(&nd);
2104 return -EXDEV;
2105 }
2106 /* We must not pack tails for quota files on reiserfs for quota IO to work */
2107 if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
2108 reiserfs_warning(sb,
2109 "reiserfs: Quota file must have tail packing disabled.");
2110 path_release(&nd);
2111 return -EINVAL;
2112 }
2113 /* Not journalling quota? No more tests needed... */
2114 if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
2115 !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
2116 path_release(&nd);
2117 return vfs_quota_on(sb, type, format_id, path);
2118 }
2119 /* Quotafile not of fs root? */
2120 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2121 reiserfs_warning(sb,
2122 "reiserfs: Quota file not on filesystem root. "
2123 "Journalled quota will not work.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 path_release(&nd);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002125 return vfs_quota_on(sb, type, format_id, path);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/* Read data from quotafile - avoid pagecache and such because we cannot afford
2129 * acquiring the locks... As quota files are never truncated and quota code
2130 * itself serializes the operations (and noone else should touch the files)
2131 * we don't have to be afraid of races */
2132static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
2133 size_t len, loff_t off)
2134{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002135 struct inode *inode = sb_dqopt(sb)->files[type];
2136 unsigned long blk = off >> sb->s_blocksize_bits;
2137 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2138 size_t toread;
2139 struct buffer_head tmp_bh, *bh;
2140 loff_t i_size = i_size_read(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002142 if (off > i_size)
2143 return 0;
2144 if (off + len > i_size)
2145 len = i_size - off;
2146 toread = len;
2147 while (toread > 0) {
2148 tocopy =
2149 sb->s_blocksize - offset <
2150 toread ? sb->s_blocksize - offset : toread;
2151 tmp_bh.b_state = 0;
2152 /* Quota files are without tails so we can safely use this function */
2153 reiserfs_write_lock(sb);
2154 err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
2155 reiserfs_write_unlock(sb);
2156 if (err)
2157 return err;
2158 if (!buffer_mapped(&tmp_bh)) /* A hole? */
2159 memset(data, 0, tocopy);
2160 else {
2161 bh = sb_bread(sb, tmp_bh.b_blocknr);
2162 if (!bh)
2163 return -EIO;
2164 memcpy(data, bh->b_data + offset, tocopy);
2165 brelse(bh);
2166 }
2167 offset = 0;
2168 toread -= tocopy;
2169 data += tocopy;
2170 blk++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002172 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
2175/* Write to quotafile (we know the transaction is already started and has
2176 * enough credits) */
2177static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
2178 const char *data, size_t len, loff_t off)
2179{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002180 struct inode *inode = sb_dqopt(sb)->files[type];
2181 unsigned long blk = off >> sb->s_blocksize_bits;
2182 int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
2183 int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
2184 size_t towrite = len;
2185 struct buffer_head tmp_bh, *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Arjan van de Ven5c81a412006-07-03 00:25:20 -07002187 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002188 while (towrite > 0) {
2189 tocopy = sb->s_blocksize - offset < towrite ?
2190 sb->s_blocksize - offset : towrite;
2191 tmp_bh.b_state = 0;
2192 err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
2193 if (err)
2194 goto out;
2195 if (offset || tocopy != sb->s_blocksize)
2196 bh = sb_bread(sb, tmp_bh.b_blocknr);
2197 else
2198 bh = sb_getblk(sb, tmp_bh.b_blocknr);
2199 if (!bh) {
2200 err = -EIO;
2201 goto out;
2202 }
2203 lock_buffer(bh);
2204 memcpy(bh->b_data + offset, data, tocopy);
2205 flush_dcache_page(bh->b_page);
2206 set_buffer_uptodate(bh);
2207 unlock_buffer(bh);
2208 reiserfs_prepare_for_journal(sb, bh, 1);
2209 journal_mark_dirty(current->journal_info, sb, bh);
2210 if (!journal_quota)
2211 reiserfs_add_ordered_list(inode, bh);
2212 brelse(bh);
2213 offset = 0;
2214 towrite -= tocopy;
2215 data += tocopy;
2216 blk++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002218 out:
2219 if (len == towrite)
2220 return err;
2221 if (inode->i_size < off + len - towrite)
2222 i_size_write(inode, off + len - towrite);
2223 inode->i_version++;
2224 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2225 mark_inode_dirty(inode);
Jes Sorensen1b1dcc12006-01-09 15:59:24 -08002226 mutex_unlock(&inode->i_mutex);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002227 return len - towrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230#endif
2231
David Howells454e2392006-06-23 02:02:57 -07002232static int get_super_block(struct file_system_type *fs_type,
2233 int flags, const char *dev_name,
2234 void *data, struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
David Howells454e2392006-06-23 02:02:57 -07002236 return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super,
2237 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002240static int __init init_reiserfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241{
2242 int ret;
2243
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002244 if ((ret = init_inodecache())) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 return ret;
2246 }
2247
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002248 if ((ret = reiserfs_xattr_register_handlers()))
2249 goto failed_reiserfs_xattr_register_handlers;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002251 reiserfs_proc_info_global_init();
2252 reiserfs_proc_register_global("version",
2253 reiserfs_global_version_in_proc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002255 ret = register_filesystem(&reiserfs_fs_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 if (ret == 0) {
2258 return 0;
2259 }
2260
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002261 reiserfs_xattr_unregister_handlers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002263 failed_reiserfs_xattr_register_handlers:
2264 reiserfs_proc_unregister_global("version");
2265 reiserfs_proc_info_global_done();
2266 destroy_inodecache();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
2268 return ret;
2269}
2270
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002271static void __exit exit_reiserfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002273 reiserfs_xattr_unregister_handlers();
2274 reiserfs_proc_unregister_global("version");
2275 reiserfs_proc_info_global_done();
2276 unregister_filesystem(&reiserfs_fs_type);
2277 destroy_inodecache();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278}
2279
2280struct file_system_type reiserfs_fs_type = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002281 .owner = THIS_MODULE,
2282 .name = "reiserfs",
2283 .get_sb = get_super_block,
2284 .kill_sb = kill_block_super,
2285 .fs_flags = FS_REQUIRES_DEV,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286};
2287
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002288MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2289MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2290MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07002292module_init(init_reiserfs_fs);
2293module_exit(exit_reiserfs_fs);