]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
14 | * | |
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 | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
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_ | |
71 | ||
72 | #include <sys/cdefs.h> | |
73 | #include <sys/kernel_types.h> | |
74 | #include <mach/memory_object_types.h> | |
75 | ||
76 | ||
77 | #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ | |
78 | #define B_READ 0x00000001 /* Read buffer. */ | |
79 | #define B_ASYNC 0x00000002 /* Start I/O, do not wait. */ | |
80 | #define B_NOCACHE 0x00000004 /* Do not cache block after use. */ | |
81 | #define B_DELWRI 0x00000008 /* Delay I/O until buffer reused. */ | |
82 | #define B_LOCKED 0x00000010 /* Locked in core (not reusable). */ | |
83 | #define B_PHYS 0x00000020 /* I/O to user memory. */ | |
84 | #define B_CLUSTER 0x00000040 /* UPL based I/O generated by cluster layer */ | |
85 | #define B_PAGEIO 0x00000080 /* Page in/out */ | |
86 | #define B_META 0x00000100 /* buffer contains meta-data. */ | |
87 | /* | |
88 | * make sure to check when adding flags that | |
89 | * that the new flags don't overlap the definitions | |
90 | * in buf_internal.h | |
91 | */ | |
92 | ||
93 | __BEGIN_DECLS | |
94 | ||
95 | /* | |
96 | * mark the buffer associated with buf_t | |
97 | * as AGED with respect to the LRU cache | |
98 | */ | |
99 | void buf_markaged(buf_t); | |
100 | ||
101 | /* | |
102 | * mark the buffer associated with buf_t | |
103 | * as invalid... on release, it will go | |
104 | * directly to the free list | |
105 | */ | |
106 | void buf_markinvalid(buf_t); | |
107 | ||
108 | /* | |
109 | * mark the buffer assoicated with buf_t | |
110 | * as a delayed write... | |
111 | */ | |
112 | void buf_markdelayed(buf_t); | |
113 | ||
114 | /* | |
115 | * mark the buffer associated with buf_t | |
116 | * as having been interrupted... EINTR | |
117 | */ | |
118 | void buf_markeintr(buf_t); | |
119 | ||
120 | /* | |
121 | * returns 1 if the buffer associated with buf_t | |
122 | * contains valid data... 0 if it does not | |
123 | */ | |
124 | int buf_valid(buf_t); | |
125 | ||
126 | /* | |
127 | * returns 1 if the buffer was already valid | |
128 | * in the cache... i.e. no I/O was performed | |
129 | * returns 0 otherwise | |
130 | */ | |
131 | int buf_fromcache(buf_t); | |
132 | ||
133 | /* | |
134 | * returns the UPL associated with buf_t | |
135 | */ | |
136 | void * buf_upl(buf_t); | |
137 | ||
138 | /* | |
139 | * returns the offset into the UPL | |
140 | * associated with buf_t which is to be | |
141 | * used as the base offset for this I/O | |
142 | */ | |
143 | uint32_t buf_uploffset(buf_t); | |
144 | ||
145 | /* | |
146 | * returns read credential associated with buf_t | |
147 | * a reference is taken which must be explicilty dropped | |
148 | */ | |
149 | ucred_t buf_rcred(buf_t); | |
150 | ||
151 | /* | |
152 | * returns write credential associated with buf_t | |
153 | * a reference is taken which must be explicilty dropped | |
154 | */ | |
155 | ucred_t buf_wcred(buf_t); | |
156 | ||
157 | /* | |
158 | * returns process handle associated with buf_t | |
159 | * i.e identity of task that issued the I/O | |
160 | */ | |
161 | proc_t buf_proc(buf_t); | |
162 | ||
163 | uint32_t buf_dirtyoff(buf_t); | |
164 | uint32_t buf_dirtyend(buf_t); | |
165 | void buf_setdirtyoff(buf_t, uint32_t); | |
166 | void buf_setdirtyend(buf_t, uint32_t); | |
167 | ||
168 | /* | |
169 | * return the errno value associated with buf_t | |
170 | */ | |
171 | errno_t buf_error(buf_t); | |
172 | ||
173 | /* | |
174 | * set errno on buf_t | |
175 | */ | |
176 | void buf_seterror(buf_t, errno_t); | |
177 | ||
178 | /* | |
179 | * set specified flags on buf_t | |
180 | * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO | |
181 | */ | |
182 | void buf_setflags(buf_t, int32_t); | |
183 | ||
184 | /* | |
185 | * clear specified flags on buf_t | |
186 | * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO | |
187 | */ | |
188 | void buf_clearflags(buf_t, int32_t); | |
189 | ||
190 | /* | |
191 | * return external flags associated with buf_t | |
192 | * B_CLUSTER/B_PHYS/B_LOCKED/B_DELWRI/B_ASYNC/B_READ/B_WRITE/B_META/B_PAGEIO | |
193 | */ | |
194 | int32_t buf_flags(buf_t); | |
195 | ||
196 | /* | |
197 | * clears I/O related flags (both internal and | |
198 | * external) associated with buf_t and allows | |
199 | * the following to be set... | |
200 | * B_READ/B_WRITE/B_ASYNC/B_NOCACHE | |
201 | */ | |
202 | void buf_reset(buf_t, int32_t); | |
203 | ||
204 | /* | |
205 | * insure that the data storage associated with buf_t | |
206 | * is addressable | |
207 | */ | |
208 | errno_t buf_map(buf_t, caddr_t *); | |
209 | ||
210 | /* | |
211 | * release our need to have the storage associated | |
212 | * with buf_t in an addressable state | |
213 | */ | |
214 | errno_t buf_unmap(buf_t); | |
215 | ||
216 | /* | |
217 | * set driver specific data for buf_t | |
218 | */ | |
219 | void buf_setdrvdata(buf_t, void *); | |
220 | ||
221 | /* | |
222 | * retrieve driver specific data associated with buf_t | |
223 | */ | |
224 | void * buf_drvdata(buf_t); | |
225 | ||
226 | /* | |
227 | * set fs specific data for buf_t | |
228 | */ | |
229 | void buf_setfsprivate(buf_t, void *); | |
230 | ||
231 | /* | |
232 | * retrieve driver specific data associated with buf_t | |
233 | */ | |
234 | void * buf_fsprivate(buf_t); | |
235 | ||
236 | /* | |
237 | * retrieve the phsyical block number associated with buf_t | |
238 | */ | |
239 | daddr64_t buf_blkno(buf_t); | |
240 | ||
241 | /* | |
242 | * retrieve the logical block number associated with buf_t | |
243 | * i.e. the block number derived from the file offset | |
244 | */ | |
245 | daddr64_t buf_lblkno(buf_t); | |
246 | ||
247 | /* | |
248 | * set the phsyical block number associated with buf_t | |
249 | */ | |
250 | void buf_setblkno(buf_t, daddr64_t); | |
251 | ||
252 | /* | |
253 | * set the logical block number associated with buf_t | |
254 | * i.e. the block number derived from the file offset | |
255 | */ | |
256 | void buf_setlblkno(buf_t, daddr64_t); | |
257 | ||
258 | /* | |
259 | * retrieve the count of valid bytes associated with buf_t | |
260 | */ | |
261 | uint32_t buf_count(buf_t); | |
262 | ||
263 | /* | |
264 | * retrieve the size of the data store assoicated with buf_t | |
265 | */ | |
266 | uint32_t buf_size(buf_t); | |
267 | ||
268 | /* | |
269 | * retrieve the residual I/O count assoicated with buf_t | |
270 | * i.e. number of bytes that have not yet been completed | |
271 | */ | |
272 | uint32_t buf_resid(buf_t); | |
273 | ||
274 | /* | |
275 | * set the count of bytes associated with buf_t | |
276 | * typically used to set the size of the I/O to be performed | |
277 | */ | |
278 | void buf_setcount(buf_t, uint32_t); | |
279 | ||
280 | /* | |
281 | * set the size of the buffer store associated with buf_t | |
282 | * typically used when providing private storage to buf_t | |
283 | */ | |
284 | void buf_setsize(buf_t, uint32_t); | |
285 | ||
286 | /* | |
287 | * set the size in bytes of the unfinished I/O associated with buf_t | |
288 | */ | |
289 | void buf_setresid(buf_t, uint32_t); | |
290 | ||
291 | /* | |
292 | * associate kernel addressable storage with buf_t | |
293 | */ | |
294 | void buf_setdataptr(buf_t, uintptr_t); | |
295 | ||
296 | /* | |
297 | * retrieve pointer to buffer associated with buf_t | |
298 | * if non-null, than guaranteed to be kernel addressable | |
299 | * size of buffer can be retrieved via buf_size | |
300 | * size of valid data can be retrieved via buf_count | |
301 | * if NULL, than use buf_map/buf_unmap to manage access to the underlying storage | |
302 | */ | |
303 | uintptr_t buf_dataptr(buf_t); | |
304 | ||
305 | /* | |
306 | * return the vnode_t associated with buf_t | |
307 | */ | |
308 | vnode_t buf_vnode(buf_t); | |
309 | ||
310 | /* | |
311 | * assign vnode_t to buf_t... the | |
312 | * device currently associated with | |
313 | * but_t is not changed. | |
314 | */ | |
315 | void buf_setvnode(buf_t, vnode_t); | |
316 | ||
317 | /* | |
318 | * return the dev_t associated with buf_t | |
319 | */ | |
320 | dev_t buf_device(buf_t); | |
321 | ||
322 | /* | |
323 | * assign the dev_t associated with vnode_t | |
324 | * to buf_t | |
325 | */ | |
326 | errno_t buf_setdevice(buf_t, vnode_t); | |
327 | ||
328 | errno_t buf_strategy(vnode_t, void *); | |
329 | ||
330 | /* | |
331 | * flags for buf_invalblkno | |
332 | */ | |
333 | #define BUF_WAIT 0x01 | |
334 | ||
335 | errno_t buf_invalblkno(vnode_t, daddr64_t, int); | |
336 | ||
337 | ||
338 | /* | |
339 | * return the callback function pointer | |
340 | * if the callback is still valid | |
341 | * returns NULL if a buffer that was not | |
342 | * allocated via buf_alloc is specified | |
343 | * or if a callback has not been set or | |
344 | * it has already fired... | |
345 | */ | |
346 | void * buf_callback(buf_t); | |
347 | ||
348 | /* | |
349 | * assign a one-shot callback function (driven from biodone) | |
350 | * to a buf_t allocated via buf_alloc... a caller specified | |
351 | * arg is passed to the callback function | |
352 | */ | |
353 | errno_t buf_setcallback(buf_t, void (*)(buf_t, void *), void *); | |
354 | ||
355 | /* | |
356 | * add a upl_t to a buffer allocated via buf_alloc | |
357 | * and set the offset into the upl_t (must be page | |
358 | * aligned). | |
359 | */ | |
360 | errno_t buf_setupl(buf_t, upl_t, uint32_t); | |
361 | ||
362 | /* | |
363 | * allocate a buf_t that is a clone of the buf_t | |
364 | * passed in, but whose I/O range is a subset... | |
365 | * if a callback routine is specified, it will | |
366 | * be called from buf_biodone with the bp and | |
367 | * arg specified. | |
368 | * it must be freed via buf_free | |
369 | */ | |
370 | buf_t buf_clone(buf_t, int, int, void (*)(buf_t, void *), void *); | |
371 | ||
372 | /* | |
373 | * allocate a buf_t associated with vnode_t | |
374 | * that has NO storage associated with it | |
375 | * but is suitable for use in issuing I/Os | |
376 | * after storage has been assigned via buf_setdataptr | |
377 | * or buf_addupl | |
378 | */ | |
379 | buf_t buf_alloc(vnode_t); | |
380 | ||
381 | /* | |
382 | * free a buf_t that was allocated via buf_alloc | |
383 | * any private storage associated with buf_t is the | |
384 | * responsiblity of the caller to release | |
385 | */ | |
386 | void buf_free(buf_t); | |
387 | ||
388 | /* | |
389 | * flags for buf_invalidateblks | |
390 | */ | |
391 | #define BUF_WRITE_DATA 0x0001 /* write data blocks first */ | |
392 | #define BUF_SKIP_META 0x0002 /* skip over metadata blocks */ | |
393 | ||
394 | int buf_invalidateblks(vnode_t, int, int, int); | |
395 | /* | |
396 | * flags for buf_flushdirtyblks and buf_iterate | |
397 | */ | |
398 | #define BUF_SKIP_NONLOCKED 0x01 | |
399 | #define BUF_SKIP_LOCKED 0x02 | |
400 | ||
401 | void buf_flushdirtyblks(vnode_t, int, int, char *); | |
402 | void buf_iterate(vnode_t, int (*)(buf_t, void *), int, void *); | |
403 | ||
404 | #define BUF_RETURNED 0 | |
405 | #define BUF_RETURNED_DONE 1 | |
406 | #define BUF_CLAIMED 2 | |
407 | #define BUF_CLAIMED_DONE 3 | |
408 | ||
409 | /* | |
410 | * zero the storage associated with buf_t | |
411 | */ | |
412 | void buf_clear(buf_t); | |
413 | ||
414 | errno_t buf_bawrite(buf_t); | |
415 | errno_t buf_bdwrite(buf_t); | |
416 | errno_t buf_bwrite(buf_t); | |
417 | ||
418 | void buf_biodone(buf_t); | |
419 | errno_t buf_biowait(buf_t); | |
420 | void buf_brelse(buf_t); | |
421 | ||
422 | errno_t buf_bread(vnode_t, daddr64_t, int, ucred_t, buf_t *); | |
423 | errno_t buf_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, ucred_t, buf_t *); | |
424 | errno_t buf_meta_bread(vnode_t, daddr64_t, int, ucred_t, buf_t *); | |
425 | errno_t buf_meta_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, ucred_t, buf_t *); | |
426 | ||
427 | u_int minphys(buf_t bp); | |
428 | int physio(void (*)(buf_t), buf_t, dev_t, int , u_int (*)(buf_t), struct uio *, int ); | |
429 | ||
430 | ||
431 | /* | |
432 | * Flags for operation type in getblk() | |
433 | */ | |
434 | #define BLK_READ 0x01 /* buffer for read */ | |
435 | #define BLK_WRITE 0x02 /* buffer for write */ | |
436 | #define BLK_META 0x10 /* buffer for metadata */ | |
437 | /* | |
438 | * modifier for above flags... if set, getblk will only return | |
439 | * a bp that is already valid... i.e. found in the cache | |
440 | */ | |
441 | #define BLK_ONLYVALID 0x80000000 | |
442 | ||
443 | /* timeout is in msecs */ | |
444 | buf_t buf_getblk(vnode_t, daddr64_t, int, int, int, int); | |
445 | buf_t buf_geteblk(int); | |
446 | ||
447 | __END_DECLS | |
448 | ||
449 | ||
450 | /* Macros to clear/set/test flags. */ | |
451 | #define SET(t, f) (t) |= (f) | |
452 | #define CLR(t, f) (t) &= ~(f) | |
453 | #define ISSET(t, f) ((t) & (f)) | |
454 | ||
455 | ||
456 | #endif /* !_SYS_BUF_H_ */ |