patch-2.1.60 linux/fs/fat/file.c

Next file: linux/fs/fat/inode.c
Previous file: linux/fs/fat/fatfs_syms.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.59/linux/fs/fat/file.c linux/fs/fat/file.c
@@ -6,6 +6,8 @@
  *  regular file handling primitives for fat-based filesystems
  */
 
+#define ASC_LINUX_VERSION(V, P, S)	(((V) * 65536) + ((P) * 256) + (S))
+#include <linux/version.h>
 #include <linux/sched.h>
 #include <linux/locks.h>
 #include <linux/fs.h>
@@ -32,7 +34,7 @@
 	fat_file_read,		/* read */
 	fat_file_write,		/* write */
 	NULL,			/* readdir - bad */
-	NULL,			/* poll - default */
+	NULL,			/* select v2.0.x/poll v2.1.x - default */
 	NULL,			/* ioctl - default */
 	generic_file_mmap,	/* mmap */
 	NULL,			/* no special open is needed */
@@ -60,6 +62,7 @@
 	NULL,			/* permission */
 	NULL			/* smap */
 };
+
 /* #Specification: msdos / special devices / mmap	
 	Mmapping does work because a special mmap is provide in that case.
 	Note that it is much less efficient than the generic_file_mmap normally
@@ -71,7 +74,7 @@
 	fat_file_read,		/* read */
 	fat_file_write,		/* write */
 	NULL,			/* readdir - bad */
-	NULL,			/* poll - default */
+	NULL,			/* select v2.0.x/poll v2.1.x - default */
 	NULL,			/* ioctl - default */
 	fat_mmap,		/* mmap */
 	NULL,			/* no special open is needed */
@@ -152,12 +155,13 @@
 /*
 	Read a file into user space
 */
-long fat_file_read(
-	struct inode *inode,
+ssize_t fat_file_read(
 	struct file *filp,
 	char *buf,
-	unsigned long count)
+	size_t count,
+	loff_t *ppos)
 {
+	struct inode *inode = filp->f_dentry->d_inode;
 	struct super_block *sb = inode->i_sb;
 	char *start = buf;
 	char *end   = buf + count;
@@ -175,7 +179,7 @@
 		printk("fat_file_read: mode = %07o\n",inode->i_mode);
 		return -EINVAL;
 	}
-	if (filp->f_pos >= inode->i_size || count == 0) return 0;
+	if (*ppos >= inode->i_size || count == 0) return 0;
 	/*
 		Tell the buffer cache which block we expect to read in advance
 		Since we are limited with the stack, we preread only MSDOS_PREFETCH
@@ -185,15 +189,15 @@
 		Each time we process one block in bhlist, we replace
 		it by a new prefetch block if needed.
 	*/
