Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[pandora-kernel.git] / fs / udf / super.c
index c5fef85..44cc702 100644 (file)
@@ -56,6 +56,7 @@
 #include <linux/mount.h>
 #include <linux/seq_file.h>
 #include <linux/bitmap.h>
+#include <linux/crc-itu-t.h>
 #include <asm/byteorder.h>
 
 #include "udf_sb.h"
@@ -84,7 +85,6 @@ static void udf_write_super(struct super_block *);
 static int udf_remount_fs(struct super_block *, int *, char *);
 static int udf_check_valid(struct super_block *, int, int);
 static int udf_vrs(struct super_block *sb, int silent);
-static int udf_load_partition(struct super_block *, kernel_lb_addr *);
 static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
 static void udf_find_anchor(struct super_block *);
 static int udf_find_fileset(struct super_block *, kernel_lb_addr *,
@@ -240,7 +240,7 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
        sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
                                  GFP_KERNEL);
        if (!sbi->s_partmaps) {
-               udf_error(sb, __FUNCTION__,
+               udf_error(sb, __func__,
                          "Unable to allocate space for %d partition maps",
                          count);
                sbi->s_partitions = 0;
@@ -588,7 +588,7 @@ static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
 static int udf_vrs(struct super_block *sb, int silent)
 {
        struct volStructDesc *vsd = NULL;
-       int sector = 32768;
+       loff_t sector = 32768;
        int sectorsize;
        struct buffer_head *bh = NULL;
        int iso9660 = 0;
@@ -609,7 +609,8 @@ static int udf_vrs(struct super_block *sb, int silent)
        sector += (sbi->s_session << sb->s_blocksize_bits);
 
        udf_debug("Starting at sector %u (%ld byte sectors)\n",
-                 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
+                 (unsigned int)(sector >> sb->s_blocksize_bits),
+                 sb->s_blocksize);
        /* Process the sequence (if applicable) */
        for (; !nsr02 && !nsr03; sector += sectorsize) {
                /* Read a block */
@@ -679,149 +680,118 @@ static int udf_vrs(struct super_block *sb, int silent)
 }
 
 /*
- * udf_find_anchor
- *
- * PURPOSE
- *     Find an anchor volume descriptor.
- *
- * PRE-CONDITIONS
- *     sb                      Pointer to _locked_ superblock.
- *     lastblock               Last block on media.
- *
- * POST-CONDITIONS
- *     <return>                1 if not found, 0 if ok
- *
- * HISTORY
- *     July 1, 1997 - Andrew E. Mileski
- *     Written, tested, and released.
+ * Check whether there is an anchor block in the given block
  */
-static void udf_find_anchor(struct super_block *sb)
+static int udf_check_anchor_block(struct super_block *sb, sector_t block)
 {
-       int lastblock;
-       struct buffer_head *bh = NULL;
+       struct buffer_head *bh;
        uint16_t ident;
-       uint32_t location;
+
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
+           udf_fixed_to_variable(block) >=
+           sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
+               return 0;
+
+       bh = udf_read_tagged(sb, block, block, &ident);
+       if (!bh)
+               return 0;
+       brelse(bh);
+
+       return ident == TAG_IDENT_AVDP;
+}
+
+/* Search for an anchor volume descriptor pointer */
+static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock)
+{
+       sector_t last[6];
        int i;
-       struct udf_sb_info *sbi;
+       struct udf_sb_info *sbi = UDF_SB(sb);
 
-       sbi = UDF_SB(sb);
-       lastblock = sbi->s_last_block;
-
-       if (lastblock) {
-               int varlastblock = udf_variable_to_fixed(lastblock);
-               int last[] =  { lastblock, lastblock - 2,
-                               lastblock - 150, lastblock - 152,
-                               varlastblock, varlastblock - 2,
-                               varlastblock - 150, varlastblock - 152 };
-
-               lastblock = 0;
-
-               /* Search for an anchor volume descriptor pointer */
-
-               /*  according to spec, anchor is in either:
-                *     block 256
-                *     lastblock-256
-                *     lastblock
-                *  however, if the disc isn't closed, it could be 512 */
-
-               for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
-                       ident = location = 0;
-                       if (last[i] >= 0) {
-                               bh = sb_bread(sb, last[i]);
-                               if (bh) {
-                                       tag *t = (tag *)bh->b_data;
-                                       ident = le16_to_cpu(t->tagIdent);
-                                       location = le32_to_cpu(t->tagLocation);
-                                       brelse(bh);
-                               }
-                       }
+       last[0] = lastblock;
+       last[1] = last[0] - 1;
+       last[2] = last[0] + 1;
+       last[3] = last[0] - 2;
+       last[4] = last[0] - 150;
+       last[5] = last[0] - 152;
+
+       /*  according to spec, anchor is in either:
+        *     block 256
+        *     lastblock-256
+        *     lastblock
+        *  however, if the disc isn't closed, it could be 512 */
+
+       for (i = 0; i < ARRAY_SIZE(last); i++) {
+               if (last[i] < 0)
+                       continue;
+               if (last[i] >= sb->s_bdev->bd_inode->i_size >>
+                               sb->s_blocksize_bits)
+                       continue;
 
-                       if (ident == TAG_IDENT_AVDP) {
-                               if (location == last[i] - sbi->s_session) {
-                                       lastblock = last[i] - sbi->s_session;
-                                       sbi->s_anchor[0] = lastblock;
-                                       sbi->s_anchor[1] = lastblock - 256;
-                               } else if (location ==
-                                               udf_variable_to_fixed(last[i]) -
-                                                       sbi->s_session) {
-                                       UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
-                                       lastblock =
-                                               udf_variable_to_fixed(last[i]) -
-                                                       sbi->s_session;
-                                       sbi->s_anchor[0] = lastblock;
-                                       sbi->s_anchor[1] = lastblock - 256 -
-                                                               sbi->s_session;
-                               } else {
-                                       udf_debug("Anchor found at block %d, "
-                                                 "location mismatch %d.\n",
-                                                 last[i], location);
-                               }
-                       } else if (ident == TAG_IDENT_FE ||
-                                       ident == TAG_IDENT_EFE) {
-                               lastblock = last[i];
-                               sbi->s_anchor[3] = 512;
-                       } else {
-                               ident = location = 0;
-                               if (last[i] >= 256) {
-                                       bh = sb_bread(sb, last[i] - 256);
-                                       if (bh) {
-                                               tag *t = (tag *)bh->b_data;
-                                               ident = le16_to_cpu(
-                                                               t->tagIdent);
-                                               location = le32_to_cpu(
-                                                               t->tagLocation);
-                                               brelse(bh);
-                                       }
-                               }
+               if (udf_check_anchor_block(sb, last[i])) {
+                       sbi->s_anchor[0] = last[i];
+                       sbi->s_anchor[1] = last[i] - 256;
+                       return last[i];
+               }
 
-                               if (ident == TAG_IDENT_AVDP &&
-                                   location == last[i] - 256 -
-                                               sbi->s_session) {
-                                       lastblock = last[i];
-                                       sbi->s_anchor[1] = last[i] - 256;
-                               } else {
-                                       ident = location = 0;
-                                       if (last[i] >= 312 + sbi->s_session) {
-                                               bh = sb_bread(sb,
-                                                               last[i] - 312 -
-                                                               sbi->s_session);
-                                               if (bh) {
-                                                       tag *t = (tag *)
-                                                                bh->b_data;
-                                                       ident = le16_to_cpu(
-                                                               t->tagIdent);
-                                                       location = le32_to_cpu(
-                                                               t->tagLocation);
-                                                       brelse(bh);
-                                               }
-                                       }
+               if (last[i] < 256)
+                       continue;
 
-                                       if (ident == TAG_IDENT_AVDP &&
-                                           location == udf_variable_to_fixed(last[i]) - 256) {
-                                               UDF_SET_FLAG(sb,
-                                                            UDF_FLAG_VARCONV);
-                                               lastblock = udf_variable_to_fixed(last[i]);
-                                               sbi->s_anchor[1] = lastblock - 256;
-                                       }
-                               }
-                       }
+               if (udf_check_anchor_block(sb, last[i] - 256)) {
+                       sbi->s_anchor[1] = last[i] - 256;
+                       return last[i];
                }
        }
 
-       if (!lastblock) {
-               /* We haven't found the lastblock. check 312 */
-               bh = sb_bread(sb, 312 + sbi->s_session);
-               if (bh) {
-                       tag *t = (tag *)bh->b_data;
-                       ident = le16_to_cpu(t->tagIdent);
-                       location = le32_to_cpu(t->tagLocation);
-                       brelse(bh);
+       if (udf_check_anchor_block(sb, sbi->s_session + 256)) {
+               sbi->s_anchor[0] = sbi->s_session + 256;
+               return last[0];
+       }
+       if (udf_check_anchor_block(sb, sbi->s_session + 512)) {
+               sbi->s_anchor[0] = sbi->s_session + 512;
+               return last[0];
+       }
+       return 0;
+}
 
-                       if (ident == TAG_IDENT_AVDP && location == 256)
-                               UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
-               }
+/*
+ * Find an anchor volume descriptor. The function expects sbi->s_lastblock to
+ * be the last block on the media.
+ *
+ * Return 1 if not found, 0 if ok
+ *
+ */
+static void udf_find_anchor(struct super_block *sb)
+{
+       sector_t lastblock;
+       struct buffer_head *bh = NULL;
+       uint16_t ident;
+       int i;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+
+       lastblock = udf_scan_anchors(sb, sbi->s_last_block);
+       if (lastblock)
+               goto check_anchor;
+
+       /* No anchor found? Try VARCONV conversion of block numbers */
+       UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
+       /* Firstly, we try to not convert number of the last block */
+       lastblock = udf_scan_anchors(sb,
+                               udf_variable_to_fixed(sbi->s_last_block));
+       if (lastblock)
+               goto check_anchor;
+
+       /* Secondly, we try with converted number of the last block */
+       lastblock = udf_scan_anchors(sb, sbi->s_last_block);
+       if (!lastblock) {
+               /* VARCONV didn't help. Clear it. */
+               UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
        }
 
+check_anchor:
+       /*
+        * Check located anchors and the anchor block supplied via
+        * mount options
+        */
        for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
                if (!sbi->s_anchor[i])
                        continue;
@@ -831,9 +801,7 @@ static void udf_find_anchor(struct super_block *sb)
                        sbi->s_anchor[i] = 0;
                else {
                        brelse(bh);
-                       if ((ident != TAG_IDENT_AVDP) &&
-                               (i || (ident != TAG_IDENT_FE &&
-                                       ident != TAG_IDENT_EFE)))
+                       if (ident != TAG_IDENT_AVDP)
                                sbi->s_anchor[i] = 0;
                }
        }
@@ -973,6 +941,101 @@ static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
        return 0;
 }
 
+static int udf_load_metadata_files(struct super_block *sb, int partition)
+{
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct udf_part_map *map;
+       struct udf_meta_data *mdata;
+       kernel_lb_addr addr;
+       int fe_error = 0;
+
+       map = &sbi->s_partmaps[partition];
+       mdata = &map->s_type_specific.s_metadata;
+
+       /* metadata address */
+       addr.logicalBlockNum =  mdata->s_meta_file_loc;
+       addr.partitionReferenceNum = map->s_partition_num;
+
+       udf_debug("Metadata file location: block = %d part = %d\n",
+                         addr.logicalBlockNum, addr.partitionReferenceNum);
+
+       mdata->s_metadata_fe = udf_iget(sb, addr);
+
+       if (mdata->s_metadata_fe == NULL) {
+               udf_warning(sb, __func__, "metadata inode efe not found, "
+                               "will try mirror inode.");
+               fe_error = 1;
+       } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
+                ICBTAG_FLAG_AD_SHORT) {
+               udf_warning(sb, __func__, "metadata inode efe does not have "
+                       "short allocation descriptors!");
+               fe_error = 1;
+               iput(mdata->s_metadata_fe);
+               mdata->s_metadata_fe = NULL;
+       }
+
+       /* mirror file entry */
+       addr.logicalBlockNum = mdata->s_mirror_file_loc;
+       addr.partitionReferenceNum = map->s_partition_num;
+
+       udf_debug("Mirror metadata file location: block = %d part = %d\n",
+                         addr.logicalBlockNum, addr.partitionReferenceNum);
+
+       mdata->s_mirror_fe = udf_iget(sb, addr);
+
+       if (mdata->s_mirror_fe == NULL) {
+               if (fe_error) {
+                       udf_error(sb, __func__, "mirror inode efe not found "
+                       "and metadata inode is missing too, exiting...");
+                       goto error_exit;
+               } else
+                       udf_warning(sb, __func__, "mirror inode efe not found,"
+                                       " but metadata inode is OK");
+       } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
+                ICBTAG_FLAG_AD_SHORT) {
+               udf_warning(sb, __func__, "mirror inode efe does not have "
+                       "short allocation descriptors!");
+               iput(mdata->s_mirror_fe);
+               mdata->s_mirror_fe = NULL;
+               if (fe_error)
+                       goto error_exit;
+       }
+
+       /*
+        * bitmap file entry
+        * Note:
+        * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
+       */
+       if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
+               addr.logicalBlockNum = mdata->s_bitmap_file_loc;
+               addr.partitionReferenceNum = map->s_partition_num;
+
+               udf_debug("Bitmap file location: block = %d part = %d\n",
+                       addr.logicalBlockNum, addr.partitionReferenceNum);
+
+               mdata->s_bitmap_fe = udf_iget(sb, addr);
+
+               if (mdata->s_bitmap_fe == NULL) {
+                       if (sb->s_flags & MS_RDONLY)
+                               udf_warning(sb, __func__, "bitmap inode efe "
+                                       "not found but it's ok since the disc"
+                                       " is mounted read-only");
+                       else {
+                               udf_error(sb, __func__, "bitmap inode efe not "
+                                       "found and attempted read-write mount");
+                               goto error_exit;
+                       }
+               }
+       }
+
+       udf_debug("udf_load_metadata_files Ok\n");
+
+       return 0;
+
+error_exit:
+       return 1;
+}
+
 static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
                             kernel_lb_addr *root)
 {
@@ -1012,7 +1075,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
                bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
 
        if (bitmap == NULL) {
-               udf_error(sb, __FUNCTION__,
+               udf_error(sb, __func__,
                          "Unable to allocate space for bitmap "
                          "and %d buffer_head pointers", nr_groups);
                return NULL;
@@ -1045,8 +1108,8 @@ static int udf_fill_partdesc_info(struct super_block *sb,
        if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
                map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
 
-       udf_debug("Partition (%d:%d type %x) starts at physical %d, "
-                 "block length %d\n", partitionNumber, p_index,
+       udf_debug("Partition (%d type %x) starts at physical %d, "
+                 "block length %d\n", p_index,
                  map->s_partition_type, map->s_partition_root,
                  map->s_partition_len);
 
@@ -1125,14 +1188,58 @@ static int udf_fill_partdesc_info(struct super_block *sb,
        return 0;
 }
 
+static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
+{
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct udf_part_map *map = &sbi->s_partmaps[p_index];
+       kernel_lb_addr ino;
+       struct buffer_head *bh = NULL;
+       struct udf_inode_info *vati;
+       uint32_t pos;
+       struct virtualAllocationTable20 *vat20;
+
+       /* VAT file entry is in the last recorded block */
+       ino.partitionReferenceNum = type1_index;
+       ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
+       sbi->s_vat_inode = udf_iget(sb, ino);
+       if (!sbi->s_vat_inode)
+               return 1;
+
+       if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
+               map->s_type_specific.s_virtual.s_start_offset = 0;
+               map->s_type_specific.s_virtual.s_num_entries =
+                       (sbi->s_vat_inode->i_size - 36) >> 2;
+       } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
+               vati = UDF_I(sbi->s_vat_inode);
+               if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
+                       pos = udf_block_map(sbi->s_vat_inode, 0);
+                       bh = sb_bread(sb, pos);
+                       if (!bh)
+                               return 1;
+                       vat20 = (struct virtualAllocationTable20 *)bh->b_data;
+               } else {
+                       vat20 = (struct virtualAllocationTable20 *)
+                                                       vati->i_ext.i_data;
+               }
+
+               map->s_type_specific.s_virtual.s_start_offset =
+                       le16_to_cpu(vat20->lengthHeader);
+               map->s_type_specific.s_virtual.s_num_entries =
+                       (sbi->s_vat_inode->i_size -
+                               map->s_type_specific.s_virtual.
+                                       s_start_offset) >> 2;
+               brelse(bh);
+       }
+       return 0;
+}
+
 static int udf_load_partdesc(struct super_block *sb, sector_t block)
 {
        struct buffer_head *bh;
        struct partitionDesc *p;
        struct udf_part_map *map;
        struct udf_sb_info *sbi = UDF_SB(sb);
-       bool found = false;
-       int i;
+       int i, type1_idx;
        uint16_t partitionNumber;
        uint16_t ident;
        int ret = 0;
@@ -1145,22 +1252,69 @@ static int udf_load_partdesc(struct super_block *sb, sector_t block)
 
        p = (struct partitionDesc *)bh->b_data;
        partitionNumber = le16_to_cpu(p->partitionNumber);
+
+       /* First scan for TYPE1, SPARABLE and METADATA partitions */
        for (i = 0; i < sbi->s_partitions; i++) {
                map = &sbi->s_partmaps[i];
                udf_debug("Searching map: (%d == %d)\n",
                          map->s_partition_num, partitionNumber);
-               found = map->s_partition_num == partitionNumber;
-               if (found)
+               if (map->s_partition_num == partitionNumber &&
+                   (map->s_partition_type == UDF_TYPE1_MAP15 ||
+                    map->s_partition_type == UDF_SPARABLE_MAP15))
                        break;
        }
 
-       if (!found) {
+       if (i >= sbi->s_partitions) {
                udf_debug("Partition (%d) not found in partition map\n",
                          partitionNumber);
                goto out_bh;
        }
 
        ret = udf_fill_partdesc_info(sb, p, i);
+
+       /*
+        * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
+        * PHYSICAL partitions are already set up
+        */
+       type1_idx = i;
+       for (i = 0; i < sbi->s_partitions; i++) {
+               map = &sbi->s_partmaps[i];
+
+               if (map->s_partition_num == partitionNumber &&
+                   (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
+                    map->s_partition_type == UDF_VIRTUAL_MAP20 ||
+                    map->s_partition_type == UDF_METADATA_MAP25))
+                       break;
+       }
+
+       if (i >= sbi->s_partitions)
+               goto out_bh;
+
+       ret = udf_fill_partdesc_info(sb, p, i);
+       if (ret)
+               goto out_bh;
+
+       if (map->s_partition_type == UDF_METADATA_MAP25) {
+               ret = udf_load_metadata_files(sb, i);
+               if (ret) {
+                       printk(KERN_ERR "UDF-fs: error loading MetaData "
+                       "partition map %d\n", i);
+                       goto out_bh;
+               }
+       } else {
+               ret = udf_load_vat(sb, i, type1_idx);
+               if (ret)
+                       goto out_bh;
+               /*
+                * Mark filesystem read-only if we have a partition with
+                * virtual map since we don't handle writing to it (we
+                * overwrite blocks instead of relocating them).
+                */
+               sb->s_flags |= MS_RDONLY;
+               printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
+                       "because writing to pseudooverwrite partition is "
+                       "not implemented.\n");
+       }
 out_bh:
        /* In case loading failed, we handle cleanup in udf_fill_super */
        brelse(bh);
@@ -1213,12 +1367,12 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
                                u16 suf =
                                        le16_to_cpu(((__le16 *)upm2->partIdent.
                                                        identSuffix)[0]);
-                               if (suf == 0x0150) {
+                               if (suf < 0x0200) {
                                        map->s_partition_type =
                                                        UDF_VIRTUAL_MAP15;
                                        map->s_partition_func =
                                                        udf_get_pblock_virt15;
-                               } else if (suf == 0x0200) {
+                               } else {
                                        map->s_partition_type =
                                                        UDF_VIRTUAL_MAP20;
                                        map->s_partition_func =
@@ -1259,6 +1413,50 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
                                        }
                                }
                                map->s_partition_func = udf_get_pblock_spar15;
+                       } else if (!strncmp(upm2->partIdent.ident,
+                                               UDF_ID_METADATA,
+                                               strlen(UDF_ID_METADATA))) {
+                               struct udf_meta_data *mdata =
+                                       &map->s_type_specific.s_metadata;
+                               struct metadataPartitionMap *mdm =
+                                               (struct metadataPartitionMap *)
+                                               &(lvd->partitionMaps[offset]);
+                               udf_debug("Parsing Logical vol part %d "
+                                       "type %d  id=%s\n", i, type,
+                                       UDF_ID_METADATA);
+
+                               map->s_partition_type = UDF_METADATA_MAP25;
+                               map->s_partition_func = udf_get_pblock_meta25;
+
+                               mdata->s_meta_file_loc   =
+                                       le32_to_cpu(mdm->metadataFileLoc);
+                               mdata->s_mirror_file_loc =
+                                       le32_to_cpu(mdm->metadataMirrorFileLoc);
+                               mdata->s_bitmap_file_loc =
+                                       le32_to_cpu(mdm->metadataBitmapFileLoc);
+                               mdata->s_alloc_unit_size =
+                                       le32_to_cpu(mdm->allocUnitSize);
+                               mdata->s_align_unit_size =
+                                       le16_to_cpu(mdm->alignUnitSize);
+                               mdata->s_dup_md_flag     =
+                                       mdm->flags & 0x01;
+
+                               udf_debug("Metadata Ident suffix=0x%x\n",
+                                       (le16_to_cpu(
+                                        ((__le16 *)
+                                             mdm->partIdent.identSuffix)[0])));
+                               udf_debug("Metadata part num=%d\n",
+                                       le16_to_cpu(mdm->partitionNum));
+                               udf_debug("Metadata part alloc unit size=%d\n",
+                                       le32_to_cpu(mdm->allocUnitSize));
+                               udf_debug("Metadata file loc=%d\n",
+                                       le32_to_cpu(mdm->metadataFileLoc));
+                               udf_debug("Mirror file loc=%d\n",
+                                      le32_to_cpu(mdm->metadataMirrorFileLoc));
+                               udf_debug("Bitmap file loc=%d\n",
+                                      le32_to_cpu(mdm->metadataBitmapFileLoc));
+                               udf_debug("Duplicate Flag: %d %d\n",
+                                       mdata->s_dup_md_flag, mdm->flags);
                        } else {
                                udf_debug("Unknown ident: %s\n",
                                          upm2->partIdent.ident);
@@ -1480,13 +1678,13 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
        return !block;
 }
 
-static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
+static int udf_load_sequence(struct super_block *sb, kernel_lb_addr *fileset)
 {
        struct anchorVolDescPtr *anchor;
        uint16_t ident;
        struct buffer_head *bh;
        long main_s, main_e, reserve_s, reserve_e;
-       int i, j;
+       int i;
        struct udf_sb_info *sbi;
 
        if (!sb)
@@ -1535,77 +1733,6 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
        }
        udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
 
-       for (i = 0; i < sbi->s_partitions; i++) {
-               kernel_lb_addr uninitialized_var(ino);
-               struct udf_part_map *map = &sbi->s_partmaps[i];
-
-               if (map->s_partition_type != UDF_VIRTUAL_MAP15 &&
-                       map->s_partition_type != UDF_VIRTUAL_MAP20)
-                       continue;
-
-               if (!sbi->s_last_block) {
-                       sbi->s_last_block = udf_get_last_block(sb);
-                       udf_find_anchor(sb);
-               }
-
-               if (!sbi->s_last_block) {
-                       udf_debug("Unable to determine Lastblock (For "
-                                       "Virtual Partition)\n");
-                       return 1;
-               }
-
-               for (j = 0; j < sbi->s_partitions; j++) {
-                       struct udf_part_map *map2 = &sbi->s_partmaps[j];
-                       if (j != i &&
-                               map->s_volumeseqnum ==
-                                       map2->s_volumeseqnum &&
-                               map->s_partition_num ==
-                                       map2->s_partition_num) {
-                               ino.partitionReferenceNum = j;
-                               ino.logicalBlockNum =
-                                       sbi->s_last_block -
-                                               map2->s_partition_root;
-                               break;
-                       }
-               }
-
-               if (j == sbi->s_partitions)
-                       return 1;
-
-               sbi->s_vat_inode = udf_iget(sb, ino);
-               if (!sbi->s_vat_inode)
-                       return 1;
-
-               if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
-                       map->s_type_specific.s_virtual.s_start_offset =
-                               udf_ext0_offset(sbi->s_vat_inode);
-                       map->s_type_specific.s_virtual.s_num_entries =
-                               (sbi->s_vat_inode->i_size - 36) >> 2;
-               } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
-                       uint32_t pos;
-                       struct virtualAllocationTable20 *vat20;
-
-                       pos = udf_block_map(sbi->s_vat_inode, 0);
-                       bh = sb_bread(sb, pos);
-                       if (!bh)
-                               return 1;
-                       vat20 = (struct virtualAllocationTable20 *)
-                               bh->b_data +
-                               udf_ext0_offset(sbi->s_vat_inode);
-                       map->s_type_specific.s_virtual.s_start_offset =
-                               le16_to_cpu(vat20->lengthHeader) +
-                               udf_ext0_offset(sbi->s_vat_inode);
-                       map->s_type_specific.s_virtual.s_num_entries =
-                               (sbi->s_vat_inode->i_size -
-                                       map->s_type_specific.s_virtual.
-                                               s_start_offset) >> 2;
-                       brelse(bh);
-               }
-               map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
-               map->s_partition_len =
-                       sbi->s_partmaps[ino.partitionReferenceNum].
-                                                       s_partition_len;
-       }
        return 0;
 }
 
