[syslinux:elflink] core: Return a file descriptor from open_config()

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Tue Jul 12 20:03:18 PDT 2011


Commit-ID:  e7d484dfec2e4e807503dce754be6c54574e4d98
Gitweb:     http://syslinux.zytor.com/commit/e7d484dfec2e4e807503dce754be6c54574e4d98
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Mon, 6 Jun 2011 22:17:03 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Tue, 7 Jun 2011 13:04:23 +0100

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 at linux.intel.com>


---
 core/Makefile |    2 +-
 core/fs/fs.c  |   27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)

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 <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)



More information about the Syslinux-commits mailing list