diff --git a/LibOS/shim/src/fs/chroot/fs.c b/LibOS/shim/src/fs/chroot/fs.c index 3de2e30b..ec0dd818 100644 --- a/LibOS/shim/src/fs/chroot/fs.c +++ b/LibOS/shim/src/fs/chroot/fs.c @@ -228,9 +228,9 @@ static int __query_attr (struct shim_dentry * dent, /* need to correct the data type */ if (data->type == FILE_UNKNOWN) switch (pal_attr.handle_type) { - case pal_type_file: data->type = FILE_REGULAR; break; - case pal_type_dir: data->type = FILE_DIR; break; - case pal_type_dev: data->type = FILE_DEV; break; + case pal_type_file: data->type = FILE_REGULAR; if (dent) dent->type = S_IFREG; break; + case pal_type_dir: data->type = FILE_DIR; if (dent) dent->type = S_IFDIR; break; + case pal_type_dev: data->type = FILE_DEV; if (dent) dent->type = S_IFCHR; break; } data->mode = (pal_attr.readable ? S_IRUSR : 0) | diff --git a/LibOS/shim/src/fs/shim_namei.c b/LibOS/shim/src/fs/shim_namei.c index de9be8e0..76ef462b 100644 --- a/LibOS/shim/src/fs/shim_namei.c +++ b/LibOS/shim/src/fs/shim_namei.c @@ -541,8 +541,10 @@ int open_namei (struct shim_handle * hdl, struct shim_dentry * start, newly_created = 1; // If we didn't get an error and made a directory, set the dcache dir flag - if (flags & O_DIRECTORY) + if (flags & O_DIRECTORY) { mydent->state |= DENTRY_ISDIRECTORY; + mydent->type = S_IFDIR; + } // Once the dentry is creat-ed, drop the negative flag mydent->state &= ~DENTRY_NEGATIVE; @@ -651,6 +653,9 @@ out: static inline void set_dirent_type (mode_t * type, int d_type) { switch (d_type) { + case LINUX_DT_DIR: + *type = S_IFDIR; + return; case LINUX_DT_FIFO: *type = S_IFIFO; return; diff --git a/LibOS/shim/src/sys/shim_open.c b/LibOS/shim/src/sys/shim_open.c index 3e5f7f4d..9cffda0e 100644 --- a/LibOS/shim/src/sys/shim_open.c +++ b/LibOS/shim/src/sys/shim_open.c @@ -387,7 +387,7 @@ size_t shim_do_getdents (int fd, struct linux_dirent * buf, size_t count) memcpy(b->d_name, name, len + 1); \ \ bt->pad = 0; \ - bt->d_type = type ? : get_dirent_type(dent->mode); \ + bt->d_type = type; \ \ b = (void *) bt + sizeof(struct linux_dirent_tail); \ bytes += DIRENT_SIZE(len); \ @@ -416,7 +416,7 @@ size_t shim_do_getdents (int fd, struct linux_dirent * buf, size_t count) dent = *dirhdl->ptr; /* DEP 3/3/17: We need to filter negative dentries */ if (!(dent->state & DENTRY_NEGATIVE)) - ASSIGN_DIRENT(dent, dentry_get_name(dent), 0); + ASSIGN_DIRENT(dent, dentry_get_name(dent), get_dirent_type(dent->type)); put_dentry(dent); *(dirhdl->ptr++) = NULL; } @@ -484,7 +484,7 @@ size_t shim_do_getdents64 (int fd, struct linux_dirent64 * buf, size_t count) b->d_ino = dent->ino; \ b->d_off = ++dirhdl->offset; \ b->d_reclen = DIRENT_SIZE(len); \ - b->d_type = type ? : get_dirent_type(dent->mode); \ + b->d_type = type; \ \ memcpy(b->d_name, name, len + 1); \ \ @@ -513,7 +513,7 @@ size_t shim_do_getdents64 (int fd, struct linux_dirent64 * buf, size_t count) dent = *dirhdl->ptr; /* DEP 3/3/17: We need to filter negative dentries */ if (!(dent->state & DENTRY_NEGATIVE)) - ASSIGN_DIRENT(dent, dentry_get_name(dent), 0); + ASSIGN_DIRENT(dent, dentry_get_name(dent), get_dirent_type(dent->type)); put_dentry(dent); *(dirhdl->ptr++) = NULL; }