]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - fs/ncpfs/inode.c
[PATCH] mark address_space_operations const
[mirror_ubuntu-zesty-kernel.git] / fs / ncpfs / inode.c
1 /*
2 * inode.c
3 *
4 * Copyright (C) 1995, 1996 by Volker Lendecke
5 * Modified for big endian by J.F. Chadima and David S. Miller
6 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
7 * Modified 1998 Wolfram Pienkoss for NLS
8 * Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
9 *
10 */
11
12 #include <linux/config.h>
13 #include <linux/module.h>
14
15 #include <asm/system.h>
16 #include <asm/uaccess.h>
17 #include <asm/byteorder.h>
18
19 #include <linux/time.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/file.h>
26 #include <linux/fcntl.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/init.h>
30 #include <linux/smp_lock.h>
31 #include <linux/vfs.h>
32
33 #include <linux/ncp_fs.h>
34
35 #include <net/sock.h>
36
37 #include "ncplib_kernel.h"
38 #include "getopt.h"
39
40 static void ncp_delete_inode(struct inode *);
41 static void ncp_put_super(struct super_block *);
42 static int ncp_statfs(struct dentry *, struct kstatfs *);
43
44 static kmem_cache_t * ncp_inode_cachep;
45
46 static struct inode *ncp_alloc_inode(struct super_block *sb)
47 {
48 struct ncp_inode_info *ei;
49 ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, SLAB_KERNEL);
50 if (!ei)
51 return NULL;
52 return &ei->vfs_inode;
53 }
54
55 static void ncp_destroy_inode(struct inode *inode)
56 {
57 kmem_cache_free(ncp_inode_cachep, NCP_FINFO(inode));
58 }
59
60 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
61 {
62 struct ncp_inode_info *ei = (struct ncp_inode_info *) foo;
63
64 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
65 SLAB_CTOR_CONSTRUCTOR) {
66 mutex_init(&ei->open_mutex);
67 inode_init_once(&ei->vfs_inode);
68 }
69 }
70
71 static int init_inodecache(void)
72 {
73 ncp_inode_cachep = kmem_cache_create("ncp_inode_cache",
74 sizeof(struct ncp_inode_info),
75 0, (SLAB_RECLAIM_ACCOUNT|
76 SLAB_MEM_SPREAD),
77 init_once, NULL);
78 if (ncp_inode_cachep == NULL)
79 return -ENOMEM;
80 return 0;
81 }
82
83 static void destroy_inodecache(void)
84 {
85 if (kmem_cache_destroy(ncp_inode_cachep))
86 printk(KERN_INFO "ncp_inode_cache: not all structures were freed\n");
87 }
88
89 static int ncp_remount(struct super_block *sb, int *flags, char* data)
90 {
91 *flags |= MS_NODIRATIME;
92 return 0;
93 }
94
95 static struct super_operations ncp_sops =
96 {
97 .alloc_inode = ncp_alloc_inode,
98 .destroy_inode = ncp_destroy_inode,
99 .drop_inode = generic_delete_inode,
100 .delete_inode = ncp_delete_inode,
101 .put_super = ncp_put_super,
102 .statfs = ncp_statfs,
103 .remount_fs = ncp_remount,
104 };
105
106 extern struct dentry_operations ncp_root_dentry_operations;
107 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
108 extern const struct address_space_operations ncp_symlink_aops;
109 extern int ncp_symlink(struct inode*, struct dentry*, const char*);
110 #endif
111
112 /*
113 * Fill in the ncpfs-specific information in the inode.
114 */
115 static void ncp_update_dirent(struct inode *inode, struct ncp_entry_info *nwinfo)
116 {
117 NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;
118 NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;
119 NCP_FINFO(inode)->volNumber = nwinfo->volume;
120 }
121
122 void ncp_update_inode(struct inode *inode, struct ncp_entry_info *nwinfo)
123 {
124 ncp_update_dirent(inode, nwinfo);
125 NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
126 NCP_FINFO(inode)->access = nwinfo->access;
127 memcpy(NCP_FINFO(inode)->file_handle, nwinfo->file_handle,
128 sizeof(nwinfo->file_handle));
129 DPRINTK("ncp_update_inode: updated %s, volnum=%d, dirent=%u\n",
130 nwinfo->i.entryName, NCP_FINFO(inode)->volNumber,
131 NCP_FINFO(inode)->dirEntNum);
132 }
133
134 static void ncp_update_dates(struct inode *inode, struct nw_info_struct *nwi)
135 {
136 /* NFS namespace mode overrides others if it's set. */
137 DPRINTK(KERN_DEBUG "ncp_update_dates_and_mode: (%s) nfs.mode=0%o\n",
138 nwi->entryName, nwi->nfs.mode);
139 if (nwi->nfs.mode) {
140 /* XXX Security? */
141 inode->i_mode = nwi->nfs.mode;
142 }
143
144 inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;
145
146 inode->i_mtime.tv_sec = ncp_date_dos2unix(nwi->modifyTime, nwi->modifyDate);
147 inode->i_ctime.tv_sec = ncp_date_dos2unix(nwi->creationTime, nwi->creationDate);
148 inode->i_atime.tv_sec = ncp_date_dos2unix(0, nwi->lastAccessDate);
149 inode->i_atime.tv_nsec = 0;
150 inode->i_mtime.tv_nsec = 0;
151 inode->i_ctime.tv_nsec = 0;
152 }
153
154 static void ncp_update_attrs(struct inode *inode, struct ncp_entry_info *nwinfo)
155 {
156 struct nw_info_struct *nwi = &nwinfo->i;
157 struct ncp_server *server = NCP_SERVER(inode);
158
159 if (nwi->attributes & aDIR) {
160 inode->i_mode = server->m.dir_mode;
161 /* for directories dataStreamSize seems to be some
162 Object ID ??? */
163 inode->i_size = NCP_BLOCK_SIZE;
164 } else {
165 inode->i_mode = server->m.file_mode;
166 inode->i_size = le32_to_cpu(nwi->dataStreamSize);
167 #ifdef CONFIG_NCPFS_EXTRAS
168 if ((server->m.flags & (NCP_MOUNT_EXTRAS|NCP_MOUNT_SYMLINKS))
169 && (nwi->attributes & aSHARED)) {
170 switch (nwi->attributes & (aHIDDEN|aSYSTEM)) {
171 case aHIDDEN:
172 if (server->m.flags & NCP_MOUNT_SYMLINKS) {
173 if (/* (inode->i_size >= NCP_MIN_SYMLINK_SIZE)
174 && */ (inode->i_size <= NCP_MAX_SYMLINK_SIZE)) {
175 inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFLNK;
176 NCP_FINFO(inode)->flags |= NCPI_KLUDGE_SYMLINK;
177 break;
178 }
179 }
180 /* FALLTHROUGH */
181 case 0:
182 if (server->m.flags & NCP_MOUNT_EXTRAS)
183 inode->i_mode |= S_IRUGO;
184 break;
185 case aSYSTEM:
186 if (server->m.flags & NCP_MOUNT_EXTRAS)
187 inode->i_mode |= (inode->i_mode >> 2) & S_IXUGO;
188 break;
189 /* case aSYSTEM|aHIDDEN: */
190 default:
191 /* reserved combination */
192 break;
193 }
194 }
195 #endif
196 }
197 if (nwi->attributes & aRONLY) inode->i_mode &= ~S_IWUGO;
198 }
199
200 void ncp_update_inode2(struct inode* inode, struct ncp_entry_info *nwinfo)
201 {
202 NCP_FINFO(inode)->flags = 0;
203 if (!atomic_read(&NCP_FINFO(inode)->opened)) {
204 NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;
205 ncp_update_attrs(inode, nwinfo);
206 }
207
208 ncp_update_dates(inode, &nwinfo->i);
209 ncp_update_dirent(inode, nwinfo);
210 }
211
212 /*
213 * Fill in the inode based on the ncp_entry_info structure.
214 */
215 static void ncp_set_attr(struct inode *inode, struct ncp_entry_info *nwinfo)
216 {
217 struct ncp_server *server = NCP_SERVER(inode);
218
219 NCP_FINFO(inode)->flags = 0;
220
221 ncp_update_attrs(inode, nwinfo);
222
223 DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
224
225 inode->i_nlink = 1;
226 inode->i_uid = server->m.uid;
227 inode->i_gid = server->m.gid;
228 inode->i_blksize = NCP_BLOCK_SIZE;
229
230 ncp_update_dates(inode, &nwinfo->i);
231 ncp_update_inode(inode, nwinfo);
232 }
233
234 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
235 static struct inode_operations ncp_symlink_inode_operations = {
236 .readlink = generic_readlink,
237 .follow_link = page_follow_link_light,
238 .put_link = page_put_link,
239 .setattr = ncp_notify_change,
240 };
241 #endif
242
243 /*
244 * Get a new inode.
245 */
246 struct inode *
247 ncp_iget(struct super_block *sb, struct ncp_entry_info *info)
248 {
249 struct inode *inode;
250
251 if (info == NULL) {
252 printk(KERN_ERR "ncp_iget: info is NULL\n");
253 return NULL;
254 }
255
256 inode = new_inode(sb);
257 if (inode) {
258 atomic_set(&NCP_FINFO(inode)->opened, info->opened);
259
260 inode->i_ino = info->ino;
261 ncp_set_attr(inode, info);
262 if (S_ISREG(inode->i_mode)) {
263 inode->i_op = &ncp_file_inode_operations;
264 inode->i_fop = &ncp_file_operations;
265 } else if (S_ISDIR(inode->i_mode)) {
266 inode->i_op = &ncp_dir_inode_operations;
267 inode->i_fop = &ncp_dir_operations;
268 #ifdef CONFIG_NCPFS_NFS_NS
269 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
270 init_special_inode(inode, inode->i_mode,
271 new_decode_dev(info->i.nfs.rdev));
272 #endif
273 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
274 } else if (S_ISLNK(inode->i_mode)) {
275 inode->i_op = &ncp_symlink_inode_operations;
276 inode->i_data.a_ops = &ncp_symlink_aops;
277 #endif
278 } else {
279 make_bad_inode(inode);
280 }
281 insert_inode_hash(inode);
282 } else
283 printk(KERN_ERR "ncp_iget: iget failed!\n");
284 return inode;
285 }
286
287 static void
288 ncp_delete_inode(struct inode *inode)
289 {
290 truncate_inode_pages(&inode->i_data, 0);
291
292 if (S_ISDIR(inode->i_mode)) {
293 DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino);
294 }
295
296 if (ncp_make_closed(inode) != 0) {
297 /* We can't do anything but complain. */
298 printk(KERN_ERR "ncp_delete_inode: could not close\n");
299 }
300 clear_inode(inode);
301 }
302
303 static void ncp_stop_tasks(struct ncp_server *server) {
304 struct sock* sk = server->ncp_sock->sk;
305
306 sk->sk_error_report = server->error_report;
307 sk->sk_data_ready = server->data_ready;
308 sk->sk_write_space = server->write_space;
309 del_timer_sync(&server->timeout_tm);
310 flush_scheduled_work();
311 }
312
313 static const struct ncp_option ncp_opts[] = {
314 { "uid", OPT_INT, 'u' },
315 { "gid", OPT_INT, 'g' },
316 { "owner", OPT_INT, 'o' },
317 { "mode", OPT_INT, 'm' },
318 { "dirmode", OPT_INT, 'd' },
319 { "timeout", OPT_INT, 't' },
320 { "retry", OPT_INT, 'r' },
321 { "flags", OPT_INT, 'f' },
322 { "wdogpid", OPT_INT, 'w' },
323 { "ncpfd", OPT_INT, 'n' },
324 { "infofd", OPT_INT, 'i' }, /* v5 */
325 { "version", OPT_INT, 'v' },
326 { NULL, 0, 0 } };
327
328 static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options) {
329 int optval;
330 char *optarg;
331 unsigned long optint;
332 int version = 0;
333
334 data->flags = 0;
335 data->int_flags = 0;
336 data->mounted_uid = 0;
337 data->wdog_pid = -1;
338 data->ncp_fd = ~0;
339 data->time_out = 10;
340 data->retry_count = 20;
341 data->uid = 0;
342 data->gid = 0;
343 data->file_mode = 0600;
344 data->dir_mode = 0700;
345 data->info_fd = -1;
346 data->mounted_vol[0] = 0;
347
348 while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
349 if (optval < 0)
350 return optval;
351 switch (optval) {
352 case 'u':
353 data->uid = optint;
354 break;
355 case 'g':
356 data->gid = optint;
357 break;
358 case 'o':
359 data->mounted_uid = optint;
360 break;
361 case 'm':
362 data->file_mode = optint;
363 break;
364 case 'd':
365 data->dir_mode = optint;
366 break;
367 case 't':
368 data->time_out = optint;
369 break;
370 case 'r':
371 data->retry_count = optint;
372 break;
373 case 'f':
374 data->flags = optint;
375 break;
376 case 'w':
377 data->wdog_pid = optint;
378 break;
379 case 'n':
380 data->ncp_fd = optint;
381 break;
382 case 'i':
383 data->info_fd = optint;
384 break;
385 case 'v':
386 if (optint < NCP_MOUNT_VERSION_V4) {
387 return -ECHRNG;
388 }
389 if (optint > NCP_MOUNT_VERSION_V5) {
390 return -ECHRNG;
391 }
392 version = optint;
393 break;
394
395 }
396 }
397 return 0;
398 }
399
400 static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
401 {
402 struct ncp_mount_data_kernel data;
403 struct ncp_server *server;
404 struct file *ncp_filp;
405 struct inode *root_inode;
406 struct inode *sock_inode;
407 struct socket *sock;
408 int error;
409 int default_bufsize;
410 #ifdef CONFIG_NCPFS_PACKET_SIGNING
411 int options;
412 #endif
413 struct ncp_entry_info finfo;
414
415 server = kmalloc(sizeof(struct ncp_server), GFP_KERNEL);
416 if (!server)
417 return -ENOMEM;
418 sb->s_fs_info = server;
419 memset(server, 0, sizeof(struct ncp_server));
420
421 error = -EFAULT;
422 if (raw_data == NULL)
423 goto out;
424 switch (*(int*)raw_data) {
425 case NCP_MOUNT_VERSION:
426 {
427 struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;
428
429 data.flags = md->flags;
430 data.int_flags = NCP_IMOUNT_LOGGEDIN_POSSIBLE;
431 data.mounted_uid = md->mounted_uid;
432 data.wdog_pid = md->wdog_pid;
433 data.ncp_fd = md->ncp_fd;
434 data.time_out = md->time_out;
435 data.retry_count = md->retry_count;
436 data.uid = md->uid;
437 data.gid = md->gid;
438 data.file_mode = md->file_mode;
439 data.dir_mode = md->dir_mode;
440 data.info_fd = -1;
441 memcpy(data.mounted_vol, md->mounted_vol,
442 NCP_VOLNAME_LEN+1);
443 }
444 break;
445 case NCP_MOUNT_VERSION_V4:
446 {
447 struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;
448
449 data.flags = md->flags;
450 data.int_flags = 0;
451 data.mounted_uid = md->mounted_uid;
452 data.wdog_pid = md->wdog_pid;
453 data.ncp_fd = md->ncp_fd;
454 data.time_out = md->time_out;
455 data.retry_count = md->retry_count;
456 data.uid = md->uid;
457 data.gid = md->gid;
458 data.file_mode = md->file_mode;
459 data.dir_mode = md->dir_mode;
460 data.info_fd = -1;
461 data.mounted_vol[0] = 0;
462 }
463 break;
464 default:
465 error = -ECHRNG;
466 if (memcmp(raw_data, "vers", 4) == 0) {
467 error = ncp_parse_options(&data, raw_data);
468 }
469 if (error)
470 goto out;
471 break;
472 }
473 error = -EBADF;
474 ncp_filp = fget(data.ncp_fd);
475 if (!ncp_filp)
476 goto out;
477 error = -ENOTSOCK;
478 sock_inode = ncp_filp->f_dentry->d_inode;
479 if (!S_ISSOCK(sock_inode->i_mode))
480 goto out_fput;
481 sock = SOCKET_I(sock_inode);
482 if (!sock)
483 goto out_fput;
484
485 if (sock->type == SOCK_STREAM)
486 default_bufsize = 0xF000;
487 else
488 default_bufsize = 1024;
489
490 sb->s_flags |= MS_NODIRATIME; /* probably even noatime */
491 sb->s_maxbytes = 0xFFFFFFFFU;
492 sb->s_blocksize = 1024; /* Eh... Is this correct? */
493 sb->s_blocksize_bits = 10;
494 sb->s_magic = NCP_SUPER_MAGIC;
495 sb->s_op = &ncp_sops;
496
497 server = NCP_SBP(sb);
498 memset(server, 0, sizeof(*server));
499
500 server->ncp_filp = ncp_filp;
501 server->ncp_sock = sock;
502
503 if (data.info_fd != -1) {
504 struct socket *info_sock;
505
506 error = -EBADF;
507 server->info_filp = fget(data.info_fd);
508 if (!server->info_filp)
509 goto out_fput;
510 error = -ENOTSOCK;
511 sock_inode = server->info_filp->f_dentry->d_inode;
512 if (!S_ISSOCK(sock_inode->i_mode))
513 goto out_fput2;
514 info_sock = SOCKET_I(sock_inode);
515 if (!info_sock)
516 goto out_fput2;
517 error = -EBADFD;
518 if (info_sock->type != SOCK_STREAM)
519 goto out_fput2;
520 server->info_sock = info_sock;
521 }
522
523 /* server->lock = 0; */
524 mutex_init(&server->mutex);
525 server->packet = NULL;
526 /* server->buffer_size = 0; */
527 /* server->conn_status = 0; */
528 /* server->root_dentry = NULL; */
529 /* server->root_setuped = 0; */
530 #ifdef CONFIG_NCPFS_PACKET_SIGNING
531 /* server->sign_wanted = 0; */
532 /* server->sign_active = 0; */
533 #endif
534 server->auth.auth_type = NCP_AUTH_NONE;
535 /* server->auth.object_name_len = 0; */
536 /* server->auth.object_name = NULL; */
537 /* server->auth.object_type = 0; */
538 /* server->priv.len = 0; */
539 /* server->priv.data = NULL; */
540
541 server->m = data;
542 /* Althought anything producing this is buggy, it happens
543 now because of PATH_MAX changes.. */
544 if (server->m.time_out < 1) {
545 server->m.time_out = 10;
546 printk(KERN_INFO "You need to recompile your ncpfs utils..\n");
547 }
548 server->m.time_out = server->m.time_out * HZ / 100;
549 server->m.file_mode = (server->m.file_mode & S_IRWXUGO) | S_IFREG;
550 server->m.dir_mode = (server->m.dir_mode & S_IRWXUGO) | S_IFDIR;
551
552 #ifdef CONFIG_NCPFS_NLS
553 /* load the default NLS charsets */
554 server->nls_vol = load_nls_default();
555 server->nls_io = load_nls_default();
556 #endif /* CONFIG_NCPFS_NLS */
557
558 server->dentry_ttl = 0; /* no caching */
559
560 INIT_LIST_HEAD(&server->tx.requests);
561 mutex_init(&server->rcv.creq_mutex);
562 server->tx.creq = NULL;
563 server->rcv.creq = NULL;
564 server->data_ready = sock->sk->sk_data_ready;
565 server->write_space = sock->sk->sk_write_space;
566 server->error_report = sock->sk->sk_error_report;
567 sock->sk->sk_user_data = server;
568
569 init_timer(&server->timeout_tm);
570 #undef NCP_PACKET_SIZE
571 #define NCP_PACKET_SIZE 131072
572 error = -ENOMEM;
573 server->packet_size = NCP_PACKET_SIZE;
574 server->packet = vmalloc(NCP_PACKET_SIZE);
575 if (server->packet == NULL)
576 goto out_nls;
577
578 sock->sk->sk_data_ready = ncp_tcp_data_ready;
579 sock->sk->sk_error_report = ncp_tcp_error_report;
580 if (sock->type == SOCK_STREAM) {
581 server->rcv.ptr = (unsigned char*)&server->rcv.buf;
582 server->rcv.len = 10;
583 server->rcv.state = 0;
584 INIT_WORK(&server->rcv.tq, ncp_tcp_rcv_proc, server);
585 INIT_WORK(&server->tx.tq, ncp_tcp_tx_proc, server);
586 sock->sk->sk_write_space = ncp_tcp_write_space;
587 } else {
588 INIT_WORK(&server->rcv.tq, ncpdgram_rcv_proc, server);
589 INIT_WORK(&server->timeout_tq, ncpdgram_timeout_proc, server);
590 server->timeout_tm.data = (unsigned long)server;
591 server->timeout_tm.function = ncpdgram_timeout_call;
592 }
593
594 ncp_lock_server(server);
595 error = ncp_connect(server);
596 ncp_unlock_server(server);
597 if (error < 0)
598 goto out_packet;
599 DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
600
601 error = -EMSGSIZE; /* -EREMOTESIDEINCOMPATIBLE */
602 #ifdef CONFIG_NCPFS_PACKET_SIGNING
603 if (ncp_negotiate_size_and_options(server, default_bufsize,
604 NCP_DEFAULT_OPTIONS, &(server->buffer_size), &options) == 0)
605 {
606 if (options != NCP_DEFAULT_OPTIONS)
607 {
608 if (ncp_negotiate_size_and_options(server,
609 default_bufsize,
610 options & 2,
611 &(server->buffer_size), &options) != 0)
612
613 {
614 goto out_disconnect;
615 }
616 }
617 if (options & 2)
618 server->sign_wanted = 1;
619 }
620 else
621 #endif /* CONFIG_NCPFS_PACKET_SIGNING */
622 if (ncp_negotiate_buffersize(server, default_bufsize,
623 &(server->buffer_size)) != 0)
624 goto out_disconnect;
625 DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
626
627 memset(&finfo, 0, sizeof(finfo));
628 finfo.i.attributes = aDIR;
629 finfo.i.dataStreamSize = 0; /* ignored */
630 finfo.i.dirEntNum = 0;
631 finfo.i.DosDirNum = 0;
632 #ifdef CONFIG_NCPFS_SMALLDOS
633 finfo.i.NSCreator = NW_NS_DOS;
634 #endif
635 finfo.volume = NCP_NUMBER_OF_VOLUMES;
636 /* set dates of mountpoint to Jan 1, 1986; 00:00 */
637 finfo.i.creationTime = finfo.i.modifyTime
638 = cpu_to_le16(0x0000);
639 finfo.i.creationDate = finfo.i.modifyDate
640 = finfo.i.lastAccessDate
641 = cpu_to_le16(0x0C21);
642 finfo.i.nameLen = 0;
643 finfo.i.entryName[0] = '\0';
644
645 finfo.opened = 0;
646 finfo.ino = 2; /* tradition */
647
648 server->name_space[finfo.volume] = NW_NS_DOS;
649
650 error = -ENOMEM;
651 root_inode = ncp_iget(sb, &finfo);
652 if (!root_inode)
653 goto out_disconnect;
654 DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
655 sb->s_root = d_alloc_root(root_inode);
656 if (!sb->s_root)
657 goto out_no_root;
658 sb->s_root->d_op = &ncp_root_dentry_operations;
659 return 0;
660
661 out_no_root:
662 iput(root_inode);
663 out_disconnect:
664 ncp_lock_server(server);
665 ncp_disconnect(server);
666 ncp_unlock_server(server);
667 out_packet:
668 ncp_stop_tasks(server);
669 vfree(server->packet);
670 out_nls:
671 #ifdef CONFIG_NCPFS_NLS
672 unload_nls(server->nls_io);
673 unload_nls(server->nls_vol);
674 #endif
675 out_fput2:
676 if (server->info_filp)
677 fput(server->info_filp);
678 out_fput:
679 /* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
680 *
681 * The previously used put_filp(ncp_filp); was bogous, since
682 * it doesn't proper unlocking.
683 */
684 fput(ncp_filp);
685 out:
686 sb->s_fs_info = NULL;
687 kfree(server);
688 return error;
689 }
690
691 static void ncp_put_super(struct super_block *sb)
692 {
693 struct ncp_server *server = NCP_SBP(sb);
694
695 ncp_lock_server(server);
696 ncp_disconnect(server);
697 ncp_unlock_server(server);
698
699 ncp_stop_tasks(server);
700
701 #ifdef CONFIG_NCPFS_NLS
702 /* unload the NLS charsets */
703 if (server->nls_vol)
704 {
705 unload_nls(server->nls_vol);
706 server->nls_vol = NULL;
707 }
708 if (server->nls_io)
709 {
710 unload_nls(server->nls_io);
711 server->nls_io = NULL;
712 }
713 #endif /* CONFIG_NCPFS_NLS */
714
715 if (server->info_filp)
716 fput(server->info_filp);
717 fput(server->ncp_filp);
718 kill_proc(server->m.wdog_pid, SIGTERM, 1);
719
720 kfree(server->priv.data);
721 kfree(server->auth.object_name);
722 vfree(server->packet);
723 sb->s_fs_info = NULL;
724 kfree(server);
725 }
726
727 static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
728 {
729 struct dentry* d;
730 struct inode* i;
731 struct ncp_inode_info* ni;
732 struct ncp_server* s;
733 struct ncp_volume_info vi;
734 struct super_block *sb = dentry->d_sb;
735 int err;
736 __u8 dh;
737
738 d = sb->s_root;
739 if (!d) {
740 goto dflt;
741 }
742 i = d->d_inode;
743 if (!i) {
744 goto dflt;
745 }
746 ni = NCP_FINFO(i);
747 if (!ni) {
748 goto dflt;
749 }
750 s = NCP_SBP(sb);
751 if (!s) {
752 goto dflt;
753 }
754 if (!s->m.mounted_vol[0]) {
755 goto dflt;
756 }
757
758 err = ncp_dirhandle_alloc(s, ni->volNumber, ni->DosDirNum, &dh);
759 if (err) {
760 goto dflt;
761 }
762 err = ncp_get_directory_info(s, dh, &vi);
763 ncp_dirhandle_free(s, dh);
764 if (err) {
765 goto dflt;
766 }
767 buf->f_type = NCP_SUPER_MAGIC;
768 buf->f_bsize = vi.sectors_per_block * 512;
769 buf->f_blocks = vi.total_blocks;
770 buf->f_bfree = vi.free_blocks;
771 buf->f_bavail = vi.free_blocks;
772 buf->f_files = vi.total_dir_entries;
773 buf->f_ffree = vi.available_dir_entries;
774 buf->f_namelen = 12;
775 return 0;
776
777 /* We cannot say how much disk space is left on a mounted
778 NetWare Server, because free space is distributed over
779 volumes, and the current user might have disk quotas. So
780 free space is not that simple to determine. Our decision
781 here is to err conservatively. */
782
783 dflt:;
784 buf->f_type = NCP_SUPER_MAGIC;
785 buf->f_bsize = NCP_BLOCK_SIZE;
786 buf->f_blocks = 0;
787 buf->f_bfree = 0;
788 buf->f_bavail = 0;
789 buf->f_namelen = 12;
790 return 0;
791 }
792
793 int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
794 {
795 struct inode *inode = dentry->d_inode;
796 int result = 0;
797 __le32 info_mask;
798 struct nw_modify_dos_info info;
799 struct ncp_server *server;
800
801 result = -EIO;
802
803 lock_kernel();
804
805 server = NCP_SERVER(inode);
806 if ((!server) || !ncp_conn_valid(server))
807 goto out;
808
809 /* ageing the dentry to force validation */
810 ncp_age_dentry(server, dentry);
811
812 result = inode_change_ok(inode, attr);
813 if (result < 0)
814 goto out;
815
816 result = -EPERM;
817 if (((attr->ia_valid & ATTR_UID) &&
818 (attr->ia_uid != server->m.uid)))
819 goto out;
820
821 if (((attr->ia_valid & ATTR_GID) &&
822 (attr->ia_gid != server->m.gid)))
823 goto out;
824
825 if (((attr->ia_valid & ATTR_MODE) &&
826 (attr->ia_mode &
827 ~(S_IFREG | S_IFDIR | S_IRWXUGO))))
828 goto out;
829
830 info_mask = 0;
831 memset(&info, 0, sizeof(info));
832
833 #if 1
834 if ((attr->ia_valid & ATTR_MODE) != 0)
835 {
836 umode_t newmode = attr->ia_mode;
837
838 info_mask |= DM_ATTRIBUTES;
839
840 if (S_ISDIR(inode->i_mode)) {
841 newmode &= server->m.dir_mode;
842 } else {
843 #ifdef CONFIG_NCPFS_EXTRAS
844 if (server->m.flags & NCP_MOUNT_EXTRAS) {
845 /* any non-default execute bit set */
846 if (newmode & ~server->m.file_mode & S_IXUGO)
847 info.attributes |= aSHARED | aSYSTEM;
848 /* read for group/world and not in default file_mode */
849 else if (newmode & ~server->m.file_mode & S_IRUGO)
850 info.attributes |= aSHARED;
851 } else
852 #endif
853 newmode &= server->m.file_mode;
854 }
855 if (newmode & S_IWUGO)
856 info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
857 else
858 info.attributes |= (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
859
860 #ifdef CONFIG_NCPFS_NFS_NS
861 if (ncp_is_nfs_extras(server, NCP_FINFO(inode)->volNumber)) {
862 result = ncp_modify_nfs_info(server,
863 NCP_FINFO(inode)->volNumber,
864 NCP_FINFO(inode)->dirEntNum,
865 attr->ia_mode, 0);
866 if (result != 0)
867 goto out;
868 info.attributes &= ~(aSHARED | aSYSTEM);
869 {
870 /* mark partial success */
871 struct iattr tmpattr;
872
873 tmpattr.ia_valid = ATTR_MODE;
874 tmpattr.ia_mode = attr->ia_mode;
875
876 result = inode_setattr(inode, &tmpattr);
877 if (result)
878 goto out;
879 }
880 }
881 #endif
882 }
883 #endif
884
885 /* Do SIZE before attributes, otherwise mtime together with size does not work...
886 */
887 if ((attr->ia_valid & ATTR_SIZE) != 0) {
888 int written;
889
890 DPRINTK("ncpfs: trying to change size to %ld\n",
891 attr->ia_size);
892
893 if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {
894 result = -EACCES;
895 goto out;
896 }
897 ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
898 attr->ia_size, 0, "", &written);
899
900 /* According to ndir, the changes only take effect after
901 closing the file */
902 ncp_inode_close(inode);
903 result = ncp_make_closed(inode);
904 if (result)
905 goto out;
906 {
907 struct iattr tmpattr;
908
909 tmpattr.ia_valid = ATTR_SIZE;
910 tmpattr.ia_size = attr->ia_size;
911
912 result = inode_setattr(inode, &tmpattr);
913 if (result)
914 goto out;
915 }
916 }
917 if ((attr->ia_valid & ATTR_CTIME) != 0) {
918 info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
919 ncp_date_unix2dos(attr->ia_ctime.tv_sec,
920 &info.creationTime, &info.creationDate);
921 }
922 if ((attr->ia_valid & ATTR_MTIME) != 0) {
923 info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
924 ncp_date_unix2dos(attr->ia_mtime.tv_sec,
925 &info.modifyTime, &info.modifyDate);
926 }
927 if ((attr->ia_valid & ATTR_ATIME) != 0) {
928 __le16 dummy;
929 info_mask |= (DM_LAST_ACCESS_DATE);
930 ncp_date_unix2dos(attr->ia_atime.tv_sec,
931 &dummy, &info.lastAccessDate);
932 }
933 if (info_mask != 0) {
934 result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
935 inode, info_mask, &info);
936 if (result != 0) {
937 result = -EACCES;
938
939 if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {
940 /* NetWare seems not to allow this. I
941 do not know why. So, just tell the
942 user everything went fine. This is
943 a terrible hack, but I do not know
944 how to do this correctly. */
945 result = 0;
946 } else
947 goto out;
948 }
949 #ifdef CONFIG_NCPFS_STRONG
950 if ((!result) && (info_mask & DM_ATTRIBUTES))
951 NCP_FINFO(inode)->nwattr = info.attributes;
952 #endif
953 }
954 if (!result)
955 result = inode_setattr(inode, attr);
956 out:
957 unlock_kernel();
958 return result;
959 }
960
961 static int ncp_get_sb(struct file_system_type *fs_type,
962 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
963 {
964 return get_sb_nodev(fs_type, flags, data, ncp_fill_super, mnt);
965 }
966
967 static struct file_system_type ncp_fs_type = {
968 .owner = THIS_MODULE,
969 .name = "ncpfs",
970 .get_sb = ncp_get_sb,
971 .kill_sb = kill_anon_super,
972 };
973
974 static int __init init_ncp_fs(void)
975 {
976 int err;
977 DPRINTK("ncpfs: init_module called\n");
978
979 err = init_inodecache();
980 if (err)
981 goto out1;
982 err = register_filesystem(&ncp_fs_type);
983 if (err)
984 goto out;
985 return 0;
986 out:
987 destroy_inodecache();
988 out1:
989 return err;
990 }
991
992 static void __exit exit_ncp_fs(void)
993 {
994 DPRINTK("ncpfs: cleanup_module called\n");
995 unregister_filesystem(&ncp_fs_type);
996 destroy_inodecache();
997 }
998
999 module_init(init_ncp_fs)
1000 module_exit(exit_ncp_fs)
1001 MODULE_LICENSE("GPL");