root/fs/nfs/file.c

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

DEFINITIONS

This source file includes following definitions.
  1. nfs_fsync
  2. nfs_file_read
  3. nfs_file_write

   1 /*
   2  *  linux/fs/nfs/file.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  nfs regular file handling functions
   7  */
   8 
   9 #include <asm/segment.h>
  10 #include <asm/system.h>
  11 
  12 #include <linux/sched.h>
  13 #include <linux/kernel.h>
  14 #include <linux/errno.h>
  15 #include <linux/fcntl.h>
  16 #include <linux/stat.h>
  17 #include <linux/mm.h>
  18 #include <linux/nfs_fs.h>
  19 #include <linux/malloc.h>
  20 
  21 static int nfs_file_read(struct inode *, struct file *, char *, int);
  22 static int nfs_file_write(struct inode *, struct file *, char *, int);
  23 static int nfs_fsync(struct inode *, struct file *);
  24 extern int nfs_mmap(struct inode * inode, struct file * file,
  25               unsigned long addr, size_t len, int prot, unsigned long off);
  26 
  27 static struct file_operations nfs_file_operations = {
  28         NULL,                   /* lseek - default */
  29         nfs_file_read,          /* read */
  30         nfs_file_write,         /* write */
  31         NULL,                   /* readdir - bad */
  32         NULL,                   /* select - default */
  33         NULL,                   /* ioctl - default */
  34         nfs_mmap,               /* mmap */
  35         NULL,                   /* no special open is needed */
  36         NULL,                   /* release */
  37         nfs_fsync,              /* fsync */
  38 };
  39 
  40 struct inode_operations nfs_file_inode_operations = {
  41         &nfs_file_operations,   /* default file operations */
  42         NULL,                   /* create */
  43         NULL,                   /* lookup */
  44         NULL,                   /* link */
  45         NULL,                   /* unlink */
  46         NULL,                   /* symlink */
  47         NULL,                   /* mkdir */
  48         NULL,                   /* rmdir */
  49         NULL,                   /* mknod */
  50         NULL,                   /* rename */
  51         NULL,                   /* readlink */
  52         NULL,                   /* follow_link */
  53         NULL,                   /* bmap */
  54         NULL                    /* truncate */
  55 };
  56 
  57 static int nfs_fsync(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         return 0;
  60 }
  61 
  62 static int nfs_file_read(struct inode *inode, struct file *file, char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
  63                          int count)
  64 {
  65         int result;
  66         int hunk;
  67         int i;
  68         int n;
  69         struct nfs_fattr fattr;
  70         char *data;
  71         off_t pos;
  72 
  73         if (!inode) {
  74                 printk("nfs_file_read: inode = NULL\n");
  75                 return -EINVAL;
  76         }
  77         if (!S_ISREG(inode->i_mode)) {
  78                 printk("nfs_file_read: read from non-file, mode %07o\n",
  79                         inode->i_mode);
  80                 return -EINVAL;
  81         }
  82         pos = file->f_pos;
  83         if (file->f_pos + count > inode->i_size)
  84                 count = inode->i_size - pos;
  85         if (count <= 0)
  86                 return 0;
  87         n = NFS_SERVER(inode)->rsize;
  88         data = (char *) kmalloc(n, GFP_KERNEL);
  89         for (i = 0; i < count; i += n) {
  90                 hunk = count - i;
  91                 if (hunk > n)
  92                         hunk = n;
  93                 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode), 
  94                         pos, hunk, data, &fattr);
  95                 if (result < 0) {
  96                         kfree_s(data, n);
  97                         return result;
  98                 }
  99                 memcpy_tofs(buf, data, result);
 100                 pos += result;
 101                 buf += result;
 102                 if (result < n) {
 103                         i += result;
 104                         break;
 105                 }
 106         }
 107         file->f_pos = pos;
 108         kfree_s(data, n);
 109         nfs_refresh_inode(inode, &fattr);
 110         return i;
 111 }
 112 
 113 static int nfs_file_write(struct inode *inode, struct file *file, char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 114                           int count)
 115 {
 116         int result;
 117         int hunk;
 118         int i;
 119         int n;
 120         struct nfs_fattr fattr;
 121         char *data;
 122         int pos;
 123 
 124         if (!inode) {
 125                 printk("nfs_file_write: inode = NULL\n");
 126                 return -EINVAL;
 127         }
 128         if (!S_ISREG(inode->i_mode)) {
 129                 printk("nfs_file_write: write to non-file, mode %07o\n",
 130                         inode->i_mode);
 131                 return -EINVAL;
 132         }
 133         if (count <= 0)
 134                 return 0;
 135         pos = file->f_pos;
 136         if (file->f_flags & O_APPEND)
 137                 pos = inode->i_size;
 138         n = NFS_SERVER(inode)->wsize;
 139         data = (char *) kmalloc(n, GFP_KERNEL);
 140         for (i = 0; i < count; i += n) {
 141                 hunk = count - i;
 142                 if (hunk >= n)
 143                         hunk = n;
 144                 memcpy_fromfs(data, buf, hunk);
 145                 result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode), 
 146                         pos, hunk, data, &fattr);
 147                 if (result < 0) {
 148                         kfree_s(data, n);
 149                         return result;
 150                 }
 151                 pos += hunk;
 152                 buf += hunk;
 153                 if (hunk < n) {
 154                         i += hunk;
 155                         break;
 156                 }
 157         }
 158         file->f_pos = pos;
 159         kfree_s(data, n);
 160         nfs_refresh_inode(inode, &fattr);
 161         return i;
 162 }
 163 

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