NTFS: Implement support for sector sizes above 512 bytes (up to the maximum
[safe/jmp/linux-2.6] / fs / ntfs / super.c
index 41aa8eb..489f704 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project.
  *
- * Copyright (c) 2001-2005 Anton Altaparmakov
+ * Copyright (c) 2001-2006 Anton Altaparmakov
  * Copyright (c) 2001,2002 Richard Russon
  *
  * This program/include file is free software; you can redistribute it and/or
@@ -22,6 +22,7 @@
 
 #include <linux/stddef.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/spinlock.h>
 #include <linux/blkdev.h>      /* For bdev_hardsect_size(). */
@@ -126,6 +127,14 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
                if (*v)                                                 \
                        goto needs_val;                                 \
        }
+#define NTFS_GETOPT_OCTAL(option, variable)                            \
+       if (!strcmp(p, option)) {                                       \
+               if (!v || !*v)                                          \
+                       goto needs_arg;                                 \
+               variable = simple_strtoul(ov = v, &v, 8);               \
+               if (*v)                                                 \
+                       goto needs_val;                                 \
+       }
 #define NTFS_GETOPT_BOOL(option, variable)                             \
        if (!strcmp(p, option)) {                                       \
                BOOL val;                                               \
@@ -157,9 +166,9 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
                        *v++ = 0;
                NTFS_GETOPT("uid", uid)
                else NTFS_GETOPT("gid", gid)
-               else NTFS_GETOPT("umask", fmask = dmask)
-               else NTFS_GETOPT("fmask", fmask)
-               else NTFS_GETOPT("dmask", dmask)
+               else NTFS_GETOPT_OCTAL("umask", fmask = dmask)
+               else NTFS_GETOPT_OCTAL("fmask", fmask)
+               else NTFS_GETOPT_OCTAL("dmask", dmask)
                else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier)
                else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
                else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
@@ -435,8 +444,8 @@ static int ntfs_remount(struct super_block *sb, int *flags, char *opt)
 
        ntfs_debug("Entering with remount options string: %s", opt);
 #ifndef NTFS_RW
-       /* For read-only compiled driver, enforce all read-only flags. */
-       *flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+       /* For read-only compiled driver, enforce read-only flag. */
+       *flags |= MS_RDONLY;
 #else /* NTFS_RW */
        /*
         * For the read-write compiled driver, if we are remounting read-write,
@@ -633,7 +642,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
 {
        const char *read_err_str = "Unable to read %s boot sector.";
        struct buffer_head *bh_primary, *bh_backup;
-       long nr_blocks = NTFS_SB(sb)->nr_blocks;
+       sector_t nr_blocks = NTFS_SB(sb)->nr_blocks;
 
        /* Try to read primary boot sector. */
        if ((bh_primary = sb_bread(sb, 0))) {
@@ -680,13 +689,18 @@ hotfix_primary_boot_sector:
                /*
                 * If we managed to read sector zero and the volume is not
                 * read-only, copy the found, valid backup boot sector to the
-                * primary boot sector.
+                * primary boot sector.  Note we only copy the actual boot
+                * sector structure, not the actual whole device sector as that
+                * may be bigger and would potentially damage the $Boot system
+                * file (FIXME: Would be nice to know if the backup boot sector
+                * on a large sector device contains the whole boot loader or
+                * just the first 512 bytes).
                 */
                if (!(sb->s_flags & MS_RDONLY)) {
                        ntfs_warning(sb, "Hot-fix: Recovering invalid primary "
                                        "boot sector from backup copy.");
                        memcpy(bh_primary->b_data, bh_backup->b_data,
-                                       sb->s_blocksize);
+                                       NTFS_BLOCK_SIZE);
                        mark_buffer_dirty(bh_primary);
                        sync_dirty_buffer(bh_primary);
                        if (buffer_uptodate(bh_primary)) {
@@ -725,9 +739,13 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
                        vol->sector_size);
        ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits,
                        vol->sector_size_bits);
-       if (vol->sector_size != vol->sb->s_blocksize)
-               ntfs_warning(vol->sb, "The boot sector indicates a sector size "
-                               "different from the device sector size.");
+       if (vol->sector_size < vol->sb->s_blocksize) {
+               ntfs_error(vol->sb, "Sector size (%i) is smaller than the "
+                               "device block size (%lu).  This is not "
+                               "supported.  Sorry.", vol->sector_size,
+                               vol->sb->s_blocksize);
+               return FALSE;
+       }
        ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster);
        sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1;
        ntfs_debug("sectors_per_cluster_bits = 0x%x",
@@ -740,16 +758,11 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
        ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size,
                        vol->cluster_size);
        ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask);
