From: Matt Fleming Date: Mon, 6 Jun 2011 21:17:03 +0000 (+0100) Subject: core: Return a file descriptor from open_config() X-Git-Tag: syslinux-5.00-pre1~41^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7d484dfec2e4e807503dce754be6c54574e4d98;p=platform%2Fupstream%2Fsyslinux.git 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 --- diff --git a/core/Makefile b/core/Makefile index 96a7b9f..95424dc 100644 --- a/core/Makefile +++ b/core/Makefile @@ -25,7 +25,7 @@ include $(MAKEDIR)/embedded.mk -include $(topdir)/version.mk OPTFLAGS = -INCLUDES = -I./include -I$(com32)/include +INCLUDES = -I./include -I$(com32)/include -I$(com32)/lib # This is very similar to cp437; technically it's for Norway and Denmark, # but it's unlikely the characters that are different will be used in diff --git a/core/fs/fs.c b/core/fs/fs.c index 39ba09e..91a2d53 100644 --- a/core/fs/fs.c +++ b/core/fs/fs.c @@ -1,8 +1,10 @@ +#include #include #include #include #include #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)