]> err.no Git - linux-2.6/blobdiff - fs/ntfs/super.c
[PATCH] proc: Kill proc_mem_inode_operations
[linux-2.6] / fs / ntfs / super.c
index 489f7049146b02c2dc8262674db216cb3f8b6614..0e14acea3f8b831d13dabc6256e10b82d0fe622f 100644 (file)
@@ -472,9 +472,16 @@ static int ntfs_remount(struct super_block *sb, int *flags, char *opt)
                        ntfs_error(sb, "Volume is dirty and read-only%s", es);
                        return -EROFS;
                }
+               if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
+                       ntfs_error(sb, "Volume has been modified by chkdsk "
+                                       "and is read-only%s", es);
+                       return -EROFS;
+               }
                if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
-                       ntfs_error(sb, "Volume has unsupported flags set and "
-                                       "is read-only%s", es);
+                       ntfs_error(sb, "Volume has unsupported flags set "
+                                       "(0x%x) and is read-only%s",
+                                       (unsigned)le16_to_cpu(vol->vol_flags),
+                                       es);
                        return -EROFS;
                }
                if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) {
@@ -1092,26 +1099,38 @@ static BOOL check_mft_mirror(ntfs_volume *vol)
                        kmirr = page_address(mirr_page);
                        ++index;
                }
-               /* Make sure the record is ok. */
-               if (ntfs_is_baad_recordp((le32*)kmft)) {
-                       ntfs_error(sb, "Incomplete multi sector transfer "
-                                       "detected in mft record %i.", i);
+               /* Do not check the record if it is not in use. */
+               if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) {
+                       /* Make sure the record is ok. */
+                       if (ntfs_is_baad_recordp((le32*)kmft)) {
+                               ntfs_error(sb, "Incomplete multi sector "
+                                               "transfer detected in mft "
+                                               "record %i.", i);
 mm_unmap_out:
-                       ntfs_unmap_page(mirr_page);
+                               ntfs_unmap_page(mirr_page);
 mft_unmap_out:
-                       ntfs_unmap_page(mft_page);
-                       return FALSE;
+                               ntfs_unmap_page(mft_page);
+                               return FALSE;
+                       }
                }
-               if (ntfs_is_baad_recordp((le32*)kmirr)) {
-                       ntfs_error(sb, "Incomplete multi sector transfer "
-                                       "detected in mft mirror record %i.", i);
-                       goto mm_unmap_out;
+               /* Do not check the mirror record if it is not in use. */
+               if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) {
+                       if (ntfs_is_baad_recordp((le32*)kmirr)) {
+                               ntfs_error(sb, "Incomplete multi sector "
+                                               "transfer detected in mft "
+                                               "mirror record %i.", i);
+                               goto mm_unmap_out;
+                       }
                }
                /* Get the amount of data in the current record. */
                bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use);
-               if (!bytes || bytes > vol->mft_record_size) {
+               if (bytes < sizeof(MFT_RECORD_OLD) ||
+                               bytes > vol->mft_record_size ||
+                               ntfs_is_baad_recordp((le32*)kmft)) {
                        bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use);
-                       if (!bytes || bytes > vol->mft_record_size)
+                       if (bytes < sizeof(MFT_RECORD_OLD) ||
+                                       bytes > vol->mft_record_size ||
+                                       ntfs_is_baad_recordp((le32*)kmirr))
                                bytes = vol->mft_record_size;
                }
                /* Compare the two records. */
@@ -1658,11 +1677,11 @@ read_partial_upcase_page:
        ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).",
                        i_size, 64 * 1024 * sizeof(ntfschar));
        iput(ino);
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (!default_upcase) {
                ntfs_debug("Using volume specified $UpCase since default is "
                                "not present.");
-               up(&ntfs_lock);
+               mutex_unlock(&ntfs_lock);
                return TRUE;
        }
        max = default_upcase_len;
@@ -1676,12 +1695,12 @@ read_partial_upcase_page:
                vol->upcase = default_upcase;
                vol->upcase_len = max;
                ntfs_nr_upcase_users++;
-               up(&ntfs_lock);
+               mutex_unlock(&ntfs_lock);
                ntfs_debug("Volume specified $UpCase matches default. Using "
                                "default.");
                return TRUE;
        }
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        ntfs_debug("Using volume specified $UpCase since it does not match "
                        "the default.");
        return TRUE;
