/*! 2017. 1.07 study -ing */ int __init sysfs_init(void) { int err; sysfs_root = kernfs_create_root(NULL, NULL); if (IS_ERR(sysfs_root)) return PTR_ERR(sysfs_root); sysfs_root_kn = sysfs_root->kn; err = register_filesystem(&sysfs_fs_type); if (err) { kernfs_destroy_root(sysfs_root); return err; } return 0; }
static struct dentry *dslab_mount(struct file_system_type *fs_type, int flags, const char *unused_dev_name, void *data) { struct dentry *dentry = NULL; struct kernfs_root *kf_root; struct kernfs_node *kn; bool new_sb; kf_root = kernfs_create_root(&dslab_kf_syscall_ops, KERNFS_ROOT_CREATE_DEACTIVATED, NULL); if (IS_ERR(kf_root)) goto out; kn = __kernfs_create_file(kf_root->kn, "dslab", FS_MODE, 0, &dslab_kernfs_ops, NULL, NULL, NULL); if (IS_ERR(kn)) goto destroy_root; dentry = kernfs_mount(fs_type, flags, kf_root, FS_MAGIC, &new_sb); if (IS_ERR(dentry) || !new_sb) goto destroy_kn; kernfs_activate(kf_root->kn); goto out; destroy_kn: kernfs_remove_by_name(kf_root->kn, "dslab"); destroy_root: kernfs_destroy_root(kf_root); kf_root = NULL; out: return dentry; }