diff options
author | Timothy Pearson <tpearson@raptorengineering.com> | 2019-05-11 15:12:49 -0500 |
---|---|---|
committer | Timothy Pearson <tpearson@raptorengineering.com> | 2019-05-11 15:12:49 -0500 |
commit | 9e80202352dd49bdd9e67b8b906d86f058431505 (patch) | |
tree | 5673c17aad6e3833da8c4ff21b5a11f666ec9fbe /src/roms/openbios/fs/ext2/ext2_mount.c | |
download | hqemu-9e80202352dd49bdd9e67b8b906d86f058431505.zip hqemu-9e80202352dd49bdd9e67b8b906d86f058431505.tar.gz |
Diffstat (limited to 'src/roms/openbios/fs/ext2/ext2_mount.c')
-rw-r--r-- | src/roms/openbios/fs/ext2/ext2_mount.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/roms/openbios/fs/ext2/ext2_mount.c b/src/roms/openbios/fs/ext2/ext2_mount.c new file mode 100644 index 0000000..06b63de --- /dev/null +++ b/src/roms/openbios/fs/ext2/ext2_mount.c @@ -0,0 +1,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; +} |