File: ext2_mount.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 (62 lines) | stat: -rw-r--r-- 1,061 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
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 *
 * (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"

#define SB_OFFSET (2)

ext2_VOLUME* ext2_mount(int fd)
{
	ext2_VOLUME *volume;
	struct ext2_super_block *super;
	char *buffer;

	super = (struct ext2_super_block*)malloc(sizeof(struct ext2_super_block));
	if (super == NULL)
		return NULL;

	ext2_get_super(fd, super);
	if (super->s_magic != EXT2_SUPER_MAGIC) {
		free(super);
		return NULL;
	}

	buffer = (char*)malloc(EXT2_BLOCK_SIZE(super));
	if (buffer == NULL) {
		free(super);
		return NULL;
	}

	volume = (ext2_VOLUME*)malloc(sizeof(ext2_VOLUME));
	if (volume == NULL) {
		free(super);
		free(buffer);
		return NULL;
	}

	volume->buffer = buffer;
	volume->fd = fd;
	volume->super = super;

	volume->current = -1;
	ext2_read_block(volume, 0);

	return volume;
}

int ext2_umount(ext2_VOLUME* volume)
{
	if (volume == NULL)
		return -1;
	free(volume->super);
	free(volume->buffer);
	free(volume);
	return 0;
}