lkml.org 
[lkml]   [1998]   [Aug]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] quadratic behaviour in ext2
    From rth@dot.cygnus.com Wed Aug 12 20:56:21 1998

On Wed, Aug 12, 1998 at 04:59:48AM +0200, Andries.Brouwer@cwi.nl wrote:
> Rereading my letter I notice the first flaw:
> since de is used as a pointer we have to guarantee
> some alignment. So, the
> if (de_len <= 0)
> had better be
> if (de_len <= 0 || (de_len % 4) != 0)

A pointer? Or an ext2_ino_t? If the former, please use
sizeof(void*), not 4. Actually, in either case please use
sizeof and the appropriate type.

No. I think you misunderstand what is happening here.
There is an array of structures

struct direntry {
__u32 inode; /* Inode number */
__u16 rec_len; /* Directory entry length */
__u8 name_len; /* Name length */
__u8 something;
char name[*]; /* File name */
};

on disk. We read the block into memory, have a pointer de to one such entry,
but that is not the entry we want, so we have to go to the next entry
using de = (struct direntry *)((char *) de + de->rec_len);
But we mistrust information from disk, so just to be sure we test
whether adding de->rec_len will again yield something that can be
used as a pointer.

But the actual ext2 filesystem uses 4 (in many places the source just
has 4, implicitly or explicitly, in other places it has EXT2_DIR_PAD
which is #defined to be 4 in <linux/ext2_fs.h>) as the alignment
for these entries on disk.

So, this number has to be 4, or, if you prefer, EXT2_DIR_PAD.

And note that it was not my purpose to improve on the ext2 code,
but to make it faster while preserving correctness.
If on certain machines my patch is wrong, the original code was wrong
(and has to be fixed many places other than just ext2/namei.c).

Your suggestion on the other hand would break things on an alpha:
there sizeof(void*) = 8 and Linux would no longer be able to read
any directories since the . and .. entries are 12 bytes apart.

Andries




-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

\
 
 \ /
  Last update: 2005-03-22 13:44    [W:0.087 / U:0.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site