xref: /freebsd/sys/sys/aio.h (revision 88137067)
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 
26 /*
27  * Returned by aio_cancel:
28  */
29 #define	AIO_CANCELED		0x1
30 #define	AIO_NOTCANCELED		0x2
31 #define	AIO_ALLDONE		0x3
32 
33 /*
34  * LIO opcodes
35  */
36 #define	LIO_NOP			0x0
37 #define LIO_WRITE		0x1
38 #define	LIO_READ		0x2
39 
40 /*
41  * LIO modes
42  */
43 #define	LIO_NOWAIT		0x0
44 #define	LIO_WAIT		0x1
45 
46 /*
47  * Maximum number of allowed LIO operations
48  */
49 #define	AIO_LISTIO_MAX		16
50 
51 /*
52  * Private members for aiocb -- don't access
53  * directly.
54  */
55 struct __aiocb_private {
56 	long	status;
57 	long	error;
58 	void	*kernelinfo;
59 };
60 
61 /*
62  * I/O control block
63  */
64 typedef struct aiocb {
65 	int	aio_fildes;		/* File descriptor */
66 	off_t	aio_offset;		/* File offset for I/O */
67 	volatile void *aio_buf;         /* I/O buffer in process space */
68 	size_t	aio_nbytes;		/* Number of bytes for I/O */
69 	struct	sigevent aio_sigevent;	/* Signal to deliver */
70 	int	aio_lio_opcode;		/* LIO opcode */
71 	int	aio_reqprio;		/* Request priority -- ignored */
72 	struct	__aiocb_private	_aiocb_private;
73 } aiocb_t;
74 
75 #ifndef _KERNEL
76 
77 __BEGIN_DECLS
78 /*
79  * Asynchronously read from a file
80  */
81 int	aio_read(struct aiocb *);
82 
83 /*
84  * Asynchronously write to file
85  */
86 int	aio_write(struct aiocb *);
87 
88 /*
89  * List I/O Asynchronously/synchronously read/write to/from file
90  *	"lio_mode" specifies whether or not the I/O is synchronous.
91  *	"acb_list" is an array of "nacb_listent" I/O control blocks.
92  *	when all I/Os are complete, the optional signal "sig" is sent.
93  */
94 int	lio_listio(int, struct aiocb * const [], int, struct sigevent *);
95 
96 /*
97  * Get completion status
98  *	returns EINPROGRESS until I/O is complete.
99  *	this routine does not block.
100  */
101 int	aio_error(const struct aiocb *);
102 
103 /*
104  * Finish up I/O, releasing I/O resources and returns the value
105  *	that would have been associated with a synchronous I/O request.
106  *	This routine must be called once and only once for each
107  *	I/O control block who has had I/O associated with it.
108  */
109 ssize_t	aio_return(struct aiocb *);
110 
111 /*
112  * Cancel I/O -- implemented only to return AIO_NOTCANCELLED or
113  *	AIO_ALLDONE.  No cancellation operation will occur.
114  */
115 int	aio_cancel(int, struct aiocb *);
116 
117 /*
118  * Suspend until all specified I/O or timeout is complete.
119  */
120 int	aio_suspend(const struct aiocb * const[], int, const struct timespec *);
121 
122 int	aio_waitcomplete(struct aiocb **, struct timespec *);
123 
124 __END_DECLS
125 
126 #else
127 /*
128  * Job queue item
129  */
130 
131 #define AIOCBLIST_CANCELLED     0x1
132 #define AIOCBLIST_RUNDOWN       0x4
133 #define AIOCBLIST_ASYNCFREE     0x8
134 #define AIOCBLIST_DONE          0x10
135 
136 struct aiocblist {
137         TAILQ_ENTRY	(aiocblist) list;	/* List of jobs */
138         TAILQ_ENTRY	(aiocblist) plist;	/* List of jobs for proc */
139         int	jobflags;
140         int	jobstate;
141         int	inputcharge, outputcharge;
142         struct	buf *bp;		/* Buffer pointer */
143         struct	proc *userproc;		/* User process */
144         struct	file *fd_file;		/* Pointer to file structure */
145 	struct	aioproclist *jobaioproc;/* AIO process descriptor */
146         struct	aio_liojob *lio;	/* Optional lio job */
147         struct	aiocb *uuaiocb;		/* Pointer in userspace of aiocb */
148 	struct	klist klist;		/* list of knotes */
149         struct	aiocb uaiocb;		/* Kernel I/O control block */
150 };
151 
152 /* Forward declarations for prototypes below. */
153 struct socket;
154 struct sockbuf;
155 
156 void	aio_proc_rundown(struct proc *p);
157 void	aio_swake(struct socket *, struct sockbuf *);
158 
159 #endif
160 
161 #endif
162