Re: [PATCH] Add getdents32t syscall

From: Linus Torvalds
Date: Thu Feb 26 2004 - 17:22:23 EST




On Thu, 26 Feb 2004, Linus Torvalds wrote:
>
> In other words, what's wrong with this much simpler "extended getdents"
> instead?

Actually, let's put the "d_type" always at the last character, so that you
don't have to search for it. Ie like the appended.

Then you just get

d_type = ((unsigned char *)dirent)[dirent->d_reclen-1];

inside glibc. Instead of having a new system call.

You can even trivially check whether the system call fills in the d_type
field or not:

- pre-fill the dirent area with 0xff or something
- do a small old-style "readdir()"
- check the first entry: the above gives a d_type of 0xff, then you have
an old-style readdir. If it gives 0, then you have to test whether it
is an old-style readdir (and the zero is the end-of-name marker) or a
new-style readdir (and the zero is DT_UNKNOWN). You can trivially do
that by checking the length of the name, and comparing it with the
reclen.

See? No new system call, and trivial detection of whether the new code is
there or not.

Linus

--
--- 1.23/fs/readdir.c Tue Feb 3 21:29:14 2004
+++ edited/fs/readdir.c Thu Feb 26 14:17:05 2004
@@ -139,7 +139,7 @@
{
struct linux_dirent __user * dirent;
struct getdents_callback * buf = (struct getdents_callback *) __buf;
- int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
+ int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);

buf->error = -EINVAL; /* only used if we fail.. */
if (reclen > buf->count)
@@ -157,6 +157,8 @@
if (copy_to_user(dirent->d_name, name, namlen))
goto efault;
if (__put_user(0, dirent->d_name + namlen))
+ goto efault;
+ if (__put_user(d_type, (char *) dirent + reclen - 1))
goto efault;
buf->previous = dirent;
dirent = (void *)dirent + reclen;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/