From: Gene Cumm <gene.cumm at gmail.com> Fix COM32 fstat() and core open_file(); This allows open() to open directories and fstat() to recognize directories. It also extends com32_filedata to include d_type. Signed-off-by: Gene Cumm <gene.cumm at gmail.com> --- diff --git a/com32/include/syslinux/pmapi.h b/com32/include/syslinux/pmapi.h index f583dea..4bc141f 100644 --- a/com32/include/syslinux/pmapi.h +++ b/com32/include/syslinux/pmapi.h @@ -49,6 +49,7 @@ struct com32_filedata { size_t size; /* File size */ int blocklg2; /* log2(block size) */ uint16_t handle; /* File handle */ + unsigned char d_type; }; struct com32_pmapi { diff --git a/com32/lib/sys/fstat.c b/com32/lib/sys/fstat.c index 0ce8cad..0d62d71 100644 --- a/com32/lib/sys/fstat.c +++ b/com32/lib/sys/fstat.c @@ -32,12 +32,14 @@ */ #include <sys/stat.h> +#include <dirent.h> #include <errno.h> #include "file.h" int fstat(int fd, struct stat *buf) { struct file_info *fp = &__file_info[fd]; + unsigned char d_type; if (fd >= NFILES || !fp->iop) { errno = EBADF; @@ -51,8 +53,18 @@ int fstat(int fd, struct stat *buf) buf->st_mode = S_IFSOCK | 0444; buf->st_size = 0; } else { - buf->st_mode = S_IFREG | 0444; buf->st_size = fp->i.fd.size; + d_type = fp->i.fd.d_type; + switch (d_type) { + case DT_DIR: + buf->st_mode = S_IFDIR | 0555; + break; + case DT_REG: + buf->st_mode = S_IFREG | 0444; + break; + default: + buf->st_mode = 0; /* Unknown; no access */ + } } } else { buf->st_mode = S_IFCHR | 0666; diff --git a/core/fs/fs.c b/core/fs/fs.c index c16f955..61b760c 100644 --- a/core/fs/fs.c +++ b/core/fs/fs.c @@ -330,20 +330,13 @@ int open_file(const char *name, struct com32_filedata *filedata) mangle_name(mangled_name, name); rv = searchdir(mangled_name); - if (rv < 0) - return rv; - - file = handle_to_file(rv); - - if (file->inode->mode != DT_REG) { - _close_file(file); - return -1; + if (rv >= 0) { + file = handle_to_file(rv); + filedata->size = file->inode->size; + filedata->blocklg2 = SECTOR_SHIFT(file->fs); + filedata->handle = rv; + filedata->d_type = (unsigned char) file->inode->mode; } - - filedata->size = file->inode->size; - filedata->blocklg2 = SECTOR_SHIFT(file->fs); - filedata->handle = rv; - return rv; }
H. Peter Anvin
2010-Jun-24 21:02 UTC
[syslinux] [PATCH] Fix COM32 fstat() and core open_file()
On 06/23/2010 09:02 PM, Gene Cumm wrote:> From: Gene Cumm <gene.cumm at gmail.com> > > Fix COM32 fstat() and core open_file(); This allows open() to open > directories and fstat() to recognize directories. It also extends > com32_filedata to include d_type. > > Signed-off-by: Gene Cumm <gene.cumm at gmail.com>Rejected, for reasons we already discussed on IRC. -hpa