@@ -1628,8 +1755,8 @@ static void udf_open_lvid(struct super_block *sb)
        lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
 
        lvid->descTag.descCRC = cpu_to_le16(
-               udf_crc((char *)lvid + sizeof(tag),
-                       le16_to_cpu(lvid->descTag.descCRCLength), 0));
+               crc_itu_t(0, (char *)lvid + sizeof(tag),
+                       le16_to_cpu(lvid->descTag.descCRCLength)));
 
        lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
        mark_buffer_dirty(bh);
@@ -1663,9 +1790,8 @@ static void udf_close_lvid(struct super_block *sb)
        lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
 
        lvid->descTag.descCRC = cpu_to_le16(
-               udf_crc((char *)lvid + sizeof(tag),
-                       le16_to_cpu(lvid->descTag.descCRCLength),
-                       0));
+                       crc_itu_t(0, (char *)lvid + sizeof(tag),
+                               le16_to_cpu(lvid->descTag.descCRCLength)));
 
        lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
        mark_buffer_dirty(bh);
@@ -1691,6 +1817,7 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
 static void udf_free_partition(struct udf_part_map *map)
 {
        int i;
+       struct udf_meta_data *mdata;
 
        if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
                iput(map->s_uspace.s_table);
@@ -1703,6 +1830,17 @@ static void udf_free_partition(struct udf_part_map *map)
        if (map->s_partition_type == UDF_SPARABLE_MAP15)
                for (i = 0; i < 4; i++)
                        brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
+       else if (map->s_partition_type == UDF_METADATA_MAP25) {
+               mdata = &map->s_type_specific.s_metadata;
+               iput(mdata->s_metadata_fe);
+               mdata->s_metadata_fe = NULL;
+
+               iput(mdata->s_mirror_fe);
+               mdata->s_mirror_fe = NULL;
+
+               iput(mdata->s_bitmap_fe);
+               mdata->s_bitmap_fe = NULL;
+       }
 }
 
 static int udf_fill_super(struct super_block *sb, void *options, int silent)
@@ -1773,7 +1911,6 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        sbi->s_last_block = uopt.lastblock;
        sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
        sbi->s_anchor[2] = uopt.anchor;
-       sbi->s_anchor[3] = 256;
 
        if (udf_check_valid(sb, uopt.novrs, silent)) {
                /* read volume recognition sequences */
@@ -1785,12 +1922,13 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
 
        /* Fill in the rest of the superblock */
        sb->s_op = &udf_sb_ops;
+       sb->s_export_op = &udf_export_ops;
        sb->dq_op = NULL;
        sb->s_dirt = 0;
        sb->s_magic = UDF_SUPER_MAGIC;
        sb->s_time_gran = 1000;
 
-       if (udf_load_partition(sb, &fileset)) {
+       if (udf_load_sequence(sb, &fileset)) {
                printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
                goto error_out;
        }