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