xref: /mimiker/include/sys/uio.h (revision 60656d5d)
1 #ifndef _SYS_UIO_H_
2 #define _SYS_UIO_H_
3 
4 #include <sys/types.h>
5 
6 typedef struct iovec {
7   void *iov_base; /* Base address. */
8   size_t iov_len; /* Length. */
9 } iovec_t;
10 
11 ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
12 ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
13 
14 #ifdef _KERNEL
15 
16 #include <sys/vm.h>
17 
18 typedef struct vm_map vm_map_t;
19 
20 /* This structure stores just enough information about an uio
21  * to be able to restore it after the uio is modified by uiomove(). */
22 typedef struct uiostate {
23   size_t us_resid;  /* Saved value of uio_resid */
24   int us_iovcnt;    /* Saved value of uio_iovcnt */
25   size_t us_iovoff; /* Saved value of uio_iovoff */
26 } uiostate_t;
27 
28 typedef enum { UIO_READ, UIO_WRITE } uio_op_t;
29 
30 typedef struct uio {
31   iovec_t *uio_iov;      /* scatter/gather list */
32   int uio_iovcnt;        /* length of scatter/gather list */
33   size_t uio_iovoff;     /* offset in current iov segment */
34   off_t uio_offset;      /* offset in target object */
35   size_t uio_resid;      /* remaining bytes to process */
36   uio_op_t uio_op;       /* operation */
37   vm_map_t *uio_vmspace; /* destination address space */
38   unsigned uio_ioflags;  /* IO_* flags associated with this operation */
39 } uio_t;
40 
41 #define UIO_SINGLE(op, vm_map, offset, buf, buflen)                            \
42   (uio_t) {                                                                    \
43     .uio_iov = (iovec_t[1]){(iovec_t){__UNCONST(buf), (buflen)}},              \
44     .uio_iovcnt = 1, .uio_iovoff = 0, .uio_offset = (offset),                  \
45     .uio_resid = (buflen), .uio_op = (op), .uio_vmspace = (vm_map)             \
46   }
47 
48 #define UIO_SINGLE_KERNEL(op, offset, buf, buflen)                             \
49   UIO_SINGLE(op, vm_map_kernel(), offset, buf, buflen)
50 
51 #define UIO_SINGLE_USER(op, offset, buf, buflen)                               \
52   UIO_SINGLE(op, vm_map_user(), offset, buf, buflen)
53 
54 #define UIO_VECTOR(op, vm_map, iov, iovcnt, len)                               \
55   (uio_t) {                                                                    \
56     .uio_iov = (iov), .uio_iovcnt = (iovcnt), .uio_iovoff = 0,                 \
57     .uio_offset = 0, .uio_resid = (len), .uio_op = (op),                       \
58     .uio_vmspace = (vm_map)                                                    \
59   }
60 
61 #define UIO_VECTOR_KERNEL(op, iov, iovcnt, len)                                \
62   UIO_VECTOR(op, vm_map_kernel(), iov, iovcnt, len)
63 
64 #define UIO_VECTOR_USER(op, iov, iovcnt, len)                                  \
65   UIO_VECTOR(op, vm_map_user(), iov, iovcnt, len)
66 
67 int uiomove(void *buf, size_t n, uio_t *uio);
68 void uio_save(const uio_t *uio, uiostate_t *save);
69 void uio_restore(uio_t *uio, const uiostate_t *save);
70 int uiomove_frombuf(void *buf, size_t buflen, struct uio *uio);
71 int iovec_length(const iovec_t *iov, int iovcnt, size_t *lengthp);
72 
73 #endif /* _KERNEL */
74 
75 #endif /* !_SYS_UIO_H_ */
76