1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
25 * Copyright 2017 RackTop Systems.
26 */
27
28 #include <sys/debug.h>
29 #include <sys/buf.h>
30 #include <sys/errno.h>
31
32 #include <strings.h>
33
34 void
35 bioinit(buf_t *bp)
36 {
37 bzero(bp, sizeof (buf_t));
38 }
39
40 void
41 biodone(buf_t *bp)
42 {
43 if (bp->b_iodone != NULL) {
44 (*(bp->b_iodone))(bp);
45 return;
46 }
47 ASSERT((bp->b_flags & B_DONE) == 0);
48 bp->b_flags |= B_DONE;
49 }
50
51 void
52 bioerror(buf_t *bp, int error)
53 {
54 ASSERT(bp != NULL);
55 ASSERT(error >= 0);
56
57 if (error != 0) {
58 bp->b_flags |= B_ERROR;
59 } else {
60 bp->b_flags &= ~B_ERROR;
61 }
62 bp->b_error = error;
63 }
64
65
66 int
67 geterror(struct buf *bp)
68 {
69 int error = 0;
70
71 if (bp->b_flags & B_ERROR) {
72 error = bp->b_error;
73 if (!error)
74 error = EIO;
75 }
76 return (error);
77 }