aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/super.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2013-07-25 13:10:59 -0400
committerJan Kara <jack@suse.cz>2013-07-31 16:14:50 -0400
commitd759bfa4e7919b89357de50a2e23817079889195 (patch)
tree77704442d642f3bef53ff230050e31271bc86cad /fs/udf/super.c
parent17b7f7cf58926844e1dd40f5eb5348d481deca6a (diff)
udf: Standardize return values in mount sequence
Change all function used in filesystem discovery during mount to user standard kernel return values - -errno on error, 0 on success instead of 1 on failure and 0 on success. This allows us to pass error number (not just failure / success) so we can abort device scanning earlier in case of errors like EIO or ENOMEM . Also we will be able to return EROFS in case writeable mount is requested but writing isn't supported. Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/udf/super.c')
-rw-r--r--fs/udf/super.c300
1 files changed, 183 insertions, 117 deletions
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 9ac4057a86c9..c68da0dac2c5 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -843,27 +843,38 @@ static int udf_find_fileset(struct super_block *sb,
843 return 1; 843 return 1;
844} 844}
845 845
846/*
847 * Load primary Volume Descriptor Sequence
848 *
849 * Return <0 on error, 0 on success. -EAGAIN is special meaning next sequence
850 * should be tried.
851 */
846static int udf_load_pvoldesc(struct super_block *sb, sector_t block) 852static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
847{ 853{
848 struct primaryVolDesc *pvoldesc; 854 struct primaryVolDesc *pvoldesc;
849 struct ustr *instr, *outstr; 855 struct ustr *instr, *outstr;
850 struct buffer_head *bh; 856 struct buffer_head *bh;
851 uint16_t ident; 857 uint16_t ident;
852 int ret = 1; 858 int ret = -ENOMEM;
853 859
854 instr = kmalloc(sizeof(struct ustr), GFP_NOFS); 860 instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
855 if (!instr) 861 if (!instr)
856 return 1; 862 return -ENOMEM;
857 863
858 outstr = kmalloc(sizeof(struct ustr), GFP_NOFS); 864 outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
859 if (!outstr) 865 if (!outstr)
860 goto out1; 866 goto out1;
861 867
862 bh = udf_read_tagged(sb, block, block, &ident); 868 bh = udf_read_tagged(sb, block, block, &ident);
863 if (!bh) 869 if (!bh) {
870 ret = -EAGAIN;
864 goto out2; 871 goto out2;
872 }
865 873
866 BUG_ON(ident != TAG_IDENT_PVD); 874 if (ident != TAG_IDENT_PVD) {
875 ret = -EIO;
876 goto out_bh;
877 }
867 878
868 pvoldesc = (struct primaryVolDesc *)bh->b_data; 879 pvoldesc = (struct primaryVolDesc *)bh->b_data;
869 880
@@ -889,8 +900,9 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
889 if (udf_CS0toUTF8(outstr, instr)) 900 if (udf_CS0toUTF8(outstr, instr))
890 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name); 901 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
891 902
892 brelse(bh);
893 ret = 0; 903 ret = 0;
904out_bh:
905 brelse(bh);
894out2: 906out2:
895 kfree(outstr); 907 kfree(outstr);
896out1: 908out1:
@@ -947,7 +959,7 @@ static int udf_load_metadata_files(struct super_block *sb, int partition)
947 959
948 if (mdata->s_mirror_fe == NULL) { 960 if (mdata->s_mirror_fe == NULL) {
949 udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n"); 961 udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n");
950 goto error_exit; 962 return -EIO;
951 } 963 }
952 } 964 }
953 965
@@ -964,23 +976,18 @@ static int udf_load_metadata_files(struct super_block *sb, int partition)
964 addr.logicalBlockNum, addr.partitionReferenceNum); 976 addr.logicalBlockNum, addr.partitionReferenceNum);
965 977
966 mdata->s_bitmap_fe = udf_iget(sb, &addr); 978 mdata->s_bitmap_fe = udf_iget(sb, &addr);
967
968 if (mdata->s_bitmap_fe == NULL) { 979 if (mdata->s_bitmap_fe == NULL) {
969 if (sb->s_flags & MS_RDONLY) 980 if (sb->s_flags & MS_RDONLY)
970 udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n"); 981 udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n");
971 else { 982 else {
972 udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n"); 983 udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n");
973 goto error_exit; 984 return -EIO;
974 } 985 }
975 } 986 }
976 } 987 }
977 988
978 udf_debug("udf_load_metadata_files Ok\n"); 989 udf_debug("udf_load_metadata_files Ok\n");
979
980 return 0; 990 return 0;
981
982error_exit:
983 return 1;
984} 991}
985 992
986static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, 993static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
@@ -1069,7 +1076,7 @@ static int udf_fill_partdesc_info(struct super_block *sb,
1069 if (!map->s_uspace.s_table) { 1076 if (!map->s_uspace.s_table) {
1070 udf_debug("cannot load unallocSpaceTable (part %d)\n", 1077 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1071 p_index); 1078 p_index);
1072 return 1; 1079 return -EIO;
1073 } 1080 }
1074 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; 1081 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
1075 udf_debug("unallocSpaceTable (part %d) @ %ld\n", 1082 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
@@ -1079,7 +1086,7 @@ static int udf_fill_partdesc_info(struct super_block *sb,
1079 if (phd->unallocSpaceBitmap.extLength) { 1086 if (phd->unallocSpaceBitmap.extLength) {
1080 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index); 1087 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1081 if (!bitmap) 1088 if (!bitmap)
1082 return 1; 1089 return -ENOMEM;
1083 map->s_uspace.s_bitmap = bitmap; 1090 map->s_uspace.s_bitmap = bitmap;
1084 bitmap->s_extPosition = le32_to_cpu( 1091 bitmap->s_extPosition = le32_to_cpu(
1085 phd->unallocSpaceBitmap.extPosition); 1092 phd->unallocSpaceBitmap.extPosition);
@@ -1102,7 +1109,7 @@ static int udf_fill_partdesc_info(struct super_block *sb,
1102 if (!map->s_fspace.s_table) { 1109 if (!map->s_fspace.s_table) {
1103 udf_debug("cannot load freedSpaceTable (part %d)\n", 1110 udf_debug("cannot load freedSpaceTable (part %d)\n",
1104 p_index); 1111 p_index);
1105 return 1; 1112 return -EIO;
1106 } 1113 }
1107 1114
1108 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; 1115 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
@@ -1113,7 +1120,7 @@ static int udf_fill_partdesc_info(struct super_block *sb,
1113 if (phd->freedSpaceBitmap.extLength) { 1120 if (phd->freedSpaceBitmap.extLength) {
1114 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index); 1121 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1115 if (!bitmap) 1122 if (!bitmap)
1116 return 1; 1123 return -ENOMEM;
1117 map->s_fspace.s_bitmap = bitmap; 1124 map->s_fspace.s_bitmap = bitmap;
1118 bitmap->s_extPosition = le32_to_cpu( 1125 bitmap->s_extPosition = le32_to_cpu(
1119 phd->freedSpaceBitmap.extPosition); 1126 phd->freedSpaceBitmap.extPosition);
@@ -1165,7 +1172,7 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1165 udf_find_vat_block(sb, p_index, type1_index, blocks - 1); 1172 udf_find_vat_block(sb, p_index, type1_index, blocks - 1);
1166 } 1173 }
1167 if (!sbi->s_vat_inode) 1174 if (!sbi->s_vat_inode)
1168 return 1; 1175 return -EIO;
1169 1176
1170 if (map->s_partition_type == UDF_VIRTUAL_MAP15) { 1177 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
1171 map->s_type_specific.s_virtual.s_start_offset = 0; 1178 map->s_type_specific.s_virtual.s_start_offset = 0;
@@ -1177,7 +1184,7 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1177 pos = udf_block_map(sbi->s_vat_inode, 0); 1184 pos = udf_block_map(sbi->s_vat_inode, 0);
1178 bh = sb_bread(sb, pos); 1185 bh = sb_bread(sb, pos);
1179 if (!bh) 1186 if (!bh)
1180 return 1; 1187 return -EIO;
1181 vat20 = (struct virtualAllocationTable20 *)bh->b_data; 1188 vat20 = (struct virtualAllocationTable20 *)bh->b_data;
1182 } else { 1189 } else {
1183 vat20 = (struct virtualAllocationTable20 *) 1190 vat20 = (struct virtualAllocationTable20 *)
@@ -1195,6 +1202,12 @@ static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1195 return 0; 1202 return 0;
1196} 1203}
1197 1204
1205/*
1206 * Load partition descriptor block
1207 *
1208 * Returns <0 on error, 0 on success, -EAGAIN is special - try next descriptor
1209 * sequence.
1210 */
1198static int udf_load_partdesc(struct super_block *sb, sector_t block) 1211static int udf_load_partdesc(struct super_block *sb, sector_t block)
1199{ 1212{
1200 struct buffer_head *bh; 1213 struct buffer_head *bh;
@@ -1204,13 +1217,15 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
1204 int i, type1_idx; 1217 int i, type1_idx;
1205 uint16_t partitionNumber; 1218 uint16_t partitionNumber;
1206 uint16_t ident; 1219 uint16_t ident;
1207 int ret = 0; 1220 int ret;
1208 1221
1209 bh = udf_read_tagged(sb, block, block, &ident); 1222 bh = udf_read_tagged(sb, block, block, &ident);
1210 if (!bh) 1223 if (!bh)
1211 return 1; 1224 return -EAGAIN;
1212 if (ident != TAG_IDENT_PD) 1225 if (ident != TAG_IDENT_PD) {
1226 ret = 0;
1213 goto out_bh; 1227 goto out_bh;
1228 }
1214 1229
1215 p = (struct partitionDesc *)bh->b_data; 1230 p = (struct partitionDesc *)bh->b_data;
1216 partitionNumber = le16_to_cpu(p->partitionNumber); 1231 partitionNumber = le16_to_cpu(p->partitionNumber);
@@ -1229,10 +1244,13 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
1229 if (i >= sbi->s_partitions) { 1244 if (i >= sbi->s_partitions) {
1230 udf_debug("Partition (%d) not found in partition map\n", 1245 udf_debug("Partition (%d) not found in partition map\n",
1231 partitionNumber); 1246 partitionNumber);
1247 ret = 0;
1232 goto out_bh; 1248 goto out_bh;
1233 } 1249 }
1234 1250
1235 ret = udf_fill_partdesc_info(sb, p, i); 1251 ret = udf_fill_partdesc_info(sb, p, i);
1252 if (ret < 0)
1253 goto out_bh;
1236 1254
1237 /* 1255 /*
1238 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and 1256 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
@@ -1249,23 +1267,25 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
1249 break; 1267 break;
1250 } 1268 }
1251 1269
1252 if (i >= sbi->s_partitions) 1270 if (i >= sbi->s_partitions) {
1271 ret = 0;
1253 goto out_bh; 1272 goto out_bh;
1273 }
1254 1274
1255 ret = udf_fill_partdesc_info(sb, p, i); 1275 ret = udf_fill_partdesc_info(sb, p, i);
1256 if (ret) 1276 if (ret < 0)
1257 goto out_bh; 1277 goto out_bh;
1258 1278
1259 if (map->s_partition_type == UDF_METADATA_MAP25) { 1279 if (map->s_partition_type == UDF_METADATA_MAP25) {
1260 ret = udf_load_metadata_files(sb, i); 1280 ret = udf_load_metadata_files(sb, i);
1261 if (ret) { 1281 if (ret < 0) {
1262 udf_err(sb, "error loading MetaData partition map %d\n", 1282 udf_err(sb, "error loading MetaData partition map %d\n",
1263 i); 1283 i);
1264 goto out_bh; 1284 goto out_bh;
1265 } 1285 }
1266 } else { 1286 } else {
1267 ret = udf_load_vat(sb, i, type1_idx); 1287 ret = udf_load_vat(sb, i, type1_idx);
1268 if (ret) 1288 if (ret < 0)
1269 goto out_bh; 1289 goto out_bh;
1270 /* 1290 /*
1271 * Mark filesystem read-only if we have a partition with 1291 * Mark filesystem read-only if we have a partition with
@@ -1275,6 +1295,7 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
1275 sb->s_flags |= MS_RDONLY; 1295 sb->s_flags |= MS_RDONLY;
1276 pr_notice("Filesystem marked read-only because writing to pseudooverwrite partition is not implemented\n"); 1296 pr_notice("Filesystem marked read-only because writing to pseudooverwrite partition is not implemented\n");
1277 } 1297 }
1298 ret = 0;
1278out_bh: 1299out_bh:
1279 /* In case loading failed, we handle cleanup in udf_fill_super */ 1300 /* In case loading failed, we handle cleanup in udf_fill_super */
1280 brelse(bh); 1301 brelse(bh);
@@ -1340,11 +1361,11 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1340 uint16_t ident; 1361 uint16_t ident;
1341 struct buffer_head *bh; 1362 struct buffer_head *bh;
1342 unsigned int table_len; 1363 unsigned int table_len;
1343 int ret = 0; 1364 int ret;
1344 1365
1345 bh = udf_read_tagged(sb, block, block, &ident); 1366 bh = udf_read_tagged(sb, block, block, &ident);
1346 if (!bh) 1367 if (!bh)
1347 return 1; 1368 return -EAGAIN;
1348 BUG_ON(ident != TAG_IDENT_LVD); 1369 BUG_ON(ident != TAG_IDENT_LVD);
1349 lvd = (struct logicalVolDesc *)bh->b_data; 1370 lvd = (struct logicalVolDesc *)bh->b_data;
1350 table_len = le32_to_cpu(lvd->mapTableLength); 1371 table_len = le32_to_cpu(lvd->mapTableLength);
@@ -1352,7 +1373,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1352 udf_err(sb, "error loading logical volume descriptor: " 1373 udf_err(sb, "error loading logical volume descriptor: "
1353 "Partition table too long (%u > %lu)\n", table_len, 1374 "Partition table too long (%u > %lu)\n", table_len,
1354 sb->s_blocksize - sizeof(*lvd)); 1375 sb->s_blocksize - sizeof(*lvd));
1355 ret = 1; 1376 ret = -EIO;
1356 goto out_bh; 1377 goto out_bh;
1357 } 1378 }
1358 1379
@@ -1396,11 +1417,10 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1396 } else if (!strncmp(upm2->partIdent.ident, 1417 } else if (!strncmp(upm2->partIdent.ident,
1397 UDF_ID_SPARABLE, 1418 UDF_ID_SPARABLE,
1398 strlen(UDF_ID_SPARABLE))) { 1419 strlen(UDF_ID_SPARABLE))) {
1399 if (udf_load_sparable_map(sb, map, 1420 ret = udf_load_sparable_map(sb, map,
1400 (struct sparablePartitionMap *)gpm) < 0) { 1421 (struct sparablePartitionMap *)gpm);
1401 ret = 1; 1422 if (ret < 0)
1402 goto out_bh; 1423 goto out_bh;
1403 }
1404 } else if (!strncmp(upm2->partIdent.ident, 1424 } else if (!strncmp(upm2->partIdent.ident,
1405 UDF_ID_METADATA, 1425 UDF_ID_METADATA,
1406 strlen(UDF_ID_METADATA))) { 1426 strlen(UDF_ID_METADATA))) {
@@ -1465,7 +1485,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1465 } 1485 }
1466 if (lvd->integritySeqExt.extLength) 1486 if (lvd->integritySeqExt.extLength)
1467 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); 1487 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1468 1488 ret = 0;
1469out_bh: 1489out_bh:
1470 brelse(bh); 1490 brelse(bh);
1471 return ret; 1491 return ret;
@@ -1503,22 +1523,18 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_
1503} 1523}
1504 1524
1505/* 1525/*
1506 * udf_process_sequence 1526 * Process a main/reserve volume descriptor sequence.
1507 * 1527 * @block First block of first extent of the sequence.
1508 * PURPOSE 1528 * @lastblock Lastblock of first extent of the sequence.
1509 * Process a main/reserve volume descriptor sequence. 1529 * @fileset There we store extent containing root fileset
1510 * 1530 *
1511 * PRE-CONDITIONS 1531 * Returns <0 on error, 0 on success. -EAGAIN is special - try next descriptor
1512 * sb Pointer to _locked_ superblock. 1532 * sequence
1513 * block First block of first extent of the sequence.
1514 * lastblock Lastblock of first extent of the sequence.
1515 *
1516 * HISTORY
1517 * July 1, 1997 - Andrew E. Mileski
1518 * Written, tested, and released.
1519 */ 1533 */
1520static noinline int udf_process_sequence(struct super_block *sb, long block, 1534static noinline int udf_process_sequence(
1521 long lastblock, struct kernel_lb_addr *fileset) 1535 struct super_block *sb,
1536 sector_t block, sector_t lastblock,
1537 struct kernel_lb_addr *fileset)
1522{ 1538{
1523 struct buffer_head *bh = NULL; 1539 struct buffer_head *bh = NULL;
1524 struct udf_vds_record vds[VDS_POS_LENGTH]; 1540 struct udf_vds_record vds[VDS_POS_LENGTH];
@@ -1529,6 +1545,7 @@ static noinline int udf_process_sequence(struct super_block *sb, long block,
1529 uint32_t vdsn; 1545 uint32_t vdsn;
1530 uint16_t ident; 1546 uint16_t ident;
1531 long next_s = 0, next_e = 0; 1547 long next_s = 0, next_e = 0;
1548 int ret;
1532 1549
1533 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); 1550 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1534 1551
@@ -1543,7 +1560,7 @@ static noinline int udf_process_sequence(struct super_block *sb, long block,
1543 udf_err(sb, 1560 udf_err(sb,
1544 "Block %llu of volume descriptor sequence is corrupted or we could not read it\n", 1561 "Block %llu of volume descriptor sequence is corrupted or we could not read it\n",
1545 (unsigned long long)block); 1562 (unsigned long long)block);
1546 return 1; 1563 return -EAGAIN;
1547 } 1564 }
1548 1565
1549 /* Process each descriptor (ISO 13346 3/8.3-8.4) */ 1566 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
@@ -1616,14 +1633,19 @@ static noinline int udf_process_sequence(struct super_block *sb, long block,
1616 */ 1633 */
1617 if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) { 1634 if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
1618 udf_err(sb, "Primary Volume Descriptor not found!\n"); 1635 udf_err(sb, "Primary Volume Descriptor not found!\n");
1619 return 1; 1636 return -EAGAIN;
1637 }
1638 ret = udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block);
1639 if (ret < 0)
1640 return ret;
1641
1642 if (vds[VDS_POS_LOGICAL_VOL_DESC].block) {
1643 ret = udf_load_logicalvol(sb,
1644 vds[VDS_POS_LOGICAL_VOL_DESC].block,
1645 fileset);
1646 if (ret < 0)
1647 return ret;
1620 } 1648 }
1621 if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
1622 return 1;
1623
1624 if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
1625 vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
1626 return 1;
1627 1649
1628 if (vds[VDS_POS_PARTITION_DESC].block) { 1650 if (vds[VDS_POS_PARTITION_DESC].block) {
1629 /* 1651 /*
@@ -1632,19 +1654,27 @@ static noinline int udf_process_sequence(struct super_block *sb, long block,
1632 */ 1654 */
1633 for (block = vds[VDS_POS_PARTITION_DESC].block; 1655 for (block = vds[VDS_POS_PARTITION_DESC].block;
1634 block < vds[VDS_POS_TERMINATING_DESC].block; 1656 block < vds[VDS_POS_TERMINATING_DESC].block;
1635 block++) 1657 block++) {
1636 if (udf_load_partdesc(sb, block)) 1658 ret = udf_load_partdesc(sb, block);
1637 return 1; 1659 if (ret < 0)
1660 return ret;
1661 }
1638 } 1662 }
1639 1663
1640 return 0; 1664 return 0;
1641} 1665}
1642 1666
1667/*
1668 * Load Volume Descriptor Sequence described by anchor in bh
1669 *
1670 * Returns <0 on error, 0 on success
1671 */
1643static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh, 1672static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
1644 struct kernel_lb_addr *fileset) 1673 struct kernel_lb_addr *fileset)
1645{ 1674{
1646 struct anchorVolDescPtr *anchor; 1675 struct anchorVolDescPtr *anchor;
1647 long main_s, main_e, reserve_s, reserve_e; 1676 sector_t main_s, main_e, reserve_s, reserve_e;
1677 int ret;
1648 1678
1649 anchor = (struct anchorVolDescPtr *)bh->b_data; 1679 anchor = (struct anchorVolDescPtr *)bh->b_data;
1650 1680
@@ -1662,18 +1692,26 @@ static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
1662 1692
1663 /* Process the main & reserve sequences */ 1693 /* Process the main & reserve sequences */
1664 /* responsible for finding the PartitionDesc(s) */ 1694 /* responsible for finding the PartitionDesc(s) */
1665 if (!udf_process_sequence(sb, main_s, main_e, fileset)) 1695 ret = udf_process_sequence(sb, main_s, main_e, fileset);
1666 return 1; 1696 if (ret != -EAGAIN)
1667 udf_sb_free_partitions(sb); 1697 return ret;
1668 if (!udf_process_sequence(sb, reserve_s, reserve_e, fileset))
1669 return 1;
1670 udf_sb_free_partitions(sb); 1698 udf_sb_free_partitions(sb);
1671 return 0; 1699 ret = udf_process_sequence(sb, reserve_s, reserve_e, fileset);
1700 if (ret < 0) {
1701 udf_sb_free_partitions(sb);
1702 /* No sequence was OK, return -EIO */
1703 if (ret == -EAGAIN)
1704 ret = -EIO;
1705 }
1706 return ret;
1672} 1707}
1673 1708
1674/* 1709/*
1675 * Check whether there is an anchor block in the given block and 1710 * Check whether there is an anchor block in the given block and
1676 * load Volume Descriptor Sequence if so. 1711 * load Volume Descriptor Sequence if so.
1712 *
1713 * Returns <0 on error, 0 on success, -EAGAIN is special - try next anchor
1714 * block
1677 */ 1715 */
1678static int udf_check_anchor_block(struct super_block *sb, sector_t block, 1716static int udf_check_anchor_block(struct super_block *sb, sector_t block,
1679 struct kernel_lb_addr *fileset) 1717 struct kernel_lb_addr *fileset)
@@ -1685,33 +1723,40 @@ static int udf_check_anchor_block(struct super_block *sb, sector_t block,
1685 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) && 1723 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
1686 udf_fixed_to_variable(block) >= 1724 udf_fixed_to_variable(block) >=
1687 sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits) 1725 sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
1688 return 0; 1726 return -EAGAIN;
1689 1727
1690 bh = udf_read_tagged(sb, block, block, &ident); 1728 bh = udf_read_tagged(sb, block, block, &ident);
1691 if (!bh) 1729 if (!bh)
1692 return 0; 1730 return -EAGAIN;
1693 if (ident != TAG_IDENT_AVDP) { 1731 if (ident != TAG_IDENT_AVDP) {
1694 brelse(bh); 1732 brelse(bh);
1695 return 0; 1733 return -EAGAIN;
1696 } 1734 }
1697 ret = udf_load_sequence(sb, bh, fileset); 1735 ret = udf_load_sequence(sb, bh, fileset);
1698 brelse(bh); 1736 brelse(bh);
1699 return ret; 1737 return ret;
1700} 1738}
1701 1739
1702/* Search for an anchor volume descriptor pointer */ 1740/*
1703static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock, 1741 * Search for an anchor volume descriptor pointer.
1704 struct kernel_lb_addr *fileset) 1742 *
1743 * Returns < 0 on error, 0 on success. -EAGAIN is special - try next set
1744 * of anchors.
1745 */
1746static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock,
1747 struct kernel_lb_addr *fileset)
1705{ 1748{
1706 sector_t last[6]; 1749 sector_t last[6];
1707 int i; 1750 int i;
1708 struct udf_sb_info *sbi = UDF_SB(sb); 1751 struct udf_sb_info *sbi = UDF_SB(sb);
1709 int last_count = 0; 1752 int last_count = 0;
1753 int ret;
1710 1754
1711 /* First try user provided anchor */ 1755 /* First try user provided anchor */
1712 if (sbi->s_anchor) { 1756 if (sbi->s_anchor) {
1713 if (udf_check_anchor_block(sb, sbi->s_anchor, fileset)) 1757 ret = udf_check_anchor_block(sb, sbi->s_anchor, fileset);
1714 return lastblock; 1758 if (ret != -EAGAIN)
1759 return ret;
1715 } 1760 }
1716 /* 1761 /*
1717 * according to spec, anchor is in either: 1762 * according to spec, anchor is in either:
@@ -1720,39 +1765,46 @@ static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
1720 * lastblock 1765 * lastblock
1721 * however, if the disc isn't closed, it could be 512. 1766 * however, if the disc isn't closed, it could be 512.
1722 */ 1767 */
1723 if (udf_check_anchor_block(sb, sbi->s_session + 256, fileset)) 1768 ret = udf_check_anchor_block(sb, sbi->s_session + 256, fileset);
1724 return lastblock; 1769 if (ret != -EAGAIN)
1770 return ret;
1725 /* 1771 /*
1726 * The trouble is which block is the last one. Drives often misreport 1772 * The trouble is which block is the last one. Drives often misreport
1727 * this so we try various possibilities. 1773 * this so we try various possibilities.
1728 */ 1774 */
1729 last[last_count++] = lastblock; 1775 last[last_count++] = *lastblock;
1730 if (lastblock >= 1) 1776 if (*lastblock >= 1)
1731 last[last_count++] = lastblock - 1; 1777 last[last_count++] = *lastblock - 1;
1732 last[last_count++] = lastblock + 1; 1778 last[last_count++] = *lastblock + 1;
1733 if (lastblock >= 2) 1779 if (*lastblock >= 2)
1734 last[last_count++] = lastblock - 2; 1780 last[last_count++] = *lastblock - 2;
1735 if (lastblock >= 150) 1781 if (*lastblock >= 150)
1736 last[last_count++] = lastblock - 150; 1782 last[last_count++] = *lastblock - 150;
1737 if (lastblock >= 152) 1783 if (*lastblock >= 152)
1738 last[last_count++] = lastblock - 152; 1784 last[last_count++] = *lastblock - 152;
1739 1785
1740 for (i = 0; i < last_count; i++) { 1786 for (i = 0; i < last_count; i++) {
1741 if (last[i] >= sb->s_bdev->bd_inode->i_size >> 1787 if (last[i] >= sb->s_bdev->bd_inode->i_size >>
1742 sb->s_blocksize_bits) 1788 sb->s_blocksize_bits)
1743 continue; 1789 continue;
1744 if (udf_check_anchor_block(sb, last[i], fileset)) 1790 ret = udf_check_anchor_block(sb, last[i], fileset);
1745 return last[i]; 1791 if (ret != -EAGAIN) {
1792 if (!ret)
1793 *lastblock = last[i];
1794 return ret;
1795 }
1746 if (last[i] < 256) 1796 if (last[i] < 256)
1747 continue; 1797 continue;
1748 if (udf_check_anchor_block(sb, last[i] - 256, fileset)) 1798 ret = udf_check_anchor_block(sb, last[i] - 256, fileset);
1749 return last[i]; 1799 if (ret != -EAGAIN) {
1800 if (!ret)
1801 *lastblock = last[i];
1802 return ret;
1803 }
1750 } 1804 }
1751 1805
1752 /* Finally try block 512 in case media is open */ 1806 /* Finally try block 512 in case media is open */
1753 if (udf_check_anchor_block(sb, sbi->s_session + 512, fileset)) 1807 return udf_check_anchor_block(sb, sbi->s_session + 512, fileset);
1754 return last[0];
1755 return 0;
1756} 1808}
1757 1809
1758/* 1810/*
@@ -1760,54 +1812,59 @@ static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
1760 * area specified by it. The function expects sbi->s_lastblock to be the last 1812 * area specified by it. The function expects sbi->s_lastblock to be the last
1761 * block on the media. 1813 * block on the media.
1762 * 1814 *
1763 * Return 1 if ok, 0 if not found. 1815 * Return <0 on error, 0 if anchor found. -EAGAIN is special meaning anchor
1764 * 1816 * was not found.
1765 */ 1817 */
1766static int udf_find_anchor(struct super_block *sb, 1818static int udf_find_anchor(struct super_block *sb,
1767 struct kernel_lb_addr *fileset) 1819 struct kernel_lb_addr *fileset)
1768{ 1820{
1769 sector_t lastblock;
1770 struct udf_sb_info *sbi = UDF_SB(sb); 1821 struct udf_sb_info *sbi = UDF_SB(sb);
1822 sector_t lastblock = sbi->s_last_block;
1823 int ret;
1771 1824
1772 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset); 1825 ret = udf_scan_anchors(sb, &lastblock, fileset);
1773 if (lastblock) 1826 if (ret != -EAGAIN)
1774 goto out; 1827 goto out;
1775 1828
1776 /* No anchor found? Try VARCONV conversion of block numbers */ 1829 /* No anchor found? Try VARCONV conversion of block numbers */
1777 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 1830 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
1831 lastblock = udf_variable_to_fixed(sbi->s_last_block);
1778 /* Firstly, we try to not convert number of the last block */ 1832 /* Firstly, we try to not convert number of the last block */
1779 lastblock = udf_scan_anchors(sb, 1833 ret = udf_scan_anchors(sb, &lastblock, fileset);
1780 udf_variable_to_fixed(sbi->s_last_block), 1834 if (ret != -EAGAIN)
1781 fileset);
1782 if (lastblock)
1783 goto out; 1835 goto out;
1784 1836
1837 lastblock = sbi->s_last_block;
1785 /* Secondly, we try with converted number of the last block */ 1838 /* Secondly, we try with converted number of the last block */
1786 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset); 1839 ret = udf_scan_anchors(sb, &lastblock, fileset);
1787 if (!lastblock) { 1840 if (ret < 0) {
1788 /* VARCONV didn't help. Clear it. */ 1841 /* VARCONV didn't help. Clear it. */
1789 UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV); 1842 UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
1790 return 0;
1791 } 1843 }
1792out: 1844out:
1793 sbi->s_last_block = lastblock; 1845 if (ret == 0)
1794 return 1; 1846 sbi->s_last_block = lastblock;
1847 return ret;
1795} 1848}
1796 1849
1797/* 1850/*
1798 * Check Volume Structure Descriptor, find Anchor block and load Volume 1851 * Check Volume Structure Descriptor, find Anchor block and load Volume
1799 * Descriptor Sequence 1852 * Descriptor Sequence.
1853 *
1854 * Returns < 0 on error, 0 on success. -EAGAIN is special meaning anchor
1855 * block was not found.
1800 */ 1856 */
1801static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt, 1857static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1802 int silent, struct kernel_lb_addr *fileset) 1858 int silent, struct kernel_lb_addr *fileset)
1803{ 1859{
1804 struct udf_sb_info *sbi = UDF_SB(sb); 1860 struct udf_sb_info *sbi = UDF_SB(sb);
1805 loff_t nsr_off; 1861 loff_t nsr_off;
1862 int ret;
1806 1863
1807 if (!sb_set_blocksize(sb, uopt->blocksize)) { 1864 if (!sb_set_blocksize(sb, uopt->blocksize)) {
1808 if (!silent) 1865 if (!silent)
1809 udf_warn(sb, "Bad block size\n"); 1866 udf_warn(sb, "Bad block size\n");
1810 return 0; 1867 return -EINVAL;
1811 } 1868 }
1812 sbi->s_last_block = uopt->lastblock; 1869 sbi->s_last_block = uopt->lastblock;
1813 if (!uopt->novrs) { 1870 if (!uopt->novrs) {
@@ -1828,12 +1885,13 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1828 1885
1829 /* Look for anchor block and load Volume Descriptor Sequence */ 1886 /* Look for anchor block and load Volume Descriptor Sequence */
1830 sbi->s_anchor = uopt->anchor; 1887 sbi->s_anchor = uopt->anchor;
1831 if (!udf_find_anchor(sb, fileset)) { 1888 ret = udf_find_anchor(sb, fileset);
1832 if (!silent) 1889 if (ret < 0) {
1890 if (!silent && ret == -EAGAIN)
1833 udf_warn(sb, "No anchor found\n"); 1891 udf_warn(sb, "No anchor found\n");
1834 return 0; 1892 return ret;
1835 } 1893 }
1836 return 1; 1894 return 0;
1837} 1895}
1838 1896
1839static void udf_open_lvid(struct super_block *sb) 1897static void udf_open_lvid(struct super_block *sb)
@@ -1939,7 +1997,7 @@ u64 lvid_get_unique_id(struct super_block *sb)
1939 1997
1940static int udf_fill_super(struct super_block *sb, void *options, int silent) 1998static int udf_fill_super(struct super_block *sb, void *options, int silent)
1941{ 1999{
1942 int ret; 2000 int ret = -EINVAL;
1943 struct inode *inode = NULL; 2001 struct inode *inode = NULL;
1944 struct udf_options uopt; 2002 struct udf_options uopt;
1945 struct kernel_lb_addr rootdir, fileset; 2003 struct kernel_lb_addr rootdir, fileset;
@@ -2011,7 +2069,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2011 } else { 2069 } else {
2012 uopt.blocksize = bdev_logical_block_size(sb->s_bdev); 2070 uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
2013 ret = udf_load_vrs(sb, &uopt, silent, &fileset); 2071 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
2014 if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) { 2072 if (ret == -EAGAIN && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
2015 if (!silent) 2073 if (!silent)
2016 pr_notice("Rescanning with blocksize %d\n", 2074 pr_notice("Rescanning with blocksize %d\n",
2017 UDF_DEFAULT_BLOCKSIZE); 2075 UDF_DEFAULT_BLOCKSIZE);
@@ -2021,8 +2079,11 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2021 ret = udf_load_vrs(sb, &uopt, silent, &fileset); 2079 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
2022 } 2080 }
2023 } 2081 }
2024 if (!ret) { 2082 if (ret < 0) {
2025 udf_warn(sb, "No partition found (1)\n"); 2083 if (ret == -EAGAIN) {
2084 udf_warn(sb, "No partition found (1)\n");
2085 ret = -EINVAL;
2086 }
2026 goto error_out; 2087 goto error_out;
2027 } 2088 }
2028 2089
@@ -2040,6 +2101,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2040 udf_err(sb, "minUDFReadRev=%x (max is %x)\n", 2101 udf_err(sb, "minUDFReadRev=%x (max is %x)\n",
2041 le16_to_cpu(lvidiu->minUDFReadRev), 2102 le16_to_cpu(lvidiu->minUDFReadRev),
2042 UDF_MAX_READ_VERSION); 2103 UDF_MAX_READ_VERSION);
2104 ret = -EINVAL;
2043 goto error_out; 2105 goto error_out;
2044 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) 2106 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
2045 sb->s_flags |= MS_RDONLY; 2107 sb->s_flags |= MS_RDONLY;
@@ -2054,6 +2116,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2054 2116
2055 if (!sbi->s_partitions) { 2117 if (!sbi->s_partitions) {
2056 udf_warn(sb, "No partition found (2)\n"); 2118 udf_warn(sb, "No partition found (2)\n");
2119 ret = -EINVAL;
2057 goto error_out; 2120 goto error_out;
2058 } 2121 }
2059 2122
@@ -2065,6 +2128,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2065 2128
2066 if (udf_find_fileset(sb, &fileset, &rootdir)) { 2129 if (udf_find_fileset(sb, &fileset, &rootdir)) {
2067 udf_warn(sb, "No fileset found\n"); 2130 udf_warn(sb, "No fileset found\n");
2131 ret = -EINVAL;
2068 goto error_out; 2132 goto error_out;
2069 } 2133 }
2070 2134
@@ -2086,6 +2150,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2086 if (!inode) { 2150 if (!inode) {
2087 udf_err(sb, "Error in udf_iget, block=%d, partition=%d\n", 2151 udf_err(sb, "Error in udf_iget, block=%d, partition=%d\n",
2088 rootdir.logicalBlockNum, rootdir.partitionReferenceNum); 2152 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
2153 ret = -EIO;
2089 goto error_out; 2154 goto error_out;
2090 } 2155 }
2091 2156
@@ -2093,6 +2158,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2093 sb->s_root = d_make_root(inode); 2158 sb->s_root = d_make_root(inode);
2094 if (!sb->s_root) { 2159 if (!sb->s_root) {
2095 udf_err(sb, "Couldn't allocate root dentry\n"); 2160 udf_err(sb, "Couldn't allocate root dentry\n");
2161 ret = -ENOMEM;
2096 goto error_out; 2162 goto error_out;
2097 } 2163 }
2098 sb->s_maxbytes = MAX_LFS_FILESIZE; 2164 sb->s_maxbytes = MAX_LFS_FILESIZE;
@@ -2113,7 +2179,7 @@ error_out:
2113 kfree(sbi); 2179 kfree(sbi);
2114 sb->s_fs_info = NULL; 2180 sb->s_fs_info = NULL;
2115 2181
2116 return -EINVAL; 2182 return ret;
2117} 2183}
2118 2184
2119void _udf_err(struct super_block *sb, const char *function, 2185void _udf_err(struct super_block *sb, const char *function,