]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
8f6c56a5 | 11 | * |
6601e61a A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
21 | */ |
22 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
23 | /* | |
24 | * Copyright (c) 1982, 1986, 1989, 1993 | |
25 | * The Regents of the University of California. All rights reserved. | |
26 | * (c) UNIX System Laboratories, Inc. | |
27 | * All or some portions of this file are derived from material licensed | |
28 | * to the University of California by American Telephone and Telegraph | |
29 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
30 | * the permission of UNIX System Laboratories, Inc. | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions | |
34 | * are met: | |
35 | * 1. Redistributions of source code must retain the above copyright | |
36 | * notice, this list of conditions and the following disclaimer. | |
37 | * 2. Redistributions in binary form must reproduce the above copyright | |
38 | * notice, this list of conditions and the following disclaimer in the | |
39 | * documentation and/or other materials provided with the distribution. | |
40 | * 3. All advertising materials mentioning features or use of this software | |
41 | * must display the following acknowledgement: | |
42 | * This product includes software developed by the University of | |
43 | * California, Berkeley and its contributors. | |
44 | * 4. Neither the name of the University nor the names of its contributors | |
45 | * may be used to endorse or promote products derived from this software | |
46 | * without specific prior written permission. | |
47 | * | |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | |
59 | * | |
60 | * @(#)buf.h 8.9 (Berkeley) 3/30/95 | |
61 | */ | |
62 | ||
63 | #ifndef _SYS_BUF_H_ | |
64 | #define _SYS_BUF_H_ | |
9bccf70c | 65 | |
9bccf70c | 66 | #include <sys/cdefs.h> |
91447636 A |
67 | #include <sys/kernel_types.h> |
68 | #include <mach/memory_object_types.h> | |
69 | ||
1c79356b | 70 | |
1c79356b | 71 | #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ |
91447636 A |
72 | #define B_READ 0x00000001 /* Read buffer. */ |
73 | #define B_ASYNC 0x00000002 /* Start I/O, do not wait. */ | |
74 | #define B_NOCACHE 0x00000004 /* Do not cache block after use. */ | |
75 | #define B_DELWRI 0x00000008 /* Delay I/O until buffer reused. */ | |
76 | #define B_LOCKED 0x00000010 /* Locked in core (not reusable). */ | |
77 | #define B_PHYS 0x00000020 /* I/O to user memory. */ | |
78 | #define B_CLUSTER 0x00000040 /* UPL based I/O generated by cluster layer */ | |
79 | #define B_PAGEIO 0x00000080 /* Page in/out */ | |
80 | #define B_META 0x00000100 /* buffer contains meta-data. */ | |
81 | /* | |
82 | * make sure to check when adding flags that | |
83 | * that the new flags don't overlap the definitions | |
84 | * in buf_internal.h | |
85 | */ | |
1c79356b | 86 | |
91447636 | 87 | __BEGIN_DECLS |
1c79356b | 88 | |
91447636 A |
89 | /* |
90 | * mark the buffer associated with buf_t | |
91 | * as AGED with respect to the LRU cache | |
92 | */ | |
93 | void buf_markaged(buf_t); | |
9bccf70c | 94 | |
91447636 A |
95 | /* |
96 | * mark the buffer associated with buf_t | |
97 | * as invalid... on release, it will go | |
98 | * directly to the free list | |
99 | */ | |
100 | void buf_markinvalid(buf_t); | |
9bccf70c | 101 | |
91447636 A |
102 | /* |
103 | * mark the buffer assoicated with buf_t | |
104 | * as a delayed write... | |
105 | */ | |
106 | void buf_markdelayed(buf_t); | |
1c79356b A |
107 | |
108 | /* | |
91447636 A |
109 | * mark the buffer associated with buf_t |
110 | * as having been interrupted... EINTR | |
1c79356b | 111 | */ |
91447636 | 112 | void buf_markeintr(buf_t); |
1c79356b | 113 | |
91447636 A |
114 | /* |
115 | * returns 1 if the buffer associated with buf_t | |
116 | * contains valid data... 0 if it does not | |
117 | */ | |
118 | int buf_valid(buf_t); | |
1c79356b | 119 | |
91447636 A |
120 | /* |
121 | * returns 1 if the buffer was already valid | |
122 | * in the cache... i.e. no I/O was performed | |
123 | * returns 0 otherwise | |
124 | */ | |
125 | int buf_fromcache(buf_t); | |
126 | ||
127 | /* | |
128 | * returns the UPL associated with buf_t | |
129 | */ | |
130 | void * buf_upl(buf_t); | |
131 | ||
132 | /* | |
133 | * returns the offset into the UPL | |
134 | * associated with buf_t which is to be | |
135 | * used as the base offset for this I/O | |
136 | */ | |
137 | uint32_t buf_uploffset(buf_t); | |
138 | ||
139 | /* | |
140 | * returns read credential associated with buf_t | |
141 | * a reference is taken which must be explicilty dropped | |
142 | */ | |
143 | ucred_t buf_rcred(buf_t); | |
144 | ||
145 | /* | |
146 | * returns write credential associated with buf_t | |
147 | * a reference is taken which must be explicilty dropped | |
148 | */ | |
149 | ucred_t buf_wcred(buf_t); | |
150 | ||
151 | /* | |
152 | * returns process handle associated with buf_t | |
153 | * i.e identity of task that issued the I/O | |
154 | */ | |
155 | proc_t buf_proc(buf_t); | |
156 | ||
157 | uint32_t buf_dirtyoff(buf_t); | |
158 | uint32_t buf_dirtyend(buf_t); | |
159 | void buf_setdirtyoff(buf_t, uint32_t); | |
160 | void buf_setdirtyend(buf_t, uint32_t); | |
161 | ||
162 | /* | |
163 | * return the errno value associated with buf_t | |
164 | */ | |
165 | errno_t buf_error(buf_t); | |
166 | ||
167 | /* | |
168 | * set errno on buf_t | |
169 | */ | |
170 | void buf_seterror(buf_t, errno_t); | |
171 | ||
172 | /* | |
173 | * set specified flags on buf_t | |
174 | * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO | |
175 | */ | |
176 | void buf_setflags(buf_t, int32_t); | |
177 | ||
178 | /* | |
179 | * clear specified flags on buf_t | |
180 | * B_LOCKED/B_NOCACHE/B_ASYNC/B_READ/B_WRITE/B_PAGEIO | |
181 | */ | |
182 | void buf_clearflags(buf_t, int32_t); | |
183 | ||
184 | /* | |
185 | * return external flags associated with buf_t | |
186 | * B_CLUSTER/B_PHYS/B_LOCKED/B_DELWRI/B_ASYNC/B_READ/B_WRITE/B_META/B_PAGEIO | |
187 | */ | |
188 | int32_t buf_flags(buf_t); | |
189 | ||
190 | /* | |
191 | * clears I/O related flags (both internal and | |
192 | * external) associated with buf_t and allows | |
193 | * the following to be set... | |
194 | * B_READ/B_WRITE/B_ASYNC/B_NOCACHE | |
195 | */ | |
196 | void buf_reset(buf_t, int32_t); | |
197 | ||
198 | /* | |
199 | * insure that the data storage associated with buf_t | |
200 | * is addressable | |
201 | */ | |
202 | errno_t buf_map(buf_t, caddr_t *); | |
203 | ||
204 | /* | |
205 | * release our need to have the storage associated | |
206 | * with buf_t in an addressable state | |
207 | */ | |
208 | errno_t buf_unmap(buf_t); | |
209 | ||
210 | /* | |
211 | * set driver specific data for buf_t | |
212 | */ | |
213 | void buf_setdrvdata(buf_t, void *); | |
214 | ||
215 | /* | |
216 | * retrieve driver specific data associated with buf_t | |
217 | */ | |
218 | void * buf_drvdata(buf_t); | |
219 | ||
220 | /* | |
221 | * set fs specific data for buf_t | |
222 | */ | |
223 | void buf_setfsprivate(buf_t, void *); | |
224 | ||
225 | /* | |
226 | * retrieve driver specific data associated with buf_t | |
227 | */ | |
228 | void * buf_fsprivate(buf_t); | |
229 | ||
230 | /* | |
231 | * retrieve the phsyical block number associated with buf_t | |
232 | */ | |
233 | daddr64_t buf_blkno(buf_t); | |
234 | ||
235 | /* | |
236 | * retrieve the logical block number associated with buf_t | |
237 | * i.e. the block number derived from the file offset | |
238 | */ | |
239 | daddr64_t buf_lblkno(buf_t); | |
240 | ||
241 | /* | |
242 | * set the phsyical block number associated with buf_t | |
243 | */ | |
244 | void buf_setblkno(buf_t, daddr64_t); | |
245 | ||
246 | /* | |
247 | * set the logical block number associated with buf_t | |
248 | * i.e. the block number derived from the file offset | |
249 | */ | |
250 | void buf_setlblkno(buf_t, daddr64_t); | |
251 | ||
252 | /* | |
253 | * retrieve the count of valid bytes associated with buf_t | |
254 | */ | |
255 | uint32_t buf_count(buf_t); | |
256 | ||
257 | /* | |
258 | * retrieve the size of the data store assoicated with buf_t | |
259 | */ | |
260 | uint32_t buf_size(buf_t); | |
261 | ||
262 | /* | |
263 | * retrieve the residual I/O count assoicated with buf_t | |
264 | * i.e. number of bytes that have not yet been completed | |
265 | */ | |
266 | uint32_t buf_resid(buf_t); | |
267 | ||
268 | /* | |
269 | * set the count of bytes associated with buf_t | |
270 | * typically used to set the size of the I/O to be performed | |
271 | */ | |
272 | void buf_setcount(buf_t, uint32_t); | |
273 | ||
274 | /* | |
275 | * set the size of the buffer store associated with buf_t | |
276 | * typically used when providing private storage to buf_t | |
277 | */ | |
278 | void buf_setsize(buf_t, uint32_t); | |
279 | ||
280 | /* | |
281 | * set the size in bytes of the unfinished I/O associated with buf_t | |
282 | */ | |
283 | void buf_setresid(buf_t, uint32_t); | |
284 | ||
285 | /* | |
286 | * associate kernel addressable storage with buf_t | |
287 | */ | |
288 | void buf_setdataptr(buf_t, uintptr_t); | |
289 | ||
290 | /* | |
291 | * retrieve pointer to buffer associated with buf_t | |
292 | * if non-null, than guaranteed to be kernel addressable | |
293 | * size of buffer can be retrieved via buf_size | |
294 | * size of valid data can be retrieved via buf_count | |
295 | * if NULL, than use buf_map/buf_unmap to manage access to the underlying storage | |
296 | */ | |
297 | uintptr_t buf_dataptr(buf_t); | |
1c79356b A |
298 | |
299 | /* | |
91447636 | 300 | * return the vnode_t associated with buf_t |
1c79356b | 301 | */ |
91447636 A |
302 | vnode_t buf_vnode(buf_t); |
303 | ||
304 | /* | |
305 | * assign vnode_t to buf_t... the | |
306 | * device currently associated with | |
307 | * but_t is not changed. | |
308 | */ | |
309 | void buf_setvnode(buf_t, vnode_t); | |
310 | ||
311 | /* | |
312 | * return the dev_t associated with buf_t | |
313 | */ | |
314 | dev_t buf_device(buf_t); | |
315 | ||
316 | /* | |
317 | * assign the dev_t associated with vnode_t | |
318 | * to buf_t | |
319 | */ | |
320 | errno_t buf_setdevice(buf_t, vnode_t); | |
321 | ||
322 | errno_t buf_strategy(vnode_t, void *); | |
323 | ||
324 | /* | |
325 | * flags for buf_invalblkno | |
326 | */ | |
327 | #define BUF_WAIT 0x01 | |
328 | ||
329 | errno_t buf_invalblkno(vnode_t, daddr64_t, int); | |
330 | ||
331 | ||
332 | /* | |
333 | * return the callback function pointer | |
334 | * if the callback is still valid | |
335 | * returns NULL if a buffer that was not | |
336 | * allocated via buf_alloc is specified | |
337 | * or if a callback has not been set or | |
338 | * it has already fired... | |
339 | */ | |
340 | void * buf_callback(buf_t); | |
341 | ||
342 | /* | |
343 | * assign a one-shot callback function (driven from biodone) | |
344 | * to a buf_t allocated via buf_alloc... a caller specified | |
345 | * arg is passed to the callback function | |
346 | */ | |
347 | errno_t buf_setcallback(buf_t, void (*)(buf_t, void *), void *); | |
348 | ||
349 | /* | |
350 | * add a upl_t to a buffer allocated via buf_alloc | |
351 | * and set the offset into the upl_t (must be page | |
352 | * aligned). | |
353 | */ | |
354 | errno_t buf_setupl(buf_t, upl_t, uint32_t); | |
355 | ||
356 | /* | |
357 | * allocate a buf_t that is a clone of the buf_t | |
358 | * passed in, but whose I/O range is a subset... | |
359 | * if a callback routine is specified, it will | |
360 | * be called from buf_biodone with the bp and | |
361 | * arg specified. | |
362 | * it must be freed via buf_free | |
363 | */ | |
364 | buf_t buf_clone(buf_t, int, int, void (*)(buf_t, void *), void *); | |
365 | ||
366 | /* | |
367 | * allocate a buf_t associated with vnode_t | |
368 | * that has NO storage associated with it | |
369 | * but is suitable for use in issuing I/Os | |
370 | * after storage has been assigned via buf_setdataptr | |
371 | * or buf_addupl | |
372 | */ | |
373 | buf_t buf_alloc(vnode_t); | |
374 | ||
375 | /* | |
376 | * free a buf_t that was allocated via buf_alloc | |
377 | * any private storage associated with buf_t is the | |
378 | * responsiblity of the caller to release | |
379 | */ | |
380 | void buf_free(buf_t); | |
381 | ||
382 | /* | |
383 | * flags for buf_invalidateblks | |
384 | */ | |
385 | #define BUF_WRITE_DATA 0x0001 /* write data blocks first */ | |
386 | #define BUF_SKIP_META 0x0002 /* skip over metadata blocks */ | |
387 | ||
388 | int buf_invalidateblks(vnode_t, int, int, int); | |
389 | /* | |
390 | * flags for buf_flushdirtyblks and buf_iterate | |
391 | */ | |
392 | #define BUF_SKIP_NONLOCKED 0x01 | |
393 | #define BUF_SKIP_LOCKED 0x02 | |
394 | ||
395 | void buf_flushdirtyblks(vnode_t, int, int, char *); | |
396 | void buf_iterate(vnode_t, int (*)(buf_t, void *), int, void *); | |
397 | ||
398 | #define BUF_RETURNED 0 | |
399 | #define BUF_RETURNED_DONE 1 | |
400 | #define BUF_CLAIMED 2 | |
401 | #define BUF_CLAIMED_DONE 3 | |
402 | ||
403 | /* | |
404 | * zero the storage associated with buf_t | |
405 | */ | |
406 | void buf_clear(buf_t); | |
407 | ||
408 | errno_t buf_bawrite(buf_t); | |
409 | errno_t buf_bdwrite(buf_t); | |
410 | errno_t buf_bwrite(buf_t); | |
411 | ||
412 | void buf_biodone(buf_t); | |
413 | errno_t buf_biowait(buf_t); | |
414 | void buf_brelse(buf_t); | |
415 | ||
416 | errno_t buf_bread(vnode_t, daddr64_t, int, ucred_t, buf_t *); | |
417 | errno_t buf_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, ucred_t, buf_t *); | |
418 | errno_t buf_meta_bread(vnode_t, daddr64_t, int, ucred_t, buf_t *); | |
419 | errno_t buf_meta_breadn(vnode_t, daddr64_t, int, daddr64_t *, int *, int, ucred_t, buf_t *); | |
420 | ||
421 | u_int minphys(buf_t bp); | |
422 | int physio(void (*)(buf_t), buf_t, dev_t, int , u_int (*)(buf_t), struct uio *, int ); | |
423 | ||
424 | ||
425 | /* | |
426 | * Flags for operation type in getblk() | |
427 | */ | |
428 | #define BLK_READ 0x01 /* buffer for read */ | |
429 | #define BLK_WRITE 0x02 /* buffer for write */ | |
430 | #define BLK_META 0x10 /* buffer for metadata */ | |
431 | /* | |
432 | * modifier for above flags... if set, getblk will only return | |
433 | * a bp that is already valid... i.e. found in the cache | |
434 | */ | |
435 | #define BLK_ONLYVALID 0x80000000 | |
436 | ||
437 | /* timeout is in msecs */ | |
438 | buf_t buf_getblk(vnode_t, daddr64_t, int, int, int, int); | |
439 | buf_t buf_geteblk(int); | |
440 | ||
441 | __END_DECLS | |
442 | ||
443 | ||
444 | /* Macros to clear/set/test flags. */ | |
445 | #define SET(t, f) (t) |= (f) | |
446 | #define CLR(t, f) (t) &= ~(f) | |
447 | #define ISSET(t, f) ((t) & (f)) | |
448 | ||
1c79356b | 449 | |
1c79356b | 450 | #endif /* !_SYS_BUF_H_ */ |