|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26: /*
27: * Copyright (c) 1982, 1986, 1989, 1993
28: * The Regents of the University of California. All rights reserved.
29: * (c) UNIX System Laboratories, Inc.
30: * All or some portions of this file are derived from material licensed
31: * to the University of California by American Telephone and Telegraph
32: * Co. or Unix System Laboratories, Inc. and are reproduced herein with
33: * the permission of UNIX System Laboratories, Inc.
34: *
35: * Redistribution and use in source and binary forms, with or without
36: * modification, are permitted provided that the following conditions
37: * are met:
38: * 1. Redistributions of source code must retain the above copyright
39: * notice, this list of conditions and the following disclaimer.
40: * 2. Redistributions in binary form must reproduce the above copyright
41: * notice, this list of conditions and the following disclaimer in the
42: * documentation and/or other materials provided with the distribution.
43: * 3. All advertising materials mentioning features or use of this software
44: * must display the following acknowledgement:
45: * This product includes software developed by the University of
46: * California, Berkeley and its contributors.
47: * 4. Neither the name of the University nor the names of its contributors
48: * may be used to endorse or promote products derived from this software
49: * without specific prior written permission.
50: *
51: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61: * SUCH DAMAGE.
62: *
63: * @(#)buf.h 8.9 (Berkeley) 3/30/95
64: */
65:
66: #ifndef _SYS_BUF_H_
67: #define _SYS_BUF_H_
68: #include <sys/queue.h>
69: #include <sys/errno.h>
70:
71: #include <sys/vm.h>
72:
73: #define NOLIST ((struct buf *)0x87654321)
74:
75: #include <sys/cdefs.h>
76:
77: /*
78: * The buffer header describes an I/O operation in the kernel.
79: */
80: struct buf {
81: LIST_ENTRY(buf) b_hash; /* Hash chain. */
82: LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */
83: TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */
84: struct buf *b_actf, **b_actb; /* Device driver queue when active. */
85: struct proc *b_proc; /* Associated proc; NULL if kernel. */
86: volatile long b_flags; /* B_* flags. */
87: int b_error; /* Errno value. */
88: long b_bufsize; /* Allocated buffer size. */
89: long b_bcount; /* Valid bytes in buffer. */
90: long b_resid; /* Remaining I/O. */
91: dev_t b_dev; /* Device associated with buffer. */
92: struct {
93: caddr_t b_addr; /* Memory, superblocks, indirect etc.*/
94: } b_un;
95: void *b_saveaddr; /* Original b_addr for physio. */
96: daddr_t b_lblkno; /* Logical block number. */
97: daddr_t b_blkno; /* Underlying physical block number. */
98: /* Function to call upon completion. */
99: void (*b_iodone) __P((struct buf *));
100: struct vnode *b_vp; /* Device vnode. */
101: int b_dirtyoff; /* Offset in buffer of dirty region. */
102: int b_dirtyend; /* Offset of end of dirty region. */
103: struct ucred *b_rcred; /* Read credentials reference. */
104: struct ucred *b_wcred; /* Write credentials reference. */
105: int b_validoff; /* Offset in buffer of valid region. */
106: int b_validend; /* Offset of end of valid region. */
107: void *b_drvdata; /* driver specific data */
108: long b_reserved[4]; /* Reserved for future HFS use */
109: };
110:
111: /*
112: * For portability with historic industry practice, the cylinder number has
113: * to be maintained in the `b_resid' field.
114: */
115: #define b_cylinder b_resid /* Cylinder number for disksort(). */
116:
117: /* Device driver compatibility definitions. */
118: #define b_active b_bcount /* Driver queue head: drive active. */
119: #define b_data b_un.b_addr /* b_un.b_addr is not changeable. */
120: #define b_errcnt b_resid /* Retry count while I/O in progress. */
121: #define iodone biodone /* Old name for biodone. */
122: #define iowait biowait /* Old name for biowait. */
123:
124: /*
125: * These flags are kept in b_flags.
126: */
127: #define B_AGE 0x00000001 /* Move to age queue when I/O done. */
128: #define B_NEEDCOMMIT 0x00000002 /* Append-write in progress. */
129: #define B_ASYNC 0x00000004 /* Start I/O, do not wait. */
130: #define B_BAD 0x00000008 /* Bad block revectoring in progress. */
131: #define B_BUSY 0x00000010 /* I/O in progress. */
132: #define B_CACHE 0x00000020 /* Bread found us in the cache. */
133: #define B_CALL 0x00000040 /* Call b_iodone from biodone. */
134: #define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */
135: #define B_DIRTY 0x00000100 /* Dirty page to be pushed out async. */
136: #define B_DONE 0x00000200 /* I/O completed. */
137: #define B_EINTR 0x00000400 /* I/O was interrupted */
138: #define B_ERROR 0x00000800 /* I/O error occurred. */
139: #define B_GATHERED 0x00001000 /* LFS: already in a segment. */
140: #define B_INVAL 0x00002000 /* Does not contain valid info. */
141: #define B_LOCKED 0x00004000 /* Locked in core (not reusable). */
142: #define B_NOCACHE 0x00008000 /* Do not cache block after use. */
143: #define B_PAGET 0x00010000 /* Page in/out of page table space. */
144: #define B_PGIN 0x00020000 /* Pagein op, so swap() can count it. */
145: #define B_PHYS 0x00040000 /* I/O to user memory. */
146: #define B_RAW 0x00080000 /* Set by physio for raw transfers. */
147: #define B_READ 0x00100000 /* Read buffer. */
148: #define B_TAPE 0x00200000 /* Magnetic tape I/O. */
149: #define B_UAREA 0x00400000 /* Buffer describes Uarea I/O. */
150: #define B_WANTED 0x00800000 /* Process wants this buffer. */
151: #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
152: #define B_WRITEINPROG 0x01000000 /* Write in progress. */
153: #define B_XXX 0x02000000 /* Debugging flag. */
154: #define B_KERNSPACE 0x04000000 /* physical I/O to kernel space */
155: #define B_CLUST_SYNC 0x08000000 /* part of synchronous cluster write */
156: #define B_CLUST_COMMIT 0x10000000 /* commit cluster to disk and wait */
157:
158: #define B_SCRACH5 0x40000000 /* Used by device drivers. */
159: #define B_SCRACH6 0x80000000 /* Used by device drivers. */
160:
161: /*
162: * This structure describes a clustered I/O. It is stored in the b_saveaddr
163: * field of the buffer on which I/O is done. At I/O completion, cluster
164: * callback uses the structure to parcel I/O's to individual buffers, and
165: * then free's this structure.
166: */
167: struct cluster_save {
168: long bs_bcount; /* Saved b_bcount. */
169: long bs_bufsize; /* Saved b_bufsize. */
170: void *bs_saveaddr; /* Saved b_addr. */
171: int bs_nchildren; /* Number of associated buffers. */
172: struct buf **bs_children; /* List of associated buffers. */
173: };
174:
175: /*
176: * Zero out the buffer's data area.
177: */
178: #define clrbuf(bp) { \
179: bzero((bp)->b_data, (u_int)(bp)->b_bcount); \
180: (bp)->b_resid = 0; \
181: }
182:
183: /* Flags to low-level allocation routines. */
184: #define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
185: #define B_SYNC 0x02 /* Do all allocations synchronously. */
186:
187: #ifdef _KERNEL
188: extern int nbuf; /* The number of buffer headers */
189: extern struct buf *buf; /* The buffer headers. */
190: extern char *buffers; /* The buffer contents. */
191: extern int bufpages; /* Number of memory pages in the buffer pool. */
192: extern struct buf *swbuf; /* Swap I/O buffer headers. */
193: extern int nswbuf; /* Number of swap I/O buffer headers. */
194: extern struct buf bswlist; /* Head of swap I/O buffer headers free list. */
195: extern struct buf *bclnlist;/* Head of cleaned page list. */
196:
197: __BEGIN_DECLS
198: int allocbuf __P((struct buf *, int));
199: void bawrite __P((struct buf *));
200: void bdwrite __P((struct buf *));
201: void biodone __P((struct buf *));
202: int biowait __P((struct buf *));
203: int bread __P((struct vnode *, daddr_t, int,
204: struct ucred *, struct buf **));
205: int breada __P((struct vnode *, daddr_t, int, daddr_t, int,
206: struct ucred *, struct buf **));
207: int breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int,
208: struct ucred *, struct buf **));
209: void brelse __P((struct buf *));
210: void bremfree __P((struct buf *));
211: void bufinit __P((void));
212: int bwrite __P((struct buf *));
213: void cluster_callback __P((struct buf *));
214: int cluster_read __P((struct vnode *, u_quad_t, daddr_t, long,
215: struct ucred *, struct buf **, long, int, long, int *));
216: int advisory_read __P((struct vnode *, u_quad_t, daddr_t, long,
217: long, long, long));
218: int cluster_write __P((struct buf *, u_quad_t, long));
219: struct buf *getblk __P((struct vnode *, daddr_t, int, int, int));
220: struct buf *geteblk __P((int));
221: struct buf *getnewbuf __P((int slpflag, int slptimeo));
222: struct buf *incore __P((struct vnode *, daddr_t));
223: u_int minphys __P((struct buf *bp));
224: __END_DECLS
225: #endif
226: #endif /* !_SYS_BUF_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.