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

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