patch-2.1.122 linux/fs/hfs/file.c

Next file: linux/fs/hfs/file_cap.c
Previous file: linux/fs/hfs/ChangeLog
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.121/linux/fs/hfs/file.c linux/fs/hfs/file.c
@@ -267,15 +267,19 @@
  *
  * Like copy_from_user() while translating NL->CR;
  */
-static inline void xlate_from_user(char *data, const char *buf, int count)
+static inline int xlate_from_user(char *data, const char *buf, int count)
 {
-	count -= copy_from_user(data, buf, count);
+	int i;
+
+	i = copy_from_user(data, buf, count);
+	count -= i;
 	while (count--) {
 		if (*data == '\n') {
 			*data = '\r';
 		}
 		++data;
 	}
+	return i;
 }
 
 /*================ Global functions ================*/
@@ -404,6 +408,13 @@
 				xlate_to_user(buf, p, chars);
 			} else {
 				chars -= copy_to_user(buf, p, chars);
+				if (!chars) {
+					brelse(*bhe);
+					count = 0;
+					if (!read)
+						read = -EFAULT;
+					break;
+				}
 			}
 			brelse(*bhe);
 			count -= chars;
@@ -477,10 +488,13 @@
 			}
 		}
 		p = (pos % HFS_SECTOR_SIZE) + bh->b_data;
-		if (convert) {
-			xlate_from_user(p, buf, c);
-		} else {
-			c -= copy_from_user(p, buf, c);
+		c -= convert ? xlate_from_user(p, buf, c) :
+			copy_from_user(p, buf, c);
+		if (!c) {
+			brelse(bh);
+			if (!written)
+				written = -EFAULT;
+			break;
 		}
 		update_vm_cache(inode,pos,p,c);
 		pos += c;

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