]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/buf.h
xnu-2050.24.15.tar.gz
[apple/xnu.git] / bsd / sys / buf.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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.
8f6c56a5 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.
17 *
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.
8f6c56a5 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_
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
1c79356b 78#define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
91447636
A
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. */
2d21ac55
A
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 */
b0d623f7
A
91#define B_IOSTREAMING 0x00001000 /* sequential access pattern detected */
92#define B_THROTTLED_IO 0x00002000 /* low priority I/O */
6d2010ae 93#define B_ENCRYPTED_IO 0x00004000 /* Encrypted I/O */
316670eb
A
94#define B_STATICCONTENT 0x00008000 /* Buffer is likely to remain unaltered */
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
A
104/*!
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
A
108 */
109void buf_markaged(buf_t);
9bccf70c 110
b0d623f7
A
111/*!
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
A
115 */
116void buf_markinvalid(buf_t);
9bccf70c 117
b0d623f7
A
118/*!
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
A
124 */
125void buf_markdelayed(buf_t);
1c79356b 126
6d2010ae
A
127void buf_markclean(buf_t);
128
b0d623f7
A
129/*!
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 */
91447636 136void buf_markeintr(buf_t);
1c79356b 137
b0d623f7
A
138/*!
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
A
142 */
143void buf_markfua(buf_t);
144
b0d623f7
A
145/*!
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
A
150 */
151int buf_fua(buf_t);
152
b0d623f7
A
153/*!
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
A
158 */
159int buf_valid(buf_t);
1c79356b 160
b0d623f7
A
161/*!
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
A
168 */
169int buf_fromcache(buf_t);
170
b0d623f7
A
171/*!
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
A
178 */
179void * buf_upl(buf_t);
180
b0d623f7
A
181/*!
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
A
187 */
188uint32_t buf_uploffset(buf_t);
189
b0d623f7
A
190/*!
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.
197 */
198kauth_cred_t buf_rcred(buf_t);
199
200/*!
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.
207 */
208kauth_cred_t buf_wcred(buf_t);
209
210/*!
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 */
b0d623f7 218proc_t buf_proc(buf_t);
91447636 219
b0d623f7
A
220/*!
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 */
b0d623f7 227uint32_t buf_dirtyoff(buf_t);
91447636 228
b0d623f7
A
229/*!
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 */
91447636 237uint32_t buf_dirtyend(buf_t);
b0d623f7
A
238
239/*!
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.
244 @return void.
245 */
91447636 246void buf_setdirtyoff(buf_t, uint32_t);
b0d623f7
A
247
248/*!
249 @function buf_setdirtyend
250 @abstract Set the ending offset of the dirty region associated with a buffer.
251 @discussion If the buffer's data was found incore and dirty, the dirty end is the size of the block; otherwise, unless
252 someone outside of xnu explicitly changes it by calling buf_setdirtyend(), it will be zero.
253 @param bp Buffer whose dirty end to set.
254 @return void.
255 */
91447636
A
256void buf_setdirtyend(buf_t, uint32_t);
257
b0d623f7
A
258/*!
259 @function buf_error
260 @abstract Get the error value associated with a buffer.
261 @discussion Errors are set with buf_seterror().
262 @param bp Buffer whose error value to retrieve.
263 @return Error value, directly.
91447636
A
264 */
265errno_t buf_error(buf_t);
266
b0d623f7
A
267/*!
268 @function buf_seterror
269 @abstract Set an error value on a buffer.
270 @param bp Buffer whose error value to set.
271 @return void.
91447636
A
272 */
273void buf_seterror(buf_t, errno_t);
274
b0d623f7
A
275/*!
276 @function buf_setflags
277 @abstract Set flags on a buffer.
278 @discussion: buffer_flags |= flags
279 @param bp Buffer whose flags to set.
280 @param flags Flags to add to buffer's mask. B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA
281 @return void.
91447636
A
282 */
283void buf_setflags(buf_t, int32_t);
284
b0d623f7
A
285/*!
286 @function buf_clearflags
287 @abstract Clear flags on a buffer.
288 @discussion: buffer_flags &= ~flags
289 @param bp Buffer whose flags to clear.
290 @param flags Flags to remove from buffer's mask. B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA
291 @return void.
91447636
A
292 */
293void buf_clearflags(buf_t, int32_t);
294
b0d623f7
A
295/*!
296 @function buf_flags
297 @abstract Get flags set on a buffer.
298 @discussion Valid flags are B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO/B_FUA.
299 @param bp Buffer whose flags to grab.
300 @return flags.
91447636
A
301 */
302int32_t buf_flags(buf_t);
303
b0d623f7
A
304/*!
305 @function buf_reset
306 @abstract Reset I/O flag state on a buffer.
307 @discussion Clears current flags on a buffer (internal and external) and allows some new flags to be set.
308 Used perhaps to prepare an iobuf for reuse.
309 @param bp Buffer whose flags to grab.
310 @param flags Flags to set on buffer: B_READ, B_WRITE, B_ASYNC, B_NOCACHE.
311 @return void.
91447636
A
312 */
313void buf_reset(buf_t, int32_t);
314
b0d623f7
A
315/*!
316 @function buf_map
317 @abstract Get virtual mappings for buffer data.
318 @discussion For buffers created through buf_getblk() (i.e. traditional buffer cache usage),
319 buf_map() just returns the address at which data was mapped by but_getblk(). For a B_CLUSTER buffer, i.e. an iobuf
320 whose upl state is managed manually, there are two possibilities. If the buffer was created
321 with an underlying "real" buffer through cluster_bp(), the mapping of the "real" buffer is returned.
322 Otherwise, the buffer was created with buf_alloc() and buf_setupl() was subsequently called; buf_map()
323 will call ubc_upl_map() to get a mapping for the buffer's upl and return the start of that mapping
324 plus the buffer's upl offset (set in buf_setupl()). In the last case, buf_unmap() must later be called
325 to tear down the mapping. NOTE: buf_map() does not set the buffer data pointer; this must be done with buf_setdataptr().
326 @param bp Buffer whose mapping to find or create.
327 @param io_addr Destination for mapping address.
328 @return 0 for success, ENOMEM if unable to map the buffer.
91447636
A
329 */
330errno_t buf_map(buf_t, caddr_t *);
331
b0d623f7
A
332/*!
333 @function buf_unmap
334 @abstract Release mappings for buffer data.
335 @discussion For buffers created through buf_getblk() (i.e. traditional buffer cache usage),
336 buf_unmap() does nothing; buf_brelse() will take care of unmapping. For a B_CLUSTER buffer, i.e. an iobuf
337 whose upl state is managed manually, there are two possibilities. If the buffer was created
338 with an underlying "real" buffer through cluster_bp(), buf_unmap() does nothing; buf_brelse() on the
339 underlying buffer will tear down the mapping. Otherwise, the buffer was created with buf_alloc() and
340 buf_setupl() was subsequently called; buf_map() created the mapping. In this case, buf_unmap() will
341 unmap the buffer.
342 @param bp Buffer whose mapping to find or create.
343 @param io_addr Destination for mapping address.
344 @return 0 for success, EINVAL if unable to unmap buffer.
91447636
A
345 */
346errno_t buf_unmap(buf_t);
347
b0d623f7
A
348/*!
349 @function buf_setdrvdata
350 @abstract Set driver-specific data on a buffer.
351 @param bp Buffer whose driver-data to set.
352 @param drvdata Opaque driver data.
353 @return void.
91447636
A
354 */
355void buf_setdrvdata(buf_t, void *);
356
b0d623f7
A
357/*!
358 @function buf_setdrvdata
359 @abstract Get driver-specific data from a buffer.
360 @param bp Buffer whose driver data to get.
361 @return Opaque driver data.
91447636
A
362 */
363void * buf_drvdata(buf_t);
364
b0d623f7
A
365/*!
366 @function buf_setfsprivate
367 @abstract Set filesystem-specific data on a buffer.
368 @param bp Buffer whose filesystem data to set.
369 @param fsprivate Opaque filesystem data.
370 @return void.
91447636
A
371 */
372void buf_setfsprivate(buf_t, void *);
373
b0d623f7
A
374/*!
375 @function buf_fsprivate
376 @abstract Get filesystem-specific data from a buffer.
377 @param bp Buffer whose filesystem data to get.
378 @return Opaque filesystem data.
91447636
A
379 */
380void * buf_fsprivate(buf_t);
381
b0d623f7
A
382/*!
383 @function buf_blkno
384 @abstract Get physical block number associated with a buffer, in the sense of VNOP_BLOCKMAP.
385 @discussion When a buffer's physical block number is the same is its logical block number, then the physical
386 block number is considered uninitialized. A physical block number of -1 indicates that there is no valid
387 physical mapping (e.g. the logical block is invalid or corresponds to a sparse region in a file). Physical
388 block number is normally set by the cluster layer or by buf_getblk().
389 @param bp Buffer whose physical block number to get.
390 @return Block number.
91447636
A
391 */
392daddr64_t buf_blkno(buf_t);
393
b0d623f7
A
394/*!
395 @function buf_lblkno
396 @abstract Get logical block number associated with a buffer.
397 @discussion Logical block number is set on traditionally-used buffers by an argument passed to buf_getblk(),
398 for example by buf_bread().
399 @param bp Buffer whose logical block number to get.
400 @return Block number.
91447636
A
401 */
402daddr64_t buf_lblkno(buf_t);
403
b0d623f7
A
404/*!
405 @function buf_setblkno
406 @abstract Set physical block number associated with a buffer.
407 @discussion Physical block number is generally set by the cluster layer or by buf_getblk().
408 @param bp Buffer whose physical block number to set.
409 @param blkno Block number to set.
410 @return void.
91447636
A
411 */
412void buf_setblkno(buf_t, daddr64_t);
413
b0d623f7
A
414/*!
415 @function buf_setlblkno
416 @abstract Set logical block number associated with a buffer.
417 @discussion Logical block number is set on traditionally-used buffers by an argument passed to buf_getblk(),
418 for example by buf_bread().
419 @param bp Buffer whose logical block number to set.
420 @param lblkno Block number to set.
421 @return void.
91447636
A
422 */
423void buf_setlblkno(buf_t, daddr64_t);
424
b0d623f7
A
425/*!
426 @function buf_count
427 @abstract Get count of valid bytes in a buffer. This may be less than the space allocated to the buffer.
428 @param bp Buffer whose byte count to get.
429 @return Byte count.
91447636
A
430 */
431uint32_t buf_count(buf_t);
432
b0d623f7
A
433/*!
434 @function buf_size
435 @abstract Get size of data region allocated to a buffer.
436 @discussion May be larger than amount of valid data in buffer.
437 @param bp Buffer whose size to get.
438 @return Size.
91447636
A
439 */
440uint32_t buf_size(buf_t);
441
b0d623f7
A
442/*!
443 @function buf_resid
444 @abstract Get a count of bytes which were not consumed by an I/O on a buffer.
445 @discussion Set when an I/O operations completes.
446 @param bp Buffer whose outstanding count to get.
447 @return Count of unwritten/unread bytes.
91447636
A
448 */
449uint32_t buf_resid(buf_t);
450
b0d623f7
A
451/*!
452 @function buf_setcount
453 @abstract Set count of valid bytes in a buffer. This may be less than the space allocated to the buffer.
454 @param bp Buffer whose byte count to set.
455 @param bcount Count to set.
456 @return void.
91447636
A
457 */
458void buf_setcount(buf_t, uint32_t);
459
b0d623f7
A
460/*!
461 @function buf_setsize
462 @abstract Set size of data region allocated to a buffer.
463 @discussion May be larger than amount of valid data in buffer. Should be used by
464 code which is manually providing storage for an iobuf, one allocated with buf_alloc().
465 @param bp Buffer whose size to set.
466 @return void.
91447636
A
467 */
468void buf_setsize(buf_t, uint32_t);
469
b0d623f7
A
470/*!
471 @function buf_setresid
472 @abstract Set a count of bytes outstanding for I/O in a buffer.
473 @discussion Set when an I/O operations completes. Examples: called by IOStorageFamily when I/O
474 completes, often called on an "original" buffer when using a manipulated buffer to perform I/O
475 on behalf of the first.
476 @param bp Buffer whose outstanding count to set.
477 @return Count of unwritten/unread bytes.
91447636
A
478 */
479void buf_setresid(buf_t, uint32_t);
480
b0d623f7
A
481/*!
482 @function buf_setdataptr
483 @abstract Set the address at which a buffer's data will be stored.
484 @discussion In traditional buffer use, the data pointer will be set automatically. This routine is
485 useful with iobufs (allocated with buf_alloc()).
486 @param bp Buffer whose data pointer to set.
487 @param data Pointer to data region.
488 @return void.
91447636
A
489 */
490void buf_setdataptr(buf_t, uintptr_t);
491
b0d623f7
A
492/*!
493 @function buf_dataptr
494 @abstract Get the address at which a buffer's data is stored; for iobufs, this must
495 be set with buf_setdataptr(). See buf_map().
496 @param bp Buffer whose data pointer to retrieve.
497 @return Data pointer; NULL if unset.
91447636
A
498 */
499uintptr_t buf_dataptr(buf_t);
1c79356b 500
b0d623f7
A
501/*!
502 @function buf_vnode
503 @abstract Get the vnode associated with a buffer.
504 @discussion Every buffer is associated with a file. Because there is an I/O in flight,
505 there is an iocount on this vnode; it is returned WITHOUT an extra iocount, and vnode_put()
506 need NOT be called.
507 @param bp Buffer whose vnode to retrieve.
508 @return Buffer's vnode.
1c79356b 509 */
91447636
A
510vnode_t buf_vnode(buf_t);
511
b0d623f7
A
512/*!
513 @function buf_setvnode
514 @abstract Set the vnode associated with a buffer.
515 @discussion This call need not be used on traditional buffers; it is for use with iobufs.
516 @param bp Buffer whose vnode to set.
517 @param vp The vnode to attach to the buffer.
518 @return void.
91447636
A
519 */
520void buf_setvnode(buf_t, vnode_t);
521
b0d623f7
A
522/*!
523 @function buf_device
524 @abstract Get the device ID associated with a buffer.
525 @discussion In traditional buffer use, this value is NODEV until buf_strategy() is called unless
526 buf_getblk() was passed a device vnode. It is set on an iobuf if buf_alloc() is passed a device
527 vnode or if buf_setdevice() is called.
528 @param bp Buffer whose device ID to retrieve.
529 @return Device id.
91447636
A
530 */
531dev_t buf_device(buf_t);
532
b0d623f7
A
533/*!
534 @function buf_setdevice
535 @abstract Set the device associated with a buffer.
536 @discussion A buffer's device is set in buf_strategy() (or in buf_getblk() if the file is a device).
537 It is also set on an iobuf if buf_alloc() is passed a device vnode.
538 @param bp Buffer whose device ID to set.
539 @param vp Device to set on the buffer.
540 @return 0 for success, EINVAL if vp is not a device file.
91447636
A
541 */
542errno_t buf_setdevice(buf_t, vnode_t);
543
b0d623f7
A
544/*!
545 @function buf_strategy
546 @abstract Pass an I/O request for a buffer down to the device layer.
547 @discussion This is one of the most important routines in the buffer cache layer. For buffers obtained
548 through buf_getblk, it handles finding physical block numbers for the I/O (with VNOP_BLKTOOFF and
549 VNOP_BLOCKMAP), packaging the I/O into page-sized chunks, and initiating I/O on the disk by calling
550 the device's strategy routine. If a buffer's UPL has been set manually with buf_setupl(), it assumes
551 that the request is already correctly configured with a block number and a size divisible by page size
552 and will just call directly to the device.
553 @param devvp Device on which to perform I/O
554 @param ap vnop_strategy_args structure (most importantly, a buffer).
555 @return 0 for success, or errors from filesystem or device layers.
556 */
91447636
A
557errno_t buf_strategy(vnode_t, void *);
558
b0d623f7
A
559/*
560 * Flags for buf_invalblkno()
91447636
A
561 */
562#define BUF_WAIT 0x01
563
b0d623f7
A
564/*!
565 @function buf_invalblkno
566 @abstract Invalidate a filesystem logical block in a file.
567 @discussion buf_invalblkno() tries to make the data for a given block in a file
568 invalid; if the buffer for that block is found in core and is not busy, we mark it
569 invalid and call buf_brelse() (see "flags" param for what happens if the buffer is busy).
570 buf_brelse(), noticing that it is invalid, will
571 will return the buffer to the empty-buffer list and tell the VM subsystem to abandon
572 the relevant pages. Data will not be written to backing store--it will be cast aside.
573 Note that this function will only work if the block in question has been
574 obtained with a buf_getblk(). If data has been read into core without using
575 traditional buffer cache routines, buf_invalblkno() will not be able to invalidate it--this
576 includes the use of iobufs.
577 @param bp Buffer whose block to invalidate.
578 @param lblkno Logical block number.
579 @param flags BUF_WAIT: wait for busy buffers to become unbusy and invalidate them then. Otherwise,
580 just return EBUSY for busy blocks.
581 @return 0 for success, EINVAL if vp is not a device file.
582 */
91447636
A
583errno_t buf_invalblkno(vnode_t, daddr64_t, int);
584
b0d623f7
A
585/*!
586 @function buf_callback
587 @abstract Get the function set to be called when I/O on a buffer completes.
588 @discussion A function returned by buf_callback was originally set with buf_setcallback().
589 @param bp Buffer whose callback to get.
590 @return 0 for success, or errors from filesystem or device layers.
91447636
A
591 */
592void * buf_callback(buf_t);
593
b0d623f7
A
594/*!
595 @function buf_setcallback
596 @abstract Set a function to be called once when I/O on a buffer completes.
597 @discussion A one-shot callout set with buf_setcallback() will be called from buf_biodone()
598 when I/O completes. It will be passed the "transaction" argument as well as the buffer.
599 buf_setcallback() also marks the buffer as B_ASYNC.
600 @param bp Buffer whose callback to set.
601 @param callback function to use as callback.
602 @param transaction Additional argument to callback function.
603 @return 0; always succeeds.
91447636
A
604 */
605errno_t buf_setcallback(buf_t, void (*)(buf_t, void *), void *);
606
b0d623f7
A
607/*!
608 @function buf_setupl
609 @abstract Set the UPL (Universal Page List), and offset therein, on a buffer.
610 @discussion buf_setupl() should only be called on buffers allocated with buf_alloc().
611 A subsequent call to buf_map() will map the UPL and give back the address at which data
612 begins. After buf_setupl() is called, a buffer is marked B_CLUSTER; when this is the case,
613 buf_strategy() assumes that a buffer is correctly configured to be passed to the device
614 layer without modification. Passing a NULL upl will clear the upl and the B_CLUSTER flag on the
615 buffer.
616 @param bp Buffer whose upl to set.
617 @param upl UPL to set in the buffer.
618 @parma offset Offset within upl at which relevant data begin.
619 @return 0 for success, EINVAL if the buffer was not allocated with buf_alloc().
91447636
A
620 */
621errno_t buf_setupl(buf_t, upl_t, uint32_t);
622
b0d623f7
A
623/*!
624 @function buf_clone
625 @abstract Clone a buffer with a restricted range and an optional callback.
626 @discussion Generates a buffer which is identical to its "bp" argument except that
627 it spans a subset of the data of the original. The buffer to be cloned should
628 have been allocated with buf_alloc(). Checks its arguments to make sure
629 that the data subset is coherent. Optionally, adds a callback function and argument to it
630 to be called when I/O completes (as with buf_setcallback(), but B_ASYNC is not set). If the original buffer had
631 a upl set through buf_setupl(), this upl is copied to the new buffer; otherwise, the original's
632 data pointer is used raw. The buffer must be released with buf_free().
633 @param bp Buffer to clone.
634 @param io_offset Offset, relative to start of data in original buffer, at which new buffer's data will begin.
635 @param io_size Size of buffer region in new buffer, in the sense of buf_count().
636 @param iodone Callback to be called from buf_biodone() when I/O completes, in the sense of buf_setcallback().
637 @param arg Argument to pass to iodone() callback.
638 @return NULL if io_offset/io_size combination is invalid for the buffer to be cloned; otherwise, the new buffer.
91447636
A
639 */
640buf_t buf_clone(buf_t, int, int, void (*)(buf_t, void *), void *);
641
6d2010ae
A
642
643/*!
644 @function buf_create_shadow
645 @abstract Create a shadow buffer with optional private storage and an optional callback.
646 @param bp Buffer to shadow.
647 @param force_copy If TRUE, do not link the shadaow to 'bp' and if 'external_storage' == NULL,
648 force a copy of the data associated with 'bp'.
649 @param external_storage If non-NULL, associate it with the new buffer as its storage instead of the
650 storage currently associated with 'bp'.
651 @param iodone Callback to be called from buf_biodone() when I/O completes, in the sense of buf_setcallback().
652 @param arg Argument to pass to iodone() callback.
653 @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.
654*/
655
656buf_t buf_create_shadow(buf_t bp, boolean_t force_copy, uintptr_t external_storage, void (*iodone)(buf_t, void *), void *arg);
657
658
659/*!
660 @function buf_shadow
661 @abstract returns true if 'bp' is a shadow of another buffer.
662 @param bp Buffer to query.
663 @return 1 if 'bp' is a shadow, 0 otherwise.
664*/
665int buf_shadow(buf_t bp);
666
667
b0d623f7
A
668/*!
669 @function buf_alloc
670 @abstract Allocate an uninitialized buffer.
671 @discussion A buffer returned by buf_alloc() is marked as busy and as an iobuf; it has no storage set up and must be
672 set up using buf_setdataptr() or buf_setupl()/buf_map().
673 @param vp vnode to associate with the buffer: optionally NULL. If vp is a device file, then
674 the buffer's associated device will be set. If vp is NULL, it can be set later with buf_setvnode().
675 @return New buffer.
91447636
A
676 */
677buf_t buf_alloc(vnode_t);
678
b0d623f7
A
679/*!
680 @function buf_free
681 @abstract Free a buffer that was allocated with buf_alloc().
682 @discussion The storage (UPL, data pointer) associated with an iobuf must be freed manually.
683 @param bp The buffer to free.
684 @return void.
91447636
A
685 */
686void buf_free(buf_t);
687
688/*
689 * flags for buf_invalidateblks
690 */
691#define BUF_WRITE_DATA 0x0001 /* write data blocks first */
692#define BUF_SKIP_META 0x0002 /* skip over metadata blocks */
6d2010ae 693#define BUF_INVALIDATE_LOCKED 0x0004 /* force B_LOCKED blocks to be invalidated */
91447636 694
b0d623f7
A
695/*!
696 @function buf_invalidateblks
697 @abstract Invalidate all the blocks associated with a vnode.
698 @discussion This function does for all blocks associated with a vnode what buf_invalblkno does for one block.
699 Again, it will only be able to invalidate data which were populated with traditional buffer cache routines,
700 i.e. by buf_getblk() and callers thereof. Unlike buf_invalblkno(), it can be made to write dirty data to disk
701 rather than casting it aside.
702 @param bp The buffer whose data to invalidate.
703 @param flags BUF_WRITE_DATA: write dirty data to disk with VNOP_BWRITE() before kicking buffer cache entries out.
704 BUF_SKIP_META: do not invalidate metadata blocks.
705 @param slpflag Flags to pass to "msleep" while waiting to acquire busy buffers.
706 @param slptimeo Timeout in "hz" (1/100 second) to wait for a buffer to become unbusy before waking from sleep
707 and re-starting the scan.
708 @return 0 for success, error values from msleep().
709 */
91447636 710int buf_invalidateblks(vnode_t, int, int, int);
b0d623f7 711
91447636
A
712/*
713 * flags for buf_flushdirtyblks and buf_iterate
714 */
715#define BUF_SKIP_NONLOCKED 0x01
716#define BUF_SKIP_LOCKED 0x02
b0d623f7
A
717#define BUF_SCAN_CLEAN 0x04 /* scan the clean buffers */
718#define BUF_SCAN_DIRTY 0x08 /* scan the dirty buffers */
2d21ac55 719#define BUF_NOTIFY_BUSY 0x10 /* notify the caller about the busy pages during the scan */
91447636 720
91447636
A
721
722#define BUF_RETURNED 0
723#define BUF_RETURNED_DONE 1
724#define BUF_CLAIMED 2
725#define BUF_CLAIMED_DONE 3
b0d623f7
A
726/*!
727 @function buf_flushdirtyblks
728 @abstract Write dirty file blocks to disk.
729 @param vp The vnode whose blocks to flush.
730 @param wait Wait for writes to complete before returning.
731 @param flags Can pass zero, meaning "flush all dirty buffers."
732 BUF_SKIP_NONLOCKED: Skip buffers which are not busy when we encounter them.
733 BUF_SKIP_LOCKED: Skip buffers which are busy when we encounter them.
734 @param msg String to pass to msleep().
735 @return void.
736 */
737void buf_flushdirtyblks(vnode_t, int, int, const char *);
91447636 738
b0d623f7
A
739/*!
740 @function buf_iterate
741 @abstract Perform some operation on all buffers associated with a vnode.
742 @param vp The vnode whose buffers to scan.
743 @param callout Function to call on each buffer. Should return one of:
744 BUF_RETURNED: buf_iterate() should call buf_brelse() on the buffer.
745 BUF_RETURNED_DONE: buf_iterate() should call buf_brelse() on the buffer and then stop iterating.
746 BUF_CLAIMED: buf_iterate() should continue iterating (and not call buf_brelse()).
747 BUF_CLAIMED_DONE: buf_iterate() should stop iterating (and not call buf_brelse()).
748 @param flag
749 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.
750 BUF_SCAN_CLEAN: Call out on clean buffers.
751 BUF_SCAN_DIRTY: Call out on dirty buffers.
752 BUF_NOTIFY_BUSY: If a buffer cannot be acquired, pass a NULL buffer to callout; otherwise,
753 that buffer will be silently skipped.
754 @param arg Argument to pass to callout in addition to buffer.
755 @return void.
756 */
757void buf_iterate(vnode_t, int (*)(buf_t, void *), int, void *);
758
759/*!
760 @function buf_clear
761 @abstract Zero out the storage associated with a buffer.
762 @discussion Calls buf_map() to get the buffer's data address; for a B_CLUSTER
763 buffer (one which has had buf_setupl() called on it), it tries to map the buffer's
764 UPL into memory; should only be called once during the life cycle of an iobuf (one allocated
765 with buf_alloc()).
766 @param bp The buffer to zero out.
767 @return void.
91447636
A
768 */
769void buf_clear(buf_t);
770
b0d623f7
A
771/*!
772 @function buf_bawrite
773 @abstract Start an asychronous write on a buffer.
774 @discussion Calls VNOP_BWRITE to start the process of propagating an asynchronous write down to the device layer.
775 Callers can wait for writes to complete at their discretion using buf_biowait(). When this function is called,
776 data should already have been written to the buffer's data region.
777 @param bp The buffer on which to initiate I/O.
778 @param throttle If "throttle" is nonzero and more than VNODE_ASYNC_THROTTLE writes are in progress on this file,
779 buf_bawrite() will block until the write count drops below VNODE_ASYNC_THROTTLE. If "throttle" is zero and the write
780 count is high, it will fail with EWOULDBLOCK; the caller can decide whether to make a blocking call or pursue
781 other opportunities.
782 @return EWOULDBLOCK if write count is high and "throttle" is zero; otherwise, errors from VNOP_BWRITE.
783 */
91447636 784errno_t buf_bawrite(buf_t);
b0d623f7
A
785
786/*!
787 @function buf_bdwrite
788 @abstract Mark a buffer for delayed write.
789 @discussion Marks a buffer as waiting for delayed write and the current I/O as complete; data will be written to backing store
790 before the buffer is reused, but it will not be queued for I/O immediately. Note that for buffers allocated
791 with buf_alloc(), there are no such guarantees; you must take care of your own flushing to disk. If
792 the number of delayed writes pending on the system is greater than an internal limit and the caller has not
793 requested otherwise [see return_error] , buf_bdwrite() will unilaterally launch an asynchronous I/O with buf_bawrite() to keep the pile of
794 delayed writes from getting too large.
795 @param bp The buffer to mark for delayed write.
796 @param return_error If the number of pending delayed writes systemwide is larger than an internal limit,
797 return EAGAIN rather than doing an asynchronous write.
798 @return EAGAIN for return_error != 0 case, 0 for succeess, errors from buf_bawrite.
799 */
91447636 800errno_t buf_bdwrite(buf_t);
b0d623f7
A
801
802/*!
803 @function buf_bwrite
804 @abstract Write a buffer's data to backing store.
805 @discussion Once the data in a buffer has been modified, buf_bwrite() starts sending it to disk by calling
806 VNOP_STRATEGY. Unless B_ASYNC has been set on the buffer (by buf_setflags() or otherwise), data will have
807 been written to disk when buf_bwrite() returns. See Bach (p 56).
808 @param bp The buffer to write to disk.
809 @return 0 for success; errors from buf_biowait().
810 */
91447636
A
811errno_t buf_bwrite(buf_t);
812
b0d623f7
A
813/*!
814 @function buf_biodone
815 @abstract Mark an I/O as completed.
816 @discussion buf_biodone() should be called by whosoever decides that an I/O on a buffer is complete; for example,
817 IOStorageFamily. It clears the dirty flag on a buffer and signals on the vnode that a write has completed
818 with vnode_writedone(). If a callout or filter has been set on the buffer, that function is called. In the case
819 of a callout, that function is expected to take care of cleaning up and freeing the buffer.
820 Otherwise, if the buffer is marked B_ASYNC (e.g. it was passed to buf_bawrite()), then buf_biodone()
821 considers itself justified in calling buf_brelse() to return it to free lists--no one is waiting for it. Finally,
822 waiters on the bp (e.g. in buf_biowait()) are woken up.
823 @param bp The buffer to mark as done with I/O.
824 @return void.
825 */
91447636 826void buf_biodone(buf_t);
b0d623f7
A
827
828/*!
829 @function buf_biowait
830 @abstract Wait for I/O on a buffer to complete.
831 @discussion Waits for I/O on a buffer to finish, as marked by a buf_biodone() call.
832 @param bp The buffer to wait on.
833 @return 0 for a successful wait; nonzero the buffer has been marked as EINTR or had an error set on it.
834 */
91447636 835errno_t buf_biowait(buf_t);
91447636 836
b0d623f7
A
837/*!
838 @function buf_brelse
839 @abstract Release any claim to a buffer, sending it back to free lists.
840 @discussion buf_brelse() cleans up buffer state and releases a buffer to the free lists. If the buffer
841 is not marked invalid and its pages are dirty (e.g. a delayed write was made), its data will be commited
842 to backing store. If it is marked invalid, its data will be discarded completely.
843 A valid, cacheable buffer will be put on a list and kept in the buffer hash so it
844 can be found again; otherwise, it will be dissociated from its vnode and treated as empty. Which list a valid
845 buffer is placed on depends on the use of buf_markaged(), whether it is metadata, and the B_LOCKED flag. A
846 B_LOCKED buffer will not be available for reuse by other files, though its data may be paged out.
847 Note that buf_brelse() is intended for use with traditionally allocated buffers.
848 @param bp The buffer to release.
849 @retrn void.
850 */
851void buf_brelse(buf_t);
91447636 852
b0d623f7
A
853/*!
854 @function buf_bread
855 @abstract Synchronously read a block of a file.
856 @discussion buf_bread() is the traditional way to read a single logical block of a file through the buffer cache.
857 It tries to find the buffer and corresponding page(s) in core, calls VNOP_STRATEGY if necessary to bring the data
858 into memory, and waits for I/O to complete. It should not be used to read blocks of greater than 4K (one VM page)
859 in size; use cluster routines for large reads. Indeed, the cluster layer is a more efficient choice for reading DATA
860 unless you need some finely-tuned semantics that it cannot provide.
861 @param vp The file from which to read.
862 @param blkno The logical (filesystem) block number to read.
863 @param size Size of block; do not use for sizes > 4K.
864 @param cred Credential to store and use for reading from disk if data are not already in core.
865 @param bpp Destination pointer for buffer.
866 @return 0 for success, or an error from buf_biowait().
867 */
868errno_t buf_bread(vnode_t, daddr64_t, int, kauth_cred_t, buf_t *);
869
870/*!
871 @function buf_breadn
872 @abstract Read a block from a file with read-ahead.
873 @discussion buf_breadn() reads one block synchronously in the style of buf_bread() and fires
874 off a specified set of asynchronous reads to improve the likelihood of future cache hits.
875 It should not be used to read blocks of greater than 4K (one VM page) in size; use cluster
876 routines for large reads. Indeed, the cluster layer is a more efficient choice for reading DATA
877 unless you need some finely-tuned semantics that it cannot provide.
878 @param vp The file from which to read.
879 @param blkno The logical (filesystem) block number to read synchronously.
880 @param size Size of block; do not use for sizes > 4K.
881 @param rablks Array of logical block numbers for asynchronous read-aheads.
882 @param rasizes Array of block sizes for asynchronous read-aheads, each index corresponding to same index in "rablks."
883 @param nrablks Number of entries in read-ahead arrays.
884 @param cred Credential to store and use for reading from disk if data are not already in core.
885 @param bpp Destination pointer for buffer.
886 @return 0 for success, or an error from buf_biowait().
887 */
888errno_t buf_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, kauth_cred_t, buf_t *);
889
890/*!
891 @function buf_meta_bread
892 @abstract Synchronously read a metadata block of a file.
893 @discussion buf_meta_bread() is the traditional way to read a single logical block of a file through the buffer cache.
894 It tries to find the buffer and corresponding page(s) in core, calls VNOP_STRATEGY if necessary to bring the data
895 into memory, and waits for I/O to complete. It should not be used to read blocks of greater than 4K (one VM page)
896 in size; use cluster routines for large reads. Reading meta-data through the traditional buffer cache, unlike
897 reading data, is efficient and encouraged, especially if the blocks being read are significantly smaller than page size.
898 @param vp The file from which to read.
899 @param blkno The logical (filesystem) block number to read.
900 @param size Size of block; do not use for sizes > 4K.
901 @param cred Credential to store and use for reading from disk if data are not already in core.
902 @param bpp Destination pointer for buffer.
903 @return 0 for success, or an error from buf_biowait().
904 */
905errno_t buf_meta_bread(vnode_t, daddr64_t, int, kauth_cred_t, buf_t *);
906
907/*!
908 @function buf_meta_breadn
909 @abstract Read a metadata block from a file with read-ahead.
910 @discussion buf_meta_breadn() reads one block synchronously in the style of buf_meta_bread() and fires
911 off a specified set of asynchronous reads to improve the likelihood of future cache hits.
912 It should not be used to read blocks of greater than 4K (one VM page) in size; use cluster
913 routines for large reads.
914 @param vp The file from which to read.
915 @param blkno The logical (filesystem) block number to read synchronously.
916 @param size Size of block; do not use for sizes > 4K.
917 @param rablks Array of logical block numbers for asynchronous read-aheads.
918 @param rasizes Array of block sizes for asynchronous read-aheads, each index corresponding to same index in "rablks."
919 @param nrablks Number of entries in read-ahead arrays.
920 @param cred Credential to store and use for reading from disk if data are not already in core.
921 @param bpp Destination pointer for buffer.
922 @return 0 for success, or an error from buf_biowait().
923 */
924errno_t buf_meta_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, kauth_cred_t, buf_t *);
925
926/*!
927 @function minphys
928 @abstract Adjust a buffer's count to be no more than maximum physical I/O transfer size for the host architecture.
929 @discussion physio() takes as a parameter a function to bound transfer sizes for each VNOP_STRATEGY() call. minphys()
930 is a default implementation. It calls buf_setcount() to make the buffer's count the min() of its current count
931 and the max I/O size for the host architecture.
932 @param bp The buffer whose byte count to modify.
933 @return New byte count.
934 */
91447636 935u_int minphys(buf_t bp);
b0d623f7
A
936
937/*!
938 @function physio
939 @abstract Perform I/O on a device to/from target memory described by a uio.
940 @discussion physio() allows I/O directly from a device to user-space memory. It waits
941 for all I/O to complete before returning.
942 @param f_strategy Strategy routine to call to initiate I/O.
943 @param bp Buffer to configure and pass to strategy routine; can be NULL.
944 @param dev Device on which to perform I/O.
945 @param flags B_READ or B_WRITE.
946 @param f_minphys Function which calls buf_setcount() to set a byte count which is suitably
947 small for the device in question. Returns byte count that has been set (or unchanged) on the buffer.
948 @param uio UIO describing the I/O operation.
949 @param blocksize Logical block size for this vnode.
950 @return 0 for success; EFAULT for an invalid uio; errors from buf_biowait().
951 */
91447636
A
952int physio(void (*)(buf_t), buf_t, dev_t, int , u_int (*)(buf_t), struct uio *, int );
953
954
955/*
956 * Flags for operation type in getblk()
957 */
958#define BLK_READ 0x01 /* buffer for read */
959#define BLK_WRITE 0x02 /* buffer for write */
960#define BLK_META 0x10 /* buffer for metadata */
961/*
962 * modifier for above flags... if set, getblk will only return
963 * a bp that is already valid... i.e. found in the cache
964 */
965#define BLK_ONLYVALID 0x80000000
966
b0d623f7
A
967/*!
968 @function buf_getblk
969 @abstract Traditional buffer cache routine to get a buffer corresponding to a logical block in a file.
970 @discussion buf_getblk() gets a buffer, not necessarily containing valid data, representing a block in a file.
971 A metadata buffer will be returned with its own zone-allocated storage, managed by the traditional buffer-cache
972 layer, whereas data buffers will be returned hooked into backing by the UBC (which in fact controls the caching of data).
973 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
974 unbusy, depending on the slpflag and slptimeo parameters. If the buffer is found unbusy and is a metadata buffer,
975 it must already contain valid data and will be returned directly; data buffers will have a UPL configured to
976 prepare for interaction with the underlying UBC. If the buffer is found in core, it will be marked as such
977 and buf_fromcache() will return truth. A buffer is allocated and initialized (but not filled with data)
978 if none is found in core. buf_bread(), buf_breadn(), buf_meta_bread(), and buf_meta_breadn() all
979 return buffers obtained with buf_getblk().
980 @param vp File for which to get block.
981 @param blkno Logical block number.
982 @param size Size of block.
983 @param slpflag Flag to pass to msleep() while waiting for buffer to become unbusy.
984 @param slptimeo Time, in milliseconds, to wait for buffer to become unbusy. 0 means to wait indefinitely.
985 @param operation BLK_READ: want a read buffer. BLK_WRITE: want a write buffer. BLK_META: want a metadata buffer. BLK_ONLYVALID:
986 only return buffers which are found in core (do not allocate anew), and do not change buffer size. The last remark means
987 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.
988 @return Buffer found in core or newly allocated, either containing valid data or ready for I/O.
989 */
91447636 990buf_t buf_getblk(vnode_t, daddr64_t, int, int, int, int);
b0d623f7
A
991
992/*!
993 @function buf_geteblk
994 @abstract Get a metadata buffer which is marked invalid and not associated with any vnode.
995 @discussion A buffer is returned with zone-allocated storage of the specified size, marked B_META and invalid.
996 It has no vnode and is not visible in the buffer hash.
997 @param size Size of buffer.
998 @return Always returns a new buffer.
999 */
91447636 1000buf_t buf_geteblk(int);
6d2010ae
A
1001
1002/*!
1003 @function buf_clear_redundancy_flags
1004 @abstract Clear flags on a buffer.
1005 @discussion: buffer_redundancy_flags &= ~flags
1006 @param bp Buffer whose flags to clear.
1007 @param flags Flags to remove from buffer's mask
1008 @return void.
1009 */
1010void buf_clear_redundancy_flags(buf_t, uint32_t);
1011
1012/*!
1013 @function buf_redundancyflags
1014 @abstract Get redundancy flags set on a buffer.
1015 @param bp Buffer whose redundancy flags to grab.
1016 @return flags.
1017 */
1018uint32_t buf_redundancy_flags(buf_t);
1019
1020/*!
1021 @function buf_setredundancyflags
1022 @abstract Set redundancy flags on a buffer.
1023 @discussion: buffer_redundancy_flags |= flags
1024 @param bp Buffer whose flags to set.
1025 @param flags Flags to add to buffer's redundancy flags
1026 @return void.
1027 */
1028void buf_set_redundancy_flags(buf_t, uint32_t);
1029
7ddcb079
A
1030/*!
1031 @function buf_attr
1032 @abstract Gets the attributes for this buf.
1033 @param bp Buffer whose attributes to get.
1034 @return bufattr_t.
1035 */
1036bufattr_t buf_attr(buf_t);
1037
316670eb
A
1038/*!
1039 @function buf_markstatic
1040 @abstract Mark a buffer as being likely to contain static data.
1041 @param bp Buffer to mark.
1042 @return void.
1043 */
1044 void buf_markstatic(buf_t);
1045
1046/*!
1047 @function buf_static
1048 @abstract Check if a buffer contains static data.
1049 @param bp Buffer to test.
1050 @return Nonzero if buffer has static data, 0 otherwise.
1051 */
1052int buf_static(buf_t);
1053
b0d623f7 1054#ifdef KERNEL_PRIVATE
6d2010ae
A
1055void buf_setfilter(buf_t, void (*)(buf_t, void *), void *, void (**)(buf_t, void *), void **);
1056
316670eb
A
1057bufattr_t bufattr_alloc(void);
1058
1059void bufattr_free(bufattr_t bap);
d1ecb069
A
1060
1061/*!
316670eb
A
1062 @function bufattr_cpaddr
1063 @abstract Get the address of cp_entry on a buffer.
1064 @param bap Buffer Attribute whose cp_entry to get.
1065 @return int.
1066 */
1067void *bufattr_cpaddr(bufattr_t);
1068
1069/*!
1070 @function bufattr_cpoff
1071 @abstract Gets the file offset on the buffer.
1072 @param bap Buffer Attribute whose file offset value is used
d1ecb069
A
1073 @return void.
1074 */
316670eb
A
1075uint64_t bufattr_cpoff(bufattr_t);
1076
d1ecb069
A
1077
1078/*!
316670eb
A
1079 @function bufattr_setcpaddr
1080 @abstract Set the address of cp_entry on a buffer attribute.
1081 @param bap Buffer Attribute whose cp entry value has to be set
1082 @return void.
1083 */
1084void bufattr_setcpaddr(bufattr_t, void *);
1085
1086/*!
1087 @function bufattr_setcpoff
1088 @abstract Set the file offset for a content protected I/O on
1089 a buffer attribute.
1090 @param bap Buffer Attribute whose cp file offset has to be set
1091 @return void.
d1ecb069 1092 */
316670eb 1093void bufattr_setcpoff(bufattr_t, uint64_t);
7ddcb079
A
1094
1095/*!
316670eb
A
1096 @function bufattr_rawencrypted
1097 @abstract Check if a buffer contains raw encrypted data.
1098 @param bap Buffer attribute to test.
1099 @return Nonzero if buffer has raw encrypted data, 0 otherwise.
1100 */
1101int bufattr_rawencrypted(bufattr_t bap);
1102
1103/*!
1104 @function bufattr_throttled
7ddcb079
A
1105 @abstract Check if a buffer is throttled.
1106 @param bap Buffer attribute to test.
1107 @return Nonzero if the buffer is throttled, 0 otherwise.
1108 */
1109int bufattr_throttled(bufattr_t bap);
b0d623f7 1110
316670eb
A
1111/*!
1112 @function bufattr_nocache
1113 @abstract Check if a buffer has nocache attribute.
1114 @param bap Buffer attribute to test.
1115 @return Nonzero if the buffer is not cached, 0 otherwise.
1116 */
1117int bufattr_nocache(bufattr_t bap);
1118
1119/*!
1120 @function bufattr_meta
1121 @abstract Check if a buffer has meta attribute.
1122 @param bap Buffer attribute to test.
1123 @return Nonzero if the buffer has meta attribute, 0 otherwise.
1124 */
1125
1126int bufattr_meta(bufattr_t bap);
1127
1128/*!
1129 @function bufattr_delayidlesleep
1130 @abstract Check if a buffer is marked to delay idle sleep on disk IO.
1131 @param bap Buffer attribute to test.
1132 @return Nonzero if the buffer is marked to delay idle sleep on disk IO, 0 otherwise.
1133 */
1134int bufattr_delayidlesleep(bufattr_t bap);
1135
1136#endif /* KERNEL_PRIVATE */
91447636
A
1137
1138__END_DECLS
1139
1140
1141/* Macros to clear/set/test flags. */
1142#define SET(t, f) (t) |= (f)
1143#define CLR(t, f) (t) &= ~(f)
1144#define ISSET(t, f) ((t) & (f))
1145
1c79356b 1146
1c79356b 1147#endif /* !_SYS_BUF_H_ */