root / lab4 / .minix-src / include / sys / ioccom.h @ 13
History | View | Annotate | Download (5 KB)
1 | 13 | up20180614 | /* $NetBSD: ioccom.h,v 1.12 2014/12/10 00:16:05 christos Exp $ */
|
---|---|---|---|
2 | |||
3 | /*-
|
||
4 | * Copyright (c) 1982, 1986, 1990, 1993, 1994
|
||
5 | * The Regents of the University of California. All rights reserved.
|
||
6 | *
|
||
7 | * Redistribution and use in source and binary forms, with or without
|
||
8 | * modification, are permitted provided that the following conditions
|
||
9 | * are met:
|
||
10 | * 1. Redistributions of source code must retain the above copyright
|
||
11 | * notice, this list of conditions and the following disclaimer.
|
||
12 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
13 | * notice, this list of conditions and the following disclaimer in the
|
||
14 | * documentation and/or other materials provided with the distribution.
|
||
15 | * 3. Neither the name of the University nor the names of its contributors
|
||
16 | * may be used to endorse or promote products derived from this software
|
||
17 | * without specific prior written permission.
|
||
18 | *
|
||
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
29 | * SUCH DAMAGE.
|
||
30 | *
|
||
31 | * @(#)ioccom.h 8.3 (Berkeley) 1/9/95
|
||
32 | */
|
||
33 | |||
34 | #ifndef _SYS_IOCCOM_H_
|
||
35 | #define _SYS_IOCCOM_H_
|
||
36 | |||
37 | #if !defined(__minix)
|
||
38 | /*
|
||
39 | * Ioctl's have the command encoded in the lower word, and the size of
|
||
40 | * any in or out parameters in the upper word. The high 3 bits of the
|
||
41 | * upper word are used to encode the in/out status of the parameter.
|
||
42 | *
|
||
43 | * 31 29 28 16 15 8 7 0
|
||
44 | * +---------------------------------------------------------------+
|
||
45 | * | I/O | Parameter Length | Command Group | Command |
|
||
46 | * +---------------------------------------------------------------+
|
||
47 | */
|
||
48 | #define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ |
||
49 | #else
|
||
50 | /* For Minix, reserve one extra flag bit: the 'big' size flag.
|
||
51 | * We have big ioctls and can't help it.
|
||
52 | *
|
||
53 | * 31 28 27 16 15 8 7 0
|
||
54 | * +----------------------------------------------------------------+
|
||
55 | * | I/O/B | Parameter Length | Command Group | Command |
|
||
56 | * +----------------------------------------------------------------+
|
||
57 | */
|
||
58 | #define IOC_BIG (unsigned long)0x10000000 |
||
59 | #define IOCPARM_MASK 0xfff /* parameter length, at most 12 bits */ |
||
60 | #define IOCPARM_MASK_BIG 0xFFFFF /* or 20 bits, if IOC_BIG is set */ |
||
61 | #define IOCPARM_SHIFT_BIG 8 |
||
62 | #endif /* !defined(__minix) */ |
||
63 | |||
64 | #define IOCPARM_SHIFT 16 |
||
65 | #define IOCGROUP_SHIFT 8 |
||
66 | #define IOCPARM_LEN(x) (((x) >> IOCPARM_SHIFT) & IOCPARM_MASK)
|
||
67 | #define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << IOCPARM_SHIFT))
|
||
68 | #define IOCGROUP(x) (((x) >> IOCGROUP_SHIFT) & 0xff) |
||
69 | |||
70 | #define IOCPARM_MAX NBPG /* max size of ioctl args, mult. of NBPG */ |
||
71 | /* no parameters */
|
||
72 | #define IOC_VOID (unsigned long)0x20000000 |
||
73 | /* copy parameters out */
|
||
74 | #define IOC_OUT (unsigned long)0x40000000 |
||
75 | /* copy parameters in */
|
||
76 | #define IOC_IN (unsigned long)0x80000000 |
||
77 | /* copy parameters in and out */
|
||
78 | #define IOC_INOUT (IOC_IN|IOC_OUT)
|
||
79 | /* mask for IN/OUT/VOID */
|
||
80 | #define IOC_DIRMASK (unsigned long)0xe0000000 |
||
81 | |||
82 | #define _IOC(inout, group, num, len) \
|
||
83 | ((inout) | (((len) & IOCPARM_MASK) << IOCPARM_SHIFT) | \ |
||
84 | ((group) << IOCGROUP_SHIFT) | (num)) |
||
85 | #define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) |
||
86 | #define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) |
||
87 | #define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) |
||
88 | /* this should be _IORW, but stdio got there first */
|
||
89 | #define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) |
||
90 | |||
91 | #define IOCSNPRINTF(buf, len, cmd) \
|
||
92 | snprintf((buf), (len), "_IO%s%s('%c', %hhu)", \
|
||
93 | (((cmd) >> 30) & 1) ? "W" : "", \ |
||
94 | (((cmd) >> 30) & 2) ? "R" : "", \ |
||
95 | (char)IOCGROUP(cmd), (unsigned char)(cmd)) |
||
96 | |||
97 | #if defined(__minix)
|
||
98 | #define _IOW_BIG(y,t) (y | ((sizeof(t) & IOCPARM_MASK_BIG) << IOCPARM_SHIFT_BIG) \ |
||
99 | | IOC_IN | IOC_BIG) |
||
100 | #define _IOR_BIG(y,t) (y | ((sizeof(t) & IOCPARM_MASK_BIG) << IOCPARM_SHIFT_BIG) \ |
||
101 | | IOC_OUT | IOC_BIG) |
||
102 | #define _IORW_BIG(y,t) (y | ((sizeof(t) & IOCPARM_MASK_BIG) << IOCPARM_SHIFT_BIG) \ |
||
103 | | IOC_INOUT | IOC_BIG) |
||
104 | |||
105 | /* Decode an ioctl call. */
|
||
106 | #define _MINIX_IOCTL_SIZE(i) (((i) >> IOCPARM_SHIFT) & IOCPARM_MASK)
|
||
107 | #define _MINIX_IOCTL_IOR(i) ((i) & IOC_OUT)
|
||
108 | #define _MINIX_IOCTL_IOW(i) ((i) & IOC_IN)
|
||
109 | |||
110 | /* Recognize and decode size of a 'big' ioctl call. */
|
||
111 | #define _MINIX_IOCTL_BIG(i) ((i) & IOC_BIG)
|
||
112 | #define _MINIX_IOCTL_SIZE_BIG(i) (((i) >> IOCPARM_SHIFT_BIG) & IOCPARM_MASK_BIG)
|
||
113 | #endif /* defined(__minix) */ |
||
114 | |||
115 | #endif /* !_SYS_IOCCOM_H_ */ |