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