mirror of
https://github.com/psankar/simplefs.git
synced 2025-07-29 17:04:12 +02:00
Load superblock from disk for a simplefs formatted filesystem
This commit is contained in:
parent
a3d7c0337e
commit
3198c6614e
21
README
21
README
@ -21,4 +21,23 @@ To test:
|
||||
409600 bytes (410 kB) copied, 0.00175839 s, 233 MB/s
|
||||
~/src/simplefs> ./mkfs-simplefs image
|
||||
Super block written succesfully
|
||||
~/src/simplefs>
|
||||
|
||||
# switch to root user (or use with sudo)
|
||||
|
||||
linux-okb0:/home/psankar/src/simplefs # insmod simplefs.ko
|
||||
linux-okb0:/home/psankar/src/simplefs # dmesg
|
||||
[ 2963.323701] Sucessfully registered simplefs
|
||||
linux-okb0:/home/psankar/src/simplefs # mount -o loop -t simplefs image /home/psankar/src/simplefs/mount/
|
||||
linux-okb0:/home/psankar/src/simplefs # dmesg
|
||||
[ 2963.323701] Sucessfully registered simplefs
|
||||
[ 2977.453535] The magic number obtained in disk is: [268640275]
|
||||
[ 2977.453544] simplefs filesystem of version [1] formatted with a block size of [4096] detected in the device.
|
||||
[ 2977.453551] simplefs is succesfully mounted on [/dev/loop1]
|
||||
linux-okb0:/home/psankar/src/simplefs # umount mount/
|
||||
linux-okb0:/home/psankar/src/simplefs # dmesg
|
||||
[ 2963.323701] Sucessfully registered simplefs
|
||||
[ 2977.453535] The magic number obtained in disk is: [268640275]
|
||||
[ 2977.453544] simplefs filesystem of version [1] formatted with a block size of [4096] detected in the device.
|
||||
[ 2977.453551] simplefs is succesfully mounted on [/dev/loop1]
|
||||
[ 2994.184508] simplefs superblock is destroyed. Unmount succesful.
|
||||
linux-okb0:/home/psankar/src/simplefs # rmmod simplefs.ko
|
||||
|
26
simple.c
26
simple.c
@ -8,6 +8,7 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/buffer_head.h>
|
||||
|
||||
#include "simple.h"
|
||||
|
||||
@ -76,6 +77,31 @@ struct inode *simplefs_get_inode(struct super_block *sb,
|
||||
int simplefs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct buffer_head *bh;
|
||||
struct simplefs_super_block *sb_disk;
|
||||
|
||||
bh = (struct buffer_head *)sb_bread(sb, 0);
|
||||
|
||||
sb_disk = (struct simplefs_super_block *)bh->b_data;
|
||||
|
||||
printk(KERN_INFO "The magic number obtained in disk is: [%d]\n",
|
||||
sb_disk->magic);
|
||||
|
||||
if (unlikely(sb_disk->magic != SIMPLEFS_MAGIC)) {
|
||||
printk(KERN_ERR
|
||||
"The filesystem that you try to mount is not of type simplefs. Magicnumber mismatch.");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (unlikely(sb_disk->block_size != SIMPLEFS_DEFAULT_BLOCK_SIZE)) {
|
||||
printk(KERN_ERR
|
||||
"simplefs seem to be formatted using a non-standard block size.");
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
printk(KERN_INFO
|
||||
"simplefs filesystem of version [%d] formatted with a block size of [%d] detected in the device.\n",
|
||||
sb_disk->version, sb_disk->block_size);
|
||||
|
||||
/* A magic number that uniquely identifies our filesystem type */
|
||||
sb->s_magic = SIMPLEFS_MAGIC;
|
||||
|
Loading…
x
Reference in New Issue
Block a user