49935ba78db8a1d4398f52d6f8da7e537754b4ef
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / hpfs / super.c
1 /*
2 * linux/fs/hpfs/super.c
3 *
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 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>
14 #include <linux/magic.h>
15 #include <linux/sched.h>
16 #include <linux/smp_lock.h>
17 #include <linux/bitmap.h>
18 #include <linux/slab.h>
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... */
53 static char err_buf[1024];
54
55 void hpfs_error(struct super_block *s, const char *fmt, ...)
56 {
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);
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");
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);
105
106 lock_kernel();
107
108 kfree(sbi->sb_cp_table);
109 kfree(sbi->sb_bmp_dir);
110 unmark_dirty(s);
111 s->s_fs_info = NULL;
112 kfree(sbi);
113
114 unlock_kernel();
115 }
116
117 unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
118 {
119 struct quad_buffer_head qbh;
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);
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
141 static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
142 {
143 struct super_block *s = dentry->d_sb;
144 struct hpfs_sb_info *sbi = hpfs_sb(s);
145 u64 id = huge_encode_dev(s->s_bdev->bd_dev);
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;
159 buf->f_fsid.val[0] = (u32)id;
160 buf->f_fsid.val[1] = (u32)(id >> 32);
161 buf->f_namelen = 254;
162
163 unlock_kernel();
164
165 return 0;
166 }
167
168 static struct kmem_cache * hpfs_inode_cachep;
169
170 static struct inode *hpfs_alloc_inode(struct super_block *sb)
171 {
172 struct hpfs_inode_info *ei;
173 ei = (struct hpfs_inode_info *)kmem_cache_alloc(hpfs_inode_cachep, GFP_NOFS);
174 if (!ei)
175 return NULL;
176 ei->vfs_inode.i_version = 1;
177 return &ei->vfs_inode;
178 }
179
180 static void hpfs_i_callback(struct rcu_head *head)
181 {
182 struct inode *inode = container_of(head, struct inode, i_rcu);
183 INIT_LIST_HEAD(&inode->i_dentry);
184 kmem_cache_free(hpfs_inode_cachep, hpfs_i(inode));
185 }
186
187 static void hpfs_destroy_inode(struct inode *inode)
188 {
189 call_rcu(&inode->i_rcu, hpfs_i_callback);
190 }
191
192 static void init_once(void *foo)
193 {
194 struct hpfs_inode_info *ei = (struct hpfs_inode_info *) foo;
195
196 mutex_init(&ei->i_mutex);
197 mutex_init(&ei->i_parent_mutex);
198 inode_init_once(&ei->vfs_inode);
199 }
200
201 static int init_inodecache(void)
202 {
203 hpfs_inode_cachep = kmem_cache_create("hpfs_inode_cache",
204 sizeof(struct hpfs_inode_info),
205 0, (SLAB_RECLAIM_ACCOUNT|
206 SLAB_MEM_SPREAD),
207 init_once);
208 if (hpfs_inode_cachep == NULL)
209 return -ENOMEM;
210 return 0;
211 }
212
213 static void destroy_inodecache(void)
214 {
215 kmem_cache_destroy(hpfs_inode_cachep);
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
234 static const match_table_t tokens = {
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);
405 char *new_opts = kstrdup(data, GFP_KERNEL);
406
407 *flags |= MS_NOATIME;
408
409 lock_kernel();
410 lock_super(s);
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, &timeshift))) {
419 printk("HPFS: bad mount options.\n");
420 goto out_err;
421 }
422 if (o == 2) {
423 hpfs_help();
424 goto out_err;
425 }
426 if (timeshift != sbi->sb_timeshift) {
427 printk("HPFS: timeshift can't be changed using remount.\n");
428 goto out_err;
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
441 replace_mount_options(s, new_opts);
442
443 unlock_super(s);
444 unlock_kernel();
445 return 0;
446
447 out_err:
448 unlock_super(s);
449 unlock_kernel();
450 kfree(new_opts);
451 return -EINVAL;
452 }
453
454 /* Super operations */
455
456 static const struct super_operations hpfs_sops =
457 {
458 .alloc_inode = hpfs_alloc_inode,
459 .destroy_inode = hpfs_destroy_inode,
460 .evict_inode = hpfs_evict_inode,
461 .put_super = hpfs_put_super,
462 .statfs = hpfs_statfs,
463 .remount_fs = hpfs_remount_fs,
464 .show_options = generic_show_options,
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
487 lock_kernel();
488
489 save_mount_options(s, options);
490
491 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
492 if (!sbi) {
493 unlock_kernel();
494 return -ENOMEM;
495 }
496 s->s_fs_info = sbi;
497
498 sbi->sb_bmp_dir = NULL;
499 sbi->sb_cp_table = NULL;
500
501 mutex_init(&sbi->hpfs_creation_de);
502
503 uid = current_uid();
504 gid = current_gid();
505 umask = current_umask();
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, &timeshift))) {
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 - mikulas@artax.karlin.mff.cuni.cz\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;
553
554 sbi->sb_root = superblock->root;
555 sbi->sb_fs_size = superblock->n_sectors;
556 sbi->sb_bitmaps = superblock->bitmaps;
557 sbi->sb_dirband_start = superblock->dir_band_start;
558 sbi->sb_dirband_size = superblock->n_dir_band;
559 sbi->sb_dmap = superblock->dir_band_bitmap;
560 sbi->sb_uid = uid;
561 sbi->sb_gid = gid;
562 sbi->sb_mode = 0777 & ~umask;
563 sbi->sb_n_free = -1;
564 sbi->sb_n_free_dnodes = -1;
565 sbi->sb_lowercase = lowercase;
566 sbi->sb_conv = conv;
567 sbi->sb_eas = eas;
568 sbi->sb_chk = chk;
569 sbi->sb_chkdsk = chkdsk;
570 sbi->sb_err = errs;
571 sbi->sb_timeshift = timeshift;
572 sbi->sb_was_error = 0;
573 sbi->sb_cp_table = NULL;
574 sbi->sb_c_bitmap = -1;
575 sbi->sb_max_fwd_alloc = 0xffffff;
576
577 /* Load bitmap directory */
578 if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, superblock->bitmaps)))
579 goto bail4;
580
581 /* Check for general fs errors*/
582 if (spareblock->dirty && !spareblock->old_wrote) {
583 if (errs == 2) {
584 printk("HPFS: Improperly stopped, not mounted\n");
585 goto bail4;
586 }
587 hpfs_error(s, "improperly stopped");
588 }
589
590 if (!(s->s_flags & MS_RDONLY)) {
591 spareblock->dirty = 1;
592 spareblock->old_wrote = 0;
593 mark_buffer_dirty(bh2);
594 }
595
596 if (spareblock->hotfixes_used || spareblock->n_spares_used) {
597 if (errs >= 2) {
598 printk("HPFS: Hotfixes not supported here, try chkdsk\n");
599 mark_dirty(s);
600 goto bail4;
601 }
602 hpfs_error(s, "hotfixes not supported here, try chkdsk");
603 if (errs == 0) printk("HPFS: Proceeding, but your filesystem will be probably corrupted by this driver...\n");
604 else printk("HPFS: This driver may read bad files or crash when operating on disk with hotfixes.\n");
605 }
606 if (spareblock->n_dnode_spares != spareblock->n_dnode_spares_free) {
607 if (errs >= 2) {
608 printk("HPFS: Spare dnodes used, try chkdsk\n");
609 mark_dirty(s);
610 goto bail4;
611 }
612 hpfs_error(s, "warning: spare dnodes used, try chkdsk");
613 if (errs == 0) printk("HPFS: Proceeding, but your filesystem could be corrupted if you delete files or directories\n");
614 }
615 if (chk) {
616 unsigned a;
617 if (superblock->dir_band_end - superblock->dir_band_start + 1 != superblock->n_dir_band ||
618 superblock->dir_band_end < superblock->dir_band_start || superblock->n_dir_band > 0x4000) {
619 hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x",
620 superblock->dir_band_start, superblock->dir_band_end, superblock->n_dir_band);
621 goto bail4;
622 }
623 a = sbi->sb_dirband_size;
624 sbi->sb_dirband_size = 0;
625 if (hpfs_chk_sectors(s, superblock->dir_band_start, superblock->n_dir_band, "dir_band") ||
626 hpfs_chk_sectors(s, superblock->dir_band_bitmap, 4, "dir_band_bitmap") ||
627 hpfs_chk_sectors(s, superblock->bitmaps, 4, "bitmaps")) {
628 mark_dirty(s);
629 goto bail4;
630 }
631 sbi->sb_dirband_size = a;
632 } else printk("HPFS: You really don't want any checks? You are crazy...\n");
633
634 /* Load code page table */
635 if (spareblock->n_code_pages)
636 if (!(sbi->sb_cp_table = hpfs_load_code_page(s, spareblock->code_page_dir)))
637 printk("HPFS: Warning: code page support is disabled\n");
638
639 brelse(bh2);
640 brelse(bh1);
641 brelse(bh0);
642
643 root = iget_locked(s, sbi->sb_root);
644 if (!root)
645 goto bail0;
646 hpfs_init_inode(root);
647 hpfs_read_inode(root);
648 unlock_new_inode(root);
649 s->s_root = d_alloc_root(root);
650 if (!s->s_root) {
651 iput(root);
652 goto bail0;
653 }
654 hpfs_set_dentry_operations(s->s_root);
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 }
680 unlock_kernel();
681 return 0;
682
683 bail4: brelse(bh2);
684 bail3: brelse(bh1);
685 bail2: brelse(bh0);
686 bail1:
687 bail0:
688 kfree(sbi->sb_bmp_dir);
689 kfree(sbi->sb_cp_table);
690 s->s_fs_info = NULL;
691 kfree(sbi);
692 unlock_kernel();
693 return -EINVAL;
694 }
695
696 static struct dentry *hpfs_mount(struct file_system_type *fs_type,
697 int flags, const char *dev_name, void *data)
698 {
699 return mount_bdev(fs_type, flags, dev_name, data, hpfs_fill_super);
700 }
701
702 static struct file_system_type hpfs_fs_type = {
703 .owner = THIS_MODULE,
704 .name = "hpfs",
705 .mount = hpfs_mount,
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");