[syslinux:lwip] core: pass the file flags down through the stack

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sun May 1 18:15:03 PDT 2011


Commit-ID:  6ed325a3c881565cc2473d1fbfa69d806b4b7bbf
Gitweb:     http://syslinux.zytor.com/commit/6ed325a3c881565cc2473d1fbfa69d806b4b7bbf
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sun, 1 May 2011 18:11:40 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sun, 1 May 2011 18:11:40 -0700

core: pass the file flags down through the stack

Pass the file flags down through the stack.  This allows us to
distinguish between open for read, open for write, or opendir in the
low-level filesystem functions; this will matter for the PXE methods.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 com32/include/syslinux/pmapi.h |    2 +-
 com32/lib/sys/open.c           |    2 +-
 core/fs/chdir.c                |    3 ++-
 core/fs/fs.c                   |   13 +++++++------
 core/fs/pxe/pxe.c              |   10 ++++++----
 core/fs/readdir.c              |    3 ++-
 core/include/fs.h              |    6 +++---
 7 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/com32/include/syslinux/pmapi.h b/com32/include/syslinux/pmapi.h
index e96b8ec..14a2c32 100644
--- a/com32/include/syslinux/pmapi.h
+++ b/com32/include/syslinux/pmapi.h
@@ -57,7 +57,7 @@ struct com32_pmapi {
     void *(*lmalloc)(size_t);
     void (*lfree)(void *);
 
-    int (*open_file)(const char *, struct com32_filedata *);
+    int (*open_file)(const char *, int, struct com32_filedata *);
     size_t (*read_file)(uint16_t *, void *, size_t);
     void (*close_file)(uint16_t);
 
diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index 3e7bb6c..b4673b2 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -61,7 +61,7 @@ int open(const char *pathname, int flags, ...)
 
     fp = &__file_info[fd];
 
-    handle = __com32.cs_pm->open_file(pathname, &fp->i.fd);
+    handle = __com32.cs_pm->open_file(pathname, flags, &fp->i.fd);
     if (handle < 0) {
 	close(fd);
 	errno = ENOENT;
diff --git a/core/fs/chdir.c b/core/fs/chdir.c
index 9e8dfd2..0df0286 100644
--- a/core/fs/chdir.c
+++ b/core/fs/chdir.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
+#include <fcntl.h>
 #include "fs.h"
 #include "cache.h"
 
@@ -79,7 +80,7 @@ int chdir(const char *src)
 	return this_fs->fs_ops->chdir(this_fs, src);
 
     /* Otherwise it is a "conventional filesystem" */
-    rv = searchdir(src);
+    rv = searchdir(src, O_RDONLY|O_DIRECTORY);
     if (rv < 0)
 	return rv;
 
diff --git a/core/fs/fs.c b/core/fs/fs.c
index 5409986..81dafe9 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
+#include <fcntl.h>
 #include <dprintf.h>
 #include "fs.h"
 #include "cache.h"
@@ -186,7 +187,7 @@ void pm_searchdir(com32sys_t *regs)
     char *name = MK_PTR(regs->ds, regs->edi.w[0]);
     int rv;
 
-    rv = searchdir(name);
+    rv = searchdir(name, O_RDONLY);
     if (rv < 0) {
 	regs->esi.w[0]  = 0;
 	regs->eax.l     = 0;
@@ -198,7 +199,7 @@ void pm_searchdir(com32sys_t *regs)
     }
 }
 
-int searchdir(const char *name)
+int searchdir(const char *name, int flags)
 {
     struct inode *inode = NULL;
     struct inode *parent = NULL;
@@ -213,7 +214,7 @@ int searchdir(const char *name)
 
     /* if we have ->searchdir method, call it */
     if (file->fs->fs_ops->searchdir) {
-	file->fs->fs_ops->searchdir(name, file);
+	file->fs->fs_ops->searchdir(name, flags, file);
 
 	if (file->inode)
 	    return file_to_handle(file);
@@ -343,14 +344,14 @@ err_no_close:
     return -1;
 }
 
-int open_file(const char *name, struct com32_filedata *filedata)
+int open_file(const char *name, int flags, struct com32_filedata *filedata)
 {
     int rv;
     struct file *file;
     char mangled_name[FILENAME_MAX];
 
     mangle_name(mangled_name, name);
-    rv = searchdir(mangled_name);
+    rv = searchdir(mangled_name, flags);
 
     if (rv < 0)
 	return rv;
@@ -377,7 +378,7 @@ void pm_open_file(com32sys_t *regs)
     char mangled_name[FILENAME_MAX];
 
     mangle_name(mangled_name, name);
-    rv = searchdir(mangled_name);
+    rv = searchdir(mangled_name, O_RDONLY);
     if (rv < 0) {
 	regs->eflags.l |= EFLAGS_CF;
     } else {
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 3242a9f..b7ec050 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -295,20 +295,20 @@ static void url_set_ip(struct url_info *url)
  * @out: the lenght of this file, stores in file->file_len
  *
  */
-static void __pxe_searchdir(const char *filename, struct file *file);
+static void __pxe_searchdir(const char *filename, int flags, struct file *file);
 extern uint16_t PXERetry;
 
-static void pxe_searchdir(const char *filename, struct file *file)
+static void pxe_searchdir(const char *filename, int flags, struct file *file)
 {
     int i = PXERetry;
 
     do {
 	dprintf("PXE: file = %p, retries left = %d: ", file, i);
-	__pxe_searchdir(filename, file);
+	__pxe_searchdir(filename, flags, file);
 	dprintf("%s\n", file->inode ? "ok" : "failed");
     } while (!file->inode && i--);
 }
-static void __pxe_searchdir(const char *filename, struct file *file)
+static void __pxe_searchdir(const char *filename, int flags, struct file *file)
 {
     struct fs_info *fs = file->fs;
     struct inode *inode;
@@ -321,6 +321,8 @@ static void __pxe_searchdir(const char *filename, struct file *file)
     int redirect_count = 0;
     bool found_scheme = false;
 
+    (void)flags;
+
     inode = file->inode = NULL;
 
     while (filename) {
diff --git a/core/fs/readdir.c b/core/fs/readdir.c
index d071aff..a437011 100644
--- a/core/fs/readdir.c
+++ b/core/fs/readdir.c
@@ -1,3 +1,4 @@
+#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/dirent.h>
@@ -12,7 +13,7 @@ DIR *opendir(const char *path)
     int rv;
     struct file *file;
 
-    rv = searchdir(path);
+    rv = searchdir(path, O_RDONLY|O_DIRECTORY);
     if (rv < 0)
 	return NULL;
 
diff --git a/core/include/fs.h b/core/include/fs.h
index 4301481..0691caa 100644
--- a/core/include/fs.h
+++ b/core/include/fs.h
@@ -52,7 +52,7 @@ struct fs_ops {
     enum fs_flags fs_flags;
     
     int      (*fs_init)(struct fs_info *);
-    void     (*searchdir)(const char *, struct file *);
+    void     (*searchdir)(const char *, int, struct file *);
     uint32_t (*getfssec)(struct file *, char *, int, bool *);
     void     (*close_file)(struct file *);
     void     (*mangle_name)(char *, const char *);
@@ -179,10 +179,10 @@ static inline struct file *handle_to_file(uint16_t handle)
 void pm_mangle_name(com32sys_t *);
 void pm_searchdir(com32sys_t *);
 void mangle_name(char *, const char *);
-int searchdir(const char *name);
+int searchdir(const char *name, int flags);
 void _close_file(struct file *);
 size_t pmapi_read_file(uint16_t *handle, void *buf, size_t sectors);
-int open_file(const char *name, struct com32_filedata *filedata);
+int open_file(const char *name, int flags, struct com32_filedata *filedata);
 void pm_open_file(com32sys_t *);
 void close_file(uint16_t handle);
 void pm_close_file(com32sys_t *);



More information about the Syslinux-commits mailing list