root/fs/smbfs/file.c

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

DEFINITIONS

This source file includes following definitions.
  1. smb_fsync
  2. smb_make_open
  3. smb_file_read
  4. smb_file_write

   1 /*
   2  *  file.c
   3  *
   4  *  Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
   5  *
   6  */
   7 
   8 #include <linux/config.h>
   9 #ifdef MODULE
  10 #include <linux/module.h>
  11 #include <linux/version.h>
  12 #endif
  13 
  14 #include <asm/segment.h>
  15 #include <asm/system.h>
  16 
  17 #include <linux/sched.h>
  18 #include <linux/kernel.h>
  19 #include <linux/errno.h>
  20 #include <linux/fcntl.h>
  21 #include <linux/stat.h>
  22 #include <linux/mm.h>
  23 #include <linux/smb_fs.h>
  24 #include <linux/malloc.h>
  25 
  26 static int 
  27 smb_fsync(struct inode *inode, struct file *file)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29         return 0;
  30 }
  31 
  32 int
  33 smb_make_open(struct inode *i, int right)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35         struct smb_dirent *dirent;
  36         int open_result;
  37 
  38         if (i == NULL) {
  39                 printk("smb_make_open: got NULL inode\n");
  40                 return -EINVAL;
  41         }
  42 
  43         dirent = &(SMB_INOP(i)->finfo);
  44 
  45         DDPRINTK("smb_make_open: dirent->opened = %d\n", dirent->opened);
  46 
  47         if ((dirent->opened) == 0) {
  48                 /* tries max. rights */
  49                 open_result = smb_proc_open(SMB_SERVER(i),
  50                                             dirent->path, dirent->len,
  51                                             dirent);
  52                 if (open_result) 
  53                         return open_result;
  54 
  55                 dirent->opened = 1;
  56         }
  57 
  58         if (   ((right == O_RDONLY) && (   (dirent->access == O_RDONLY)
  59                                         || (dirent->access == O_RDWR)))
  60             || ((right == O_WRONLY) && (   (dirent->access == O_WRONLY)
  61                                         || (dirent->access == O_RDWR)))
  62             || ((right == O_RDWR)   && (dirent->access == O_RDWR)))
  63                 return 0;
  64 
  65         return -EACCES;
  66 }
  67 
  68 static int 
  69 smb_file_read(struct inode *inode, struct file *file, char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71         int result, bufsize, to_read, already_read;
  72         off_t pos;
  73         int errno;
  74 
  75         DPRINTK("smb_file_read: enter %s\n", SMB_FINFO(inode)->path);
  76         
  77         if (!inode) {
  78                 DPRINTK("smb_file_read: inode = NULL\n");
  79                 return -EINVAL;
  80         }
  81 
  82         if (!S_ISREG(inode->i_mode)) {
  83                 DPRINTK("smb_file_read: read from non-file, mode %07o\n",
  84                         inode->i_mode);
  85                 return -EINVAL;
  86         }
  87 
  88         if ((errno = smb_make_open(inode, O_RDONLY)) != 0)
  89                 return errno;
  90         
  91         pos = file->f_pos;
  92 
  93         if (pos + count > inode->i_size)
  94                 count = inode->i_size - pos;
  95 
  96         if (count <= 0)
  97                 return 0;
  98         bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
  99 
 100         already_read = 0;
 101 
 102         /* First read in as much as possible for each bufsize. */
 103         while (already_read < count) {
 104 
 105                 to_read = min(bufsize, count - already_read);
 106 
 107                 result = smb_proc_read(SMB_SERVER(inode), SMB_FINFO(inode),
 108                                        pos, to_read, buf, 1);
 109                 if (result < 0)
 110                         return result;
 111                 pos += result;
 112                 buf += result;
 113                 already_read += result;
 114 
 115                 if (result < to_read) {
 116                         break;
 117                 }
 118         }
 119 
 120         file->f_pos = pos;
 121 
 122         DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->path);
 123 
 124         return already_read;
 125 }
 126 
 127 static int 
 128 smb_file_write(struct inode *inode, struct file *file, char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 129 {
 130         int result, bufsize, to_write, already_written;
 131         off_t pos;
 132         int errno;
 133                           
 134         if (!inode) {
 135                 DPRINTK("smb_file_write: inode = NULL\n");
 136                 return -EINVAL;
 137         }
 138 
 139         if (!S_ISREG(inode->i_mode)) {
 140                 DPRINTK("smb_file_write: write to non-file, mode %07o\n",
 141                        inode->i_mode);
 142                 return -EINVAL;
 143         }
 144 
 145         DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->path);
 146 
 147         if (count <= 0)
 148                 return 0;
 149 
 150         if ((errno = smb_make_open(inode, O_RDWR)) != 0)
 151                 return errno;
 152         
 153         pos = file->f_pos;
 154 
 155         if (file->f_flags & O_APPEND)
 156                 pos = inode->i_size;
 157 
 158         bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
 159 
 160         already_written = 0;
 161 
 162         while (already_written < count) {
 163 
 164                 to_write = min(bufsize, count - already_written);
 165 
 166                 result = smb_proc_write(SMB_SERVER(inode), SMB_FINFO(inode), 
 167                                         pos, to_write, buf);
 168 
 169                 if (result < 0)
 170                         return result;
 171 
 172                 pos += result;
 173                 buf += result;
 174                 already_written += result;
 175 
 176                 if (result < to_write) {
 177                         break;
 178                 }
 179         }
 180 
 181         file->f_pos = pos;
 182 
 183         if (pos > inode->i_size) {
 184                 inode->i_size = pos;
 185         }
 186 
 187         DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->path);
 188 
 189         return already_written;
 190 }
 191 
 192 static struct file_operations smb_file_operations = {
 193         NULL,                   /* lseek - default */
 194         smb_file_read,          /* read */
 195         smb_file_write,         /* write */
 196         NULL,                   /* readdir - bad */
 197         NULL,                   /* select - default */
 198         smb_ioctl,              /* ioctl */
 199         smb_mmap,               /* mmap */
 200         NULL,                   /* open */
 201         NULL,                   /* release */
 202         smb_fsync,              /* fsync */
 203 };
 204 
 205 struct inode_operations smb_file_inode_operations = {
 206         &smb_file_operations,   /* default file operations */
 207         NULL,                   /* create */
 208         NULL,                   /* lookup */
 209         NULL,                   /* link */
 210         NULL,                   /* unlink */
 211         NULL,                   /* symlink */
 212         NULL,                   /* mkdir */
 213         NULL,                   /* rmdir */
 214         NULL,                   /* mknod */
 215         NULL,                   /* rename */
 216         NULL,                   /* readlink */
 217         NULL,                   /* follow_link */
 218         NULL,                   /* bmap */
 219         NULL                    /* truncate */
 220 };
 221 
 222 /*
 223  * Overrides for Emacs so that we follow Linus's tabbing style.
 224  * Emacs will notice this stuff at the end of the file and automatically
 225  * adjust the settings for this buffer only.  This must remain at the end
 226  * of the file.
 227  * ---------------------------------------------------------------------------
 228  * Local variables:
 229  * c-indent-level: 8
 230  * c-brace-imaginary-offset: 0
 231  * c-brace-offset: -8
 232  * c-argdecl-indent: 8
 233  * c-label-offset: -8
 234  * c-continued-statement-offset: 8
 235  * c-continued-brace-offset: 0
 236  * End:
 237  */

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