summaryrefslogtreecommitdiffstats
path: root/fs/udf/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/super.c')
-rw-r--r--fs/udf/super.c261
1 files changed, 152 insertions, 109 deletions
diff --git a/fs/udf/super.c b/fs/udf/super.c
index a14346137361..8c28e93e9b73 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -92,10 +92,6 @@ static void udf_put_super(struct super_block *);
92static int udf_sync_fs(struct super_block *, int); 92static int udf_sync_fs(struct super_block *, int);
93static int udf_remount_fs(struct super_block *, int *, char *); 93static int udf_remount_fs(struct super_block *, int *, char *);
94static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad); 94static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
95static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *,
96 struct kernel_lb_addr *);
97static void udf_load_fileset(struct super_block *, struct buffer_head *,
98 struct kernel_lb_addr *);
99static void udf_open_lvid(struct super_block *); 95static void udf_open_lvid(struct super_block *);
100static void udf_close_lvid(struct super_block *); 96static void udf_close_lvid(struct super_block *);
101static unsigned int udf_count_free(struct super_block *); 97static unsigned int udf_count_free(struct super_block *);
@@ -151,9 +147,11 @@ static struct inode *udf_alloc_inode(struct super_block *sb)
151 147
152 ei->i_unique = 0; 148 ei->i_unique = 0;
153 ei->i_lenExtents = 0; 149 ei->i_lenExtents = 0;
150 ei->i_lenStreams = 0;
154 ei->i_next_alloc_block = 0; 151 ei->i_next_alloc_block = 0;
155 ei->i_next_alloc_goal = 0; 152 ei->i_next_alloc_goal = 0;
156 ei->i_strat4096 = 0; 153 ei->i_strat4096 = 0;
154 ei->i_streamdir = 0;
157 init_rwsem(&ei->i_data_sem); 155 init_rwsem(&ei->i_data_sem);
158 ei->cached_extent.lstart = -1; 156 ei->cached_extent.lstart = -1;
159 spin_lock_init(&ei->i_extent_cache_lock); 157 spin_lock_init(&ei->i_extent_cache_lock);
@@ -271,8 +269,7 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
271 int nr_groups = bitmap->s_nr_groups; 269 int nr_groups = bitmap->s_nr_groups;
272 270
273 for (i = 0; i < nr_groups; i++) 271 for (i = 0; i < nr_groups; i++)
274 if (bitmap->s_block_bitmap[i]) 272 brelse(bitmap->s_block_bitmap[i]);
275 brelse(bitmap->s_block_bitmap[i]);
276 273
277 kvfree(bitmap); 274 kvfree(bitmap);
278} 275}
@@ -646,16 +643,67 @@ out_unlock:
646 return error; 643 return error;
647} 644}
648 645
649/* Check Volume Structure Descriptors (ECMA 167 2/9.1) */ 646/*
650/* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ 647 * Check VSD descriptor. Returns -1 in case we are at the end of volume
651static loff_t udf_check_vsd(struct super_block *sb) 648 * recognition area, 0 if the descriptor is valid but non-interesting, 1 if
649 * we found one of NSR descriptors we are looking for.
650 */
651static int identify_vsd(const struct volStructDesc *vsd)
652{
653 int ret = 0;
654
655 if (!memcmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
656 switch (vsd->structType) {
657 case 0:
658 udf_debug("ISO9660 Boot Record found\n");
659 break;
660 case 1:
661 udf_debug("ISO9660 Primary Volume Descriptor found\n");
662 break;
663 case 2:
664 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
665 break;
666 case 3:
667 udf_debug("ISO9660 Volume Partition Descriptor found\n");
668 break;
669 case 255:
670 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
671 break;
672 default:
673 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
674 break;
675 }
676 } else if (!memcmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
677 ; /* ret = 0 */
678 else if (!memcmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
679 ret = 1;
680 else if (!memcmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
681 ret = 1;
682 else if (!memcmp(vsd->stdIdent, VSD_STD_ID_BOOT2, VSD_STD_ID_LEN))
683 ; /* ret = 0 */
684 else if (!memcmp(vsd->stdIdent, VSD_STD_ID_CDW02, VSD_STD_ID_LEN))
685 ; /* ret = 0 */
686 else {
687 /* TEA01 or invalid id : end of volume recognition area */
688 ret = -1;
689 }
690
691 return ret;
692}
693
694/*
695 * Check Volume Structure Descriptors (ECMA 167 2/9.1)
696 * We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1)
697 * @return 1 if NSR02 or NSR03 found,
698 * -1 if first sector read error, 0 otherwise
699 */
700static int udf_check_vsd(struct super_block *sb)
652{ 701{
653 struct volStructDesc *vsd = NULL; 702 struct volStructDesc *vsd = NULL;
654 loff_t sector = VSD_FIRST_SECTOR_OFFSET; 703 loff_t sector = VSD_FIRST_SECTOR_OFFSET;
655 int sectorsize; 704 int sectorsize;
656 struct buffer_head *bh = NULL; 705 struct buffer_head *bh = NULL;
657 int nsr02 = 0; 706 int nsr = 0;
658 int nsr03 = 0;
659 struct udf_sb_info *sbi; 707 struct udf_sb_info *sbi;
660 708
661 sbi = UDF_SB(sb); 709 sbi = UDF_SB(sb);
@@ -679,71 +727,36 @@ static loff_t udf_check_vsd(struct super_block *sb)
679 * activity. This actually happened with uninitialised SSD partitions 727 * activity. This actually happened with uninitialised SSD partitions
680 * (all 0xFF) before the check for the limit and all valid IDs were 728 * (all 0xFF) before the check for the limit and all valid IDs were
681 * added */ 729 * added */
682 for (; !nsr02 && !nsr03 && sector < VSD_MAX_SECTOR_OFFSET; 730 for (; !nsr && sector < VSD_MAX_SECTOR_OFFSET; sector += sectorsize) {
683 sector += sectorsize) {
684 /* Read a block */ 731 /* Read a block */
685 bh = udf_tread(sb, sector >> sb->s_blocksize_bits); 732 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
686 if (!bh) 733 if (!bh)
687 break; 734 break;
688 735
689 /* Look for ISO descriptors */
690 vsd = (struct volStructDesc *)(bh->b_data + 736 vsd = (struct volStructDesc *)(bh->b_data +
691 (sector & (sb->s_blocksize - 1))); 737 (sector & (sb->s_blocksize - 1)));
692 738 nsr = identify_vsd(vsd);
693 if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, 739 /* Found NSR or end? */
694 VSD_STD_ID_LEN)) { 740 if (nsr) {
695 switch (vsd->structType) {
696 case 0:
697 udf_debug("ISO9660 Boot Record found\n");
698 break;
699 case 1:
700 udf_debug("ISO9660 Primary Volume Descriptor found\n");
701 break;
702 case 2:
703 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
704 break;
705 case 3:
706 udf_debug("ISO9660 Volume Partition Descriptor found\n");
707 break;
708 case 255:
709 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
710 break;
711 default:
712 udf_debug("ISO9660 VRS (%u) found\n",
713 vsd->structType);
714 break;
715 }
716 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
717 VSD_STD_ID_LEN))
718 ; /* nothing */
719 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
720 VSD_STD_ID_LEN)) {
721 brelse(bh);
722 break;
723 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
724 VSD_STD_ID_LEN))
725 nsr02 = sector;
726 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
727 VSD_STD_ID_LEN))
728 nsr03 = sector;
729 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BOOT2,
730 VSD_STD_ID_LEN))
731 ; /* nothing */
732 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CDW02,
733 VSD_STD_ID_LEN))
734 ; /* nothing */
735 else {
736 /* invalid id : end of volume recognition area */
737 brelse(bh); 741 brelse(bh);
738 break; 742 break;
739 } 743 }
744 /*
745 * Special handling for improperly formatted VRS (e.g., Win10)
746 * where components are separated by 2048 bytes even though
747 * sectors are 4K
748 */
749 if (sb->s_blocksize == 4096) {
750 nsr = identify_vsd(vsd + 1);
751 /* Ignore unknown IDs... */
752 if (nsr < 0)
753 nsr = 0;
754 }
740 brelse(bh); 755 brelse(bh);
741 } 756 }
742 757
743 if (nsr03) 758 if (nsr > 0)
744 return nsr03; 759 return 1;
745 else if (nsr02)
746 return nsr02;
747 else if (!bh && sector - (sbi->s_session << sb->s_blocksize_bits) == 760 else if (!bh && sector - (sbi->s_session << sb->s_blocksize_bits) ==
748 VSD_FIRST_SECTOR_OFFSET) 761 VSD_FIRST_SECTOR_OFFSET)
749 return -1; 762 return -1;
@@ -751,34 +764,82 @@ static loff_t udf_check_vsd(struct super_block *sb)
751 return 0; 764 return 0;
752} 765}
753 766
767static int udf_verify_domain_identifier(struct super_block *sb,
768 struct regid *ident, char *dname)
769{
770 struct domainEntityIDSuffix *suffix;
771
772 if (memcmp(ident->ident, UDF_ID_COMPLIANT, strlen(UDF_ID_COMPLIANT))) {
773 udf_warn(sb, "Not OSTA UDF compliant %s descriptor.\n", dname);
774 goto force_ro;
775 }
776 if (ident->flags & (1 << ENTITYID_FLAGS_DIRTY)) {
777 udf_warn(sb, "Possibly not OSTA UDF compliant %s descriptor.\n",
778 dname);
779 goto force_ro;
780 }
781 suffix = (struct domainEntityIDSuffix *)ident->identSuffix;
782 if (suffix->flags & (1 << ENTITYIDSUFFIX_FLAGS_HARDWRITEPROTECT) ||
783 suffix->flags & (1 << ENTITYIDSUFFIX_FLAGS_SOFTWRITEPROTECT)) {
784 if (!sb_rdonly(sb)) {
785 udf_warn(sb, "Descriptor for %s marked write protected."
786 " Forcing read only mount.\n", dname);
787 }
788 goto force_ro;
789 }
790 return 0;
791
792force_ro:
793 if (!sb_rdonly(sb))
794 return -EACCES;
795 UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
796 return 0;
797}
798
799static int udf_load_fileset(struct super_block *sb, struct fileSetDesc *fset,
800 struct kernel_lb_addr *root)
801{
802 int ret;
803
804 ret = udf_verify_domain_identifier(sb, &fset->domainIdent, "file set");
805 if (ret < 0)
806 return ret;
807
808 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
809 UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
810
811 udf_debug("Rootdir at block=%u, partition=%u\n",
812 root->logicalBlockNum, root->partitionReferenceNum);
813 return 0;
814}
815
754static int udf_find_fileset(struct super_block *sb, 816static int udf_find_fileset(struct super_block *sb,
755 struct kernel_lb_addr *fileset, 817 struct kernel_lb_addr *fileset,
756 struct kernel_lb_addr *root) 818 struct kernel_lb_addr *root)
757{ 819{
758 struct buffer_head *bh = NULL; 820 struct buffer_head *bh = NULL;
759 uint16_t ident; 821 uint16_t ident;
822 int ret;
760 823
761 if (fileset->logicalBlockNum != 0xFFFFFFFF || 824 if (fileset->logicalBlockNum == 0xFFFFFFFF &&
762 fileset->partitionReferenceNum != 0xFFFF) { 825 fileset->partitionReferenceNum == 0xFFFF)
763 bh = udf_read_ptagged(sb, fileset, 0, &ident); 826 return -EINVAL;
764
765 if (!bh) {
766 return 1;
767 } else if (ident != TAG_IDENT_FSD) {
768 brelse(bh);
769 return 1;
770 }
771
772 udf_debug("Fileset at block=%u, partition=%u\n",
773 fileset->logicalBlockNum,
774 fileset->partitionReferenceNum);
775 827
776 UDF_SB(sb)->s_partition = fileset->partitionReferenceNum; 828 bh = udf_read_ptagged(sb, fileset, 0, &ident);
777 udf_load_fileset(sb, bh, root); 829 if (!bh)
830 return -EIO;
831 if (ident != TAG_IDENT_FSD) {
778 brelse(bh); 832 brelse(bh);
779 return 0; 833 return -EINVAL;
780 } 834 }
781 return 1; 835
836 udf_debug("Fileset at block=%u, partition=%u\n",
837 fileset->logicalBlockNum, fileset->partitionReferenceNum);
838
839 UDF_SB(sb)->s_partition = fileset->partitionReferenceNum;
840 ret = udf_load_fileset(sb, (struct fileSetDesc *)bh->b_data, root);
841 brelse(bh);
842 return ret;
782} 843}
783 844
784/* 845/*
@@ -794,9 +855,7 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
794 struct buffer_head *bh; 855 struct buffer_head *bh;
795 uint16_t ident; 856 uint16_t ident;
796 int ret = -ENOMEM; 857 int ret = -ENOMEM;
797#ifdef UDFFS_DEBUG
798 struct timestamp *ts; 858 struct timestamp *ts;
799#endif
800 859
801 outstr = kmalloc(128, GFP_NOFS); 860 outstr = kmalloc(128, GFP_NOFS);
802 if (!outstr) 861 if (!outstr)
@@ -817,13 +876,10 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
817 876
818 udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time, 877 udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
819 pvoldesc->recordingDateAndTime); 878 pvoldesc->recordingDateAndTime);
820#ifdef UDFFS_DEBUG
821 ts = &pvoldesc->recordingDateAndTime; 879 ts = &pvoldesc->recordingDateAndTime;
822 udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n", 880 udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n",
823 le16_to_cpu(ts->year), ts->month, ts->day, ts->hour, 881 le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
824 ts->minute, le16_to_cpu(ts->typeAndTimezone)); 882 ts->minute, le16_to_cpu(ts->typeAndTimezone));
825#endif
826
827 883
828 ret = udf_dstrCS0toChar(sb, outstr, 31, pvoldesc->volIdent, 32); 884 ret = udf_dstrCS0toChar(sb, outstr, 31, pvoldesc->volIdent, 32);
829 if (ret < 0) { 885 if (ret < 0) {
@@ -939,21 +995,6 @@ static int udf_load_metadata_files(struct super_block *sb, int partition,
939 return 0; 995 return 0;
940} 996}
941 997
942static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
943 struct kernel_lb_addr *root)
944{
945 struct fileSetDesc *fset;
946
947 fset = (struct fileSetDesc *)bh->b_data;
948
949 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
950
951 UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
952
953 udf_debug("Rootdir at block=%u, partition=%u\n",
954 root->logicalBlockNum, root->partitionReferenceNum);
955}
956
957int udf_compute_nr_groups(struct super_block *sb, u32 partition) 998int udf_compute_nr_groups(struct super_block *sb, u32 partition)
958{ 999{
959 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; 1000 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
@@ -1238,9 +1279,7 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
1238 * PHYSICAL partitions are already set up 1279 * PHYSICAL partitions are already set up
1239 */ 1280 */
1240 type1_idx = i; 1281 type1_idx = i;
1241#ifdef UDFFS_DEBUG
1242 map = NULL; /* supress 'maybe used uninitialized' warning */ 1282 map = NULL; /* supress 'maybe used uninitialized' warning */
1243#endif
1244 for (i = 0; i < sbi->s_partitions; i++) { 1283 for (i = 0; i < sbi->s_partitions; i++) {
1245 map = &sbi->s_partmaps[i]; 1284 map = &sbi->s_partmaps[i];
1246 1285
@@ -1364,6 +1403,10 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1364 goto out_bh; 1403 goto out_bh;
1365 } 1404 }
1366 1405
1406 ret = udf_verify_domain_identifier(sb, &lvd->domainIdent,
1407 "logical volume");
1408 if (ret)
1409 goto out_bh;
1367 ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps)); 1410 ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1368 if (ret) 1411 if (ret)
1369 goto out_bh; 1412 goto out_bh;
@@ -1915,7 +1958,7 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1915 int silent, struct kernel_lb_addr *fileset) 1958 int silent, struct kernel_lb_addr *fileset)
1916{ 1959{
1917 struct udf_sb_info *sbi = UDF_SB(sb); 1960 struct udf_sb_info *sbi = UDF_SB(sb);
1918 loff_t nsr_off; 1961 int nsr = 0;
1919 int ret; 1962 int ret;
1920 1963
1921 if (!sb_set_blocksize(sb, uopt->blocksize)) { 1964 if (!sb_set_blocksize(sb, uopt->blocksize)) {
@@ -1926,13 +1969,13 @@ static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1926 sbi->s_last_block = uopt->lastblock; 1969 sbi->s_last_block = uopt->lastblock;
1927 if (!uopt->novrs) { 1970 if (!uopt->novrs) {
1928 /* Check that it is NSR02 compliant */ 1971 /* Check that it is NSR02 compliant */
1929 nsr_off = udf_check_vsd(sb); 1972 nsr = udf_check_vsd(sb);
1930 if (!nsr_off) { 1973 if (!nsr) {
1931 if (!silent) 1974 if (!silent)
1932 udf_warn(sb, "No VRS found\n"); 1975 udf_warn(sb, "No VRS found\n");
1933 return -EINVAL; 1976 return -EINVAL;
1934 } 1977 }
1935 if (nsr_off == -1) 1978 if (nsr == -1)
1936 udf_debug("Failed to read sector at offset %d. " 1979 udf_debug("Failed to read sector at offset %d. "
1937 "Assuming open disc. Skipping validity " 1980 "Assuming open disc. Skipping validity "
1938 "check\n", VSD_FIRST_SECTOR_OFFSET); 1981 "check\n", VSD_FIRST_SECTOR_OFFSET);
@@ -2216,9 +2259,9 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
2216 UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT); 2259 UDF_SET_FLAG(sb, UDF_FLAG_RW_INCOMPAT);
2217 } 2260 }
2218 2261
2219 if (udf_find_fileset(sb, &fileset, &rootdir)) { 2262 ret = udf_find_fileset(sb, &fileset, &rootdir);
2263 if (ret < 0) {
2220 udf_warn(sb, "No fileset found\n"); 2264 udf_warn(sb, "No fileset found\n");
2221 ret = -EINVAL;
2222 goto error_out; 2265 goto error_out;
2223 } 2266 }
2224 2267