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         if (!IS_RDONLY(inode)) inode->i_atime = CURRENT_TIME;
 123         inode->i_dirt = 1;
 124 
 125         DPRINTK("smb_file_read: exit %s\n", SMB_FINFO(inode)->path);
 126 
 127         return already_read;
 128 }
 129 
 130 static int 
 131 smb_file_write(struct inode *inode, struct file *file, const char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133         int result, bufsize, to_write, already_written;
 134         off_t pos;
 135         int errno;
 136                           
 137         if (!inode) {
 138                 DPRINTK("smb_file_write: inode = NULL\n");
 139                 return -EINVAL;
 140         }
 141 
 142         if (!S_ISREG(inode->i_mode)) {
 143                 DPRINTK("smb_file_write: write to non-file, mode %07o\n",
 144                        inode->i_mode);
 145                 return -EINVAL;
 146         }
 147 
 148         DPRINTK("smb_file_write: enter %s\n", SMB_FINFO(inode)->path);
 149 
 150         if (count <= 0)
 151                 return 0;
 152 
 153         if ((errno = smb_make_open(inode, O_RDWR)) != 0)
 154                 return errno;
 155         
 156         pos = file->f_pos;
 157 
 158         if (file->f_flags & O_APPEND)
 159                 pos = inode->i_size;
 160 
 161         bufsize = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 5;
 162 
 163         already_written = 0;
 164 
 165         while (already_written < count) {
 166 
 167                 to_write = min(bufsize, count - already_written);
 168 
 169                 result = smb_proc_write(SMB_SERVER(inode), SMB_FINFO(inode), 
 170                                         pos, to_write, buf);
 171 
 172                 if (result < 0)
 173                         return result;
 174 
 175                 pos += result;
 176                 buf += result;
 177                 already_written += result;
 178 
 179                 if (result < to_write) {
 180                         break;
 181                 }
 182         }
 183 
 184         inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 185         inode->i_dirt = 1;
 186 
 187         file->f_pos = pos;
 188 
 189         if (pos > inode->i_size) {
 190                 inode->i_size = pos;
 191         }
 192 
 193         DPRINTK("smb_file_write: exit %s\n", SMB_FINFO(inode)->path);
 194 
 195         return already_written;
 196 }
 197 
 198 static struct file_operations smb_file_operations = {
 199         NULL,                   /* lseek - default */
 200         smb_file_read,          /* read */
 201         smb_file_write,         /* write */
 202         NULL,                   /* readdir - bad */
 203         NULL,                   /* select - default */
 204         smb_ioctl,              /* ioctl */
 205         smb_mmap,               /* mmap */
 206         NULL,                   /* open */
 207         NULL,                   /* release */
 208         smb_fsync,              /* fsync */
 209 };
 210 
 211 struct inode_operations smb_file_inode_operations = {
 212         &smb_file_operations,   /* default file operations */
 213         NULL,                   /* create */
 214         NULL,                   /* lookup */
 215         NULL,                   /* link */
 216         NULL,                   /* unlink */
 217         NULL,                   /* symlink */
 218         NULL,                   /* mkdir */
 219         NULL,                   /* rmdir */
 220         NULL,                   /* mknod */
 221         NULL,                   /* rename */
 222         NULL,                   /* readlink */
 223         NULL,                   /* follow_link */
 224         NULL,                   /* bmap */
 225         NULL                    /* truncate */
 226 };
 227 
 228 /*
 229  * Overrides for Emacs so that we follow Linus's tabbing style.
 230  * Emacs will notice this stuff at the end of the file and automatically
 231  * adjust the settings for this buffer only.  This must remain at the end
 232  * of the file.
 233  * ---------------------------------------------------------------------------
 234  * Local variables:
 235  * c-indent-level: 8
 236  * c-brace-imaginary-offset: 0
 237  * c-brace-offset: -8
 238  * c-argdecl-indent: 8
 239  * c-label-offset: -8
 240  * c-continued-statement-offset: 8
 241  * c-continued-brace-offset: 0
 242  * End:
 243  */

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