-	PRINTK (("#### ino %ld pos %ld size %ld count %d\n",inode->i_ino,filp->f_pos,inode->i_size,count));
+	PRINTK (("#### ino %ld pos %ld size %ld count %d\n",inode->i_ino,*ppos,inode->i_size,count));
 	{
 		/*
 			We must prefetch complete block, so we must
 			take in account the offset in the first block.
 		*/
-		int count_max = (filp->f_pos & (SECTOR_SIZE-1)) + count;
+		int count_max = (*ppos & (SECTOR_SIZE-1)) + count;
 		int   to_reada;	/* How many block to read all at once */
-		pre.file_sector = filp->f_pos >> SECTOR_BITS;
+		pre.file_sector = *ppos >> SECTOR_BITS;
 		to_reada = count_max / SECTOR_SIZE;
 		if (count_max & (SECTOR_SIZE-1)) to_reada++;
 		if (filp->f_reada || !MSDOS_I(inode)->i_binary){
@@ -211,7 +215,7 @@
 	}
 	pre.nolist = 0;
 	PRINTK (("count %d ahead %d nblist %d\n",count,read_ahead[MAJOR(inode->i_dev)],pre.nblist));
-	while ((left_in_file = inode->i_size - filp->f_pos) > 0
+	while ((left_in_file = inode->i_size - *ppos) > 0
 		&& buf < end){
 		struct buffer_head *bh = pre.bhlist[pre.nolist];
 		char *data;
@@ -226,27 +230,27 @@
 			fat_prefetch (inode,&pre,MSDOS_PREFETCH/2);
 			pre.nolist = 0;
 		}
-		PRINTK (("file_read pos %ld nblist %d %d %d\n",filp->f_pos,pre.nblist,pre.fetched,count));
+		PRINTK (("file_read pos %ld nblist %d %d %d\n",*ppos,pre.nblist,pre.fetched,count));
 		wait_on_buffer(bh);
 		if (!fat_is_uptodate(sb,bh)){
 			/* read error  ? */
 			fat_brelse (sb, bh);
 			break;
 		}
-		offset = filp->f_pos & (SECTOR_SIZE-1);
+		offset = *ppos & (SECTOR_SIZE-1);
 		data = bh->b_data + offset;
 		size = MIN(SECTOR_SIZE-offset,left_in_file);
 		if (MSDOS_I(inode)->i_binary) {
 			size = MIN(size,end-buf);
 			copy_to_user(buf,data,size);
 			buf += size;
-			filp->f_pos += size;
+			*ppos += size;
 		}else{
 			for (; size && buf < end; size--) {
 				char ch = *data++;
-				filp->f_pos++;
+				++*ppos;
 				if (ch == 26){
-					filp->f_pos = inode->i_size;
+					*ppos = inode->i_size;
 					break;
 				}else if (ch != '\r'){
 					put_user(ch,buf++);
@@ -269,12 +273,13 @@
 /*
 	Write to a file either from user space
 */
-long fat_file_write(
-	struct inode *inode,
+ssize_t fat_file_write(
 	struct file *filp,
 	const char *buf,
-	unsigned long count)
+	size_t count,
+	loff_t *ppos)
 {
+	struct inode *inode = filp->f_dentry->d_inode;
 	struct super_block *sb = inode->i_sb;
 	int sector,offset,size,left,written;
 	int error,carry;
@@ -300,23 +305,23 @@
  * but so what. That way leads to madness anyway.
  */
 	if (filp->f_flags & O_APPEND)
-		filp->f_pos = inode->i_size;
+		*ppos = inode->i_size;
 	if (count == 0)
 		return 0;
 	error = carry = 0;
 	for (start = buf; count || carry; count -= size) {
-		while (!(sector = fat_smap(inode,filp->f_pos >> SECTOR_BITS)))
+		while (!(sector = fat_smap(inode,*ppos >> SECTOR_BITS)))
 			if ((error = fat_add_cluster(inode)) < 0) break;
 		if (error) {
 			fat_truncate(inode);
 			break;
 		}
-		offset = filp->f_pos & (SECTOR_SIZE-1);
+		offset = *ppos & (SECTOR_SIZE-1);
 		size = MIN(SECTOR_SIZE-offset,MAX(carry,count));
 		if (binary_mode
 			&& offset == 0
 			&& (size == SECTOR_SIZE
-				|| filp->f_pos + size >= inode->i_size)){
+				|| *ppos + size >= inode->i_size)){
 			/* No need to read the block first since we will */
 			/* completely overwrite it */
 			/* or at least write past the end of file */
@@ -333,7 +338,7 @@
 			buf += size;
 		} else {
 			written = left = SECTOR_SIZE-offset;
-			to = (char *) bh->b_data+(filp->f_pos & (SECTOR_SIZE-1));
+			to = (char *) bh->b_data+(*ppos & (SECTOR_SIZE-1));
 			if (carry) {
 				*to++ = '\n';
 				left--;
@@ -353,10 +358,10 @@
 			}
 			written -= left;
 		}
-		update_vm_cache(inode, filp->f_pos, bh->b_data + (filp->f_pos & (SECTOR_SIZE-1)), written);
-		filp->f_pos += written;
-		if (filp->f_pos > inode->i_size) {
-			inode->i_size = filp->f_pos;
+		update_vm_cache(inode, *ppos, bh->b_data + (*ppos & (SECTOR_SIZE-1)), written);
+		*ppos += written;
+		if (*ppos > inode->i_size) {
+			inode->i_size = *ppos;
 			mark_inode_dirty(inode);
 		}
 		fat_set_uptodate(sb, bh, 1);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov