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