-       ntfs_debug("vol->cluster_size_bits = %i (0x%x)",
-                       vol->cluster_size_bits, vol->cluster_size_bits);
-       if (vol->sector_size > vol->cluster_size) {
-               ntfs_error(vol->sb, "Sector sizes above the cluster size are "
-                               "not supported.  Sorry.");
-               return FALSE;
-       }
-       if (vol->sb->s_blocksize > vol->cluster_size) {
-               ntfs_error(vol->sb, "Cluster sizes smaller than the device "
-                               "sector size are not supported.  Sorry.");
+       ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits);
+       if (vol->cluster_size < vol->sector_size) {
+               ntfs_error(vol->sb, "Cluster size (%i) is smaller than the "
+                               "sector size (%i).  This is not supported.  "
+                               "Sorry.", vol->cluster_size, vol->sector_size);
                return FALSE;
        }
        clusters_per_mft_record = b->clusters_per_mft_record;
@@ -778,11 +791,18 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
         * we store $MFT/$DATA, the table of mft records in the page cache.
         */
        if (vol->mft_record_size > PAGE_CACHE_SIZE) {
-               ntfs_error(vol->sb, "Mft record size %i (0x%x) exceeds the "
-                               "page cache size on your system %lu (0x%lx).  "
+               ntfs_error(vol->sb, "Mft record size (%i) exceeds the "
+                               "PAGE_CACHE_SIZE on your system (%lu).  "
                                "This is not supported.  Sorry.",
-                               vol->mft_record_size, vol->mft_record_size,
-                               PAGE_CACHE_SIZE, PAGE_CACHE_SIZE);
+                               vol->mft_record_size, PAGE_CACHE_SIZE);
+               return FALSE;
+       }
+       /* We cannot support mft record sizes below the sector size. */
+       if (vol->mft_record_size < vol->sector_size) {
+               ntfs_error(vol->sb, "Mft record size (%i) is smaller than the "
+                               "sector size (%i).  This is not supported.  "
+                               "Sorry.", vol->mft_record_size,
+                               vol->sector_size);
                return FALSE;
        }
        clusters_per_index_record = b->clusters_per_index_record;
@@ -808,6 +828,14 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
        ntfs_debug("vol->index_record_size_bits = %i (0x%x)",
                        vol->index_record_size_bits,
                        vol->index_record_size_bits);
+       /* We cannot support index record sizes below the sector size. */
+       if (vol->index_record_size < vol->sector_size) {
+               ntfs_error(vol->sb, "Index record size (%i) is smaller than "
+                               "the sector size (%i).  This is not "
+                               "supported.  Sorry.", vol->index_record_size,
+                               vol->sector_size);
+               return FALSE;
+       }
        /*
         * Get the size of the volume in clusters and check for 64-bit-ness.
         * Windows currently only uses 32 bits to save the clusters so we do
@@ -837,15 +865,18 @@ static BOOL parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
        }
        ll = sle64_to_cpu(b->mft_lcn);
        if (ll >= vol->nr_clusters) {
-               ntfs_error(vol->sb, "MFT LCN is beyond end of volume.  Weird.");
+               ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of "
+                               "volume.  Weird.", (unsigned long long)ll,
+                               (unsigned long long)ll);
                return FALSE;
        }
        vol->mft_lcn = ll;
        ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn);
        ll = sle64_to_cpu(b->mftmirr_lcn);
        if (ll >= vol->nr_clusters) {
-               ntfs_error(vol->sb, "MFTMirr LCN is beyond end of volume.  "
-                               "Weird.");
+               ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end "
+                               "of volume.  Weird.", (unsigned long long)ll,
+                               (unsigned long long)ll);
                return FALSE;
        }
        vol->mftmirr_lcn = ll;
@@ -1133,7 +1164,8 @@ mft_unmap_out:
  *
  * Return TRUE on success or FALSE on error.
  */
-static BOOL load_and_check_logfile(ntfs_volume *vol)
+static BOOL load_and_check_logfile(ntfs_volume *vol,
+               RESTART_PAGE_HEADER **rp)
 {
        struct inode *tmp_ino;
 
@@ -1145,7 +1177,7 @@ static BOOL load_and_check_logfile(ntfs_volume *vol)
                /* Caller will display error message. */
                return FALSE;
        }
