summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-05-01 18:11:40 -0700
committerH. Peter Anvin <hpa@zytor.com>2011-05-01 18:11:40 -0700
commit6ed325a3c881565cc2473d1fbfa69d806b4b7bbf (patch)
treefccf7b5c5035386928dec4d08e9008c2a9b672b8
parent1b30df94470464ac17c75b07d5062e03af1ef68a (diff)
downloadsyslinux-6ed325a3c881565cc2473d1fbfa69d806b4b7bbf.tar.gz
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@zytor.com>
-rw-r--r--com32/include/syslinux/pmapi.h2
-rw-r--r--com32/lib/sys/open.c2
-rw-r--r--core/fs/chdir.c3
-rw-r--r--core/fs/fs.c13
-rw-r--r--core/fs/pxe/pxe.c10
-rw-r--r--core/fs/readdir.c3
-rw-r--r--core/include/fs.h6
7 files changed, 22 insertions, 17 deletions
diff --git a/com32/include/syslinux/pmapi.h b/com32/include/syslinux/pmapi.h
index e96b8ec0..14a2c326 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 3e7bb6cf..b4673b20 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 9e8dfd2e..0df0286b 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 54099860..81dafe9d 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 3242a9f5..b7ec0506 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 d071affd..a437011d 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 4301481e..0691caa5 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 *);