public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Andrew Morton <akpm@osdl.org>
Cc: r6144 <rainy6144@gmail.com>,
	linux-kernel@vger.kernel.org, ext2-devel@lists.sourceforge.net,
	phillips@istop.com, Alex Tomas <alex@clusterfs.com>,
	Christopher Li <chrisl@vmware.com>,
	Christopher Li <ext2-devel@chrisli.org>,
	"Stephen C. Tweedie" <sct@redhat.com>
Subject: Re: Fw: [POSSIBLE-BUG] telldir() broken on ext3 dir_index'd directories just after the first entry.
Date: Wed, 17 Nov 2004 17:34:36 -0500	[thread overview]
Message-ID: <20041117223436.GB5334@thunk.org> (raw)
In-Reply-To: <20041116183813.11cbf280.akpm@osdl.org>

> [1.] One line summary of the problem:
> telldir() broken on large ext3 dir_index'd directories because
> getdents() gives d_off==0 for the first entry

Here's a patch which fixes the problem, but note the following warning
from the readdir man page:

       According to POSIX, the dirent structure contains a field char d_name[]
       of  unspecified  size,  with  at most NAME_MAX characters preceding the
       terminating null character.  Use of other fields will harm  the  porta-
       bility  of  your  programs. 

Also, as always, telldir() and seekdir() are truly awful interfaces
because they implicitly assume that (a) a directory is a linear data
structure, and (b) that the position in a directory can be expressed
in a cookie which hsa only 31 bits on 32-bit systems. 

So there will be hash colliions that will cause programs that assume
that seekdir(dirent->d_off) will always return the next directory
entry to sometimes lose directory entries in the
not-as-unlikely-as-we-would wish case of a 31-bit hash collision.
Really, any program which is using telldir/seekdir really should be
rewritten to not use these interfaces if at all possible.  So with
these caveats....

						- Ted

Here is a patch which causes d_off of '.' to be 1, and for seekdir(1)
to cause readdir to return the directory entry of '..'.  

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

===== fs/ext3/namei.c 1.59 vs edited =====
--- 1.59/fs/ext3/namei.c	2004-10-19 05:40:30 -04:00
+++ edited/fs/ext3/namei.c	2004-11-17 17:14:06 -05:00
@@ -610,10 +610,15 @@ int ext3_htree_fill_tree(struct file *di
 		de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data;
 		if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
 			goto errout;
+		count++;
+		start_hash=2;
+	}
+	if (start_hash==2 && start_minor_hash==0) {
+		de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data;
 		de = ext3_next_entry(de);
-		if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
+		if ((err = ext3_htree_store_dirent(dir_file, 2, 0, de)) != 0)
 			goto errout;
-		count += 2;
+		count++;
 	}
 
 	while (1) {

       reply	other threads:[~2004-11-17 22:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20041116183813.11cbf280.akpm@osdl.org>
2004-11-17 22:34 ` Theodore Ts'o [this message]
2004-11-18  0:00   ` Fw: [POSSIBLE-BUG] telldir() broken on ext3 dir_index'd directories just after the first entry Stephen C. Tweedie
2004-11-18  4:53     ` Theodore Ts'o
2004-11-18 11:22       ` Jan Engelhardt
2004-11-18 14:06         ` Theodore Ts'o
2004-11-18 15:40           ` Jan Engelhardt
2004-11-18 15:37       ` Stephen C. Tweedie

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=20041117223436.GB5334@thunk.org \
    --to=tytso@mit.edu \
    --cc=akpm@osdl.org \
    --cc=alex@clusterfs.com \
    --cc=chrisl@vmware.com \
    --cc=ext2-devel@chrisli.org \
    --cc=ext2-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@istop.com \
    --cc=rainy6144@gmail.com \
    --cc=sct@redhat.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