]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
9bccf70c | 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
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_ | |
9bccf70c A |
68 | |
69 | #include <sys/appleapiopts.h> | |
70 | ||
71 | #ifdef KERNEL | |
1c79356b A |
72 | #include <sys/queue.h> |
73 | #include <sys/errno.h> | |
1c79356b | 74 | #include <sys/vm.h> |
9bccf70c | 75 | #include <sys/cdefs.h> |
1c79356b | 76 | |
9bccf70c | 77 | #ifdef __APPLE_API_PRIVATE |
1c79356b | 78 | |
9bccf70c | 79 | #define NOLIST ((struct buf *)0x87654321) |
1c79356b A |
80 | |
81 | /* | |
82 | * The buffer header describes an I/O operation in the kernel. | |
83 | */ | |
84 | struct buf { | |
85 | LIST_ENTRY(buf) b_hash; /* Hash chain. */ | |
86 | LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */ | |
87 | TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */ | |
88 | struct proc *b_proc; /* Associated proc; NULL if kernel. */ | |
89 | volatile long b_flags; /* B_* flags. */ | |
90 | int b_error; /* Errno value. */ | |
91 | long b_bufsize; /* Allocated buffer size. */ | |
92 | long b_bcount; /* Valid bytes in buffer. */ | |
93 | long b_resid; /* Remaining I/O. */ | |
94 | dev_t b_dev; /* Device associated with buffer. */ | |
95 | struct { | |
96 | caddr_t b_addr; /* Memory, superblocks, indirect etc.*/ | |
97 | } b_un; | |
98 | void *b_saveaddr; /* Original b_addr for physio. */ | |
99 | daddr_t b_lblkno; /* Logical block number. */ | |
100 | daddr_t b_blkno; /* Underlying physical block number. */ | |
101 | /* Function to call upon completion. */ | |
102 | void (*b_iodone) __P((struct buf *)); | |
103 | struct vnode *b_vp; /* Device vnode. */ | |
104 | int b_dirtyoff; /* Offset in buffer of dirty region. */ | |
105 | int b_dirtyend; /* Offset of end of dirty region. */ | |
106 | int b_validoff; /* Offset in buffer of valid region. */ | |
107 | int b_validend; /* Offset of end of valid region. */ | |
108 | struct ucred *b_rcred; /* Read credentials reference. */ | |
109 | struct ucred *b_wcred; /* Write credentials reference. */ | |
110 | int b_timestamp; /* timestamp for queuing operation */ | |
111 | long b_vectorcount; /* number of vectors in b_vectorlist */ | |
112 | void *b_vectorlist; /* vector list for I/O */ | |
113 | void *b_pagelist; /* to save pagelist info */ | |
114 | long b_vects[2]; /* vectorlist when b_vectorcount is 1 */ | |
115 | long b_whichq; /* the free list the buffer belongs to */ | |
116 | TAILQ_ENTRY(buf) b_act; /* Device driver queue when active */ | |
117 | void *b_drvdata; /* Device driver private use */ | |
118 | }; | |
119 | ||
120 | /* | |
121 | * For portability with historic industry practice, the cylinder number has | |
122 | * to be maintained in the `b_resid' field. | |
123 | */ | |
124 | #define b_cylinder b_resid /* Cylinder number for disksort(). */ | |
125 | ||
126 | /* Device driver compatibility definitions. */ | |
127 | #define b_active b_bcount /* Driver queue head: drive active. */ | |
128 | #define b_data b_un.b_addr /* b_un.b_addr is not changeable. */ | |
129 | #define b_errcnt b_resid /* Retry count while I/O in progress. */ | |
130 | #define iodone biodone /* Old name for biodone. */ | |
131 | #define iowait biowait /* Old name for biowait. */ | |
132 | ||
133 | /* cluster_io definitions for use with io bufs */ | |
134 | #define b_uploffset b_bufsize | |
135 | #define b_trans_head b_freelist.tqe_prev | |
136 | #define b_trans_next b_freelist.tqe_next | |
137 | #define b_real_bp b_saveaddr | |
b4c24cb9 A |
138 | #define b_iostate b_rcred |
139 | ||
140 | /* journaling uses this cluster i/o field for its own | |
141 | * purposes because meta data buf's should never go | |
142 | * through the clustering code. | |
143 | */ | |
144 | #define b_transaction b_vectorlist | |
145 | ||
146 | ||
1c79356b A |
147 | |
148 | /* | |
149 | * These flags are kept in b_flags. | |
150 | */ | |
151 | #define B_AGE 0x00000001 /* Move to age queue when I/O done. */ | |
152 | #define B_NEEDCOMMIT 0x00000002 /* Append-write in progress. */ | |
153 | #define B_ASYNC 0x00000004 /* Start I/O, do not wait. */ | |
154 | #define B_BAD 0x00000008 /* Bad block revectoring in progress. */ | |
155 | #define B_BUSY 0x00000010 /* I/O in progress. */ | |
156 | #define B_CACHE 0x00000020 /* Bread found us in the cache. */ | |
157 | #define B_CALL 0x00000040 /* Call b_iodone from biodone. */ | |
158 | #define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */ | |
159 | #define B_DIRTY 0x00000100 /* Dirty page to be pushed out async. */ | |
160 | #define B_DONE 0x00000200 /* I/O completed. */ | |
161 | #define B_EINTR 0x00000400 /* I/O was interrupted */ | |
162 | #define B_ERROR 0x00000800 /* I/O error occurred. */ | |
163 | #define B_WASDIRTY 0x00001000 /* page was found dirty in the VM cache */ | |
164 | #define B_INVAL 0x00002000 /* Does not contain valid info. */ | |
165 | #define B_LOCKED 0x00004000 /* Locked in core (not reusable). */ | |
166 | #define B_NOCACHE 0x00008000 /* Do not cache block after use. */ | |
167 | #define B_PAGEOUT 0x00010000 /* Page out indicator... */ | |
168 | #define B_PGIN 0x00020000 /* Pagein op, so swap() can count it. */ | |
169 | #define B_PHYS 0x00040000 /* I/O to user memory. */ | |
170 | #define B_RAW 0x00080000 /* Set by physio for raw transfers. */ | |
171 | #define B_READ 0x00100000 /* Read buffer. */ | |
172 | #define B_TAPE 0x00200000 /* Magnetic tape I/O. */ | |
173 | #define B_PAGELIST 0x00400000 /* Buffer describes pagelist I/O. */ | |
174 | #define B_WANTED 0x00800000 /* Process wants this buffer. */ | |
175 | #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ | |
176 | #define B_WRITEINPROG 0x01000000 /* Write in progress. */ | |
765c9de3 | 177 | #define B_HDRALLOC 0x02000000 /* zone allocated buffer header */ |
b4c24cb9 | 178 | #define B_NORELSE 0x04000000 /* don't brelse() in bwrite() */ |
1c79356b A |
179 | #define B_NEED_IODONE 0x08000000 |
180 | /* need to do a biodone on the */ | |
181 | /* real_bp associated with a cluster_io */ | |
182 | #define B_COMMIT_UPL 0x10000000 | |
183 | /* commit pages in upl when */ | |
184 | /* I/O completes/fails */ | |
185 | #define B_ZALLOC 0x20000000 /* b_data is zalloc()ed */ | |
186 | #define B_META 0x40000000 /* buffer contains meta-data. */ | |
187 | #define B_VECTORLIST 0x80000000 /* Used by device drivers. */ | |
188 | ||
189 | ||
190 | /* | |
191 | * Zero out the buffer's data area. | |
192 | */ | |
193 | #define clrbuf(bp) { \ | |
194 | bzero((bp)->b_data, (u_int)(bp)->b_bcount); \ | |
195 | (bp)->b_resid = 0; \ | |
196 | } | |
197 | ||
198 | /* Flags to low-level allocation routines. */ | |
199 | #define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ | |
200 | #define B_SYNC 0x02 /* Do all allocations synchronously. */ | |
201 | #define B_NOBUFF 0x04 /* Do not allocate struct buf */ | |
202 | ||
203 | /* Flags for operation type in getblk() */ | |
204 | #define BLK_READ 0x01 /* buffer for read */ | |
205 | #define BLK_WRITE 0x02 /* buffer for write */ | |
206 | #define BLK_PAGEIN 0x04 /* buffer for pagein */ | |
207 | #define BLK_PAGEOUT 0x08 /* buffer for pageout */ | |
208 | #define BLK_META 0x10 /* buffer for metadata */ | |
209 | #define BLK_CLREAD 0x20 /* buffer for cluster read */ | |
210 | #define BLK_CLWRITE 0x40 /* buffer for cluster write */ | |
211 | ||
1c79356b A |
212 | extern int nbuf; /* The number of buffer headers */ |
213 | extern struct buf *buf; /* The buffer headers. */ | |
214 | ||
9bccf70c A |
215 | #endif /* __APPLE_API_PRIVATE */ |
216 | ||
217 | ||
218 | #ifdef __APPLE_API_UNSTABLE | |
1c79356b A |
219 | /* Macros to clear/set/test flags. */ |
220 | #define SET(t, f) (t) |= (f) | |
221 | #define CLR(t, f) (t) &= ~(f) | |
222 | #define ISSET(t, f) ((t) & (f)) | |
9bccf70c | 223 | #endif /* __APPLE_API_UNSTABLE */ |
1c79356b | 224 | |
9bccf70c | 225 | #ifdef __APPLE_API_PRIVATE |
1c79356b A |
226 | /* |
227 | * Definitions for the buffer free lists. | |
228 | */ | |
765c9de3 | 229 | #define BQUEUES 6 /* number of free buffer queues */ |
1c79356b A |
230 | |
231 | #define BQ_LOCKED 0 /* super-blocks &c */ | |
232 | #define BQ_LRU 1 /* lru, useful buffers */ | |
233 | #define BQ_AGE 2 /* rubbish */ | |
234 | #define BQ_EMPTY 3 /* buffer headers with no memory */ | |
235 | #define BQ_META 4 /* buffer containing metadata */ | |
765c9de3 | 236 | #define BQ_LAUNDRY 5 /* buffers that need cleaning */ |
9bccf70c | 237 | #endif /* __APPLE_API_PRIVATE */ |
1c79356b A |
238 | |
239 | __BEGIN_DECLS | |
9bccf70c | 240 | #ifdef __APPLE_API_UNSTABLE |
1c79356b A |
241 | int allocbuf __P((struct buf *, int)); |
242 | void bawrite __P((struct buf *)); | |
243 | void bdwrite __P((struct buf *)); | |
244 | void biodone __P((struct buf *)); | |
245 | int biowait __P((struct buf *)); | |
246 | int bread __P((struct vnode *, daddr_t, int, | |
247 | struct ucred *, struct buf **)); | |
248 | int meta_bread __P((struct vnode *, daddr_t, int, | |
249 | struct ucred *, struct buf **)); | |
250 | int breada __P((struct vnode *, daddr_t, int, daddr_t, int, | |
251 | struct ucred *, struct buf **)); | |
252 | int breadn __P((struct vnode *, daddr_t, int, daddr_t *, int *, int, | |
253 | struct ucred *, struct buf **)); | |
254 | void brelse __P((struct buf *)); | |
255 | void bremfree __P((struct buf *)); | |
256 | void bufinit __P((void)); | |
9bccf70c | 257 | void bwillwrite __P((void)); |
1c79356b A |
258 | int bwrite __P((struct buf *)); |
259 | struct buf *getblk __P((struct vnode *, daddr_t, int, int, int, int)); | |
260 | struct buf *geteblk __P((int)); | |
261 | struct buf *incore __P((struct vnode *, daddr_t)); | |
262 | u_int minphys __P((struct buf *bp)); | |
263 | int physio __P((void (*)(struct buf *), struct buf *, dev_t, int , u_int (*)(struct buf *), struct uio *, int )); | |
264 | int count_busy_buffers __P((void)); | |
0b4e3aa0 A |
265 | struct buf *alloc_io_buf __P((struct vnode *, int)); |
266 | void free_io_buf __P((struct buf *)); | |
9bccf70c A |
267 | void reassignbuf __P((struct buf *, struct vnode *)); |
268 | #endif /* __APPLE_API_UNSTABLE */ | |
1c79356b A |
269 | __END_DECLS |
270 | ||
9bccf70c | 271 | #ifdef __APPLE_API_PRIVATE |
1c79356b A |
272 | /* |
273 | * Stats on usefulness of the buffer cache | |
274 | */ | |
275 | struct bufstats { | |
276 | long bufs_incore; /* found incore */ | |
277 | long bufs_busyincore; /* found incore. was busy */ | |
278 | long bufs_vmhits; /* not incore. found in VM */ | |
279 | long bufs_miss; /* not incore. not in VM */ | |
280 | long bufs_sleeps; /* buffer starvation */ | |
281 | long bufs_eblk; /* Calls to geteblk */ | |
282 | long bufs_iobufmax; /* Max. number of IO buffers used */ | |
283 | long bufs_iobufinuse; /* number of IO buffers in use */ | |
284 | long bufs_iobufsleeps; /* IO buffer starvation */ | |
285 | }; | |
9bccf70c | 286 | #endif /* __APPLE_API_PRIVATE */ |
1c79356b A |
287 | |
288 | #endif /* KERNEL */ | |
289 | #endif /* !_SYS_BUF_H_ */ |