2008-04-12 21:17:49 +00:00
|
|
|
/*
|
|
|
|
*
|
2013-09-05 12:39:22 +00:00
|
|
|
* (c) 2008 Laurent Vivier <Laurent@Vivier.EU>
|
2008-04-12 21:17:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2008-04-20 16:25:24 +00:00
|
|
|
#include <libstream.h>
|
2008-04-12 21:17:49 +00:00
|
|
|
#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"
|
|
|
|
|
|
|
|
#define SB_OFFSET (2)
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
stream_VOLUME* ext2_mount(device_io_t *device)
|
2008-04-12 21:17:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2008-04-13 22:24:57 +00:00
|
|
|
ext2_get_super(device, super);
|
2008-04-12 21:17:49 +00:00
|
|
|
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->device = device;
|
|
|
|
volume->super = super;
|
|
|
|
|
|
|
|
volume->current = -1;
|
|
|
|
ext2_read_block(volume, 0);
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
return (stream_VOLUME*)volume;
|
2008-04-12 21:17:49 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 16:25:24 +00:00
|
|
|
int ext2_umount(stream_VOLUME* _volume)
|
2008-04-12 21:17:49 +00:00
|
|
|
{
|
2008-04-20 16:25:24 +00:00
|
|
|
ext2_VOLUME *volume = (ext2_VOLUME*)_volume;
|
2008-04-12 21:17:49 +00:00
|
|
|
if (volume == NULL)
|
|
|
|
return -1;
|
|
|
|
free(volume->super);
|
|
|
|
free(volume->buffer);
|
|
|
|
free(volume);
|
|
|
|
return 0;
|
|
|
|
}
|