summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/fs/ext2/ext2_open.c
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@intel.com>2015-08-28 09:58:54 +0800
committerYang Zhang <yang.z.zhang@intel.com>2015-09-01 12:44:00 +0800
commite44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch)
tree66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/openbios/fs/ext2/ext2_open.c
parent9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff)
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/openbios/fs/ext2/ext2_open.c')
-rw-r--r--qemu/roms/openbios/fs/ext2/ext2_open.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/qemu/roms/openbios/fs/ext2/ext2_open.c b/qemu/roms/openbios/fs/ext2/ext2_open.c
new file mode 100644
index 000000000..03a89bbd0
--- /dev/null
+++ b/qemu/roms/openbios/fs/ext2/ext2_open.c
@@ -0,0 +1,65 @@
+/*
+ *
+ * (c) 2008-2009 Laurent Vivier <Laurent@lvivier.info>
+ *
+ * This file has been copied from EMILE, http://emile.sf.net
+ *
+ */
+
+#include "libext2.h"
+#include "ext2.h"
+#include "ext2_utils.h"
+
+ext2_FILE* ext2_open(ext2_VOLUME *volume, const char* pathname)
+{
+ ext2_FILE *file;
+ struct ext2_inode *inode;
+ int ino;
+ int ret;
+
+ ino = ext2_seek_name(volume, pathname);
+ if (ino == 0)
+ return NULL;
+
+ inode = (struct ext2_inode*)malloc(sizeof(struct ext2_inode));
+ if (inode == NULL)
+ return NULL;
+
+ ret = ext2_get_inode(volume, ino, inode);
+ if (ret == -1) {
+ free(inode);
+ return NULL;
+ }
+ if (S_ISLNK(inode->i_mode)) {
+ static char buffer[1024];
+ int i, last = 0;
+ strcpy(buffer, pathname);
+ for (i = 0; buffer[i]; i++)
+ if (buffer[i] == '\\')
+ last = i;
+ buffer[last] = '\\';
+ strcpy(buffer + last + 1, (char*)inode->i_block);
+ ino = ext2_seek_name((ext2_VOLUME*)volume, buffer);
+ if (ino == 0) {
+ free(inode);
+ return NULL;
+ }
+ ret = ext2_get_inode((ext2_VOLUME*)volume, ino, inode);
+ if (ret == -1) {
+ free(inode);
+ return NULL;
+ }
+ }
+
+ file = (ext2_FILE*)malloc(sizeof(ext2_FILE));
+ if (file == NULL) {
+ free(inode);
+ return NULL;
+ }
+ file->volume = volume;
+ file->inode = inode;
+ file->offset = 0;
+ file->path = strdup(pathname);
+
+ return file;
+}