1139825Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 3414476Shsu * @(#)buf.h 8.9 (Berkeley) 3/30/95 3550477Speter * $FreeBSD$ 361541Srgrimes */ 371541Srgrimes 3860041Sphk#ifndef _SYS_BIO_H_ 3960041Sphk#define _SYS_BIO_H_ 4015493Sbde 411541Srgrimes#include <sys/queue.h> 421541Srgrimes 43200403Sluigi/* bio_cmd */ 44248654Swill#define BIO_READ 0x01 /* Read I/O data */ 45248654Swill#define BIO_WRITE 0x02 /* Write I/O data */ 46248654Swill#define BIO_DELETE 0x04 /* TRIM or free blocks, i.e. mark as unused */ 47248654Swill#define BIO_GETATTR 0x08 /* Get GEOM attributes of object */ 48248654Swill#define BIO_FLUSH 0x10 /* Commit outstanding I/O now */ 49200403Sluigi#define BIO_CMD0 0x20 /* Available for local hacks */ 50200403Sluigi#define BIO_CMD1 0x40 /* Available for local hacks */ 51200403Sluigi#define BIO_CMD2 0x80 /* Available for local hacks */ 52200403Sluigi 53200403Sluigi/* bio_flags */ 54248654Swill#define BIO_ERROR 0x01 /* An error occurred processing this bio. */ 55248654Swill#define BIO_DONE 0x02 /* This bio is finished. */ 56248654Swill#define BIO_ONQUEUE 0x04 /* This bio is in a queue & not yet taken. */ 57248654Swill/* 58248654Swill * This bio must be executed after all previous bios in the queue have been 59248654Swill * executed, and before any successive bios can be executed. 60248654Swill */ 61212160Sgibbs#define BIO_ORDERED 0x08 62248508Skib#define BIO_UNMAPPED 0x10 63248508Skib#define BIO_TRANSIENT_MAPPING 0x20 64200403Sluigi 65200403Sluigi#ifdef _KERNEL 66110230Sphkstruct disk; 67110736Sphkstruct bio; 68248508Skibstruct vm_map; 69110736Sphk 70193981Sluigi/* Empty classifier tag, to prevent further classification. */ 71193981Sluigi#define BIO_NOTCLASSIFIED (void *)(~0UL) 72193981Sluigi 73125137Sphktypedef void bio_task_t(void *); 74110736Sphk 751541Srgrimes/* 7658934Sphk * The bio structure describes an I/O operation in the kernel. 7758926Sphk */ 7858926Sphkstruct bio { 79133142Spjd uint8_t bio_cmd; /* I/O operation. */ 80133142Spjd uint8_t bio_flags; /* General flags. */ 81133142Spjd uint8_t bio_cflags; /* Private use by the consumer. */ 82133142Spjd uint8_t bio_pflags; /* Private use by the provider. */ 83130585Sphk struct cdev *bio_dev; /* Device to do I/O on. */ 84110230Sphk struct disk *bio_disk; /* Valid below geom_disk.c only */ 8558942Sphk off_t bio_offset; /* Offset into file. */ 8658942Sphk long bio_bcount; /* Valid bytes in buffer. */ 8758942Sphk caddr_t bio_data; /* Memory, superblocks, indirect etc. */ 88248508Skib struct vm_page **bio_ma; /* Or unmapped. */ 89248508Skib int bio_ma_offset; /* Offset in the first page of bio_ma. */ 90248508Skib int bio_ma_n; /* Number of pages in bio_ma. */ 9158934Sphk int bio_error; /* Errno for BIO_ERROR. */ 92152739Skris long bio_resid; /* Remaining I/O in bytes. */ 9392719Salfred void (*bio_done)(struct bio *); 94133142Spjd void *bio_driver1; /* Private use by the provider. */ 95133142Spjd void *bio_driver2; /* Private use by the provider. */ 96133142Spjd void *bio_caller1; /* Private use by the consumer. */ 97133142Spjd void *bio_caller2; /* Private use by the consumer. */ 9860938Sjake TAILQ_ENTRY(bio) bio_queue; /* Disksort queue. */ 99104700Sphk const char *bio_attribute; /* Attribute for BIO_[GS]ETATTR */ 100104700Sphk struct g_consumer *bio_from; /* GEOM linkage */ 101104700Sphk struct g_provider *bio_to; /* GEOM linkage */ 102104700Sphk off_t bio_length; /* Like bio_bcount */ 103104700Sphk off_t bio_completed; /* Inverse of bio_resid */ 104104700Sphk u_int bio_children; /* Number of spawned bios */ 105110523Sphk u_int bio_inbed; /* Children safely home by now */ 106110517Sphk struct bio *bio_parent; /* Pointer to parent */ 107110517Sphk struct bintime bio_t0; /* Time request started */ 10858934Sphk 109110736Sphk bio_task_t *bio_task; /* Task_queue handler */ 110110736Sphk void *bio_task_arg; /* Argument to above */ 111193981Sluigi 112193981Sluigi void *bio_classifier1; /* Classifier tag. */ 113193981Sluigi void *bio_classifier2; /* Classifier tag. */ 114193981Sluigi 115156170Spjd#ifdef DIAGNOSTIC 116156170Spjd void *_bio_caller1; 117156170Spjd void *_bio_caller2; 118156170Spjd uint8_t _bio_cflags; 119156170Spjd#endif 120110736Sphk 12158934Sphk /* XXX: these go away when bio chaining is introduced */ 12296572Sphk daddr_t bio_pblkno; /* physical block number */ 12358926Sphk}; 12458926Sphk 125102956Sbdestruct uio; 12676322Sphkstruct devstat; 12776322Sphk 12858942Sphkstruct bio_queue_head { 12960938Sjake TAILQ_HEAD(bio_queue, bio) queue; 130121207Sphk off_t last_offset; 13158942Sphk struct bio *insert_point; 13258942Sphk}; 13358942Sphk 134248508Skibextern struct vm_map *bio_transient_map; 135248508Skibextern int bio_transient_maxcnt; 136248508Skib 137103330Sphkvoid biodone(struct bio *bp); 138103330Sphkvoid biofinish(struct bio *bp, struct devstat *stat, int error); 139103330Sphkint biowait(struct bio *bp, const char *wchan); 140112846Sphk 141103683Sphkvoid bioq_disksort(struct bio_queue_head *ap, struct bio *bp); 142112846Sphkstruct bio *bioq_first(struct bio_queue_head *head); 143134038Sphkstruct bio *bioq_takefirst(struct bio_queue_head *head); 144112941Sphkvoid bioq_flush(struct bio_queue_head *head, struct devstat *stp, int error); 145103330Sphkvoid bioq_init(struct bio_queue_head *head); 146138800Spjdvoid bioq_insert_head(struct bio_queue_head *head, struct bio *bp); 147112846Sphkvoid bioq_insert_tail(struct bio_queue_head *head, struct bio *bp); 148103330Sphkvoid bioq_remove(struct bio_queue_head *head, struct bio *bp); 14959249Sphk 150125137Sphkvoid bio_taskqueue(struct bio *bp, bio_task_t *fund, void *arg); 151125137Sphk 152130585Sphkint physio(struct cdev *dev, struct uio *uio, int ioflag); 15352066Sphk#define physread physio 15452066Sphk#define physwrite physio 15546349Salc 15655205Speter#endif /* _KERNEL */ 15715493Sbde 15860041Sphk#endif /* !_SYS_BIO_H_ */ 159