Skip to content

Commit 3ee6bd8

Browse files
geerturichardweinberger
authored andcommitted
uml/hostfs: Propagate dirent.d_type to filldir()
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> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent c0b79a9 commit 3ee6bd8

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎fs/hostfs/hostfs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ extern int access_file(char *path, int r, int w, int x);
6767
extern int open_file(char *path, int r, int w, int append);
6868
extern void *open_dir(char *path, int *err_out);
6969
extern char *read_dir(void *stream, unsigned long long *pos,
70-
unsigned long long *ino_out, int *len_out);
70+
unsigned long long *ino_out, int *len_out,
71+
unsigned int *type_out);
7172
extern void close_file(void *stream);
7273
extern int replace_file(int oldfd, int fd);
7374
extern void close_dir(void *stream);

‎fs/hostfs/hostfs_kern.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
283283
char *name;
284284
unsigned long long next, ino;
285285
int error, len;
286+
unsigned int type;
286287

287288
name = dentry_name(file->f_path.dentry);
288289
if (name == NULL)
@@ -292,9 +293,9 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
292293
if (dir == NULL)
293294
return -error;
294295
next = file->f_pos;
295-
while ((name = read_dir(dir, &next, &ino, &len)) != NULL) {
296+
while ((name = read_dir(dir, &next, &ino, &len, &type)) != NULL) {
296297
error = (*filldir)(ent, name, len, file->f_pos,
297-
ino, DT_UNKNOWN);
298+
ino, type);
298299
if (error) break;
299300
file->f_pos = next;
300301
}

‎fs/hostfs/hostfs_user.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void *open_dir(char *path, int *err_out)
9898
}
9999

100100
char *read_dir(void *stream, unsigned long long *pos,
101-
unsigned long long *ino_out, int *len_out)
101+
unsigned long long *ino_out, int *len_out,
102+
unsigned int *type_out)
102103
{
103104
DIR *dir = stream;
104105
struct dirent *ent;
@@ -109,6 +110,7 @@ char *read_dir(void *stream, unsigned long long *pos,
109110
return NULL;
110111
*len_out = strlen(ent->d_name);
111112
*ino_out = ent->d_ino;
113+
*type_out = ent->d_type;
112114
*pos = telldir(dir);
113115
return ent->d_name;
114116
}

0 commit comments

Comments
 (0)