blob: 590a80db5b2aa5e365bebbae78d7b50b2c2204f6 [file] [log] [blame]
Miklos Szeredibc22e7b2001-10-23 19:26:04 +00001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu)
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
Miklos Szeredibc22e7b2001-10-23 19:26:04 +00009#include "fuse_i.h"
10
11#include <linux/module.h>
12#include <linux/kernel.h>
Miklos Szeredibc22e7b2001-10-23 19:26:04 +000013#include <linux/sched.h>
14#include <linux/file.h>
15
16#define FUSE_SUPER_MAGIC 0x65735546
17
18static void fuse_read_inode(struct inode *inode)
19{
20 printk(KERN_DEBUG "fuse_read_inode: %li\n", inode->i_ino);
21
22
23}
24
25static void fuse_put_super(struct super_block *sb)
26{
27 struct fuse_conn *fc = sb->u.generic_sbp;
28
Miklos Szeredi79b52f62001-10-24 14:37:13 +000029 printk(KERN_DEBUG "fuse_put_super[%i]\n", fc->id);
Miklos Szeredibc22e7b2001-10-23 19:26:04 +000030
Miklos Szeredi79b52f62001-10-24 14:37:13 +000031 spin_lock(&fuse_lock);
Miklos Szeredibc22e7b2001-10-23 19:26:04 +000032 fc->sb = NULL;
33 fuse_release_conn(fc);
Miklos Szeredi79b52f62001-10-24 14:37:13 +000034 spin_unlock(&fuse_lock);
35
Miklos Szeredibc22e7b2001-10-23 19:26:04 +000036}
37
38static struct super_operations fuse_super_operations = {
39 read_inode: fuse_read_inode,
40 put_super: fuse_put_super,
41};
42
43
44static struct fuse_conn *get_conn(struct fuse_mount_data *d)
45{
46 struct fuse_conn *fc = NULL;
47 struct file *file;
48 struct inode *ino;
49
50 printk(KERN_DEBUG "fuse_read_super\n");
51
52 if(d == NULL) {
53 printk("fuse_read_super: Bad mount data\n");
54 return NULL;
55 }
56
57 if(d->version != FUSE_MOUNT_VERSION) {
58 printk("fuse_read_super: Bad mount version: %i\n", d->version);
59 return NULL;
60 }
61
62 file = fget(d->fd);
63 ino = NULL;
64 if(file)
65 ino = file->f_dentry->d_inode;
66
67 if(!ino || ino->u.generic_ip != proc_fuse_dev) {
68 printk("fuse_read_super: Bad file: %i\n", d->fd);
69 goto out;
70 }
71
72 fc = file->private_data;
73
74 out:
75 fput(file);
76 return fc;
77
78}
79
Miklos Szeredi79b52f62001-10-24 14:37:13 +000080static struct inode *get_root_inode(struct super_block *sb)
81{
82 struct inode *root ;
83
84 root = iget(sb, 1);
85 if(root) {
86 root->i_mode = S_IFDIR;
87 root->i_uid = 0;
88 root->i_gid = 0;
89 root->i_nlink = 2;
90 root->i_size = 0;
91 root->i_blksize = 1024;
92 root->i_blocks = 0;
93 root->i_atime = CURRENT_TIME;
94 root->i_mtime = CURRENT_TIME;
95 root->i_ctime = CURRENT_TIME;
96 fuse_dir_init(root);
97 }
98
99 return root;
100}
101
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000102static struct super_block *fuse_read_super(struct super_block *sb,
103 void *data, int silent)
104{
105 struct fuse_conn *fc;
106 struct inode *root;
107
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000108 sb->s_blocksize = 1024;
109 sb->s_blocksize_bits = 10;
110 sb->s_magic = FUSE_SUPER_MAGIC;
111 sb->s_op = &fuse_super_operations;
112
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000113 root = get_root_inode(sb);
114 if(root == NULL) {
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000115 printk("fuse_read_super: failed to get root inode\n");
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000116 return NULL;
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000117 }
118
119 printk(KERN_DEBUG "root inode: %ld/%d\n", root->i_ino, root->i_dev);
120
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000121 spin_lock(&fuse_lock);
122 fc = get_conn(data);
123 if(fc == NULL)
124 goto err;
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000125
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000126 if(fc->sb != NULL) {
127 printk("fuse_read_super: connection %i already mounted\n",
128 fc->id);
129 goto err;
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000130 }
131
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000132 sb->u.generic_sbp = fc;
133 sb->s_root = d_alloc_root(root);
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000134 fc->sb = sb;
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000135 spin_unlock(&fuse_lock);
136
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000137 return sb;
138
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000139 err:
Miklos Szeredi79b52f62001-10-24 14:37:13 +0000140 spin_unlock(&fuse_lock);
141 iput(root);
Miklos Szeredibc22e7b2001-10-23 19:26:04 +0000142 return NULL;
143}
144
145
146static DECLARE_FSTYPE(fuse_fs_type, "fuse", fuse_read_super, 0);
147
148int fuse_fs_init()
149{
150 int res;
151
152 res = register_filesystem(&fuse_fs_type);
153 if(res)
154 printk("fuse: failed to register filesystem\n");
155
156 return res;
157}
158
159void fuse_fs_cleanup()
160{
161 unregister_filesystem(&fuse_fs_type);
162}
163
164/*
165 * Local Variables:
166 * indent-tabs-mode: t
167 * c-basic-offset: 8
168 * End:
169 */
170