xref: /freebsd/sys/sys/aio.h (revision 0f606585b82cdc5e5f433c2706394164f7b5ec55)
10f606585SJohn Dyson #ifndef	_AIO_H_
20f606585SJohn Dyson #define	_AIO_H_
30f606585SJohn Dyson 
40f606585SJohn Dyson /*
50f606585SJohn Dyson  * Copyright (c) 1997 John S. Dyson.  All rights reserved.
60f606585SJohn Dyson  *
70f606585SJohn Dyson  * Redistribution and use in source and binary forms, with or without
80f606585SJohn Dyson  * modification, are permitted provided that the following conditions
90f606585SJohn Dyson  * are met:
100f606585SJohn Dyson  * 1. Redistributions of source code must retain the above copyright
110f606585SJohn Dyson  *    notice, this list of conditions and the following disclaimer.
120f606585SJohn Dyson  * 2. John S. Dyson's name may not be used to endorse or promote products
130f606585SJohn Dyson  *    derived from this software without specific prior written permission.
140f606585SJohn Dyson  *
150f606585SJohn Dyson  * DISCLAIMER:  This code isn't warranted to do anything useful.  Anything
160f606585SJohn Dyson  * bad that happens because of using this software isn't the responsibility
170f606585SJohn Dyson  * of the author.  This software is distributed AS-IS.
180f606585SJohn Dyson  *
190f606585SJohn Dyson  * $Id: aio.h,v 1.1 1997/05/22 00:19:44 toor Exp $
200f606585SJohn Dyson  */
210f606585SJohn Dyson 
220f606585SJohn Dyson #include <sys/types.h>
230f606585SJohn Dyson 
240f606585SJohn Dyson /**************************************************************************/
250f606585SJohn Dyson /* Additions to signal.h -- hack alert.                                   */
260f606585SJohn Dyson /**************************************************************************/
270f606585SJohn Dyson /*
280f606585SJohn Dyson  * sigval structure:
290f606585SJohn Dyson  */
300f606585SJohn Dyson union sigval {
310f606585SJohn Dyson 	int	sival_int;
320f606585SJohn Dyson 	void	*sival_ptr;
330f606585SJohn Dyson };
340f606585SJohn Dyson 
350f606585SJohn Dyson /*
360f606585SJohn Dyson  * this is the sigevent structure:
370f606585SJohn Dyson  */
380f606585SJohn Dyson struct sigevent {
390f606585SJohn Dyson 	int	sigev_notify;		/* Notification */
400f606585SJohn Dyson 	int	sigev_signo;		/* Signal number */
410f606585SJohn Dyson 	union sigval sigev_value;	/* Not used yet in FreeBSD */
420f606585SJohn Dyson };
430f606585SJohn Dyson 
440f606585SJohn Dyson /*
450f606585SJohn Dyson  * values for sigev_notify:
460f606585SJohn Dyson  */
470f606585SJohn Dyson #define	SIGEV_NONE	0		/* Don't post a signal */
480f606585SJohn Dyson #define	SIGEV_SIGNAL	1		/* Post specified signal */
490f606585SJohn Dyson 
500f606585SJohn Dyson /**************************************************************************/
510f606585SJohn Dyson /* Actual AIO header                                                      */
520f606585SJohn Dyson /**************************************************************************/
530f606585SJohn Dyson /*
540f606585SJohn Dyson  * Returned by aio_cancel:
550f606585SJohn Dyson  *  (Note that FreeBSD's aio is not cancellable -- yet.)
560f606585SJohn Dyson  */
570f606585SJohn Dyson #define	AIO_CANCELED		0x1
580f606585SJohn Dyson #define AIO_NOTCANCELLED	0x2
590f606585SJohn Dyson #define	AIO_ALLDONE		0x3
600f606585SJohn Dyson 
610f606585SJohn Dyson /*
620f606585SJohn Dyson  * LIO opcodes
630f606585SJohn Dyson  */
640f606585SJohn Dyson #define	LIO_NOP			0x0
650f606585SJohn Dyson #define LIO_WRITE		0x1
660f606585SJohn Dyson #define	LIO_READ		0x2
670f606585SJohn Dyson 
680f606585SJohn Dyson /*
690f606585SJohn Dyson  * LIO modes
700f606585SJohn Dyson  */
710f606585SJohn Dyson #define	LIO_NOWAIT		0x0
720f606585SJohn Dyson #define	LIO_WAIT		0x1
730f606585SJohn Dyson 
740f606585SJohn Dyson /*
750f606585SJohn Dyson  * Maximum number of allowed LIO operations
760f606585SJohn Dyson  */
770f606585SJohn Dyson #define	AIO_LISTIO_MAX		16
780f606585SJohn Dyson 
790f606585SJohn Dyson /*
800f606585SJohn Dyson  * Private mode bit for aio.
810f606585SJohn Dyson  * (This bit is set by the library routine
820f606585SJohn Dyson  *  to allow the kernel to support sync
830f606585SJohn Dyson  *  or async operations in the future.)
840f606585SJohn Dyson  */
850f606585SJohn Dyson #define AIO_PMODE_SYNC		0x1
860f606585SJohn Dyson #define AIO_PMODE_DONE		0x2
870f606585SJohn Dyson #define AIO_PMODE_SUSPEND	0x4
880f606585SJohn Dyson 
890f606585SJohn Dyson /*
900f606585SJohn Dyson  * I/O active flag -- used for compat
910f606585SJohn Dyson  * with kernel.
920f606585SJohn Dyson  */
930f606585SJohn Dyson #define AIO_PMODE_ACTIVE	0x2357c0de
940f606585SJohn Dyson 
950f606585SJohn Dyson /*
960f606585SJohn Dyson  * Private members for aiocb -- don't access
970f606585SJohn Dyson  * directly.
980f606585SJohn Dyson  */
990f606585SJohn Dyson struct __aiocb_private {
1000f606585SJohn Dyson 	int	status;
1010f606585SJohn Dyson 	int	error;
1020f606585SJohn Dyson 	int	privatemodes;
1030f606585SJohn Dyson 	int	active;
1040f606585SJohn Dyson 	int	tid;
1050f606585SJohn Dyson 	int	threadinfo;
1060f606585SJohn Dyson 	void	*userinfo;
1070f606585SJohn Dyson 	void	*kernelinfo;
1080f606585SJohn Dyson };
1090f606585SJohn Dyson 
1100f606585SJohn Dyson /*
1110f606585SJohn Dyson  * I/O control block
1120f606585SJohn Dyson  */
1130f606585SJohn Dyson typedef struct aiocb {
1140f606585SJohn Dyson 	int	aio_fildes;		/* File descriptor */
1150f606585SJohn Dyson 	off_t	aio_offset;		/* File offset for I/O */
1160f606585SJohn Dyson 	void	*aio_buf;		/* I/O buffer in process space */
1170f606585SJohn Dyson 	size_t	aio_nbytes;		/* Number of bytes for I/O */
1180f606585SJohn Dyson 	struct	sigevent aio_sigevent;	/* Signal to deliver */
1190f606585SJohn Dyson 	int	aio_lio_opcode;		/* LIO opcode */
1200f606585SJohn Dyson 	int	aio_reqprio;		/* Request priority -- ignored */
1210f606585SJohn Dyson 	struct	__aiocb_private	_aiocb_private;
1220f606585SJohn Dyson } aiocb_t;
1230f606585SJohn Dyson 
1240f606585SJohn Dyson #ifndef KERNEL
1250f606585SJohn Dyson /*
1260f606585SJohn Dyson  * Asynchronously read from a file
1270f606585SJohn Dyson  */
1280f606585SJohn Dyson int aio_read( struct aiocb *iocb);
1290f606585SJohn Dyson 
1300f606585SJohn Dyson /*
1310f606585SJohn Dyson  * Asynchronously write to file
1320f606585SJohn Dyson  */
1330f606585SJohn Dyson int aio_write( struct aiocb *iocb);
1340f606585SJohn Dyson 
1350f606585SJohn Dyson /*
1360f606585SJohn Dyson  * List I/O Asynchronously/synchronously read/write to/from file
1370f606585SJohn Dyson  *	"lio_mode" specifies whether or not the I/O is synchronous.
1380f606585SJohn Dyson  *	"acb_list" is an array of "nacb_listent" I/O control blocks.
1390f606585SJohn Dyson  *	when all I/Os are complete, the optional signal "sig" is sent.
1400f606585SJohn Dyson  */
1410f606585SJohn Dyson int lio_listio( int lio_mode, struct aiocb * const acb_list[],
1420f606585SJohn Dyson 	       int nacb_listent, struct sigevent *sig);
1430f606585SJohn Dyson 
1440f606585SJohn Dyson /*
1450f606585SJohn Dyson  * Get completion status
1460f606585SJohn Dyson  *	returns EINPROGRESS until I/O is complete.
1470f606585SJohn Dyson  *	this routine does not block.
1480f606585SJohn Dyson  */
1490f606585SJohn Dyson int aio_error( struct aiocb *iocb);
1500f606585SJohn Dyson 
1510f606585SJohn Dyson /*
1520f606585SJohn Dyson  * Finish up I/O, releasing I/O resources and returns the value
1530f606585SJohn Dyson  *	that would have been associated with a synchronous I/O request.
1540f606585SJohn Dyson  *	This routine must be called once and only once for each
1550f606585SJohn Dyson  *	I/O control block who has had I/O associated with it.
1560f606585SJohn Dyson  */
1570f606585SJohn Dyson int aio_return( struct aiocb *iocb);
1580f606585SJohn Dyson 
1590f606585SJohn Dyson /*
1600f606585SJohn Dyson  * Cancel I/O -- implemented only to return AIO_NOTCANCELLED or
1610f606585SJohn Dyson  *	AIO_ALLDONE.  No cancellation operation will occur.
1620f606585SJohn Dyson  */
1630f606585SJohn Dyson int aio_cancel( int fd, struct aiocb *iocb);
1640f606585SJohn Dyson 
1650f606585SJohn Dyson /*
1660f606585SJohn Dyson  * Suspend until all specified I/O or timeout is complete.
1670f606585SJohn Dyson  */
1680f606585SJohn Dyson int aio_suspend( struct aiocb * const acb_list[], int nacb_listent,
1690f606585SJohn Dyson 		 struct timespec *tm);
1700f606585SJohn Dyson 
1710f606585SJohn Dyson #endif
1720f606585SJohn Dyson #endif
1730f606585SJohn Dyson 
174