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
12 #include <linux/config.h>
13 #include <linux/module.h>
15 #include <asm/system.h>
16 #include <asm/uaccess.h>
17 #include <asm/byteorder.h>
19 #include <linux/time.h>
20 #include <linux/kernel.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>
33 #include <linux/ncp_fs.h>
37 #include "ncplib_kernel.h"
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 *);
44 static kmem_cache_t * ncp_inode_cachep;
46 static struct inode *ncp_alloc_inode(struct super_block *sb)
48 struct ncp_inode_info *ei;
49 ei = (struct ncp_inode_info *)kmem_cache_alloc(ncp_inode_cachep, SLAB_KERNEL);
52 return &ei->vfs_inode;
55 static void ncp_destroy_inode(struct inode *inode)
57 kmem_cache_free(ncp_inode_cachep, NCP_FINFO(inode));
60 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
62 struct ncp_inode_info *ei = (struct ncp_inode_info *) foo;
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);
71 static int init_inodecache(void)
73 ncp_inode_cachep = kmem_cache_create("ncp_inode_cache",
74 sizeof(struct ncp_inode_info),
75 0, (SLAB_RECLAIM_ACCOUNT|
78 if (ncp_inode_cachep == NULL)
83 static void destroy_inodecache(void)
85 if (kmem_cache_destroy(ncp_inode_cachep))
86 printk(KERN_INFO "ncp_inode_cache: not all structures were freed\n");
89 static int ncp_remount(struct super_block *sb, int *flags, char* data)
91 *flags |= MS_NODIRATIME;
95 static struct super_operations ncp_sops =
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,
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*);
113 * Fill in the ncpfs-specific information in the inode.
115 static void ncp_update_dirent(struct inode *inode, struct ncp_entry_info *nwinfo)
117 NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;
118 NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;
119 NCP_FINFO(inode)->volNumber = nwinfo->volume;
122 void ncp_update_inode(struct inode *inode, struct ncp_entry_info *nwinfo)
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);
134 static void ncp_update_dates(struct inode *inode, struct nw_info_struct *nwi)
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);
141 inode->i_mode = nwi->nfs.mode;
144 inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;
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;
154 static void ncp_update_attrs(struct inode *inode, struct ncp_entry_info *nwinfo)
156 struct nw_info_struct *nwi = &nwinfo->i;
157 struct ncp_server *server = NCP_SERVER(inode);
159 if (nwi->attributes & aDIR) {
160 inode->i_mode = server->m.dir_mode;
161 /* for directories dataStreamSize seems to be some
163 inode->i_size = NCP_BLOCK_SIZE;
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)) {
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;
182 if (server->m.flags & NCP_MOUNT_EXTRAS)
183 inode->i_mode |= S_IRUGO;
186 if (server->m.flags & NCP_MOUNT_EXTRAS)
187 inode->i_mode |= (inode->i_mode >> 2) & S_IXUGO;
189 /* case aSYSTEM|aHIDDEN: */
191 /* reserved combination */
197 if (nwi->attributes & aRONLY) inode->i_mode &= ~S_IWUGO;
200 void ncp_update_inode2(struct inode* inode, struct ncp_entry_info *nwinfo)
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);
208 ncp_update_dates(inode, &nwinfo->i);
209 ncp_update_dirent(inode, nwinfo);
213 * Fill in the inode based on the ncp_entry_info structure.
215 static void ncp_set_attr(struct inode *inode, struct ncp_entry_info *nwinfo)
217 struct ncp_server *server = NCP_SERVER(inode);
219 NCP_FINFO(inode)->flags = 0;
221 ncp_update_attrs(inode, nwinfo);
223 DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
226 inode->i_uid = server->m.uid;
227 inode->i_gid = server->m.gid;
228 inode->i_blksize = NCP_BLOCK_SIZE;
230 ncp_update_dates(inode, &nwinfo->i);
231 ncp_update_inode(inode, nwinfo);
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,
247 ncp_iget(struct super_block *sb, struct ncp_entry_info *info)
252 printk(KERN_ERR "ncp_iget: info is NULL\n");
256 inode = new_inode(sb);
258 atomic_set(&NCP_FINFO(inode)->opened, info->opened);
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));
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;
279 make_bad_inode(inode);
281 insert_inode_hash(inode);
283 printk(KERN_ERR "ncp_iget: iget failed!\n");
288 ncp_delete_inode(struct inode *inode)
290 truncate_inode_pages(&inode->i_data, 0);
292 if (S_ISDIR(inode->i_mode)) {
293 DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino);
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");
303 static void ncp_stop_tasks(struct ncp_server *server) {
304 struct sock* sk = server->ncp_sock->sk;
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();
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' },
328 static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options) {
331 unsigned long optint;
336 data->mounted_uid = 0;
340 data->retry_count = 20;
343 data->file_mode = 0600;
344 data->dir_mode = 0700;
346 data->mounted_vol[0] = 0;
348 while ((optval = ncp_getopt("ncpfs", &options, ncp_opts, NULL, &optarg, &optint)) != 0) {
359 data->mounted_uid = optint;
362 data->file_mode = optint;
365 data->dir_mode = optint;
368 data->time_out = optint;
371 data->retry_count = optint;
374 data->flags = optint;
377 data->wdog_pid = optint;
380 data->ncp_fd = optint;
383 data->info_fd = optint;
386 if (optint < NCP_MOUNT_VERSION_V4) {
389 if (optint > NCP_MOUNT_VERSION_V5) {
400 static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
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;
410 #ifdef CONFIG_NCPFS_PACKET_SIGNING
413 struct ncp_entry_info finfo;
415 server = kmalloc(sizeof(struct ncp_server), GFP_KERNEL);
418 sb->s_fs_info = server;
419 memset(server, 0, sizeof(struct ncp_server));
422 if (raw_data == NULL)
424 switch (*(int*)raw_data) {
425 case NCP_MOUNT_VERSION:
427 struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;
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;
438 data.file_mode = md->file_mode;
439 data.dir_mode = md->dir_mode;
441 memcpy(data.mounted_vol, md->mounted_vol,
445 case NCP_MOUNT_VERSION_V4:
447 struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;
449 data.flags = md->flags;
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;
458 data.file_mode = md->file_mode;
459 data.dir_mode = md->dir_mode;
461 data.mounted_vol[0] = 0;
466 if (memcmp(raw_data, "vers", 4) == 0) {
467 error = ncp_parse_options(&data, raw_data);
474 ncp_filp = fget(data.ncp_fd);
478 sock_inode = ncp_filp->f_dentry->d_inode;
479 if (!S_ISSOCK(sock_inode->i_mode))
481 sock = SOCKET_I(sock_inode);
485 if (sock->type == SOCK_STREAM)
486 default_bufsize = 0xF000;
488 default_bufsize = 1024;
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;
497 server = NCP_SBP(sb);
498 memset(server, 0, sizeof(*server));
500 server->ncp_filp = ncp_filp;
501 server->ncp_sock = sock;
503 if (data.info_fd != -1) {
504 struct socket *info_sock;
507 server->info_filp = fget(data.info_fd);
508 if (!server->info_filp)
511 sock_inode = server->info_filp->f_dentry->d_inode;
512 if (!S_ISSOCK(sock_inode->i_mode))
514 info_sock = SOCKET_I(sock_inode);
518 if (info_sock->type != SOCK_STREAM)
520 server->info_sock = info_sock;
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; */
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; */
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");
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;
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 */
558 server->dentry_ttl = 0; /* no caching */
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;
569 init_timer(&server->timeout_tm);
570 #undef NCP_PACKET_SIZE
571 #define NCP_PACKET_SIZE 131072
573 server->packet_size = NCP_PACKET_SIZE;
574 server->packet = vmalloc(NCP_PACKET_SIZE);
575 if (server->packet == NULL)
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;
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;
594 ncp_lock_server(server);
595 error = ncp_connect(server);
596 ncp_unlock_server(server);
599 DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
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)
606 if (options != NCP_DEFAULT_OPTIONS)
608 if (ncp_negotiate_size_and_options(server,
611 &(server->buffer_size), &options) != 0)
618 server->sign_wanted = 1;
621 #endif /* CONFIG_NCPFS_PACKET_SIGNING */
622 if (ncp_negotiate_buffersize(server, default_bufsize,
623 &(server->buffer_size)) != 0)
625 DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
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;
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);
643 finfo.i.entryName[0] = '\0';
646 finfo.ino = 2; /* tradition */
648 server->name_space[finfo.volume] = NW_NS_DOS;
651 root_inode = ncp_iget(sb, &finfo);
654 DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);
655 sb->s_root = d_alloc_root(root_inode);
658 sb->s_root->d_op = &ncp_root_dentry_operations;
664 ncp_lock_server(server);
665 ncp_disconnect(server);
666 ncp_unlock_server(server);
668 ncp_stop_tasks(server);
669 vfree(server->packet);
671 #ifdef CONFIG_NCPFS_NLS
672 unload_nls(server->nls_io);
673 unload_nls(server->nls_vol);
676 if (server->info_filp)
677 fput(server->info_filp);
679 /* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
681 * The previously used put_filp(ncp_filp); was bogous, since
682 * it doesn't proper unlocking.
686 sb->s_fs_info = NULL;
691 static void ncp_put_super(struct super_block *sb)
693 struct ncp_server *server = NCP_SBP(sb);
695 ncp_lock_server(server);
696 ncp_disconnect(server);
697 ncp_unlock_server(server);
699 ncp_stop_tasks(server);
701 #ifdef CONFIG_NCPFS_NLS
702 /* unload the NLS charsets */
705 unload_nls(server->nls_vol);
706 server->nls_vol = NULL;
710 unload_nls(server->nls_io);
711 server->nls_io = NULL;
713 #endif /* CONFIG_NCPFS_NLS */
715 if (server->info_filp)
716 fput(server->info_filp);
717 fput(server->ncp_filp);
718 kill_proc(server->m.wdog_pid, SIGTERM, 1);
720 kfree(server->priv.data);
721 kfree(server->auth.object_name);
722 vfree(server->packet);
723 sb->s_fs_info = NULL;
727 static int ncp_statfs(struct dentry *dentry, struct kstatfs *buf)
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;
754 if (!s->m.mounted_vol[0]) {
758 err = ncp_dirhandle_alloc(s, ni->volNumber, ni->DosDirNum, &dh);
762 err = ncp_get_directory_info(s, dh, &vi);
763 ncp_dirhandle_free(s, dh);
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;
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. */
784 buf->f_type = NCP_SUPER_MAGIC;
785 buf->f_bsize = NCP_BLOCK_SIZE;
793 int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
795 struct inode *inode = dentry->d_inode;
798 struct nw_modify_dos_info info;
799 struct ncp_server *server;
805 server = NCP_SERVER(inode);
806 if ((!server) || !ncp_conn_valid(server))
809 /* ageing the dentry to force validation */
810 ncp_age_dentry(server, dentry);
812 result = inode_change_ok(inode, attr);
817 if (((attr->ia_valid & ATTR_UID) &&
818 (attr->ia_uid != server->m.uid)))
821 if (((attr->ia_valid & ATTR_GID) &&
822 (attr->ia_gid != server->m.gid)))
825 if (((attr->ia_valid & ATTR_MODE) &&
827 ~(S_IFREG | S_IFDIR | S_IRWXUGO))))
831 memset(&info, 0, sizeof(info));
834 if ((attr->ia_valid & ATTR_MODE) != 0)
836 umode_t newmode = attr->ia_mode;
838 info_mask |= DM_ATTRIBUTES;
840 if (S_ISDIR(inode->i_mode)) {
841 newmode &= server->m.dir_mode;
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;
853 newmode &= server->m.file_mode;
855 if (newmode & S_IWUGO)
856 info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
858 info.attributes |= (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);
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,
868 info.attributes &= ~(aSHARED | aSYSTEM);
870 /* mark partial success */
871 struct iattr tmpattr;
873 tmpattr.ia_valid = ATTR_MODE;
874 tmpattr.ia_mode = attr->ia_mode;
876 result = inode_setattr(inode, &tmpattr);
885 /* Do SIZE before attributes, otherwise mtime together with size does not work...
887 if ((attr->ia_valid & ATTR_SIZE) != 0) {
890 DPRINTK("ncpfs: trying to change size to %ld\n",
893 if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {
897 ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
898 attr->ia_size, 0, "", &written);
900 /* According to ndir, the changes only take effect after
902 ncp_inode_close(inode);
903 result = ncp_make_closed(inode);
907 struct iattr tmpattr;
909 tmpattr.ia_valid = ATTR_SIZE;
910 tmpattr.ia_size = attr->ia_size;
912 result = inode_setattr(inode, &tmpattr);
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);
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);
927 if ((attr->ia_valid & ATTR_ATIME) != 0) {
929 info_mask |= (DM_LAST_ACCESS_DATE);
930 ncp_date_unix2dos(attr->ia_atime.tv_sec,
931 &dummy, &info.lastAccessDate);
933 if (info_mask != 0) {
934 result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
935 inode, info_mask, &info);
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. */
949 #ifdef CONFIG_NCPFS_STRONG
950 if ((!result) && (info_mask & DM_ATTRIBUTES))
951 NCP_FINFO(inode)->nwattr = info.attributes;
955 result = inode_setattr(inode, attr);
961 static int ncp_get_sb(struct file_system_type *fs_type,
962 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
964 return get_sb_nodev(fs_type, flags, data, ncp_fill_super, mnt);
967 static struct file_system_type ncp_fs_type = {
968 .owner = THIS_MODULE,
970 .get_sb = ncp_get_sb,
971 .kill_sb = kill_anon_super,
974 static int __init init_ncp_fs(void)
977 DPRINTK("ncpfs: init_module called\n");
979 err = init_inodecache();
982 err = register_filesystem(&ncp_fs_type);
987 destroy_inodecache();
992 static void __exit exit_ncp_fs(void)
994 DPRINTK("ncpfs: cleanup_module called\n");
995 unregister_filesystem(&ncp_fs_type);
996 destroy_inodecache();
999 module_init(init_ncp_fs)
1000 module_exit(exit_ncp_fs)
1001 MODULE_LICENSE("GPL");