1139825Simp/*- 226685Sdyson * Copyright (c) 1997 John S. Dyson. All rights reserved. 326685Sdyson * 426685Sdyson * Redistribution and use in source and binary forms, with or without 526685Sdyson * modification, are permitted provided that the following conditions 626685Sdyson * are met: 726685Sdyson * 1. Redistributions of source code must retain the above copyright 826685Sdyson * notice, this list of conditions and the following disclaimer. 926685Sdyson * 2. John S. Dyson's name may not be used to endorse or promote products 1026685Sdyson * derived from this software without specific prior written permission. 1126685Sdyson * 1226685Sdyson * DISCLAIMER: This code isn't warranted to do anything useful. Anything 1326685Sdyson * bad that happens because of using this software isn't the responsibility 1426685Sdyson * of the author. This software is distributed AS-IS. 1526685Sdyson * 1650477Speter * $FreeBSD$ 1726685Sdyson */ 1826685Sdyson 1942773Sdt#ifndef _SYS_AIO_H_ 2042773Sdt#define _SYS_AIO_H_ 2142773Sdt 2226685Sdyson#include <sys/types.h> 2334925Sdufault#include <sys/signal.h> 2442773Sdt 2526685Sdyson/* 2626685Sdyson * Returned by aio_cancel: 2726685Sdyson */ 2826685Sdyson#define AIO_CANCELED 0x1 2942773Sdt#define AIO_NOTCANCELED 0x2 3026685Sdyson#define AIO_ALLDONE 0x3 3126685Sdyson 3226685Sdyson/* 3326685Sdyson * LIO opcodes 3426685Sdyson */ 3526685Sdyson#define LIO_NOP 0x0 3626685Sdyson#define LIO_WRITE 0x1 3726685Sdyson#define LIO_READ 0x2 38157038Sdavidxu#ifdef _KERNEL 39157038Sdavidxu#define LIO_SYNC 0x3 40251526Sglebius#define LIO_MLOCK 0x4 41157038Sdavidxu#endif 4226685Sdyson 4326685Sdyson/* 4426685Sdyson * LIO modes 4526685Sdyson */ 4626685Sdyson#define LIO_NOWAIT 0x0 4726685Sdyson#define LIO_WAIT 0x1 4826685Sdyson 4926685Sdyson/* 5034327Sdufault * Maximum number of allowed LIO operations 5134327Sdufault */ 5234327Sdufault#define AIO_LISTIO_MAX 16 5334327Sdufault 5434327Sdufault/* 5526685Sdyson * Private members for aiocb -- don't access 5626685Sdyson * directly. 5726685Sdyson */ 5826685Sdysonstruct __aiocb_private { 5965484Salc long status; 6065484Salc long error; 6126685Sdyson void *kernelinfo; 6226685Sdyson}; 6326685Sdyson 6426685Sdyson/* 6526685Sdyson * I/O control block 6626685Sdyson */ 6726685Sdysontypedef struct aiocb { 6826685Sdyson int aio_fildes; /* File descriptor */ 6926685Sdyson off_t aio_offset; /* File offset for I/O */ 7042773Sdt volatile void *aio_buf; /* I/O buffer in process space */ 7126685Sdyson size_t aio_nbytes; /* Number of bytes for I/O */ 72185874Sjhb int __spare__[2]; 73185874Sjhb void *__spare2__; 7426685Sdyson int aio_lio_opcode; /* LIO opcode */ 7526685Sdyson int aio_reqprio; /* Request priority -- ignored */ 7626685Sdyson struct __aiocb_private _aiocb_private; 77151867Sdavidxu struct sigevent aio_sigevent; /* Signal to deliver */ 7826685Sdyson} aiocb_t; 7926685Sdyson 8055205Speter#ifndef _KERNEL 8142773Sdt 82189822Sdasstruct timespec; 83189822Sdas 8442773Sdt__BEGIN_DECLS 8526685Sdyson/* 8626685Sdyson * Asynchronously read from a file 8726685Sdyson */ 8855943Sjasoneint aio_read(struct aiocb *); 8926685Sdyson 9026685Sdyson/* 9126685Sdyson * Asynchronously write to file 9226685Sdyson */ 9355943Sjasoneint aio_write(struct aiocb *); 9426685Sdyson 9526685Sdyson/* 9626685Sdyson * List I/O Asynchronously/synchronously read/write to/from file 9726685Sdyson * "lio_mode" specifies whether or not the I/O is synchronous. 9826685Sdyson * "acb_list" is an array of "nacb_listent" I/O control blocks. 9926685Sdyson * when all I/Os are complete, the optional signal "sig" is sent. 10026685Sdyson */ 10155943Sjasoneint lio_listio(int, struct aiocb * const [], int, struct sigevent *); 10226685Sdyson 10326685Sdyson/* 10426685Sdyson * Get completion status 10526685Sdyson * returns EINPROGRESS until I/O is complete. 10626685Sdyson * this routine does not block. 10726685Sdyson */ 10855943Sjasoneint aio_error(const struct aiocb *); 10926685Sdyson 11026685Sdyson/* 11126685Sdyson * Finish up I/O, releasing I/O resources and returns the value 11226685Sdyson * that would have been associated with a synchronous I/O request. 11326685Sdyson * This routine must be called once and only once for each 11426685Sdyson * I/O control block who has had I/O associated with it. 11526685Sdyson */ 11655943Sjasonessize_t aio_return(struct aiocb *); 11726685Sdyson 11826685Sdyson/* 11973557Salc * Cancel I/O 12026685Sdyson */ 12155943Sjasoneint aio_cancel(int, struct aiocb *); 12226685Sdyson 12326685Sdyson/* 12426685Sdyson * Suspend until all specified I/O or timeout is complete. 12526685Sdyson */ 12655943Sjasoneint aio_suspend(const struct aiocb * const[], int, const struct timespec *); 12726685Sdyson 128251526Sglebius/* 129251526Sglebius * Asynchronous mlock 130251526Sglebius */ 131251526Sglebiusint aio_mlock(struct aiocb *); 132251526Sglebius 133189822Sdas#ifdef __BSD_VISIBLE 13455943Sjasoneint aio_waitcomplete(struct aiocb **, struct timespec *); 135189822Sdas#endif 13655943Sjasone 137157038Sdavidxuint aio_fsync(int op, struct aiocb *aiocbp); 13842773Sdt__END_DECLS 13942773Sdt 14027465Sdyson#else 14127465Sdyson 14259528Swollman/* Forward declarations for prototypes below. */ 14359528Swollmanstruct socket; 14459528Swollmanstruct sockbuf; 14559528Swollman 14688633Salfredextern void (*aio_swake)(struct socket *, struct sockbuf *); 14755943Sjasone 14826685Sdyson#endif 14927465Sdyson 15026685Sdyson#endif 151