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