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/module.h>
14 #include <asm/system.h>
15 #include <asm/uaccess.h>
16 #include <asm/byteorder.h>
18 #include <linux/time.h>
19 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/stat.h>
23 #include <linux/errno.h>
24 #include <linux/file.h>
25 #include <linux/fcntl.h>
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/init.h>
29 #include <linux/smp_lock.h>
30 #include <linux/vfs.h>
32 #include <linux/ncp_fs.h>
36 #include "ncplib_kernel.h"
39 static void ncp_delete_inode(struct inode
*);
40 static void ncp_put_super(struct super_block
*);
41 static int ncp_statfs(struct dentry
*, struct kstatfs
*);
43 static kmem_cache_t
* ncp_inode_cachep
;
45 static struct inode
*ncp_alloc_inode(struct super_block
*sb
)
47 struct ncp_inode_info
*ei
;
48 ei
= (struct ncp_inode_info
*)kmem_cache_alloc(ncp_inode_cachep
, SLAB_KERNEL
);
51 return &ei
->vfs_inode
;
54 static void ncp_destroy_inode(struct inode
*inode
)
56 kmem_cache_free(ncp_inode_cachep
, NCP_FINFO(inode
));
59 static void init_once(void * foo
, kmem_cache_t
* cachep
, unsigned long flags
)
61 struct ncp_inode_info
*ei
= (struct ncp_inode_info
*) foo
;
63 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
64 SLAB_CTOR_CONSTRUCTOR
) {
65 mutex_init(&ei
->open_mutex
);
66 inode_init_once(&ei
->vfs_inode
);
70 static int init_inodecache(void)
72 ncp_inode_cachep
= kmem_cache_create("ncp_inode_cache",
73 sizeof(struct ncp_inode_info
),
74 0, (SLAB_RECLAIM_ACCOUNT
|
77 if (ncp_inode_cachep
== NULL
)
82 static void destroy_inodecache(void)
84 kmem_cache_destroy(ncp_inode_cachep
);
87 static int ncp_remount(struct super_block
*sb
, int *flags
, char* data
)
89 *flags
|= MS_NODIRATIME
;
93 static struct super_operations ncp_sops
=
95 .alloc_inode
= ncp_alloc_inode
,
96 .destroy_inode
= ncp_destroy_inode
,
97 .drop_inode
= generic_delete_inode
,
98 .delete_inode
= ncp_delete_inode
,
99 .put_super
= ncp_put_super
,
100 .statfs
= ncp_statfs
,
101 .remount_fs
= ncp_remount
,
104 extern struct dentry_operations ncp_root_dentry_operations
;
105 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
106 extern const struct address_space_operations ncp_symlink_aops
;
107 extern int ncp_symlink(struct inode
*, struct dentry
*, const char*);
111 * Fill in the ncpfs-specific information in the inode.
113 static void ncp_update_dirent(struct inode
*inode
, struct ncp_entry_info
*nwinfo
)
115 NCP_FINFO(inode
)->DosDirNum
= nwinfo
->i
.DosDirNum
;
116 NCP_FINFO(inode
)->dirEntNum
= nwinfo
->i
.dirEntNum
;
117 NCP_FINFO(inode
)->volNumber
= nwinfo
->volume
;
120 void ncp_update_inode(struct inode
*inode
, struct ncp_entry_info
*nwinfo
)
122 ncp_update_dirent(inode
, nwinfo
);
123 NCP_FINFO(inode
)->nwattr
= nwinfo
->i
.attributes
;
124 NCP_FINFO(inode
)->access
= nwinfo
->access
;
125 memcpy(NCP_FINFO(inode
)->file_handle
, nwinfo
->file_handle
,
126 sizeof(nwinfo
->file_handle
));
127 DPRINTK("ncp_update_inode: updated %s, volnum=%d, dirent=%u\n",
128 nwinfo
->i
.entryName
, NCP_FINFO(inode
)->volNumber
,
129 NCP_FINFO(inode
)->dirEntNum
);
132 static void ncp_update_dates(struct inode
*inode
, struct nw_info_struct
*nwi
)
134 /* NFS namespace mode overrides others if it's set. */
135 DPRINTK(KERN_DEBUG
"ncp_update_dates_and_mode: (%s) nfs.mode=0%o\n",
136 nwi
->entryName
, nwi
->nfs
.mode
);
139 inode
->i_mode
= nwi
->nfs
.mode
;
142 inode
->i_blocks
= (inode
->i_size
+ NCP_BLOCK_SIZE
- 1) >> NCP_BLOCK_SHIFT
;
144 inode
->i_mtime
.tv_sec
= ncp_date_dos2unix(nwi
->modifyTime
, nwi
->modifyDate
);
145 inode
->i_ctime
.tv_sec
= ncp_date_dos2unix(nwi
->creationTime
, nwi
->creationDate
);
146 inode
->i_atime
.tv_sec
= ncp_date_dos2unix(0, nwi
->lastAccessDate
);
147 inode
->i_atime
.tv_nsec
= 0;
148 inode
->i_mtime
.tv_nsec
= 0;
149 inode
->i_ctime
.tv_nsec
= 0;
152 static void ncp_update_attrs(struct inode
*inode
, struct ncp_entry_info
*nwinfo
)
154 struct nw_info_struct
*nwi
= &nwinfo
->i
;
155 struct ncp_server
*server
= NCP_SERVER(inode
);
157 if (nwi
->attributes
& aDIR
) {
158 inode
->i_mode
= server
->m
.dir_mode
;
159 /* for directories dataStreamSize seems to be some
161 inode
->i_size
= NCP_BLOCK_SIZE
;
163 inode
->i_mode
= server
->m
.file_mode
;
164 inode
->i_size
= le32_to_cpu(nwi
->dataStreamSize
);
165 #ifdef CONFIG_NCPFS_EXTRAS
166 if ((server
->m
.flags
& (NCP_MOUNT_EXTRAS
|NCP_MOUNT_SYMLINKS
))
167 && (nwi
->attributes
& aSHARED
)) {
168 switch (nwi
->attributes
& (aHIDDEN
|aSYSTEM
)) {
170 if (server
->m
.flags
& NCP_MOUNT_SYMLINKS
) {
171 if (/* (inode->i_size >= NCP_MIN_SYMLINK_SIZE)
172 && */ (inode
->i_size
<= NCP_MAX_SYMLINK_SIZE
)) {
173 inode
->i_mode
= (inode
->i_mode
& ~S_IFMT
) | S_IFLNK
;
174 NCP_FINFO(inode
)->flags
|= NCPI_KLUDGE_SYMLINK
;
180 if (server
->m
.flags
& NCP_MOUNT_EXTRAS
)
181 inode
->i_mode
|= S_IRUGO
;
184 if (server
->m
.flags
& NCP_MOUNT_EXTRAS
)
185 inode
->i_mode
|= (inode
->i_mode
>> 2) & S_IXUGO
;
187 /* case aSYSTEM|aHIDDEN: */
189 /* reserved combination */
195 if (nwi
->attributes
& aRONLY
) inode
->i_mode
&= ~S_IWUGO
;
198 void ncp_update_inode2(struct inode
* inode
, struct ncp_entry_info
*nwinfo
)
200 NCP_FINFO(inode
)->flags
= 0;
201 if (!atomic_read(&NCP_FINFO(inode
)->opened
)) {
202 NCP_FINFO(inode
)->nwattr
= nwinfo
->i
.attributes
;
203 ncp_update_attrs(inode
, nwinfo
);
206 ncp_update_dates(inode
, &nwinfo
->i
);
207 ncp_update_dirent(inode
, nwinfo
);
211 * Fill in the inode based on the ncp_entry_info structure.
213 static void ncp_set_attr(struct inode
*inode
, struct ncp_entry_info
*nwinfo
)
215 struct ncp_server
*server
= NCP_SERVER(inode
);
217 NCP_FINFO(inode
)->flags
= 0;
219 ncp_update_attrs(inode
, nwinfo
);
221 DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode
->i_mode
);
224 inode
->i_uid
= server
->m
.uid
;
225 inode
->i_gid
= server
->m
.gid
;
227 ncp_update_dates(inode
, &nwinfo
->i
);
228 ncp_update_inode(inode
, nwinfo
);
231 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
232 static struct inode_operations ncp_symlink_inode_operations
= {
233 .readlink
= generic_readlink
,
234 .follow_link
= page_follow_link_light
,
235 .put_link
= page_put_link
,
236 .setattr
= ncp_notify_change
,
244 ncp_iget(struct super_block
*sb
, struct ncp_entry_info
*info
)
249 printk(KERN_ERR
"ncp_iget: info is NULL\n");
253 inode
= new_inode(sb
);
255 atomic_set(&NCP_FINFO(inode
)->opened
, info
->opened
);
257 inode
->i_ino
= info
->ino
;
258 ncp_set_attr(inode
, info
);
259 if (S_ISREG(inode
->i_mode
)) {
260 inode
->i_op
= &ncp_file_inode_operations
;
261 inode
->i_fop
= &ncp_file_operations
;
262 } else if (S_ISDIR(inode
->i_mode
)) {
263 inode
->i_op
= &ncp_dir_inode_operations
;
264 inode
->i_fop
= &ncp_dir_operations
;
265 #ifdef CONFIG_NCPFS_NFS_NS
266 } else if (S_ISCHR(inode
->i_mode
) || S_ISBLK(inode
->i_mode
) || S_ISFIFO(inode
->i_mode
) || S_ISSOCK(inode
->i_mode
)) {
267 init_special_inode(inode
, inode
->i_mode
,
268 new_decode_dev(info
->i
.nfs
.rdev
));
270 #if defined(CONFIG_NCPFS_EXTRAS) || defined(CONFIG_NCPFS_NFS_NS)
271 } else if (S_ISLNK(inode
->i_mode
)) {
272 inode
->i_op
= &ncp_symlink_inode_operations
;
273 inode
->i_data
.a_ops
= &ncp_symlink_aops
;
276 make_bad_inode(inode
);
278 insert_inode_hash(inode
);
280 printk(KERN_ERR
"ncp_iget: iget failed!\n");
285 ncp_delete_inode(struct inode
*inode
)
287 truncate_inode_pages(&inode
->i_data
, 0);
289 if (S_ISDIR(inode
->i_mode
)) {
290 DDPRINTK("ncp_delete_inode: put directory %ld\n", inode
->i_ino
);
293 if (ncp_make_closed(inode
) != 0) {
294 /* We can't do anything but complain. */
295 printk(KERN_ERR
"ncp_delete_inode: could not close\n");
300 static void ncp_stop_tasks(struct ncp_server
*server
) {
301 struct sock
* sk
= server
->ncp_sock
->sk
;
303 sk
->sk_error_report
= server
->error_report
;
304 sk
->sk_data_ready
= server
->data_ready
;
305 sk
->sk_write_space
= server
->write_space
;
306 del_timer_sync(&server
->timeout_tm
);
307 flush_scheduled_work();
310 static const struct ncp_option ncp_opts
[] = {
311 { "uid", OPT_INT
, 'u' },
312 { "gid", OPT_INT
, 'g' },
313 { "owner", OPT_INT
, 'o' },
314 { "mode", OPT_INT
, 'm' },
315 { "dirmode", OPT_INT
, 'd' },
316 { "timeout", OPT_INT
, 't' },
317 { "retry", OPT_INT
, 'r' },
318 { "flags", OPT_INT
, 'f' },
319 { "wdogpid", OPT_INT
, 'w' },
320 { "ncpfd", OPT_INT
, 'n' },
321 { "infofd", OPT_INT
, 'i' }, /* v5 */
322 { "version", OPT_INT
, 'v' },
325 static int ncp_parse_options(struct ncp_mount_data_kernel
*data
, char *options
) {
328 unsigned long optint
;
333 data
->mounted_uid
= 0;
337 data
->retry_count
= 20;
340 data
->file_mode
= 0600;
341 data
->dir_mode
= 0700;
343 data
->mounted_vol
[0] = 0;
345 while ((optval
= ncp_getopt("ncpfs", &options
, ncp_opts
, NULL
, &optarg
, &optint
)) != 0) {
356 data
->mounted_uid
= optint
;
359 data
->file_mode
= optint
;
362 data
->dir_mode
= optint
;
365 data
->time_out
= optint
;
368 data
->retry_count
= optint
;
371 data
->flags
= optint
;
374 data
->wdog_pid
= optint
;
377 data
->ncp_fd
= optint
;
380 data
->info_fd
= optint
;
383 if (optint
< NCP_MOUNT_VERSION_V4
) {
386 if (optint
> NCP_MOUNT_VERSION_V5
) {
397 static int ncp_fill_super(struct super_block
*sb
, void *raw_data
, int silent
)
399 struct ncp_mount_data_kernel data
;
400 struct ncp_server
*server
;
401 struct file
*ncp_filp
;
402 struct inode
*root_inode
;
403 struct inode
*sock_inode
;
407 #ifdef CONFIG_NCPFS_PACKET_SIGNING
410 struct ncp_entry_info finfo
;
412 server
= kzalloc(sizeof(struct ncp_server
), GFP_KERNEL
);
415 sb
->s_fs_info
= server
;
418 if (raw_data
== NULL
)
420 switch (*(int*)raw_data
) {
421 case NCP_MOUNT_VERSION
:
423 struct ncp_mount_data
* md
= (struct ncp_mount_data
*)raw_data
;
425 data
.flags
= md
->flags
;
426 data
.int_flags
= NCP_IMOUNT_LOGGEDIN_POSSIBLE
;
427 data
.mounted_uid
= md
->mounted_uid
;
428 data
.wdog_pid
= md
->wdog_pid
;
429 data
.ncp_fd
= md
->ncp_fd
;
430 data
.time_out
= md
->time_out
;
431 data
.retry_count
= md
->retry_count
;
434 data
.file_mode
= md
->file_mode
;
435 data
.dir_mode
= md
->dir_mode
;
437 memcpy(data
.mounted_vol
, md
->mounted_vol
,
441 case NCP_MOUNT_VERSION_V4
:
443 struct ncp_mount_data_v4
* md
= (struct ncp_mount_data_v4
*)raw_data
;
445 data
.flags
= md
->flags
;
447 data
.mounted_uid
= md
->mounted_uid
;
448 data
.wdog_pid
= md
->wdog_pid
;
449 data
.ncp_fd
= md
->ncp_fd
;
450 data
.time_out
= md
->time_out
;
451 data
.retry_count
= md
->retry_count
;
454 data
.file_mode
= md
->file_mode
;
455 data
.dir_mode
= md
->dir_mode
;
457 data
.mounted_vol
[0] = 0;
462 if (memcmp(raw_data
, "vers", 4) == 0) {
463 error
= ncp_parse_options(&data
, raw_data
);
470 ncp_filp
= fget(data
.ncp_fd
);
474 sock_inode
= ncp_filp
->f_dentry
->d_inode
;
475 if (!S_ISSOCK(sock_inode
->i_mode
))
477 sock
= SOCKET_I(sock_inode
);
481 if (sock
->type
== SOCK_STREAM
)
482 default_bufsize
= 0xF000;
484 default_bufsize
= 1024;
486 sb
->s_flags
|= MS_NODIRATIME
; /* probably even noatime */
487 sb
->s_maxbytes
= 0xFFFFFFFFU
;
488 sb
->s_blocksize
= 1024; /* Eh... Is this correct? */
489 sb
->s_blocksize_bits
= 10;
490 sb
->s_magic
= NCP_SUPER_MAGIC
;
491 sb
->s_op
= &ncp_sops
;
493 server
= NCP_SBP(sb
);
494 memset(server
, 0, sizeof(*server
));
496 server
->ncp_filp
= ncp_filp
;
497 server
->ncp_sock
= sock
;
499 if (data
.info_fd
!= -1) {
500 struct socket
*info_sock
;
503 server
->info_filp
= fget(data
.info_fd
);
504 if (!server
->info_filp
)
507 sock_inode
= server
->info_filp
->f_dentry
->d_inode
;
508 if (!S_ISSOCK(sock_inode
->i_mode
))
510 info_sock
= SOCKET_I(sock_inode
);
514 if (info_sock
->type
!= SOCK_STREAM
)
516 server
->info_sock
= info_sock
;
519 /* server->lock = 0; */
520 mutex_init(&server
->mutex
);
521 server
->packet
= NULL
;
522 /* server->buffer_size = 0; */
523 /* server->conn_status = 0; */
524 /* server->root_dentry = NULL; */
525 /* server->root_setuped = 0; */
526 #ifdef CONFIG_NCPFS_PACKET_SIGNING
527 /* server->sign_wanted = 0; */
528 /* server->sign_active = 0; */
530 server
->auth
.auth_type
= NCP_AUTH_NONE
;
531 /* server->auth.object_name_len = 0; */
532 /* server->auth.object_name = NULL; */
533 /* server->auth.object_type = 0; */
534 /* server->priv.len = 0; */
535 /* server->priv.data = NULL; */
538 /* Althought anything producing this is buggy, it happens
539 now because of PATH_MAX changes.. */
540 if (server
->m
.time_out
< 1) {
541 server
->m
.time_out
= 10;
542 printk(KERN_INFO
"You need to recompile your ncpfs utils..\n");
544 server
->m
.time_out
= server
->m
.time_out
* HZ
/ 100;
545 server
->m
.file_mode
= (server
->m
.file_mode
& S_IRWXUGO
) | S_IFREG
;
546 server
->m
.dir_mode
= (server
->m
.dir_mode
& S_IRWXUGO
) | S_IFDIR
;
548 #ifdef CONFIG_NCPFS_NLS
549 /* load the default NLS charsets */
550 server
->nls_vol
= load_nls_default();
551 server
->nls_io
= load_nls_default();
552 #endif /* CONFIG_NCPFS_NLS */
554 server
->dentry_ttl
= 0; /* no caching */
556 INIT_LIST_HEAD(&server
->tx
.requests
);
557 mutex_init(&server
->rcv
.creq_mutex
);
558 server
->tx
.creq
= NULL
;
559 server
->rcv
.creq
= NULL
;
560 server
->data_ready
= sock
->sk
->sk_data_ready
;
561 server
->write_space
= sock
->sk
->sk_write_space
;
562 server
->error_report
= sock
->sk
->sk_error_report
;
563 sock
->sk
->sk_user_data
= server
;
565 init_timer(&server
->timeout_tm
);
566 #undef NCP_PACKET_SIZE
567 #define NCP_PACKET_SIZE 131072
569 server
->packet_size
= NCP_PACKET_SIZE
;
570 server
->packet
= vmalloc(NCP_PACKET_SIZE
);
571 if (server
->packet
== NULL
)
574 sock
->sk
->sk_data_ready
= ncp_tcp_data_ready
;
575 sock
->sk
->sk_error_report
= ncp_tcp_error_report
;
576 if (sock
->type
== SOCK_STREAM
) {
577 server
->rcv
.ptr
= (unsigned char*)&server
->rcv
.buf
;
578 server
->rcv
.len
= 10;
579 server
->rcv
.state
= 0;
580 INIT_WORK(&server
->rcv
.tq
, ncp_tcp_rcv_proc
, server
);
581 INIT_WORK(&server
->tx
.tq
, ncp_tcp_tx_proc
, server
);
582 sock
->sk
->sk_write_space
= ncp_tcp_write_space
;
584 INIT_WORK(&server
->rcv
.tq
, ncpdgram_rcv_proc
, server
);
585 INIT_WORK(&server
->timeout_tq
, ncpdgram_timeout_proc
, server
);
586 server
->timeout_tm
.data
= (unsigned long)server
;
587 server
->timeout_tm
.function
= ncpdgram_timeout_call
;
590 ncp_lock_server(server
);
591 error
= ncp_connect(server
);
592 ncp_unlock_server(server
);
595 DPRINTK("ncp_fill_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb
));
597 error
= -EMSGSIZE
; /* -EREMOTESIDEINCOMPATIBLE */
598 #ifdef CONFIG_NCPFS_PACKET_SIGNING
599 if (ncp_negotiate_size_and_options(server
, default_bufsize
,
600 NCP_DEFAULT_OPTIONS
, &(server
->buffer_size
), &options
) == 0)
602 if (options
!= NCP_DEFAULT_OPTIONS
)
604 if (ncp_negotiate_size_and_options(server
,
607 &(server
->buffer_size
), &options
) != 0)
614 server
->sign_wanted
= 1;
617 #endif /* CONFIG_NCPFS_PACKET_SIGNING */
618 if (ncp_negotiate_buffersize(server
, default_bufsize
,
619 &(server
->buffer_size
)) != 0)
621 DPRINTK("ncpfs: bufsize = %d\n", server
->buffer_size
);
623 memset(&finfo
, 0, sizeof(finfo
));
624 finfo
.i
.attributes
= aDIR
;
625 finfo
.i
.dataStreamSize
= 0; /* ignored */
626 finfo
.i
.dirEntNum
= 0;
627 finfo
.i
.DosDirNum
= 0;
628 #ifdef CONFIG_NCPFS_SMALLDOS
629 finfo
.i
.NSCreator
= NW_NS_DOS
;
631 finfo
.volume
= NCP_NUMBER_OF_VOLUMES
;
632 /* set dates of mountpoint to Jan 1, 1986; 00:00 */
633 finfo
.i
.creationTime
= finfo
.i
.modifyTime
634 = cpu_to_le16(0x0000);
635 finfo
.i
.creationDate
= finfo
.i
.modifyDate
636 = finfo
.i
.lastAccessDate
637 = cpu_to_le16(0x0C21);
639 finfo
.i
.entryName
[0] = '\0';
642 finfo
.ino
= 2; /* tradition */
644 server
->name_space
[finfo
.volume
] = NW_NS_DOS
;
647 root_inode
= ncp_iget(sb
, &finfo
);
650 DPRINTK("ncp_fill_super: root vol=%d\n", NCP_FINFO(root_inode
)->volNumber
);
651 sb
->s_root
= d_alloc_root(root_inode
);
654 sb
->s_root
->d_op
= &ncp_root_dentry_operations
;
660 ncp_lock_server(server
);
661 ncp_disconnect(server
);
662 ncp_unlock_server(server
);
664 ncp_stop_tasks(server
);
665 vfree(server
->packet
);
667 #ifdef CONFIG_NCPFS_NLS
668 unload_nls(server
->nls_io
);
669 unload_nls(server
->nls_vol
);
672 if (server
->info_filp
)
673 fput(server
->info_filp
);
675 /* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
677 * The previously used put_filp(ncp_filp); was bogous, since
678 * it doesn't proper unlocking.
682 sb
->s_fs_info
= NULL
;
687 static void ncp_put_super(struct super_block
*sb
)
689 struct ncp_server
*server
= NCP_SBP(sb
);
691 ncp_lock_server(server
);
692 ncp_disconnect(server
);
693 ncp_unlock_server(server
);
695 ncp_stop_tasks(server
);
697 #ifdef CONFIG_NCPFS_NLS
698 /* unload the NLS charsets */
701 unload_nls(server
->nls_vol
);
702 server
->nls_vol
= NULL
;
706 unload_nls(server
->nls_io
);
707 server
->nls_io
= NULL
;
709 #endif /* CONFIG_NCPFS_NLS */
711 if (server
->info_filp
)
712 fput(server
->info_filp
);
713 fput(server
->ncp_filp
);
714 kill_proc(server
->m
.wdog_pid
, SIGTERM
, 1);
716 kfree(server
->priv
.data
);
717 kfree(server
->auth
.object_name
);
718 vfree(server
->packet
);
719 sb
->s_fs_info
= NULL
;
723 static int ncp_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
727 struct ncp_inode_info
* ni
;
728 struct ncp_server
* s
;
729 struct ncp_volume_info vi
;
730 struct super_block
*sb
= dentry
->d_sb
;
750 if (!s
->m
.mounted_vol
[0]) {
754 err
= ncp_dirhandle_alloc(s
, ni
->volNumber
, ni
->DosDirNum
, &dh
);
758 err
= ncp_get_directory_info(s
, dh
, &vi
);
759 ncp_dirhandle_free(s
, dh
);
763 buf
->f_type
= NCP_SUPER_MAGIC
;
764 buf
->f_bsize
= vi
.sectors_per_block
* 512;
765 buf
->f_blocks
= vi
.total_blocks
;
766 buf
->f_bfree
= vi
.free_blocks
;
767 buf
->f_bavail
= vi
.free_blocks
;
768 buf
->f_files
= vi
.total_dir_entries
;
769 buf
->f_ffree
= vi
.available_dir_entries
;
773 /* We cannot say how much disk space is left on a mounted
774 NetWare Server, because free space is distributed over
775 volumes, and the current user might have disk quotas. So
776 free space is not that simple to determine. Our decision
777 here is to err conservatively. */
780 buf
->f_type
= NCP_SUPER_MAGIC
;
781 buf
->f_bsize
= NCP_BLOCK_SIZE
;
789 int ncp_notify_change(struct dentry
*dentry
, struct iattr
*attr
)
791 struct inode
*inode
= dentry
->d_inode
;
794 struct nw_modify_dos_info info
;
795 struct ncp_server
*server
;
801 server
= NCP_SERVER(inode
);
802 if ((!server
) || !ncp_conn_valid(server
))
805 /* ageing the dentry to force validation */
806 ncp_age_dentry(server
, dentry
);
808 result
= inode_change_ok(inode
, attr
);
813 if (((attr
->ia_valid
& ATTR_UID
) &&
814 (attr
->ia_uid
!= server
->m
.uid
)))
817 if (((attr
->ia_valid
& ATTR_GID
) &&
818 (attr
->ia_gid
!= server
->m
.gid
)))
821 if (((attr
->ia_valid
& ATTR_MODE
) &&
823 ~(S_IFREG
| S_IFDIR
| S_IRWXUGO
))))
827 memset(&info
, 0, sizeof(info
));
830 if ((attr
->ia_valid
& ATTR_MODE
) != 0)
832 umode_t newmode
= attr
->ia_mode
;
834 info_mask
|= DM_ATTRIBUTES
;
836 if (S_ISDIR(inode
->i_mode
)) {
837 newmode
&= server
->m
.dir_mode
;
839 #ifdef CONFIG_NCPFS_EXTRAS
840 if (server
->m
.flags
& NCP_MOUNT_EXTRAS
) {
841 /* any non-default execute bit set */
842 if (newmode
& ~server
->m
.file_mode
& S_IXUGO
)
843 info
.attributes
|= aSHARED
| aSYSTEM
;
844 /* read for group/world and not in default file_mode */
845 else if (newmode
& ~server
->m
.file_mode
& S_IRUGO
)
846 info
.attributes
|= aSHARED
;
849 newmode
&= server
->m
.file_mode
;
851 if (newmode
& S_IWUGO
)
852 info
.attributes
&= ~(aRONLY
|aRENAMEINHIBIT
|aDELETEINHIBIT
);
854 info
.attributes
|= (aRONLY
|aRENAMEINHIBIT
|aDELETEINHIBIT
);
856 #ifdef CONFIG_NCPFS_NFS_NS
857 if (ncp_is_nfs_extras(server
, NCP_FINFO(inode
)->volNumber
)) {
858 result
= ncp_modify_nfs_info(server
,
859 NCP_FINFO(inode
)->volNumber
,
860 NCP_FINFO(inode
)->dirEntNum
,
864 info
.attributes
&= ~(aSHARED
| aSYSTEM
);
866 /* mark partial success */
867 struct iattr tmpattr
;
869 tmpattr
.ia_valid
= ATTR_MODE
;
870 tmpattr
.ia_mode
= attr
->ia_mode
;
872 result
= inode_setattr(inode
, &tmpattr
);
881 /* Do SIZE before attributes, otherwise mtime together with size does not work...
883 if ((attr
->ia_valid
& ATTR_SIZE
) != 0) {
886 DPRINTK("ncpfs: trying to change size to %ld\n",
889 if ((result
= ncp_make_open(inode
, O_WRONLY
)) < 0) {
893 ncp_write_kernel(NCP_SERVER(inode
), NCP_FINFO(inode
)->file_handle
,
894 attr
->ia_size
, 0, "", &written
);
896 /* According to ndir, the changes only take effect after
898 ncp_inode_close(inode
);
899 result
= ncp_make_closed(inode
);
903 struct iattr tmpattr
;
905 tmpattr
.ia_valid
= ATTR_SIZE
;
906 tmpattr
.ia_size
= attr
->ia_size
;
908 result
= inode_setattr(inode
, &tmpattr
);
913 if ((attr
->ia_valid
& ATTR_CTIME
) != 0) {
914 info_mask
|= (DM_CREATE_TIME
| DM_CREATE_DATE
);
915 ncp_date_unix2dos(attr
->ia_ctime
.tv_sec
,
916 &info
.creationTime
, &info
.creationDate
);
918 if ((attr
->ia_valid
& ATTR_MTIME
) != 0) {
919 info_mask
|= (DM_MODIFY_TIME
| DM_MODIFY_DATE
);
920 ncp_date_unix2dos(attr
->ia_mtime
.tv_sec
,
921 &info
.modifyTime
, &info
.modifyDate
);
923 if ((attr
->ia_valid
& ATTR_ATIME
) != 0) {
925 info_mask
|= (DM_LAST_ACCESS_DATE
);
926 ncp_date_unix2dos(attr
->ia_atime
.tv_sec
,
927 &dummy
, &info
.lastAccessDate
);
929 if (info_mask
!= 0) {
930 result
= ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode
),
931 inode
, info_mask
, &info
);
935 if (info_mask
== (DM_CREATE_TIME
| DM_CREATE_DATE
)) {
936 /* NetWare seems not to allow this. I
937 do not know why. So, just tell the
938 user everything went fine. This is
939 a terrible hack, but I do not know
940 how to do this correctly. */
945 #ifdef CONFIG_NCPFS_STRONG
946 if ((!result
) && (info_mask
& DM_ATTRIBUTES
))
947 NCP_FINFO(inode
)->nwattr
= info
.attributes
;
951 result
= inode_setattr(inode
, attr
);
957 static int ncp_get_sb(struct file_system_type
*fs_type
,
958 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
960 return get_sb_nodev(fs_type
, flags
, data
, ncp_fill_super
, mnt
);
963 static struct file_system_type ncp_fs_type
= {
964 .owner
= THIS_MODULE
,
966 .get_sb
= ncp_get_sb
,
967 .kill_sb
= kill_anon_super
,
970 static int __init
init_ncp_fs(void)
973 DPRINTK("ncpfs: init_module called\n");
975 err
= init_inodecache();
978 err
= register_filesystem(&ncp_fs_type
);
983 destroy_inodecache();
988 static void __exit
exit_ncp_fs(void)
990 DPRINTK("ncpfs: cleanup_module called\n");
991 unregister_filesystem(&ncp_fs_type
);
992 destroy_inodecache();
995 module_init(init_ncp_fs
)
996 module_exit(exit_ncp_fs
)
997 MODULE_LICENSE("GPL");