problems in implementing a new file system

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am implementing a new file system. As a prototype, only read_super and
read_inode are implmented. What suprises me is that, when read_inode is
called to read in root inode , inode->i_sb is _not_ the super block
pointer passed to read_super function call. Can anybody kindly help me
find the problem? My code is the following:

#include <linux/config.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/snet_fs.h>

static struct super_operations snet_sops = {
    read_inode:     snet_read_inode,
};

void snet_read_inode(struct inode *inode)
{
    SNETFS_DEBUG("snet_read_inode, ino = %lu, sb = %p\n", inode->i_ino,
                 inode->i_sb);
    if (inode->i_ino == 1){
        inode->i_mode = S_IFDIR;
    }
}

struct super_block * snet_read_super(struct super_block * sb, void * data,
                                     int silent)
{
    SNETFS_DEBUG("snet_read_super() called, sb = %p\n", sb);
    sb->s_magic = SNET_SUPER_MAGIC;
    sb->s_op = &snet_sops;
    sb->s_root = d_alloc_root(iget(sb, 1));
    if (!sb->s_root){
        printk("snet_read_super: get root inode failed\n");
        return NULL;
    }

    return sb;
}

static DECLARE_FSTYPE(snet_fs_type, "simple", snet_read_super, 0);

static int __init init_snet_fs(void)
{
    return register_filesystem(&snet_fs_type);
}

static void __exit exit_snet_fs(void)
{
    unregister_filesystem(&snet_fs_type);
}

EXPORT_NO_SYMBOLS;

module_init(init_snet_fs)
module_exit(exit_snet_fs)


To test it, I first insmod snet.o, then run mount /dev/zero /mnt -t
simple. dmesg show the following:
snet_read_super() called, sb = d1f86800
snet_read_inode() called, sb = c02cd4a0

notice that two sb are different, which should not be.

Thanks.

rz
#include <linux/config.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/snet_fs.h>

static struct super_operations snet_sops = {
	read_inode:     snet_read_inode,
};

void snet_read_inode(struct inode *inode)
{
	SNETFS_DEBUG("snet_read_inode, ino = %lu, sb = %p\n", inode->i_ino,
	             inode->i_sb);
	if (SNET_IS_RESERVED_DIR(inode->i_ino)){
		inode->i_mode = S_IFDIR;
	}
}

struct super_block * snet_read_super(struct super_block * sb, void * data, 
                                     int silent)
{	
	SNETFS_DEBUG("snet_read_super() called, sb = %p\n", sb);
	sb->s_magic = SNET_SUPER_MAGIC;
	sb->s_op = &snet_sops;
	sb->s_root = d_alloc_root(iget(sb, SNET_ROOT_INO));
	if (!sb->s_root){
		printk("snet_read_super: get root inode failed\n");
		return NULL; 
	}

	/* TODO: allocate the first page for /, /raw, /event, /proc */
	SNETFS_DEBUG("snet_read_super() done\n");
	return sb;
}

static DECLARE_FSTYPE(snet_fs_type, "simple", snet_read_super, 0);

static int __init init_snet_fs(void)
{
	SNETFS_DEBUG("init_snet_fs() called\n");

	return register_filesystem(&snet_fs_type);
}

static void __exit exit_snet_fs(void)
{
	SNETFS_DEBUG("exit_snet_fs() called\n");
	unregister_filesystem(&snet_fs_type);
}

EXPORT_NO_SYMBOLS;

module_init(init_snet_fs)
module_exit(exit_snet_fs)


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux