From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC] readdir mess
Date: Wed, 13 Aug 2008 02:02:38 +0900 [thread overview]
Message-ID: <87ej4u9nf5.fsf@devron.myhome.or.jp> (raw)
In-Reply-To: <20080812062241.GQ28946@ZenIV.linux.org.uk> (Al Viro's message of "Tue, 12 Aug 2008 07:22:41 +0100")
Al Viro <viro@ZenIV.linux.org.uk> writes:
> An obvious way to deal with that would be to have filldir_t return
> bool; true => stop, false => go on. However, that's going to cause silent
> breakage of out-of-tree filesystems. Even though e.g. ext2 had always
> treated any non-zero return value of filldir as "stop", we'd grown filesystems
> that check for return value < 0 instead. Having it return true (i.e. 1)
> will break all of those. Note that generic callbacks currently return
> negative values for "stop", so they work with those filesystems right now.
>
> FWIW, I'm seriously tempted to go for the following variant:
> new __bitwise type with two values - READDIR_STOP and READDIR_CONTINUE,
> -1 and 0 resp. The type of filldir_t would become filldir_res_t (*)(......),
> all existing instances of ->readdir() would keep working and sparse
> would catch all mismatches.
>
> Another variant is to change filldir_t in visible incompatible way
> that would have bool as return value and let readdir instances adjust or
> refuse to compile; maintainers of out-of-tree code would presumably notice
> that, so we would just have to document the calling conventions and say
> that checking for < 0 doesn't work anymore.
Personally, I'd like latter than would it work. And I hope we don't do
this again... In the case of -EOVERFLOW, even current generic filldir()
is strange like following, and I saw simular in past.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
The return value of fillonedir/filldir() is for the caller of
fillonedir/filldir(). If we want to tell the result to the caller of
->readdir(), we need to set it to buf->result/error.
This fixes -EOVERFLOW case, and cleans up related stuff.
[BTW: 32bit compat of ia64/powerpc seems to need to update]
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/readdir.c | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff -puN fs/readdir.c~filldir-errcode-fix fs/readdir.c
--- linux-2.6/fs/readdir.c~filldir-errcode-fix 2008-02-02 04:03:55.000000000 +0900
+++ linux-2.6-hirofumi/fs/readdir.c 2008-02-02 04:03:55.000000000 +0900
@@ -46,18 +46,15 @@ out:
EXPORT_SYMBOL(vfs_readdir);
+#ifdef __ARCH_WANT_OLD_READDIR
/*
* Traditional linux readdir() handling..
*
- * "count=1" is a special case, meaning that the buffer is one
+ * "result=1" is a special case, meaning that the buffer is one
* dirent-structure in size and that the code can't handle more
* anyway. Thus the special "fillonedir()" function for that
* case (the low-level handlers don't need to care about this).
*/
-#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
-
-#ifdef __ARCH_WANT_OLD_READDIR
-
struct old_linux_dirent {
unsigned long d_ino;
unsigned long d_offset;
@@ -80,8 +77,10 @@ static int fillonedir(void * __buf, cons
if (buf->result)
return -EINVAL;
d_ino = ino;
- if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
- return -EOVERFLOW;
+ if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
+ buf->result = -EOVERFLOW;
+ goto error;
+ }
buf->result++;
dirent = buf->dirent;
if (!access_ok(VERIFY_WRITE, dirent,
@@ -97,7 +96,8 @@ static int fillonedir(void * __buf, cons
return 0;
efault:
buf->result = -EFAULT;
- return -EFAULT;
+error:
+ return buf->result;
}
asmlinkage long old_readdir(unsigned int fd, struct old_linux_dirent __user * dirent, unsigned int count)
@@ -122,9 +122,10 @@ asmlinkage long old_readdir(unsigned int
out:
return error;
}
-
#endif /* __ARCH_WANT_OLD_READDIR */
+#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
+
/*
* New, all-improved, singing, dancing, iBCS2-compliant getdents()
* interface.
@@ -151,12 +152,15 @@ static int filldir(void * __buf, const c
unsigned long d_ino;
int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 2, sizeof(long));
- buf->error = -EINVAL; /* only used if we fail.. */
- if (reclen > buf->count)
- return -EINVAL;
+ if (reclen > buf->count) {
+ buf->error = -EINVAL;
+ goto error;
+ }
d_ino = ino;
- if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
- return -EOVERFLOW;
+ if (sizeof(d_ino) < sizeof(ino) && d_ino != ino) {
+ buf->error = -EOVERFLOW;
+ goto error;
+ }
dirent = buf->previous;
if (dirent) {
if (__put_user(offset, &dirent->d_off))
@@ -180,7 +184,8 @@ static int filldir(void * __buf, const c
return 0;
efault:
buf->error = -EFAULT;
- return -EFAULT;
+error:
+ return buf->error;
}
asmlinkage long sys_getdents(unsigned int fd, struct linux_dirent __user * dirent, unsigned int count)
@@ -236,9 +241,10 @@ static int filldir64(void * __buf, const
struct getdents_callback64 * buf = (struct getdents_callback64 *) __buf;
int reclen = ALIGN(NAME_OFFSET(dirent) + namlen + 1, sizeof(u64));
- buf->error = -EINVAL; /* only used if we fail.. */
- if (reclen > buf->count)
- return -EINVAL;
+ if (reclen > buf->count) {
+ buf->error = -EINVAL;
+ goto error;
+ }
dirent = buf->previous;
if (dirent) {
if (__put_user(offset, &dirent->d_off))
@@ -264,7 +270,8 @@ static int filldir64(void * __buf, const
return 0;
efault:
buf->error = -EFAULT;
- return -EFAULT;
+error:
+ return buf->error;
}
asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64 __user * dirent, unsigned int count)
_
next prev parent reply other threads:[~2008-08-12 17:02 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-12 6:22 Al Viro
2008-08-12 17:02 ` OGAWA Hirofumi [this message]
2008-08-12 17:18 ` Linus Torvalds
2008-08-12 18:10 ` Al Viro
2008-08-12 18:22 ` Al Viro
2008-08-12 18:37 ` Al Viro
2008-08-12 19:24 ` Al Viro
2008-08-12 20:02 ` Linus Torvalds
2008-08-12 20:21 ` Linus Torvalds
2008-08-12 20:38 ` Al Viro
2008-08-12 21:04 ` Linus Torvalds
2008-08-13 0:04 ` Al Viro
2008-08-13 0:28 ` Linus Torvalds
2008-08-13 1:19 ` Al Viro
2008-08-13 1:51 ` Linus Torvalds
2008-08-13 8:36 ` Brad Boyer
2008-08-13 16:19 ` Al Viro
2008-08-15 5:06 ` Jan Harkes
2008-08-15 5:34 ` Al Viro
2008-08-15 16:58 ` Linus Torvalds
2008-08-24 10:10 ` Al Viro
2008-08-24 11:03 ` Al Viro
2008-08-25 16:16 ` J. Bruce Fields
2008-08-24 17:20 ` Linus Torvalds
2008-08-24 19:59 ` Al Viro
2008-08-24 23:51 ` Linus Torvalds
2008-08-25 1:33 ` Al Viro
2008-08-25 1:44 ` Al Viro
2008-08-12 19:45 ` OGAWA Hirofumi
2008-08-12 20:05 ` Linus Torvalds
2008-08-12 20:59 ` Al Viro
2008-08-12 21:24 ` Linus Torvalds
2008-08-12 21:54 ` Al Viro
2008-08-12 22:04 ` Linus Torvalds
2008-08-13 16:20 ` J. Bruce Fields
2008-08-12 21:47 ` Alan Cox
2008-08-12 22:20 ` Linus Torvalds
2008-08-12 22:10 ` Alan Cox
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=87ej4u9nf5.fsf@devron.myhome.or.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@ZenIV.linux.org.uk \
/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
Powered by JetHome