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 return NULL ;
147 } else {
148
149 struct socket *sock;
150 int dummylen ;
151
152
153
154 sock = &((filp->f_inode)->u.socket_i);
155
156
157 sock->ops->getname(sock, &(server->toaddr), &dummylen, 1) ;
158 }
159 } else {
160
161 memcpy((char *)&(server->toaddr),(char *)(&data->addr),sizeof(server->toaddr));
162 }
163
164
165 sb->u.nfs_sb.s_root = data->root;
166 unlock_super(sb);
167 if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
168 sb->s_dev = 0;
169 printk("nfs_read_super: get root inode failed\n");
170 MOD_DEC_USE_COUNT;
171 return NULL;
172 }
173 return sb;
174 }
175
176 void nfs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
177 {
178 int error;
179 struct nfs_fsinfo res;
180 struct statfs tmp;
181
182 error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
183 &res);
184 if (error) {
185 printk("nfs_statfs: statfs error = %d\n", -error);
186 res.bsize = res.blocks = res.bfree = res.bavail = 0;
187 }
188 tmp.f_type = NFS_SUPER_MAGIC;
189 tmp.f_bsize = res.bsize;
190 tmp.f_blocks = res.blocks;
191 tmp.f_bfree = res.bfree;
192 tmp.f_bavail = res.bavail;
193 tmp.f_files = 0;
194 tmp.f_ffree = 0;
195 tmp.f_namelen = NAME_MAX;
196 memcpy_tofs(buf, &tmp, bufsiz);
197 }
198
199
200
201
202
203
204
205
206
207
208 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
209 struct nfs_fattr *fattr)
210 {
211 struct nfs_fattr newfattr;
212 int error;
213 struct inode *inode;
214
215 if (!sb) {
216 printk("nfs_fhget: super block is NULL\n");
217 return NULL;
218 }
219 if (!fattr) {
220 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
221 &newfattr);
222 if (error) {
223 printk("nfs_fhget: getattr error = %d\n", -error);
224 return NULL;
225 }
226 fattr = &newfattr;
227 }
228 if (!(inode = iget(sb, fattr->fileid))) {
229 printk("nfs_fhget: iget failed\n");
230 return NULL;
231 }
232 if (inode->i_dev == sb->s_dev) {
233 if (inode->i_ino != fattr->fileid) {
234 printk("nfs_fhget: unexpected inode from iget\n");
235 return inode;
236 }
237 *NFS_FH(inode) = *fhandle;
238 nfs_refresh_inode(inode, fattr);
239 }
240 return inode;
241 }
242
243 int nfs_notify_change(struct inode *inode, struct iattr *attr)
244 {
245 struct nfs_sattr sattr;
246 struct nfs_fattr fattr;
247 int error;
248
249 if (attr->ia_valid & ATTR_MODE)
250 sattr.mode = attr->ia_mode;
251 else
252 sattr.mode = (unsigned) -1;
253
254 if (attr->ia_valid & ATTR_UID)
255 sattr.uid = attr->ia_uid;
256 else
257 sattr.uid = (unsigned) -1;
258
259 if (attr->ia_valid & ATTR_GID)
260 sattr.gid = attr->ia_gid;
261 else
262 sattr.gid = (unsigned) -1;
263
264 if (attr->ia_valid & ATTR_SIZE)
265 sattr.size = S_ISREG(inode->i_mode) ? attr->ia_size : -1;
266 else
267 sattr.size = (unsigned) -1;
268
269 if (attr->ia_valid & ATTR_MTIME) {
270 sattr.mtime.seconds = attr->ia_mtime;
271 sattr.mtime.useconds = 0;
272 } else
273 sattr.mtime.seconds = sattr.mtime.useconds = (unsigned) -1;
274
275 if (attr->ia_valid & ATTR_ATIME) {
276 sattr.atime.seconds = attr->ia_atime;
277 sattr.atime.useconds = 0;
278 } else
279 sattr.atime.seconds = sattr.atime.useconds = (unsigned) -1;
280
281 error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
282 &sattr, &fattr);
283 if (!error)
284 nfs_refresh_inode(inode, &fattr);
285 inode->i_dirt = 0;
286 return error;
287 }
288
289 #ifdef MODULE
290
291
292
293 char kernel_version[] = UTS_RELEASE;
294
295 static struct file_system_type nfs_fs_type = {
296 nfs_read_super, "nfs", 0, NULL
297 };
298
299 int init_module(void)
300 {
301 register_filesystem(&nfs_fs_type);
302 return 0;
303 }
304
305 void cleanup_module(void)
306 {
307 unregister_filesystem(&nfs_fs_type);
308 }
309
310 #endif