Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / fs / ext2 / ext2_opendir.c
1 /*
2  *
3  * (c) 2008-2009 Laurent Vivier <Laurent@lvivier.info>
4  *
5  * This file has been copied from EMILE, http://emile.sf.net
6  *
7  */
8
9 #include "libext2.h"
10 #include "ext2.h"
11 #include "ext2_utils.h"
12
13 ext2_DIR* ext2_opendir(ext2_VOLUME *volume, const char *name)
14 {
15         ext2_DIR* dir;
16         int ino;
17         struct ext2_inode *inode;
18         int ret;
19
20         ino = ext2_seek_name(volume, name);
21         if (ino == 0)
22                 return NULL;
23
24         inode = (struct ext2_inode*)malloc(sizeof(struct ext2_inode));
25         if (inode == NULL)
26                 return NULL;
27
28         ret = ext2_get_inode(volume, ino, inode);
29         if (ret == -1) {
30                 free(inode);
31                 return NULL;
32         }
33
34         if (!S_ISDIR(inode->i_mode)) {
35                 free(inode);
36                 return NULL;
37         }
38
39         dir = (ext2_DIR*)malloc(sizeof(ext2_DIR));
40         if (dir == NULL) {
41                 free(inode);
42                 return NULL;
43         }
44         dir->volume = (ext2_VOLUME*)volume;
45         dir->inode = inode;
46         dir->index = 0;
47
48         return dir;
49 }