]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - fs/fat/inode.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial
[linux-2.6.git] / fs / fat / inode.c
index 920a576e1c25e26240c8ed583cbdfce7e4452e4e..3ab841054d533c1853f1835e1386b53c56be7447 100644 (file)
@@ -14,9 +14,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/slab.h>
-#include <linux/smp_lock.h>
 #include <linux/seq_file.h>
-#include <linux/msdos_fs.h>
 #include <linux/pagemap.h>
 #include <linux/mpage.h>
 #include <linux/buffer_head.h>
@@ -27,7 +25,9 @@
 #include <linux/uio.h>
 #include <linux/writeback.h>
 #include <linux/log2.h>
+#include <linux/hash.h>
 #include <asm/unaligned.h>
+#include "fat.h"
 
 #ifndef CONFIG_FAT_DEFAULT_IOCHARSET
 /* if user don't select VFAT, this is undefined. */
@@ -63,7 +63,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
        sector_t phys;
        int err, offset;
 
-       err = fat_bmap(inode, iblock, &phys, &mapped_blocks);
+       err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create);
        if (err)
                return err;
        if (phys) {
@@ -75,7 +75,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
                return 0;
 
        if (iblock != MSDOS_I(inode)->mmu_private >> sb->s_blocksize_bits) {
-               fat_fs_panic(sb, "corrupted file size (i_pos %lld, %lld)",
+               fat_fs_error(sb, "corrupted file size (i_pos %lld, %lld)",
                        MSDOS_I(inode)->i_pos, MSDOS_I(inode)->mmu_private);
                return -EIO;
        }
@@ -93,7 +93,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock,
        *max_blocks = min(mapped_blocks, *max_blocks);
        MSDOS_I(inode)->mmu_private += *max_blocks << sb->s_blocksize_bits;
 
-       err = fat_bmap(inode, iblock, &phys, &mapped_blocks);
+       err = fat_bmap(inode, iblock, &phys, &mapped_blocks, create);
        if (err)
                return err;
 
@@ -141,14 +141,29 @@ static int fat_readpages(struct file *file, struct address_space *mapping,
        return mpage_readpages(mapping, pages, nr_pages, fat_get_block);
 }
 
+static void fat_write_failed(struct address_space *mapping, loff_t to)
+{
+       struct inode *inode = mapping->host;
+
+       if (to > inode->i_size) {
+               truncate_pagecache(inode, to, inode->i_size);
+               fat_truncate_blocks(inode, inode->i_size);
+       }
+}
+
 static int fat_write_begin(struct file *file, struct address_space *mapping,
                        loff_t pos, unsigned len, unsigned flags,
                        struct page **pagep, void **fsdata)
 {
+       int err;
+
        *pagep = NULL;
-       return cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
-                               fat_get_block,
+       err = cont_write_begin(file, mapping, pos, len, flags,
+                               pagep, fsdata, fat_get_block,
                                &MSDOS_I(mapping->host)->mmu_private);
+       if (err < 0)
+               fat_write_failed(mapping, pos + len);
+       return err;
 }
 
 static int fat_write_end(struct file *file, struct address_space *mapping,
@@ -158,6 +173,8 @@ static int fat_write_end(struct file *file, struct address_space *mapping,
        struct inode *inode = mapping->host;
        int err;
        err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata);
+       if (err < len)
+               fat_write_failed(mapping, pos + len);
        if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) {
                inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
                MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
@@ -171,11 +188,13 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
                             loff_t offset, unsigned long nr_segs)
 {
        struct file *file = iocb->ki_filp;
-       struct inode *inode = file->f_mapping->host;
+       struct address_space *mapping = file->f_mapping;
+       struct inode *inode = mapping->host;
+       ssize_t ret;
 
        if (rw == WRITE) {
                /*
-                * FIXME: blockdev_direct_IO() doesn't use ->prepare_write(),
+                * FIXME: blockdev_direct_IO() doesn't use ->write_begin(),
                 * so we need to update the ->mmu_private to block boundary.
                 *
                 * But we must fill the remaining area or hole by nul for
@@ -192,13 +211,24 @@ static ssize_t fat_direct_IO(int rw, struct kiocb *iocb,
         * FAT need to use the DIO_LOCKING for avoiding the race
         * condition of fat_get_block() and ->truncate().
         */
-       return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
-                                 offset, nr_segs, fat_get_block, NULL);
+       ret = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs,
+                                fat_get_block);
+       if (ret < 0 && (rw & WRITE))
+               fat_write_failed(mapping, offset + iov_length(iov, nr_segs));
+
+       return ret;
 }
 
 static sector_t _fat_bmap(struct address_space *mapping, sector_t block)
 {
-       return generic_block_bmap(mapping, block, fat_get_block);
+       sector_t blocknr;
+
+       /* fat_get_cluster() assumes the requested blocknr isn't truncated. */
+       down_read(&MSDOS_I(mapping->host)->truncate_lock);
+       blocknr = generic_block_bmap(mapping, block, fat_get_block);
+       up_read(&MSDOS_I(mapping->host)->truncate_lock);
+
+       return blocknr;
 }
 
 static const struct address_space_operations fat_aops = {
@@ -206,7 +236,6 @@ static const struct address_space_operations fat_aops = {
        .readpages      = fat_readpages,
        .writepage      = fat_writepage,
        .writepages     = fat_writepages,
-       .sync_page      = block_sync_page,
        .write_begin    = fat_write_begin,
        .write_end      = fat_write_end,
        .direct_IO      = fat_direct_IO,
@@ -232,7 +261,7 @@ static const struct address_space_operations fat_aops = {
  *                     check if the location is still valid and retry if it
  *                     isn't. Otherwise we do changes.
  *             5. Spinlock is used to protect hash/unhash/location check/lookup
- *             6. fat_clear_inode() unhashes the F-d-c entry.
+ *             6. fat_evict_inode() unhashes the F-d-c entry.
  *             7. lookup() and readdir() do igrab() if they find a F-d-c entry
  *                     and consider negative result as cache miss.
  */
@@ -247,25 +276,21 @@ static void fat_hash_init(struct super_block *sb)
                INIT_HLIST_HEAD(&sbi->inode_hashtable[i]);
 }
 
-static inline unsigned long fat_hash(struct super_block *sb, loff_t i_pos)
+static inline unsigned long fat_hash(loff_t i_pos)
 {
-       unsigned long tmp = (unsigned long)i_pos | (unsigned long) sb;
-       tmp = tmp + (tmp >> FAT_HASH_BITS) + (tmp >> FAT_HASH_BITS * 2);
-       return tmp & FAT_HASH_MASK;
+       return hash_32(i_pos, FAT_HASH_BITS);
 }
 
 void fat_attach(struct inode *inode, loff_t i_pos)
 {
-       struct super_block *sb = inode->i_sb;
-       struct msdos_sb_info *sbi = MSDOS_SB(sb);
+       struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+       struct hlist_head *head = sbi->inode_hashtable + fat_hash(i_pos);
 
        spin_lock(&sbi->inode_hash_lock);
        MSDOS_I(inode)->i_pos = i_pos;
-       hlist_add_head(&MSDOS_I(inode)->i_fat_hash,
-                       sbi->inode_hashtable + fat_hash(sb, i_pos));
+       hlist_add_head(&MSDOS_I(inode)->i_fat_hash, head);
        spin_unlock(&sbi->inode_hash_lock);
 }
-
 EXPORT_SYMBOL_GPL(fat_attach);
 
 void fat_detach(struct inode *inode)
@@ -276,13 +301,12 @@ void fat_detach(struct inode *inode)
        hlist_del_init(&MSDOS_I(inode)->i_fat_hash);
        spin_unlock(&sbi->inode_hash_lock);
 }
-
 EXPORT_SYMBOL_GPL(fat_detach);
 
 struct inode *fat_iget(struct super_block *sb, loff_t i_pos)
 {
        struct msdos_sb_info *sbi = MSDOS_SB(sb);
-       struct hlist_head *head = sbi->inode_hashtable + fat_hash(sb, i_pos);
+       struct hlist_head *head = sbi->inode_hashtable + fat_hash(i_pos);
        struct hlist_node *_p;
        struct msdos_inode_info *i;
        struct inode *inode = NULL;
@@ -341,8 +365,7 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
 
        if ((de->attr & ATTR_DIR) && !IS_FREE(de->name)) {
                inode->i_generation &= ~1;
-               inode->i_mode = MSDOS_MKMODE(de->attr,
-                       S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
+               inode->i_mode = fat_make_mode(sbi, de->attr, S_IRWXUGO);
                inode->i_op = sbi->dir_ops;
                inode->i_fop = &fat_dir_operations;
 
@@ -356,13 +379,12 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
                        return error;
                MSDOS_I(inode)->mmu_private = inode->i_size;
 
-               inode->i_nlink = fat_subdirs(inode);
+               set_nlink(inode, fat_subdirs(inode));
        } else { /* not a directory */
                inode->i_generation |= 1;
-               inode->i_mode = MSDOS_MKMODE(de->attr,
-                   ((sbi->options.showexec && !is_exec(de->name + 8))
-                       ? S_IRUGO|S_IWUGO : S_IRWXUGO)
-                   & ~sbi->options.fs_fmask) | S_IFREG;
+               inode->i_mode = fat_make_mode(sbi, de->attr,
+                       ((sbi->options.showexec && !is_exec(de->name + 8))
+                        ? S_IRUGO|S_IWUGO : S_IRWXUGO));
                MSDOS_I(inode)->i_start = le16_to_cpu(de->start);
                if (sbi->fat_bits == 32)
                        MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
@@ -378,22 +400,16 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
                if (sbi->options.sys_immutable)
                        inode->i_flags |= S_IMMUTABLE;
        }
-       MSDOS_I(inode)->i_attrs = de->attr & ATTR_UNUSED;
+       fat_save_attrs(inode, de->attr);
+
        inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
                           & ~((loff_t)sbi->cluster_size - 1)) >> 9;
-       inode->i_mtime.tv_sec =
-               date_dos2unix(le16_to_cpu(de->time), le16_to_cpu(de->date));
-       inode->i_mtime.tv_nsec = 0;
+
+       fat_time_fat2unix(sbi, &inode->i_mtime, de->time, de->date, 0);
        if (sbi->options.isvfat) {
-               int secs = de->ctime_cs / 100;
-               int csecs = de->ctime_cs % 100;
-               inode->i_ctime.tv_sec  =
-                       date_dos2unix(le16_to_cpu(de->ctime),
-                                     le16_to_cpu(de->cdate)) + secs;
-               inode->i_ctime.tv_nsec = csecs * 10000000;
-               inode->i_atime.tv_sec =
-                       date_dos2unix(0, le16_to_cpu(de->adate));
-               inode->i_atime.tv_nsec = 0;
+               fat_time_fat2unix(sbi, &inode->i_ctime, de->ctime,
+                                 de->cdate, de->ctime_cs);
+               fat_time_fat2unix(sbi, &inode->i_atime, 0, de->adate, 0);
        } else
                inode->i_ctime = inode->i_atime = inode->i_mtime;
 
@@ -430,56 +446,57 @@ out:
 
 EXPORT_SYMBOL_GPL(fat_build_inode);
 
-static void fat_delete_inode(struct inode *inode)
+static void fat_evict_inode(struct inode *inode)
 {
        truncate_inode_pages(&inode->i_data, 0);
-
-       if (!is_bad_inode(inode)) {
+       if (!inode->i_nlink) {
                inode->i_size = 0;
-               fat_truncate(inode);
+               fat_truncate_blocks(inode, 0);
        }
-       clear_inode(inode);
-}
-
-static void fat_clear_inode(struct inode *inode)
-{
-       struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
-
-       if (is_bad_inode(inode))
-               return;
-       lock_kernel();
-       spin_lock(&sbi->inode_hash_lock);
+       invalidate_inode_buffers(inode);
+       end_writeback(inode);
        fat_cache_inval_inode(inode);
-       hlist_del_init(&MSDOS_I(inode)->i_fat_hash);
-       spin_unlock(&sbi->inode_hash_lock);
-       unlock_kernel();
+       fat_detach(inode);
 }
 
 static void fat_write_super(struct super_block *sb)
 {
+       lock_super(sb);
        sb->s_dirt = 0;
 
        if (!(sb->s_flags & MS_RDONLY))
                fat_clusters_flush(sb);
+       unlock_super(sb);
+}
+
+static int fat_sync_fs(struct super_block *sb, int wait)
+{
+       int err = 0;
+
+       if (sb->s_dirt) {
+               lock_super(sb);
+               sb->s_dirt = 0;
+               err = fat_clusters_flush(sb);
+               unlock_super(sb);
+       }
+
+       return err;
 }
 
 static void fat_put_super(struct super_block *sb)
 {
        struct msdos_sb_info *sbi = MSDOS_SB(sb);
 
-       if (sbi->nls_disk) {
-               unload_nls(sbi->nls_disk);
-               sbi->nls_disk = NULL;
-               sbi->options.codepage = fat_default_codepage;
-       }
-       if (sbi->nls_io) {
-               unload_nls(sbi->nls_io);
-               sbi->nls_io = NULL;
-       }
-       if (sbi->options.iocharset != fat_default_iocharset) {
+       if (sb->s_dirt)
+               fat_write_super(sb);
+
+       iput(sbi->fat_inode);
+
+       unload_nls(sbi->nls_disk);
+       unload_nls(sbi->nls_io);
+
+       if (sbi->options.iocharset != fat_default_iocharset)
                kfree(sbi->options.iocharset);
-               sbi->options.iocharset = fat_default_iocharset;
-       }
 
        sb->s_fs_info = NULL;
        kfree(sbi);
@@ -490,18 +507,26 @@ static struct kmem_cache *fat_inode_cachep;
 static struct inode *fat_alloc_inode(struct super_block *sb)
 {
        struct msdos_inode_info *ei;
-       ei = kmem_cache_alloc(fat_inode_cachep, GFP_KERNEL);
+       ei = kmem_cache_alloc(fat_inode_cachep, GFP_NOFS);
        if (!ei)
                return NULL;
+
+       init_rwsem(&ei->truncate_lock);
        return &ei->vfs_inode;
 }
 
-static void fat_destroy_inode(struct inode *inode)
+static void fat_i_callback(struct rcu_head *head)
 {
+       struct inode *inode = container_of(head, struct inode, i_rcu);
        kmem_cache_free(fat_inode_cachep, MSDOS_I(inode));
 }
 
-static void init_once(struct kmem_cache *cachep, void *foo)
+static void fat_destroy_inode(struct inode *inode)
+{
+       call_rcu(&inode->i_rcu, fat_i_callback);
+}
+
+static void init_once(void *foo)
 {
        struct msdos_inode_info *ei = (struct msdos_inode_info *)foo;
 
@@ -539,10 +564,12 @@ static int fat_remount(struct super_block *sb, int *flags, char *data)
 
 static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
-       struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
+       struct super_block *sb = dentry->d_sb;
+       struct msdos_sb_info *sbi = MSDOS_SB(sb);
+       u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
 
        /* If the count of free cluster is still unknown, counts it here. */
-       if (sbi->free_clusters == -1) {
+       if (sbi->free_clusters == -1 || !sbi->free_clus_valid) {
                int err = fat_count_free_clusters(dentry->d_sb);
                if (err)
                        return err;
@@ -553,38 +580,55 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_blocks = sbi->max_cluster - FAT_START_ENT;
        buf->f_bfree = sbi->free_clusters;
        buf->f_bavail = sbi->free_clusters;
-       buf->f_namelen = sbi->options.isvfat ? 260 : 12;
+       buf->f_fsid.val[0] = (u32)id;
+       buf->f_fsid.val[1] = (u32)(id >> 32);
+       buf->f_namelen =
+               (sbi->options.isvfat ? FAT_LFN_LEN : 12) * NLS_MAX_CHARSET_SIZE;
 
        return 0;
 }
 
-static int fat_write_inode(struct inode *inode, int wait)
+static inline loff_t fat_i_pos_read(struct msdos_sb_info *sbi,
+                                   struct inode *inode)
+{
+       loff_t i_pos;
+#if BITS_PER_LONG == 32
+       spin_lock(&sbi->inode_hash_lock);
+#endif
+       i_pos = MSDOS_I(inode)->i_pos;
+#if BITS_PER_LONG == 32
+       spin_unlock(&sbi->inode_hash_lock);
+#endif
+       return i_pos;
+}
+
+static int __fat_write_inode(struct inode *inode, int wait)
 {
        struct super_block *sb = inode->i_sb;
        struct msdos_sb_info *sbi = MSDOS_SB(sb);
        struct buffer_head *bh;
        struct msdos_dir_entry *raw_entry;
        loff_t i_pos;
-       int err = 0;
+       int err;
+
+       if (inode->i_ino == MSDOS_ROOT_INO)
+               return 0;
 
 retry:
-       i_pos = MSDOS_I(inode)->i_pos;
-       if (inode->i_ino == MSDOS_ROOT_INO || !i_pos)
+       i_pos = fat_i_pos_read(sbi, inode);
+       if (!i_pos)
                return 0;
 
-       lock_kernel();
        bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits);
        if (!bh) {
-               printk(KERN_ERR "FAT: unable to read inode block "
-                      "for updating (i_pos %lld)\n", i_pos);
-               err = -EIO;
-               goto out;
+               fat_msg(sb, KERN_ERR, "unable to read inode block "
+                      "for updating (i_pos %lld)", i_pos);
+               return -EIO;
        }
        spin_lock(&sbi->inode_hash_lock);
        if (i_pos != MSDOS_I(inode)->i_pos) {
                spin_unlock(&sbi->inode_hash_lock);
                brelse(bh);
-               unlock_kernel();
                goto retry;
        }
 
@@ -594,48 +638,51 @@ retry:
                raw_entry->size = 0;
        else
                raw_entry->size = cpu_to_le32(inode->i_size);
-       raw_entry->attr = fat_attr(inode);
+       raw_entry->attr = fat_make_attrs(inode);
        raw_entry->start = cpu_to_le16(MSDOS_I(inode)->i_logstart);
        raw_entry->starthi = cpu_to_le16(MSDOS_I(inode)->i_logstart >> 16);
-       fat_date_unix2dos(inode->i_mtime.tv_sec, &raw_entry->time, &raw_entry->date);
+       fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
+                         &raw_entry->date, NULL);
        if (sbi->options.isvfat) {
                __le16 atime;
-               fat_date_unix2dos(inode->i_ctime.tv_sec,&raw_entry->ctime,&raw_entry->cdate);
-               fat_date_unix2dos(inode->i_atime.tv_sec,&atime,&raw_entry->adate);
-               raw_entry->ctime_cs = (inode->i_ctime.tv_sec & 1) * 100 +
-                       inode->i_ctime.tv_nsec / 10000000;
+               fat_time_unix2fat(sbi, &inode->i_ctime, &raw_entry->ctime,
+                                 &raw_entry->cdate, &raw_entry->ctime_cs);
+               fat_time_unix2fat(sbi, &inode->i_atime, &atime,
+                                 &raw_entry->adate, NULL);
        }
        spin_unlock(&sbi->inode_hash_lock);
        mark_buffer_dirty(bh);
+       err = 0;
        if (wait)
                err = sync_dirty_buffer(bh);
        brelse(bh);
-out:
-       unlock_kernel();
        return err;
 }
 
+static int fat_write_inode(struct inode *inode, struct writeback_control *wbc)
+{
+       return __fat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
+}
+
 int fat_sync_inode(struct inode *inode)
 {
-       return fat_write_inode(inode, 1);
+       return __fat_write_inode(inode, 1);
 }
 
 EXPORT_SYMBOL_GPL(fat_sync_inode);
 
-static int fat_show_options(struct seq_file *m, struct vfsmount *mnt);
+static int fat_show_options(struct seq_file *m, struct dentry *root);
 static const struct super_operations fat_sops = {
        .alloc_inode    = fat_alloc_inode,
        .destroy_inode  = fat_destroy_inode,
        .write_inode    = fat_write_inode,
-       .delete_inode   = fat_delete_inode,
+       .evict_inode    = fat_evict_inode,
        .put_super      = fat_put_super,
        .write_super    = fat_write_super,
+       .sync_fs        = fat_sync_fs,
        .statfs         = fat_statfs,
-       .clear_inode    = fat_clear_inode,
        .remount_fs     = fat_remount,
 
-       .read_inode     = make_bad_inode,
-
        .show_options   = fat_show_options,
 };
 
@@ -657,14 +704,13 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
                struct fid *fid, int fh_len, int fh_type)
 {
        struct inode *inode = NULL;
-       struct dentry *result;
        u32 *fh = fid->raw;
 
        if (fh_len < 5 || fh_type != 3)
                return NULL;
 
-       inode = iget(sb, fh[0]);
-       if (!inode || is_bad_inode(inode) || inode->i_generation != fh[1]) {
+       inode = ilookup(sb, fh[0]);
+       if (!inode || inode->i_generation != fh[1]) {
                if (inode)
                        iput(inode);
                inode = NULL;
@@ -687,34 +733,22 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
                        inode = NULL;
                }
        }
-       if (!inode) {
-               /* For now, do nothing
-                * What we could do is:
-                * follow the file starting at fh[4], and record
-                * the ".." entry, and the name of the fh[2] entry.
-                * The follow the ".." file finding the next step up.
-                * This way we build a path to the root of
-                * the tree. If this works, we lookup the path and so
-                * get this inode into the cache.
-                * Finally try the fat_iget lookup again
-                * If that fails, then weare totally out of luck
-                * But all that is for another day
-                */
-       }
-       if (!inode)
-               return ERR_PTR(-ESTALE);
-
 
-       /* now to find a dentry.
-        * If possible, get a well-connected one
+       /*
+        * For now, do nothing if the inode is not found.
+        *
+        * What we could do is:
+        *
+        *      - follow the file starting at fh[4], and record the ".." entry,
+        *        and the name of the fh[2] entry.
+        *      - then follow the ".." file finding the next step up.
+        *
+        * This way we build a path to the root of the tree. If this works, we
+        * lookup the path and so get this inode into the cache.  Finally try
+        * the fat_iget lookup again.  If that fails, then we are totally out
+        * of luck.  But all that is for another day
         */
-       result = d_alloc_anon(inode);
-       if (result == NULL) {
-               iput(inode);
-               return ERR_PTR(-ENOMEM);
-       }
-       result->d_op = sb->s_root->d_op;
-       return result;
+       return d_obtain_alias(inode);
 }
 
 static int
@@ -724,8 +758,10 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
        struct inode *inode =  de->d_inode;
        u32 ipos_h, ipos_m, ipos_l;
 
-       if (len < 5)
+       if (len < 5) {
+               *lenp = 5;
                return 255; /* no room */
+       }
 
        ipos_h = MSDOS_I(inode)->i_pos >> 8;
        ipos_m = (MSDOS_I(inode)->i_pos & 0xf0) << 24;
@@ -743,6 +779,7 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
 
 static struct dentry *fat_get_parent(struct dentry *child)
 {
+       struct super_block *sb = child->d_sb;
        struct buffer_head *bh;
        struct msdos_dir_entry *de;
        loff_t i_pos;
@@ -750,26 +787,19 @@ static struct dentry *fat_get_parent(struct dentry *child)
        struct inode *inode;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = fat_get_dotdot_entry(child->d_inode, &bh, &de, &i_pos);
        if (err) {
                parent = ERR_PTR(err);
                goto out;
        }
-       inode = fat_build_inode(child->d_sb, de, i_pos);
+       inode = fat_build_inode(sb, de, i_pos);
        brelse(bh);
-       if (IS_ERR(inode)) {
-               parent = ERR_PTR(PTR_ERR(inode));
-               goto out;
-       }
-       parent = d_alloc_anon(inode);
-       if (!parent) {
-               iput(inode);
-               parent = ERR_PTR(-ENOMEM);
-       }
+
+       parent = d_obtain_alias(inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
 
        return parent;
 }
@@ -780,9 +810,9 @@ static const struct export_operations fat_export_ops = {
        .get_parent     = fat_get_parent,
 };
 
-static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
+static int fat_show_options(struct seq_file *m, struct dentry *root)
 {
-       struct msdos_sb_info *sbi = MSDOS_SB(mnt->mnt_sb);
+       struct msdos_sb_info *sbi = MSDOS_SB(root->d_sb);
        struct fat_mount_options *opts = &sbi->options;
        int isvfat = opts->isvfat;
 
@@ -792,6 +822,8 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
                seq_printf(m, ",gid=%u", opts->fs_gid);
        seq_printf(m, ",fmask=%04o", opts->fs_fmask);
        seq_printf(m, ",dmask=%04o", opts->fs_dmask);
+       if (opts->allow_utime)
+               seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
        if (sbi->nls_disk)
                seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
        if (isvfat) {
@@ -809,7 +841,7 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
                        seq_puts(m, ",shortname=mixed");
                        break;
                case VFAT_SFN_DISPLAY_LOWER | VFAT_SFN_CREATE_WIN95:
-                       /* seq_puts(m, ",shortname=lower"); */
+                       seq_puts(m, ",shortname=lower");
                        break;
                default:
                        seq_puts(m, ",shortname=unknown");
@@ -838,23 +870,38 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
                        seq_puts(m, ",uni_xlate");
                if (!opts->numtail)
                        seq_puts(m, ",nonumtail");
+               if (opts->rodir)
+                       seq_puts(m, ",rodir");
        }
+       if (opts->flush)
+               seq_puts(m, ",flush");
+       if (opts->tz_utc)
+               seq_puts(m, ",tz=UTC");
+       if (opts->errors == FAT_ERRORS_CONT)
+               seq_puts(m, ",errors=continue");
+       else if (opts->errors == FAT_ERRORS_PANIC)
+               seq_puts(m, ",errors=panic");
+       else
+               seq_puts(m, ",errors=remount-ro");
+       if (opts->discard)
+               seq_puts(m, ",discard");
 
        return 0;
 }
 
 enum {
        Opt_check_n, Opt_check_r, Opt_check_s, Opt_uid, Opt_gid,
-       Opt_umask, Opt_dmask, Opt_fmask, Opt_codepage, Opt_usefree, Opt_nocase,
-       Opt_quiet, Opt_showexec, Opt_debug, Opt_immutable,
-       Opt_dots, Opt_nodots,
+       Opt_umask, Opt_dmask, Opt_fmask, Opt_allow_utime, Opt_codepage,
+       Opt_usefree, Opt_nocase, Opt_quiet, Opt_showexec, Opt_debug,
+       Opt_immutable, Opt_dots, Opt_nodots,
        Opt_charset, Opt_shortname_lower, Opt_shortname_win95,
        Opt_shortname_winnt, Opt_shortname_mixed, Opt_utf8_no, Opt_utf8_yes,
        Opt_uni_xl_no, Opt_uni_xl_yes, Opt_nonumtail_no, Opt_nonumtail_yes,
-       Opt_obsolate, Opt_flush, Opt_err,
+       Opt_obsolete, Opt_flush, Opt_tz_utc, Opt_rodir, Opt_err_cont,
+       Opt_err_panic, Opt_err_ro, Opt_discard, Opt_err,
 };
 
-static match_table_t fat_tokens = {
+static const match_table_t fat_tokens = {
        {Opt_check_r, "check=relaxed"},
        {Opt_check_s, "check=strict"},
        {Opt_check_n, "check=normal"},
@@ -866,6 +913,7 @@ static match_table_t fat_tokens = {
        {Opt_umask, "umask=%o"},
        {Opt_dmask, "dmask=%o"},
        {Opt_fmask, "fmask=%o"},
+       {Opt_allow_utime, "allow_utime=%o"},
        {Opt_codepage, "codepage=%u"},
        {Opt_usefree, "usefree"},
        {Opt_nocase, "nocase"},
@@ -873,28 +921,33 @@ static match_table_t fat_tokens = {
        {Opt_showexec, "showexec"},
        {Opt_debug, "debug"},
        {Opt_immutable, "sys_immutable"},
-       {Opt_obsolate, "conv=binary"},
-       {Opt_obsolate, "conv=text"},
-       {Opt_obsolate, "conv=auto"},
-       {Opt_obsolate, "conv=b"},
-       {Opt_obsolate, "conv=t"},
-       {Opt_obsolate, "conv=a"},
-       {Opt_obsolate, "fat=%u"},
-       {Opt_obsolate, "blocksize=%u"},
-       {Opt_obsolate, "cvf_format=%20s"},
-       {Opt_obsolate, "cvf_options=%100s"},
-       {Opt_obsolate, "posix"},
        {Opt_flush, "flush"},
+       {Opt_tz_utc, "tz=UTC"},
+       {Opt_err_cont, "errors=continue"},
+       {Opt_err_panic, "errors=panic"},
+       {Opt_err_ro, "errors=remount-ro"},
+       {Opt_discard, "discard"},
+       {Opt_obsolete, "conv=binary"},
+       {Opt_obsolete, "conv=text"},
+       {Opt_obsolete, "conv=auto"},
+       {Opt_obsolete, "conv=b"},
+       {Opt_obsolete, "conv=t"},
+       {Opt_obsolete, "conv=a"},
+       {Opt_obsolete, "fat=%u"},
+       {Opt_obsolete, "blocksize=%u"},
+       {Opt_obsolete, "cvf_format=%20s"},
+       {Opt_obsolete, "cvf_options=%100s"},
+       {Opt_obsolete, "posix"},
        {Opt_err, NULL},
 };
-static match_table_t msdos_tokens = {
+static const match_table_t msdos_tokens = {
        {Opt_nodots, "nodots"},
        {Opt_nodots, "dotsOK=no"},
        {Opt_dots, "dots"},
        {Opt_dots, "dotsOK=yes"},
        {Opt_err, NULL}
 };
-static match_table_t vfat_tokens = {
+static const match_table_t vfat_tokens = {
        {Opt_charset, "iocharset=%s"},
        {Opt_shortname_lower, "shortname=lower"},
        {Opt_shortname_win95, "shortname=win95"},
@@ -921,11 +974,12 @@ static match_table_t vfat_tokens = {
        {Opt_nonumtail_yes, "nonumtail=yes"},
        {Opt_nonumtail_yes, "nonumtail=true"},
        {Opt_nonumtail_yes, "nonumtail"},
+       {Opt_rodir, "rodir"},
        {Opt_err, NULL}
 };
 
-static int parse_options(char *options, int is_vfat, int silent, int *debug,
-                        struct fat_mount_options *opts)
+static int parse_options(struct super_block *sb, char *options, int is_vfat,
+                        int silent, int *debug, struct fat_mount_options *opts)
 {
        char *p;
        substring_t args[MAX_OPT_ARGS];
@@ -934,24 +988,30 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
 
        opts->isvfat = is_vfat;
 
-       opts->fs_uid = current->uid;
-       opts->fs_gid = current->gid;
-       opts->fs_fmask = opts->fs_dmask = current->fs->umask;
+       opts->fs_uid = current_uid();
+       opts->fs_gid = current_gid();
+       opts->fs_fmask = opts->fs_dmask = current_umask();
+       opts->allow_utime = -1;
        opts->codepage = fat_default_codepage;
        opts->iocharset = fat_default_iocharset;
-       if (is_vfat)
-               opts->shortname = VFAT_SFN_DISPLAY_LOWER|VFAT_SFN_CREATE_WIN95;
-       else
+       if (is_vfat) {
+               opts->shortname = VFAT_SFN_DISPLAY_WINNT|VFAT_SFN_CREATE_WIN95;
+               opts->rodir = 0;
+       } else {
                opts->shortname = 0;
+               opts->rodir = 1;
+       }
        opts->name_check = 'n';
        opts->quiet = opts->showexec = opts->sys_immutable = opts->dotsOK =  0;
        opts->utf8 = opts->unicode_xlate = 0;
        opts->numtail = 1;
        opts->usefree = opts->nocase = 0;
+       opts->tz_utc = 0;
+       opts->errors = FAT_ERRORS_RO;
        *debug = 0;
 
        if (!options)
-               return 0;
+               goto out;
 
        while ((p = strsep(&options, ",")) != NULL) {
                int token;
@@ -1024,6 +1084,11 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
                                return 0;
                        opts->fs_fmask = option;
                        break;
+               case Opt_allow_utime:
+                       if (match_octal(&args[0], &option))
+                               return 0;
+                       opts->allow_utime = option & (S_IWGRP | S_IWOTH);
+                       break;
                case Opt_codepage:
                        if (match_int(&args[0], &option))
                                return 0;
@@ -1032,6 +1097,18 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
                case Opt_flush:
                        opts->flush = 1;
                        break;
+               case Opt_tz_utc:
+                       opts->tz_utc = 1;
+                       break;
+               case Opt_err_cont:
+                       opts->errors = FAT_ERRORS_CONT;
+                       break;
+               case Opt_err_panic:
+                       opts->errors = FAT_ERRORS_PANIC;
+                       break;
+               case Opt_err_ro:
+                       opts->errors = FAT_ERRORS_RO;
+                       break;
 
                /* msdos specific */
                case Opt_dots:
@@ -1084,28 +1161,40 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,
                case Opt_nonumtail_yes:         /* empty or 1 or yes or true */
                        opts->numtail = 0;      /* negated option */
                        break;
+               case Opt_rodir:
+                       opts->rodir = 1;
+                       break;
+               case Opt_discard:
+                       opts->discard = 1;
+                       break;
 
                /* obsolete mount options */
-               case Opt_obsolate:
-                       printk(KERN_INFO "FAT: \"%s\" option is obsolete, "
-                              "not supported now\n", p);
+               case Opt_obsolete:
+                       fat_msg(sb, KERN_INFO, "\"%s\" option is obsolete, "
+                              "not supported now", p);
                        break;
                /* unknown option */
                default:
                        if (!silent) {
-                               printk(KERN_ERR
-                                      "FAT: Unrecognized mount option \"%s\" "
-                                      "or missing value\n", p);
+                               fat_msg(sb, KERN_ERR,
+                                      "Unrecognized mount option \"%s\" "
+                                      "or missing value", p);
                        }
                        return -EINVAL;
                }
        }
+
+out:
        /* UTF-8 doesn't provide FAT semantics */
        if (!strcmp(opts->iocharset, "utf8")) {
-               printk(KERN_ERR "FAT: utf8 is not a recommended IO charset"
-                      " for FAT filesystems, filesystem will be case sensitive!\n");
+               fat_msg(sb, KERN_WARNING, "utf8 is not a recommended IO charset"
+                      " for FAT filesystems, filesystem will be "
+                      "case sensitive!");
        }
 
+       /* If user doesn't specify allow_utime, it's initialized from dmask. */
+       if (opts->allow_utime == (unsigned short)-1)
+               opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
        if (opts->unicode_xlate)
                opts->utf8 = 0;
 
@@ -1123,7 +1212,7 @@ static int fat_read_root(struct inode *inode)
        inode->i_gid = sbi->options.fs_gid;
        inode->i_version++;
        inode->i_generation = 0;
-       inode->i_mode = (S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
+       inode->i_mode = fat_make_mode(sbi, ATTR_DIR, S_IRWXUGO);
        inode->i_op = sbi->dir_ops;
        inode->i_fop = &fat_dir_operations;
        if (sbi->fat_bits == 32) {
@@ -1140,10 +1229,10 @@ static int fat_read_root(struct inode *inode)
        MSDOS_I(inode)->i_logstart = 0;
        MSDOS_I(inode)->mmu_private = inode->i_size;
 
-       MSDOS_I(inode)->i_attrs = ATTR_NONE;
+       fat_save_attrs(inode, ATTR_DIR);
        inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = 0;
        inode->i_mtime.tv_nsec = inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec = 0;
-       inode->i_nlink = fat_subdirs(inode)+2;
+       set_nlink(inode, fat_subdirs(inode)+2);
 
        return 0;
 }
@@ -1151,10 +1240,10 @@ static int fat_read_root(struct inode *inode)
 /*
  * Read the super block of an MS-DOS FS.
  */
-int fat_fill_super(struct super_block *sb, void *data, int silent,
-                  const struct inode_operations *fs_dir_inode_ops, int isvfat)
+int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
+                  void (*setup)(struct super_block *))
 {
-       struct inode *root_inode = NULL;
+       struct inode *root_inode = NULL, *fat_inode = NULL;
        struct buffer_head *bh;
        struct fat_boot_sector *b;
        struct msdos_sb_info *sbi;
@@ -1165,6 +1254,12 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        long error;
        char buf[50];
 
+       /*
+        * GFP_KERNEL is ok here, because while we do hold the
+        * supeblock lock, memory pressure can't call back into
+        * the filesystem, since we're only just about to mount
+        * it and have no inodes etc active!
+        */
        sbi = kzalloc(sizeof(struct msdos_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
@@ -1174,30 +1269,33 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        sb->s_magic = MSDOS_SUPER_MAGIC;
        sb->s_op = &fat_sops;
        sb->s_export_op = &fat_export_ops;
-       sbi->dir_ops = fs_dir_inode_ops;
+       ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
+                            DEFAULT_RATELIMIT_BURST);
 
-       error = parse_options(data, isvfat, silent, &debug, &sbi->options);
+       error = parse_options(sb, data, isvfat, silent, &debug, &sbi->options);
        if (error)
                goto out_fail;
 
+       setup(sb); /* flavour-specific stuff that needs options */
+
        error = -EIO;
        sb_min_blocksize(sb, 512);
        bh = sb_bread(sb, 0);
        if (bh == NULL) {
-               printk(KERN_ERR "FAT: unable to read boot sector\n");
+               fat_msg(sb, KERN_ERR, "unable to read boot sector");
                goto out_fail;
        }
 
        b = (struct fat_boot_sector *) bh->b_data;
        if (!b->reserved) {
                if (!silent)
-                       printk(KERN_ERR "FAT: bogus number of reserved sectors\n");
+                       fat_msg(sb, KERN_ERR, "bogus number of reserved sectors");
                brelse(bh);
                goto out_invalid;
        }
        if (!b->fats) {
                if (!silent)
-                       printk(KERN_ERR "FAT: bogus number of FAT structure\n");
+                       fat_msg(sb, KERN_ERR, "bogus number of FAT structure");
                brelse(bh);
                goto out_invalid;
        }
@@ -1208,20 +1306,19 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
         */
 
        media = b->media;
-       if (!FAT_VALID_MEDIA(media)) {
+       if (!fat_valid_media(media)) {
                if (!silent)
-                       printk(KERN_ERR "FAT: invalid media value (0x%02x)\n",
+                       fat_msg(sb, KERN_ERR, "invalid media value (0x%02x)",
                               media);
                brelse(bh);
                goto out_invalid;
        }
-       logical_sector_size =
-               le16_to_cpu(get_unaligned((__le16 *)&b->sector_size));
+       logical_sector_size = get_unaligned_le16(&b->sector_size);
        if (!is_power_of_2(logical_sector_size)
            || (logical_sector_size < 512)
-           || (PAGE_CACHE_SIZE < logical_sector_size)) {
+           || (logical_sector_size > 4096)) {
                if (!silent)
-                       printk(KERN_ERR "FAT: bogus logical sector size %u\n",
+                       fat_msg(sb, KERN_ERR, "bogus logical sector size %u",
                               logical_sector_size);
                brelse(bh);
                goto out_invalid;
@@ -1229,15 +1326,15 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        sbi->sec_per_clus = b->sec_per_clus;
        if (!is_power_of_2(sbi->sec_per_clus)) {
                if (!silent)
-                       printk(KERN_ERR "FAT: bogus sectors per cluster %u\n",
+                       fat_msg(sb, KERN_ERR, "bogus sectors per cluster %u",
                               sbi->sec_per_clus);
                brelse(bh);
                goto out_invalid;
        }
 
        if (logical_sector_size < sb->s_blocksize) {
-               printk(KERN_ERR "FAT: logical sector size too small for device"
-                      " (logical sector size = %u)\n", logical_sector_size);
+               fat_msg(sb, KERN_ERR, "logical sector size too small for device"
+                      " (logical sector size = %u)", logical_sector_size);
                brelse(bh);
                goto out_fail;
        }
@@ -1245,14 +1342,14 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
                brelse(bh);
 
                if (!sb_set_blocksize(sb, logical_sector_size)) {
-                       printk(KERN_ERR "FAT: unable to set blocksize %u\n",
+                       fat_msg(sb, KERN_ERR, "unable to set blocksize %u",
                               logical_sector_size);
                        goto out_fail;
                }
                bh = sb_bread(sb, 0);
                if (bh == NULL) {
-                       printk(KERN_ERR "FAT: unable to read boot sector"
-                              " (logical sector size = %lu)\n",
+                       fat_msg(sb, KERN_ERR, "unable to read boot sector"
+                              " (logical sector size = %lu)",
                               sb->s_blocksize);
                        goto out_fail;
                }
@@ -1267,7 +1364,9 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        sbi->fat_length = le16_to_cpu(b->fat_length);
        sbi->root_cluster = 0;
        sbi->free_clusters = -1;        /* Don't know yet */
+       sbi->free_clus_valid = 0;
        sbi->prev_free = FAT_START_ENT;
+       sb->s_maxbytes = 0xffffffff;
 
        if (!sbi->fat_length && b->fat32_length) {
                struct fat_boot_fsinfo *fsinfo;
@@ -1278,8 +1377,6 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
                sbi->fat_length = le32_to_cpu(b->fat32_length);
                sbi->root_cluster = le32_to_cpu(b->root_cluster);
 
-               sb->s_maxbytes = 0xffffffff;
-
                /* MC - if info_sector is 0, don't multiply by 0 */
                sbi->fsinfo_sector = le16_to_cpu(b->info_sector);
                if (sbi->fsinfo_sector == 0)
@@ -1287,25 +1384,23 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
 
                fsinfo_bh = sb_bread(sb, sbi->fsinfo_sector);
                if (fsinfo_bh == NULL) {
-                       printk(KERN_ERR "FAT: bread failed, FSINFO block"
-                              " (sector = %lu)\n", sbi->fsinfo_sector);
+                       fat_msg(sb, KERN_ERR, "bread failed, FSINFO block"
+                              " (sector = %lu)", sbi->fsinfo_sector);
                        brelse(bh);
                        goto out_fail;
                }
 
                fsinfo = (struct fat_boot_fsinfo *)fsinfo_bh->b_data;
                if (!IS_FSINFO(fsinfo)) {
-                       printk(KERN_WARNING
-                              "FAT: Did not find valid FSINFO signature.\n"
-                              "     Found signature1 0x%08x signature2 0x%08x"
-                              " (sector = %lu)\n",
+                       fat_msg(sb, KERN_WARNING, "Invalid FSINFO signature: "
+                              "0x%08x, 0x%08x (sector = %lu)",
                               le32_to_cpu(fsinfo->signature1),
                               le32_to_cpu(fsinfo->signature2),
                               sbi->fsinfo_sector);
                } else {
                        if (sbi->options.usefree)
-                               sbi->free_clusters =
-                                       le32_to_cpu(fsinfo->free_clusters);
+                               sbi->free_clus_valid = 1;
+                       sbi->free_clusters = le32_to_cpu(fsinfo->free_clusters);
                        sbi->prev_free = le32_to_cpu(fsinfo->next_cluster);
                }
 
@@ -1316,12 +1411,11 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        sbi->dir_per_block_bits = ffs(sbi->dir_per_block) - 1;
 
        sbi->dir_start = sbi->fat_start + sbi->fats * sbi->fat_length;
-       sbi->dir_entries =
-               le16_to_cpu(get_unaligned((__le16 *)&b->dir_entries));
+       sbi->dir_entries = get_unaligned_le16(&b->dir_entries);
        if (sbi->dir_entries & (sbi->dir_per_block - 1)) {
                if (!silent)
-                       printk(KERN_ERR "FAT: bogus directroy-entries per block"
-                              " (%u)\n", sbi->dir_entries);
+                       fat_msg(sb, KERN_ERR, "bogus directroy-entries per block"
+                              " (%u)", sbi->dir_entries);
                brelse(bh);
                goto out_invalid;
        }
@@ -1329,7 +1423,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        rootdir_sectors = sbi->dir_entries
                * sizeof(struct msdos_dir_entry) / sb->s_blocksize;
        sbi->data_start = sbi->dir_start + rootdir_sectors;
-       total_sectors = le16_to_cpu(get_unaligned((__le16 *)&b->sectors));
+       total_sectors = get_unaligned_le16(&b->sectors);
        if (total_sectors == 0)
                total_sectors = le32_to_cpu(b->total_sect);
 
@@ -1343,7 +1437,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        total_clusters = min(total_clusters, fat_clusters - FAT_START_ENT);
        if (total_clusters > MAX_FAT(sb)) {
                if (!silent)
-                       printk(KERN_ERR "FAT: count of clusters too big (%u)\n",
+                       fat_msg(sb, KERN_ERR, "count of clusters too big (%u)",
                               total_clusters);
                brelse(bh);
                goto out_invalid;
@@ -1376,7 +1470,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        sprintf(buf, "cp%d", sbi->options.codepage);
        sbi->nls_disk = load_nls(buf);
        if (!sbi->nls_disk) {
-               printk(KERN_ERR "FAT: codepage %s not found\n", buf);
+               fat_msg(sb, KERN_ERR, "codepage %s not found", buf);
                goto out_fail;
        }
 
@@ -1384,13 +1478,18 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        if (sbi->options.isvfat) {
                sbi->nls_io = load_nls(sbi->options.iocharset);
                if (!sbi->nls_io) {
-                       printk(KERN_ERR "FAT: IO charset %s not found\n",
+                       fat_msg(sb, KERN_ERR, "IO charset %s not found",
                               sbi->options.iocharset);
                        goto out_fail;
                }
        }
 
        error = -ENOMEM;
+       fat_inode = new_inode(sb);
+       if (!fat_inode)
+               goto out_fail;
+       MSDOS_I(fat_inode)->i_pos = 0;
+       sbi->fat_inode = fat_inode;
        root_inode = new_inode(sb);
        if (!root_inode)
                goto out_fail;
@@ -1403,7 +1502,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        insert_inode_hash(root_inode);
        sb->s_root = d_alloc_root(root_inode);
        if (!sb->s_root) {
-               printk(KERN_ERR "FAT: get root inode failed\n");
+               fat_msg(sb, KERN_ERR, "get root inode failed");
                goto out_fail;
        }
 
@@ -1412,16 +1511,15 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
 out_invalid:
        error = -EINVAL;
        if (!silent)
-               printk(KERN_INFO "VFS: Can't find a valid FAT filesystem"
-                      " on dev %s.\n", sb->s_id);
+               fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
 
 out_fail:
+       if (fat_inode)
+               iput(fat_inode);
        if (root_inode)
                iput(root_inode);
-       if (sbi->nls_io)
-               unload_nls(sbi->nls_io);
-       if (sbi->nls_disk)
-               unload_nls(sbi->nls_disk);
+       unload_nls(sbi->nls_io);
+       unload_nls(sbi->nls_disk);
        if (sbi->options.iocharset != fat_default_iocharset)
                kfree(sbi->options.iocharset);
        sb->s_fs_info = NULL;