* problems in implementing a new file system
@ 2003-02-17 22:43 Ronghua Zhang
2003-02-17 22:53 ` Ronghua Zhang
0 siblings, 1 reply; 2+ messages in thread
From: Ronghua Zhang @ 2003-02-17 22:43 UTC (permalink / raw)
To: linux-fsdevel, kernelnewbies
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1722 bytes --]
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
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1361 bytes --]
#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)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: problems in implementing a new file system
2003-02-17 22:43 problems in implementing a new file system Ronghua Zhang
@ 2003-02-17 22:53 ` Ronghua Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Ronghua Zhang @ 2003-02-17 22:53 UTC (permalink / raw)
To: linux-fsdevel, kernelnewbies
Oh, I just forgot to mention that the kernel is 2.4.19 and gcc version is
3.2. I also used uml to trace it, and I found that the 'magic' happens
within get_new_inode():
....
inode->i_sb = sb;
...
if (sb->s_op->read_inode2) sb->s_op->read_inode2(inode, opaque);
else sb->s_op->read_inode(inode);
just before sb->s_op_read_inode() is executed, inode->i_sb is still sb.
But once the function (which is snet_read_inode()) is called, inode->i_sb
just magically point to some other place.
rz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-02-17 22:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-17 22:43 problems in implementing a new file system Ronghua Zhang
2003-02-17 22:53 ` Ronghua Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).