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