]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/hpfs/super.c | |
3 | * | |
4 | * Mikulas Patocka ([email protected]), 1998-1999 | |
5 | * | |
6 | * mounting, unmounting, error handling | |
7 | */ | |
8 | ||
9 | #include "hpfs_fn.h" | |
10 | #include <linux/module.h> | |
11 | #include <linux/parser.h> | |
12 | #include <linux/init.h> | |
13 | #include <linux/statfs.h> | |
e18fa700 | 14 | #include <linux/magic.h> |
e8edc6e0 | 15 | #include <linux/sched.h> |
337eb00a | 16 | #include <linux/smp_lock.h> |
f4c54fcf | 17 | #include <linux/bitmap.h> |
5a0e3ad6 | 18 | #include <linux/slab.h> |
1da177e4 LT |
19 | |
20 | /* Mark the filesystem dirty, so that chkdsk checks it when os/2 booted */ | |
21 | ||
22 | static void mark_dirty(struct super_block *s) | |
23 | { | |
24 | if (hpfs_sb(s)->sb_chkdsk && !(s->s_flags & MS_RDONLY)) { | |
25 | struct buffer_head *bh; | |
26 | struct hpfs_spare_block *sb; | |
27 | if ((sb = hpfs_map_sector(s, 17, &bh, 0))) { | |
28 | sb->dirty = 1; | |
29 | sb->old_wrote = 0; | |
30 | mark_buffer_dirty(bh); | |
31 | brelse(bh); | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
36 | /* Mark the filesystem clean (mark it dirty for chkdsk if chkdsk==2 or if there | |
37 | were errors) */ | |
38 | ||
39 | static void unmark_dirty(struct super_block *s) | |
40 | { | |
41 | struct buffer_head *bh; | |
42 | struct hpfs_spare_block *sb; | |
43 | if (s->s_flags & MS_RDONLY) return; | |
44 | if ((sb = hpfs_map_sector(s, 17, &bh, 0))) { | |
45 | sb->dirty = hpfs_sb(s)->sb_chkdsk > 1 - hpfs_sb(s)->sb_was_error; | |
46 | sb->old_wrote = hpfs_sb(s)->sb_chkdsk >= 2 && !hpfs_sb(s)->sb_was_error; | |
47 | mark_buffer_dirty(bh); | |
48 | brelse(bh); | |
49 | } | |
50 | } | |
51 | ||
52 | /* Filesystem error... */ | |
352d94d0 | 53 | static char err_buf[1024]; |
1da177e4 | 54 | |
352d94d0 | 55 | void hpfs_error(struct super_block *s, const char *fmt, ...) |
1da177e4 | 56 | { |
352d94d0 AD |
57 | va_list args; |
58 | ||
59 | va_start(args, fmt); | |
60 | vsnprintf(err_buf, sizeof(err_buf), fmt, args); | |
61 | va_end(args); | |
62 | ||
63 | printk("HPFS: filesystem error: %s", err_buf); | |
1da177e4 LT |
64 | if (!hpfs_sb(s)->sb_was_error) { |
65 | if (hpfs_sb(s)->sb_err == 2) { | |
66 | printk("; crashing the system because you wanted it\n"); | |
67 | mark_dirty(s); | |
68 | panic("HPFS panic"); | |
69 | } else if (hpfs_sb(s)->sb_err == 1) { | |
70 | if (s->s_flags & MS_RDONLY) printk("; already mounted read-only\n"); | |
71 | else { | |
72 | printk("; remounting read-only\n"); | |
73 | mark_dirty(s); | |
74 | s->s_flags |= MS_RDONLY; | |
75 | } | |
76 | } else if (s->s_flags & MS_RDONLY) printk("; going on - but anything won't be destroyed because it's read-only\n"); | |
77 | else printk("; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so!\n"); | |
78 | } else printk("\n"); | |
1da177e4 LT |
79 | hpfs_sb(s)->sb_was_error = 1; |
80 | } | |
81 | ||
82 | /* | |
83 | * A little trick to detect cycles in many hpfs structures and don't let the | |
84 | * kernel crash on corrupted filesystem. When first called, set c2 to 0. | |
85 | * | |
86 | * BTW. chkdsk doesn't detect cycles correctly. When I had 2 lost directories | |
87 | * nested each in other, chkdsk locked up happilly. | |
88 | */ | |
89 | ||
90 | int hpfs_stop_cycles(struct super_block *s, int key, int *c1, int *c2, | |
91 | char *msg) | |
92 | { | |
93 | if (*c2 && *c1 == key) { | |
94 | hpfs_error(s, "cycle detected on key %08x in %s", key, msg); | |
95 | return 1; | |
96 | } | |
97 | (*c2)++; | |
98 | if (!((*c2 - 1) & *c2)) *c1 = key; | |
99 | return 0; | |
100 | } | |
101 | ||
102 | static void hpfs_put_super(struct super_block *s) | |
103 | { | |
104 | struct hpfs_sb_info *sbi = hpfs_sb(s); | |
6cfd0148 CH |
105 | |
106 | lock_kernel(); | |
107 | ||
f99d49ad JJ |
108 | kfree(sbi->sb_cp_table); |
109 | kfree(sbi->sb_bmp_dir); | |
1da177e4 LT |
110 | unmark_dirty(s); |
111 | s->s_fs_info = NULL; | |
112 | kfree(sbi); | |
6cfd0148 CH |
113 | |
114 | unlock_kernel(); | |
1da177e4 LT |
115 | } |
116 | ||
117 | unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno) | |
118 | { | |
119 | struct quad_buffer_head qbh; | |
f4c54fcf AM |
120 | unsigned long *bits; |
121 | unsigned count; | |
122 | ||
123 | bits = hpfs_map_4sectors(s, secno, &qbh, 4); | |
124 | if (!bits) | |
125 | return 0; | |
126 | count = bitmap_weight(bits, 2048 * BITS_PER_BYTE); | |
1da177e4 LT |
127 | hpfs_brelse4(&qbh); |
128 | return count; | |
129 | } | |
130 | ||
131 | static unsigned count_bitmaps(struct super_block *s) | |
132 | { | |
133 | unsigned n, count, n_bands; | |
134 | n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14; | |
135 | count = 0; | |
136 | for (n = 0; n < n_bands; n++) | |
137 | count += hpfs_count_one_bitmap(s, hpfs_sb(s)->sb_bmp_dir[n]); | |
138 | return count; | |
139 | } | |
140 | ||
726c3342 | 141 | static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4 | 142 | { |
726c3342 | 143 | struct super_block *s = dentry->d_sb; |
1da177e4 | 144 | struct hpfs_sb_info *sbi = hpfs_sb(s); |
604d295c | 145 | u64 id = huge_encode_dev(s->s_bdev->bd_dev); |
1da177e4 LT |
146 | lock_kernel(); |
147 | ||
148 | /*if (sbi->sb_n_free == -1) {*/ | |
149 | sbi->sb_n_free = count_bitmaps(s); | |
150 | sbi->sb_n_free_dnodes = hpfs_count_one_bitmap(s, sbi->sb_dmap); | |
151 | /*}*/ | |
152 | buf->f_type = s->s_magic; | |
153 | buf->f_bsize = 512; | |
154 | buf->f_blocks = sbi->sb_fs_size; | |
155 | buf->f_bfree = sbi->sb_n_free; | |
156 | buf->f_bavail = sbi->sb_n_free; | |
157 | buf->f_files = sbi->sb_dirband_size / 4; | |
158 | buf->f_ffree = sbi->sb_n_free_dnodes; | |
604d295c CL |
159 | buf->f_fsid.val[0] = (u32)id; |
160 | buf->f_fsid.val[1] = (u32)(id >> 32); | |
1da177e4 LT |
161 | buf->f_namelen = 254; |
162 | ||
163 | unlock_kernel(); | |
164 | ||
165 | return 0; | |
166 | } | |
167 | ||
e18b890b | 168 | static struct kmem_cache * hpfs_inode_cachep; |
1da177e4 LT |
169 | |
170 | static struct inode *hpfs_alloc_inode(struct super_block *sb) | |
171 | { | |
172 | struct hpfs_inode_info *ei; | |
e6b4f8da | 173 | ei = (struct hpfs_inode_info *)kmem_cache_alloc(hpfs_inode_cachep, GFP_NOFS); |
1da177e4 LT |
174 | if (!ei) |
175 | return NULL; | |
176 | ei->vfs_inode.i_version = 1; | |
177 | return &ei->vfs_inode; | |
178 | } | |
179 | ||
fa0d7e3d | 180 | static void hpfs_i_callback(struct rcu_head *head) |
1da177e4 | 181 | { |
fa0d7e3d NP |
182 | struct inode *inode = container_of(head, struct inode, i_rcu); |
183 | INIT_LIST_HEAD(&inode->i_dentry); | |
1da177e4 LT |
184 | kmem_cache_free(hpfs_inode_cachep, hpfs_i(inode)); |
185 | } | |
186 | ||
fa0d7e3d NP |
187 | static void hpfs_destroy_inode(struct inode *inode) |
188 | { | |
189 | call_rcu(&inode->i_rcu, hpfs_i_callback); | |
190 | } | |
191 | ||
51cc5068 | 192 | static void init_once(void *foo) |
1da177e4 LT |
193 | { |
194 | struct hpfs_inode_info *ei = (struct hpfs_inode_info *) foo; | |
195 | ||
a35afb83 CL |
196 | mutex_init(&ei->i_mutex); |
197 | mutex_init(&ei->i_parent_mutex); | |
198 | inode_init_once(&ei->vfs_inode); | |
1da177e4 | 199 | } |
20c2df83 | 200 | |
1da177e4 LT |
201 | static int init_inodecache(void) |
202 | { | |
203 | hpfs_inode_cachep = kmem_cache_create("hpfs_inode_cache", | |
204 | sizeof(struct hpfs_inode_info), | |
fffb60f9 PJ |
205 | 0, (SLAB_RECLAIM_ACCOUNT| |
206 | SLAB_MEM_SPREAD), | |
20c2df83 | 207 | init_once); |
1da177e4 LT |
208 | if (hpfs_inode_cachep == NULL) |
209 | return -ENOMEM; | |
210 | return 0; | |
211 | } | |
212 | ||
213 | static void destroy_inodecache(void) | |
214 | { | |
1a1d92c1 | 215 | kmem_cache_destroy(hpfs_inode_cachep); |
1da177e4 LT |
216 | } |
217 | ||
218 | /* | |
219 | * A tiny parser for option strings, stolen from dosfs. | |
220 | * Stolen again from read-only hpfs. | |
221 | * And updated for table-driven option parsing. | |
222 | */ | |
223 | ||
224 | enum { | |
225 | Opt_help, Opt_uid, Opt_gid, Opt_umask, Opt_case_lower, Opt_case_asis, | |
226 | Opt_conv_binary, Opt_conv_text, Opt_conv_auto, | |
227 | Opt_check_none, Opt_check_normal, Opt_check_strict, | |
228 | Opt_err_cont, Opt_err_ro, Opt_err_panic, | |
229 | Opt_eas_no, Opt_eas_ro, Opt_eas_rw, | |
230 | Opt_chkdsk_no, Opt_chkdsk_errors, Opt_chkdsk_always, | |
231 | Opt_timeshift, Opt_err, | |
232 | }; | |
233 | ||
a447c093 | 234 | static const match_table_t tokens = { |
1da177e4 LT |
235 | {Opt_help, "help"}, |
236 | {Opt_uid, "uid=%u"}, | |
237 | {Opt_gid, "gid=%u"}, | |
238 | {Opt_umask, "umask=%o"}, | |
239 | {Opt_case_lower, "case=lower"}, | |
240 | {Opt_case_asis, "case=asis"}, | |
241 | {Opt_conv_binary, "conv=binary"}, | |
242 | {Opt_conv_text, "conv=text"}, | |
243 | {Opt_conv_auto, "conv=auto"}, | |
244 | {Opt_check_none, "check=none"}, | |
245 | {Opt_check_normal, "check=normal"}, | |
246 | {Opt_check_strict, "check=strict"}, | |
247 | {Opt_err_cont, "errors=continue"}, | |
248 | {Opt_err_ro, "errors=remount-ro"}, | |
249 | {Opt_err_panic, "errors=panic"}, | |
250 | {Opt_eas_no, "eas=no"}, | |
251 | {Opt_eas_ro, "eas=ro"}, | |
252 | {Opt_eas_rw, "eas=rw"}, | |
253 | {Opt_chkdsk_no, "chkdsk=no"}, | |
254 | {Opt_chkdsk_errors, "chkdsk=errors"}, | |
255 | {Opt_chkdsk_always, "chkdsk=always"}, | |
256 | {Opt_timeshift, "timeshift=%d"}, | |
257 | {Opt_err, NULL}, | |
258 | }; | |
259 | ||
260 | static int parse_opts(char *opts, uid_t *uid, gid_t *gid, umode_t *umask, | |
261 | int *lowercase, int *conv, int *eas, int *chk, int *errs, | |
262 | int *chkdsk, int *timeshift) | |
263 | { | |
264 | char *p; | |
265 | int option; | |
266 | ||
267 | if (!opts) | |
268 | return 1; | |
269 | ||
270 | /*printk("Parsing opts: '%s'\n",opts);*/ | |
271 | ||
272 | while ((p = strsep(&opts, ",")) != NULL) { | |
273 | substring_t args[MAX_OPT_ARGS]; | |
274 | int token; | |
275 | if (!*p) | |
276 | continue; | |
277 | ||
278 | token = match_token(p, tokens, args); | |
279 | switch (token) { | |
280 | case Opt_help: | |
281 | return 2; | |
282 | case Opt_uid: | |
283 | if (match_int(args, &option)) | |
284 | return 0; | |
285 | *uid = option; | |
286 | break; | |
287 | case Opt_gid: | |
288 | if (match_int(args, &option)) | |
289 | return 0; | |
290 | *gid = option; | |
291 | break; | |
292 | case Opt_umask: | |
293 | if (match_octal(args, &option)) | |
294 | return 0; | |
295 | *umask = option; | |
296 | break; | |
297 | case Opt_case_lower: | |
298 | *lowercase = 1; | |
299 | break; | |
300 | case Opt_case_asis: | |
301 | *lowercase = 0; | |
302 | break; | |
303 | case Opt_conv_binary: | |
304 | *conv = CONV_BINARY; | |
305 | break; | |
306 | case Opt_conv_text: | |
307 | *conv = CONV_TEXT; | |
308 | break; | |
309 | case Opt_conv_auto: | |
310 | *conv = CONV_AUTO; | |
311 | break; | |
312 | case Opt_check_none: | |
313 | *chk = 0; | |
314 | break; | |
315 | case Opt_check_normal: | |
316 | *chk = 1; | |
317 | break; | |
318 | case Opt_check_strict: | |
319 | *chk = 2; | |
320 | break; | |
321 | case Opt_err_cont: | |
322 | *errs = 0; | |
323 | break; | |
324 | case Opt_err_ro: | |
325 | *errs = 1; | |
326 | break; | |
327 | case Opt_err_panic: | |
328 | *errs = 2; | |
329 | break; | |
330 | case Opt_eas_no: | |
331 | *eas = 0; | |
332 | break; | |
333 | case Opt_eas_ro: | |
334 | *eas = 1; | |
335 | break; | |
336 | case Opt_eas_rw: | |
337 | *eas = 2; | |
338 | break; | |
339 | case Opt_chkdsk_no: | |
340 | *chkdsk = 0; | |
341 | break; | |
342 | case Opt_chkdsk_errors: | |
343 | *chkdsk = 1; | |
344 | break; | |
345 | case Opt_chkdsk_always: | |
346 | *chkdsk = 2; | |
347 | break; | |
348 | case Opt_timeshift: | |
349 | { | |
350 | int m = 1; | |
351 | char *rhs = args[0].from; | |
352 | if (!rhs || !*rhs) | |
353 | return 0; | |
354 | if (*rhs == '-') m = -1; | |
355 | if (*rhs == '+' || *rhs == '-') rhs++; | |
356 | *timeshift = simple_strtoul(rhs, &rhs, 0) * m; | |
357 | if (*rhs) | |
358 | return 0; | |
359 | break; | |
360 | } | |
361 | default: | |
362 | return 0; | |
363 | } | |
364 | } | |
365 | return 1; | |
366 | } | |
367 | ||
368 | static inline void hpfs_help(void) | |
369 | { | |
370 | printk("\n\ | |
371 | HPFS filesystem options:\n\ | |
372 | help do not mount and display this text\n\ | |
373 | uid=xxx set uid of files that don't have uid specified in eas\n\ | |
374 | gid=xxx set gid of files that don't have gid specified in eas\n\ | |
375 | umask=xxx set mode of files that don't have mode specified in eas\n\ | |
376 | case=lower lowercase all files\n\ | |
377 | case=asis do not lowercase files (default)\n\ | |
378 | conv=binary do not convert CR/LF -> LF (default)\n\ | |
379 | conv=auto convert only files with known text extensions\n\ | |
380 | conv=text convert all files\n\ | |
381 | check=none no fs checks - kernel may crash on corrupted filesystem\n\ | |
382 | check=normal do some checks - it should not crash (default)\n\ | |
383 | check=strict do extra time-consuming checks, used for debugging\n\ | |
384 | errors=continue continue on errors\n\ | |
385 | errors=remount-ro remount read-only if errors found (default)\n\ | |
386 | errors=panic panic on errors\n\ | |
387 | chkdsk=no do not mark fs for chkdsking even if there were errors\n\ | |
388 | chkdsk=errors mark fs dirty if errors found (default)\n\ | |
389 | chkdsk=always always mark fs dirty - used for debugging\n\ | |
390 | eas=no ignore extended attributes\n\ | |
391 | eas=ro read but do not write extended attributes\n\ | |
392 | eas=rw r/w eas => enables chmod, chown, mknod, ln -s (default)\n\ | |
393 | timeshift=nnn add nnn seconds to file times\n\ | |
394 | \n"); | |
395 | } | |
396 | ||
397 | static int hpfs_remount_fs(struct super_block *s, int *flags, char *data) | |
398 | { | |
399 | uid_t uid; | |
400 | gid_t gid; | |
401 | umode_t umask; | |
402 | int lowercase, conv, eas, chk, errs, chkdsk, timeshift; | |
403 | int o; | |
404 | struct hpfs_sb_info *sbi = hpfs_sb(s); | |
6d9c1fd4 | 405 | char *new_opts = kstrdup(data, GFP_KERNEL); |
1da177e4 LT |
406 | |
407 | *flags |= MS_NOATIME; | |
408 | ||
337eb00a | 409 | lock_kernel(); |
bbd6851a | 410 | lock_super(s); |
1da177e4 LT |
411 | uid = sbi->sb_uid; gid = sbi->sb_gid; |
412 | umask = 0777 & ~sbi->sb_mode; | |
413 | lowercase = sbi->sb_lowercase; conv = sbi->sb_conv; | |
414 | eas = sbi->sb_eas; chk = sbi->sb_chk; chkdsk = sbi->sb_chkdsk; | |
415 | errs = sbi->sb_err; timeshift = sbi->sb_timeshift; | |
416 | ||
417 | if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase, &conv, | |
418 | &eas, &chk, &errs, &chkdsk, ×hift))) { | |
419 | printk("HPFS: bad mount options.\n"); | |
6d9c1fd4 | 420 | goto out_err; |
1da177e4 LT |
421 | } |
422 | if (o == 2) { | |
423 | hpfs_help(); | |
6d9c1fd4 | 424 | goto out_err; |
1da177e4 LT |
425 | } |
426 | if (timeshift != sbi->sb_timeshift) { | |
427 | printk("HPFS: timeshift can't be changed using remount.\n"); | |
6d9c1fd4 | 428 | goto out_err; |
1da177e4 LT |
429 | } |
430 | ||
431 | unmark_dirty(s); | |
432 | ||
433 | sbi->sb_uid = uid; sbi->sb_gid = gid; | |
434 | sbi->sb_mode = 0777 & ~umask; | |
435 | sbi->sb_lowercase = lowercase; sbi->sb_conv = conv; | |
436 | sbi->sb_eas = eas; sbi->sb_chk = chk; sbi->sb_chkdsk = chkdsk; | |
437 | sbi->sb_err = errs; sbi->sb_timeshift = timeshift; | |
438 | ||
439 | if (!(*flags & MS_RDONLY)) mark_dirty(s); | |
440 | ||
2a32cebd | 441 | replace_mount_options(s, new_opts); |
6d9c1fd4 | 442 | |
bbd6851a | 443 | unlock_super(s); |
337eb00a | 444 | unlock_kernel(); |
1da177e4 | 445 | return 0; |
6d9c1fd4 MS |
446 | |
447 | out_err: | |
bbd6851a | 448 | unlock_super(s); |
337eb00a | 449 | unlock_kernel(); |
6d9c1fd4 MS |
450 | kfree(new_opts); |
451 | return -EINVAL; | |
1da177e4 LT |
452 | } |
453 | ||
454 | /* Super operations */ | |
455 | ||
ee9b6d61 | 456 | static const struct super_operations hpfs_sops = |
1da177e4 LT |
457 | { |
458 | .alloc_inode = hpfs_alloc_inode, | |
459 | .destroy_inode = hpfs_destroy_inode, | |
ea544009 | 460 | .evict_inode = hpfs_evict_inode, |
1da177e4 LT |
461 | .put_super = hpfs_put_super, |
462 | .statfs = hpfs_statfs, | |
463 | .remount_fs = hpfs_remount_fs, | |
6d9c1fd4 | 464 | .show_options = generic_show_options, |
1da177e4 LT |
465 | }; |
466 | ||
467 | static int hpfs_fill_super(struct super_block *s, void *options, int silent) | |
468 | { | |
469 | struct buffer_head *bh0, *bh1, *bh2; | |
470 | struct hpfs_boot_block *bootblock; | |
471 | struct hpfs_super_block *superblock; | |
472 | struct hpfs_spare_block *spareblock; | |
473 | struct hpfs_sb_info *sbi; | |
474 | struct inode *root; | |
475 | ||
476 | uid_t uid; | |
477 | gid_t gid; | |
478 | umode_t umask; | |
479 | int lowercase, conv, eas, chk, errs, chkdsk, timeshift; | |
480 | ||
481 | dnode_secno root_dno; | |
482 | struct hpfs_dirent *de = NULL; | |
483 | struct quad_buffer_head qbh; | |
484 | ||
485 | int o; | |
486 | ||
db719222 JB |
487 | lock_kernel(); |
488 | ||
6d9c1fd4 MS |
489 | save_mount_options(s, options); |
490 | ||
f8314dc6 | 491 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
db719222 JB |
492 | if (!sbi) { |
493 | unlock_kernel(); | |
1da177e4 | 494 | return -ENOMEM; |
db719222 | 495 | } |
1da177e4 | 496 | s->s_fs_info = sbi; |
1da177e4 LT |
497 | |
498 | sbi->sb_bmp_dir = NULL; | |
499 | sbi->sb_cp_table = NULL; | |
500 | ||
117bf5fb | 501 | mutex_init(&sbi->hpfs_creation_de); |
1da177e4 | 502 | |
de395b8a DH |
503 | uid = current_uid(); |
504 | gid = current_gid(); | |
ce3b0f8d | 505 | umask = current_umask(); |
1da177e4 LT |
506 | lowercase = 0; |
507 | conv = CONV_BINARY; | |
508 | eas = 2; | |
509 | chk = 1; | |
510 | errs = 1; | |
511 | chkdsk = 1; | |
512 | timeshift = 0; | |
513 | ||
514 | if (!(o = parse_opts(options, &uid, &gid, &umask, &lowercase, &conv, | |
515 | &eas, &chk, &errs, &chkdsk, ×hift))) { | |
516 | printk("HPFS: bad mount options.\n"); | |
517 | goto bail0; | |
518 | } | |
519 | if (o==2) { | |
520 | hpfs_help(); | |
521 | goto bail0; | |
522 | } | |
523 | ||
524 | /*sbi->sb_mounting = 1;*/ | |
525 | sb_set_blocksize(s, 512); | |
526 | sbi->sb_fs_size = -1; | |
527 | if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1; | |
528 | if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2; | |
529 | if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3; | |
530 | ||
531 | /* Check magics */ | |
532 | if (/*bootblock->magic != BB_MAGIC | |
533 | ||*/ superblock->magic != SB_MAGIC | |
534 | || spareblock->magic != SP_MAGIC) { | |
535 | if (!silent) printk("HPFS: Bad magic ... probably not HPFS\n"); | |
536 | goto bail4; | |
537 | } | |
538 | ||
539 | /* Check version */ | |
540 | if (!(s->s_flags & MS_RDONLY) && | |
541 | superblock->funcversion != 2 && superblock->funcversion != 3) { | |
542 | printk("HPFS: Bad version %d,%d. Mount readonly to go around\n", | |
543 | (int)superblock->version, (int)superblock->funcversion); | |
544 | printk("HPFS: please try recent version of HPFS driver at http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi and if it still can't understand this format, contact author - [email protected]\n"); | |
545 | goto bail4; | |
546 | } | |
547 | ||
548 | s->s_flags |= MS_NOATIME; | |
549 | ||
550 | /* Fill superblock stuff */ | |
551 | s->s_magic = HPFS_SUPER_MAGIC; | |
552 | s->s_op = &hpfs_sops; | |
43d344d7 | 553 | s->s_d_op = &hpfs_dentry_operations; |
1da177e4 LT |
554 | |
555 | sbi->sb_root = superblock->root; | |
556 | sbi->sb_fs_size = superblock->n_sectors; | |
557 | sbi->sb_bitmaps = superblock->bitmaps; | |
558 | sbi->sb_dirband_start = superblock->dir_band_start; | |
559 | sbi->sb_dirband_size = superblock->n_dir_band; | |
560 | sbi->sb_dmap = superblock->dir_band_bitmap; | |
561 | sbi->sb_uid = uid; | |
562 | sbi->sb_gid = gid; | |
563 | sbi->sb_mode = 0777 & ~umask; | |
564 | sbi->sb_n_free = -1; | |
565 | sbi->sb_n_free_dnodes = -1; | |
566 | sbi->sb_lowercase = lowercase; | |
567 | sbi->sb_conv = conv; | |
568 | sbi->sb_eas = eas; | |
569 | sbi->sb_chk = chk; | |
570 | sbi->sb_chkdsk = chkdsk; | |
571 | sbi->sb_err = errs; | |
572 | sbi->sb_timeshift = timeshift; | |
573 | sbi->sb_was_error = 0; | |
574 | sbi->sb_cp_table = NULL; | |
575 | sbi->sb_c_bitmap = -1; | |
576 | sbi->sb_max_fwd_alloc = 0xffffff; | |
577 | ||
578 | /* Load bitmap directory */ | |
579 | if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, superblock->bitmaps))) | |
580 | goto bail4; | |
581 | ||
582 | /* Check for general fs errors*/ | |
583 | if (spareblock->dirty && !spareblock->old_wrote) { | |
584 | if (errs == 2) { | |
585 | printk("HPFS: Improperly stopped, not mounted\n"); | |
586 | goto bail4; | |
587 | } | |
588 | hpfs_error(s, "improperly stopped"); | |
589 | } | |
590 | ||
591 | if (!(s->s_flags & MS_RDONLY)) { | |
592 | spareblock->dirty = 1; | |
593 | spareblock->old_wrote = 0; | |
594 | mark_buffer_dirty(bh2); | |
595 | } | |
596 | ||
597 | if (spareblock->hotfixes_used || spareblock->n_spares_used) { | |
598 | if (errs >= 2) { | |
599 | printk("HPFS: Hotfixes not supported here, try chkdsk\n"); | |
600 | mark_dirty(s); | |
601 | goto bail4; | |
602 | } | |
603 | hpfs_error(s, "hotfixes not supported here, try chkdsk"); | |
604 | if (errs == 0) printk("HPFS: Proceeding, but your filesystem will be probably corrupted by this driver...\n"); | |
605 | else printk("HPFS: This driver may read bad files or crash when operating on disk with hotfixes.\n"); | |
606 | } | |
607 | if (spareblock->n_dnode_spares != spareblock->n_dnode_spares_free) { | |
608 | if (errs >= 2) { | |
609 | printk("HPFS: Spare dnodes used, try chkdsk\n"); | |
610 | mark_dirty(s); | |
611 | goto bail4; | |
612 | } | |
613 | hpfs_error(s, "warning: spare dnodes used, try chkdsk"); | |
614 | if (errs == 0) printk("HPFS: Proceeding, but your filesystem could be corrupted if you delete files or directories\n"); | |
615 | } | |
616 | if (chk) { | |
617 | unsigned a; | |
618 | if (superblock->dir_band_end - superblock->dir_band_start + 1 != superblock->n_dir_band || | |
619 | superblock->dir_band_end < superblock->dir_band_start || superblock->n_dir_band > 0x4000) { | |
620 | hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x", | |
621 | superblock->dir_band_start, superblock->dir_band_end, superblock->n_dir_band); | |
622 | goto bail4; | |
623 | } | |
624 | a = sbi->sb_dirband_size; | |
625 | sbi->sb_dirband_size = 0; | |
626 | if (hpfs_chk_sectors(s, superblock->dir_band_start, superblock->n_dir_band, "dir_band") || | |
627 | hpfs_chk_sectors(s, superblock->dir_band_bitmap, 4, "dir_band_bitmap") || | |
628 | hpfs_chk_sectors(s, superblock->bitmaps, 4, "bitmaps")) { | |
629 | mark_dirty(s); | |
630 | goto bail4; | |
631 | } | |
632 | sbi->sb_dirband_size = a; | |
633 | } else printk("HPFS: You really don't want any checks? You are crazy...\n"); | |
634 | ||
635 | /* Load code page table */ | |
636 | if (spareblock->n_code_pages) | |
637 | if (!(sbi->sb_cp_table = hpfs_load_code_page(s, spareblock->code_page_dir))) | |
638 | printk("HPFS: Warning: code page support is disabled\n"); | |
639 | ||
640 | brelse(bh2); | |
641 | brelse(bh1); | |
642 | brelse(bh0); | |
643 | ||
644 | root = iget_locked(s, sbi->sb_root); | |
645 | if (!root) | |
646 | goto bail0; | |
647 | hpfs_init_inode(root); | |
648 | hpfs_read_inode(root); | |
649 | unlock_new_inode(root); | |
650 | s->s_root = d_alloc_root(root); | |
651 | if (!s->s_root) { | |
652 | iput(root); | |
653 | goto bail0; | |
654 | } | |
1da177e4 LT |
655 | |
656 | /* | |
657 | * find the root directory's . pointer & finish filling in the inode | |
658 | */ | |
659 | ||
660 | root_dno = hpfs_fnode_dno(s, sbi->sb_root); | |
661 | if (root_dno) | |
662 | de = map_dirent(root, root_dno, "\001\001", 2, NULL, &qbh); | |
663 | if (!de) | |
664 | hpfs_error(s, "unable to find root dir"); | |
665 | else { | |
666 | root->i_atime.tv_sec = local_to_gmt(s, de->read_date); | |
667 | root->i_atime.tv_nsec = 0; | |
668 | root->i_mtime.tv_sec = local_to_gmt(s, de->write_date); | |
669 | root->i_mtime.tv_nsec = 0; | |
670 | root->i_ctime.tv_sec = local_to_gmt(s, de->creation_date); | |
671 | root->i_ctime.tv_nsec = 0; | |
672 | hpfs_i(root)->i_ea_size = de->ea_size; | |
673 | hpfs_i(root)->i_parent_dir = root->i_ino; | |
674 | if (root->i_size == -1) | |
675 | root->i_size = 2048; | |
676 | if (root->i_blocks == -1) | |
677 | root->i_blocks = 5; | |
678 | hpfs_brelse4(&qbh); | |
679 | } | |
db719222 | 680 | unlock_kernel(); |
1da177e4 LT |
681 | return 0; |
682 | ||
683 | bail4: brelse(bh2); | |
684 | bail3: brelse(bh1); | |
685 | bail2: brelse(bh0); | |
686 | bail1: | |
687 | bail0: | |
f99d49ad JJ |
688 | kfree(sbi->sb_bmp_dir); |
689 | kfree(sbi->sb_cp_table); | |
1da177e4 LT |
690 | s->s_fs_info = NULL; |
691 | kfree(sbi); | |
db719222 | 692 | unlock_kernel(); |
1da177e4 LT |
693 | return -EINVAL; |
694 | } | |
695 | ||
152a0836 AV |
696 | static struct dentry *hpfs_mount(struct file_system_type *fs_type, |
697 | int flags, const char *dev_name, void *data) | |
1da177e4 | 698 | { |
152a0836 | 699 | return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super); |
1da177e4 LT |
700 | } |
701 | ||
702 | static struct file_system_type hpfs_fs_type = { | |
703 | .owner = THIS_MODULE, | |
704 | .name = "hpfs", | |
152a0836 | 705 | .mount = hpfs_mount, |
1da177e4 LT |
706 | .kill_sb = kill_block_super, |
707 | .fs_flags = FS_REQUIRES_DEV, | |
708 | }; | |
709 | ||
710 | static int __init init_hpfs_fs(void) | |
711 | { | |
712 | int err = init_inodecache(); | |
713 | if (err) | |
714 | goto out1; | |
715 | err = register_filesystem(&hpfs_fs_type); | |
716 | if (err) | |
717 | goto out; | |
718 | return 0; | |
719 | out: | |
720 | destroy_inodecache(); | |
721 | out1: | |
722 | return err; | |
723 | } | |
724 | ||
725 | static void __exit exit_hpfs_fs(void) | |
726 | { | |
727 | unregister_filesystem(&hpfs_fs_type); | |
728 | destroy_inodecache(); | |
729 | } | |
730 | ||
731 | module_init(init_hpfs_fs) | |
732 | module_exit(exit_hpfs_fs) | |
733 | MODULE_LICENSE("GPL"); |