[syslinux] [PATCH] COM32: Fix read() with directories

Gene Cumm gene.cumm at gmail.com
Thu Jun 24 10:13:44 PDT 2010


From: Gene Cumm <gene.cumm at gmail.com>

COM32: Fix read() with directories to return -1 and set errno =
EISDIR.  A file descriptor for a directory may be open()ed but must be
used with fdopendir() and readdir() to read anything beyond what
stat()/fstat() returns.

Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

Depends on previous patch from last night for the change to the struct
com32_filedata.

---

diff --git a/com32/lib/sys/read.c b/com32/lib/sys/read.c
index e097ade..5e45697 100644
--- a/com32/lib/sys/read.c
+++ b/com32/lib/sys/read.c
@@ -36,6 +36,7 @@
 #include <com32.h>
 #include <minmax.h>
 #include <klibc/compiler.h>
+#include <dirent.h>
 #include "file.h"

 ssize_t read(int fd, void *buf, size_t count)
@@ -46,6 +47,10 @@ ssize_t read(int fd, void *buf, size_t count)
        errno = EBADF;
        return -1;
     }
+    if (fp->i.fd.d_type == DT_DIR) {
+       errno = EISDIR;
+       return -1;
+    }

     return fp->iop->read(fp, buf, count);
 }




More information about the Syslinux mailing list