|
|
Subscribe / Log in / New account

Creating Linux virtual filesystems

Creating Linux virtual filesystems

Posted Apr 4, 2012 5:24 UTC (Wed) by crxz0193 (guest, #75555)
Parent article: Creating Linux virtual filesystems

to make it work with the linux 3.0 change following:
/*
* Stuff to pass in when registering the filesystem.
*/
static struct super_block *lfs_get_super(struct file_system_type *fst,
int flags, char *devname, void *data)
{
/* return get_sb_single(fst, flags, data, lfs_fill_super, mnt);*/
return mount_single(fst, flags, data, lfs_fill_super);
}

static struct file_system_type lfs_type = {
.owner = THIS_MODULE,
.name = "lwnfs",
.mount = lfs_get_super,
/*.get_sb = lfs_get_super,*/
.kill_sb = kill_litter_super,
};


to post comments

Creating Linux virtual filesystems

Posted Apr 4, 2012 6:11 UTC (Wed) by viro (subscriber, #7872) [Link]

Several points:

1) return value of mount_single() is struct dentry *; so's that of ->mount(). IOW, the body is correct, but declaration isn't - it should return struct dentry *, not struct super_block *.

2) use d_make_root() instead of d_alloc_root(); cleanup is easier with that one (and d_alloc_root() will be gone in 3.4 anyway). In this case it becomes simply

root = lfs_make_inode (sb, S_IFDIR | 0755);
if (root) {
root->i_op = &simple_dir_inode_operations;
root->i_fop = &simple_dir_operations;
}
sb->s_root = d_make_root(root);
if (!sb->s_root)
return -ENOMEM;
lfs_create_files(sb, sb->s_root);
return 0;

3) simple_read_from_buffer() is your friend. Instead of

len = snprintf(tmp, TMPSIZE, "%d\n", v);
if (*offset > len)
return 0;
if (count > len - *offset)
count = len - *offset;
/*
* Copy it back, increment the offset, and we're done.
*/
if (copy_to_user(buf, tmp + *offset, count))
return -EFAULT;
*offset += count;
return count;

just do

len = snprintf(tmp, TMPSIZE, "%d\n", v);
return simple_read_from_buffer(buf, count, offset, tmp, len);

and be done with that.

4) no need to open-code d_alloc_name(). Or simple_mkdir(), for that matter...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds