diff --git a/README b/README index 0bd2bf8..a737ce6 100644 --- a/README +++ b/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 diff --git a/simple.c b/simple.c index 69c82c2..5ec21d1 100644 --- a/simple.c +++ b/simple.c @@ -8,6 +8,7 @@ #include #include #include +#include #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; diff --git a/simple.h b/simple.h index 1e54c7b..aefea3a 100644 --- a/simple.h +++ b/simple.h @@ -7,5 +7,5 @@ struct simplefs_super_block { unsigned int block_size; unsigned int free_blocks; - char padding[ (4 * 1024) - (4 * sizeof(unsigned int))]; + char padding[(4 * 1024) - (4 * sizeof(unsigned int))]; };