]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39037602 | 2 | * Copyright (c) 2000-2016 Apple Computer, Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1982, 1986, 1989, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * (c) UNIX System Laboratories, Inc. | |
33 | * All or some portions of this file are derived from material licensed | |
34 | * to the University of California by American Telephone and Telegraph | |
35 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
36 | * the permission of UNIX System Laboratories, Inc. | |
37 | * | |
38 | * Redistribution and use in source and binary forms, with or without | |
39 | * modification, are permitted provided that the following conditions | |
40 | * are met: | |
41 | * 1. Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * 2. Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in the | |
45 | * documentation and/or other materials provided with the distribution. | |
46 | * 3. All advertising materials mentioning features or use of this software | |
47 | * must display the following acknowledgement: | |
48 | * This product includes software developed by the University of | |
49 | * California, Berkeley and its contributors. | |
50 | * 4. Neither the name of the University nor the names of its contributors | |
51 | * may be used to endorse or promote products derived from this software | |
52 | * without specific prior written permission. | |
53 | * | |
54 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
56 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | |
65 | * | |
66 | * @(#)buf.h 8.9 (Berkeley) 3/30/95 | |
67 | */ | |
68 | ||
69 | #ifndef _SYS_BUF_H_ | |
0a7de745 | 70 | #define _SYS_BUF_H_ |
9bccf70c | 71 | |
9bccf70c | 72 | #include <sys/cdefs.h> |
91447636 | 73 | #include <sys/kernel_types.h> |
b0d623f7 | 74 | #include <sys/ucred.h> |
91447636 A |
75 | #include <mach/memory_object_types.h> |
76 | ||
1c79356b | 77 | |
0a7de745 A |
78 | #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ |
79 | #define B_READ 0x00000001 /* Read buffer. */ | |
80 | #define B_ASYNC 0x00000002 /* Start I/O, do not wait. */ | |
81 | #define B_NOCACHE 0x00000004 /* Do not cache block after use. */ | |
82 | #define B_DELWRI 0x00000008 /* Delay I/O until buffer reused. */ | |
83 | #define B_LOCKED 0x00000010 /* Locked in core (not reusable). */ | |
84 | #define B_PHYS 0x00000020 /* I/O to user memory. */ | |
85 | #define B_CLUSTER 0x00000040 /* UPL based I/O generated by cluster layer */ | |
86 | #define B_PAGEIO 0x00000080 /* Page in/out */ | |
87 | #define B_META 0x00000100 /* buffer contains meta-data. */ | |
88 | #define B_RAW 0x00000200 /* Set by physio for raw transfers. */ | |
89 | #define B_FUA 0x00000400 /* Write-through disk cache(if supported) */ | |
90 | #define B_PASSIVE 0x00000800 /* PASSIVE I/Os are ignored by THROTTLE I/O */ | |
91 | #define B_IOSTREAMING 0x00001000 /* sequential access pattern detected */ | |
92 | #define B_THROTTLED_IO 0x00002000 /* low priority I/O (deprecated) */ | |
93 | #define B_ENCRYPTED_IO 0x00004000 /* Encrypted I/O */ | |
94 | #define B_STATICCONTENT 0x00008000 /* Buffer is likely to remain unaltered */ | |
316670eb | 95 | |
91447636 A |
96 | /* |
97 | * make sure to check when adding flags that | |
98 | * that the new flags don't overlap the definitions | |
99 | * in buf_internal.h | |
100 | */ | |
1c79356b | 101 | |
91447636 | 102 | __BEGIN_DECLS |
1c79356b | 103 | |
b0d623f7 | 104 | /*! |
0a7de745 A |
105 | * @function buf_markaged |
106 | * @abstract Mark a buffer as "aged," i.e. as a good candidate to be discarded and reused after buf_brelse(). | |
107 | * @param bp Buffer to mark. | |
91447636 | 108 | */ |
0a7de745 | 109 | void buf_markaged(buf_t bp); |
9bccf70c | 110 | |
b0d623f7 | 111 | /*! |
0a7de745 A |
112 | * @function buf_markinvalid |
113 | * @abstract Mark a buffer as not having valid data and being ready for immediate reuse after buf_brelse(). | |
114 | * @param bp Buffer to mark. | |
91447636 | 115 | */ |
0a7de745 | 116 | void buf_markinvalid(buf_t bp); |
9bccf70c | 117 | |
b0d623f7 | 118 | /*! |
0a7de745 A |
119 | * @function buf_markdelayed |
120 | * @abstract Mark a buffer as a delayed write: mark it dirty without actually scheduling I/O. | |
121 | * @discussion Data will be flushed to disk at some later time, not with brelse(). A sync()/fsync() | |
122 | * or pressure necessitating reuse of the buffer will cause it to be written back to disk. | |
123 | * @param bp Buffer to mark. | |
91447636 | 124 | */ |
0a7de745 | 125 | void buf_markdelayed(buf_t bp); |
1c79356b | 126 | |
0a7de745 | 127 | void buf_markclean(buf_t); |
6d2010ae | 128 | |
b0d623f7 | 129 | /*! |
0a7de745 A |
130 | * @function buf_markeintr |
131 | * @abstract Mark a buffer as having been interrupted during I/O. | |
132 | * @discussion Waiters for I/O to complete (buf_biowait()) will return with EINTR when woken up. | |
133 | * buf_markeintr does not itself do a wakeup. | |
134 | * @param bp Buffer to mark. | |
1c79356b | 135 | */ |
0a7de745 | 136 | void buf_markeintr(buf_t bp); |
1c79356b | 137 | |
b0d623f7 | 138 | /*! |
0a7de745 A |
139 | * @function buf_markfua |
140 | * @abstract Mark a buffer for write through disk cache, if disk supports it. | |
141 | * @param bp Buffer to mark. | |
2d21ac55 | 142 | */ |
0a7de745 | 143 | void buf_markfua(buf_t bp); |
2d21ac55 | 144 | |
b0d623f7 | 145 | /*! |
0a7de745 A |
146 | * @function buf_fua |
147 | * @abstract Check if a buffer is marked for write through disk caches. | |
148 | * @param bp Buffer to test. | |
149 | * @return Nonzero if buffer is marked for write-through, 0 if not. | |
2d21ac55 | 150 | */ |
0a7de745 | 151 | int buf_fua(buf_t bp); |
2d21ac55 | 152 | |
b0d623f7 | 153 | /*! |
0a7de745 A |
154 | * @function buf_valid |
155 | * @abstract Check if a buffer contains valid data. | |
156 | * @param bp Buffer to test. | |
157 | * @return Nonzero if buffer has valid data, 0 if not. | |
91447636 | 158 | */ |
0a7de745 | 159 | int buf_valid(buf_t bp); |
1c79356b | 160 | |
b0d623f7 | 161 | /*! |
0a7de745 A |
162 | * @function buf_fromcache |
163 | * @abstract Check if a buffer's data was found in core. | |
164 | * @discussion Will return truth after a buf_getblk that finds a valid buffer in the cache or the relevant | |
165 | * data in core (but not in a buffer). | |
166 | * @param bp Buffer to test. | |
167 | * @return Nonzero if we got this buffer's data without doing I/O, 0 if not. | |
91447636 | 168 | */ |
0a7de745 | 169 | int buf_fromcache(buf_t bp); |
91447636 | 170 | |
b0d623f7 | 171 | /*! |
0a7de745 A |
172 | * @function buf_upl |
173 | * @abstract Get the upl (Universal Page List) associated with a buffer. | |
174 | * @discussion Buffers allocated with buf_alloc() are not returned with a upl, and | |
175 | * traditional buffers only have a upl while an I/O is in progress. | |
176 | * @param bp Buffer whose upl to grab. | |
177 | * @return Buffer's upl if it has one, else NULL. | |
91447636 | 178 | */ |
0a7de745 | 179 | void * buf_upl(buf_t bp); |
91447636 | 180 | |
b0d623f7 | 181 | /*! |
0a7de745 A |
182 | * @function buf_uploffset |
183 | * @abstract Get the offset into a UPL at which this buffer begins. | |
184 | * @discussion This function should only be called on iobufs, i.e. buffers allocated with buf_alloc(). | |
185 | * @param bp Buffer whose uploffset to grab. | |
186 | * @return Buffer's uploffset--does not check whether that value makes sense for this buffer. | |
91447636 | 187 | */ |
39037602 | 188 | uint32_t buf_uploffset(buf_t bp); |
91447636 | 189 | |
b0d623f7 | 190 | /*! |
0a7de745 A |
191 | * @function buf_rcred |
192 | * @abstract Get the credential associated with a buffer for reading. | |
193 | * @discussion No reference is taken; if the credential is to be held on to persistently, an additional | |
194 | * reference must be taken with kauth_cred_ref. | |
195 | * @param bp Buffer whose credential to grab. | |
196 | * @return Credential if it exists, else NULL. | |
b0d623f7 | 197 | */ |
39037602 | 198 | kauth_cred_t buf_rcred(buf_t bp); |
b0d623f7 A |
199 | |
200 | /*! | |
0a7de745 A |
201 | * @function buf_wcred |
202 | * @abstract Get the credential associated with a buffer for writing. | |
203 | * @discussion No reference is taken; if the credential is to be held on to persistently, an additional | |
204 | * reference must be taken with kauth_cred_ref. | |
205 | * @param bp Buffer whose credential to grab. | |
206 | * @return Credential if it exists, else NULL. | |
b0d623f7 | 207 | */ |
39037602 | 208 | kauth_cred_t buf_wcred(buf_t bp); |
b0d623f7 A |
209 | |
210 | /*! | |
0a7de745 A |
211 | * @function buf_proc |
212 | * @abstract Get the process associated with this buffer. | |
213 | * @discussion buf_proc() will generally return NULL; a process is currently only associated with | |
214 | * a buffer in the event of a physio() call. | |
215 | * @param bp Buffer whose associated process to find. | |
216 | * @return Associated process, possibly NULL. | |
91447636 | 217 | */ |
0a7de745 | 218 | proc_t buf_proc(buf_t bp); |
91447636 | 219 | |
b0d623f7 | 220 | /*! |
0a7de745 A |
221 | * @function buf_dirtyoff |
222 | * @abstract Get the starting offset of the dirty region associated with a buffer. | |
223 | * @discussion The dirty offset is zero unless someone explicitly calls buf_setdirtyoff() (which the kernel does not). | |
224 | * @param bp Buffer whose dirty offset to get. | |
225 | * @return Dirty offset (0 if not explicitly changed). | |
91447636 | 226 | */ |
39037602 | 227 | uint32_t buf_dirtyoff(buf_t bp); |
91447636 | 228 | |
b0d623f7 | 229 | /*! |
0a7de745 A |
230 | * @function buf_dirtyend |
231 | * @abstract Get the ending offset of the dirty region associated with a buffer. | |
232 | * @discussion If the buffer's data was found incore and dirty, the dirty end is the size of the block; otherwise, unless | |
233 | * someone outside of xnu explicitly changes it by calling buf_setdirtyend(), it will be zero. | |
234 | * @param bp Buffer whose dirty end to get. | |
235 | * @return 0 if buffer is found clean; size of buffer if found dirty. Can be set to any value by callers of buf_setdirtyend(). | |
91447636 | 236 | */ |
39037602 | 237 | uint32_t buf_dirtyend(buf_t bp); |
b0d623f7 A |
238 | |
239 | /*! | |
0a7de745 A |
240 | * @function buf_setdirtyoff |
241 | * @abstract Set the starting offset of the dirty region associated with a buffer. | |
242 | * @discussion This value is zero unless someone set it explicitly. | |
243 | * @param bp Buffer whose dirty end to set. | |
b0d623f7 | 244 | */ |
0a7de745 | 245 | void buf_setdirtyoff(buf_t bp, uint32_t); |
b0d623f7 A |
246 | |
247 | /*! | |
0a7de745 A |
248 | * @function buf_setdirtyend |
249 | * @abstract Set the ending offset of the dirty region associated with a buffer. | |
250 | * @discussion If the buffer's data was found incore and dirty, the dirty end is the size of the block; otherwise, unless | |
251 | * someone outside of xnu explicitly changes it by calling buf_setdirtyend(), it will be zero. | |
252 | * @param bp Buffer whose dirty end to set. | |
b0d623f7 | 253 | */ |
0a7de745 | 254 | void buf_setdirtyend(buf_t bp, uint32_t); |
91447636 | 255 | |
b0d623f7 | 256 | /*! |
0a7de745 A |
257 | * @function buf_error |
258 | * @abstract Get the error value associated with a buffer. | |
259 | * @discussion Errors are set with buf_seterror(). | |
260 | * @param bp Buffer whose error value to retrieve. | |
261 | * @return Error value, directly. | |
91447636 | 262 | */ |
0a7de745 | 263 | errno_t buf_error(buf_t bp); |
91447636 | 264 | |
b0d623f7 | 265 | /*! |
0a7de745 A |
266 | * @function buf_seterror |
267 | * @abstract Set an error value on a buffer. | |
268 | * @param bp Buffer whose error value to set. | |
91447636 | 269 | */ |
0a7de745 | 270 | void buf_seterror(buf_t bp, errno_t); |
91447636 | 271 | |
b0d623f7 | 272 | /*! |
0a7de745 A |
273 | * @function buf_setflags |
274 | * @abstract Set flags on a buffer. | |
275 | * @discussion buffer_flags |= flags | |
276 | * @param bp Buffer whose flags to set. | |
277 | * @param flags Flags to add to buffer's mask. B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA | |
91447636 | 278 | */ |
0a7de745 | 279 | void buf_setflags(buf_t bp, int32_t flags); |
91447636 | 280 | |
b0d623f7 | 281 | /*! |
0a7de745 A |
282 | * @function buf_clearflags |
283 | * @abstract Clear flags on a buffer. | |
284 | * @discussion buffer_flags &= ~flags | |
285 | * @param bp Buffer whose flags to clear. | |
286 | * @param flags Flags to remove from buffer's mask. B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA | |
91447636 | 287 | */ |
0a7de745 | 288 | void buf_clearflags(buf_t bp, int32_t flags); |
91447636 | 289 | |
b0d623f7 | 290 | /*! |
0a7de745 A |
291 | * @function buf_flags |
292 | * @abstract Get flags set on a buffer. | |
293 | * @discussion Valid flags are B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA. | |
294 | * @param bp Buffer whose flags to grab. | |
295 | * @return flags. | |
91447636 | 296 | */ |
0a7de745 | 297 | int32_t buf_flags(buf_t bp); |
91447636 | 298 | |
b0d623f7 | 299 | /*! |
0a7de745 A |
300 | * @function buf_reset |
301 | * @abstract Reset I/O flag state on a buffer. | |
302 | * @discussion Clears current flags on a buffer (internal and external) and allows some new flags to be set. | |
303 | * Used perhaps to prepare an iobuf for reuse. | |
304 | * @param bp Buffer whose flags to grab. | |
305 | * @param flags Flags to set on buffer: B_READ, B_WRITE, B_ASYNC, B_NOCACHE. | |
91447636 | 306 | */ |
0a7de745 | 307 | void buf_reset(buf_t bp, int32_t flags); |
91447636 | 308 | |
b0d623f7 | 309 | /*! |
0a7de745 A |
310 | * @function buf_map |
311 | * @abstract Get virtual mappings for buffer data. | |
312 | * @discussion For buffers created through buf_getblk() (i.e. traditional buffer cache usage), | |
313 | * buf_map() just returns the address at which data was mapped by but_getblk(). For a B_CLUSTER buffer, i.e. an iobuf | |
314 | * whose upl state is managed manually, there are two possibilities. If the buffer was created | |
315 | * with an underlying "real" buffer through cluster_bp(), the mapping of the "real" buffer is returned. | |
316 | * Otherwise, the buffer was created with buf_alloc() and buf_setupl() was subsequently called; buf_map() | |
317 | * will call ubc_upl_map() to get a mapping for the buffer's upl and return the start of that mapping | |
318 | * plus the buffer's upl offset (set in buf_setupl()). In the last case, buf_unmap() must later be called | |
319 | * to tear down the mapping. NOTE: buf_map() does not set the buffer data pointer; this must be done with buf_setdataptr(). | |
320 | * @param bp Buffer whose mapping to find or create. | |
321 | * @param io_addr Destination for mapping address. | |
322 | * @return 0 for success, ENOMEM if unable to map the buffer. | |
91447636 | 323 | */ |
0a7de745 | 324 | errno_t buf_map(buf_t bp, caddr_t *io_addr); |
91447636 | 325 | |
b0d623f7 | 326 | /*! |
0a7de745 A |
327 | * @function buf_unmap |
328 | * @abstract Release mappings for buffer data. | |
329 | * @discussion For buffers created through buf_getblk() (i.e. traditional buffer cache usage), | |
330 | * buf_unmap() does nothing; buf_brelse() will take care of unmapping. For a B_CLUSTER buffer, i.e. an iobuf | |
331 | * whose upl state is managed manually, there are two possibilities. If the buffer was created | |
332 | * with an underlying "real" buffer through cluster_bp(), buf_unmap() does nothing; buf_brelse() on the | |
333 | * underlying buffer will tear down the mapping. Otherwise, the buffer was created with buf_alloc() and | |
334 | * buf_setupl() was subsequently called; buf_map() created the mapping. In this case, buf_unmap() will | |
335 | * unmap the buffer. | |
336 | * @param bp Buffer whose mapping to find or create. | |
337 | * @return 0 for success, EINVAL if unable to unmap buffer. | |
91447636 | 338 | */ |
0a7de745 | 339 | errno_t buf_unmap(buf_t bp); |
91447636 | 340 | |
b0d623f7 | 341 | /*! |
0a7de745 A |
342 | * @function buf_setdrvdata |
343 | * @abstract Set driver-specific data on a buffer. | |
344 | * @param bp Buffer whose driver-data to set. | |
345 | * @param drvdata Opaque driver data. | |
91447636 | 346 | */ |
0a7de745 | 347 | void buf_setdrvdata(buf_t bp, void *drvdata); |
91447636 | 348 | |
b0d623f7 | 349 | /*! |
0a7de745 A |
350 | * @function buf_setdrvdata |
351 | * @abstract Get driver-specific data from a buffer. | |
352 | * @param bp Buffer whose driver data to get. | |
353 | * @return Opaque driver data. | |
91447636 | 354 | */ |
0a7de745 | 355 | void * buf_drvdata(buf_t bp); |
91447636 | 356 | |
b0d623f7 | 357 | /*! |
0a7de745 A |
358 | * @function buf_setfsprivate |
359 | * @abstract Set filesystem-specific data on a buffer. | |
360 | * @param bp Buffer whose filesystem data to set. | |
361 | * @param fsprivate Opaque filesystem data. | |
91447636 | 362 | */ |
0a7de745 | 363 | void buf_setfsprivate(buf_t bp, void *fsprivate); |
91447636 | 364 | |
b0d623f7 | 365 | /*! |
0a7de745 A |
366 | * @function buf_fsprivate |
367 | * @abstract Get filesystem-specific data from a buffer. | |
368 | * @param bp Buffer whose filesystem data to get. | |
369 | * @return Opaque filesystem data. | |
91447636 | 370 | */ |
0a7de745 | 371 | void * buf_fsprivate(buf_t bp); |
91447636 | 372 | |
b0d623f7 | 373 | /*! |
0a7de745 A |
374 | * @function buf_blkno |
375 | * @abstract Get physical block number associated with a buffer, in the sense of VNOP_BLOCKMAP. | |
376 | * @discussion When a buffer's physical block number is the same is its logical block number, then the physical | |
377 | * block number is considered uninitialized. A physical block number of -1 indicates that there is no valid | |
378 | * physical mapping (e.g. the logical block is invalid or corresponds to a sparse region in a file). Physical | |
379 | * block number is normally set by the cluster layer or by buf_getblk(). | |
380 | * @param bp Buffer whose physical block number to get. | |
381 | * @return Block number. | |
91447636 | 382 | */ |
39037602 | 383 | daddr64_t buf_blkno(buf_t bp); |
91447636 | 384 | |
b0d623f7 | 385 | /*! |
0a7de745 A |
386 | * @function buf_lblkno |
387 | * @abstract Get logical block number associated with a buffer. | |
388 | * @discussion Logical block number is set on traditionally-used buffers by an argument passed to buf_getblk(), | |
389 | * for example by buf_bread(). | |
390 | * @param bp Buffer whose logical block number to get. | |
391 | * @return Block number. | |
91447636 | 392 | */ |
39037602 | 393 | daddr64_t buf_lblkno(buf_t bp); |
91447636 | 394 | |
b0d623f7 | 395 | /*! |
0a7de745 A |
396 | * @function buf_setblkno |
397 | * @abstract Set physical block number associated with a buffer. | |
398 | * @discussion Physical block number is generally set by the cluster layer or by buf_getblk(). | |
399 | * @param bp Buffer whose physical block number to set. | |
400 | * @param blkno Block number to set. | |
91447636 | 401 | */ |
0a7de745 | 402 | void buf_setblkno(buf_t bp, daddr64_t blkno); |
91447636 | 403 | |
b0d623f7 | 404 | /*! |
0a7de745 A |
405 | * @function buf_setlblkno |
406 | * @abstract Set logical block number associated with a buffer. | |
407 | * @discussion Logical block number is set on traditionally-used buffers by an argument passed to buf_getblk(), | |
408 | * for example by buf_bread(). | |
409 | * @param bp Buffer whose logical block number to set. | |
410 | * @param lblkno Block number to set. | |
91447636 | 411 | */ |
0a7de745 | 412 | void buf_setlblkno(buf_t bp, daddr64_t lblkno); |
91447636 | 413 | |
b0d623f7 | 414 | /*! |
0a7de745 A |
415 | * @function buf_count |
416 | * @abstract Get count of valid bytes in a buffer. This may be less than the space allocated to the buffer. | |
417 | * @param bp Buffer whose byte count to get. | |
418 | * @return Byte count. | |
91447636 | 419 | */ |
39037602 | 420 | uint32_t buf_count(buf_t bp); |
91447636 | 421 | |
b0d623f7 | 422 | /*! |
0a7de745 A |
423 | * @function buf_size |
424 | * @abstract Get size of data region allocated to a buffer. | |
425 | * @discussion May be larger than amount of valid data in buffer. | |
426 | * @param bp Buffer whose size to get. | |
427 | * @return Size. | |
91447636 | 428 | */ |
39037602 | 429 | uint32_t buf_size(buf_t bp); |
91447636 | 430 | |
b0d623f7 | 431 | /*! |
0a7de745 A |
432 | * @function buf_resid |
433 | * @abstract Get a count of bytes which were not consumed by an I/O on a buffer. | |
434 | * @discussion Set when an I/O operations completes. | |
435 | * @param bp Buffer whose outstanding count to get. | |
436 | * @return Count of unwritten/unread bytes. | |
91447636 | 437 | */ |
39037602 | 438 | uint32_t buf_resid(buf_t bp); |
91447636 | 439 | |
b0d623f7 | 440 | /*! |
0a7de745 A |
441 | * @function buf_setcount |
442 | * @abstract Set count of valid bytes in a buffer. This may be less than the space allocated to the buffer. | |
443 | * @param bp Buffer whose byte count to set. | |
444 | * @param bcount Count to set. | |
91447636 | 445 | */ |
0a7de745 | 446 | void buf_setcount(buf_t bp, uint32_t bcount); |
91447636 | 447 | |
b0d623f7 | 448 | /*! |
0a7de745 A |
449 | * @function buf_setsize |
450 | * @abstract Set size of data region allocated to a buffer. | |
451 | * @discussion May be larger than amount of valid data in buffer. Should be used by | |
452 | * code which is manually providing storage for an iobuf, one allocated with buf_alloc(). | |
453 | * @param bp Buffer whose size to set. | |
91447636 | 454 | */ |
0a7de745 | 455 | void buf_setsize(buf_t bp, uint32_t); |
91447636 | 456 | |
b0d623f7 | 457 | /*! |
0a7de745 A |
458 | * @function buf_setresid |
459 | * @abstract Set a count of bytes outstanding for I/O in a buffer. | |
460 | * @discussion Set when an I/O operations completes. Examples: called by IOStorageFamily when I/O | |
461 | * completes, often called on an "original" buffer when using a manipulated buffer to perform I/O | |
462 | * on behalf of the first. | |
463 | * @param bp Buffer whose outstanding count to set. | |
91447636 | 464 | */ |
0a7de745 | 465 | void buf_setresid(buf_t bp, uint32_t resid); |
91447636 | 466 | |
b0d623f7 | 467 | /*! |
0a7de745 A |
468 | * @function buf_setdataptr |
469 | * @abstract Set the address at which a buffer's data will be stored. | |
470 | * @discussion In traditional buffer use, the data pointer will be set automatically. This routine is | |
471 | * useful with iobufs (allocated with buf_alloc()). | |
472 | * @param bp Buffer whose data pointer to set. | |
473 | * @param data Pointer to data region. | |
91447636 | 474 | */ |
0a7de745 | 475 | void buf_setdataptr(buf_t bp, uintptr_t data); |
91447636 | 476 | |
b0d623f7 | 477 | /*! |
0a7de745 A |
478 | * @function buf_dataptr |
479 | * @abstract Get the address at which a buffer's data is stored; for iobufs, this must | |
480 | * be set with buf_setdataptr(). See buf_map(). | |
481 | * @param bp Buffer whose data pointer to retrieve. | |
482 | * @return Data pointer; NULL if unset. | |
91447636 | 483 | */ |
39037602 | 484 | uintptr_t buf_dataptr(buf_t bp); |
1c79356b | 485 | |
b0d623f7 | 486 | /*! |
0a7de745 A |
487 | * @function buf_vnode |
488 | * @abstract Get the vnode associated with a buffer. | |
489 | * @discussion Every buffer is associated with a file. Because there is an I/O in flight, | |
490 | * there is an iocount on this vnode; it is returned WITHOUT an extra iocount, and vnode_put() | |
491 | * need NOT be called. | |
492 | * @param bp Buffer whose vnode to retrieve. | |
493 | * @return Buffer's vnode. | |
1c79356b | 494 | */ |
0a7de745 | 495 | vnode_t buf_vnode(buf_t bp); |
91447636 | 496 | |
b0d623f7 | 497 | /*! |
0a7de745 A |
498 | * @function buf_setvnode |
499 | * @abstract Set the vnode associated with a buffer. | |
500 | * @discussion This call need not be used on traditional buffers; it is for use with iobufs. | |
501 | * @param bp Buffer whose vnode to set. | |
502 | * @param vp The vnode to attach to the buffer. | |
91447636 | 503 | */ |
0a7de745 | 504 | void buf_setvnode(buf_t bp, vnode_t vp); |
91447636 | 505 | |
b0d623f7 | 506 | /*! |
0a7de745 A |
507 | * @function buf_device |
508 | * @abstract Get the device ID associated with a buffer. | |
509 | * @discussion In traditional buffer use, this value is NODEV until buf_strategy() is called unless | |
510 | * buf_getblk() was passed a device vnode. It is set on an iobuf if buf_alloc() is passed a device | |
511 | * vnode or if buf_setdevice() is called. | |
512 | * @param bp Buffer whose device ID to retrieve. | |
513 | * @return Device id. | |
91447636 | 514 | */ |
0a7de745 | 515 | dev_t buf_device(buf_t bp); |
91447636 | 516 | |
b0d623f7 | 517 | /*! |
0a7de745 A |
518 | * @function buf_setdevice |
519 | * @abstract Set the device associated with a buffer. | |
520 | * @discussion A buffer's device is set in buf_strategy() (or in buf_getblk() if the file is a device). | |
521 | * It is also set on an iobuf if buf_alloc() is passed a device vnode. | |
522 | * @param bp Buffer whose device ID to set. | |
523 | * @param vp Device to set on the buffer. | |
524 | * @return 0 for success, EINVAL if vp is not a device file. | |
91447636 | 525 | */ |
0a7de745 | 526 | errno_t buf_setdevice(buf_t bp, vnode_t vp); |
91447636 | 527 | |
b0d623f7 | 528 | /*! |
0a7de745 A |
529 | * @function buf_strategy |
530 | * @abstract Pass an I/O request for a buffer down to the device layer. | |
531 | * @discussion This is one of the most important routines in the buffer cache layer. For buffers obtained | |
532 | * through buf_getblk, it handles finding physical block numbers for the I/O (with VNOP_BLKTOOFF and | |
533 | * VNOP_BLOCKMAP), packaging the I/O into page-sized chunks, and initiating I/O on the disk by calling | |
534 | * the device's strategy routine. If a buffer's UPL has been set manually with buf_setupl(), it assumes | |
535 | * that the request is already correctly configured with a block number and a size divisible by page size | |
536 | * and will just call directly to the device. | |
537 | * @param devvp Device on which to perform I/O | |
538 | * @param ap vnop_strategy_args structure (most importantly, a buffer). | |
539 | * @return 0 for success, or errors from filesystem or device layers. | |
b0d623f7 | 540 | */ |
0a7de745 | 541 | errno_t buf_strategy(vnode_t devvp, void *ap); |
91447636 | 542 | |
0a7de745 A |
543 | /* |
544 | * Flags for buf_invalblkno() | |
545 | */ | |
546 | #define BUF_WAIT 0x01 | |
547 | ||
548 | /*! | |
549 | * @function buf_invalblkno | |
550 | * @abstract Invalidate a filesystem logical block in a file. | |
551 | * @discussion buf_invalblkno() tries to make the data for a given block in a file | |
552 | * invalid; if the buffer for that block is found in core and is not busy, we mark it | |
553 | * invalid and call buf_brelse() (see "flags" param for what happens if the buffer is busy). | |
554 | * buf_brelse(), noticing that it is invalid, will | |
555 | * will return the buffer to the empty-buffer list and tell the VM subsystem to abandon | |
556 | * the relevant pages. Data will not be written to backing store--it will be cast aside. | |
557 | * Note that this function will only work if the block in question has been | |
558 | * obtained with a buf_getblk(). If data has been read into core without using | |
559 | * traditional buffer cache routines, buf_invalblkno() will not be able to invalidate it--this | |
560 | * includes the use of iobufs. | |
561 | * @param vp vnode whose block to invalidate. | |
562 | * @param lblkno Logical block number. | |
563 | * @param flags BUF_WAIT: wait for busy buffers to become unbusy and invalidate them then. Otherwise, | |
564 | * just return EBUSY for busy blocks. | |
565 | * @return 0 for success, EINVAL if vp is not a device file. | |
566 | */ | |
567 | errno_t buf_invalblkno(vnode_t vp, daddr64_t lblkno, int flags); | |
568 | ||
569 | /*! | |
570 | * @function buf_callback | |
571 | * @abstract Get the function set to be called when I/O on a buffer completes. | |
572 | * @discussion A function returned by buf_callback was originally set with buf_setcallback(). | |
573 | * @param bp Buffer whose callback to get. | |
574 | * @return 0 for success, or errors from filesystem or device layers. | |
91447636 | 575 | */ |
39037602 | 576 | void * buf_callback(buf_t bp); |
91447636 | 577 | |
b0d623f7 | 578 | /*! |
0a7de745 A |
579 | * @function buf_setcallback |
580 | * @abstract Set a function to be called once when I/O on a buffer completes. | |
581 | * @discussion A one-shot callout set with buf_setcallback() will be called from buf_biodone() | |
582 | * when I/O completes. It will be passed the "transaction" argument as well as the buffer. | |
583 | * buf_setcallback() also marks the buffer as B_ASYNC. | |
584 | * @param bp Buffer whose callback to set. | |
585 | * @param callback function to use as callback. | |
586 | * @param transaction Additional argument to callback function. | |
587 | * @return 0; always succeeds. | |
91447636 | 588 | */ |
0a7de745 | 589 | errno_t buf_setcallback(buf_t bp, void (*callback)(buf_t, void *), void *transaction); |
91447636 | 590 | |
b0d623f7 | 591 | /*! |
0a7de745 A |
592 | * @function buf_setupl |
593 | * @abstract Set the UPL (Universal Page List), and offset therein, on a buffer. | |
594 | * @discussion buf_setupl() should only be called on buffers allocated with buf_alloc(). | |
595 | * A subsequent call to buf_map() will map the UPL and give back the address at which data | |
596 | * begins. After buf_setupl() is called, a buffer is marked B_CLUSTER; when this is the case, | |
597 | * buf_strategy() assumes that a buffer is correctly configured to be passed to the device | |
598 | * layer without modification. Passing a NULL upl will clear the upl and the B_CLUSTER flag on the | |
599 | * buffer. | |
600 | * @param bp Buffer whose upl to set. | |
601 | * @param upl UPL to set in the buffer. | |
602 | * @param offset Offset within upl at which relevant data begin. | |
603 | * @return 0 for success, EINVAL if the buffer was not allocated with buf_alloc(). | |
91447636 | 604 | */ |
0a7de745 | 605 | errno_t buf_setupl(buf_t bp, upl_t upl, uint32_t offset); |
91447636 | 606 | |
b0d623f7 | 607 | /*! |
0a7de745 A |
608 | * @function buf_clone |
609 | * @abstract Clone a buffer with a restricted range and an optional callback. | |
610 | * @discussion Generates a buffer which is identical to its "bp" argument except that | |
611 | * it spans a subset of the data of the original. The buffer to be cloned should | |
612 | * have been allocated with buf_alloc(). Checks its arguments to make sure | |
613 | * that the data subset is coherent. Optionally, adds a callback function and argument to it | |
614 | * to be called when I/O completes (as with buf_setcallback(), but B_ASYNC is not set). If the original buffer had | |
615 | * a upl set through buf_setupl(), this upl is copied to the new buffer; otherwise, the original's | |
616 | * data pointer is used raw. The buffer must be released with buf_free(). | |
617 | * @param bp Buffer to clone. | |
618 | * @param io_offset Offset, relative to start of data in original buffer, at which new buffer's data will begin. | |
619 | * @param io_size Size of buffer region in new buffer, in the sense of buf_count(). | |
620 | * @param iodone Callback to be called from buf_biodone() when I/O completes, in the sense of buf_setcallback(). | |
621 | * @param arg Argument to pass to iodone() callback. | |
622 | * @return NULL if io_offset/io_size combination is invalid for the buffer to be cloned; otherwise, the new buffer. | |
91447636 | 623 | */ |
0a7de745 | 624 | buf_t buf_clone(buf_t bp, int io_offset, int io_size, void (*iodone)(buf_t, void *), void *arg); |
91447636 | 625 | |
6d2010ae A |
626 | |
627 | /*! | |
0a7de745 A |
628 | * @function buf_create_shadow |
629 | * @abstract Create a shadow buffer with optional private storage and an optional callback. | |
630 | * @param bp Buffer to shadow. | |
631 | * @param force_copy If TRUE, do not link the shadaow to 'bp' and if 'external_storage' == NULL, | |
632 | * force a copy of the data associated with 'bp'. | |
633 | * @param external_storage If non-NULL, associate it with the new buffer as its storage instead of the | |
634 | * storage currently associated with 'bp'. | |
635 | * @param iodone Callback to be called from buf_biodone() when I/O completes, in the sense of buf_setcallback(). | |
636 | * @param arg Argument to pass to iodone() callback. | |
637 | * @return NULL if the buffer to be shadowed is not B_META or a primary buffer (i.e. not a shadow buffer); otherwise, the new buffer. | |
638 | */ | |
6d2010ae | 639 | |
0a7de745 | 640 | buf_t buf_create_shadow(buf_t bp, boolean_t force_copy, uintptr_t external_storage, void (*iodone)(buf_t, void *), void *arg); |
6d2010ae A |
641 | |
642 | ||
643 | /*! | |
0a7de745 A |
644 | * @function buf_shadow |
645 | * @abstract returns true if 'bp' is a shadow of another buffer. | |
646 | * @param bp Buffer to query. | |
647 | * @return 1 if 'bp' is a shadow, 0 otherwise. | |
648 | */ | |
649 | int buf_shadow(buf_t bp); | |
6d2010ae A |
650 | |
651 | ||
b0d623f7 | 652 | /*! |
0a7de745 A |
653 | * @function buf_alloc |
654 | * @abstract Allocate an uninitialized buffer. | |
655 | * @discussion A buffer returned by buf_alloc() is marked as busy and as an iobuf; it has no storage set up and must be | |
656 | * set up using buf_setdataptr() or buf_setupl()/buf_map(). | |
657 | * @param vp vnode to associate with the buffer: optionally NULL. If vp is a device file, then | |
658 | * the buffer's associated device will be set. If vp is NULL, it can be set later with buf_setvnode(). | |
659 | * @return New buffer. | |
91447636 | 660 | */ |
0a7de745 | 661 | buf_t buf_alloc(vnode_t vp); |
91447636 | 662 | |
b0d623f7 | 663 | /*! |
0a7de745 A |
664 | * @function buf_free |
665 | * @abstract Free a buffer that was allocated with buf_alloc(). | |
666 | * @discussion The storage (UPL, data pointer) associated with an iobuf must be freed manually. | |
667 | * @param bp The buffer to free. | |
91447636 | 668 | */ |
0a7de745 | 669 | void buf_free(buf_t bp); |
91447636 A |
670 | |
671 | /* | |
672 | * flags for buf_invalidateblks | |
673 | */ | |
0a7de745 A |
674 | #define BUF_WRITE_DATA 0x0001 /* write data blocks first */ |
675 | #define BUF_SKIP_META 0x0002 /* skip over metadata blocks */ | |
676 | #define BUF_INVALIDATE_LOCKED 0x0004 /* force B_LOCKED blocks to be invalidated */ | |
91447636 | 677 | |
b0d623f7 | 678 | /*! |
0a7de745 A |
679 | * @function buf_invalidateblks |
680 | * @abstract Invalidate all the blocks associated with a vnode. | |
681 | * @discussion This function does for all blocks associated with a vnode what buf_invalblkno does for one block. | |
682 | * Again, it will only be able to invalidate data which were populated with traditional buffer cache routines, | |
683 | * i.e. by buf_getblk() and callers thereof. Unlike buf_invalblkno(), it can be made to write dirty data to disk | |
684 | * rather than casting it aside. | |
685 | * @param vp The vnode whose data to invalidate. | |
686 | * @param flags BUF_WRITE_DATA: write dirty data to disk with VNOP_BWRITE() before kicking buffer cache entries out. | |
687 | * BUF_SKIP_META: do not invalidate metadata blocks. | |
688 | * @param slpflag Flags to pass to "msleep" while waiting to acquire busy buffers. | |
689 | * @param slptimeo Timeout in "hz" (1/100 second) to wait for a buffer to become unbusy before waking from sleep | |
690 | * and re-starting the scan. | |
691 | * @return 0 for success, error values from msleep(). | |
b0d623f7 | 692 | */ |
0a7de745 | 693 | int buf_invalidateblks(vnode_t vp, int flags, int slpflag, int slptimeo); |
b0d623f7 | 694 | |
91447636 A |
695 | /* |
696 | * flags for buf_flushdirtyblks and buf_iterate | |
697 | */ | |
0a7de745 A |
698 | #define BUF_SKIP_NONLOCKED 0x01 |
699 | #define BUF_SKIP_LOCKED 0x02 | |
700 | #define BUF_SCAN_CLEAN 0x04 /* scan the clean buffers */ | |
701 | #define BUF_SCAN_DIRTY 0x08 /* scan the dirty buffers */ | |
702 | #define BUF_NOTIFY_BUSY 0x10 /* notify the caller about the busy pages during the scan */ | |
703 | ||
704 | ||
705 | #define BUF_RETURNED 0 | |
706 | #define BUF_RETURNED_DONE 1 | |
707 | #define BUF_CLAIMED 2 | |
708 | #define BUF_CLAIMED_DONE 3 | |
709 | /*! | |
710 | * @function buf_flushdirtyblks | |
711 | * @abstract Write dirty file blocks to disk. | |
712 | * @param vp The vnode whose blocks to flush. | |
713 | * @param wait Wait for writes to complete before returning. | |
714 | * @param flags Can pass zero, meaning "flush all dirty buffers." | |
715 | * BUF_SKIP_NONLOCKED: Skip buffers which are not busy when we encounter them. | |
716 | * BUF_SKIP_LOCKED: Skip buffers which are busy when we encounter them. | |
717 | * @param msg String to pass to msleep(). | |
718 | */ | |
719 | void buf_flushdirtyblks(vnode_t vp, int wait, int flags, const char *msg); | |
720 | ||
721 | /*! | |
722 | * @function buf_iterate | |
723 | * @abstract Perform some operation on all buffers associated with a vnode. | |
724 | * @param vp The vnode whose buffers to scan. | |
725 | * @param callout Function to call on each buffer. Should return one of: | |
726 | * BUF_RETURNED: buf_iterate() should call buf_brelse() on the buffer. | |
727 | * BUF_RETURNED_DONE: buf_iterate() should call buf_brelse() on the buffer and then stop iterating. | |
728 | * BUF_CLAIMED: buf_iterate() should continue iterating (and not call buf_brelse()). | |
729 | * BUF_CLAIMED_DONE: buf_iterate() should stop iterating (and not call buf_brelse()). | |
730 | * @param flags | |
731 | * BUF_SKIP_NONLOCKED: Skip buffers which are not busy when we encounter them. BUF_SKIP_LOCKED: Skip buffers which are busy when we encounter them. | |
732 | * BUF_SCAN_CLEAN: Call out on clean buffers. | |
733 | * BUF_SCAN_DIRTY: Call out on dirty buffers. | |
734 | * BUF_NOTIFY_BUSY: If a buffer cannot be acquired, pass a NULL buffer to callout; otherwise, | |
735 | * that buffer will be silently skipped. | |
736 | * @param arg Argument to pass to callout in addition to buffer. | |
737 | */ | |
738 | void buf_iterate(vnode_t vp, int (*callout)(buf_t, void *), int flags, void *arg); | |
739 | ||
740 | /*! | |
741 | * @function buf_clear | |
742 | * @abstract Zero out the storage associated with a buffer. | |
743 | * @discussion Calls buf_map() to get the buffer's data address; for a B_CLUSTER | |
744 | * buffer (one which has had buf_setupl() called on it), it tries to map the buffer's | |
745 | * UPL into memory; should only be called once during the life cycle of an iobuf (one allocated | |
746 | * with buf_alloc()). | |
747 | * @param bp The buffer to zero out. | |
748 | */ | |
749 | void buf_clear(buf_t bp); | |
750 | ||
751 | /*! | |
752 | * @function buf_bawrite | |
753 | * @abstract Start an asychronous write on a buffer. | |
754 | * @discussion Calls VNOP_BWRITE to start the process of propagating an asynchronous write down to the device layer. | |
755 | * Callers can wait for writes to complete at their discretion using buf_biowait(). When this function is called, | |
756 | * data should already have been written to the buffer's data region. | |
757 | * @param bp The buffer on which to initiate I/O. | |
758 | * @return EWOULDBLOCK if write count is high and "throttle" is zero; otherwise, errors from VNOP_BWRITE. | |
759 | */ | |
760 | errno_t buf_bawrite(buf_t bp); | |
761 | ||
762 | /*! | |
763 | * @function buf_bdwrite | |
764 | * @abstract Mark a buffer for delayed write. | |
765 | * @discussion Marks a buffer as waiting for delayed write and the current I/O as complete; data will be written to backing store | |
766 | * before the buffer is reused, but it will not be queued for I/O immediately. Note that for buffers allocated | |
767 | * with buf_alloc(), there are no such guarantees; you must take care of your own flushing to disk. If | |
768 | * the number of delayed writes pending on the system is greater than an internal limit and the caller has not | |
769 | * requested otherwise [see return_error] , buf_bdwrite() will unilaterally launch an asynchronous I/O with buf_bawrite() to keep the pile of | |
770 | * delayed writes from getting too large. | |
771 | * @param bp The buffer to mark for delayed write. | |
772 | * @return EAGAIN for return_error != 0 case, 0 for succeess, errors from buf_bawrite. | |
773 | */ | |
774 | errno_t buf_bdwrite(buf_t bp); | |
775 | ||
776 | /*! | |
777 | * @function buf_bwrite | |
778 | * @abstract Write a buffer's data to backing store. | |
779 | * @discussion Once the data in a buffer has been modified, buf_bwrite() starts sending it to disk by calling | |
780 | * VNOP_STRATEGY. Unless B_ASYNC has been set on the buffer (by buf_setflags() or otherwise), data will have | |
781 | * been written to disk when buf_bwrite() returns. See Bach (p 56). | |
782 | * @param bp The buffer to write to disk. | |
783 | * @return 0 for success; errors from buf_biowait(). | |
784 | */ | |
785 | errno_t buf_bwrite(buf_t bp); | |
786 | ||
787 | /*! | |
788 | * @function buf_biodone | |
789 | * @abstract Mark an I/O as completed. | |
790 | * @discussion buf_biodone() should be called by whosoever decides that an I/O on a buffer is complete; for example, | |
791 | * IOStorageFamily. It clears the dirty flag on a buffer and signals on the vnode that a write has completed | |
792 | * with vnode_writedone(). If a callout or filter has been set on the buffer, that function is called. In the case | |
793 | * of a callout, that function is expected to take care of cleaning up and freeing the buffer. | |
794 | * Otherwise, if the buffer is marked B_ASYNC (e.g. it was passed to buf_bawrite()), then buf_biodone() | |
795 | * considers itself justified in calling buf_brelse() to return it to free lists--no one is waiting for it. Finally, | |
796 | * waiters on the bp (e.g. in buf_biowait()) are woken up. | |
797 | * @param bp The buffer to mark as done with I/O. | |
798 | */ | |
799 | void buf_biodone(buf_t bp); | |
800 | ||
801 | /*! | |
802 | * @function buf_biowait | |
803 | * @abstract Wait for I/O on a buffer to complete. | |
804 | * @discussion Waits for I/O on a buffer to finish, as marked by a buf_biodone() call. | |
805 | * @param bp The buffer to wait on. | |
806 | * @return 0 for a successful wait; nonzero the buffer has been marked as EINTR or had an error set on it. | |
807 | */ | |
808 | errno_t buf_biowait(buf_t bp); | |
809 | ||
810 | /*! | |
811 | * @function buf_brelse | |
812 | * @abstract Release any claim to a buffer, sending it back to free lists. | |
813 | * @discussion buf_brelse() cleans up buffer state and releases a buffer to the free lists. If the buffer | |
814 | * is not marked invalid and its pages are dirty (e.g. a delayed write was made), its data will be commited | |
815 | * to backing store. If it is marked invalid, its data will be discarded completely. | |
816 | * A valid, cacheable buffer will be put on a list and kept in the buffer hash so it | |
817 | * can be found again; otherwise, it will be dissociated from its vnode and treated as empty. Which list a valid | |
818 | * buffer is placed on depends on the use of buf_markaged(), whether it is metadata, and the B_LOCKED flag. A | |
819 | * B_LOCKED buffer will not be available for reuse by other files, though its data may be paged out. | |
820 | * Note that buf_brelse() is intended for use with traditionally allocated buffers. | |
821 | * @param bp The buffer to release. | |
822 | */ | |
823 | void buf_brelse(buf_t bp); | |
824 | ||
825 | /*! | |
826 | * @function buf_bread | |
827 | * @abstract Synchronously read a block of a file. | |
828 | * @discussion buf_bread() is the traditional way to read a single logical block of a file through the buffer cache. | |
829 | * It tries to find the buffer and corresponding page(s) in core, calls VNOP_STRATEGY if necessary to bring the data | |
830 | * into memory, and waits for I/O to complete. It should not be used to read blocks of greater than 4K (one VM page) | |
831 | * in size; use cluster routines for large reads. Indeed, the cluster layer is a more efficient choice for reading DATA | |
832 | * unless you need some finely-tuned semantics that it cannot provide. | |
833 | * @param vp The file from which to read. | |
834 | * @param blkno The logical (filesystem) block number to read. | |
835 | * @param size Size of block; do not use for sizes > 4K. | |
836 | * @param cred Credential to store and use for reading from disk if data are not already in core. | |
837 | * @param bpp Destination pointer for buffer. | |
838 | * @return 0 for success, or an error from buf_biowait(). | |
839 | */ | |
840 | errno_t buf_bread(vnode_t vp, daddr64_t blkno, int size, kauth_cred_t cred, buf_t *bpp); | |
841 | ||
842 | /*! | |
843 | * @function buf_breadn | |
844 | * @abstract Read a block from a file with read-ahead. | |
845 | * @discussion buf_breadn() reads one block synchronously in the style of buf_bread() and fires | |
846 | * off a specified set of asynchronous reads to improve the likelihood of future cache hits. | |
847 | * It should not be used to read blocks of greater than 4K (one VM page) in size; use cluster | |
848 | * routines for large reads. Indeed, the cluster layer is a more efficient choice for reading DATA | |
849 | * unless you need some finely-tuned semantics that it cannot provide. | |
850 | * @param vp The file from which to read. | |
851 | * @param blkno The logical (filesystem) block number to read synchronously. | |
852 | * @param size Size of block; do not use for sizes > 4K. | |
853 | * @param rablks Array of logical block numbers for asynchronous read-aheads. | |
854 | * @param rasizes Array of block sizes for asynchronous read-aheads, each index corresponding to same index in "rablks." | |
855 | * @param nrablks Number of entries in read-ahead arrays. | |
856 | * @param cred Credential to store and use for reading from disk if data are not already in core. | |
857 | * @param bpp Destination pointer for buffer. | |
858 | * @return 0 for success, or an error from buf_biowait(). | |
859 | */ | |
860 | errno_t buf_breadn(vnode_t vp, daddr64_t blkno, int size, daddr64_t *rablks, int *rasizes, int nrablks, kauth_cred_t cred, buf_t *bpp); | |
861 | ||
862 | /*! | |
863 | * @function buf_meta_bread | |
864 | * @abstract Synchronously read a metadata block of a file. | |
865 | * @discussion buf_meta_bread() is the traditional way to read a single logical block of a file through the buffer cache. | |
866 | * It tries to find the buffer and corresponding page(s) in core, calls VNOP_STRATEGY if necessary to bring the data | |
867 | * into memory, and waits for I/O to complete. It should not be used to read blocks of greater than 4K (one VM page) | |
868 | * in size; use cluster routines for large reads. Reading meta-data through the traditional buffer cache, unlike | |
869 | * reading data, is efficient and encouraged, especially if the blocks being read are significantly smaller than page size. | |
870 | * @param vp The file from which to read. | |
871 | * @param blkno The logical (filesystem) block number to read. | |
872 | * @param size Size of block; do not use for sizes > 4K. | |
873 | * @param cred Credential to store and use for reading from disk if data are not already in core. | |
874 | * @param bpp Destination pointer for buffer. | |
875 | * @return 0 for success, or an error from buf_biowait(). | |
876 | */ | |
877 | errno_t buf_meta_bread(vnode_t vp, daddr64_t blkno, int size, kauth_cred_t cred, buf_t *bpp); | |
878 | ||
879 | /*! | |
880 | * @function buf_meta_breadn | |
881 | * @abstract Read a metadata block from a file with read-ahead. | |
882 | * @discussion buf_meta_breadn() reads one block synchronously in the style of buf_meta_bread() and fires | |
883 | * off a specified set of asynchronous reads to improve the likelihood of future cache hits. | |
884 | * It should not be used to read blocks of greater than 4K (one VM page) in size; use cluster | |
885 | * routines for large reads. | |
886 | * @param vp The file from which to read. | |
887 | * @param blkno The logical (filesystem) block number to read synchronously. | |
888 | * @param size Size of block; do not use for sizes > 4K. | |
889 | * @param rablks Array of logical block numbers for asynchronous read-aheads. | |
890 | * @param rasizes Array of block sizes for asynchronous read-aheads, each index corresponding to same index in "rablks." | |
891 | * @param nrablks Number of entries in read-ahead arrays. | |
892 | * @param cred Credential to store and use for reading from disk if data are not already in core. | |
893 | * @param bpp Destination pointer for buffer. | |
894 | * @return 0 for success, or an error from buf_biowait(). | |
895 | */ | |
896 | errno_t buf_meta_breadn(vnode_t vp, daddr64_t blkno, int size, daddr64_t *rablks, int *rasizes, int nrablks, kauth_cred_t cred, buf_t *bpp); | |
897 | ||
898 | /*! | |
899 | * @function minphys | |
900 | * @abstract Adjust a buffer's count to be no more than maximum physical I/O transfer size for the host architecture. | |
901 | * @discussion physio() takes as a parameter a function to bound transfer sizes for each VNOP_STRATEGY() call. minphys() | |
902 | * is a default implementation. It calls buf_setcount() to make the buffer's count the min() of its current count | |
903 | * and the max I/O size for the host architecture. | |
904 | * @param bp The buffer whose byte count to modify. | |
905 | * @return New byte count. | |
906 | */ | |
907 | u_int minphys(buf_t bp); | |
908 | ||
909 | /*! | |
910 | * @function physio | |
911 | * @abstract Perform I/O on a device to/from target memory described by a uio. | |
912 | * @discussion physio() allows I/O directly from a device to user-space memory. It waits | |
913 | * for all I/O to complete before returning. | |
914 | * @param f_strategy Strategy routine to call to initiate I/O. | |
915 | * @param bp Buffer to configure and pass to strategy routine; can be NULL. | |
916 | * @param dev Device on which to perform I/O. | |
917 | * @param flags B_READ or B_WRITE. | |
918 | * @param f_minphys Function which calls buf_setcount() to set a byte count which is suitably | |
919 | * small for the device in question. Returns byte count that has been set (or unchanged) on the buffer. | |
920 | * @param uio UIO describing the I/O operation. | |
921 | * @param blocksize Logical block size for this vnode. | |
922 | * @return 0 for success; EFAULT for an invalid uio; errors from buf_biowait(). | |
923 | */ | |
924 | int physio(void (*f_strategy)(buf_t), buf_t bp, dev_t dev, int flags, u_int (*f_minphys)(buf_t), struct uio *uio, int blocksize); | |
91447636 A |
925 | |
926 | ||
927 | /* | |
928 | * Flags for operation type in getblk() | |
929 | */ | |
0a7de745 A |
930 | #define BLK_READ 0x01 /* buffer for read */ |
931 | #define BLK_WRITE 0x02 /* buffer for write */ | |
932 | #define BLK_META 0x10 /* buffer for metadata */ | |
91447636 A |
933 | /* |
934 | * modifier for above flags... if set, getblk will only return | |
935 | * a bp that is already valid... i.e. found in the cache | |
936 | */ | |
0a7de745 A |
937 | #define BLK_ONLYVALID 0x80000000 |
938 | ||
b0d623f7 | 939 | /*! |
0a7de745 A |
940 | * @function buf_getblk |
941 | * @abstract Traditional buffer cache routine to get a buffer corresponding to a logical block in a file. | |
942 | * @discussion buf_getblk() gets a buffer, not necessarily containing valid data, representing a block in a file. | |
943 | * A metadata buffer will be returned with its own zone-allocated storage, managed by the traditional buffer-cache | |
944 | * layer, whereas data buffers will be returned hooked into backing by the UBC (which in fact controls the caching of data). | |
945 | * buf_getblk() first looks for the buffer header in cache; if the buffer is in-core but busy, buf_getblk() will wait for it to become | |
946 | * unbusy, depending on the slpflag and slptimeo parameters. If the buffer is found unbusy and is a metadata buffer, | |
947 | * it must already contain valid data and will be returned directly; data buffers will have a UPL configured to | |
948 | * prepare for interaction with the underlying UBC. If the buffer is found in core, it will be marked as such | |
949 | * and buf_fromcache() will return truth. A buffer is allocated and initialized (but not filled with data) | |
950 | * if none is found in core. buf_bread(), buf_breadn(), buf_meta_bread(), and buf_meta_breadn() all | |
951 | * return buffers obtained with buf_getblk(). | |
952 | * @param vp File for which to get block. | |
953 | * @param blkno Logical block number. | |
954 | * @param size Size of block. | |
955 | * @param slpflag Flag to pass to msleep() while waiting for buffer to become unbusy. | |
956 | * @param slptimeo Time, in milliseconds, to wait for buffer to become unbusy. 0 means to wait indefinitely. | |
957 | * @param operation BLK_READ: want a read buffer. BLK_WRITE: want a write buffer. BLK_META: want a metadata buffer. BLK_ONLYVALID: | |
958 | * only return buffers which are found in core (do not allocate anew), and do not change buffer size. The last remark means | |
959 | * that if a given logical block is found in core with a different size than what is requested, the buffer size will not be modified. | |
960 | * @return Buffer found in core or newly allocated, either containing valid data or ready for I/O. | |
b0d623f7 | 961 | */ |
0a7de745 | 962 | buf_t buf_getblk(vnode_t vp, daddr64_t blkno, int size, int slpflag, int slptimeo, int operation); |
b0d623f7 A |
963 | |
964 | /*! | |
0a7de745 A |
965 | * @function buf_geteblk |
966 | * @abstract Get a metadata buffer which is marked invalid and not associated with any vnode. | |
967 | * @discussion A buffer is returned with zone-allocated storage of the specified size, marked B_META and invalid. | |
968 | * It has no vnode and is not visible in the buffer hash. | |
969 | * @param size Size of buffer. | |
970 | * @return Always returns a new buffer. | |
b0d623f7 | 971 | */ |
0a7de745 | 972 | buf_t buf_geteblk(int size); |
6d2010ae A |
973 | |
974 | /*! | |
0a7de745 A |
975 | * @function buf_clear_redundancy_flags |
976 | * @abstract Clear flags on a buffer. | |
977 | * @discussion buffer_redundancy_flags &= ~flags | |
978 | * @param bp Buffer whose flags to clear. | |
979 | * @param flags Flags to remove from buffer's mask | |
6d2010ae | 980 | */ |
0a7de745 | 981 | void buf_clear_redundancy_flags(buf_t bp, uint32_t flags); |
6d2010ae A |
982 | |
983 | /*! | |
0a7de745 A |
984 | * @function buf_redundancyflags |
985 | * @abstract Get redundancy flags set on a buffer. | |
986 | * @param bp Buffer whose redundancy flags to grab. | |
987 | * @return flags. | |
6d2010ae | 988 | */ |
0a7de745 | 989 | uint32_t buf_redundancy_flags(buf_t bp); |
6d2010ae A |
990 | |
991 | /*! | |
0a7de745 A |
992 | * @function buf_setredundancyflags |
993 | * @abstract Set redundancy flags on a buffer. | |
994 | * @discussion buffer_redundancy_flags |= flags | |
995 | * @param bp Buffer whose flags to set. | |
996 | * @param flags Flags to add to buffer's redundancy flags | |
6d2010ae | 997 | */ |
0a7de745 | 998 | void buf_set_redundancy_flags(buf_t bp, uint32_t flags); |
6d2010ae | 999 | |
7ddcb079 | 1000 | /*! |
0a7de745 A |
1001 | * @function buf_attr |
1002 | * @abstract Gets the attributes for this buf. | |
1003 | * @param bp Buffer whose attributes to get. | |
1004 | * @return bufattr_t. | |
7ddcb079 | 1005 | */ |
39037602 | 1006 | bufattr_t buf_attr(buf_t bp); |
7ddcb079 | 1007 | |
316670eb | 1008 | /*! |
0a7de745 A |
1009 | * @function buf_markstatic |
1010 | * @abstract Mark a buffer as being likely to contain static data. | |
1011 | * @param bp Buffer to mark. | |
316670eb | 1012 | */ |
0a7de745 | 1013 | void buf_markstatic(buf_t bp); |
316670eb A |
1014 | |
1015 | /*! | |
0a7de745 A |
1016 | * @function buf_static |
1017 | * @abstract Check if a buffer contains static data. | |
1018 | * @param bp Buffer to test. | |
1019 | * @return Nonzero if buffer has static data, 0 otherwise. | |
316670eb | 1020 | */ |
0a7de745 | 1021 | int buf_static(buf_t bp); |
316670eb | 1022 | |
cb323159 A |
1023 | /*! |
1024 | * @function bufattr_markiosched | |
1025 | * @abstract Mark a buffer as belonging to an io scheduled mount point | |
1026 | * @param bap Buffer attributes to mark. | |
1027 | * @discussion Marks the buffer so that spec_strategy() will know that it belongs to an io scheduled mount point | |
1028 | */ | |
1029 | void bufattr_markioscheduled(bufattr_t bap); | |
1030 | ||
1031 | /*! | |
1032 | * @function bufattr_iosched | |
1033 | * @abstract Check if a buffer is marked as io scheduled | |
1034 | * @param bap Buffer attributes to test. | |
1035 | * @return Nonzero if the buffer is marked io scheduled, 0 otherwise. | |
1036 | */ | |
1037 | int bufattr_ioscheduled(bufattr_t bap); | |
1038 | ||
b0d623f7 | 1039 | #ifdef KERNEL_PRIVATE |
0a7de745 | 1040 | void buf_setfilter(buf_t, void (*)(buf_t, void *), void *, void(**)(buf_t, void *), void **); |
6d2010ae | 1041 | |
fe8ab488 | 1042 | /* bufattr allocation/duplication/deallocation functions */ |
316670eb | 1043 | bufattr_t bufattr_alloc(void); |
0a7de745 | 1044 | bufattr_t bufattr_dup(bufattr_t bap); |
316670eb | 1045 | void bufattr_free(bufattr_t bap); |
d1ecb069 A |
1046 | |
1047 | /*! | |
0a7de745 A |
1048 | * @function bufattr_cpx |
1049 | * @abstract Returns a pointer to a cpx_t structure. | |
1050 | * @param bap Buffer Attribute whose cpx_t structure you wish to get. | |
1051 | * @return Returns a cpx_t structure, or NULL if not valid | |
316670eb | 1052 | */ |
39037602 | 1053 | struct cpx *bufattr_cpx(bufattr_t bap); |
3e170ce0 A |
1054 | |
1055 | /*! | |
0a7de745 A |
1056 | * @function bufattr_setcpx |
1057 | * @abstract Set the cp_ctx on a buffer attribute. | |
1058 | * @param bap Buffer Attribute that you wish to change | |
3e170ce0 | 1059 | */ |
39037602 | 1060 | void bufattr_setcpx(bufattr_t bap, struct cpx *cpx); |
316670eb A |
1061 | |
1062 | /*! | |
0a7de745 A |
1063 | * @function bufattr_cpoff |
1064 | * @abstract Gets the file offset on the buffer. | |
1065 | * @param bap Buffer Attribute whose file offset value is used | |
d1ecb069 | 1066 | */ |
39037602 | 1067 | uint64_t bufattr_cpoff(bufattr_t bap); |
316670eb | 1068 | |
316670eb | 1069 | /*! |
0a7de745 A |
1070 | * @function bufattr_setcpoff |
1071 | * @abstract Set the file offset for a content protected I/O on | |
1072 | * a buffer attribute. | |
1073 | * @param bap Buffer Attribute whose cp file offset has to be set | |
d1ecb069 | 1074 | */ |
39037602 | 1075 | void bufattr_setcpoff(bufattr_t bap, uint64_t); |
7ddcb079 A |
1076 | |
1077 | /*! | |
0a7de745 A |
1078 | * @function bufattr_rawencrypted |
1079 | * @abstract Check if a buffer contains raw encrypted data. | |
1080 | * @param bap Buffer attribute to test. | |
1081 | * @return Nonzero if buffer has raw encrypted data, 0 otherwise. | |
316670eb A |
1082 | */ |
1083 | int bufattr_rawencrypted(bufattr_t bap); | |
1084 | ||
39236c6e | 1085 | /*! |
0a7de745 A |
1086 | * @function bufattr_markgreedymode |
1087 | * @abstract Mark a buffer to use the greedy mode for writing. | |
1088 | * @param bap Buffer attributes to mark. | |
1089 | * @discussion Greedy Mode: request improved write performance from the underlying device at the expense of storage efficiency | |
39236c6e | 1090 | */ |
0a7de745 | 1091 | void bufattr_markgreedymode(bufattr_t bap); |
39236c6e A |
1092 | |
1093 | /*! | |
0a7de745 A |
1094 | * @function bufattr_greedymode |
1095 | * @abstract Check if a buffer is written using the Greedy Mode | |
1096 | * @param bap Buffer attributes to test. | |
1097 | * @discussion Greedy Mode: request improved write performance from the underlying device at the expense of storage efficiency | |
1098 | * @return Nonzero if buffer uses greedy mode, 0 otherwise. | |
39236c6e | 1099 | */ |
0a7de745 | 1100 | int bufattr_greedymode(bufattr_t bap); |
39236c6e | 1101 | |
fe8ab488 | 1102 | /*! |
0a7de745 A |
1103 | * @function bufattr_markisochronous |
1104 | * @abstract Mark a buffer to use the isochronous throughput mode for writing. | |
1105 | * @param bap Buffer attributes to mark. | |
1106 | * @discussion isochronous mode: request improved write performance from the underlying device at the expense of storage efficiency | |
fe8ab488 | 1107 | */ |
0a7de745 | 1108 | void bufattr_markisochronous(bufattr_t bap); |
fe8ab488 | 1109 | |
0a7de745 A |
1110 | /*! |
1111 | * @function bufattr_isochronous | |
1112 | * @abstract Check if a buffer is written using the isochronous | |
1113 | * @param bap Buffer attributes to test. | |
1114 | * @discussion isochronous mode: request improved write performance from the underlying device at the expense of storage efficiency | |
1115 | * @return Nonzero if buffer uses isochronous mode, 0 otherwise. | |
fe8ab488 | 1116 | */ |
0a7de745 | 1117 | int bufattr_isochronous(bufattr_t bap); |
fe8ab488 A |
1118 | |
1119 | ||
316670eb | 1120 | /*! |
0a7de745 A |
1121 | * @function bufattr_throttled |
1122 | * @abstract Check if a buffer is throttled. | |
1123 | * @param bap Buffer attribute to test. | |
1124 | * @return Nonzero if the buffer is throttled, 0 otherwise. | |
7ddcb079 A |
1125 | */ |
1126 | int bufattr_throttled(bufattr_t bap); | |
b0d623f7 | 1127 | |
fe8ab488 | 1128 | /*! |
0a7de745 A |
1129 | * @function bufattr_passive |
1130 | * @abstract Check if a buffer is marked passive. | |
1131 | * @param bap Buffer attribute to test. | |
1132 | * @return Nonzero if the buffer is marked passive, 0 otherwise. | |
fe8ab488 A |
1133 | */ |
1134 | int bufattr_passive(bufattr_t bap); | |
1135 | ||
316670eb | 1136 | /*! |
0a7de745 A |
1137 | * @function bufattr_nocache |
1138 | * @abstract Check if a buffer has nocache attribute. | |
1139 | * @param bap Buffer attribute to test. | |
1140 | * @return Nonzero if the buffer is not cached, 0 otherwise. | |
316670eb A |
1141 | */ |
1142 | int bufattr_nocache(bufattr_t bap); | |
1143 | ||
1144 | /*! | |
0a7de745 A |
1145 | * @function bufattr_meta |
1146 | * @abstract Check if a buffer has the bufattr meta attribute. | |
1147 | * @param bap Buffer attribute to test. | |
1148 | * @return Nonzero if the buffer has meta attribute, 0 otherwise. | |
316670eb A |
1149 | */ |
1150 | ||
1151 | int bufattr_meta(bufattr_t bap); | |
1152 | ||
fe8ab488 | 1153 | /*! |
0a7de745 A |
1154 | * @function bufattr_markmeta |
1155 | * @abstract Set the bufattr meta attribute. | |
1156 | * @param bap Buffer attribute to manipulate. | |
fe8ab488 A |
1157 | */ |
1158 | void bufattr_markmeta(bufattr_t bap); | |
1159 | ||
1160 | ||
316670eb | 1161 | /*! |
0a7de745 A |
1162 | * @function bufattr_delayidlesleep |
1163 | * @abstract Check if a buffer is marked to delay idle sleep on disk IO. | |
1164 | * @param bap Buffer attribute to test. | |
1165 | * @return Nonzero if the buffer is marked to delay idle sleep on disk IO, 0 otherwise. | |
316670eb A |
1166 | */ |
1167 | int bufattr_delayidlesleep(bufattr_t bap); | |
1168 | ||
39236c6e | 1169 | /*! |
0a7de745 A |
1170 | * @function buf_kernel_addrperm_addr |
1171 | * @abstract Obfuscate the buf pointers. | |
1172 | * @param addr Buf_t pointer. | |
1173 | * @return Obfuscated pointer if addr is non zero, 0 otherwise. | |
39236c6e A |
1174 | */ |
1175 | vm_offset_t buf_kernel_addrperm_addr(void * addr); | |
1176 | ||
1177 | /*! | |
0a7de745 A |
1178 | * @function bufattr_markquickcomplete |
1179 | * @abstract Mark a buffer to hint quick completion to the driver. | |
1180 | * @discussion This flag hints the storage driver that some thread is waiting for this I/O to complete. | |
1181 | * It should therefore attempt to complete it as soon as possible at the cost of device efficiency. | |
1182 | * @param bap Buffer attributes to mark. | |
39236c6e A |
1183 | */ |
1184 | void bufattr_markquickcomplete(bufattr_t bap); | |
1185 | ||
1186 | /*! | |
0a7de745 A |
1187 | * @function bufattr_quickcomplete |
1188 | * @abstract Check if a buffer is marked for quick completion | |
1189 | * @discussion This flag hints the storage driver that some thread is waiting for this I/O to complete. | |
1190 | * It should therefore attempt to complete it as soon as possible at the cost of device efficiency. | |
1191 | * @param bap Buffer attribute to test. | |
1192 | * @return Nonzero if the buffer is marked for quick completion, 0 otherwise. | |
39236c6e A |
1193 | */ |
1194 | int bufattr_quickcomplete(bufattr_t bap); | |
1195 | ||
0a7de745 | 1196 | int count_lock_queue(void); |
39037602 A |
1197 | |
1198 | /* | |
1199 | * Flags for buf_acquire | |
1200 | */ | |
0a7de745 A |
1201 | #define BAC_NOWAIT 0x01 /* Don't wait if buffer is busy */ |
1202 | #define BAC_REMOVE 0x02 /* Remove from free list once buffer is acquired */ | |
1203 | #define BAC_SKIP_NONLOCKED 0x04 /* Don't return LOCKED buffers */ | |
1204 | #define BAC_SKIP_LOCKED 0x08 /* Only return LOCKED buffers */ | |
39037602 | 1205 | |
0a7de745 | 1206 | errno_t buf_acquire(buf_t, int, int, int); |
39037602 | 1207 | |
0a7de745 | 1208 | buf_t buf_create_shadow_priv(buf_t bp, boolean_t force_copy, uintptr_t external_storage, void (*iodone)(buf_t, void *), void *arg); |
39037602 | 1209 | |
0a7de745 | 1210 | void buf_drop(buf_t); |
39037602 | 1211 | |
316670eb | 1212 | #endif /* KERNEL_PRIVATE */ |
91447636 A |
1213 | |
1214 | __END_DECLS | |
1215 | ||
1216 | ||
1217 | /* Macros to clear/set/test flags. */ | |
0a7de745 A |
1218 | #define SET(t, f) (t) |= (f) |
1219 | #define CLR(t, f) (t) &= ~(f) | |
1220 | #define ISSET(t, f) ((t) & (f)) | |
91447636 | 1221 | |
1c79356b | 1222 | |
1c79356b | 1223 | #endif /* !_SYS_BUF_H_ */ |