0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/init.h>
0016 #include <linux/module.h>
0017
0018 #include <linux/slab.h>
0019 #include <linux/cred.h>
0020 #include <linux/nls.h>
0021 #include <linux/ctype.h>
0022 #include <linux/statfs.h>
0023 #include <linux/cdrom.h>
0024 #include <linux/parser.h>
0025 #include <linux/mpage.h>
0026 #include <linux/user_namespace.h>
0027 #include <linux/seq_file.h>
0028 #include <linux/blkdev.h>
0029
0030 #include "isofs.h"
0031 #include "zisofs.h"
0032
0033
0034 #define MAX_TZ_OFFSET (52*15*60)
0035
0036 #define BEQUIET
0037
0038 static int isofs_hashi(const struct dentry *parent, struct qstr *qstr);
0039 static int isofs_dentry_cmpi(const struct dentry *dentry,
0040 unsigned int len, const char *str, const struct qstr *name);
0041
0042 #ifdef CONFIG_JOLIET
0043 static int isofs_hashi_ms(const struct dentry *parent, struct qstr *qstr);
0044 static int isofs_hash_ms(const struct dentry *parent, struct qstr *qstr);
0045 static int isofs_dentry_cmpi_ms(const struct dentry *dentry,
0046 unsigned int len, const char *str, const struct qstr *name);
0047 static int isofs_dentry_cmp_ms(const struct dentry *dentry,
0048 unsigned int len, const char *str, const struct qstr *name);
0049 #endif
0050
0051 static void isofs_put_super(struct super_block *sb)
0052 {
0053 struct isofs_sb_info *sbi = ISOFS_SB(sb);
0054
0055 #ifdef CONFIG_JOLIET
0056 unload_nls(sbi->s_nls_iocharset);
0057 #endif
0058
0059 kfree(sbi);
0060 sb->s_fs_info = NULL;
0061 return;
0062 }
0063
0064 static int isofs_read_inode(struct inode *, int relocated);
0065 static int isofs_statfs (struct dentry *, struct kstatfs *);
0066 static int isofs_show_options(struct seq_file *, struct dentry *);
0067
0068 static struct kmem_cache *isofs_inode_cachep;
0069
0070 static struct inode *isofs_alloc_inode(struct super_block *sb)
0071 {
0072 struct iso_inode_info *ei;
0073 ei = alloc_inode_sb(sb, isofs_inode_cachep, GFP_KERNEL);
0074 if (!ei)
0075 return NULL;
0076 return &ei->vfs_inode;
0077 }
0078
0079 static void isofs_free_inode(struct inode *inode)
0080 {
0081 kmem_cache_free(isofs_inode_cachep, ISOFS_I(inode));
0082 }
0083
0084 static void init_once(void *foo)
0085 {
0086 struct iso_inode_info *ei = foo;
0087
0088 inode_init_once(&ei->vfs_inode);
0089 }
0090
0091 static int __init init_inodecache(void)
0092 {
0093 isofs_inode_cachep = kmem_cache_create("isofs_inode_cache",
0094 sizeof(struct iso_inode_info),
0095 0, (SLAB_RECLAIM_ACCOUNT|
0096 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
0097 init_once);
0098 if (!isofs_inode_cachep)
0099 return -ENOMEM;
0100 return 0;
0101 }
0102
0103 static void destroy_inodecache(void)
0104 {
0105
0106
0107
0108
0109 rcu_barrier();
0110 kmem_cache_destroy(isofs_inode_cachep);
0111 }
0112
0113 static int isofs_remount(struct super_block *sb, int *flags, char *data)
0114 {
0115 sync_filesystem(sb);
0116 if (!(*flags & SB_RDONLY))
0117 return -EROFS;
0118 return 0;
0119 }
0120
0121 static const struct super_operations isofs_sops = {
0122 .alloc_inode = isofs_alloc_inode,
0123 .free_inode = isofs_free_inode,
0124 .put_super = isofs_put_super,
0125 .statfs = isofs_statfs,
0126 .remount_fs = isofs_remount,
0127 .show_options = isofs_show_options,
0128 };
0129
0130
0131 static const struct dentry_operations isofs_dentry_ops[] = {
0132 {
0133 .d_hash = isofs_hashi,
0134 .d_compare = isofs_dentry_cmpi,
0135 },
0136 #ifdef CONFIG_JOLIET
0137 {
0138 .d_hash = isofs_hash_ms,
0139 .d_compare = isofs_dentry_cmp_ms,
0140 },
0141 {
0142 .d_hash = isofs_hashi_ms,
0143 .d_compare = isofs_dentry_cmpi_ms,
0144 },
0145 #endif
0146 };
0147
0148 struct iso9660_options{
0149 unsigned int rock:1;
0150 unsigned int joliet:1;
0151 unsigned int cruft:1;
0152 unsigned int hide:1;
0153 unsigned int showassoc:1;
0154 unsigned int nocompress:1;
0155 unsigned int overriderockperm:1;
0156 unsigned int uid_set:1;
0157 unsigned int gid_set:1;
0158 unsigned char map;
0159 unsigned char check;
0160 unsigned int blocksize;
0161 umode_t fmode;
0162 umode_t dmode;
0163 kgid_t gid;
0164 kuid_t uid;
0165 char *iocharset;
0166
0167 s32 session;
0168 s32 sbsector;
0169 };
0170
0171
0172
0173
0174 static int
0175 isofs_hashi_common(const struct dentry *dentry, struct qstr *qstr, int ms)
0176 {
0177 const char *name;
0178 int len;
0179 char c;
0180 unsigned long hash;
0181
0182 len = qstr->len;
0183 name = qstr->name;
0184 if (ms) {
0185 while (len && name[len-1] == '.')
0186 len--;
0187 }
0188
0189 hash = init_name_hash(dentry);
0190 while (len--) {
0191 c = tolower(*name++);
0192 hash = partial_name_hash(c, hash);
0193 }
0194 qstr->hash = end_name_hash(hash);
0195
0196 return 0;
0197 }
0198
0199
0200
0201
0202 static int isofs_dentry_cmp_common(
0203 unsigned int len, const char *str,
0204 const struct qstr *name, int ms, int ci)
0205 {
0206 int alen, blen;
0207
0208
0209 alen = name->len;
0210 blen = len;
0211 if (ms) {
0212 while (alen && name->name[alen-1] == '.')
0213 alen--;
0214 while (blen && str[blen-1] == '.')
0215 blen--;
0216 }
0217 if (alen == blen) {
0218 if (ci) {
0219 if (strncasecmp(name->name, str, alen) == 0)
0220 return 0;
0221 } else {
0222 if (strncmp(name->name, str, alen) == 0)
0223 return 0;
0224 }
0225 }
0226 return 1;
0227 }
0228
0229 static int
0230 isofs_hashi(const struct dentry *dentry, struct qstr *qstr)
0231 {
0232 return isofs_hashi_common(dentry, qstr, 0);
0233 }
0234
0235 static int
0236 isofs_dentry_cmpi(const struct dentry *dentry,
0237 unsigned int len, const char *str, const struct qstr *name)
0238 {
0239 return isofs_dentry_cmp_common(len, str, name, 0, 1);
0240 }
0241
0242 #ifdef CONFIG_JOLIET
0243
0244
0245
0246 static int
0247 isofs_hash_common(const struct dentry *dentry, struct qstr *qstr, int ms)
0248 {
0249 const char *name;
0250 int len;
0251
0252 len = qstr->len;
0253 name = qstr->name;
0254 if (ms) {
0255 while (len && name[len-1] == '.')
0256 len--;
0257 }
0258
0259 qstr->hash = full_name_hash(dentry, name, len);
0260
0261 return 0;
0262 }
0263
0264 static int
0265 isofs_hash_ms(const struct dentry *dentry, struct qstr *qstr)
0266 {
0267 return isofs_hash_common(dentry, qstr, 1);
0268 }
0269
0270 static int
0271 isofs_hashi_ms(const struct dentry *dentry, struct qstr *qstr)
0272 {
0273 return isofs_hashi_common(dentry, qstr, 1);
0274 }
0275
0276 static int
0277 isofs_dentry_cmp_ms(const struct dentry *dentry,
0278 unsigned int len, const char *str, const struct qstr *name)
0279 {
0280 return isofs_dentry_cmp_common(len, str, name, 1, 0);
0281 }
0282
0283 static int
0284 isofs_dentry_cmpi_ms(const struct dentry *dentry,
0285 unsigned int len, const char *str, const struct qstr *name)
0286 {
0287 return isofs_dentry_cmp_common(len, str, name, 1, 1);
0288 }
0289 #endif
0290
0291 enum {
0292 Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore,
0293 Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet,
0294 Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err,
0295 Opt_nocompress, Opt_hide, Opt_showassoc, Opt_dmode, Opt_overriderockperm,
0296 };
0297
0298 static const match_table_t tokens = {
0299 {Opt_norock, "norock"},
0300 {Opt_nojoliet, "nojoliet"},
0301 {Opt_unhide, "unhide"},
0302 {Opt_hide, "hide"},
0303 {Opt_showassoc, "showassoc"},
0304 {Opt_cruft, "cruft"},
0305 {Opt_utf8, "utf8"},
0306 {Opt_iocharset, "iocharset=%s"},
0307 {Opt_map_a, "map=acorn"},
0308 {Opt_map_a, "map=a"},
0309 {Opt_map_n, "map=normal"},
0310 {Opt_map_n, "map=n"},
0311 {Opt_map_o, "map=off"},
0312 {Opt_map_o, "map=o"},
0313 {Opt_session, "session=%u"},
0314 {Opt_sb, "sbsector=%u"},
0315 {Opt_check_r, "check=relaxed"},
0316 {Opt_check_r, "check=r"},
0317 {Opt_check_s, "check=strict"},
0318 {Opt_check_s, "check=s"},
0319 {Opt_uid, "uid=%u"},
0320 {Opt_gid, "gid=%u"},
0321 {Opt_mode, "mode=%u"},
0322 {Opt_dmode, "dmode=%u"},
0323 {Opt_overriderockperm, "overriderockperm"},
0324 {Opt_block, "block=%u"},
0325 {Opt_ignore, "conv=binary"},
0326 {Opt_ignore, "conv=b"},
0327 {Opt_ignore, "conv=text"},
0328 {Opt_ignore, "conv=t"},
0329 {Opt_ignore, "conv=mtext"},
0330 {Opt_ignore, "conv=m"},
0331 {Opt_ignore, "conv=auto"},
0332 {Opt_ignore, "conv=a"},
0333 {Opt_nocompress, "nocompress"},
0334 {Opt_err, NULL}
0335 };
0336
0337 static int parse_options(char *options, struct iso9660_options *popt)
0338 {
0339 char *p;
0340 int option;
0341 unsigned int uv;
0342
0343 popt->map = 'n';
0344 popt->rock = 1;
0345 popt->joliet = 1;
0346 popt->cruft = 0;
0347 popt->hide = 0;
0348 popt->showassoc = 0;
0349 popt->check = 'u';
0350 popt->nocompress = 0;
0351 popt->blocksize = 1024;
0352 popt->fmode = popt->dmode = ISOFS_INVALID_MODE;
0353 popt->uid_set = 0;
0354 popt->gid_set = 0;
0355 popt->gid = GLOBAL_ROOT_GID;
0356 popt->uid = GLOBAL_ROOT_UID;
0357 popt->iocharset = NULL;
0358 popt->overriderockperm = 0;
0359 popt->session=-1;
0360 popt->sbsector=-1;
0361 if (!options)
0362 return 1;
0363
0364 while ((p = strsep(&options, ",")) != NULL) {
0365 int token;
0366 substring_t args[MAX_OPT_ARGS];
0367 unsigned n;
0368
0369 if (!*p)
0370 continue;
0371
0372 token = match_token(p, tokens, args);
0373 switch (token) {
0374 case Opt_norock:
0375 popt->rock = 0;
0376 break;
0377 case Opt_nojoliet:
0378 popt->joliet = 0;
0379 break;
0380 case Opt_hide:
0381 popt->hide = 1;
0382 break;
0383 case Opt_unhide:
0384 case Opt_showassoc:
0385 popt->showassoc = 1;
0386 break;
0387 case Opt_cruft:
0388 popt->cruft = 1;
0389 break;
0390 #ifdef CONFIG_JOLIET
0391 case Opt_utf8:
0392 kfree(popt->iocharset);
0393 popt->iocharset = kstrdup("utf8", GFP_KERNEL);
0394 if (!popt->iocharset)
0395 return 0;
0396 break;
0397 case Opt_iocharset:
0398 kfree(popt->iocharset);
0399 popt->iocharset = match_strdup(&args[0]);
0400 if (!popt->iocharset)
0401 return 0;
0402 break;
0403 #endif
0404 case Opt_map_a:
0405 popt->map = 'a';
0406 break;
0407 case Opt_map_o:
0408 popt->map = 'o';
0409 break;
0410 case Opt_map_n:
0411 popt->map = 'n';
0412 break;
0413 case Opt_session:
0414 if (match_int(&args[0], &option))
0415 return 0;
0416 n = option;
0417
0418
0419
0420
0421 if (n >= 99)
0422 return 0;
0423 popt->session = n + 1;
0424 break;
0425 case Opt_sb:
0426 if (match_int(&args[0], &option))
0427 return 0;
0428 popt->sbsector = option;
0429 break;
0430 case Opt_check_r:
0431 popt->check = 'r';
0432 break;
0433 case Opt_check_s:
0434 popt->check = 's';
0435 break;
0436 case Opt_ignore:
0437 break;
0438 case Opt_uid:
0439 if (match_uint(&args[0], &uv))
0440 return 0;
0441 popt->uid = make_kuid(current_user_ns(), uv);
0442 if (!uid_valid(popt->uid))
0443 return 0;
0444 popt->uid_set = 1;
0445 break;
0446 case Opt_gid:
0447 if (match_uint(&args[0], &uv))
0448 return 0;
0449 popt->gid = make_kgid(current_user_ns(), uv);
0450 if (!gid_valid(popt->gid))
0451 return 0;
0452 popt->gid_set = 1;
0453 break;
0454 case Opt_mode:
0455 if (match_int(&args[0], &option))
0456 return 0;
0457 popt->fmode = option;
0458 break;
0459 case Opt_dmode:
0460 if (match_int(&args[0], &option))
0461 return 0;
0462 popt->dmode = option;
0463 break;
0464 case Opt_overriderockperm:
0465 popt->overriderockperm = 1;
0466 break;
0467 case Opt_block:
0468 if (match_int(&args[0], &option))
0469 return 0;
0470 n = option;
0471 if (n != 512 && n != 1024 && n != 2048)
0472 return 0;
0473 popt->blocksize = n;
0474 break;
0475 case Opt_nocompress:
0476 popt->nocompress = 1;
0477 break;
0478 default:
0479 return 0;
0480 }
0481 }
0482 return 1;
0483 }
0484
0485
0486
0487
0488 static int isofs_show_options(struct seq_file *m, struct dentry *root)
0489 {
0490 struct isofs_sb_info *sbi = ISOFS_SB(root->d_sb);
0491
0492 if (!sbi->s_rock) seq_puts(m, ",norock");
0493 else if (!sbi->s_joliet_level) seq_puts(m, ",nojoliet");
0494 if (sbi->s_cruft) seq_puts(m, ",cruft");
0495 if (sbi->s_hide) seq_puts(m, ",hide");
0496 if (sbi->s_nocompress) seq_puts(m, ",nocompress");
0497 if (sbi->s_overriderockperm) seq_puts(m, ",overriderockperm");
0498 if (sbi->s_showassoc) seq_puts(m, ",showassoc");
0499
0500 if (sbi->s_check) seq_printf(m, ",check=%c", sbi->s_check);
0501 if (sbi->s_mapping) seq_printf(m, ",map=%c", sbi->s_mapping);
0502 if (sbi->s_session != 255) seq_printf(m, ",session=%u", sbi->s_session - 1);
0503 if (sbi->s_sbsector != -1) seq_printf(m, ",sbsector=%u", sbi->s_sbsector);
0504
0505 if (root->d_sb->s_blocksize != 1024)
0506 seq_printf(m, ",blocksize=%lu", root->d_sb->s_blocksize);
0507
0508 if (sbi->s_uid_set)
0509 seq_printf(m, ",uid=%u",
0510 from_kuid_munged(&init_user_ns, sbi->s_uid));
0511 if (sbi->s_gid_set)
0512 seq_printf(m, ",gid=%u",
0513 from_kgid_munged(&init_user_ns, sbi->s_gid));
0514
0515 if (sbi->s_dmode != ISOFS_INVALID_MODE)
0516 seq_printf(m, ",dmode=%o", sbi->s_dmode);
0517 if (sbi->s_fmode != ISOFS_INVALID_MODE)
0518 seq_printf(m, ",fmode=%o", sbi->s_fmode);
0519
0520 #ifdef CONFIG_JOLIET
0521 if (sbi->s_nls_iocharset)
0522 seq_printf(m, ",iocharset=%s", sbi->s_nls_iocharset->charset);
0523 else
0524 seq_puts(m, ",iocharset=utf8");
0525 #endif
0526 return 0;
0527 }
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545 #define WE_OBEY_THE_WRITTEN_STANDARDS 1
0546
0547 static unsigned int isofs_get_last_session(struct super_block *sb, s32 session)
0548 {
0549 struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
0550 unsigned int vol_desc_start = 0;
0551
0552 if (session > 0) {
0553 struct cdrom_tocentry te;
0554
0555 if (!cdi)
0556 return 0;
0557
0558 te.cdte_track = session;
0559 te.cdte_format = CDROM_LBA;
0560 if (cdrom_read_tocentry(cdi, &te) == 0) {
0561 printk(KERN_DEBUG "ISOFS: Session %d start %d type %d\n",
0562 session, te.cdte_addr.lba,
0563 te.cdte_ctrl & CDROM_DATA_TRACK);
0564 if ((te.cdte_ctrl & CDROM_DATA_TRACK) == 4)
0565 return te.cdte_addr.lba;
0566 }
0567
0568 printk(KERN_ERR "ISOFS: Invalid session number or type of track\n");
0569 }
0570
0571 if (cdi) {
0572 struct cdrom_multisession ms_info;
0573
0574 ms_info.addr_format = CDROM_LBA;
0575 if (cdrom_multisession(cdi, &ms_info) == 0) {
0576 #if WE_OBEY_THE_WRITTEN_STANDARDS
0577
0578 if (ms_info.xa_flag)
0579 #endif
0580 vol_desc_start = ms_info.addr.lba;
0581 }
0582 }
0583
0584 return vol_desc_start;
0585 }
0586
0587
0588
0589
0590
0591
0592
0593
0594 static bool rootdir_empty(struct super_block *sb, unsigned long block)
0595 {
0596 int offset = 0, files = 0, de_len;
0597 struct iso_directory_record *de;
0598 struct buffer_head *bh;
0599
0600 bh = sb_bread(sb, block);
0601 if (!bh)
0602 return true;
0603 while (files < 3) {
0604 de = (struct iso_directory_record *) (bh->b_data + offset);
0605 de_len = *(unsigned char *) de;
0606 if (de_len == 0)
0607 break;
0608 files++;
0609 offset += de_len;
0610 }
0611 brelse(bh);
0612 return files < 3;
0613 }
0614
0615
0616
0617
0618 static int isofs_fill_super(struct super_block *s, void *data, int silent)
0619 {
0620 struct buffer_head *bh = NULL, *pri_bh = NULL;
0621 struct hs_primary_descriptor *h_pri = NULL;
0622 struct iso_primary_descriptor *pri = NULL;
0623 struct iso_supplementary_descriptor *sec = NULL;
0624 struct iso_directory_record *rootp;
0625 struct inode *inode;
0626 struct iso9660_options opt;
0627 struct isofs_sb_info *sbi;
0628 unsigned long first_data_zone;
0629 int joliet_level = 0;
0630 int iso_blknum, block;
0631 int orig_zonesize;
0632 int table, error = -EINVAL;
0633 unsigned int vol_desc_start;
0634
0635 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
0636 if (!sbi)
0637 return -ENOMEM;
0638 s->s_fs_info = sbi;
0639
0640 if (!parse_options((char *)data, &opt))
0641 goto out_freesbi;
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652 if (bdev_logical_block_size(s->s_bdev) > 2048) {
0653 printk(KERN_WARNING
0654 "ISOFS: unsupported/invalid hardware sector size %d\n",
0655 bdev_logical_block_size(s->s_bdev));
0656 goto out_freesbi;
0657 }
0658 opt.blocksize = sb_min_blocksize(s, opt.blocksize);
0659
0660 sbi->s_high_sierra = 0;
0661 sbi->s_session = opt.session;
0662 sbi->s_sbsector = opt.sbsector;
0663
0664 vol_desc_start = (opt.sbsector != -1) ?
0665 opt.sbsector : isofs_get_last_session(s,opt.session);
0666
0667 for (iso_blknum = vol_desc_start+16;
0668 iso_blknum < vol_desc_start+100; iso_blknum++) {
0669 struct hs_volume_descriptor *hdp;
0670 struct iso_volume_descriptor *vdp;
0671
0672 block = iso_blknum << (ISOFS_BLOCK_BITS - s->s_blocksize_bits);
0673 if (!(bh = sb_bread(s, block)))
0674 goto out_no_read;
0675
0676 vdp = (struct iso_volume_descriptor *)bh->b_data;
0677 hdp = (struct hs_volume_descriptor *)bh->b_data;
0678
0679
0680
0681
0682
0683
0684 if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) {
0685 if (isonum_711(vdp->type) == ISO_VD_END)
0686 break;
0687 if (isonum_711(vdp->type) == ISO_VD_PRIMARY) {
0688 if (!pri) {
0689 pri = (struct iso_primary_descriptor *)vdp;
0690
0691 pri_bh = bh;
0692 bh = NULL;
0693 }
0694 }
0695 #ifdef CONFIG_JOLIET
0696 else if (isonum_711(vdp->type) == ISO_VD_SUPPLEMENTARY) {
0697 sec = (struct iso_supplementary_descriptor *)vdp;
0698 if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) {
0699 if (opt.joliet) {
0700 if (sec->escape[2] == 0x40)
0701 joliet_level = 1;
0702 else if (sec->escape[2] == 0x43)
0703 joliet_level = 2;
0704 else if (sec->escape[2] == 0x45)
0705 joliet_level = 3;
0706
0707 printk(KERN_DEBUG "ISO 9660 Extensions: "
0708 "Microsoft Joliet Level %d\n",
0709 joliet_level);
0710 }
0711 goto root_found;
0712 } else {
0713
0714 sec = NULL;
0715 }
0716 }
0717 #endif
0718 } else {
0719 if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) {
0720 if (isonum_711(hdp->type) != ISO_VD_PRIMARY)
0721 goto out_freebh;
0722
0723 sbi->s_high_sierra = 1;
0724 opt.rock = 0;
0725 h_pri = (struct hs_primary_descriptor *)vdp;
0726 goto root_found;
0727 }
0728 }
0729
0730
0731
0732 brelse(bh);
0733 bh = NULL;
0734 }
0735
0736
0737
0738
0739 if (!pri)
0740 goto out_unknown_format;
0741 brelse(bh);
0742 bh = pri_bh;
0743 pri_bh = NULL;
0744
0745 root_found:
0746
0747 if (!sb_rdonly(s)) {
0748 error = -EACCES;
0749 goto out_freebh;
0750 }
0751
0752 if (joliet_level && (!pri || !opt.rock)) {
0753
0754
0755
0756 pri = (struct iso_primary_descriptor *) sec;
0757 }
0758
0759 if(sbi->s_high_sierra){
0760 rootp = (struct iso_directory_record *) h_pri->root_directory_record;
0761 sbi->s_nzones = isonum_733(h_pri->volume_space_size);
0762 sbi->s_log_zone_size = isonum_723(h_pri->logical_block_size);
0763 sbi->s_max_size = isonum_733(h_pri->volume_space_size);
0764 } else {
0765 if (!pri)
0766 goto out_freebh;
0767 rootp = (struct iso_directory_record *) pri->root_directory_record;
0768 sbi->s_nzones = isonum_733(pri->volume_space_size);
0769 sbi->s_log_zone_size = isonum_723(pri->logical_block_size);
0770 sbi->s_max_size = isonum_733(pri->volume_space_size);
0771 }
0772
0773 sbi->s_ninodes = 0;
0774
0775 orig_zonesize = sbi->s_log_zone_size;
0776
0777
0778
0779
0780
0781
0782
0783 if (orig_zonesize < opt.blocksize)
0784 goto out_bad_size;
0785
0786
0787 switch (sbi->s_log_zone_size) {
0788 case 512: sbi->s_log_zone_size = 9; break;
0789 case 1024: sbi->s_log_zone_size = 10; break;
0790 case 2048: sbi->s_log_zone_size = 11; break;
0791
0792 default:
0793 goto out_bad_zone_size;
0794 }
0795
0796 s->s_magic = ISOFS_SUPER_MAGIC;
0797
0798
0799
0800
0801
0802 s->s_maxbytes = 0x80000000000LL;
0803
0804
0805 s->s_time_min = mktime64(1900, 1, 1, 0, 0, 0) - MAX_TZ_OFFSET;
0806 s->s_time_max = mktime64(U8_MAX+1900, 12, 31, 23, 59, 59) + MAX_TZ_OFFSET;
0807
0808
0809
0810
0811 first_data_zone = isonum_733(rootp->extent) +
0812 isonum_711(rootp->ext_attr_length);
0813 sbi->s_firstdatazone = first_data_zone;
0814 #ifndef BEQUIET
0815 printk(KERN_DEBUG "ISOFS: Max size:%ld Log zone size:%ld\n",
0816 sbi->s_max_size, 1UL << sbi->s_log_zone_size);
0817 printk(KERN_DEBUG "ISOFS: First datazone:%ld\n", sbi->s_firstdatazone);
0818 if(sbi->s_high_sierra)
0819 printk(KERN_DEBUG "ISOFS: Disc in High Sierra format.\n");
0820 #endif
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830 if (joliet_level) {
0831 pri = (struct iso_primary_descriptor *) sec;
0832 rootp = (struct iso_directory_record *)
0833 pri->root_directory_record;
0834 first_data_zone = isonum_733(rootp->extent) +
0835 isonum_711(rootp->ext_attr_length);
0836 }
0837
0838
0839
0840
0841
0842 brelse(pri_bh);
0843 brelse(bh);
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857
0858
0859
0860
0861
0862 sb_set_blocksize(s, orig_zonesize);
0863
0864 sbi->s_nls_iocharset = NULL;
0865
0866 #ifdef CONFIG_JOLIET
0867 if (joliet_level) {
0868 char *p = opt.iocharset ? opt.iocharset : CONFIG_NLS_DEFAULT;
0869 if (strcmp(p, "utf8") != 0) {
0870 sbi->s_nls_iocharset = opt.iocharset ?
0871 load_nls(opt.iocharset) : load_nls_default();
0872 if (!sbi->s_nls_iocharset)
0873 goto out_freesbi;
0874 }
0875 }
0876 #endif
0877 s->s_op = &isofs_sops;
0878 s->s_export_op = &isofs_export_ops;
0879 sbi->s_mapping = opt.map;
0880 sbi->s_rock = (opt.rock ? 2 : 0);
0881 sbi->s_rock_offset = -1;
0882 sbi->s_cruft = opt.cruft;
0883 sbi->s_hide = opt.hide;
0884 sbi->s_showassoc = opt.showassoc;
0885 sbi->s_uid = opt.uid;
0886 sbi->s_gid = opt.gid;
0887 sbi->s_uid_set = opt.uid_set;
0888 sbi->s_gid_set = opt.gid_set;
0889 sbi->s_nocompress = opt.nocompress;
0890 sbi->s_overriderockperm = opt.overriderockperm;
0891
0892
0893
0894
0895
0896 if (opt.fmode != ISOFS_INVALID_MODE)
0897 sbi->s_fmode = opt.fmode & 0777;
0898 else
0899 sbi->s_fmode = ISOFS_INVALID_MODE;
0900 if (opt.dmode != ISOFS_INVALID_MODE)
0901 sbi->s_dmode = opt.dmode & 0777;
0902 else
0903 sbi->s_dmode = ISOFS_INVALID_MODE;
0904
0905
0906
0907
0908
0909
0910 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
0911 if (IS_ERR(inode))
0912 goto out_no_root;
0913
0914
0915
0916
0917
0918 if (sbi->s_rock == 1 && joliet_level &&
0919 rootdir_empty(s, sbi->s_firstdatazone)) {
0920 printk(KERN_NOTICE
0921 "ISOFS: primary root directory is empty. "
0922 "Disabling Rock Ridge and switching to Joliet.");
0923 sbi->s_rock = 0;
0924 }
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934 if (sbi->s_rock == 1) {
0935 joliet_level = 0;
0936 } else if (joliet_level) {
0937 sbi->s_rock = 0;
0938 if (sbi->s_firstdatazone != first_data_zone) {
0939 sbi->s_firstdatazone = first_data_zone;
0940 printk(KERN_DEBUG
0941 "ISOFS: changing to secondary root\n");
0942 iput(inode);
0943 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
0944 if (IS_ERR(inode))
0945 goto out_no_root;
0946 }
0947 }
0948
0949 if (opt.check == 'u') {
0950
0951 if (joliet_level)
0952 opt.check = 'r';
0953 else
0954 opt.check = 's';
0955 }
0956 sbi->s_joliet_level = joliet_level;
0957
0958
0959 if (!S_ISDIR(inode->i_mode)) {
0960 printk(KERN_WARNING
0961 "isofs_fill_super: root inode is not a directory. "
0962 "Corrupted media?\n");
0963 goto out_iput;
0964 }
0965
0966 table = 0;
0967 if (joliet_level)
0968 table += 2;
0969 if (opt.check == 'r')
0970 table++;
0971 sbi->s_check = opt.check;
0972
0973 if (table)
0974 s->s_d_op = &isofs_dentry_ops[table - 1];
0975
0976
0977 s->s_root = d_make_root(inode);
0978 if (!(s->s_root)) {
0979 error = -ENOMEM;
0980 goto out_no_inode;
0981 }
0982
0983 kfree(opt.iocharset);
0984
0985 return 0;
0986
0987
0988
0989
0990 out_iput:
0991 iput(inode);
0992 goto out_no_inode;
0993 out_no_root:
0994 error = PTR_ERR(inode);
0995 if (error != -ENOMEM)
0996 printk(KERN_WARNING "%s: get root inode failed\n", __func__);
0997 out_no_inode:
0998 #ifdef CONFIG_JOLIET
0999 unload_nls(sbi->s_nls_iocharset);
1000 #endif
1001 goto out_freesbi;
1002 out_no_read:
1003 printk(KERN_WARNING "%s: bread failed, dev=%s, iso_blknum=%d, block=%d\n",
1004 __func__, s->s_id, iso_blknum, block);
1005 goto out_freebh;
1006 out_bad_zone_size:
1007 printk(KERN_WARNING "ISOFS: Bad logical zone size %ld\n",
1008 sbi->s_log_zone_size);
1009 goto out_freebh;
1010 out_bad_size:
1011 printk(KERN_WARNING "ISOFS: Logical zone size(%d) < hardware blocksize(%u)\n",
1012 orig_zonesize, opt.blocksize);
1013 goto out_freebh;
1014 out_unknown_format:
1015 if (!silent)
1016 printk(KERN_WARNING "ISOFS: Unable to identify CD-ROM format.\n");
1017
1018 out_freebh:
1019 brelse(bh);
1020 brelse(pri_bh);
1021 out_freesbi:
1022 kfree(opt.iocharset);
1023 kfree(sbi);
1024 s->s_fs_info = NULL;
1025 return error;
1026 }
1027
1028 static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
1029 {
1030 struct super_block *sb = dentry->d_sb;
1031 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
1032
1033 buf->f_type = ISOFS_SUPER_MAGIC;
1034 buf->f_bsize = sb->s_blocksize;
1035 buf->f_blocks = (ISOFS_SB(sb)->s_nzones
1036 << (ISOFS_SB(sb)->s_log_zone_size - sb->s_blocksize_bits));
1037 buf->f_bfree = 0;
1038 buf->f_bavail = 0;
1039 buf->f_files = ISOFS_SB(sb)->s_ninodes;
1040 buf->f_ffree = 0;
1041 buf->f_fsid = u64_to_fsid(id);
1042 buf->f_namelen = NAME_MAX;
1043 return 0;
1044 }
1045
1046
1047
1048
1049
1050
1051 int isofs_get_blocks(struct inode *inode, sector_t iblock,
1052 struct buffer_head **bh, unsigned long nblocks)
1053 {
1054 unsigned long b_off = iblock;
1055 unsigned offset, sect_size;
1056 unsigned int firstext;
1057 unsigned long nextblk, nextoff;
1058 int section, rv, error;
1059 struct iso_inode_info *ei = ISOFS_I(inode);
1060
1061 error = -EIO;
1062 rv = 0;
1063 if (iblock != b_off) {
1064 printk(KERN_DEBUG "%s: block number too large\n", __func__);
1065 goto abort;
1066 }
1067
1068
1069 offset = 0;
1070 firstext = ei->i_first_extent;
1071 sect_size = ei->i_section_size >> ISOFS_BUFFER_BITS(inode);
1072 nextblk = ei->i_next_section_block;
1073 nextoff = ei->i_next_section_offset;
1074 section = 0;
1075
1076 while (nblocks) {
1077
1078
1079
1080
1081
1082
1083
1084 if (b_off > ((inode->i_size + PAGE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) {
1085 printk(KERN_DEBUG "%s: block >= EOF (%lu, %llu)\n",
1086 __func__, b_off,
1087 (unsigned long long)inode->i_size);
1088 goto abort;
1089 }
1090
1091
1092
1093
1094
1095 while (nextblk && (b_off >= (offset + sect_size))) {
1096 struct inode *ninode;
1097
1098 offset += sect_size;
1099 ninode = isofs_iget(inode->i_sb, nextblk, nextoff);
1100 if (IS_ERR(ninode)) {
1101 error = PTR_ERR(ninode);
1102 goto abort;
1103 }
1104 firstext = ISOFS_I(ninode)->i_first_extent;
1105 sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode);
1106 nextblk = ISOFS_I(ninode)->i_next_section_block;
1107 nextoff = ISOFS_I(ninode)->i_next_section_offset;
1108 iput(ninode);
1109
1110 if (++section > 100) {
1111 printk(KERN_DEBUG "%s: More than 100 file sections ?!?"
1112 " aborting...\n", __func__);
1113 printk(KERN_DEBUG "%s: block=%lu firstext=%u sect_size=%u "
1114 "nextblk=%lu nextoff=%lu\n", __func__,
1115 b_off, firstext, (unsigned) sect_size,
1116 nextblk, nextoff);
1117 goto abort;
1118 }
1119 }
1120
1121 if (*bh) {
1122 map_bh(*bh, inode->i_sb, firstext + b_off - offset);
1123 } else {
1124 *bh = sb_getblk(inode->i_sb, firstext+b_off-offset);
1125 if (!*bh)
1126 goto abort;
1127 }
1128 bh++;
1129 b_off++;
1130 nblocks--;
1131 rv++;
1132 }
1133
1134 error = 0;
1135 abort:
1136 return rv != 0 ? rv : error;
1137 }
1138
1139
1140
1141
1142 static int isofs_get_block(struct inode *inode, sector_t iblock,
1143 struct buffer_head *bh_result, int create)
1144 {
1145 int ret;
1146
1147 if (create) {
1148 printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__);
1149 return -EROFS;
1150 }
1151
1152 ret = isofs_get_blocks(inode, iblock, &bh_result, 1);
1153 return ret < 0 ? ret : 0;
1154 }
1155
1156 static int isofs_bmap(struct inode *inode, sector_t block)
1157 {
1158 struct buffer_head dummy;
1159 int error;
1160
1161 dummy.b_state = 0;
1162 dummy.b_blocknr = -1000;
1163 error = isofs_get_block(inode, block, &dummy, 0);
1164 if (!error)
1165 return dummy.b_blocknr;
1166 return 0;
1167 }
1168
1169 struct buffer_head *isofs_bread(struct inode *inode, sector_t block)
1170 {
1171 sector_t blknr = isofs_bmap(inode, block);
1172 if (!blknr)
1173 return NULL;
1174 return sb_bread(inode->i_sb, blknr);
1175 }
1176
1177 static int isofs_read_folio(struct file *file, struct folio *folio)
1178 {
1179 return mpage_read_folio(folio, isofs_get_block);
1180 }
1181
1182 static void isofs_readahead(struct readahead_control *rac)
1183 {
1184 mpage_readahead(rac, isofs_get_block);
1185 }
1186
1187 static sector_t _isofs_bmap(struct address_space *mapping, sector_t block)
1188 {
1189 return generic_block_bmap(mapping,block,isofs_get_block);
1190 }
1191
1192 static const struct address_space_operations isofs_aops = {
1193 .read_folio = isofs_read_folio,
1194 .readahead = isofs_readahead,
1195 .bmap = _isofs_bmap
1196 };
1197
1198 static int isofs_read_level3_size(struct inode *inode)
1199 {
1200 unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
1201 int high_sierra = ISOFS_SB(inode->i_sb)->s_high_sierra;
1202 struct buffer_head *bh = NULL;
1203 unsigned long block, offset, block_saved, offset_saved;
1204 int i = 0;
1205 int more_entries = 0;
1206 struct iso_directory_record *tmpde = NULL;
1207 struct iso_inode_info *ei = ISOFS_I(inode);
1208
1209 inode->i_size = 0;
1210
1211
1212
1213
1214 ei->i_next_section_block = 0;
1215 ei->i_next_section_offset = 0;
1216
1217 block = ei->i_iget5_block;
1218 offset = ei->i_iget5_offset;
1219
1220 do {
1221 struct iso_directory_record *de;
1222 unsigned int de_len;
1223
1224 if (!bh) {
1225 bh = sb_bread(inode->i_sb, block);
1226 if (!bh)
1227 goto out_noread;
1228 }
1229 de = (struct iso_directory_record *) (bh->b_data + offset);
1230 de_len = *(unsigned char *) de;
1231
1232 if (de_len == 0) {
1233 brelse(bh);
1234 bh = NULL;
1235 ++block;
1236 offset = 0;
1237 continue;
1238 }
1239
1240 block_saved = block;
1241 offset_saved = offset;
1242 offset += de_len;
1243
1244
1245 if (offset >= bufsize) {
1246 int slop = bufsize - offset + de_len;
1247 if (!tmpde) {
1248 tmpde = kmalloc(256, GFP_KERNEL);
1249 if (!tmpde)
1250 goto out_nomem;
1251 }
1252 memcpy(tmpde, de, slop);
1253 offset &= bufsize - 1;
1254 block++;
1255 brelse(bh);
1256 bh = NULL;
1257 if (offset) {
1258 bh = sb_bread(inode->i_sb, block);
1259 if (!bh)
1260 goto out_noread;
1261 memcpy((void *)tmpde+slop, bh->b_data, offset);
1262 }
1263 de = tmpde;
1264 }
1265
1266 inode->i_size += isonum_733(de->size);
1267 if (i == 1) {
1268 ei->i_next_section_block = block_saved;
1269 ei->i_next_section_offset = offset_saved;
1270 }
1271
1272 more_entries = de->flags[-high_sierra] & 0x80;
1273
1274 i++;
1275 if (i > 100)
1276 goto out_toomany;
1277 } while (more_entries);
1278 out:
1279 kfree(tmpde);
1280 if (bh)
1281 brelse(bh);
1282 return 0;
1283
1284 out_nomem:
1285 if (bh)
1286 brelse(bh);
1287 return -ENOMEM;
1288
1289 out_noread:
1290 printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block);
1291 kfree(tmpde);
1292 return -EIO;
1293
1294 out_toomany:
1295 printk(KERN_INFO "%s: More than 100 file sections ?!?, aborting...\n"
1296 "isofs_read_level3_size: inode=%lu\n",
1297 __func__, inode->i_ino);
1298 goto out;
1299 }
1300
1301 static int isofs_read_inode(struct inode *inode, int relocated)
1302 {
1303 struct super_block *sb = inode->i_sb;
1304 struct isofs_sb_info *sbi = ISOFS_SB(sb);
1305 unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
1306 unsigned long block;
1307 int high_sierra = sbi->s_high_sierra;
1308 struct buffer_head *bh;
1309 struct iso_directory_record *de;
1310 struct iso_directory_record *tmpde = NULL;
1311 unsigned int de_len;
1312 unsigned long offset;
1313 struct iso_inode_info *ei = ISOFS_I(inode);
1314 int ret = -EIO;
1315
1316 block = ei->i_iget5_block;
1317 bh = sb_bread(inode->i_sb, block);
1318 if (!bh)
1319 goto out_badread;
1320
1321 offset = ei->i_iget5_offset;
1322
1323 de = (struct iso_directory_record *) (bh->b_data + offset);
1324 de_len = *(unsigned char *) de;
1325 if (de_len < sizeof(struct iso_directory_record))
1326 goto fail;
1327
1328 if (offset + de_len > bufsize) {
1329 int frag1 = bufsize - offset;
1330
1331 tmpde = kmalloc(de_len, GFP_KERNEL);
1332 if (!tmpde) {
1333 ret = -ENOMEM;
1334 goto fail;
1335 }
1336 memcpy(tmpde, bh->b_data + offset, frag1);
1337 brelse(bh);
1338 bh = sb_bread(inode->i_sb, ++block);
1339 if (!bh)
1340 goto out_badread;
1341 memcpy((char *)tmpde+frag1, bh->b_data, de_len - frag1);
1342 de = tmpde;
1343 }
1344
1345 inode->i_ino = isofs_get_ino(ei->i_iget5_block,
1346 ei->i_iget5_offset,
1347 ISOFS_BUFFER_BITS(inode));
1348
1349
1350 ei->i_file_format = isofs_file_normal;
1351
1352 if (de->flags[-high_sierra] & 2) {
1353 if (sbi->s_dmode != ISOFS_INVALID_MODE)
1354 inode->i_mode = S_IFDIR | sbi->s_dmode;
1355 else
1356 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
1357 set_nlink(inode, 1);
1358
1359
1360
1361
1362
1363
1364 } else {
1365 if (sbi->s_fmode != ISOFS_INVALID_MODE) {
1366 inode->i_mode = S_IFREG | sbi->s_fmode;
1367 } else {
1368
1369
1370
1371
1372
1373 inode->i_mode = S_IFREG | S_IRUGO | S_IXUGO;
1374 }
1375 set_nlink(inode, 1);
1376 }
1377 inode->i_uid = sbi->s_uid;
1378 inode->i_gid = sbi->s_gid;
1379 inode->i_blocks = 0;
1380
1381 ei->i_format_parm[0] = 0;
1382 ei->i_format_parm[1] = 0;
1383 ei->i_format_parm[2] = 0;
1384
1385 ei->i_section_size = isonum_733(de->size);
1386 if (de->flags[-high_sierra] & 0x80) {
1387 ret = isofs_read_level3_size(inode);
1388 if (ret < 0)
1389 goto fail;
1390 ret = -EIO;
1391 } else {
1392 ei->i_next_section_block = 0;
1393 ei->i_next_section_offset = 0;
1394 inode->i_size = isonum_733(de->size);
1395 }
1396
1397
1398
1399
1400
1401
1402
1403 if (sbi->s_cruft)
1404 inode->i_size &= 0x00ffffff;
1405
1406 if (de->interleave[0]) {
1407 printk(KERN_DEBUG "ISOFS: Interleaved files not (yet) supported.\n");
1408 inode->i_size = 0;
1409 }
1410
1411
1412
1413 if (de->file_unit_size[0] != 0) {
1414 printk(KERN_DEBUG "ISOFS: File unit size != 0 for ISO file (%ld).\n",
1415 inode->i_ino);
1416 }
1417
1418
1419
1420 #ifdef DEBUG
1421 if((de->flags[-high_sierra] & ~2)!= 0){
1422 printk(KERN_DEBUG "ISOFS: Unusual flag settings for ISO file "
1423 "(%ld %x).\n",
1424 inode->i_ino, de->flags[-high_sierra]);
1425 }
1426 #endif
1427
1428 inode->i_mtime.tv_sec =
1429 inode->i_atime.tv_sec =
1430 inode->i_ctime.tv_sec = iso_date(de->date, high_sierra);
1431 inode->i_mtime.tv_nsec =
1432 inode->i_atime.tv_nsec =
1433 inode->i_ctime.tv_nsec = 0;
1434
1435 ei->i_first_extent = (isonum_733(de->extent) +
1436 isonum_711(de->ext_attr_length));
1437
1438
1439 inode->i_blocks = (inode->i_size + 511) >> 9;
1440
1441
1442
1443
1444
1445
1446 if (!high_sierra) {
1447 parse_rock_ridge_inode(de, inode, relocated);
1448
1449 if (sbi->s_uid_set)
1450 inode->i_uid = sbi->s_uid;
1451 if (sbi->s_gid_set)
1452 inode->i_gid = sbi->s_gid;
1453 }
1454
1455 if (S_ISDIR(inode->i_mode) && sbi->s_overriderockperm &&
1456 sbi->s_dmode != ISOFS_INVALID_MODE)
1457 inode->i_mode = S_IFDIR | sbi->s_dmode;
1458 if (S_ISREG(inode->i_mode) && sbi->s_overriderockperm &&
1459 sbi->s_fmode != ISOFS_INVALID_MODE)
1460 inode->i_mode = S_IFREG | sbi->s_fmode;
1461
1462
1463 if (S_ISREG(inode->i_mode)) {
1464 inode->i_fop = &generic_ro_fops;
1465 switch (ei->i_file_format) {
1466 #ifdef CONFIG_ZISOFS
1467 case isofs_file_compressed:
1468 inode->i_data.a_ops = &zisofs_aops;
1469 break;
1470 #endif
1471 default:
1472 inode->i_data.a_ops = &isofs_aops;
1473 break;
1474 }
1475 } else if (S_ISDIR(inode->i_mode)) {
1476 inode->i_op = &isofs_dir_inode_operations;
1477 inode->i_fop = &isofs_dir_operations;
1478 } else if (S_ISLNK(inode->i_mode)) {
1479 inode->i_op = &page_symlink_inode_operations;
1480 inode_nohighmem(inode);
1481 inode->i_data.a_ops = &isofs_symlink_aops;
1482 } else
1483
1484 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1485
1486 ret = 0;
1487 out:
1488 kfree(tmpde);
1489 if (bh)
1490 brelse(bh);
1491 return ret;
1492
1493 out_badread:
1494 printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
1495 fail:
1496 goto out;
1497 }
1498
1499 struct isofs_iget5_callback_data {
1500 unsigned long block;
1501 unsigned long offset;
1502 };
1503
1504 static int isofs_iget5_test(struct inode *ino, void *data)
1505 {
1506 struct iso_inode_info *i = ISOFS_I(ino);
1507 struct isofs_iget5_callback_data *d =
1508 (struct isofs_iget5_callback_data*)data;
1509 return (i->i_iget5_block == d->block)
1510 && (i->i_iget5_offset == d->offset);
1511 }
1512
1513 static int isofs_iget5_set(struct inode *ino, void *data)
1514 {
1515 struct iso_inode_info *i = ISOFS_I(ino);
1516 struct isofs_iget5_callback_data *d =
1517 (struct isofs_iget5_callback_data*)data;
1518 i->i_iget5_block = d->block;
1519 i->i_iget5_offset = d->offset;
1520 return 0;
1521 }
1522
1523
1524
1525
1526
1527 struct inode *__isofs_iget(struct super_block *sb,
1528 unsigned long block,
1529 unsigned long offset,
1530 int relocated)
1531 {
1532 unsigned long hashval;
1533 struct inode *inode;
1534 struct isofs_iget5_callback_data data;
1535 long ret;
1536
1537 if (offset >= 1ul << sb->s_blocksize_bits)
1538 return ERR_PTR(-EINVAL);
1539
1540 data.block = block;
1541 data.offset = offset;
1542
1543 hashval = (block << sb->s_blocksize_bits) | offset;
1544
1545 inode = iget5_locked(sb, hashval, &isofs_iget5_test,
1546 &isofs_iget5_set, &data);
1547
1548 if (!inode)
1549 return ERR_PTR(-ENOMEM);
1550
1551 if (inode->i_state & I_NEW) {
1552 ret = isofs_read_inode(inode, relocated);
1553 if (ret < 0) {
1554 iget_failed(inode);
1555 inode = ERR_PTR(ret);
1556 } else {
1557 unlock_new_inode(inode);
1558 }
1559 }
1560
1561 return inode;
1562 }
1563
1564 static struct dentry *isofs_mount(struct file_system_type *fs_type,
1565 int flags, const char *dev_name, void *data)
1566 {
1567 return mount_bdev(fs_type, flags, dev_name, data, isofs_fill_super);
1568 }
1569
1570 static struct file_system_type iso9660_fs_type = {
1571 .owner = THIS_MODULE,
1572 .name = "iso9660",
1573 .mount = isofs_mount,
1574 .kill_sb = kill_block_super,
1575 .fs_flags = FS_REQUIRES_DEV,
1576 };
1577 MODULE_ALIAS_FS("iso9660");
1578 MODULE_ALIAS("iso9660");
1579
1580 static int __init init_iso9660_fs(void)
1581 {
1582 int err = init_inodecache();
1583 if (err)
1584 goto out;
1585 #ifdef CONFIG_ZISOFS
1586 err = zisofs_init();
1587 if (err)
1588 goto out1;
1589 #endif
1590 err = register_filesystem(&iso9660_fs_type);
1591 if (err)
1592 goto out2;
1593 return 0;
1594 out2:
1595 #ifdef CONFIG_ZISOFS
1596 zisofs_cleanup();
1597 out1:
1598 #endif
1599 destroy_inodecache();
1600 out:
1601 return err;
1602 }
1603
1604 static void __exit exit_iso9660_fs(void)
1605 {
1606 unregister_filesystem(&iso9660_fs_type);
1607 #ifdef CONFIG_ZISOFS
1608 zisofs_cleanup();
1609 #endif
1610 destroy_inodecache();
1611 }
1612
1613 module_init(init_iso9660_fs)
1614 module_exit(exit_iso9660_fs)
1615 MODULE_LICENSE("GPL");