2008-04-12 21:17:49 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2008 Laurent Vivier <Laurent@lvivier.info>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "libext2.h"
|
2008-04-20 16:25:24 +00:00
|
|
|
#include "ext2.h"
|
2008-04-12 21:17:49 +00:00
|
|
|
#include "ext2_utils.h"
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
stream_DIR* ext2_opendir(stream_VOLUME *volume, char *name)
|
2008-04-12 21:17:49 +00:00
|
|
|
{
|
|
|
|
ext2_DIR* dir;
|
|
|
|
int ino;
|
|
|
|
struct ext2_inode *inode;
|
|
|
|
int ret;
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
ino = ext2_seek_name((ext2_VOLUME*)volume, name);
|
2008-04-12 21:17:49 +00:00
|
|
|
if (ino == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
inode = (struct ext2_inode*)malloc(sizeof(struct ext2_inode));
|
|
|
|
if (inode == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
ret = ext2_get_inode((ext2_VOLUME*)volume, ino, inode);
|
2008-04-12 21:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-04-20 16:25:24 +00:00
|
|
|
dir->volume = (ext2_VOLUME*)volume;
|
2008-04-12 21:17:49 +00:00
|
|
|
dir->inode = inode;
|
|
|
|
dir->index = 0;
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
return (stream_DIR*)dir;
|
2008-04-12 21:17:49 +00:00
|
|
|
}
|