root/fs/minix/file.c

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

DEFINITIONS

This source file includes following definitions.
  1. minix_file_write

   1 /*
   2  *  linux/fs/minix/file.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   6  *  minix regular file handling primitives
   7  */
   8 
   9 #include <linux/sched.h>
  10 #include <linux/minix_fs.h>
  11 #include <linux/kernel.h>
  12 #include <linux/errno.h>
  13 #include <linux/fcntl.h>
  14 #include <linux/stat.h>
  15 #include <linux/locks.h>
  16 
  17 #include <asm/segment.h>
  18 #include <asm/system.h>
  19 
  20 #define NBUF    32
  21 
  22 #define MIN(a,b) (((a)<(b))?(a):(b))
  23 #define MAX(a,b) (((a)>(b))?(a):(b))
  24 
  25 #include <linux/fs.h>
  26 #include <linux/minix_fs.h>
  27 
  28 static int minix_file_write(struct inode *, struct file *, const char *, int);
  29 
  30 /*
  31  * We have mostly NULL's here: the current defaults are ok for
  32  * the minix filesystem.
  33  */
  34 static struct file_operations minix_file_operations = {
  35         NULL,                   /* lseek - default */
  36         generic_file_read,      /* read */
  37         minix_file_write,       /* write */
  38         NULL,                   /* readdir - bad */
  39         NULL,                   /* select - default */
  40         NULL,                   /* ioctl - default */
  41         generic_mmap,           /* mmap */
  42         NULL,                   /* no special open is needed */
  43         NULL,                   /* release */
  44         minix_sync_file         /* fsync */
  45 };
  46 
  47 struct inode_operations minix_file_inode_operations = {
  48         &minix_file_operations, /* default file operations */
  49         NULL,                   /* create */
  50         NULL,                   /* lookup */
  51         NULL,                   /* link */
  52         NULL,                   /* unlink */
  53         NULL,                   /* symlink */
  54         NULL,                   /* mkdir */
  55         NULL,                   /* rmdir */
  56         NULL,                   /* mknod */
  57         NULL,                   /* rename */
  58         NULL,                   /* readlink */
  59         NULL,                   /* follow_link */
  60         generic_readpage,       /* readpage */
  61         NULL,                   /* writepage */
  62         minix_bmap,             /* bmap */
  63         minix_truncate,         /* truncate */
  64         NULL                    /* permission */
  65 };
  66 
  67 static int minix_file_write(struct inode * inode, struct file * filp, const char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  68 {
  69         off_t pos;
  70         int written,c;
  71         struct buffer_head * bh;
  72         char * p;
  73 
  74         if (!inode) {
  75                 printk("minix_file_write: inode = NULL\n");
  76                 return -EINVAL;
  77         }
  78         if (!S_ISREG(inode->i_mode)) {
  79                 printk("minix_file_write: mode = %07o\n",inode->i_mode);
  80                 return -EINVAL;
  81         }
  82         if (filp->f_flags & O_APPEND)
  83                 pos = inode->i_size;
  84         else
  85                 pos = filp->f_pos;
  86         written = 0;
  87         while (written < count) {
  88                 bh = minix_getblk(inode,pos/BLOCK_SIZE,1);
  89                 if (!bh) {
  90                         if (!written)
  91                                 written = -ENOSPC;
  92                         break;
  93                 }
  94                 c = BLOCK_SIZE - (pos % BLOCK_SIZE);
  95                 if (c > count-written)
  96                         c = count-written;
  97                 if (c != BLOCK_SIZE && !buffer_uptodate(bh)) {
  98                         ll_rw_block(READ, 1, &bh);
  99                         wait_on_buffer(bh);
 100                         if (!buffer_uptodate(bh)) {
 101                                 brelse(bh);
 102                                 if (!written)
 103                                         written = -EIO;
 104                                 break;
 105                         }
 106                 }
 107                 p = (pos % BLOCK_SIZE) + bh->b_data;
 108                 memcpy_fromfs(p,buf,c);
 109                 update_vm_cache(inode, pos, p, c);
 110                 mark_buffer_uptodate(bh, 1);
 111                 mark_buffer_dirty(bh, 0);
 112                 brelse(bh);
 113                 pos += c;
 114                 written += c;
 115                 buf += c;
 116         }
 117         if (pos > inode->i_size)
 118                 inode->i_size = pos;
 119         inode->i_mtime = inode->i_ctime = CURRENT_TIME;
 120         filp->f_pos = pos;
 121         inode->i_dirt = 1;
 122         return written;
 123 }

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