root/fs/nfs/file.c

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

DEFINITIONS

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

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