diff options
author | Matt Fleming <matt.fleming@linux.intel.com> | 2011-06-06 22:17:03 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@linux.intel.com> | 2011-06-07 13:04:23 +0100 |
commit | e7d484dfec2e4e807503dce754be6c54574e4d98 (patch) | |
tree | e78c8e09536d11ca515ab3ae6c58aa6bd07723f2 /core/fs/fs.c | |
parent | f181c7083a188d7c189323990057b55374908449 (diff) | |
download | syslinux-e7d484dfec2e4e807503dce754be6c54574e4d98.tar.gz |
core: Return a file descriptor from open_config()
Wrap open_config() the same way that open() wraps open_file(). The
only user of open_config() requires access to a file descriptor so it
makes sense to return a file descriptor.
The file handle implementation is a historic piece of code and this
patch tries to hide it as they will likely be removed at a future
point in time. Furthermore, the file handle code is very core-specific
and should not be exposed to any callers of open_config().
Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
Diffstat (limited to 'core/fs/fs.c')
-rw-r--r-- | core/fs/fs.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/core/fs/fs.c b/core/fs/fs.c index 39ba09eb..91a2d534 100644 --- a/core/fs/fs.c +++ b/core/fs/fs.c @@ -1,8 +1,10 @@ +#include <sys/file.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <dprintf.h> #include "core.h" +#include "dev.h" #include "fs.h" #include "cache.h" @@ -74,12 +76,33 @@ void _close_file(struct file *file) free_file(file); } +extern const struct input_dev __file_dev; + /* * Find and open the configuration file */ -int open_config(struct com32_filedata *filedata) +int open_config(void) { - return this_fs->fs_ops->open_config(filedata); + int fd, handle; + struct file_info *fp; + + fd = opendev(&__file_dev, NULL, O_RDONLY); + if (fd < 0) + return -1; + + fp = &__file_info[fd]; + + handle = this_fs->fs_ops->open_config(&fp->i.fd); + if (handle < 0) { + close(fd); + errno = ENOENT; + return -1; + } + + fp->i.offset = 0; + fp->i.nbytes = 0; + + return fd; } void pm_mangle_name(com32sys_t *regs) |