patch-1.3.54 linux/fs/minix/file.c

Next file: linux/fs/minix/fsync.c
Previous file: linux/fs/isofs/file.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.53/linux/fs/minix/file.c linux/fs/minix/file.c
@@ -25,7 +25,6 @@
 #include <linux/fs.h>
 #include <linux/minix_fs.h>
 
-static int minix_file_read(struct inode *, struct file *, char *, int);
 static int minix_file_write(struct inode *, struct file *, const char *, int);
 
 /*
@@ -34,7 +33,7 @@
  */
 static struct file_operations minix_file_operations = {
 	NULL,			/* lseek - default */
-	minix_file_read,	/* read */
+	generic_file_read,	/* read */
 	minix_file_write,	/* write */
 	NULL,			/* readdir - bad */
 	NULL,			/* select - default */
@@ -58,136 +57,13 @@
 	NULL,			/* rename */
 	NULL,			/* readlink */
 	NULL,			/* follow_link */
-	NULL,			/* readpage */
+	generic_readpage,	/* readpage */
 	NULL,			/* writepage */
 	minix_bmap,		/* bmap */
 	minix_truncate,		/* truncate */
 	NULL			/* permission */
 };
 
-static int minix_file_read(struct inode * inode, struct file * filp, char * buf, int count)
-{
-	int read,left,chars;
-	int block, blocks, offset;
-	int bhrequest, uptodate;
-	struct buffer_head ** bhb, ** bhe;
-	struct buffer_head * bhreq[NBUF];
-	struct buffer_head * buflist[NBUF];
-	unsigned int size;
-
-	if (!inode) {
-		printk("minix_file_read: inode = NULL\n");
-		return -EINVAL;
-	}
-	if (!S_ISREG(inode->i_mode)) {
-		printk("minix_file_read: mode = %07o\n",inode->i_mode);
-		return -EINVAL;
-	}
-	offset = filp->f_pos;
-	size = inode->i_size;
-	if (offset > size)
-		left = 0;
-	else
-		left = size - offset;
-	if (left > count)
-		left = count;
-	if (left <= 0)
-		return 0;
-	read = 0;
-	block = offset >> BLOCK_SIZE_BITS;
-	offset &= BLOCK_SIZE-1;
-	size = (size + (BLOCK_SIZE-1)) >> BLOCK_SIZE_BITS;
-	blocks = (left + offset + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS;
-	bhb = bhe = buflist;
-	if (filp->f_reada) {
-	        if(blocks < read_ahead[MAJOR(inode->i_dev)] / (BLOCK_SIZE >> 9))
-		  blocks = read_ahead[MAJOR(inode->i_dev)] / (BLOCK_SIZE >> 9);
-		if (block + blocks > size)
-			blocks = size - block;
-	}
-
-	/* We do this in a two stage process.  We first try and request
-	   as many blocks as we can, then we wait for the first one to
-	   complete, and then we try and wrap up as many as are actually
-	   done.  This routine is rather generic, in that it can be used
-	   in a filesystem by substituting the appropriate function in
-	   for getblk.
-
-	   This routine is optimized to make maximum use of the various
-	   buffers and caches. */
-
-	do {
-		bhrequest = 0;
-		uptodate = 1;
-		while (blocks) {
-			--blocks;
-			*bhb = minix_getblk(inode, block++, 0);
-			if (*bhb && !buffer_uptodate(*bhb)) {
-				uptodate = 0;
-				bhreq[bhrequest++] = *bhb;
-			}
-
-			if (++bhb == &buflist[NBUF])
-				bhb = buflist;
-
-			/* If the block we have on hand is uptodate, go ahead
-			   and complete processing. */
-			if (uptodate)
-				break;
-			if (bhb == bhe)
-				break;
-		}
-
-		/* Now request them all */
-		if (bhrequest)
-			ll_rw_block(READ, bhrequest, bhreq);
-
-		do { /* Finish off all I/O that has actually completed */
-			if (*bhe) {
-				wait_on_buffer(*bhe);
-				if (!buffer_uptodate(*bhe)) {	/* read error? */
-				        brelse(*bhe);
-					if (++bhe == &buflist[NBUF])
-					  bhe = buflist;
-					left = 0;
-					break;
-				}
-			}
-			if (left < BLOCK_SIZE - offset)
-				chars = left;
-			else
-				chars = BLOCK_SIZE - offset;
-			filp->f_pos += chars;
-			left -= chars;
-			read += chars;
-			if (*bhe) {
-				memcpy_tofs(buf,offset+(*bhe)->b_data,chars);
-				brelse(*bhe);
-				buf += chars;
-			} else {
-				while (chars-->0)
-					put_user(0,buf++);
-			}
-			offset = 0;
-			if (++bhe == &buflist[NBUF])
-				bhe = buflist;
-		} while (left > 0 && bhe != bhb && (!*bhe || !buffer_locked(*bhe)));
-	} while (left > 0);
-
-/* Release the read-ahead blocks */
-	while (bhe != bhb) {
-		brelse(*bhe);
-		if (++bhe == &buflist[NBUF])
-			bhe = buflist;
-	};
-	if (!read)
-		return -EIO;
-	filp->f_reada = 1;
-	if (!IS_RDONLY(inode))
-		inode->i_atime = CURRENT_TIME;
-	return read;
-}
-
 static int minix_file_write(struct inode * inode, struct file * filp, const char * buf, int count)
 {
 	off_t pos;
@@ -229,13 +105,14 @@
 			}
 		}
 		p = (pos % BLOCK_SIZE) + bh->b_data;
-		pos += c;
-		written += c;
 		memcpy_fromfs(p,buf,c);
-		buf += c;
+		update_vm_cache(inode, pos, p, c);
 		mark_buffer_uptodate(bh, 1);
 		mark_buffer_dirty(bh, 0);
 		brelse(bh);
+		pos += c;
+		written += c;
+		buf += c;
 	}
 	if (pos > inode->i_size)
 		inode->i_size = pos;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this