]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/fat/file.c
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6-omap-h63xx.git] / fs / fat / file.c
index e99c5a73b39e6f172e52ee394cba5b9289a78e87..0aa813d944a67fec2e7955eadeb3e781b66915c9 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
 #include <linux/writeback.h>
+#include <linux/backing-dev.h>
+#include <linux/blkdev.h>
 
 int fat_generic_ioctl(struct inode *inode, struct file *filp,
                      unsigned int cmd, unsigned long arg)
@@ -112,15 +114,24 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
        }
 }
 
-struct file_operations fat_file_operations = {
+static int fat_file_release(struct inode *inode, struct file *filp)
+{
+       if ((filp->f_mode & FMODE_WRITE) &&
+            MSDOS_SB(inode->i_sb)->options.flush) {
+               fat_flush_inodes(inode->i_sb, inode, NULL);
+               congestion_wait(WRITE, HZ/10);
+       }
+       return 0;
+}
+
+const struct file_operations fat_file_operations = {
        .llseek         = generic_file_llseek,
        .read           = do_sync_read,
        .write          = do_sync_write,
-       .readv          = generic_file_readv,
-       .writev         = generic_file_writev,
        .aio_read       = generic_file_aio_read,
        .aio_write      = generic_file_aio_write,
        .mmap           = generic_file_mmap,
+       .release        = fat_file_release,
        .ioctl          = fat_generic_ioctl,
        .fsync          = file_fsync,
        .sendfile       = generic_file_sendfile,
@@ -210,10 +221,30 @@ static int fat_free(struct inode *inode, int skip)
        if (MSDOS_I(inode)->i_start == 0)
                return 0;
 
-       /*
-        * Write a new EOF, and get the remaining cluster chain for freeing.
-        */
+       fat_cache_inval_inode(inode);
+
        wait = IS_DIRSYNC(inode);
+       i_start = free_start = MSDOS_I(inode)->i_start;
+       i_logstart = MSDOS_I(inode)->i_logstart;
+
+       /* First, we write the new file size. */
+       if (!skip) {
+               MSDOS_I(inode)->i_start = 0;
+               MSDOS_I(inode)->i_logstart = 0;
+       }
+       MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
+       inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
+       if (wait) {
+               err = fat_sync_inode(inode);
+               if (err) {
+                       MSDOS_I(inode)->i_start = i_start;
+                       MSDOS_I(inode)->i_logstart = i_logstart;
+                       return err;
+               }
+       } else
+               mark_inode_dirty(inode);
+
+       /* Write a new EOF, and get the remaining cluster chain for freeing. */
        if (skip) {
                struct fat_entry fatent;
                int ret, fclus, dclus;
@@ -244,35 +275,11 @@ static int fat_free(struct inode *inode, int skip)
                        return ret;
 
                free_start = ret;
-               i_start = i_logstart = 0;
-               fat_cache_inval_inode(inode);
-       } else {
-               fat_cache_inval_inode(inode);
-
-               i_start = free_start = MSDOS_I(inode)->i_start;
-               i_logstart = MSDOS_I(inode)->i_logstart;
-               MSDOS_I(inode)->i_start = 0;
-               MSDOS_I(inode)->i_logstart = 0;
        }
-       MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
-       inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
-       if (wait) {
-               err = fat_sync_inode(inode);
-               if (err)
-                       goto error;
-       } else
-               mark_inode_dirty(inode);
        inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
 
        /* Freeing the remained cluster chain */
        return fat_free_clusters(inode, free_start);
-
-error:
-       if (i_start) {
-               MSDOS_I(inode)->i_start = i_start;
-               MSDOS_I(inode)->i_logstart = i_logstart;
-       }
-       return err;
 }
 
 void fat_truncate(struct inode *inode)
@@ -293,9 +300,20 @@ void fat_truncate(struct inode *inode)
        lock_kernel();
        fat_free(inode, nr_clusters);
        unlock_kernel();
+       fat_flush_inodes(inode->i_sb, inode, NULL);
+}
+
+int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
+{
+       struct inode *inode = dentry->d_inode;
+       generic_fillattr(inode, stat);
+       stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(fat_getattr);
 
 struct inode_operations fat_file_inode_operations = {
        .truncate       = fat_truncate,
        .setattr        = fat_notify_change,
+       .getattr        = fat_getattr,
 };