-       if (!ntfs_check_logfile(tmp_ino)) {
+       if (!ntfs_check_logfile(tmp_ino, rp)) {
                iput(tmp_ino);
                /* ntfs_check_logfile() will have displayed error output. */
                return FALSE;
@@ -1204,10 +1236,10 @@ static int check_windows_hibernation_status(ntfs_volume *vol)
         * Find the inode number for the hibernation file by looking up the
         * filename hiberfil.sys in the root directory.
         */
-       down(&vol->root_ino->i_sem);
+       mutex_lock(&vol->root_ino->i_mutex);
        mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12,
                        &name);
-       up(&vol->root_ino->i_sem);
+       mutex_unlock(&vol->root_ino->i_mutex);
        if (IS_ERR_MREF(mref)) {
                ret = MREF_ERR(mref);
                /* If the file does not exist, Windows is not hibernated. */
@@ -1298,10 +1330,10 @@ static BOOL load_and_init_quota(ntfs_volume *vol)
         * Find the inode number for the quota file by looking up the filename
         * $Quota in the extended system files directory $Extend.
         */
-       down(&vol->extend_ino->i_sem);
+       mutex_lock(&vol->extend_ino->i_mutex);
        mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6,
                        &name);
-       up(&vol->extend_ino->i_sem);
+       mutex_unlock(&vol->extend_ino->i_mutex);
        if (IS_ERR_MREF(mref)) {
                /*
                 * If the file does not exist, quotas are disabled and have
@@ -1381,10 +1413,10 @@ static BOOL load_and_init_usnjrnl(ntfs_volume *vol)
         * Find the inode number for the transaction log file by looking up the
         * filename $UsnJrnl in the extended system files directory $Extend.
         */
-       down(&vol->extend_ino->i_sem);
+       mutex_lock(&vol->extend_ino->i_mutex);
        mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8,
                        &name);
-       up(&vol->extend_ino->i_sem);
+       mutex_unlock(&vol->extend_ino->i_mutex);
        if (IS_ERR_MREF(mref)) {
                /*
                 * If the file does not exist, transaction logging is disabled,
@@ -1438,7 +1470,7 @@ not_enabled:
        if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) {
                ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max "
                                "attribute (size is 0x%llx but should be at "
-                               "least 0x%x bytes).", i_size_read(tmp_ino),
+                               "least 0x%zx bytes).", i_size_read(tmp_ino),
                                sizeof(USN_HEADER));
                return FALSE;
        }
@@ -1689,6 +1721,7 @@ static BOOL load_system_files(ntfs_volume *vol)
        VOLUME_INFORMATION *vi;
        ntfs_attr_search_ctx *ctx;
 #ifdef NTFS_RW
+       RESTART_PAGE_HEADER *rp;
        int err;
 #endif /* NTFS_RW */
 
@@ -1711,7 +1744,7 @@ static BOOL load_system_files(ntfs_volume *vol)
                                                es3);
                                goto iput_mirr_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s",
                                        !vol->mftmirr_ino ? es1 : es2, es3);
                } else
@@ -1827,7 +1860,7 @@ get_ctx_vol_failed:
                                                es1, es2);
                                goto iput_vol_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
                } else
                        ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1841,8 +1874,9 @@ get_ctx_vol_failed:
         * Get the inode for the logfile, check it and determine if the volume
         * was shutdown cleanly.
         */
-       if (!load_and_check_logfile(vol) ||
-                       !ntfs_is_logfile_clean(vol->logfile_ino)) {
+       rp = NULL;
+       if (!load_and_check_logfile(vol, &rp) ||
+                       !ntfs_is_logfile_clean(vol->logfile_ino, rp)) {
                static const char *es1a = "Failed to load $LogFile";
                static const char *es1b = "$LogFile is not clean";
                static const char *es2 = ".  Mount in Windows.";
@@ -1857,9 +1891,13 @@ get_ctx_vol_failed:
                                                "continue nor on_errors="
                                                "remount-ro was specified%s",
                                                es1, es2);
+                               if (vol->logfile_ino) {
+                                       BUG_ON(!rp);
+                                       ntfs_free(rp);
+                               }
                                goto iput_logfile_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
                } else
                        ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1867,6 +1905,7 @@ get_ctx_vol_failed:
                /* This will prevent a read-write remount. */
                NVolSetErrors(vol);
        }
+       ntfs_free(rp);
 #endif /* NTFS_RW */
        /* Get the root directory inode so we can do path lookups. */
        vol->root_ino = ntfs_iget(sb, FILE_root);
