aboutsummaryrefslogtreecommitdiffstats
path: root/fs/isofs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/isofs/inode.c')
-rw-r--r--fs/isofs/inode.c94
1 files changed, 64 insertions, 30 deletions
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 09e3d306e96f..044a254d526b 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -54,7 +54,7 @@ static void isofs_put_super(struct super_block *sb)
54 return; 54 return;
55} 55}
56 56
57static void isofs_read_inode(struct inode *); 57static int isofs_read_inode(struct inode *);
58static int isofs_statfs (struct dentry *, struct kstatfs *); 58static int isofs_statfs (struct dentry *, struct kstatfs *);
59 59
60static struct kmem_cache *isofs_inode_cachep; 60static struct kmem_cache *isofs_inode_cachep;
@@ -107,10 +107,10 @@ static int isofs_remount(struct super_block *sb, int *flags, char *data)
107static const struct super_operations isofs_sops = { 107static const struct super_operations isofs_sops = {
108 .alloc_inode = isofs_alloc_inode, 108 .alloc_inode = isofs_alloc_inode,
109 .destroy_inode = isofs_destroy_inode, 109 .destroy_inode = isofs_destroy_inode,
110 .read_inode = isofs_read_inode,
111 .put_super = isofs_put_super, 110 .put_super = isofs_put_super,
112 .statfs = isofs_statfs, 111 .statfs = isofs_statfs,
113 .remount_fs = isofs_remount, 112 .remount_fs = isofs_remount,
113 .show_options = generic_show_options,
114}; 114};
115 115
116 116
@@ -145,7 +145,8 @@ struct iso9660_options{
145 char nocompress; 145 char nocompress;
146 unsigned char check; 146 unsigned char check;
147 unsigned int blocksize; 147 unsigned int blocksize;
148 mode_t mode; 148 mode_t fmode;
149 mode_t dmode;
149 gid_t gid; 150 gid_t gid;
150 uid_t uid; 151 uid_t uid;
151 char *iocharset; 152 char *iocharset;
@@ -306,7 +307,7 @@ enum {
306 Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore, 307 Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore,
307 Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet, 308 Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet,
308 Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err, 309 Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err,
309 Opt_nocompress, Opt_hide, Opt_showassoc, 310 Opt_nocompress, Opt_hide, Opt_showassoc, Opt_dmode,
310}; 311};
311 312
312static match_table_t tokens = { 313static match_table_t tokens = {
@@ -333,6 +334,7 @@ static match_table_t tokens = {
333 {Opt_uid, "uid=%u"}, 334 {Opt_uid, "uid=%u"},
334 {Opt_gid, "gid=%u"}, 335 {Opt_gid, "gid=%u"},
335 {Opt_mode, "mode=%u"}, 336 {Opt_mode, "mode=%u"},
337 {Opt_dmode, "dmode=%u"},
336 {Opt_block, "block=%u"}, 338 {Opt_block, "block=%u"},
337 {Opt_ignore, "conv=binary"}, 339 {Opt_ignore, "conv=binary"},
338 {Opt_ignore, "conv=b"}, 340 {Opt_ignore, "conv=b"},
@@ -360,7 +362,7 @@ static int parse_options(char *options, struct iso9660_options *popt)
360 popt->check = 'u'; /* unset */ 362 popt->check = 'u'; /* unset */
361 popt->nocompress = 0; 363 popt->nocompress = 0;
362 popt->blocksize = 1024; 364 popt->blocksize = 1024;
363 popt->mode = S_IRUGO | S_IXUGO; /* 365 popt->fmode = popt->dmode = S_IRUGO | S_IXUGO; /*
364 * r-x for all. The disc could 366 * r-x for all. The disc could
365 * be shared with DOS machines so 367 * be shared with DOS machines so
366 * virtually anything could be 368 * virtually anything could be
@@ -452,7 +454,12 @@ static int parse_options(char *options, struct iso9660_options *popt)
452 case Opt_mode: 454 case Opt_mode:
453 if (match_int(&args[0], &option)) 455 if (match_int(&args[0], &option))
454 return 0; 456 return 0;
455 popt->mode = option; 457 popt->fmode = option;
458 break;
459 case Opt_dmode:
460 if (match_int(&args[0], &option))
461 return 0;
462 popt->dmode = option;
456 break; 463 break;
457 case Opt_block: 464 case Opt_block:
458 if (match_int(&args[0], &option)) 465 if (match_int(&args[0], &option))
@@ -552,9 +559,11 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
552 int joliet_level = 0; 559 int joliet_level = 0;
553 int iso_blknum, block; 560 int iso_blknum, block;
554 int orig_zonesize; 561 int orig_zonesize;
555 int table; 562 int table, error = -EINVAL;
556 unsigned int vol_desc_start; 563 unsigned int vol_desc_start;
557 564
565 save_mount_options(s, data);
566
558 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 567 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
559 if (!sbi) 568 if (!sbi)
560 return -ENOMEM; 569 return -ENOMEM;
@@ -802,7 +811,8 @@ root_found:
802 * on the disk as suid, so we merely allow them to set the default 811 * on the disk as suid, so we merely allow them to set the default
803 * permissions. 812 * permissions.
804 */ 813 */
805 sbi->s_mode = opt.mode & 0777; 814 sbi->s_fmode = opt.fmode & 0777;
815 sbi->s_dmode = opt.dmode & 0777;
806 816
807 /* 817 /*
808 * Read the root inode, which _may_ result in changing 818 * Read the root inode, which _may_ result in changing
@@ -810,6 +820,8 @@ root_found:
810 * we then decide whether to use the Joliet descriptor. 820 * we then decide whether to use the Joliet descriptor.
811 */ 821 */
812 inode = isofs_iget(s, sbi->s_firstdatazone, 0); 822 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
823 if (IS_ERR(inode))
824 goto out_no_root;
813 825
814 /* 826 /*
815 * If this disk has both Rock Ridge and Joliet on it, then we 827 * If this disk has both Rock Ridge and Joliet on it, then we
@@ -829,6 +841,8 @@ root_found:
829 "ISOFS: changing to secondary root\n"); 841 "ISOFS: changing to secondary root\n");
830 iput(inode); 842 iput(inode);
831 inode = isofs_iget(s, sbi->s_firstdatazone, 0); 843 inode = isofs_iget(s, sbi->s_firstdatazone, 0);
844 if (IS_ERR(inode))
845 goto out_no_root;
832 } 846 }
833 } 847 }
834 848
@@ -842,8 +856,6 @@ root_found:
842 sbi->s_joliet_level = joliet_level; 856 sbi->s_joliet_level = joliet_level;
843 857
844 /* check the root inode */ 858 /* check the root inode */
845 if (!inode)
846 goto out_no_root;
847 if (!inode->i_op) 859 if (!inode->i_op)
848 goto out_bad_root; 860 goto out_bad_root;
849 861
@@ -876,11 +888,14 @@ root_found:
876 */ 888 */
877out_bad_root: 889out_bad_root:
878 printk(KERN_WARNING "%s: root inode not initialized\n", __func__); 890 printk(KERN_WARNING "%s: root inode not initialized\n", __func__);
879 goto out_iput;
880out_no_root:
881 printk(KERN_WARNING "%s: get root inode failed\n", __func__);
882out_iput: 891out_iput:
883 iput(inode); 892 iput(inode);
893 goto out_no_inode;
894out_no_root:
895 error = PTR_ERR(inode);
896 if (error != -ENOMEM)
897 printk(KERN_WARNING "%s: get root inode failed\n", __func__);
898out_no_inode:
884#ifdef CONFIG_JOLIET 899#ifdef CONFIG_JOLIET
885 if (sbi->s_nls_iocharset) 900 if (sbi->s_nls_iocharset)
886 unload_nls(sbi->s_nls_iocharset); 901 unload_nls(sbi->s_nls_iocharset);
@@ -908,7 +923,7 @@ out_freesbi:
908 kfree(opt.iocharset); 923 kfree(opt.iocharset);
909 kfree(sbi); 924 kfree(sbi);
910 s->s_fs_info = NULL; 925 s->s_fs_info = NULL;
911 return -EINVAL; 926 return error;
912} 927}
913 928
914static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf) 929static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
@@ -930,7 +945,7 @@ static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
930/* 945/*
931 * Get a set of blocks; filling in buffer_heads if already allocated 946 * Get a set of blocks; filling in buffer_heads if already allocated
932 * or getblk() if they are not. Returns the number of blocks inserted 947 * or getblk() if they are not. Returns the number of blocks inserted
933 * (0 == error.) 948 * (-ve == error.)
934 */ 949 */
935int isofs_get_blocks(struct inode *inode, sector_t iblock_s, 950int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
936 struct buffer_head **bh, unsigned long nblocks) 951 struct buffer_head **bh, unsigned long nblocks)
@@ -940,11 +955,12 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
940 unsigned int firstext; 955 unsigned int firstext;
941 unsigned long nextblk, nextoff; 956 unsigned long nextblk, nextoff;
942 long iblock = (long)iblock_s; 957 long iblock = (long)iblock_s;
943 int section, rv; 958 int section, rv, error;
944 struct iso_inode_info *ei = ISOFS_I(inode); 959 struct iso_inode_info *ei = ISOFS_I(inode);
945 960
946 lock_kernel(); 961 lock_kernel();
947 962
963 error = -EIO;
948 rv = 0; 964 rv = 0;
949 if (iblock < 0 || iblock != iblock_s) { 965 if (iblock < 0 || iblock != iblock_s) {
950 printk(KERN_DEBUG "%s: block number too large\n", __func__); 966 printk(KERN_DEBUG "%s: block number too large\n", __func__);
@@ -983,8 +999,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
983 999
984 offset += sect_size; 1000 offset += sect_size;
985 ninode = isofs_iget(inode->i_sb, nextblk, nextoff); 1001 ninode = isofs_iget(inode->i_sb, nextblk, nextoff);
986 if (!ninode) 1002 if (IS_ERR(ninode)) {
1003 error = PTR_ERR(ninode);
987 goto abort; 1004 goto abort;
1005 }
988 firstext = ISOFS_I(ninode)->i_first_extent; 1006 firstext = ISOFS_I(ninode)->i_first_extent;
989 sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode); 1007 sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode);
990 nextblk = ISOFS_I(ninode)->i_next_section_block; 1008 nextblk = ISOFS_I(ninode)->i_next_section_block;
@@ -1015,9 +1033,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
1015 rv++; 1033 rv++;
1016 } 1034 }
1017 1035
1036 error = 0;
1018abort: 1037abort:
1019 unlock_kernel(); 1038 unlock_kernel();
1020 return rv; 1039 return rv != 0 ? rv : error;
1021} 1040}
1022 1041
1023/* 1042/*
@@ -1026,12 +1045,15 @@ abort:
1026static int isofs_get_block(struct inode *inode, sector_t iblock, 1045static int isofs_get_block(struct inode *inode, sector_t iblock,
1027 struct buffer_head *bh_result, int create) 1046 struct buffer_head *bh_result, int create)
1028{ 1047{
1048 int ret;
1049
1029 if (create) { 1050 if (create) {
1030 printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__); 1051 printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__);
1031 return -EROFS; 1052 return -EROFS;
1032 } 1053 }
1033 1054
1034 return isofs_get_blocks(inode, iblock, &bh_result, 1) ? 0 : -EIO; 1055 ret = isofs_get_blocks(inode, iblock, &bh_result, 1);
1056 return ret < 0 ? ret : 0;
1035} 1057}
1036 1058
1037static int isofs_bmap(struct inode *inode, sector_t block) 1059static int isofs_bmap(struct inode *inode, sector_t block)
@@ -1186,7 +1208,7 @@ out_toomany:
1186 goto out; 1208 goto out;
1187} 1209}
1188 1210
1189static void isofs_read_inode(struct inode *inode) 1211static int isofs_read_inode(struct inode *inode)
1190{ 1212{
1191 struct super_block *sb = inode->i_sb; 1213 struct super_block *sb = inode->i_sb;
1192 struct isofs_sb_info *sbi = ISOFS_SB(sb); 1214 struct isofs_sb_info *sbi = ISOFS_SB(sb);
@@ -1199,6 +1221,7 @@ static void isofs_read_inode(struct inode *inode)
1199 unsigned int de_len; 1221 unsigned int de_len;
1200 unsigned long offset; 1222 unsigned long offset;
1201 struct iso_inode_info *ei = ISOFS_I(inode); 1223 struct iso_inode_info *ei = ISOFS_I(inode);
1224 int ret = -EIO;
1202 1225
1203 block = ei->i_iget5_block; 1226 block = ei->i_iget5_block;
1204 bh = sb_bread(inode->i_sb, block); 1227 bh = sb_bread(inode->i_sb, block);
@@ -1216,6 +1239,7 @@ static void isofs_read_inode(struct inode *inode)
1216 tmpde = kmalloc(de_len, GFP_KERNEL); 1239 tmpde = kmalloc(de_len, GFP_KERNEL);
1217 if (tmpde == NULL) { 1240 if (tmpde == NULL) {
1218 printk(KERN_INFO "%s: out of memory\n", __func__); 1241 printk(KERN_INFO "%s: out of memory\n", __func__);
1242 ret = -ENOMEM;
1219 goto fail; 1243 goto fail;
1220 } 1244 }
1221 memcpy(tmpde, bh->b_data + offset, frag1); 1245 memcpy(tmpde, bh->b_data + offset, frag1);
@@ -1235,7 +1259,7 @@ static void isofs_read_inode(struct inode *inode)
1235 ei->i_file_format = isofs_file_normal; 1259 ei->i_file_format = isofs_file_normal;
1236 1260
1237 if (de->flags[-high_sierra] & 2) { 1261 if (de->flags[-high_sierra] & 2) {
1238 inode->i_mode = S_IRUGO | S_IXUGO | S_IFDIR; 1262 inode->i_mode = sbi->s_dmode | S_IFDIR;
1239 inode->i_nlink = 1; /* 1263 inode->i_nlink = 1; /*
1240 * Set to 1. We know there are 2, but 1264 * Set to 1. We know there are 2, but
1241 * the find utility tries to optimize 1265 * the find utility tries to optimize
@@ -1245,9 +1269,8 @@ static void isofs_read_inode(struct inode *inode)
1245 */ 1269 */
1246 } else { 1270 } else {
1247 /* Everybody gets to read the file. */ 1271 /* Everybody gets to read the file. */
1248 inode->i_mode = sbi->s_mode; 1272 inode->i_mode = sbi->s_fmode | S_IFREG;
1249 inode->i_nlink = 1; 1273 inode->i_nlink = 1;
1250 inode->i_mode |= S_IFREG;
1251 } 1274 }
1252 inode->i_uid = sbi->s_uid; 1275 inode->i_uid = sbi->s_uid;
1253 inode->i_gid = sbi->s_gid; 1276 inode->i_gid = sbi->s_gid;
@@ -1259,8 +1282,10 @@ static void isofs_read_inode(struct inode *inode)
1259 1282
1260 ei->i_section_size = isonum_733(de->size); 1283 ei->i_section_size = isonum_733(de->size);
1261 if (de->flags[-high_sierra] & 0x80) { 1284 if (de->flags[-high_sierra] & 0x80) {
1262 if(isofs_read_level3_size(inode)) 1285 ret = isofs_read_level3_size(inode);
1286 if (ret < 0)
1263 goto fail; 1287 goto fail;
1288 ret = -EIO;
1264 } else { 1289 } else {
1265 ei->i_next_section_block = 0; 1290 ei->i_next_section_block = 0;
1266 ei->i_next_section_offset = 0; 1291 ei->i_next_section_offset = 0;
@@ -1346,16 +1371,16 @@ static void isofs_read_inode(struct inode *inode)
1346 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */ 1371 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1347 init_special_inode(inode, inode->i_mode, inode->i_rdev); 1372 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1348 1373
1374 ret = 0;
1349out: 1375out:
1350 kfree(tmpde); 1376 kfree(tmpde);
1351 if (bh) 1377 if (bh)
1352 brelse(bh); 1378 brelse(bh);
1353 return; 1379 return ret;
1354 1380
1355out_badread: 1381out_badread:
1356 printk(KERN_WARNING "ISOFS: unable to read i-node block\n"); 1382 printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
1357fail: 1383fail:
1358 make_bad_inode(inode);
1359 goto out; 1384 goto out;
1360} 1385}
1361 1386
@@ -1394,9 +1419,10 @@ struct inode *isofs_iget(struct super_block *sb,
1394 unsigned long hashval; 1419 unsigned long hashval;
1395 struct inode *inode; 1420 struct inode *inode;
1396 struct isofs_iget5_callback_data data; 1421 struct isofs_iget5_callback_data data;
1422 long ret;
1397 1423
1398 if (offset >= 1ul << sb->s_blocksize_bits) 1424 if (offset >= 1ul << sb->s_blocksize_bits)
1399 return NULL; 1425 return ERR_PTR(-EINVAL);
1400 1426
1401 data.block = block; 1427 data.block = block;
1402 data.offset = offset; 1428 data.offset = offset;
@@ -1406,9 +1432,17 @@ struct inode *isofs_iget(struct super_block *sb,
1406 inode = iget5_locked(sb, hashval, &isofs_iget5_test, 1432 inode = iget5_locked(sb, hashval, &isofs_iget5_test,
1407 &isofs_iget5_set, &data); 1433 &isofs_iget5_set, &data);
1408 1434
1409 if (inode && (inode->i_state & I_NEW)) { 1435 if (!inode)
1410 sb->s_op->read_inode(inode); 1436 return ERR_PTR(-ENOMEM);
1411 unlock_new_inode(inode); 1437
1438 if (inode->i_state & I_NEW) {
1439 ret = isofs_read_inode(inode);
1440 if (ret < 0) {
1441 iget_failed(inode);
1442 inode = ERR_PTR(ret);
1443 } else {
1444 unlock_new_inode(inode);
1445 }
1412 } 1446 }
1413 1447
1414 return inode; 1448 return inode;