1 /* 2 * Copyright (c) 1997 John S. Dyson. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. John S. Dyson's name may not be used to endorse or promote products 10 * derived from this software without specific prior written permission. 11 * 12 * DISCLAIMER: This code isn't warranted to do anything useful. Anything 13 * bad that happens because of using this software isn't the responsibility 14 * of the author. This software is distributed AS-IS. 15 * 16 * $FreeBSD$ 17 */ 18 19 #ifndef _SYS_AIO_H_ 20 #define _SYS_AIO_H_ 21 22 #include <sys/time.h> 23 #include <sys/types.h> 24 #include <sys/signal.h> 25 #include <sys/socketvar.h> 26 27 /* 28 * Returned by aio_cancel: 29 * (Note that FreeBSD's aio is not cancellable -- yet.) 30 */ 31 #define AIO_CANCELED 0x1 32 #define AIO_NOTCANCELED 0x2 33 #define AIO_ALLDONE 0x3 34 35 /* 36 * LIO opcodes 37 */ 38 #define LIO_NOP 0x0 39 #define LIO_WRITE 0x1 40 #define LIO_READ 0x2 41 42 /* 43 * LIO modes 44 */ 45 #define LIO_NOWAIT 0x0 46 #define LIO_WAIT 0x1 47 48 /* 49 * Maximum number of allowed LIO operations 50 */ 51 #define AIO_LISTIO_MAX 16 52 53 /* 54 * Private mode bit for aio. 55 * (This bit is set by the library routine 56 * to allow the kernel to support sync 57 * or async operations in the future.) 58 */ 59 #define AIO_PMODE_SYNC 0x1 60 #define AIO_PMODE_DONE 0x2 61 #define AIO_PMODE_SUSPEND 0x4 62 #define AIO_PMODE_ACTIVE 0x2357c0de 63 64 /* 65 * Private members for aiocb -- don't access 66 * directly. 67 */ 68 struct __aiocb_private { 69 int status; 70 int error; 71 int privatemodes; 72 int active; 73 int tid; 74 int threadinfo; 75 void *userinfo; 76 void *kernelinfo; 77 }; 78 79 /* 80 * I/O control block 81 */ 82 typedef struct aiocb { 83 int aio_fildes; /* File descriptor */ 84 off_t aio_offset; /* File offset for I/O */ 85 volatile void *aio_buf; /* I/O buffer in process space */ 86 size_t aio_nbytes; /* Number of bytes for I/O */ 87 struct sigevent aio_sigevent; /* Signal to deliver */ 88 int aio_lio_opcode; /* LIO opcode */ 89 int aio_reqprio; /* Request priority -- ignored */ 90 struct __aiocb_private _aiocb_private; 91 } aiocb_t; 92 93 #ifndef _KERNEL 94 95 __BEGIN_DECLS 96 /* 97 * Asynchronously read from a file 98 */ 99 int aio_read(struct aiocb *); 100 101 /* 102 * Asynchronously write to file 103 */ 104 int aio_write(struct aiocb *); 105 106 /* 107 * List I/O Asynchronously/synchronously read/write to/from file 108 * "lio_mode" specifies whether or not the I/O is synchronous. 109 * "acb_list" is an array of "nacb_listent" I/O control blocks. 110 * when all I/Os are complete, the optional signal "sig" is sent. 111 */ 112 int lio_listio(int, struct aiocb * const [], int, struct sigevent *); 113 114 /* 115 * Get completion status 116 * returns EINPROGRESS until I/O is complete. 117 * this routine does not block. 118 */ 119 int aio_error(const struct aiocb *); 120 121 /* 122 * Finish up I/O, releasing I/O resources and returns the value 123 * that would have been associated with a synchronous I/O request. 124 * This routine must be called once and only once for each 125 * I/O control block who has had I/O associated with it. 126 */ 127 ssize_t aio_return(struct aiocb *); 128 129 /* 130 * Cancel I/O -- implemented only to return AIO_NOTCANCELLED or 131 * AIO_ALLDONE. No cancellation operation will occur. 132 */ 133 int aio_cancel(int, struct aiocb *); 134 135 /* 136 * Suspend until all specified I/O or timeout is complete. 137 */ 138 int aio_suspend(const struct aiocb * const[], int, const struct timespec *); 139 140 /* 141 * Retrieve the status of the specified I/O request. 142 */ 143 int aio_error(const struct aiocb *); 144 145 int aio_waitcomplete(struct aiocb **, struct timespec *); 146 147 __END_DECLS 148 149 #else 150 /* 151 * Job queue item 152 */ 153 154 #define AIOCBLIST_CANCELLED 0x1 155 #define AIOCBLIST_RUNDOWN 0x4 156 #define AIOCBLIST_ASYNCFREE 0x8 157 #define AIOCBLIST_DONE 0x10 158 159 struct aiocblist { 160 TAILQ_ENTRY (aiocblist) list; /* List of jobs */ 161 TAILQ_ENTRY (aiocblist) plist; /* List of jobs for proc */ 162 int jobflags; 163 int jobstate; 164 int inputcharge, outputcharge; 165 struct buf *bp; /* Buffer pointer */ 166 struct proc *userproc; /* User process */ 167 struct file *fd_file; /* Pointer to file structure */ 168 struct aioproclist *jobaioproc;/* AIO process descriptor */ 169 struct aio_liojob *lio; /* Optional lio job */ 170 struct aiocb *uuaiocb; /* Pointer in userspace of aiocb */ 171 struct aiocb uaiocb; /* Kernel I/O control block */ 172 }; 173 174 void aio_proc_rundown(struct proc *p); 175 176 void aio_swake(struct socket *, struct sockbuf *); 177 178 #endif 179 180 #endif 181