@@ -1903,7 +1942,7 @@ get_ctx_vol_failed:
                                                es1, es2);
                                goto iput_root_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
                } else
                        ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -1927,7 +1966,7 @@ get_ctx_vol_failed:
                        goto iput_root_err_out;
                }
                ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-               sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+               sb->s_flags |= MS_RDONLY;
                /*
                 * Do not set NVolErrors() because ntfs_remount() might manage
                 * to set the dirty flag in which case all would be well.
@@ -1954,7 +1993,7 @@ get_ctx_vol_failed:
                        goto iput_root_err_out;
                }
                ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-               sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+               sb->s_flags |= MS_RDONLY;
                NVolSetErrors(vol);
        }
 #endif
@@ -1973,7 +2012,7 @@ get_ctx_vol_failed:
                        goto iput_root_err_out;
                }
                ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-               sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+               sb->s_flags |= MS_RDONLY;
                NVolSetErrors(vol);
        }
 #endif /* NTFS_RW */
@@ -2014,7 +2053,7 @@ get_ctx_vol_failed:
                                                es1, es2);
                                goto iput_quota_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
                } else
                        ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -2037,7 +2076,7 @@ get_ctx_vol_failed:
                        goto iput_quota_err_out;
                }
                ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-               sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+               sb->s_flags |= MS_RDONLY;
                NVolSetErrors(vol);
        }
        /*
@@ -2058,7 +2097,7 @@ get_ctx_vol_failed:
                                                es1, es2);
                                goto iput_usnjrnl_err_out;
                        }
-                       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+                       sb->s_flags |= MS_RDONLY;
                        ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
                } else
                        ntfs_warning(sb, "%s.  Will not be able to remount "
@@ -2081,7 +2120,7 @@ get_ctx_vol_failed:
                        goto iput_usnjrnl_err_out;
                }
                ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-               sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+               sb->s_flags |= MS_RDONLY;
                NVolSetErrors(vol);
        }
 #endif /* NTFS_RW */
