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

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