1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <linux/fs.h>
38#include <linux/buffer_head.h>
39#include <linux/blkdev.h>
40#include <linux/log2.h>
41
42#include "jfs_incore.h"
43#include "jfs_filsys.h"
44#include "jfs_superblock.h"
45#include "jfs_dmap.h"
46#include "jfs_imap.h"
47#include "jfs_metapage.h"
48#include "jfs_debug.h"
49
50
51
52
53
54static int chkSuper(struct super_block *);
55static int logMOUNT(struct super_block *sb);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70int jfs_mount(struct super_block *sb)
71{
72 int rc = 0;
73 struct jfs_sb_info *sbi = JFS_SBI(sb);
74 struct inode *ipaimap = NULL;
75 struct inode *ipaimap2 = NULL;
76 struct inode *ipimap = NULL;
77 struct inode *ipbmap = NULL;
78
79
80
81
82
83 if ((rc = chkSuper(sb))) {
84 goto errout20;
85 }
86
87 ipaimap = diReadSpecial(sb, AGGREGATE_I, 0);
88 if (ipaimap == NULL) {
89 jfs_err("jfs_mount: Failed to read AGGREGATE_I");
90 rc = -EIO;
91 goto errout20;
92 }
93 sbi->ipaimap = ipaimap;
94
95 jfs_info("jfs_mount: ipaimap:0x%p", ipaimap);
96
97
98
99
100 if ((rc = diMount(ipaimap))) {
101 jfs_err("jfs_mount: diMount(ipaimap) failed w/rc = %d", rc);
102 goto errout21;
103 }
104
105
106
107
108 ipbmap = diReadSpecial(sb, BMAP_I, 0);
109 if (ipbmap == NULL) {
110 rc = -EIO;
111 goto errout22;
112 }
113
114 jfs_info("jfs_mount: ipbmap:0x%p", ipbmap);
115
116 sbi->ipbmap = ipbmap;
117
118
119
120
121 if ((rc = dbMount(ipbmap))) {
122 jfs_err("jfs_mount: dbMount failed w/rc = %d", rc);
123 goto errout22;
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 if ((sbi->mntflag & JFS_BAD_SAIT) == 0) {
138 ipaimap2 = diReadSpecial(sb, AGGREGATE_I, 1);
139 if (!ipaimap2) {
140 jfs_err("jfs_mount: Failed to read AGGREGATE_I");
141 rc = -EIO;
142 goto errout35;
143 }
144 sbi->ipaimap2 = ipaimap2;
145
146 jfs_info("jfs_mount: ipaimap2:0x%p", ipaimap2);
147
148
149
150
151 if ((rc = diMount(ipaimap2))) {
152 jfs_err("jfs_mount: diMount(ipaimap2) failed, rc = %d",
153 rc);
154 goto errout35;
155 }
156 } else
157
158 sbi->ipaimap2 = NULL;
159
160
161
162
163
164
165
166 ipimap = diReadSpecial(sb, FILESYSTEM_I, 0);
167 if (ipimap == NULL) {
168 jfs_err("jfs_mount: Failed to read FILESYSTEM_I");
169
170 rc = -EIO;
171 goto errout40;
172 }
173 jfs_info("jfs_mount: ipimap:0x%p", ipimap);
174
175
176 sbi->ipimap = ipimap;
177
178
179 if ((rc = diMount(ipimap))) {
180 jfs_err("jfs_mount: diMount failed w/rc = %d", rc);
181 goto errout41;
182 }
183
184 goto out;
185
186
187
188
189 errout41:
190 diFreeSpecial(ipimap);
191
192 errout40:
193
194
195 if (ipaimap2) {
196 diUnmount(ipaimap2, 1);
197 diFreeSpecial(ipaimap2);
198 }
199
200 errout35:
201
202
203 dbUnmount(ipbmap, 1);
204 diFreeSpecial(ipbmap);
205
206 errout22:
207
208 diUnmount(ipaimap, 1);
209
210 errout21:
211 diFreeSpecial(ipaimap);
212 errout20:
213
214 out:
215
216 if (rc)
217 jfs_err("Mount JFS Failure: %d", rc);
218
219 return rc;
220}
221
222
223
224
225
226
227
228int jfs_mount_rw(struct super_block *sb, int remount)
229{
230 struct jfs_sb_info *sbi = JFS_SBI(sb);
231 int rc;
232
233
234
235
236
237
238 if (remount) {
239 if (chkSuper(sb) || (sbi->state != FM_CLEAN))
240 return -EINVAL;
241
242 truncate_inode_pages(sbi->ipimap->i_mapping, 0);
243 truncate_inode_pages(sbi->ipbmap->i_mapping, 0);
244 diUnmount(sbi->ipimap, 1);
245 if ((rc = diMount(sbi->ipimap))) {
246 jfs_err("jfs_mount_rw: diMount failed!");
247 return rc;
248 }
249
250 dbUnmount(sbi->ipbmap, 1);
251 if ((rc = dbMount(sbi->ipbmap))) {
252 jfs_err("jfs_mount_rw: dbMount failed!");
253 return rc;
254 }
255 }
256
257
258
259
260 if ((rc = lmLogOpen(sb)))
261 return rc;
262
263
264
265
266 if ((rc = updateSuper(sb, FM_MOUNT))) {
267 jfs_err("jfs_mount: updateSuper failed w/rc = %d", rc);
268 lmLogClose(sb);
269 return rc;
270 }
271
272
273
274
275 logMOUNT(sb);
276
277 return rc;
278}
279
280
281
282
283
284
285
286
287
288
289
290static int chkSuper(struct super_block *sb)
291{
292 int rc = 0;
293 struct jfs_sb_info *sbi = JFS_SBI(sb);
294 struct jfs_superblock *j_sb;
295 struct buffer_head *bh;
296 int AIM_bytesize, AIT_bytesize;
297 int expected_AIM_bytesize, expected_AIT_bytesize;
298 s64 AIM_byte_addr, AIT_byte_addr, fsckwsp_addr;
299 s64 byte_addr_diff0, byte_addr_diff1;
300 s32 bsize;
301
302 if ((rc = readSuper(sb, &bh)))
303 return rc;
304 j_sb = (struct jfs_superblock *)bh->b_data;
305
306
307
308
309
310 if (strncmp(j_sb->s_magic, JFS_MAGIC, 4) ||
311 le32_to_cpu(j_sb->s_version) > JFS_VERSION) {
312 rc = -EINVAL;
313 goto out;
314 }
315
316 bsize = le32_to_cpu(j_sb->s_bsize);
317#ifdef _JFS_4K
318 if (bsize != PSIZE) {
319 jfs_err("Currently only 4K block size supported!");
320 rc = -EINVAL;
321 goto out;
322 }
323#endif
324
325 jfs_info("superblock: flag:0x%08x state:0x%08x size:0x%Lx",
326 le32_to_cpu(j_sb->s_flag), le32_to_cpu(j_sb->s_state),
327 (unsigned long long) le64_to_cpu(j_sb->s_size));
328
329
330 if ((j_sb->s_flag & cpu_to_le32(JFS_BAD_SAIT)) !=
331 cpu_to_le32(JFS_BAD_SAIT)) {
332 expected_AIM_bytesize = 2 * PSIZE;
333 AIM_bytesize = lengthPXD(&(j_sb->s_aim2)) * bsize;
334 expected_AIT_bytesize = 4 * PSIZE;
335 AIT_bytesize = lengthPXD(&(j_sb->s_ait2)) * bsize;
336 AIM_byte_addr = addressPXD(&(j_sb->s_aim2)) * bsize;
337 AIT_byte_addr = addressPXD(&(j_sb->s_ait2)) * bsize;
338 byte_addr_diff0 = AIT_byte_addr - AIM_byte_addr;
339 fsckwsp_addr = addressPXD(&(j_sb->s_fsckpxd)) * bsize;
340 byte_addr_diff1 = fsckwsp_addr - AIT_byte_addr;
341 if ((AIM_bytesize != expected_AIM_bytesize) ||
342 (AIT_bytesize != expected_AIT_bytesize) ||
343 (byte_addr_diff0 != AIM_bytesize) ||
344 (byte_addr_diff1 <= AIT_bytesize))
345 j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT);
346 }
347
348 if ((j_sb->s_flag & cpu_to_le32(JFS_GROUPCOMMIT)) !=
349 cpu_to_le32(JFS_GROUPCOMMIT))
350 j_sb->s_flag |= cpu_to_le32(JFS_GROUPCOMMIT);
351
352
353 if (j_sb->s_state != cpu_to_le32(FM_CLEAN) &&
354 !sb_rdonly(sb)) {
355 jfs_err("jfs_mount: Mount Failure: File System Dirty.");
356 rc = -EINVAL;
357 goto out;
358 }
359
360 sbi->state = le32_to_cpu(j_sb->s_state);
361 sbi->mntflag = le32_to_cpu(j_sb->s_flag);
362
363
364
365
366
367 sbi->bsize = bsize;
368 sbi->l2bsize = le16_to_cpu(j_sb->s_l2bsize);
369
370
371 if (sbi->l2bsize != ilog2((u32)bsize) ||
372 j_sb->pad != 0 ||
373 le32_to_cpu(j_sb->s_state) > FM_STATE_MAX) {
374 rc = -EINVAL;
375 jfs_err("jfs_mount: Mount Failure: superblock is corrupt!");
376 goto out;
377 }
378
379
380
381
382
383 sbi->nbperpage = PSIZE >> sbi->l2bsize;
384 sbi->l2nbperpage = L2PSIZE - sbi->l2bsize;
385 sbi->l2niperblk = sbi->l2bsize - L2DISIZE;
386 if (sbi->mntflag & JFS_INLINELOG)
387 sbi->logpxd = j_sb->s_logpxd;
388 else {
389 sbi->logdev = new_decode_dev(le32_to_cpu(j_sb->s_logdev));
390 uuid_copy(&sbi->uuid, &j_sb->s_uuid);
391 uuid_copy(&sbi->loguuid, &j_sb->s_loguuid);
392 }
393 sbi->fsckpxd = j_sb->s_fsckpxd;
394 sbi->ait2 = j_sb->s_ait2;
395
396 out:
397 brelse(bh);
398 return rc;
399}
400
401
402
403
404
405
406
407int updateSuper(struct super_block *sb, uint state)
408{
409 struct jfs_superblock *j_sb;
410 struct jfs_sb_info *sbi = JFS_SBI(sb);
411 struct buffer_head *bh;
412 int rc;
413
414 if (sbi->flag & JFS_NOINTEGRITY) {
415 if (state == FM_DIRTY) {
416 sbi->p_state = state;
417 return 0;
418 } else if (state == FM_MOUNT) {
419 sbi->p_state = sbi->state;
420 state = FM_DIRTY;
421 } else if (state == FM_CLEAN) {
422 state = sbi->p_state;
423 } else
424 jfs_err("updateSuper: bad state");
425 } else if (sbi->state == FM_DIRTY)
426 return 0;
427
428 if ((rc = readSuper(sb, &bh)))
429 return rc;
430
431 j_sb = (struct jfs_superblock *)bh->b_data;
432
433 j_sb->s_state = cpu_to_le32(state);
434 sbi->state = state;
435
436 if (state == FM_MOUNT) {
437
438 j_sb->s_logdev = cpu_to_le32(new_encode_dev(sbi->log->bdev->bd_dev));
439 j_sb->s_logserial = cpu_to_le32(sbi->log->serial);
440 } else if (state == FM_CLEAN) {
441
442
443
444
445 if (j_sb->s_flag & cpu_to_le32(JFS_DASD_ENABLED))
446 j_sb->s_flag |= cpu_to_le32(JFS_DASD_PRIME);
447 }
448
449 mark_buffer_dirty(bh);
450 sync_dirty_buffer(bh);
451 brelse(bh);
452
453 return 0;
454}
455
456
457
458
459
460
461
462int readSuper(struct super_block *sb, struct buffer_head **bpp)
463{
464
465 *bpp = sb_bread(sb, SUPER1_OFF >> sb->s_blocksize_bits);
466 if (*bpp)
467 return 0;
468
469
470 *bpp = sb_bread(sb, SUPER2_OFF >> sb->s_blocksize_bits);
471 if (*bpp)
472 return 0;
473
474 return -EIO;
475}
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492static int logMOUNT(struct super_block *sb)
493{
494 struct jfs_log *log = JFS_SBI(sb)->log;
495 struct lrd lrd;
496
497 lrd.logtid = 0;
498 lrd.backchain = 0;
499 lrd.type = cpu_to_le16(LOG_MOUNT);
500 lrd.length = 0;
501 lrd.aggregate = cpu_to_le32(new_encode_dev(sb->s_bdev->bd_dev));
502 lmLog(log, NULL, &lrd, NULL);
503
504 return 0;
505}
506