@@ -1690,17 +1709,17 @@ iput_upcase_failed:
        ntfs_free(vol->upcase);
        vol->upcase = NULL;
 upcase_failed:
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (default_upcase) {
                vol->upcase = default_upcase;
                vol->upcase_len = default_upcase_len;
                ntfs_nr_upcase_users++;
-               up(&ntfs_lock);
+               mutex_unlock(&ntfs_lock);
                ntfs_error(sb, "Failed to load $UpCase from the volume. Using "
                                "default.");
                return TRUE;
        }
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        ntfs_error(sb, "Failed to initialize upcase table.");
        return FALSE;
 }
@@ -1845,11 +1864,24 @@ get_ctx_vol_failed:
        /* Make sure that no unsupported volume flags are set. */
        if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
                static const char *es1a = "Volume is dirty";
-               static const char *es1b = "Volume has unsupported flags set";
-               static const char *es2 = ".  Run chkdsk and mount in Windows.";
-               const char *es1;
-               
-               es1 = vol->vol_flags & VOLUME_IS_DIRTY ? es1a : es1b;
+               static const char *es1b = "Volume has been modified by chkdsk";
+               static const char *es1c = "Volume has unsupported flags set";
+               static const char *es2a = ".  Run chkdsk and mount in Windows.";
+               static const char *es2b = ".  Mount in Windows.";
+               const char *es1, *es2;
+
+               es2 = es2a;
+               if (vol->vol_flags & VOLUME_IS_DIRTY)
+                       es1 = es1a;
+               else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
+                       es1 = es1b;
+                       es2 = es2b;
+               } else {
+                       es1 = es1c;
+                       ntfs_warning(sb, "Unsupported volume flags 0x%x "
+                                       "encountered.",
+                                       (unsigned)le16_to_cpu(vol->vol_flags));
+               }
                /* If a read-write mount, convert it to a read-only mount. */
                if (!(sb->s_flags & MS_RDONLY)) {
                        if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
@@ -2163,12 +2195,12 @@ iput_attrdef_err_out:
 iput_upcase_err_out:
 #endif /* NTFS_RW */
        vol->upcase_len = 0;
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (vol->upcase == default_upcase) {
                ntfs_nr_upcase_users--;
                vol->upcase = NULL;
        }
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        if (vol->upcase) {
                ntfs_free(vol->upcase);
                vol->upcase = NULL;
@@ -2373,7 +2405,7 @@ static void ntfs_put_super(struct super_block *sb)
         * Destroy the global default upcase table if necessary.  Also decrease
         * the number of upcase users if we are a user.
         */
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (vol->upcase == default_upcase) {
                ntfs_nr_upcase_users--;
                vol->upcase = NULL;
@@ -2384,7 +2416,7 @@ static void ntfs_put_super(struct super_block *sb)
        }
        if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
                free_compression_buffers();
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        if (vol->upcase) {
                ntfs_free(vol->upcase);
                vol->upcase = NULL;
@@ -2569,10 +2601,10 @@ static unsigned long __get_nr_free_mft_records(ntfs_volume *vol,
 
 /**
  * ntfs_statfs - return information about mounted NTFS volume
- * @sb:                super block of mounted volume
+ * @dentry:    dentry from mounted volume
  * @sfs:       statfs structure in which to return the information
  *
- * Return information about the mounted NTFS volume @sb in the statfs structure
+ * Return information about the mounted NTFS volume @dentry in the statfs structure
  * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is
  * called). We interpret the values to be correct of the moment in time at
  * which we are called. Most values are variable otherwise and this isn't just
@@ -2585,8 +2617,9 @@ static unsigned long __get_nr_free_mft_records(ntfs_volume *vol,
  *
  * Return 0 on success or -errno on error.
  */
-static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs)
+static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs)
 {
+       struct super_block *sb = dentry->d_sb;
        s64 size;
        ntfs_volume *vol = NTFS_SB(sb);
        ntfs_inode *mft_ni = NTFS_I(vol->mft_ino);
@@ -2858,7 +2891,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
                        ntfs_error(sb, "Failed to load essential metadata.");
                goto iput_tmp_ino_err_out_now;
        }
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        /*
         * The current mount is a compression user if the cluster size is
         * less than or equal 4kiB.
@@ -2869,7 +2902,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
                        ntfs_error(NULL, "Failed to allocate buffers "
                                        "for compression engine.");
                        ntfs_nr_compression_users--;
-                       up(&ntfs_lock);
+                       mutex_unlock(&ntfs_lock);
                        goto iput_tmp_ino_err_out_now;
                }
        }
@@ -2881,7 +2914,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
        if (!default_upcase)
                default_upcase = generate_default_upcase();
        ntfs_nr_upcase_users++;
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        /*
         * From now on, ignore @silent parameter. If we fail below this line,
         * it will be due to a corrupt fs or a system error, so we report it.
@@ -2899,12 +2932,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
                atomic_inc(&vol->root_ino->i_count);
                ntfs_debug("Exiting, status successful.");
                /* Release the default upcase if it has no users. */
-               down(&ntfs_lock);
+               mutex_lock(&ntfs_lock);
                if (!--ntfs_nr_upcase_users && default_upcase) {
                        ntfs_free(default_upcase);
                        default_upcase = NULL;
                }
-               up(&ntfs_lock);
+               mutex_unlock(&ntfs_lock);
                sb->s_export_op = &ntfs_export_ops;
                lock_kernel();
                return 0;
@@ -2972,12 +3005,12 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
                vol->attrdef = NULL;
        }
        vol->upcase_len = 0;
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (vol->upcase == default_upcase) {
                ntfs_nr_upcase_users--;
                vol->upcase = NULL;
        }
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
        if (vol->upcase) {
                ntfs_free(vol->upcase);
                vol->upcase = NULL;
@@ -2992,14 +3025,14 @@ unl_upcase_iput_tmp_ino_err_out_now:
         * Decrease the number of upcase users and destroy the global default
         * upcase table if necessary.
         */
-       down(&ntfs_lock);
+       mutex_lock(&ntfs_lock);
        if (!--ntfs_nr_upcase_users && default_upcase) {
                ntfs_free(default_upcase);
                default_upcase = NULL;
        }
        if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
                free_compression_buffers();
-       up(&ntfs_lock);
+       mutex_unlock(&ntfs_lock);
 iput_tmp_ino_err_out_now:
        iput(tmp_ino);
        if (vol->mft_ino && vol->mft_ino != tmp_ino)
@@ -3058,13 +3091,14 @@ static void ntfs_big_inode_init_once(void *foo, struct kmem_cache *cachep,
 struct kmem_cache *ntfs_attr_ctx_cache;
 struct kmem_cache *ntfs_index_ctx_cache;
 
-/* Driver wide semaphore. */
-DECLARE_MUTEX(ntfs_lock);
+/* Driver wide mutex. */
+DEFINE_MUTEX(ntfs_lock);
 
-static struct super_block *ntfs_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int ntfs_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_bdev(fs_type, flags, dev_name, data, ntfs_fill_super);
+       return get_sb_bdev(fs_type, flags, dev_name, data, ntfs_fill_super,
+                          mnt);
 }
 
 static struct file_system_type ntfs_fs_type = {
@@ -3131,7 +3165,7 @@ static int __init init_ntfs_fs(void)
 
        ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name,
                        sizeof(ntfs_inode), 0,
-                       SLAB_RECLAIM_ACCOUNT, NULL, NULL);
+                       SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL, NULL);
        if (!ntfs_inode_cache) {
                printk(KERN_CRIT "NTFS: Failed to create %s!\n",
                                ntfs_inode_cache_name);
@@ -3140,7 +3174,7 @@ static int __init init_ntfs_fs(void)
 
        ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name,
                        sizeof(big_ntfs_inode), 0,
-                       SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
+                       SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
                        ntfs_big_inode_init_once, NULL);
        if (!ntfs_big_inode_cache) {
                printk(KERN_CRIT "NTFS: Failed to create %s!\n",
@@ -3214,7 +3248,7 @@ static void __exit exit_ntfs_fs(void)
 }
 
 MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>");
-MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2005 Anton Altaparmakov");
+MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2006 Anton Altaparmakov");
 MODULE_VERSION(NTFS_VERSION);
 MODULE_LICENSE("GPL");
 #ifdef DEBUG