15 #include <linux/module.h>
17 #include <linux/slab.h>
19 #include <linux/ctype.h>
21 #include <linux/cdrom.h>
31 static int isofs_hashi(
const struct dentry *parent,
const struct inode *
inode,
33 static int isofs_hash(
const struct dentry *parent,
const struct inode *
inode,
35 static int isofs_dentry_cmpi(
const struct dentry *parent,
36 const struct inode *pinode,
38 unsigned int len,
const char *
str,
const struct qstr *
name);
39 static int isofs_dentry_cmp(
const struct dentry *parent,
40 const struct inode *pinode,
42 unsigned int len,
const char *
str,
const struct qstr *
name);
45 static int isofs_hashi_ms(
const struct dentry *parent,
const struct inode *
inode,
47 static int isofs_hash_ms(
const struct dentry *parent,
const struct inode *
inode,
49 static int isofs_dentry_cmpi_ms(
const struct dentry *parent,
50 const struct inode *pinode,
52 unsigned int len,
const char *
str,
const struct qstr *
name);
53 static int isofs_dentry_cmp_ms(
const struct dentry *parent,
54 const struct inode *pinode,
56 unsigned int len,
const char *
str,
const struct qstr *
name);
72 static int isofs_read_inode(
struct inode *);
92 static void isofs_destroy_inode(
struct inode *inode)
97 static void init_once(
void *
foo)
104 static int init_inodecache(
void)
111 if (isofs_inode_cachep ==
NULL)
116 static void destroy_inodecache(
void)
134 .alloc_inode = isofs_alloc_inode,
135 .destroy_inode = isofs_destroy_inode,
136 .put_super = isofs_put_super,
137 .statfs = isofs_statfs,
138 .remount_fs = isofs_remount,
145 .d_hash = isofs_hash,
146 .d_compare = isofs_dentry_cmp,
149 .d_hash = isofs_hashi,
150 .d_compare = isofs_dentry_cmpi,
154 .d_hash = isofs_hash_ms,
155 .d_compare = isofs_dentry_cmp_ms,
158 .d_hash = isofs_hashi_ms,
159 .d_compare = isofs_dentry_cmpi_ms,
200 while (len && name[len-1] ==
'.')
223 while (len && name[len-1] ==
'.')
230 hash = partial_name_hash(c, hash);
232 qstr->hash = end_name_hash(hash);
240 static int isofs_dentry_cmp_common(
241 unsigned int len,
const char *
str,
242 const struct qstr *name,
int ms,
int ci)
250 while (alen && name->
name[alen-1] ==
'.')
252 while (blen && str[blen-1] ==
'.')
268 isofs_hash(
const struct dentry *dentry,
const struct inode *inode,
271 return isofs_hash_common(dentry, qstr, 0);
275 isofs_hashi(
const struct dentry *dentry,
const struct inode *inode,
278 return isofs_hashi_common(dentry, qstr, 0);
282 isofs_dentry_cmp(
const struct dentry *parent,
const struct inode *pinode,
283 const struct dentry *dentry,
const struct inode *inode,
284 unsigned int len,
const char *str,
const struct qstr *name)
286 return isofs_dentry_cmp_common(len, str, name, 0, 0);
290 isofs_dentry_cmpi(
const struct dentry *parent,
const struct inode *pinode,
291 const struct dentry *dentry,
const struct inode *inode,
292 unsigned int len,
const char *str,
const struct qstr *name)
294 return isofs_dentry_cmp_common(len, str, name, 0, 1);
299 isofs_hash_ms(
const struct dentry *dentry,
const struct inode *inode,
302 return isofs_hash_common(dentry, qstr, 1);
306 isofs_hashi_ms(
const struct dentry *dentry,
const struct inode *inode,
309 return isofs_hashi_common(dentry, qstr, 1);
313 isofs_dentry_cmp_ms(
const struct dentry *parent,
const struct inode *pinode,
314 const struct dentry *dentry,
const struct inode *inode,
315 unsigned int len,
const char *str,
const struct qstr *name)
317 return isofs_dentry_cmp_common(len, str, name, 1, 0);
321 isofs_dentry_cmpi_ms(
const struct dentry *parent,
const struct inode *pinode,
322 const struct dentry *dentry,
const struct inode *inode,
323 unsigned int len,
const char *str,
const struct qstr *name)
325 return isofs_dentry_cmp_common(len, str, name, 1, 1);
470 if (!uid_valid(popt->
uid))
478 if (!gid_valid(popt->
gid))
499 if (n != 512 && n != 1024 && n != 2048)
529 #define WE_OBEY_THE_WRITTEN_STANDARDS 1
531 static unsigned int isofs_get_last_session(
struct super_block *sb,
s32 session)
534 unsigned int vol_desc_start;
540 if(session >= 0 && session <= 99) {
547 session, Te.cdte_addr.lba,
550 return Te.cdte_addr.lba;
553 printk(
KERN_ERR "ISOFS: Invalid session number or type of track\n");
566 #if WE_OBEY_THE_WRITTEN_STANDARDS
569 vol_desc_start=ms_info.addr.lba;
570 return vol_desc_start;
584 struct buffer_head *bh;
586 bh = sb_bread(sb, block);
591 de_len = *(
unsigned char *) de;
609 struct buffer_head *bh =
NULL, *pri_bh =
NULL;
617 unsigned long first_data_zone;
618 int joliet_level = 0;
619 int iso_blknum,
block;
622 unsigned int vol_desc_start;
631 if (!parse_options((
char *)data, &
opt))
647 vol_desc_start = (
opt.sbsector != -1) ?
648 opt.sbsector : isofs_get_last_session(s,
opt.session);
650 for (iso_blknum = vol_desc_start+16;
651 iso_blknum < vol_desc_start+100; iso_blknum++) {
656 if (!(bh = sb_bread(s, block)))
683 if (sec->
escape[2] == 0x40)
685 else if (sec->
escape[2] == 0x43)
687 else if (sec->
escape[2] == 0x45)
691 "Microsoft Joliet Level %d\n",
723 goto out_unknown_format;
730 if (joliet_level && (pri ==
NULL || !
opt.rock)) {
761 if (orig_zonesize <
opt.blocksize)
771 goto out_bad_zone_size;
794 first_data_zone = isonum_733(rootp->
extent) +
817 first_data_zone = isonum_733(rootp->
extent) +
850 if (joliet_level &&
opt.utf8 == 0) {
851 char *p =
opt.iocharset ?
opt.iocharset : CONFIG_NLS_DEFAULT;
861 s->
s_op = &isofs_sops;
903 if (sbi->
s_rock == 1 && joliet_level &&
906 "ISOFS: primary root directory is empty. "
907 "Disabling Rock Ridge and switching to Joliet.");
921 }
else if (joliet_level) {
926 "ISOFS: changing to secondary root\n");
934 if (
opt.check ==
'u') {
946 "isofs_fill_super: root inode is not a directory. "
947 "Corrupted media?\n");
954 if (
opt.check ==
'r')
977 error = PTR_ERR(inode);
987 __func__, s->
s_id, iso_blknum, block);
995 orig_zonesize,
opt.blocksize);
1011 static int isofs_statfs (
struct dentry *dentry,
struct kstatfs *
buf)
1014 u64 id = huge_encode_dev(sb->
s_bdev->bd_dev);
1018 buf->
f_blocks = (ISOFS_SB(sb)->s_nzones
1022 buf->
f_files = ISOFS_SB(sb)->s_ninodes;
1036 struct buffer_head **bh,
unsigned long nblocks)
1038 unsigned long b_off = iblock;
1039 unsigned offset, sect_size;
1040 unsigned int firstext;
1041 unsigned long nextblk, nextoff;
1047 if (iblock != b_off) {
1071 (
unsigned long long)inode->
i_size);
1079 while (nextblk && (b_off >= (offset + sect_size))) {
1080 struct inode *ninode;
1082 offset += sect_size;
1084 if (IS_ERR(ninode)) {
1085 error = PTR_ERR(ninode);
1088 firstext = ISOFS_I(ninode)->i_first_extent;
1090 nextblk = ISOFS_I(ninode)->i_next_section_block;
1091 nextoff = ISOFS_I(ninode)->i_next_section_offset;
1094 if (++section > 100) {
1096 " aborting...\n", __func__);
1098 "nextblk=%lu nextoff=%lu\n", __func__,
1099 b_off, firstext, (
unsigned) sect_size,
1106 map_bh(*bh, inode->
i_sb, firstext + b_off - offset);
1108 *bh = sb_getblk(inode->
i_sb, firstext+b_off-offset);
1120 return rv != 0 ? rv :
error;
1126 static int isofs_get_block(
struct inode *inode,
sector_t iblock,
1127 struct buffer_head *bh_result,
int create)
1137 return ret < 0 ? ret : 0;
1140 static int isofs_bmap(
struct inode *inode,
sector_t block)
1142 struct buffer_head
dummy;
1146 dummy.b_blocknr = -1000;
1147 error = isofs_get_block(inode, block, &
dummy, 0);
1149 return dummy.b_blocknr;
1155 sector_t blknr = isofs_bmap(inode, block);
1158 return sb_bread(inode->
i_sb, blknr);
1178 .readpage = isofs_readpage,
1179 .readpages = isofs_readpages,
1183 static int isofs_read_level3_size(
struct inode *inode)
1186 int high_sierra = ISOFS_SB(inode->
i_sb)->s_high_sierra;
1187 struct buffer_head *bh =
NULL;
1188 unsigned long block,
offset, block_saved, offset_saved;
1190 int more_entries = 0;
1207 unsigned int de_len;
1210 bh = sb_bread(inode->
i_sb, block);
1215 de_len = *(
unsigned char *) de;
1225 block_saved =
block;
1230 if (offset >= bufsize) {
1231 int slop = bufsize - offset + de_len;
1238 offset &= bufsize - 1;
1243 bh = sb_bread(inode->
i_sb, block);
1246 memcpy((
void *)tmpde+slop, bh->b_data, offset);
1257 more_entries = de->
flags[-high_sierra] & 0x80;
1262 }
while (more_entries);
1281 "isofs_read_level3_size: inode=%lu\n",
1282 __func__, inode->
i_ino);
1286 static int isofs_read_inode(
struct inode *inode)
1291 unsigned long block;
1293 struct buffer_head *bh =
NULL;
1296 unsigned int de_len;
1302 bh = sb_bread(inode->
i_sb, block);
1309 de_len = *(
unsigned char *) de;
1311 if (offset + de_len > bufsize) {
1312 int frag1 = bufsize -
offset;
1315 if (tmpde ==
NULL) {
1320 memcpy(tmpde, bh->b_data + offset, frag1);
1322 bh = sb_bread(inode->
i_sb, ++block);
1325 memcpy((
char *)tmpde+frag1, bh->b_data, de_len - frag1);
1336 if (de->
flags[-high_sierra] & 2) {
1370 if (de->
flags[-high_sierra] & 0x80) {
1371 ret = isofs_read_level3_size(inode);
1388 inode->
i_size &= 0x00ffffff;
1405 if((de->
flags[-high_sierra] & ~2)!= 0){
1450 #ifdef CONFIG_ZISOFS
1456 inode->
i_data.a_ops = &isofs_aops;
1487 static int isofs_iget5_test(
struct inode *
ino,
void *data)
1496 static int isofs_iget5_set(
struct inode *
ino,
void *data)
1511 unsigned long block,
1512 unsigned long offset)
1514 unsigned long hashval;
1515 struct inode *
inode;
1528 &isofs_iget5_set, &data);
1534 ret = isofs_read_inode(inode);
1537 inode = ERR_PTR(ret);
1547 int flags,
const char *dev_name,
void *data)
1549 return mount_bdev(fs_type, flags, dev_name, data, isofs_fill_super);
1555 .mount = isofs_mount,
1560 static int __init init_iso9660_fs(
void)
1562 int err = init_inodecache();
1565 #ifdef CONFIG_ZISOFS
1575 #ifdef CONFIG_ZISOFS
1579 destroy_inodecache();
1584 static void __exit exit_iso9660_fs(
void)
1587 #ifdef CONFIG_ZISOFS
1590 destroy_inodecache();