mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sancho Dauskardt <sda@bdit.de>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: "Randy.Dunlap" <rddunlap@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: FAT statfs loop abort on read-error
Date: Thu, 11 Sep 2003 22:47:31 +0200	[thread overview]
Message-ID: <5.0.2.1.2.20030911222745.02e59ec0@pop.kundenserver.de> (raw)
In-Reply-To: <87wuetnkjw.fsf@devron.myhome.or.jp>

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

Hi,

  It's a while back, but now here's a patch that "works for me".
Once applied, we get a nice -EIO when doing a df / statfs() on a mounted 
FAT partition with removed media (without this would hang for minutes).

The change will affect anybody calling fat_access() (the cvf stuff, other 
fat-dependent modules).

Applies on 2.4.19 .. 2.4.22 for me.

Thanks,
- sda

At 23:46 08.07.03 +0900, OGAWA Hirofumi wrote:
>Sancho Dauskardt <sda@bdit.de> writes:
>
> > >I don't know anybody ported dmsdos to 2.4. The cvf stuff was removed
> > >and many error handlings was fixed on 2.5.x. So, personally I think to
> > >remove the cvf stuff and backport the some parts of fat driver to 2.4
> > >is good.
> >
> > OK, the 100k diff between 2.4.21/fs/fat and 2.5.74 didn't really help
> > me understand what's really changed (other than the cvf removal).
> > Should I attempt to brute-force backport fs/fat/* in one large patch,
> > or incrementally re-apply the 2.5 changes to 2.4 ?
>
>I submited the some patch to marcelo several times about one year ago,
>however, unfortunately those patches was ignored.
>
>So, one large patch may not be applied. And incremental ways is more
>safety, I think. (Probably, we need to address the difference of vfs
>and umsdos)
>
> > Or, as you write 'some parts', which parts would that be ?
>
>I thought that the patches of only bug fix is probably easy to be
>applied.


[-- Attachment #2: patch_2.4.21-fat-statfs-loop-abort.diff --]
[-- Type: application/octet-stream, Size: 3136 bytes --]

diff -urN -X dontdiff.txt linux-2.4.21-640l-net/fs/fat/cache.c linux-2.4.21/fs/fat/cache.c
--- linux-2.4.21-640l-net/fs/fat/cache.c	Fri Oct 12 22:48:42 2001
+++ linux-2.4.21/fs/fat/cache.c	Tue Sep  9 13:10:30 2003
@@ -56,7 +56,7 @@
 	b = MSDOS_SB(sb)->fat_start + (first >> sb->s_blocksize_bits);
 	if (!(bh = fat_bread(sb, b))) {
 		printk("bread in fat_access failed\n");
-		return 0;
+		return -2;		/* !!!!!!!!!!!!! */
 	}
 	if ((first >> sb->s_blocksize_bits) == (last >> sb->s_blocksize_bits)) {
 		bh2 = bh;
@@ -64,7 +68,7 @@
 		if (!(bh2 = fat_bread(sb, b+1))) {
 			fat_brelse(sb, bh);
 			printk("2nd bread in fat_access failed\n");
-			return 0;
+			return -2;	/* !!!!!!!! */
 		}
 	}
 	if (MSDOS_SB(sb)->fat_bits == 32) {
@@ -283,8 +287,8 @@
 	count = 0;
 	for (fat_cache_lookup(inode,cluster,&count,&nr); count < cluster;
 	    count++) {
-		if ((nr = fat_access(inode->i_sb,nr,-1)) == -1) return 0;
-		if (!nr) return 0;
+		nr = fat_access(inode->i_sb,nr,-1);
+		if (nr <= 0) return 0;		/* 0=last, -1=end -2=error */
 	}
 	fat_cache_add(inode,cluster,nr);
 	return nr;
@@ -328,7 +332,13 @@
 	last = 0;
 	while (skip--) {
 		last = nr;
-		if ((nr = fat_access(inode->i_sb,nr,-1)) == -1) return 0;
+		nr = fat_access(inode->i_sb,nr,-1);
+
+		if (nr == -1) return 0;
+		if (nr == -2) {
+			printk("fat_free: read error\n");
+			return -EIO;
+		}
 		if (!nr) {
 			printk("fat_free: skipped EOF\n");
 			return -EIO;
@@ -344,7 +354,7 @@
 		mark_inode_dirty(inode);
 	}
 	lock_fat(inode->i_sb);
-	while (nr != -1) {
+	while (nr >= 0) {		/* != -1 */
 		if (!(nr = fat_access(inode->i_sb,nr,0))) {
 			fat_fs_panic(inode->i_sb,"fat_free: deleting beyond EOF");
 			break;
diff -urN -X dontdiff.txt linux-2.4.21-640l-net/fs/fat/inode.c linux-2.4.21/fs/fat/inode.c
--- linux-2.4.21-640l-net/fs/fat/inode.c	Sat Aug  3 02:39:45 2002
+++ linux-2.4.21/fs/fat/inode.c	Tue Sep  9 13:10:28 2003
@@ -820,7 +820,7 @@
 
 int fat_statfs(struct super_block *sb,struct statfs *buf)
 {
-	int free,nr;
+	int free,nr,e;
        
 	if (MSDOS_SB(sb)->cvf_format &&
 	    MSDOS_SB(sb)->cvf_format->cvf_statfs)
@@ -832,8 +832,18 @@
 		free = MSDOS_SB(sb)->free_clusters;
 	else {
 		free = 0;
-		for (nr = 2; nr < MSDOS_SB(sb)->clusters+2; nr++)
-			if (!fat_access(sb,nr,-1)) free++;
+		for (nr = 2; nr < MSDOS_SB(sb)->clusters+2; nr++){
+			e = fat_access(sb,nr,-1);
+			if(!e)
+				free++;
+
+			if( e == -2 ){
+				printk("Can't fat_access sector %d, %d.\n",nr,e);
+				unlock_fat(sb);
+				return -EIO;
+			}
+		}
+		
 		MSDOS_SB(sb)->free_clusters = free;
 	}
 	unlock_fat(sb);
diff -urN -X dontdiff.txt linux-2.4.21-640l-net/fs/fat/misc.c linux-2.4.21/fs/fat/misc.c
--- linux-2.4.21-640l-net/fs/fat/misc.c	Fri Oct 12 22:48:42 2001
+++ linux-2.4.21/fs/fat/misc.c	Tue Sep  9 13:19:04 2003
@@ -165,7 +165,7 @@
 	if ((curr = MSDOS_I(inode)->i_start) != 0) {
 		fat_cache_lookup(inode, INT_MAX, &last, &curr);
 		file_cluster = last;
-		while (curr && curr != -1){
+		while ( curr > 0){	/* was (curr && curr != -1), now -2 == error */
 			file_cluster++;
 			if (!(curr = fat_access(sb, last = curr,-1))) {
 				fat_fs_panic(sb, "File without EOF");

  reply	other threads:[~2003-09-11 20:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-04 11:57 Sancho Dauskardt
2003-07-06 17:24 ` Randy.Dunlap
2003-07-07 15:54   ` OGAWA Hirofumi
2003-07-07 16:24     ` Christoph Hellwig
2003-07-08 12:18       ` OGAWA Hirofumi
2003-07-08 12:33         ` Christoph Hellwig
2003-07-08 14:56           ` OGAWA Hirofumi
2003-07-07 16:38     ` Jeff Garzik
2003-07-08 12:29     ` Sancho Dauskardt
2003-07-08 14:46       ` OGAWA Hirofumi
2003-09-11 20:47         ` Sancho Dauskardt [this message]
2003-09-12 17:12           ` OGAWA Hirofumi

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=5.0.2.1.2.20030911222745.02e59ec0@pop.kundenserver.de \
    --to=sda@bdit.de \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rddunlap@osdl.org \
    /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

all inboxes | Powered by JetHome®