fs: add detection for ext2 filesystems
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
30bf724282
commit
8584c56f5e
5 changed files with 183 additions and 15 deletions
44
fs/ext2.c
Normal file
44
fs/ext2.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <fs/ext2.h>
|
||||
|
||||
static int ext2_read_super(struct block_device *bdev, struct ext2_superblock *sb_struct)
|
||||
{
|
||||
char *buf = kmalloc(1024, ALLOC_DMA);
|
||||
if (!buf)
|
||||
return -1;
|
||||
|
||||
int ret = block_read(bdev, buf, 2, 1);
|
||||
if (ret < 0) {
|
||||
kfree(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ext2_superblock *sb = (struct ext2_superblock *)buf;
|
||||
if (sb->magic != EXT2_SUPER_MAGIC) {
|
||||
kfree(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(sb_struct, buf, sizeof(*sb_struct));
|
||||
kfree(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct ext2fs *ext2_init_fs(struct block_device *bdev)
|
||||
{
|
||||
struct ext2fs *ret = kmalloc(sizeof(*ret), ALLOC_KERN);
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->bdev = bdev;
|
||||
if (ext2_read_super(bdev, ret->sb) < 0) {
|
||||
kfree(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
Loading…
Reference in a new issue