This source file includes following definitions.
- nfs_read_inode
- nfs_put_inode
- nfs_put_super
- nfs_read_super
- nfs_statfs
- nfs_fhget
- nfs_notify_change
- init_nfs_fs
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/module.h>
17
18 #include <linux/sched.h>
19 #include <linux/nfs_fs.h>
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/string.h>
23 #include <linux/stat.h>
24 #include <linux/errno.h>
25 #include <linux/locks.h>
26
27 #include <asm/system.h>
28 #include <asm/segment.h>
29
30 extern int close_fp(struct file *filp);
31
32 static int nfs_notify_change(struct inode *, struct iattr *);
33 static void nfs_put_inode(struct inode *);
34 static void nfs_put_super(struct super_block *);
35 static void nfs_read_inode(struct inode *);
36 static void nfs_statfs(struct super_block *, struct statfs *, int bufsiz);
37
38 static struct super_operations nfs_sops = {
39 nfs_read_inode,
40 nfs_notify_change,
41 NULL,
42 nfs_put_inode,
43 nfs_put_super,
44 NULL,
45 nfs_statfs,
46 NULL
47 };
48
49
50
51
52
53
54
55
56 static void nfs_read_inode(struct inode * inode)
57 {
58 inode->i_mode = 0;
59 inode->i_op = NULL;
60 NFS_CACHEINV(inode);
61 }
62
63 static void nfs_put_inode(struct inode * inode)
64 {
65 if (inode->i_pipe)
66 clear_inode(inode);
67 }
68
69 void nfs_put_super(struct super_block *sb)
70 {
71 close_fp(sb->u.nfs_sb.s_server.file);
72 rpc_closesock(sb->u.nfs_sb.s_server.rsock);
73 lock_super(sb);
74 sb->s_dev = 0;
75 unlock_super(sb);
76 MOD_DEC_USE_COUNT;
77 }
78
79
80
81
82
83
84
85
86
87 struct super_block *nfs_read_super(struct super_block *sb, void *raw_data,
88 int silent)
89 {
90 struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
91 struct nfs_server *server;
92 unsigned int fd;
93 struct file *filp;
94
95 kdev_t dev = sb->s_dev;
96
97 MOD_INC_USE_COUNT;
98 if (!data) {
99 printk("nfs_read_super: missing data argument\n");
100 sb->s_dev = 0;
101 MOD_DEC_USE_COUNT;
102 return NULL;
103 }
104 fd = data->fd;
105 if (data->version != NFS_MOUNT_VERSION) {
106 printk("nfs warning: mount version %s than kernel\n",
107 data->version < NFS_MOUNT_VERSION ? "older" : "newer");
108 }
109 if (fd >= NR_OPEN || !(filp = current->files->fd[fd])) {
110 printk("nfs_read_super: invalid file descriptor\n");
111 sb->s_dev = 0;
112 MOD_DEC_USE_COUNT;
113 return NULL;
114 }
115 if (!S_ISSOCK(filp->f_inode->i_mode)) {
116 printk("nfs_read_super: not a socket\n");
117 sb->s_dev = 0;
118 MOD_DEC_USE_COUNT;
119 return NULL;
120 }
121 filp->f_count++;
122 lock_super(sb);
123
124 sb->s_blocksize = 1024;
125 sb->s_blocksize_bits = 10;
126 sb->s_magic = NFS_SUPER_MAGIC;
127 sb->s_dev = dev;
128 sb->s_op = &nfs_sops;
129 server = &sb->u.nfs_sb.s_server;
130 server->file = filp;
131 server->lock = 0;
132 server->wait = NULL;
133 server->flags = data->flags;
134 server->rsize = data->rsize;
135 if (server->rsize <= 0)
136 server->rsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
137 else if (server->rsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
138 server->rsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
139 server->wsize = data->wsize;
140 if (server->wsize <= 0)
141 server->wsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
142 else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
143 server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
144 server->timeo = data->timeo*HZ/10;
145 server->retrans = data->retrans;
146 server->acregmin = data->acregmin*HZ;
147 server->acregmax = data->acregmax*HZ;
148 server->acdirmin = data->acdirmin*HZ;
149 server->acdirmax = data->acdirmax*HZ;
150 strcpy(server->hostname, data->hostname);
151
152
153
154 if (data->addr.sin_addr.s_addr == INADDR_ANY) {
155 if (((struct sockaddr_in *)(&server->toaddr))->sin_addr.s_addr == INADDR_ANY) {
156 printk("NFS: Error passed unconnected socket and no address\n") ;
157 MOD_DEC_USE_COUNT;
158 return NULL ;
159 } else {
160
161 struct socket *sock;
162 int dummylen ;
163
164
165
166 sock = &((filp->f_inode)->u.socket_i);
167
168
169 sock->ops->getname(sock, &(server->toaddr), &dummylen, 1) ;
170 }
171 } else {
172
173 memcpy((char *)&(server->toaddr),(char *)(&data->addr),sizeof(server->toaddr));
174 }
175
176
177 if ((server->rsock = rpc_makesock(filp)) == NULL) {
178 printk("NFS: cannot create RPC socket.\n");
179 MOD_DEC_USE_COUNT;
180 return NULL;
181 }
182
183 sb->u.nfs_sb.s_root = data->root;
184 unlock_super(sb);
185 if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
186 sb->s_dev = 0;
187 printk("nfs_read_super: get root inode failed\n");
188 MOD_DEC_USE_COUNT;
189 return NULL;
190 }
191 return sb;
192 }
193
194 void nfs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
195 {
196 int error;
197 struct nfs_fsinfo res;
198 struct statfs tmp;
199
200 error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
201 &res);
202 if (error) {
203 printk("nfs_statfs: statfs error = %d\n", -error);
204 res.bsize = res.blocks = res.bfree = res.bavail = 0;
205 }
206 tmp.f_type = NFS_SUPER_MAGIC;
207 tmp.f_bsize = res.bsize;
208 tmp.f_blocks = res.blocks;
209 tmp.f_bfree = res.bfree;
210 tmp.f_bavail = res.bavail;
211 tmp.f_files = 0;
212 tmp.f_ffree = 0;
213 tmp.f_namelen = NAME_MAX;
214 memcpy_tofs(buf, &tmp, bufsiz);
215 }
216
217
218
219
220
221
222
223
224
225
226 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
227 struct nfs_fattr *fattr)
228 {
229 struct nfs_fattr newfattr;
230 int error;
231 struct inode *inode;
232
233 if (!sb) {
234 printk("nfs_fhget: super block is NULL\n");
235 return NULL;
236 }
237 if (!fattr) {
238 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
239 &newfattr);
240 if (error) {
241 printk("nfs_fhget: getattr error = %d\n", -error);
242 return NULL;
243 }
244 fattr = &newfattr;
245 }
246 if (!(inode = iget(sb, fattr->fileid))) {
247 printk("nfs_fhget: iget failed\n");
248 return NULL;
249 }
250 if (inode->i_dev == sb->s_dev) {
251 if (inode->i_ino != fattr->fileid) {
252 printk("nfs_fhget: unexpected inode from iget\n");
253 return inode;
254 }
255 *NFS_FH(inode) = *fhandle;
256 nfs_refresh_inode(inode, fattr);
257 }
258 return inode;
259 }
260
261 int nfs_notify_change(struct inode *inode, struct iattr *attr)
262 {
263 struct nfs_sattr sattr;
264 struct nfs_fattr fattr;
265 int error;
266
267 sattr.mode = (unsigned) -1;
268 if (attr->ia_valid & ATTR_MODE)
269 sattr.mode = attr->ia_mode;
270
271 sattr.uid = (unsigned) -1;
272 if (attr->ia_valid & ATTR_UID)
273 sattr.uid = attr->ia_uid;
274
275 sattr.gid = (unsigned) -1;
276 if (attr->ia_valid & ATTR_GID)
277 sattr.gid = attr->ia_gid;
278
279
280 sattr.size = (unsigned) -1;
281 if (attr->ia_valid & ATTR_SIZE)
282 sattr.size = S_ISREG(inode->i_mode) ? attr->ia_size : -1;
283
284 sattr.mtime.seconds = sattr.mtime.useconds = (unsigned) -1;
285 if (attr->ia_valid & ATTR_MTIME) {
286 sattr.mtime.seconds = attr->ia_mtime;
287 sattr.mtime.useconds = 0;
288 }
289
290 sattr.atime.seconds = sattr.atime.useconds = (unsigned) -1;
291 if (attr->ia_valid & ATTR_ATIME) {
292 sattr.atime.seconds = attr->ia_atime;
293 sattr.atime.useconds = 0;
294 }
295
296 error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
297 &sattr, &fattr);
298 if (!error)
299 nfs_refresh_inode(inode, &fattr);
300 inode->i_dirt = 0;
301 return error;
302 }
303
304
305
306 static struct file_system_type nfs_fs_type = {
307 nfs_read_super, "nfs", 0, NULL
308 };
309
310 int init_nfs_fs(void)
311 {
312 return register_filesystem(&nfs_fs_type);
313 }
314
315 #ifdef MODULE
316 int init_module(void)
317 {
318 int status;
319
320 if ((status = init_nfs_fs()) == 0)
321 register_symtab(0);
322 return status;
323 }
324
325 void cleanup_module(void)
326 {
327 unregister_filesystem(&nfs_fs_type);
328 nfs_kfree_cache();
329 }
330
331 #endif