xref: /freebsd/sys/sys/aio.h (revision ce834215a70ff69e7e222827437116eee2f9ac6f)
1 #ifndef	_AIO_H_
2 #define	_AIO_H_
3 
4 /*
5  * Copyright (c) 1997 John S. Dyson.  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. John S. Dyson's name may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * DISCLAIMER:  This code isn't warranted to do anything useful.  Anything
16  * bad that happens because of using this software isn't the responsibility
17  * of the author.  This software is distributed AS-IS.
18  *
19  * $Id: aio.h,v 1.1 1997/05/22 00:19:44 toor Exp $
20  */
21 
22 #include <sys/types.h>
23 
24 /**************************************************************************/
25 /* Additions to signal.h -- hack alert.                                   */
26 /**************************************************************************/
27 /*
28  * sigval structure:
29  */
30 union sigval {
31 	int	sival_int;
32 	void	*sival_ptr;
33 };
34 
35 /*
36  * this is the sigevent structure:
37  */
38 struct sigevent {
39 	int	sigev_notify;		/* Notification */
40 	int	sigev_signo;		/* Signal number */
41 	union sigval sigev_value;	/* Not used yet in FreeBSD */
42 };
43 
44 /*
45  * values for sigev_notify:
46  */
47 #define	SIGEV_NONE	0		/* Don't post a signal */
48 #define	SIGEV_SIGNAL	1		/* Post specified signal */
49 
50 /**************************************************************************/
51 /* Actual AIO header                                                      */
52 /**************************************************************************/
53 /*
54  * Returned by aio_cancel:
55  *  (Note that FreeBSD's aio is not cancellable -- yet.)
56  */
57 #define	AIO_CANCELED		0x1
58 #define AIO_NOTCANCELLED	0x2
59 #define	AIO_ALLDONE		0x3
60 
61 /*
62  * LIO opcodes
63  */
64 #define	LIO_NOP			0x0
65 #define LIO_WRITE		0x1
66 #define	LIO_READ		0x2
67 
68 /*
69  * LIO modes
70  */
71 #define	LIO_NOWAIT		0x0
72 #define	LIO_WAIT		0x1
73 
74 /*
75  * Maximum number of allowed LIO operations
76  */
77 #define	AIO_LISTIO_MAX		16
78 
79 /*
80  * Private mode bit for aio.
81  * (This bit is set by the library routine
82  *  to allow the kernel to support sync
83  *  or async operations in the future.)
84  */
85 #define AIO_PMODE_SYNC		0x1
86 #define AIO_PMODE_DONE		0x2
87 #define AIO_PMODE_SUSPEND	0x4
88 
89 /*
90  * I/O active flag -- used for compat
91  * with kernel.
92  */
93 #define AIO_PMODE_ACTIVE	0x2357c0de
94 
95 /*
96  * Private members for aiocb -- don't access
97  * directly.
98  */
99 struct __aiocb_private {
100 	int	status;
101 	int	error;
102 	int	privatemodes;
103 	int	active;
104 	int	tid;
105 	int	threadinfo;
106 	void	*userinfo;
107 	void	*kernelinfo;
108 };
109 
110 /*
111  * I/O control block
112  */
113 typedef struct aiocb {
114 	int	aio_fildes;		/* File descriptor */
115 	off_t	aio_offset;		/* File offset for I/O */
116 	void	*aio_buf;		/* I/O buffer in process space */
117 	size_t	aio_nbytes;		/* Number of bytes for I/O */
118 	struct	sigevent aio_sigevent;	/* Signal to deliver */
119 	int	aio_lio_opcode;		/* LIO opcode */
120 	int	aio_reqprio;		/* Request priority -- ignored */
121 	struct	__aiocb_private	_aiocb_private;
122 } aiocb_t;
123 
124 #ifndef KERNEL
125 /*
126  * Asynchronously read from a file
127  */
128 int aio_read( struct aiocb *iocb);
129 
130 /*
131  * Asynchronously write to file
132  */
133 int aio_write( struct aiocb *iocb);
134 
135 /*
136  * List I/O Asynchronously/synchronously read/write to/from file
137  *	"lio_mode" specifies whether or not the I/O is synchronous.
138  *	"acb_list" is an array of "nacb_listent" I/O control blocks.
139  *	when all I/Os are complete, the optional signal "sig" is sent.
140  */
141 int lio_listio( int lio_mode, struct aiocb * const acb_list[],
142 	       int nacb_listent, struct sigevent *sig);
143 
144 /*
145  * Get completion status
146  *	returns EINPROGRESS until I/O is complete.
147  *	this routine does not block.
148  */
149 int aio_error( struct aiocb *iocb);
150 
151 /*
152  * Finish up I/O, releasing I/O resources and returns the value
153  *	that would have been associated with a synchronous I/O request.
154  *	This routine must be called once and only once for each
155  *	I/O control block who has had I/O associated with it.
156  */
157 int aio_return( struct aiocb *iocb);
158 
159 /*
160  * Cancel I/O -- implemented only to return AIO_NOTCANCELLED or
161  *	AIO_ALLDONE.  No cancellation operation will occur.
162  */
163 int aio_cancel( int fd, struct aiocb *iocb);
164 
165 /*
166  * Suspend until all specified I/O or timeout is complete.
167  */
168 int aio_suspend( struct aiocb * const acb_list[], int nacb_listent,
169 		 struct timespec *tm);
170 
171 #endif
172 #endif
173 
174