root/fs/nfs/file.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. revalidate_inode
  2. nfs_file_read
  3. nfs_file_mmap
  4. nfs_fsync
  5. nfs_file_write

   1 /*
   2  *  linux/fs/nfs/file.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  Changes Copyright (C) 1994 by Florian La Roche
   7  *   - Do not copy data too often around in the kernel.
   8  *   - In nfs_file_read the return value of kmalloc wasn't checked.
   9  *   - Put in a better version of read look-ahead buffering. Original idea
  10  *     and implementation by Wai S Kok elekokws@ee.nus.sg.
  11  *
  12  *  Expire cache on write to a file by Wai S Kok (Oct 1994).
  13  *
  14  *  Total rewrite of read side for new NFS buffer cache.. Linus.
  15  *
  16  *  nfs regular file handling functions
  17  */
  18 
  19 #include <linux/sched.h>
  20 #include <linux/kernel.h>
  21 #include <linux/errno.h>
  22 #include <linux/fcntl.h>
  23 #include <linux/stat.h>
  24 #include <linux/mm.h>
  25 #include <linux/nfs_fs.h>
  26 #include <linux/malloc.h>
  27 #include <linux/pagemap.h>
  28 
  29 #include <asm/segment.h>
  30 #include <asm/system.h>
  31 
  32 static int nfs_file_mmap(struct inode *, struct file *, struct vm_area_struct *);
  33 static int nfs_file_read(struct inode *, struct file *, char *, int);
  34 static int nfs_file_write(struct inode *, struct file *, const char *, int);
  35 static int nfs_fsync(struct inode *, struct file *);
  36 
  37 static struct file_operations nfs_file_operations = {
  38         NULL,                   /* lseek - default */
  39         nfs_file_read,          /* read */
  40         nfs_file_write,         /* write */
  41         NULL,                   /* readdir - bad */
  42         NULL,                   /* select - default */
  43         NULL,                   /* ioctl - default */
  44         nfs_file_mmap,          /* mmap */
  45         NULL,                   /* no special open is needed */
  46         NULL,                   /* release */
  47         nfs_fsync,              /* fsync */
  48 };
  49 
  50 struct inode_operations nfs_file_inode_operations = {
  51         &nfs_file_operations,   /* default file operations */
  52         NULL,                   /* create */
  53         NULL,                   /* lookup */
  54         NULL,                   /* link */
  55         NULL,                   /* unlink */
  56         NULL,                   /* symlink */
  57         NULL,                   /* mkdir */
  58         NULL,                   /* rmdir */
  59         NULL,                   /* mknod */
  60         NULL,                   /* rename */
  61         NULL,                   /* readlink */
  62         NULL,                   /* follow_link */
  63         nfs_readpage,           /* readpage */
  64         NULL,                   /* writepage */
  65         NULL,                   /* bmap */
  66         NULL                    /* truncate */
  67 };
  68 
  69 static inline void revalidate_inode(struct nfs_server * server, struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71         struct nfs_fattr fattr;
  72 
  73         if (jiffies - NFS_READTIME(inode) < server->acregmax)
  74                 return;
  75 
  76         NFS_READTIME(inode) = jiffies;
  77         if (nfs_proc_getattr(server, NFS_FH(inode), &fattr) == 0) {
  78                 nfs_refresh_inode(inode, &fattr);
  79                 if (fattr.mtime.seconds == NFS_OLDMTIME(inode))
  80                         return;
  81                 NFS_OLDMTIME(inode) = fattr.mtime.seconds;
  82         }
  83         invalidate_inode_pages(inode);
  84 }
  85 
  86 
  87 static int nfs_file_read(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
  88         char * buf, int count)
  89 {
  90         revalidate_inode(NFS_SERVER(inode), inode);
  91         return generic_file_read(inode, file, buf, count);
  92 }
  93 
  94 static int nfs_file_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         revalidate_inode(NFS_SERVER(inode), inode);
  97         return generic_file_mmap(inode, file, vma);
  98 }
  99 
 100 static int nfs_fsync(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         return 0;
 103 }
 104 
 105 static int nfs_file_write(struct inode *inode, struct file *file, const char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 106                           int count)
 107 {
 108         int result, written, wsize;
 109         struct nfs_fattr fattr;
 110         unsigned long pos;
 111 
 112         if (!inode) {
 113                 printk("nfs_file_write: inode = NULL\n");
 114                 return -EINVAL;
 115         }
 116         if (!S_ISREG(inode->i_mode)) {
 117                 printk("nfs_file_write: write to non-file, mode %07o\n",
 118                         inode->i_mode);
 119                 return -EINVAL;
 120         }
 121         if (count <= 0)
 122                 return 0;
 123 
 124         pos = file->f_pos;
 125         if (file->f_flags & O_APPEND)
 126                 pos = inode->i_size;
 127         wsize = NFS_SERVER(inode)->wsize;
 128         result = 0;
 129         written = 0;
 130         while (written < count) {
 131                 int hunk = count - written;
 132                 if (hunk >= wsize)
 133                         hunk = wsize;
 134                 result = nfs_proc_write(inode,
 135                         pos, hunk, buf, &fattr);
 136                 if (result < 0)
 137                         break;
 138                 pos += hunk;
 139                 buf += hunk;
 140                 written += hunk;
 141                 if (hunk < wsize)
 142                         break;
 143         }
 144         if (!written)
 145                 return result;
 146         file->f_pos = pos;
 147         if (pos > inode->i_size)
 148                 inode->i_size = pos;
 149         nfs_refresh_inode(inode, &fattr);
 150         return written;
 151 }
 152 

/* [previous][next][first][last][top][bottom][index][help] */