]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/buf.h
912d07a49a1bfbb9d90670988bd6b5bb92a5bfca
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1982, 1986, 1989, 1993
33 * The Regents of the University of California. All rights reserved.
34 * (c) UNIX System Laboratories, Inc.
35 * All or some portions of this file are derived from material licensed
36 * to the University of California by American Telephone and Telegraph
37 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
38 * the permission of UNIX System Laboratories, Inc.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)buf.h 8.9 (Berkeley) 3/30/95
74 #include <sys/cdefs.h>
75 #include <sys/kernel_types.h>
76 #include <mach/memory_object_types.h>
79 #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
80 #define B_READ 0x00000001 /* Read buffer. */
81 #define B_ASYNC 0x00000002 /* Start I/O, do not wait. */
82 #define B_NOCACHE 0x00000004 /* Do not cache block after use. */
83 #define B_DELWRI 0x00000008 /* Delay I/O until buffer reused. */
84 #define B_LOCKED 0x00000010 /* Locked in core (not reusable). */
85 #define B_PHYS 0x00000020 /* I/O to user memory. */
86 #define B_CLUSTER 0x00000040 /* UPL based I/O generated by cluster layer */
87 #define B_PAGEIO 0x00000080 /* Page in/out */
88 #define B_META 0x00000100 /* buffer contains meta-data. */
90 * make sure to check when adding flags that
91 * that the new flags don't overlap the definitions
98 * mark the buffer associated with buf_t
99 * as AGED with respect to the LRU cache
101 void buf_markaged(buf_t
);
104 * mark the buffer associated with buf_t
105 * as invalid... on release, it will go
106 * directly to the free list
108 void buf_markinvalid(buf_t
);
111 * mark the buffer assoicated with buf_t
112 * as a delayed write...
114 void buf_markdelayed(buf_t
);
117 * mark the buffer associated with buf_t
118 * as having been interrupted... EINTR
120 void buf_markeintr(buf_t
);
123 * returns 1 if the buffer associated with buf_t
124 * contains valid data... 0 if it does not
126 int buf_valid(buf_t
);
129 * returns 1 if the buffer was already valid
130 * in the cache... i.e. no I/O was performed
131 * returns 0 otherwise
133 int buf_fromcache(buf_t
);
136 * returns the UPL associated with buf_t
138 void * buf_upl(buf_t
);
141 * returns the offset into the UPL
142 * associated with buf_t which is to be
143 * used as the base offset for this I/O
145 uint32_t buf_uploffset(buf_t
);
148 * returns read credential associated with buf_t
149 * a reference is taken which must be explicilty dropped
151 ucred_t
buf_rcred(buf_t
);
154 * returns write credential associated with buf_t
155 * a reference is taken which must be explicilty dropped
157 ucred_t
buf_wcred(buf_t
);
160 * returns process handle associated with buf_t
161 * i.e identity of task that issued the I/O
163 proc_t
buf_proc(buf_t
);
165 uint32_t buf_dirtyoff(buf_t
);
166 uint32_t buf_dirtyend(buf_t
);
167 void buf_setdirtyoff(buf_t
, uint32_t);
168 void buf_setdirtyend(buf_t
, uint32_t);
171 * return the errno value associated with buf_t
173 errno_t
buf_error(buf_t
);
178 void buf_seterror(buf_t
, errno_t
);
181 * set specified flags on buf_t
182 * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO
184 void buf_setflags(buf_t
, int32_t);
187 * clear specified flags on buf_t
188 * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO
190 void buf_clearflags(buf_t
, int32_t);
193 * return external flags associated with buf_t
194 * B_CLUSTER/B_PHYS/B_LOCKED/B_DELWRI/B_ASYNC/B_READ/B_WRITE/B_META/B_PAGEIO
196 int32_t buf_flags(buf_t
);
199 * clears I/O related flags (both internal and
200 * external) associated with buf_t and allows
201 * the following to be set...
202 * B_READ/B_WRITE/B_ASYNC/B_NOCACHE
204 void buf_reset(buf_t
, int32_t);
207 * insure that the data storage associated with buf_t
210 errno_t
buf_map(buf_t
, caddr_t
*);
213 * release our need to have the storage associated
214 * with buf_t in an addressable state
216 errno_t
buf_unmap(buf_t
);
219 * set driver specific data for buf_t
221 void buf_setdrvdata(buf_t
, void *);
224 * retrieve driver specific data associated with buf_t
226 void * buf_drvdata(buf_t
);
229 * set fs specific data for buf_t
231 void buf_setfsprivate(buf_t
, void *);
234 * retrieve driver specific data associated with buf_t
236 void * buf_fsprivate(buf_t
);
239 * retrieve the phsyical block number associated with buf_t
241 daddr64_t
buf_blkno(buf_t
);
244 * retrieve the logical block number associated with buf_t
245 * i.e. the block number derived from the file offset
247 daddr64_t
buf_lblkno(buf_t
);
250 * set the phsyical block number associated with buf_t
252 void buf_setblkno(buf_t
, daddr64_t
);
255 * set the logical block number associated with buf_t
256 * i.e. the block number derived from the file offset
258 void buf_setlblkno(buf_t
, daddr64_t
);
261 * retrieve the count of valid bytes associated with buf_t
263 uint32_t buf_count(buf_t
);
266 * retrieve the size of the data store assoicated with buf_t
268 uint32_t buf_size(buf_t
);
271 * retrieve the residual I/O count assoicated with buf_t
272 * i.e. number of bytes that have not yet been completed
274 uint32_t buf_resid(buf_t
);
277 * set the count of bytes associated with buf_t
278 * typically used to set the size of the I/O to be performed
280 void buf_setcount(buf_t
, uint32_t);
283 * set the size of the buffer store associated with buf_t
284 * typically used when providing private storage to buf_t
286 void buf_setsize(buf_t
, uint32_t);
289 * set the size in bytes of the unfinished I/O associated with buf_t
291 void buf_setresid(buf_t
, uint32_t);
294 * associate kernel addressable storage with buf_t
296 void buf_setdataptr(buf_t
, uintptr_t);
299 * retrieve pointer to buffer associated with buf_t
300 * if non-null, than guaranteed to be kernel addressable
301 * size of buffer can be retrieved via buf_size
302 * size of valid data can be retrieved via buf_count
303 * if NULL, than use buf_map/buf_unmap to manage access to the underlying storage
305 uintptr_t buf_dataptr(buf_t
);
308 * return the vnode_t associated with buf_t
310 vnode_t
buf_vnode(buf_t
);
313 * assign vnode_t to buf_t... the
314 * device currently associated with
315 * but_t is not changed.
317 void buf_setvnode(buf_t
, vnode_t
);
320 * return the dev_t associated with buf_t
322 dev_t
buf_device(buf_t
);
325 * assign the dev_t associated with vnode_t
328 errno_t
buf_setdevice(buf_t
, vnode_t
);
330 errno_t
buf_strategy(vnode_t
, void *);
333 * flags for buf_invalblkno
335 #define BUF_WAIT 0x01
337 errno_t
buf_invalblkno(vnode_t
, daddr64_t
, int);
341 * return the callback function pointer
342 * if the callback is still valid
343 * returns NULL if a buffer that was not
344 * allocated via buf_alloc is specified
345 * or if a callback has not been set or
346 * it has already fired...
348 void * buf_callback(buf_t
);
351 * assign a one-shot callback function (driven from biodone)
352 * to a buf_t allocated via buf_alloc... a caller specified
353 * arg is passed to the callback function
355 errno_t
buf_setcallback(buf_t
, void (*)(buf_t
, void *), void *);
358 * add a upl_t to a buffer allocated via buf_alloc
359 * and set the offset into the upl_t (must be page
362 errno_t
buf_setupl(buf_t
, upl_t
, uint32_t);
365 * allocate a buf_t that is a clone of the buf_t
366 * passed in, but whose I/O range is a subset...
367 * if a callback routine is specified, it will
368 * be called from buf_biodone with the bp and
370 * it must be freed via buf_free
372 buf_t
buf_clone(buf_t
, int, int, void (*)(buf_t
, void *), void *);
375 * allocate a buf_t associated with vnode_t
376 * that has NO storage associated with it
377 * but is suitable for use in issuing I/Os
378 * after storage has been assigned via buf_setdataptr
381 buf_t
buf_alloc(vnode_t
);
384 * free a buf_t that was allocated via buf_alloc
385 * any private storage associated with buf_t is the
386 * responsiblity of the caller to release
388 void buf_free(buf_t
);
391 * flags for buf_invalidateblks
393 #define BUF_WRITE_DATA 0x0001 /* write data blocks first */
394 #define BUF_SKIP_META 0x0002 /* skip over metadata blocks */
396 int buf_invalidateblks(vnode_t
, int, int, int);
398 * flags for buf_flushdirtyblks and buf_iterate
400 #define BUF_SKIP_NONLOCKED 0x01
401 #define BUF_SKIP_LOCKED 0x02
403 void buf_flushdirtyblks(vnode_t
, int, int, char *);
404 void buf_iterate(vnode_t
, int (*)(buf_t
, void *), int, void *);
406 #define BUF_RETURNED 0
407 #define BUF_RETURNED_DONE 1
408 #define BUF_CLAIMED 2
409 #define BUF_CLAIMED_DONE 3
412 * zero the storage associated with buf_t
414 void buf_clear(buf_t
);
416 errno_t
buf_bawrite(buf_t
);
417 errno_t
buf_bdwrite(buf_t
);
418 errno_t
buf_bwrite(buf_t
);
420 void buf_biodone(buf_t
);
421 errno_t
buf_biowait(buf_t
);
422 void buf_brelse(buf_t
);
424 errno_t
buf_bread(vnode_t
, daddr64_t
, int, ucred_t
, buf_t
*);
425 errno_t
buf_breadn(vnode_t
, daddr64_t
, int, daddr64_t
*, int *, int, ucred_t
, buf_t
*);
426 errno_t
buf_meta_bread(vnode_t
, daddr64_t
, int, ucred_t
, buf_t
*);
427 errno_t
buf_meta_breadn(vnode_t
, daddr64_t
, int, daddr64_t
*, int *, int, ucred_t
, buf_t
*);
429 u_int
minphys(buf_t bp
);
430 int physio(void (*)(buf_t
), buf_t
, dev_t
, int , u_int (*)(buf_t
), struct uio
*, int );
434 * Flags for operation type in getblk()
436 #define BLK_READ 0x01 /* buffer for read */
437 #define BLK_WRITE 0x02 /* buffer for write */
438 #define BLK_META 0x10 /* buffer for metadata */
440 * modifier for above flags... if set, getblk will only return
441 * a bp that is already valid... i.e. found in the cache
443 #define BLK_ONLYVALID 0x80000000
445 /* timeout is in msecs */
446 buf_t
buf_getblk(vnode_t
, daddr64_t
, int, int, int, int);
447 buf_t
buf_geteblk(int);
452 /* Macros to clear/set/test flags. */
453 #define SET(t, f) (t) |= (f)
454 #define CLR(t, f) (t) &= ~(f)
455 #define ISSET(t, f) ((t) & (f))
458 #endif /* !_SYS_BUF_H_ */