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