@@ -2296,9 +2335,9 @@ static void ntfs_put_super(struct super_block *sb)
        if (!list_empty(&sb->s_dirty)) {
                const char *s1, *s2;
 
-               down(&vol->mft_ino->i_sem);
+               mutex_lock(&vol->mft_ino->i_mutex);
                truncate_inode_pages(vol->mft_ino->i_mapping, 0);
-               up(&vol->mft_ino->i_sem);
+               mutex_unlock(&vol->mft_ino->i_mutex);
                write_inode_now(vol->mft_ino, 1);
                if (!list_empty(&sb->s_dirty)) {
                        static const char *_s1 = "inodes";
@@ -2669,11 +2708,11 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
        ntfs_volume *vol;
        struct buffer_head *bh;
        struct inode *tmp_ino;
-       int result;
+       int blocksize, result;
 
        ntfs_debug("Entering.");
 #ifndef NTFS_RW
-       sb->s_flags |= MS_RDONLY | MS_NOATIME | MS_NODIRATIME;
+       sb->s_flags |= MS_RDONLY;
 #endif /* ! NTFS_RW */
        /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */
        sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS);
@@ -2708,60 +2747,85 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
        if (!parse_options(vol, (char*)opt))
                goto err_out_now;
 
+       /* We support sector sizes up to the PAGE_CACHE_SIZE. */
+       if (bdev_hardsect_size(sb->s_bdev) > PAGE_CACHE_SIZE) {
+               if (!silent)
+                       ntfs_error(sb, "Device has unsupported sector size "
+                                       "(%i).  The maximum supported sector "
+                                       "size on this architecture is %lu "
+                                       "bytes.",
+                                       bdev_hardsect_size(sb->s_bdev),
+                                       PAGE_CACHE_SIZE);
+               goto err_out_now;
+       }
        /*
-        * TODO: Fail safety check. In the future we should really be able to
-        * cope with this being the case, but for now just bail out.
+        * Setup the device access block size to NTFS_BLOCK_SIZE or the hard
+        * sector size, whichever is bigger.
         */
-       if (bdev_hardsect_size(sb->s_bdev) > NTFS_BLOCK_SIZE) {
+       blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE);
+       if (blocksize < NTFS_BLOCK_SIZE) {
                if (!silent)
-                       ntfs_error(sb, "Device has unsupported hardsect_size.");
+                       ntfs_error(sb, "Unable to set device block size.");
                goto err_out_now;
        }
-
-       /* Setup the device access block size to NTFS_BLOCK_SIZE. */
-       if (sb_set_blocksize(sb, NTFS_BLOCK_SIZE) != NTFS_BLOCK_SIZE) {
+       BUG_ON(blocksize != sb->s_blocksize);
+       ntfs_debug("Set device block size to %i bytes (block size bits %i).",
+                       blocksize, sb->s_blocksize_bits);
+       /* Determine the size of the device in units of block_size bytes. */
+       if (!i_size_read(sb->s_bdev->bd_inode)) {
                if (!silent)
-                       ntfs_error(sb, "Unable to set block size.");
+                       ntfs_error(sb, "Unable to determine device size.");
                goto err_out_now;
        }
-
-       /* Get the size of the device in units of NTFS_BLOCK_SIZE bytes. */
        vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
-                       NTFS_BLOCK_SIZE_BITS;
-
+                       sb->s_blocksize_bits;
        /* Read the boot sector and return unlocked buffer head to it. */
        if (!(bh = read_ntfs_boot_sector(sb, silent))) {
                if (!silent)
                        ntfs_error(sb, "Not an NTFS volume.");
                goto err_out_now;
        }
-
        /*
-        * Extract the data from the boot sector and setup the ntfs super block
+        * Extract the data from the boot sector and setup the ntfs volume
         * using it.
         */
        result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data);
-
-       /* Initialize the cluster and mft allocators. */
-       ntfs_setup_allocators(vol);
-
        brelse(bh);
-
        if (!result) {
                if (!silent)
                        ntfs_error(sb, "Unsupported NTFS filesystem.");
                goto err_out_now;
        }
-
        /*
-        * TODO: When we start coping with sector sizes different from
-        * NTFS_BLOCK_SIZE, we now probably need to set the blocksize of the
-        * device (probably to NTFS_BLOCK_SIZE).
+        * If the boot sector indicates a sector size bigger than the current
+        * device block size, switch the device block size to the sector size.
+        * TODO: It may be possible to support this case even when the set
+        * below fails, we would just be breaking up the i/o for each sector
+        * into multiple blocks for i/o purposes but otherwise it should just
+        * work.  However it is safer to leave disabled until someone hits this
+        * error message and then we can get them to try it without the setting
+        * so we know for sure that it works.
         */
-
+       if (vol->sector_size > blocksize) {
+               blocksize = sb_set_blocksize(sb, vol->sector_size);
+               if (blocksize != vol->sector_size) {
+                       if (!silent)
+                               ntfs_error(sb, "Unable to set device block "
+                                               "size to sector size (%i).",
+                                               vol->sector_size);
+                       goto err_out_now;
+               }
+               BUG_ON(blocksize != sb->s_blocksize);
+               vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
+                               sb->s_blocksize_bits;
+               ntfs_debug("Changed device block size to %i bytes (block size "
+                               "bits %i) to match volume sector size.",
+                               blocksize, sb->s_blocksize_bits);
+       }
+       /* Initialize the cluster and mft allocators. */
+       ntfs_setup_allocators(vol);
        /* Setup remaining fields in the super block. */
        sb->s_magic = NTFS_SB_MAGIC;
-
        /*
         * Ntfs allows 63 bits for the file size, i.e. correct would be:
         *      sb->s_maxbytes = ~0ULL >> 1;
@@ -2771,9 +2835,8 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
         * without overflowing the index or to 2^63 - 1, whichever is smaller.
         */
        sb->s_maxbytes = MAX_LFS_FILESIZE;
-
+       /* Ntfs measures time in 100ns intervals. */
        sb->s_time_gran = 100;
-
        /*
         * Now load the metadata required for the page cache and our address
         * space operations to function. We do this by setting up a specialised
@@ -2971,14 +3034,14 @@ err_out_now:
  * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN
  * (255) Unicode characters + a terminating NULL Unicode character.
  */
-kmem_cache_t *ntfs_name_cache;
+struct kmem_cache *ntfs_name_cache;
 
 /* Slab caches for efficient allocation/deallocation of inodes. */
-kmem_cache_t *ntfs_inode_cache;
-kmem_cache_t *ntfs_big_inode_cache;
+struct kmem_cache *ntfs_inode_cache;
+struct kmem_cache *ntfs_big_inode_cache;
 
 /* Init once constructor for the inode slab cache. */
-static void ntfs_big_inode_init_once(void *foo, kmem_cache_t *cachep,
+static void ntfs_big_inode_init_once(void *foo, struct kmem_cache *cachep,
                unsigned long flags)
 {
        ntfs_inode *ni = (ntfs_inode *)foo;
@@ -2992,8 +3055,8 @@ static void ntfs_big_inode_init_once(void *foo, kmem_cache_t *cachep,
  * Slab caches to optimize allocations and deallocations of attribute search
  * contexts and index contexts, respectively.
  */
-kmem_cache_t *ntfs_attr_ctx_cache;
-kmem_cache_t *ntfs_index_ctx_cache;
+struct kmem_cache *ntfs_attr_ctx_cache;
+struct kmem_cache *ntfs_index_ctx_cache;
 
 /* Driver wide semaphore. */
 DECLARE_MUTEX(ntfs_lock);