⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inode.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt){	struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb);	seq_printf(m, ",user_id=%u", fc->user_id);	seq_printf(m, ",group_id=%u", fc->group_id);	if (fc->flags & FUSE_DEFAULT_PERMISSIONS)		seq_puts(m, ",default_permissions");	if (fc->flags & FUSE_ALLOW_OTHER)		seq_puts(m, ",allow_other");	if (fc->max_read != ~0)		seq_printf(m, ",max_read=%u", fc->max_read);	return 0;}static struct fuse_conn *new_conn(void){	struct fuse_conn *fc;	int err;	fc = kzalloc(sizeof(*fc), GFP_KERNEL);	if (fc) {		spin_lock_init(&fc->lock);		mutex_init(&fc->inst_mutex);		atomic_set(&fc->count, 1);		init_waitqueue_head(&fc->waitq);		init_waitqueue_head(&fc->blocked_waitq);		init_waitqueue_head(&fc->reserved_req_waitq);		INIT_LIST_HEAD(&fc->pending);		INIT_LIST_HEAD(&fc->processing);		INIT_LIST_HEAD(&fc->io);		INIT_LIST_HEAD(&fc->interrupts);		atomic_set(&fc->num_waiting, 0);		fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;		fc->bdi.unplug_io_fn = default_unplug_io_fn;		err = bdi_init(&fc->bdi);		if (err) {			kfree(fc);			fc = NULL;			goto out;		}		fc->reqctr = 0;		fc->blocked = 1;		fc->attr_version = 1;		get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));	}out:	return fc;}void fuse_conn_put(struct fuse_conn *fc){	if (atomic_dec_and_test(&fc->count)) {		if (fc->destroy_req)			fuse_request_free(fc->destroy_req);		mutex_destroy(&fc->inst_mutex);		bdi_destroy(&fc->bdi);		kfree(fc);	}}struct fuse_conn *fuse_conn_get(struct fuse_conn *fc){	atomic_inc(&fc->count);	return fc;}static struct inode *get_root_inode(struct super_block *sb, unsigned mode){	struct fuse_attr attr;	memset(&attr, 0, sizeof(attr));	attr.mode = mode;	attr.ino = FUSE_ROOT_ID;	attr.nlink = 1;	return fuse_iget(sb, 1, 0, &attr, 0, 0);}static const struct super_operations fuse_super_operations = {	.alloc_inode    = fuse_alloc_inode,	.destroy_inode  = fuse_destroy_inode,	.read_inode	= fuse_read_inode,	.clear_inode	= fuse_clear_inode,	.drop_inode	= generic_delete_inode,	.remount_fs	= fuse_remount_fs,	.put_super	= fuse_put_super,	.umount_begin	= fuse_umount_begin,	.statfs		= fuse_statfs,	.show_options	= fuse_show_options,};static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req){	struct fuse_init_out *arg = &req->misc.init_out;	if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION)		fc->conn_error = 1;	else {		unsigned long ra_pages;		if (arg->minor >= 6) {			ra_pages = arg->max_readahead / PAGE_CACHE_SIZE;			if (arg->flags & FUSE_ASYNC_READ)				fc->async_read = 1;			if (!(arg->flags & FUSE_POSIX_LOCKS))				fc->no_lock = 1;			if (arg->flags & FUSE_ATOMIC_O_TRUNC)				fc->atomic_o_trunc = 1;		} else {			ra_pages = fc->max_read / PAGE_CACHE_SIZE;			fc->no_lock = 1;		}		fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);		fc->minor = arg->minor;		fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;		fc->conn_init = 1;	}	fuse_put_request(fc, req);	fc->blocked = 0;	wake_up_all(&fc->blocked_waitq);}static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req){	struct fuse_init_in *arg = &req->misc.init_in;	arg->major = FUSE_KERNEL_VERSION;	arg->minor = FUSE_KERNEL_MINOR_VERSION;	arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;	arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_ATOMIC_O_TRUNC;	req->in.h.opcode = FUSE_INIT;	req->in.numargs = 1;	req->in.args[0].size = sizeof(*arg);	req->in.args[0].value = arg;	req->out.numargs = 1;	/* Variable length arguement used for backward compatibility	   with interface version < 7.5.  Rest of init_out is zeroed	   by do_get_request(), so a short reply is not a problem */	req->out.argvar = 1;	req->out.args[0].size = sizeof(struct fuse_init_out);	req->out.args[0].value = &req->misc.init_out;	req->end = process_init_reply;	request_send_background(fc, req);}static u64 conn_id(void){	static u64 ctr = 1;	return ctr++;}static int fuse_fill_super(struct super_block *sb, void *data, int silent){	struct fuse_conn *fc;	struct inode *root;	struct fuse_mount_data d;	struct file *file;	struct dentry *root_dentry;	struct fuse_req *init_req;	int err;	int is_bdev = sb->s_bdev != NULL;	if (sb->s_flags & MS_MANDLOCK)		return -EINVAL;	if (!parse_fuse_opt((char *) data, &d, is_bdev))		return -EINVAL;	if (is_bdev) {#ifdef CONFIG_BLOCK		if (!sb_set_blocksize(sb, d.blksize))			return -EINVAL;#endif	} else {		sb->s_blocksize = PAGE_CACHE_SIZE;		sb->s_blocksize_bits = PAGE_CACHE_SHIFT;	}	sb->s_magic = FUSE_SUPER_MAGIC;	sb->s_op = &fuse_super_operations;	sb->s_maxbytes = MAX_LFS_FILESIZE;	file = fget(d.fd);	if (!file)		return -EINVAL;	if (file->f_op != &fuse_dev_operations)		return -EINVAL;	fc = new_conn();	if (!fc)		return -ENOMEM;	fc->flags = d.flags;	fc->user_id = d.user_id;	fc->group_id = d.group_id;	fc->max_read = d.max_read;	/* Used by get_root_inode() */	sb->s_fs_info = fc;	err = -ENOMEM;	root = get_root_inode(sb, d.rootmode);	if (!root)		goto err;	root_dentry = d_alloc_root(root);	if (!root_dentry) {		iput(root);		goto err;	}	init_req = fuse_request_alloc();	if (!init_req)		goto err_put_root;	if (is_bdev) {		fc->destroy_req = fuse_request_alloc();		if (!fc->destroy_req)			goto err_put_root;	}	mutex_lock(&fuse_mutex);	err = -EINVAL;	if (file->private_data)		goto err_unlock;	fc->id = conn_id();	err = fuse_ctl_add_conn(fc);	if (err)		goto err_unlock;	list_add_tail(&fc->entry, &fuse_conn_list);	sb->s_root = root_dentry;	fc->connected = 1;	file->private_data = fuse_conn_get(fc);	mutex_unlock(&fuse_mutex);	/*	 * atomic_dec_and_test() in fput() provides the necessary	 * memory barrier for file->private_data to be visible on all	 * CPUs after this	 */	fput(file);	fuse_send_init(fc, init_req);	return 0; err_unlock:	mutex_unlock(&fuse_mutex);	fuse_request_free(init_req); err_put_root:	dput(root_dentry); err:	fput(file);	fuse_conn_put(fc);	return err;}static int fuse_get_sb(struct file_system_type *fs_type,		       int flags, const char *dev_name,		       void *raw_data, struct vfsmount *mnt){	return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt);}static struct file_system_type fuse_fs_type = {	.owner		= THIS_MODULE,	.name		= "fuse",	.fs_flags	= FS_HAS_SUBTYPE,	.get_sb		= fuse_get_sb,	.kill_sb	= kill_anon_super,};#ifdef CONFIG_BLOCKstatic int fuse_get_sb_blk(struct file_system_type *fs_type,			   int flags, const char *dev_name,			   void *raw_data, struct vfsmount *mnt){	return get_sb_bdev(fs_type, flags, dev_name, raw_data, fuse_fill_super,			   mnt);}static struct file_system_type fuseblk_fs_type = {	.owner		= THIS_MODULE,	.name		= "fuseblk",	.get_sb		= fuse_get_sb_blk,	.kill_sb	= kill_block_super,	.fs_flags	= FS_REQUIRES_DEV | FS_HAS_SUBTYPE,};static inline int register_fuseblk(void){	return register_filesystem(&fuseblk_fs_type);}static inline void unregister_fuseblk(void){	unregister_filesystem(&fuseblk_fs_type);}#elsestatic inline int register_fuseblk(void){	return 0;}static inline void unregister_fuseblk(void){}#endifstatic decl_subsys(fuse, NULL, NULL);static decl_subsys(connections, NULL, NULL);static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo){	struct inode * inode = foo;	inode_init_once(inode);}static int __init fuse_fs_init(void){	int err;	err = register_filesystem(&fuse_fs_type);	if (err)		goto out;	err = register_fuseblk();	if (err)		goto out_unreg;	fuse_inode_cachep = kmem_cache_create("fuse_inode",					      sizeof(struct fuse_inode),					      0, SLAB_HWCACHE_ALIGN,					      fuse_inode_init_once);	err = -ENOMEM;	if (!fuse_inode_cachep)		goto out_unreg2;	return 0; out_unreg2:	unregister_fuseblk(); out_unreg:	unregister_filesystem(&fuse_fs_type); out:	return err;}static void fuse_fs_cleanup(void){	unregister_filesystem(&fuse_fs_type);	unregister_fuseblk();	kmem_cache_destroy(fuse_inode_cachep);}static int fuse_sysfs_init(void){	int err;	kobj_set_kset_s(&fuse_subsys, fs_subsys);	err = subsystem_register(&fuse_subsys);	if (err)		goto out_err;	kobj_set_kset_s(&connections_subsys, fuse_subsys);	err = subsystem_register(&connections_subsys);	if (err)		goto out_fuse_unregister;	return 0; out_fuse_unregister:	subsystem_unregister(&fuse_subsys); out_err:	return err;}static void fuse_sysfs_cleanup(void){	subsystem_unregister(&connections_subsys);	subsystem_unregister(&fuse_subsys);}static int __init fuse_init(void){	int res;	printk("fuse init (API version %i.%i)\n",	       FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);	INIT_LIST_HEAD(&fuse_conn_list);	res = fuse_fs_init();	if (res)		goto err;	res = fuse_dev_init();	if (res)		goto err_fs_cleanup;	res = fuse_sysfs_init();	if (res)		goto err_dev_cleanup;	res = fuse_ctl_init();	if (res)		goto err_sysfs_cleanup;	return 0; err_sysfs_cleanup:	fuse_sysfs_cleanup(); err_dev_cleanup:	fuse_dev_cleanup(); err_fs_cleanup:	fuse_fs_cleanup(); err:	return res;}static void __exit fuse_exit(void){	printk(KERN_DEBUG "fuse exit\n");	fuse_ctl_cleanup();	fuse_sysfs_cleanup();	fuse_fs_cleanup();	fuse_dev_cleanup();}module_init(fuse_init);module_exit(fuse_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -