linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uml/hostfs: Propagate dirent.d_type to filldir()
@ 2012-01-27 18:14 Geert Uytterhoeven
  2012-01-27 18:20 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2012-01-27 18:14 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: user-mode-linux-devel, linux-kernel, linux-fsdevel, Geert Uytterhoeven

Currently the (optional) d_type member in struct dirent is always
DT_UNKNOWN on hostfs, which may confuse buggy software using readdir().
Make sure to propagate its value from the underlying filesystem if it's
available there.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 fs/hostfs/hostfs.h      |    3 ++-
 fs/hostfs/hostfs_kern.c |    5 +++--
 fs/hostfs/hostfs_user.c |    4 +++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h
index 3cbfa93..1fe7313 100644
--- a/fs/hostfs/hostfs.h
+++ b/fs/hostfs/hostfs.h
@@ -67,7 +67,8 @@ extern int access_file(char *path, int r, int w, int x);
 extern int open_file(char *path, int r, int w, int append);
 extern void *open_dir(char *path, int *err_out);
 extern char *read_dir(void *stream, unsigned long long *pos,
-		      unsigned long long *ino_out, int *len_out);
+		      unsigned long long *ino_out, int *len_out,
+		      unsigned int *type_out);
 extern void close_file(void *stream);
 extern int replace_file(int oldfd, int fd);
 extern void close_dir(void *stream);
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index e130bd4..dc4222b 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -283,6 +283,7 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
 	char *name;
 	unsigned long long next, ino;
 	int error, len;
+	unsigned int type;
 
 	name = dentry_name(file->f_path.dentry);
 	if (name == NULL)
@@ -292,9 +293,9 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
 	if (dir == NULL)
 		return -error;
 	next = file->f_pos;
-	while ((name = read_dir(dir, &next, &ino, &len)) != NULL) {
+	while ((name = read_dir(dir, &next, &ino, &len, &type)) != NULL) {
 		error = (*filldir)(ent, name, len, file->f_pos,
-				   ino, DT_UNKNOWN);
+				   ino, type);
 		if (error) break;
 		file->f_pos = next;
 	}
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c
index dd7bc38..a74ad0d 100644
--- a/fs/hostfs/hostfs_user.c
+++ b/fs/hostfs/hostfs_user.c
@@ -98,7 +98,8 @@ void *open_dir(char *path, int *err_out)
 }
 
 char *read_dir(void *stream, unsigned long long *pos,
-	       unsigned long long *ino_out, int *len_out)
+	       unsigned long long *ino_out, int *len_out,
+	       unsigned int *type_out)
 {
 	DIR *dir = stream;
 	struct dirent *ent;
@@ -109,6 +110,7 @@ char *read_dir(void *stream, unsigned long long *pos,
 		return NULL;
 	*len_out = strlen(ent->d_name);
 	*ino_out = ent->d_ino;
+	*type_out = ent->d_type;
 	*pos = telldir(dir);
 	return ent->d_name;
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] uml/hostfs: Propagate dirent.d_type to filldir()
  2012-01-27 18:14 [PATCH] uml/hostfs: Propagate dirent.d_type to filldir() Geert Uytterhoeven
@ 2012-01-27 18:20 ` Christoph Hellwig
  2012-01-27 20:54   ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2012-01-27 18:20 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Richard Weinberger, user-mode-linux-devel, linux-kernel, linux-fsdevel

On Fri, Jan 27, 2012 at 07:14:58PM +0100, Geert Uytterhoeven wrote:
> Currently the (optional) d_type member in struct dirent is always
> DT_UNKNOWN on hostfs, which may confuse buggy software using readdir().
> Make sure to propagate its value from the underlying filesystem if it's
> available there.

What software would that be?  We have lots of filesystems not filling
in d_type, and several operating systems don't have it at all.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] uml/hostfs: Propagate dirent.d_type to filldir()
  2012-01-27 18:20 ` Christoph Hellwig
@ 2012-01-27 20:54   ` Geert Uytterhoeven
  0 siblings, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2012-01-27 20:54 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Richard Weinberger, user-mode-linux-devel, linux-kernel, linux-fsdevel

Hi Christoph,

On Fri, Jan 27, 2012 at 19:20, Christoph Hellwig <hch@infradead.org> wrote:
> On Fri, Jan 27, 2012 at 07:14:58PM +0100, Geert Uytterhoeven wrote:
>> Currently the (optional) d_type member in struct dirent is always
>> DT_UNKNOWN on hostfs, which may confuse buggy software using readdir().
>> Make sure to propagate its value from the underlying filesystem if it's
>> available there.
>
> What software would that be?  We have lots of filesystems not filling

Something proprietary, which got fixed in the mean time.

> in d_type, and several operating systems don't have it at all.

Almost all filesystems on a typical Ubuntu desktop or Android device fill it in.
Iso9660 is the notable exception.

Several of the more exotic ones probably don't support it. E.g. affs
fills it in for
directories only.

>From getdents(2):
       The d_type field is implemented since Linux 2.6.4.  It occupies a space
       that was previously a zero-filled  padding  byte  in  the  linux_dirent
       structure.   Thus,  on  kernels before 2.6.3, attempting to access this
       field always provides the value 0 (DT_UNKNOWN).

       Currently, only some file systems (among them: Btrfs, ext2,  ext3,  and
       ext4)  have  full  support  for returning the file type in d_type.  All
       applications must properly handle a return of DT_UNKNOWN.

If it's there, it saves lots of stat calls.
So I take it it's a good thing if it gets fixed?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-27 20:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 18:14 [PATCH] uml/hostfs: Propagate dirent.d_type to filldir() Geert Uytterhoeven
2012-01-27 18:20 ` Christoph Hellwig
2012-01-27 20:54   ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).