linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jari Ruusu <jari.ruusu@pp.inet.fi>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: linux-kernel@vger.kernel.org
Subject: Patch for O_SYNC/ENOSPC bug (on Ted's TODO list)
Date: Sat, 04 Nov 2000 20:15:16 +0200	[thread overview]
Message-ID: <3A045234.8395F94@pp.inet.fi> (raw)

Hi Linus,

This patch (against 2.4.0-test10) fixes the O_SYNC/ENOSPC bug. Alan Cox
included a fix for this same bug in 2.2.18pre7 and David Weinehall in
2.0.39final. This bug is listed on Ted's "Linux 2.4 Status / TODO page" as
"Fix Exists But Isnt Merged", "Writing past end of removeable device can
cause data corruption bugs in the future".

More information and source code for small test program here:
http://marc.theaimsgroup.com/?l=linux-kernel&m=96879269024716&w=2

Regards,
Jari Ruusu <jari.ruusu@pp.inet.fi>

--- linux-2.4.0-test10/fs/block_dev.c	Wed Oct  4 01:03:11 2000
+++ linux/fs/block_dev.c	Sat Nov  4 17:14:19 2000
@@ -30,7 +30,7 @@
 	ssize_t block, blocks;
 	loff_t offset;
 	ssize_t chars;
-	ssize_t written;
+	ssize_t written, retval;
 	struct buffer_head * bhlist[NBUF];
 	size_t size;
 	kdev_t dev = inode->i_rdev;
@@ -40,7 +40,7 @@
 	if (is_read_only(dev))
 		return -EPERM;
 
-	written = write_error = buffercount = 0;
+	retval = written = write_error = buffercount = 0;
 	blocksize = BLOCK_SIZE;
 	if (blksize_size[MAJOR(dev)] && blksize_size[MAJOR(dev)][MINOR(dev)])
 		blocksize = blksize_size[MAJOR(dev)][MINOR(dev)];
@@ -60,8 +60,10 @@
 	else
 		size = INT_MAX;
 	while (count>0) {
-		if (block >= size)
-			return written ? written : -ENOSPC;
+		if (block >= size) {
+			retval = -ENOSPC;
+			goto cleanup;
+		}
 		chars = blocksize - offset;
 		if (chars > count)
 			chars=count;
@@ -73,15 +75,19 @@
 			if (chars != blocksize)
 				fn = bread;
 			bh = fn(dev, block, blocksize);
-			if (!bh)
-				return written ? written : -EIO;
+			if (!bh) {
+				retval = -EIO;
+				goto cleanup;
+			}
 			if (!buffer_uptodate(bh))
 				wait_on_buffer(bh);
 		}
 #else
 		bh = getblk(dev, block, blocksize);
-		if (!bh)
-			return written ? written : -EIO;
+		if (!bh) {
+			retval = -EIO;
+			goto cleanup;
+		}
 
 		if (!buffer_uptodate(bh))
 		{
@@ -105,7 +111,8 @@
 		        if (!bhlist[i])
 			{
 			  while(i >= 0) brelse(bhlist[i--]);
-			  return written ? written : -EIO;
+			  retval = -EIO;
+			  goto cleanup;
 		        }
 		      }
 		    }
@@ -114,7 +121,8 @@
 		    wait_on_buffer(bh);
 		    if (!buffer_uptodate(bh)) {
 			  brelse(bh);
-			  return written ? written : -EIO;
+			  retval = -EIO;
+			  goto cleanup;
 		    }
 		  };
 		};
@@ -148,6 +156,7 @@
 		if (write_error)
 			break;
 	}
+	cleanup:
 	if ( buffercount ){
 		ll_rw_block(WRITE, buffercount, bufferlist);
 		for(i=0; i<buffercount; i++){
@@ -157,10 +166,11 @@
 			brelse(bufferlist[i]);
 		}
 	}		
-	filp->f_reada = 1;
+	if(!retval)
+		filp->f_reada = 1;
 	if(write_error)
 		return -EIO;
-	return written;
+	return written ? written : retval;
 }
 
 ssize_t block_read(struct file * filp, char * buf, size_t count, loff_t *ppos)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

                 reply	other threads:[~2000-11-04 18:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3A045234.8395F94@pp.inet.fi \
    --to=jari.ruusu@pp.inet.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).