Load superblock from disk for a simplefs formatted filesystem

This commit is contained in:
Sankar சங்கர் 2013-04-12 00:16:18 +05:30
parent a3d7c0337e
commit 3198c6614e
3 changed files with 47 additions and 2 deletions

21
README
View File

@ -21,4 +21,23 @@ To test:
409600 bytes (410 kB) copied, 0.00175839 s, 233 MB/s 409600 bytes (410 kB) copied, 0.00175839 s, 233 MB/s
~/src/simplefs> ./mkfs-simplefs image ~/src/simplefs> ./mkfs-simplefs image
Super block written succesfully 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

View File

@ -8,6 +8,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/buffer_head.h>
#include "simple.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) int simplefs_fill_super(struct super_block *sb, void *data, int silent)
{ {
struct inode *inode; 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 */ /* A magic number that uniquely identifies our filesystem type */
sb->s_magic = SIMPLEFS_MAGIC; sb->s_magic = SIMPLEFS_MAGIC;

View File

@ -7,5 +7,5 @@ struct simplefs_super_block {
unsigned int block_size; unsigned int block_size;
unsigned int free_blocks; unsigned int free_blocks;
char padding[ (4 * 1024) - (4 * sizeof(unsigned int))]; char padding[(4 * 1024) - (4 * sizeof(unsigned int))];
}; };