File: ext2_opendir.c

package info (click to toggle)
openbios-sparc 1.0%2Bsvn640-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,412 kB
  • ctags: 12,091
  • sloc: ansic: 57,249; asm: 2,680; xml: 1,335; cpp: 414; makefile: 224; sh: 190
file content (49 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 *
 * (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_DIR* ext2_opendir(ext2_VOLUME *volume, const char *name)
{
	ext2_DIR* dir;
	int ino;
	struct ext2_inode *inode;
	int ret;

	ino = ext2_seek_name(volume, name);
	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_ISDIR(inode->i_mode)) {
		free(inode);
		return NULL;
	}

	dir = (ext2_DIR*)malloc(sizeof(ext2_DIR));
	if (dir == NULL) {
		free(inode);
		return NULL;
	}
	dir->volume = (ext2_VOLUME*)volume;
	dir->inode = inode;
	dir->index = 0;

	return dir;
}