Patched to support 'cd' to the mountpoint and do an 'ls' there

This commit is contained in:
Sankar சங்கர் 2013-03-17 14:22:56 +05:30
parent 0e2ed5c9aa
commit f050b4f8e7
2 changed files with 40 additions and 18 deletions

31
README
View File

@ -22,23 +22,18 @@ Repeat everytime after making changes to the source:
linux-okb0:/home/psankar/src/simplefs > make
linux-okb0:/home/psankar/src/simplefs > su - ; # switch to root user if not already, or use sudo
linux-okb0:/home/psankar/src/simplefs # dmesg -c
linux-okb0:/home/psankar/src/simplefs # insmod simplefs.ko ; mount -o loop -t simplefs image /home/psankar/src/simplefs/mount/ ; dmesg
[ 5788.269663] Sucessfully registered simplefs
[ 5788.274803] simplefs is succesfully mounted on [/dev/loop2]
linux-okb0:/home/psankar/src/simplefs # cd mount/
linux-okb0:/home/psankar/src/simplefs/mount # ls
linux-okb0:/home/psankar/src/simplefs/mount # cd ..
linux-okb0:/home/psankar/src/simplefs # umount mount ; rmmod simplefs.ko
linux-okb0:/home/psankar/src/simplefs # dmesg
linux-okb0:/home/psankar/src/simplefs # insmod simplefs.ko
linux-okb0:/home/psankar/src/simplefs # dmesg
[ 7467.426112] 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
[ 7467.426112] Sucessfully registered simplefs
[ 7478.223432] simplefs is succesfully mounted on [/dev/loop1]
linux-okb0:/home/psankar/src/simplefs # umount /home/psankar/src/simplefs/mount/
linux-okb0:/home/psankar/src/simplefs # dmesg
[ 7467.426112] Sucessfully registered simplefs
[ 7478.223432] simplefs is succesfully mounted on [/dev/loop1]
[ 7498.889439] simplefs superblock is destroyed. Unmount succesful.
linux-okb0:/home/psankar/src/simplefs # rmmod simplefs.ko
linux-okb0:/home/psankar/src/simplefs # dmesg
[ 7467.426112] Sucessfully registered simplefs
[ 7478.223432] simplefs is succesfully mounted on [/dev/loop1]
[ 7498.889439] simplefs superblock is destroyed. Unmount succesful.
[ 7506.906067] Sucessfully unregistered simplefs
[ 5788.269663] Sucessfully registered simplefs
[ 5788.274803] simplefs is succesfully mounted on [/dev/loop2]
[ 5814.008604] simplefs superblock is destroyed. Unmount succesful.
[ 5814.014065] Sucessfully unregistered simplefs
linux-okb0:/home/psankar/src/simplefs #

View File

@ -9,6 +9,31 @@
#include <linux/module.h>
#include <linux/fs.h>
static int simplefs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
/* ls will list nothing as of now.
* Basic skeleton code to make ls (readdir) work for simplefs */
return 0;
}
const struct file_operations simplefs_dir_operations = {
.owner = THIS_MODULE,
.readdir = simplefs_readdir,
};
struct dentry *simplefs_lookup(struct inode *parent_inode,
struct dentry *child_dentry, unsigned int flags)
{
/* The lookup function is used for dentry association.
* As of now, we don't deal with dentries in simplefs.
* So we will keep this simple for now and revisit later */
return NULL;
}
static struct inode_operations simplefs_inode_ops = {
.lookup = simplefs_lookup,
};
/* This function creates, configures and returns an inode,
* for the asked file (or) directory (differentiated by the mode param),
* under the directory specified by the dir param
@ -54,6 +79,8 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_magic = 0x10032013;
inode = simplefs_get_inode(sb, NULL, S_IFDIR, 0);
inode->i_op = &simplefs_inode_ops;
inode->i_fop = &simplefs_dir_operations;
sb->s_root = d_make_root(inode);
if (!sb->s_root)
return -ENOMEM;