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