160727d8bSWarner Losh /*- 20f606585SJohn Dyson * Copyright (c) 1997 John S. Dyson. All rights reserved. 30f606585SJohn Dyson * 40f606585SJohn Dyson * Redistribution and use in source and binary forms, with or without 50f606585SJohn Dyson * modification, are permitted provided that the following conditions 60f606585SJohn Dyson * are met: 70f606585SJohn Dyson * 1. Redistributions of source code must retain the above copyright 80f606585SJohn Dyson * notice, this list of conditions and the following disclaimer. 90f606585SJohn Dyson * 2. John S. Dyson's name may not be used to endorse or promote products 100f606585SJohn Dyson * derived from this software without specific prior written permission. 110f606585SJohn Dyson * 120f606585SJohn Dyson * DISCLAIMER: This code isn't warranted to do anything useful. Anything 130f606585SJohn Dyson * bad that happens because of using this software isn't the responsibility 140f606585SJohn Dyson * of the author. This software is distributed AS-IS. 150f606585SJohn Dyson * 16c3aac50fSPeter Wemm * $FreeBSD$ 170f606585SJohn Dyson */ 180f606585SJohn Dyson 19f0231545SDmitrij Tejblum #ifndef _SYS_AIO_H_ 20f0231545SDmitrij Tejblum #define _SYS_AIO_H_ 21f0231545SDmitrij Tejblum 220f606585SJohn Dyson #include <sys/types.h> 238a6472b7SPeter Dufault #include <sys/signal.h> 24f0231545SDmitrij Tejblum 250f606585SJohn Dyson /* 260f606585SJohn Dyson * Returned by aio_cancel: 270f606585SJohn Dyson */ 280f606585SJohn Dyson #define AIO_CANCELED 0x1 2978922e41SJohn Dyson #define AIO_NOTCANCELED 0x2 300f606585SJohn Dyson #define AIO_ALLDONE 0x3 310f606585SJohn Dyson 320f606585SJohn Dyson /* 330f606585SJohn Dyson * LIO opcodes 340f606585SJohn Dyson */ 350f606585SJohn Dyson #define LIO_NOP 0x0 360f606585SJohn Dyson #define LIO_WRITE 0x1 370f606585SJohn Dyson #define LIO_READ 0x2 3853fcc63cSDavid Xu #ifdef _KERNEL 3953fcc63cSDavid Xu #define LIO_SYNC 0x3 4053fcc63cSDavid Xu #endif 410f606585SJohn Dyson 420f606585SJohn Dyson /* 430f606585SJohn Dyson * LIO modes 440f606585SJohn Dyson */ 450f606585SJohn Dyson #define LIO_NOWAIT 0x0 460f606585SJohn Dyson #define LIO_WAIT 0x1 470f606585SJohn Dyson 480f606585SJohn Dyson /* 497a2ac24cSPeter Dufault * Maximum number of allowed LIO operations 507a2ac24cSPeter Dufault */ 517a2ac24cSPeter Dufault #define AIO_LISTIO_MAX 16 527a2ac24cSPeter Dufault 537a2ac24cSPeter Dufault /* 540f606585SJohn Dyson * Private members for aiocb -- don't access 550f606585SJohn Dyson * directly. 560f606585SJohn Dyson */ 570f606585SJohn Dyson struct __aiocb_private { 5896b8882aSAlan Cox long status; 5996b8882aSAlan Cox long error; 600f606585SJohn Dyson void *kernelinfo; 610f606585SJohn Dyson }; 620f606585SJohn Dyson 630f606585SJohn Dyson /* 640f606585SJohn Dyson * I/O control block 650f606585SJohn Dyson */ 660f606585SJohn Dyson typedef struct aiocb { 670f606585SJohn Dyson int aio_fildes; /* File descriptor */ 680f606585SJohn Dyson off_t aio_offset; /* File offset for I/O */ 6978922e41SJohn Dyson volatile void *aio_buf; /* I/O buffer in process space */ 700f606585SJohn Dyson size_t aio_nbytes; /* Number of bytes for I/O */ 71c4592cbcSJohn Baldwin int __spare__[2]; 72c4592cbcSJohn Baldwin void *__spare2__; 730f606585SJohn Dyson int aio_lio_opcode; /* LIO opcode */ 740f606585SJohn Dyson int aio_reqprio; /* Request priority -- ignored */ 750f606585SJohn Dyson struct __aiocb_private _aiocb_private; 760972628aSDavid Xu struct sigevent aio_sigevent; /* Signal to deliver */ 770f606585SJohn Dyson } aiocb_t; 780f606585SJohn Dyson 79664a31e4SPeter Wemm #ifndef _KERNEL 80f0231545SDmitrij Tejblum 8134d3ac59SDavid Schultz struct timespec; 8234d3ac59SDavid Schultz 83f0231545SDmitrij Tejblum __BEGIN_DECLS 840f606585SJohn Dyson /* 850f606585SJohn Dyson * Asynchronously read from a file 860f606585SJohn Dyson */ 87f0231545SDmitrij Tejblum int aio_read(struct aiocb *); 880f606585SJohn Dyson 890f606585SJohn Dyson /* 900f606585SJohn Dyson * Asynchronously write to file 910f606585SJohn Dyson */ 92f0231545SDmitrij Tejblum int aio_write(struct aiocb *); 930f606585SJohn Dyson 940f606585SJohn Dyson /* 950f606585SJohn Dyson * List I/O Asynchronously/synchronously read/write to/from file 960f606585SJohn Dyson * "lio_mode" specifies whether or not the I/O is synchronous. 970f606585SJohn Dyson * "acb_list" is an array of "nacb_listent" I/O control blocks. 980f606585SJohn Dyson * when all I/Os are complete, the optional signal "sig" is sent. 990f606585SJohn Dyson */ 100f0231545SDmitrij Tejblum int lio_listio(int, struct aiocb * const [], int, struct sigevent *); 1010f606585SJohn Dyson 1020f606585SJohn Dyson /* 1030f606585SJohn Dyson * Get completion status 1040f606585SJohn Dyson * returns EINPROGRESS until I/O is complete. 1050f606585SJohn Dyson * this routine does not block. 1060f606585SJohn Dyson */ 107f0231545SDmitrij Tejblum int aio_error(const struct aiocb *); 1080f606585SJohn Dyson 1090f606585SJohn Dyson /* 1100f606585SJohn Dyson * Finish up I/O, releasing I/O resources and returns the value 1110f606585SJohn Dyson * that would have been associated with a synchronous I/O request. 1120f606585SJohn Dyson * This routine must be called once and only once for each 1130f606585SJohn Dyson * I/O control block who has had I/O associated with it. 1140f606585SJohn Dyson */ 115f0231545SDmitrij Tejblum ssize_t aio_return(struct aiocb *); 1160f606585SJohn Dyson 1170f606585SJohn Dyson /* 1184270aed7SAlan Cox * Cancel I/O 1190f606585SJohn Dyson */ 120f0231545SDmitrij Tejblum int aio_cancel(int, struct aiocb *); 1210f606585SJohn Dyson 1220f606585SJohn Dyson /* 1230f606585SJohn Dyson * Suspend until all specified I/O or timeout is complete. 1240f606585SJohn Dyson */ 125f0231545SDmitrij Tejblum int aio_suspend(const struct aiocb * const[], int, const struct timespec *); 1260f606585SJohn Dyson 12734d3ac59SDavid Schultz #ifdef __BSD_VISIBLE 128bfbbc4aaSJason Evans int aio_waitcomplete(struct aiocb **, struct timespec *); 12934d3ac59SDavid Schultz #endif 130bfbbc4aaSJason Evans 13153fcc63cSDavid Xu int aio_fsync(int op, struct aiocb *aiocbp); 132f0231545SDmitrij Tejblum __END_DECLS 13371af8fbaSJohn Dyson 1345aaef07cSJohn Dyson #else 1355aaef07cSJohn Dyson 1364807c4ebSGarrett Wollman /* Forward declarations for prototypes below. */ 1374807c4ebSGarrett Wollman struct socket; 1384807c4ebSGarrett Wollman struct sockbuf; 1394807c4ebSGarrett Wollman 14021d56e9cSAlfred Perlstein extern void (*aio_swake)(struct socket *, struct sockbuf *); 1415aaef07cSJohn Dyson 1420f606585SJohn Dyson #endif 1430f606585SJohn Dyson 144bfbbc4aaSJason Evans #endif 145