2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)buf.h 8.9 (Berkeley) 3/30/95
45 #include <sys/queue.h>
52 void (*ic_prev_iodone) __P((struct bio *));
53 void *ic_prev_iodone_chain;
61 * The bio structure describes an I/O operation in the kernel.
64 u_int bio_cmd; /* I/O operation. */
65 dev_t bio_dev; /* Device to do I/O on. */
66 daddr_t bio_blkno; /* Underlying physical block number. */
67 off_t bio_offset; /* Offset into file. */
68 long bio_bcount; /* Valid bytes in buffer. */
69 caddr_t bio_data; /* Memory, superblocks, indirect etc. */
70 u_int bio_flags; /* BIO_ flags. */
71 struct buf *_bio_buf; /* Parent buffer. */
72 int bio_error; /* Errno for BIO_ERROR. */
73 long bio_resid; /* Remaining I/0 in bytes. */
74 void (*bio_done) __P((struct bio *));
75 void *bio_driver1; /* Private use by the callee. */
76 void *bio_driver2; /* Private use by the callee. */
77 void *bio_caller1; /* Private use by the caller. */
78 void *bio_caller2; /* Private use by the caller. */
79 TAILQ_ENTRY(bio) bio_queue; /* Disksort queue. */
81 /* XXX: these go away when bio chaining is introduced */
82 daddr_t bio_pblkno; /* physical block number */
83 struct iodone_chain *bio_done_chain;
91 #define BIO_CMD1 0x40000000 /* Available for local hacks */
92 #define BIO_CMD2 0x80000000 /* Available for local hacks */
95 #define BIO_ERROR 0x00000001
96 #define BIO_ORDERED 0x00000002
97 #define BIO_DONE 0x00000004
98 #define BIO_FLAG2 0x40000000 /* Available for local hacks */
99 #define BIO_FLAG1 0x80000000 /* Available for local hacks */
103 static __inline__ void
104 biodone(struct bio *bp)
106 bp->bio_flags |= BIO_DONE;
110 #ifndef _DEVICESTAT_H
112 void devstat_end_transaction_bio(struct devstat *, struct bio *);
115 static __inline__ void
116 biofinish(struct bio *bp, struct devstat *stat, int error)
120 bp->bio_error = error;
121 bp->bio_flags |= BIO_ERROR;
124 devstat_end_transaction_bio(stat, bp);
128 struct bio_queue_head {
129 TAILQ_HEAD(bio_queue, bio) queue;
131 struct bio *insert_point;
132 struct bio *switch_point;
136 static __inline void bioq_init __P((struct bio_queue_head *head));
137 static __inline void bioq_insert_tail __P((struct bio_queue_head *head,
139 static __inline void bioq_remove __P((struct bio_queue_head *head,
141 static __inline struct bio *bioq_first __P((struct bio_queue_head *head));
144 bioq_init(struct bio_queue_head *head)
146 TAILQ_INIT(&head->queue);
147 head->last_pblkno = 0;
148 head->insert_point = NULL;
149 head->switch_point = NULL;
153 bioq_insert_tail(struct bio_queue_head *head, struct bio *bp)
155 if ((bp->bio_flags & BIO_ORDERED) != 0) {
156 head->insert_point = bp;
157 head->switch_point = NULL;
159 TAILQ_INSERT_TAIL(&head->queue, bp, bio_queue);
163 bioq_remove(struct bio_queue_head *head, struct bio *bp)
165 if (bp == head->switch_point)
166 head->switch_point = TAILQ_NEXT(bp, bio_queue);
167 if (bp == head->insert_point) {
168 head->insert_point = TAILQ_PREV(bp, bio_queue, bio_queue);
169 if (head->insert_point == NULL)
170 head->last_pblkno = 0;
171 } else if (bp == TAILQ_FIRST(&head->queue))
172 head->last_pblkno = bp->bio_pblkno;
173 TAILQ_REMOVE(&head->queue, bp, bio_queue);
174 if (TAILQ_FIRST(&head->queue) == head->switch_point)
175 head->switch_point = NULL;
178 static __inline struct bio *
179 bioq_first(struct bio_queue_head *head)
181 return (TAILQ_FIRST(&head->queue));
185 * Zero out the bio's data area.
187 #define clrbio(bp) { \
188 bzero((bp)->bio_data, (u_int)(bp)->bio_bcount); \
189 (bp)->bio_resid = 0; \
192 int physio __P((dev_t dev, struct uio *uio, int ioflag));
193 #define physread physio
194 #define physwrite physio
198 #endif /* !_SYS_BIO_H_ */