sl82c105: DMA support fixes
[linux-2.6/mini2440.git] / fs / ncpfs / ioctl.c
blob8843a83d4ef03dc4242dd11646c78480736375cb
1 /*
2 * ioctl.c
4 * Copyright (C) 1995, 1996 by Volker Lendecke
5 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
6 * Modified 1998, 1999 Wolfram Pienkoss for NLS
8 */
10 #include <linux/capability.h>
11 #include <linux/compat.h>
12 #include <linux/errno.h>
13 #include <linux/fs.h>
14 #include <linux/ioctl.h>
15 #include <linux/time.h>
16 #include <linux/mm.h>
17 #include <linux/highuid.h>
18 #include <linux/smp_lock.h>
19 #include <linux/vmalloc.h>
21 #include <linux/ncp_fs.h>
23 #include <asm/uaccess.h>
25 #include "ncplib_kernel.h"
27 /* maximum limit for ncp_objectname_ioctl */
28 #define NCP_OBJECT_NAME_MAX_LEN 4096
29 /* maximum limit for ncp_privatedata_ioctl */
30 #define NCP_PRIVATE_DATA_MAX_LEN 8192
31 /* maximum negotiable packet size */
32 #define NCP_PACKET_SIZE_INTERNAL 65536
34 static int
35 ncp_get_fs_info(struct ncp_server * server, struct file *file,
36 struct ncp_fs_info __user *arg)
38 struct inode *inode = file->f_path.dentry->d_inode;
39 struct ncp_fs_info info;
41 if ((file_permission(file, MAY_WRITE) != 0)
42 && (current->uid != server->m.mounted_uid)) {
43 return -EACCES;
45 if (copy_from_user(&info, arg, sizeof(info)))
46 return -EFAULT;
48 if (info.version != NCP_GET_FS_INFO_VERSION) {
49 DPRINTK("info.version invalid: %d\n", info.version);
50 return -EINVAL;
52 /* TODO: info.addr = server->m.serv_addr; */
53 SET_UID(info.mounted_uid, server->m.mounted_uid);
54 info.connection = server->connection;
55 info.buffer_size = server->buffer_size;
56 info.volume_number = NCP_FINFO(inode)->volNumber;
57 info.directory_id = NCP_FINFO(inode)->DosDirNum;
59 if (copy_to_user(arg, &info, sizeof(info)))
60 return -EFAULT;
61 return 0;
64 static int
65 ncp_get_fs_info_v2(struct ncp_server * server, struct file *file,
66 struct ncp_fs_info_v2 __user * arg)
68 struct inode *inode = file->f_path.dentry->d_inode;
69 struct ncp_fs_info_v2 info2;
71 if ((file_permission(file, MAY_WRITE) != 0)
72 && (current->uid != server->m.mounted_uid)) {
73 return -EACCES;
75 if (copy_from_user(&info2, arg, sizeof(info2)))
76 return -EFAULT;
78 if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
79 DPRINTK("info.version invalid: %d\n", info2.version);
80 return -EINVAL;
82 info2.mounted_uid = server->m.mounted_uid;
83 info2.connection = server->connection;
84 info2.buffer_size = server->buffer_size;
85 info2.volume_number = NCP_FINFO(inode)->volNumber;
86 info2.directory_id = NCP_FINFO(inode)->DosDirNum;
87 info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
89 if (copy_to_user(arg, &info2, sizeof(info2)))
90 return -EFAULT;
91 return 0;
94 #ifdef CONFIG_COMPAT
95 struct compat_ncp_objectname_ioctl
97 s32 auth_type;
98 u32 object_name_len;
99 compat_caddr_t object_name; /* an userspace data, in most cases user name */
102 struct compat_ncp_fs_info_v2 {
103 s32 version;
104 u32 mounted_uid;
105 u32 connection;
106 u32 buffer_size;
108 u32 volume_number;
109 u32 directory_id;
111 u32 dummy1;
112 u32 dummy2;
113 u32 dummy3;
116 struct compat_ncp_ioctl_request {
117 u32 function;
118 u32 size;
119 compat_caddr_t data;
122 struct compat_ncp_privatedata_ioctl
124 u32 len;
125 compat_caddr_t data; /* ~1000 for NDS */
128 #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2)
129 #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request)
130 #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl)
131 #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl)
132 #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl)
133 #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl)
135 static int
136 ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file,
137 struct compat_ncp_fs_info_v2 __user * arg)
139 struct inode *inode = file->f_path.dentry->d_inode;
140 struct compat_ncp_fs_info_v2 info2;
142 if ((file_permission(file, MAY_WRITE) != 0)
143 && (current->uid != server->m.mounted_uid)) {
144 return -EACCES;
146 if (copy_from_user(&info2, arg, sizeof(info2)))
147 return -EFAULT;
149 if (info2.version != NCP_GET_FS_INFO_VERSION_V2) {
150 DPRINTK("info.version invalid: %d\n", info2.version);
151 return -EINVAL;
153 info2.mounted_uid = server->m.mounted_uid;
154 info2.connection = server->connection;
155 info2.buffer_size = server->buffer_size;
156 info2.volume_number = NCP_FINFO(inode)->volNumber;
157 info2.directory_id = NCP_FINFO(inode)->DosDirNum;
158 info2.dummy1 = info2.dummy2 = info2.dummy3 = 0;
160 if (copy_to_user(arg, &info2, sizeof(info2)))
161 return -EFAULT;
162 return 0;
164 #endif
166 #define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16)
167 #define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32)
168 #define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64)
170 #ifdef CONFIG_NCPFS_NLS
171 /* Here we are select the iocharset and the codepage for NLS.
172 * Thanks Petr Vandrovec for idea and many hints.
174 static int
175 ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
177 struct ncp_nls_ioctl user;
178 struct nls_table *codepage;
179 struct nls_table *iocharset;
180 struct nls_table *oldset_io;
181 struct nls_table *oldset_cp;
183 if (!capable(CAP_SYS_ADMIN))
184 return -EACCES;
185 if (server->root_setuped)
186 return -EBUSY;
188 if (copy_from_user(&user, arg, sizeof(user)))
189 return -EFAULT;
191 codepage = NULL;
192 user.codepage[NCP_IOCSNAME_LEN] = 0;
193 if (!user.codepage[0] || !strcmp(user.codepage, "default"))
194 codepage = load_nls_default();
195 else {
196 codepage = load_nls(user.codepage);
197 if (!codepage) {
198 return -EBADRQC;
202 iocharset = NULL;
203 user.iocharset[NCP_IOCSNAME_LEN] = 0;
204 if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) {
205 iocharset = load_nls_default();
206 NCP_CLR_FLAG(server, NCP_FLAG_UTF8);
207 } else if (!strcmp(user.iocharset, "utf8")) {
208 iocharset = load_nls_default();
209 NCP_SET_FLAG(server, NCP_FLAG_UTF8);
210 } else {
211 iocharset = load_nls(user.iocharset);
212 if (!iocharset) {
213 unload_nls(codepage);
214 return -EBADRQC;
216 NCP_CLR_FLAG(server, NCP_FLAG_UTF8);
219 oldset_cp = server->nls_vol;
220 server->nls_vol = codepage;
221 oldset_io = server->nls_io;
222 server->nls_io = iocharset;
224 if (oldset_cp)
225 unload_nls(oldset_cp);
226 if (oldset_io)
227 unload_nls(oldset_io);
229 return 0;
232 static int
233 ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg)
235 struct ncp_nls_ioctl user;
236 int len;
238 memset(&user, 0, sizeof(user));
239 if (server->nls_vol && server->nls_vol->charset) {
240 len = strlen(server->nls_vol->charset);
241 if (len > NCP_IOCSNAME_LEN)
242 len = NCP_IOCSNAME_LEN;
243 strncpy(user.codepage, server->nls_vol->charset, len);
244 user.codepage[len] = 0;
247 if (NCP_IS_FLAG(server, NCP_FLAG_UTF8))
248 strcpy(user.iocharset, "utf8");
249 else if (server->nls_io && server->nls_io->charset) {
250 len = strlen(server->nls_io->charset);
251 if (len > NCP_IOCSNAME_LEN)
252 len = NCP_IOCSNAME_LEN;
253 strncpy(user.iocharset, server->nls_io->charset, len);
254 user.iocharset[len] = 0;
257 if (copy_to_user(arg, &user, sizeof(user)))
258 return -EFAULT;
259 return 0;
261 #endif /* CONFIG_NCPFS_NLS */
263 int ncp_ioctl(struct inode *inode, struct file *filp,
264 unsigned int cmd, unsigned long arg)
266 struct ncp_server *server = NCP_SERVER(inode);
267 int result;
268 struct ncp_ioctl_request request;
269 char* bouncebuffer;
270 void __user *argp = (void __user *)arg;
272 switch (cmd) {
273 #ifdef CONFIG_COMPAT
274 case NCP_IOC_NCPREQUEST_32:
275 #endif
276 case NCP_IOC_NCPREQUEST:
277 if ((file_permission(filp, MAY_WRITE) != 0)
278 && (current->uid != server->m.mounted_uid)) {
279 return -EACCES;
281 #ifdef CONFIG_COMPAT
282 if (cmd == NCP_IOC_NCPREQUEST_32) {
283 struct compat_ncp_ioctl_request request32;
284 if (copy_from_user(&request32, argp, sizeof(request32)))
285 return -EFAULT;
286 request.function = request32.function;
287 request.size = request32.size;
288 request.data = compat_ptr(request32.data);
289 } else
290 #endif
291 if (copy_from_user(&request, argp, sizeof(request)))
292 return -EFAULT;
294 if ((request.function > 255)
295 || (request.size >
296 NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) {
297 return -EINVAL;
299 bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL);
300 if (!bouncebuffer)
301 return -ENOMEM;
302 if (copy_from_user(bouncebuffer, request.data, request.size)) {
303 vfree(bouncebuffer);
304 return -EFAULT;
306 ncp_lock_server(server);
308 /* FIXME: We hack around in the server's structures
309 here to be able to use ncp_request */
311 server->has_subfunction = 0;
312 server->current_size = request.size;
313 memcpy(server->packet, bouncebuffer, request.size);
315 result = ncp_request2(server, request.function,
316 bouncebuffer, NCP_PACKET_SIZE_INTERNAL);
317 if (result < 0)
318 result = -EIO;
319 else
320 result = server->reply_size;
321 ncp_unlock_server(server);
322 DPRINTK("ncp_ioctl: copy %d bytes\n",
323 result);
324 if (result >= 0)
325 if (copy_to_user(request.data, bouncebuffer, result))
326 result = -EFAULT;
327 vfree(bouncebuffer);
328 return result;
330 case NCP_IOC_CONN_LOGGED_IN:
332 if (!capable(CAP_SYS_ADMIN))
333 return -EACCES;
334 if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE))
335 return -EINVAL;
336 if (server->root_setuped)
337 return -EBUSY;
338 server->root_setuped = 1;
339 return ncp_conn_logged_in(inode->i_sb);
341 case NCP_IOC_GET_FS_INFO:
342 return ncp_get_fs_info(server, filp, argp);
344 case NCP_IOC_GET_FS_INFO_V2:
345 return ncp_get_fs_info_v2(server, filp, argp);
347 #ifdef CONFIG_COMPAT
348 case NCP_IOC_GET_FS_INFO_V2_32:
349 return ncp_get_compat_fs_info_v2(server, filp, argp);
350 #endif
351 /* we have too many combinations of CONFIG_COMPAT,
352 * CONFIG_64BIT and CONFIG_UID16, so just handle
353 * any of the possible ioctls */
354 case NCP_IOC_GETMOUNTUID16:
355 case NCP_IOC_GETMOUNTUID32:
356 case NCP_IOC_GETMOUNTUID64:
357 if ((file_permission(filp, MAY_READ) != 0)
358 && (current->uid != server->m.mounted_uid)) {
359 return -EACCES;
361 if (cmd == NCP_IOC_GETMOUNTUID16) {
362 u16 uid;
363 SET_UID(uid, server->m.mounted_uid);
364 if (put_user(uid, (u16 __user *)argp))
365 return -EFAULT;
366 } else if (cmd == NCP_IOC_GETMOUNTUID32) {
367 if (put_user(server->m.mounted_uid,
368 (u32 __user *)argp))
369 return -EFAULT;
370 } else {
371 if (put_user(server->m.mounted_uid,
372 (u64 __user *)argp))
373 return -EFAULT;
375 return 0;
377 case NCP_IOC_GETROOT:
379 struct ncp_setroot_ioctl sr;
381 if ((file_permission(filp, MAY_READ) != 0)
382 && (current->uid != server->m.mounted_uid))
384 return -EACCES;
386 if (server->m.mounted_vol[0]) {
387 struct dentry* dentry = inode->i_sb->s_root;
389 if (dentry) {
390 struct inode* inode = dentry->d_inode;
392 if (inode) {
393 sr.volNumber = NCP_FINFO(inode)->volNumber;
394 sr.dirEntNum = NCP_FINFO(inode)->dirEntNum;
395 sr.namespace = server->name_space[sr.volNumber];
396 } else
397 DPRINTK("ncpfs: s_root->d_inode==NULL\n");
398 } else
399 DPRINTK("ncpfs: s_root==NULL\n");
400 } else {
401 sr.volNumber = -1;
402 sr.namespace = 0;
403 sr.dirEntNum = 0;
405 if (copy_to_user(argp, &sr, sizeof(sr)))
406 return -EFAULT;
407 return 0;
409 case NCP_IOC_SETROOT:
411 struct ncp_setroot_ioctl sr;
412 __u32 vnum;
413 __le32 de;
414 __le32 dosde;
415 struct dentry* dentry;
417 if (!capable(CAP_SYS_ADMIN))
419 return -EACCES;
421 if (server->root_setuped) return -EBUSY;
422 if (copy_from_user(&sr, argp, sizeof(sr)))
423 return -EFAULT;
424 if (sr.volNumber < 0) {
425 server->m.mounted_vol[0] = 0;
426 vnum = NCP_NUMBER_OF_VOLUMES;
427 de = 0;
428 dosde = 0;
429 } else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) {
430 return -EINVAL;
431 } else if (ncp_mount_subdir(server, sr.volNumber,
432 sr.namespace, sr.dirEntNum,
433 &vnum, &de, &dosde)) {
434 return -ENOENT;
437 dentry = inode->i_sb->s_root;
438 server->root_setuped = 1;
439 if (dentry) {
440 struct inode* inode = dentry->d_inode;
442 if (inode) {
443 NCP_FINFO(inode)->volNumber = vnum;
444 NCP_FINFO(inode)->dirEntNum = de;
445 NCP_FINFO(inode)->DosDirNum = dosde;
446 } else
447 DPRINTK("ncpfs: s_root->d_inode==NULL\n");
448 } else
449 DPRINTK("ncpfs: s_root==NULL\n");
451 return 0;
454 #ifdef CONFIG_NCPFS_PACKET_SIGNING
455 case NCP_IOC_SIGN_INIT:
456 if ((file_permission(filp, MAY_WRITE) != 0)
457 && (current->uid != server->m.mounted_uid))
459 return -EACCES;
461 if (argp) {
462 if (server->sign_wanted)
464 struct ncp_sign_init sign;
466 if (copy_from_user(&sign, argp, sizeof(sign)))
467 return -EFAULT;
468 memcpy(server->sign_root,sign.sign_root,8);
469 memcpy(server->sign_last,sign.sign_last,16);
470 server->sign_active = 1;
472 /* ignore when signatures not wanted */
473 } else {
474 server->sign_active = 0;
476 return 0;
478 case NCP_IOC_SIGN_WANTED:
479 if ((file_permission(filp, MAY_READ) != 0)
480 && (current->uid != server->m.mounted_uid))
482 return -EACCES;
485 if (put_user(server->sign_wanted, (int __user *)argp))
486 return -EFAULT;
487 return 0;
488 case NCP_IOC_SET_SIGN_WANTED:
490 int newstate;
492 if ((file_permission(filp, MAY_WRITE) != 0)
493 && (current->uid != server->m.mounted_uid))
495 return -EACCES;
497 /* get only low 8 bits... */
498 if (get_user(newstate, (unsigned char __user *)argp))
499 return -EFAULT;
500 if (server->sign_active) {
501 /* cannot turn signatures OFF when active */
502 if (!newstate) return -EINVAL;
503 } else {
504 server->sign_wanted = newstate != 0;
506 return 0;
509 #endif /* CONFIG_NCPFS_PACKET_SIGNING */
511 #ifdef CONFIG_NCPFS_IOCTL_LOCKING
512 case NCP_IOC_LOCKUNLOCK:
513 if ((file_permission(filp, MAY_WRITE) != 0)
514 && (current->uid != server->m.mounted_uid))
516 return -EACCES;
519 struct ncp_lock_ioctl rqdata;
520 int result;
522 if (copy_from_user(&rqdata, argp, sizeof(rqdata)))
523 return -EFAULT;
524 if (rqdata.origin != 0)
525 return -EINVAL;
526 /* check for cmd */
527 switch (rqdata.cmd) {
528 case NCP_LOCK_EX:
529 case NCP_LOCK_SH:
530 if (rqdata.timeout == 0)
531 rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT;
532 else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT)
533 rqdata.timeout = NCP_LOCK_MAX_TIMEOUT;
534 break;
535 case NCP_LOCK_LOG:
536 rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */
537 case NCP_LOCK_CLEAR:
538 break;
539 default:
540 return -EINVAL;
542 /* locking needs both read and write access */
543 if ((result = ncp_make_open(inode, O_RDWR)) != 0)
545 return result;
547 result = -EIO;
548 if (!ncp_conn_valid(server))
549 goto outrel;
550 result = -EISDIR;
551 if (!S_ISREG(inode->i_mode))
552 goto outrel;
553 if (rqdata.cmd == NCP_LOCK_CLEAR)
555 result = ncp_ClearPhysicalRecord(NCP_SERVER(inode),
556 NCP_FINFO(inode)->file_handle,
557 rqdata.offset,
558 rqdata.length);
559 if (result > 0) result = 0; /* no such lock */
561 else
563 int lockcmd;
565 switch (rqdata.cmd)
567 case NCP_LOCK_EX: lockcmd=1; break;
568 case NCP_LOCK_SH: lockcmd=3; break;
569 default: lockcmd=0; break;
571 result = ncp_LogPhysicalRecord(NCP_SERVER(inode),
572 NCP_FINFO(inode)->file_handle,
573 lockcmd,
574 rqdata.offset,
575 rqdata.length,
576 rqdata.timeout);
577 if (result > 0) result = -EAGAIN;
579 outrel:
580 ncp_inode_close(inode);
581 return result;
583 #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
585 #ifdef CONFIG_COMPAT
586 case NCP_IOC_GETOBJECTNAME_32:
587 if (current->uid != server->m.mounted_uid) {
588 return -EACCES;
591 struct compat_ncp_objectname_ioctl user;
592 size_t outl;
594 if (copy_from_user(&user, argp, sizeof(user)))
595 return -EFAULT;
596 user.auth_type = server->auth.auth_type;
597 outl = user.object_name_len;
598 user.object_name_len = server->auth.object_name_len;
599 if (outl > user.object_name_len)
600 outl = user.object_name_len;
601 if (outl) {
602 if (copy_to_user(compat_ptr(user.object_name),
603 server->auth.object_name,
604 outl)) return -EFAULT;
606 if (copy_to_user(argp, &user, sizeof(user)))
607 return -EFAULT;
608 return 0;
610 #endif
611 case NCP_IOC_GETOBJECTNAME:
612 if (current->uid != server->m.mounted_uid) {
613 return -EACCES;
616 struct ncp_objectname_ioctl user;
617 size_t outl;
619 if (copy_from_user(&user, argp, sizeof(user)))
620 return -EFAULT;
621 user.auth_type = server->auth.auth_type;
622 outl = user.object_name_len;
623 user.object_name_len = server->auth.object_name_len;
624 if (outl > user.object_name_len)
625 outl = user.object_name_len;
626 if (outl) {
627 if (copy_to_user(user.object_name,
628 server->auth.object_name,
629 outl)) return -EFAULT;
631 if (copy_to_user(argp, &user, sizeof(user)))
632 return -EFAULT;
633 return 0;
635 #ifdef CONFIG_COMPAT
636 case NCP_IOC_SETOBJECTNAME_32:
637 #endif
638 case NCP_IOC_SETOBJECTNAME:
639 if (current->uid != server->m.mounted_uid) {
640 return -EACCES;
643 struct ncp_objectname_ioctl user;
644 void* newname;
645 void* oldname;
646 size_t oldnamelen;
647 void* oldprivate;
648 size_t oldprivatelen;
650 #ifdef CONFIG_COMPAT
651 if (cmd == NCP_IOC_SETOBJECTNAME_32) {
652 struct compat_ncp_objectname_ioctl user32;
653 if (copy_from_user(&user32, argp, sizeof(user32)))
654 return -EFAULT;
655 user.auth_type = user32.auth_type;
656 user.object_name_len = user32.object_name_len;
657 user.object_name = compat_ptr(user32.object_name);
658 } else
659 #endif
660 if (copy_from_user(&user, argp, sizeof(user)))
661 return -EFAULT;
663 if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN)
664 return -ENOMEM;
665 if (user.object_name_len) {
666 newname = kmalloc(user.object_name_len, GFP_USER);
667 if (!newname)
668 return -ENOMEM;
669 if (copy_from_user(newname, user.object_name, user.object_name_len)) {
670 kfree(newname);
671 return -EFAULT;
673 } else {
674 newname = NULL;
676 /* enter critical section */
677 /* maybe that kfree can sleep so do that this way */
678 /* it is at least more SMP friendly (in future...) */
679 oldname = server->auth.object_name;
680 oldnamelen = server->auth.object_name_len;
681 oldprivate = server->priv.data;
682 oldprivatelen = server->priv.len;
683 server->auth.auth_type = user.auth_type;
684 server->auth.object_name_len = user.object_name_len;
685 server->auth.object_name = newname;
686 server->priv.len = 0;
687 server->priv.data = NULL;
688 /* leave critical section */
689 kfree(oldprivate);
690 kfree(oldname);
691 return 0;
693 #ifdef CONFIG_COMPAT
694 case NCP_IOC_GETPRIVATEDATA_32:
695 #endif
696 case NCP_IOC_GETPRIVATEDATA:
697 if (current->uid != server->m.mounted_uid) {
698 return -EACCES;
701 struct ncp_privatedata_ioctl user;
702 size_t outl;
704 #ifdef CONFIG_COMPAT
705 if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
706 struct compat_ncp_privatedata_ioctl user32;
707 if (copy_from_user(&user32, argp, sizeof(user32)))
708 return -EFAULT;
709 user.len = user32.len;
710 user.data = compat_ptr(user32.data);
711 } else
712 #endif
713 if (copy_from_user(&user, argp, sizeof(user)))
714 return -EFAULT;
716 outl = user.len;
717 user.len = server->priv.len;
718 if (outl > user.len) outl = user.len;
719 if (outl) {
720 if (copy_to_user(user.data,
721 server->priv.data,
722 outl)) return -EFAULT;
724 #ifdef CONFIG_COMPAT
725 if (cmd == NCP_IOC_GETPRIVATEDATA_32) {
726 struct compat_ncp_privatedata_ioctl user32;
727 user32.len = user.len;
728 user32.data = (unsigned long) user.data;
729 if (copy_to_user(argp, &user32, sizeof(user32)))
730 return -EFAULT;
731 } else
732 #endif
733 if (copy_to_user(argp, &user, sizeof(user)))
734 return -EFAULT;
736 return 0;
738 #ifdef CONFIG_COMPAT
739 case NCP_IOC_SETPRIVATEDATA_32:
740 #endif
741 case NCP_IOC_SETPRIVATEDATA:
742 if (current->uid != server->m.mounted_uid) {
743 return -EACCES;
746 struct ncp_privatedata_ioctl user;
747 void* new;
748 void* old;
749 size_t oldlen;
751 #ifdef CONFIG_COMPAT
752 if (cmd == NCP_IOC_SETPRIVATEDATA_32) {
753 struct compat_ncp_privatedata_ioctl user32;
754 if (copy_from_user(&user32, argp, sizeof(user32)))
755 return -EFAULT;
756 user.len = user32.len;
757 user.data = compat_ptr(user32.data);
758 } else
759 #endif
760 if (copy_from_user(&user, argp, sizeof(user)))
761 return -EFAULT;
763 if (user.len > NCP_PRIVATE_DATA_MAX_LEN)
764 return -ENOMEM;
765 if (user.len) {
766 new = kmalloc(user.len, GFP_USER);
767 if (!new)
768 return -ENOMEM;
769 if (copy_from_user(new, user.data, user.len)) {
770 kfree(new);
771 return -EFAULT;
773 } else {
774 new = NULL;
776 /* enter critical section */
777 old = server->priv.data;
778 oldlen = server->priv.len;
779 server->priv.len = user.len;
780 server->priv.data = new;
781 /* leave critical section */
782 kfree(old);
783 return 0;
786 #ifdef CONFIG_NCPFS_NLS
787 case NCP_IOC_SETCHARSETS:
788 return ncp_set_charsets(server, argp);
790 case NCP_IOC_GETCHARSETS:
791 return ncp_get_charsets(server, argp);
793 #endif /* CONFIG_NCPFS_NLS */
795 case NCP_IOC_SETDENTRYTTL:
796 if ((file_permission(filp, MAY_WRITE) != 0) &&
797 (current->uid != server->m.mounted_uid))
798 return -EACCES;
800 u_int32_t user;
802 if (copy_from_user(&user, argp, sizeof(user)))
803 return -EFAULT;
804 /* 20 secs at most... */
805 if (user > 20000)
806 return -EINVAL;
807 user = (user * HZ) / 1000;
808 server->dentry_ttl = user;
809 return 0;
812 case NCP_IOC_GETDENTRYTTL:
814 u_int32_t user = (server->dentry_ttl * 1000) / HZ;
815 if (copy_to_user(argp, &user, sizeof(user)))
816 return -EFAULT;
817 return 0;
821 return -EINVAL;
824 #ifdef CONFIG_COMPAT
825 long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
827 struct inode *inode = file->f_path.dentry->d_inode;
828 int ret;
830 lock_kernel();
831 arg = (unsigned long) compat_ptr(arg);
832 ret = ncp_ioctl(inode, file, cmd, arg);
833 unlock_kernel();
834 return ret;
836 #endif