1copyout(9F) Kernel Functions for Drivers copyout(9F)
2
3
4
6 copyout - copy data from a driver to a user program
7
9 #include <sys/types.h>
10 #include <sys/ddi.h>
11
12
13
14 int copyout(const void *driverbuf, void *userbuf, size_t cn);
15
16
18 This interface is obsolete. ddi_copyout(9F) should be used instead.
19
21 driverbuf Source address in the driver from which the data is
22 transferred.
23
24
25 userbuf Destination address in the user program to which the data
26 is transferred.
27
28
29 cn Number of bytes moved.
30
31
33 copyout() copies data from driver buffers to user data space.
34
35
36 Addresses that are word-aligned are moved most efficiently. However,
37 the driver developer is not obligated to ensure alignment. This func‐
38 tion automatically finds the most efficient move algorithm according to
39 address alignment.
40
42 Under normal conditions, a 0 is returned to indicate a successful copy.
43 Otherwise, a −1 is returned if one of the following occurs:
44
45 o Paging fault; the driver tried to access a page of memory
46 for which it did not have read or write access.
47
48 o Invalid user address, such as a user area or stack area.
49
50 o Invalid address that would have resulted in data being
51 copied into the user block.
52
53 o Hardware fault; a hardware error prevented access to the
54 specified user memory. For example, an uncorrectable parity
55 or ECC error occurred.
56
57
58 If a −1 is returned to the caller, driver entry point routines should
59 return EFAULT.
60
62 copyout() can be called from user context only.
63
65 Example 1 An ioctl() Routine
66
67
68 A driver ioctl(9E) routine (line 10) can be used to get or set device
69 attributes or registers. In the XX_GETREGS condition (line 17), the
70 driver copies the current device register values to a user data area
71 (line 18). If the specified argument contains an invalid address, an
72 error code is returned.
73
74
75 1 struct device { /* layout of physical device registers */
76 2 int control; /* physical device control word */
77 3 int status; /* physical device status word */
78 4 short recv_char; /* receive character from device */
79 5 short xmit_char; /* transmit character to device */
80 6 };
81 7
82 8 extern struct device xx_addr[]; /* phys. device regs. location */
83 9 . . .
84 10 xx_ioctl(dev_t dev, int cmd, int arg, int mode,
85 11 cred_t *cred_p, int *rval_p)
86 12 ...
87 13 {
88 14 register struct device *rp = &xx_addr[getminor(dev) >> 4];
89 15 switch (cmd) {
90 16
91 17 case XX_GETREGS: /* copy device regs. to user program */
92 18 if (copyout(rp, arg, sizeof(struct device)))
93 19 return(EFAULT);
94 20 break;
95 21 ...
96 22 }
97 23 ...
98 24 }
99
100
102 See attributes(5) for a description of the following attributes:
103
104
105
106
107 ┌─────────────────────────────┬─────────────────────────────┐
108 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
109 ├─────────────────────────────┼─────────────────────────────┤
110 │Stability Level │Obsolete │
111 └─────────────────────────────┴─────────────────────────────┘
112
114 attributes(5), ioctl(9E), bcopy(9F), copyin(9F), ddi_copyin(9F),
115 ddi_copyout(9F), uiomove(9F)
116
117
118 Writing Device Drivers
119
121 Driver writers who intend to support layered ioctls in their ioctl(9E)
122 routines should use ddi_copyout(9F) instead.
123
124
125 Driver defined locks should not be held across calls to this function.
126
127
128 copyout() should not be used from a streams driver. See M_COPYIN and
129 M_COPYOUT in STREAMS Programming Guide.
130
131
132
133SunOS 5.11 27 Sep 2002 copyout(9F)