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, struct vm_area_struct * vma);
  25 
  26 static struct file_operations nfs_file_operations = {
  27         NULL,                   /* lseek - default */
  28         nfs_file_read,          /* read */
  29         nfs_file_write,         /* write */
  30         NULL,                   /* readdir - bad */
  31         NULL,                   /* select - default */
  32         NULL,                   /* ioctl - default */
  33         nfs_mmap,               /* mmap */
  34         NULL,                   /* no special open is needed */
  35         NULL,                   /* release */
  36         nfs_fsync,              /* fsync */
  37 };
  38 
  39 struct inode_operations nfs_file_inode_operations = {
  40         &nfs_file_operations,   /* default file operations */
  41         NULL,                   /* create */
  42         NULL,                   /* lookup */
  43         NULL,                   /* link */
  44         NULL,                   /* unlink */
  45         NULL,                   /* symlink */
  46         NULL,                   /* mkdir */
  47         NULL,                   /* rmdir */
  48         NULL,                   /* mknod */
  49         NULL,                   /* rename */
  50         NULL,                   /* readlink */
  51         NULL,                   /* follow_link */
  52         NULL,                   /* bmap */
  53         NULL                    /* truncate */
  54 };
  55 
  56 static int nfs_fsync(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         return 0;
  59 }
  60 
  61 static int nfs_file_read(struct inode *inode, struct file *file, char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
  62                          int count)
  63 {
  64         int result;
  65         int hunk;
  66         int i;
  67         int n;
  68         struct nfs_fattr fattr;
  69         char *data;
  70         off_t pos;
  71 
  72         if (!inode) {
  73                 printk("nfs_file_read: inode = NULL\n");
  74                 return -EINVAL;
  75         }
  76         if (!S_ISREG(inode->i_mode)) {
  77                 printk("nfs_file_read: read from non-file, mode %07o\n",
  78                         inode->i_mode);
  79                 return -EINVAL;
  80         }
  81         pos = file->f_pos;
  82         if (file->f_pos + count > inode->i_size)
  83                 count = inode->i_size - pos;
  84         if (count <= 0)
  85                 return 0;
  86         n = NFS_SERVER(inode)->rsize;
  87         data = (char *) kmalloc(n, GFP_KERNEL);
  88         for (i = 0; i < count; i += n) {
  89                 hunk = count - i;
  90                 if (hunk > n)
  91                         hunk = n;
  92                 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode), 
  93                         pos, hunk, data, &fattr);
  94                 if (result < 0) {
  95                         kfree_s(data, n);
  96                         return result;
  97                 }
  98                 memcpy_tofs(buf, data, result);
  99                 pos += result;
 100                 buf += result;
 101                 if (result < n) {
 102                         i += result;
 103                         break;
 104                 }
 105         }
 106         file->f_pos = pos;
 107         kfree_s(data, n);
 108         nfs_refresh_inode(inode, &fattr);
 109         return i;
 110 }
 111 
 112 static int nfs_file_write(struct inode *inode, struct file *file, char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 113                           int count)
 114 {
 115         int result;
 116         int hunk;
 117         int i;
 118         int n;
 119         struct nfs_fattr fattr;
 120         char *data;
 121         int pos;
 122 
 123         if (!inode) {
 124                 printk("nfs_file_write: inode = NULL\n");
 125                 return -EINVAL;
 126         }
 127         if (!S_ISREG(inode->i_mode)) {
 128                 printk("nfs_file_write: write to non-file, mode %07o\n",
 129                         inode->i_mode);
 130                 return -EINVAL;
 131         }
 132         if (count <= 0)
 133                 return 0;
 134         pos = file->f_pos;
 135         if (file->f_flags & O_APPEND)
 136                 pos = inode->i_size;
 137         n = NFS_SERVER(inode)->wsize;
 138         data = (char *) kmalloc(n, GFP_KERNEL);
 139         for (i = 0; i < count; i += n) {
 140                 hunk = count - i;
 141                 if (hunk >= n)
 142                         hunk = n;
 143                 memcpy_fromfs(data, buf, hunk);
 144                 result = nfs_proc_write(NFS_SERVER(inode), NFS_FH(inode), 
 145                         pos, hunk, data, &fattr);
 146                 if (result < 0) {
 147                         kfree_s(data, n);
 148                         return result;
 149                 }
 150                 pos += hunk;
 151                 buf += hunk;
 152                 if (hunk < n) {
 153                         i += hunk;
 154                         break;
 155                 }
 156         }
 157         file->f_pos = pos;
 158         kfree_s(data, n);
 159         nfs_refresh_inode(inode, &fattr);
 160         return i;
 161 }
 162 

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