Change AFS*_LINUXnn_ENV to AFS*_LINUX_ENV
[openafs.git] / src / afs / LINUX / osi_ioctl.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux module support routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17
18 #include <linux/module.h> /* early to avoid printf->printk mapping */
19 #include "afs/sysincludes.h"
20 #include "afsincludes.h"
21 #include <linux/unistd.h>               /* For syscall numbers. */
22 #include <linux/mm.h>
23
24 #ifdef AFS_AMD64_LINUX_ENV
25 #include <asm/ia32_unistd.h>
26 #endif
27
28 #include <linux/slab.h>
29 #include <linux/init.h>
30 #include <linux/sched.h>
31 #include <linux/kernel.h>
32
33 #include "osi_compat.h"
34
35 extern struct proc_dir_entry *openafs_procfs;
36
37 extern asmlinkage long
38 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
39
40 static int
41 afs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
42           unsigned long arg)
43 {
44
45     struct afsprocdata sysargs;
46
47     if (cmd != VIOC_SYSCALL && cmd != VIOC_SYSCALL32) return -EINVAL;
48
49 #ifdef NEED_IOCTL32
50     if (afs_in_compat_syscall()) {
51         struct afsprocdata32 sysargs32;
52
53         if (copy_from_user(&sysargs32, (void *)arg,
54                            sizeof(struct afsprocdata32)))
55             return -EFAULT;
56
57         return afs_syscall((unsigned long)sysargs32.syscall,
58                            (unsigned long)sysargs32.param1,
59                            (unsigned long)sysargs32.param2,
60                            (unsigned long)sysargs32.param3,
61                            (unsigned long)sysargs32.param4);
62     } else
63 #endif /* NEED_IOCTL32 */
64     {
65         if (copy_from_user(&sysargs, (void *)arg, sizeof(struct afsprocdata)))
66             return -EFAULT;
67
68         return afs_syscall(sysargs.syscall, sysargs.param1,
69                            sysargs.param2, sysargs.param3, sysargs.param4);
70     }
71 }
72
73 static long afs_unlocked_ioctl(struct file *file, unsigned int cmd,
74                                unsigned long arg) {
75     return afs_ioctl(FILE_INODE(file), file, cmd, arg);
76 }
77
78 #if defined(HAVE_LINUX_STRUCT_PROC_OPS)
79 static struct proc_ops afs_syscall_ops = {
80     .proc_ioctl = afs_unlocked_ioctl,
81 # ifdef STRUCT_PROC_OPS_HAS_PROC_COMPAT_IOCTL
82     .proc_compat_ioctl = afs_unlocked_ioctl,
83 # endif
84 };
85 #else
86 static struct file_operations afs_syscall_ops = {
87     .unlocked_ioctl = afs_unlocked_ioctl,
88     .compat_ioctl = afs_unlocked_ioctl,
89 };
90 #endif /* HAVE_LINUX_STRUCT_PROC_OPS */
91
92 void
93 osi_ioctl_init(void)
94 {
95     struct proc_dir_entry *entry;
96
97     entry = afs_proc_create(PROC_SYSCALL_NAME, 0666, openafs_procfs, &afs_syscall_ops);
98 #if defined(STRUCT_PROC_DIR_ENTRY_HAS_OWNER)
99     if (entry)
100         entry->owner = THIS_MODULE;
101 #endif
102
103 }
104
105 void
106 osi_ioctl_clean(void)
107 {
108     remove_proc_entry(PROC_SYSCALL_NAME, openafs_procfs);
109 }