core: Return a file descriptor from open_config()
authorMatt Fleming <matt.fleming@linux.intel.com>
Mon, 6 Jun 2011 21:17:03 +0000 (22:17 +0100)
committerMatt Fleming <matt.fleming@linux.intel.com>
Tue, 7 Jun 2011 12:04:23 +0000 (13:04 +0100)
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>
core/Makefile
core/fs/fs.c

index 96a7b9f..95424dc 100644 (file)
@@ -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
index 39ba09e..91a2d53 100644 (file)
@@ -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)