|
|
1.1 root 1: /*
2: *
3: * (c) 2008-2009 Laurent Vivier <[email protected]>
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_FILE* ext2_open(ext2_VOLUME *volume, const char* pathname)
14: {
15: ext2_FILE *file;
16: struct ext2_inode *inode;
17: int ino;
18: int ret;
19:
20: ino = ext2_seek_name(volume, pathname);
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: if (S_ISLNK(inode->i_mode)) {
34: static char buffer[1024];
35: int i, last = 0;
36: strcpy(buffer, pathname);
37: for (i = 0; buffer[i]; i++)
38: if (buffer[i] == '\\')
39: last = i;
40: buffer[last] = '\\';
41: strcpy(buffer + last + 1, (char*)inode->i_block);
42: ino = ext2_seek_name((ext2_VOLUME*)volume, buffer);
43: if (ino == 0) {
44: free(inode);
45: return NULL;
46: }
47: ret = ext2_get_inode((ext2_VOLUME*)volume, ino, inode);
48: if (ret == -1) {
49: free(inode);
50: return NULL;
51: }
52: }
53:
54: file = (ext2_FILE*)malloc(sizeof(ext2_FILE));
55: if (file == NULL) {
56: free(inode);
57: return NULL;
58: }
59: file->volume = volume;
60: file->inode = inode;
61: file->offset = 0;
62: file->path = strdup(pathname);
63:
64: return file;
65: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.