From be678577f6e285ada2e1d5ba66acb9eafe8b15d3 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Tue, 12 Aug 2008 23:36:12 +0000 Subject: [PATCH] ext2_init() fails if device is not an ext2 filesystem --- libext2/ext2_init.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libext2/ext2_init.c b/libext2/ext2_init.c index 2f29cb8..35703fe 100644 --- a/libext2/ext2_init.c +++ b/libext2/ext2_init.c @@ -5,9 +5,23 @@ */ #include "libext2.h" +#include "ext2.h" +#include "ext2_utils.h" + +static int is_ext2(device_io_t *device) +{ + struct ext2_super_block super; + ext2_get_super(device, &super); + if (super.s_magic == EXT2_SUPER_MAGIC) + return 1; + return 0; +} int ext2_init(device_io_t *device, filesystem_io_t *fs) { + if (!is_ext2(device)) + return -1; + fs->mount = ext2_mount; fs->open = ext2_open; fs->read = ext2_read;