]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/ubc.h
0b647d1db31212d5706ffe899a07b7607ba6cdf0
[apple/xnu.git] / bsd / sys / ubc.h
1 /*
2 * Copyright (c) 1999, 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * File: ubc.h
24 * Author: Umesh Vaishampayan [umeshv@apple.com]
25 * 05-Aug-1999 umeshv Created.
26 *
27 * Header file for Unified Buffer Cache.
28 *
29 */
30
31 #ifndef _SYS_UBC_H_
32 #define _SYS_UBC_H_
33
34 #include <sys/types.h>
35 #include <sys/ucred.h>
36 #include <sys/vnode.h>
37
38 #include <sys/cdefs.h>
39
40 #include <mach/memory_object_types.h>
41
42 #define UBC_INFO_NULL ((struct ubc_info *) 0)
43 #define UBC_NOINFO ((struct ubc_info *)0xDEADD1ED)
44
45 extern struct zone *ubc_info_zone;
46
47 /*
48 * The following data structure keeps the information to associate
49 * a vnode to the correspondig VM objects.
50 */
51
52 struct ubc_info {
53 void * ui_pager; /* pager */
54 void *ui_object; /* VM object corresponding to the pager */
55 long ui_flags; /* flags */
56 struct vnode *ui_vnode; /* The vnode associated with this ubc_info */
57 struct ucred *ui_ucred; /* holds credentials for NFS paging */
58 int ui_holdcnt; /* hold the memory object */
59 off_t ui_size; /* file size for the vnode */
60 long ui_mapped; /* is it currently mapped */
61 };
62
63 /* Defines for ui_flags */
64 #define UI_NONE 0x00000000 /* none */
65 #define UI_HASPAGER 0x00000001 /* has a pager associated */
66 #define UI_INITED 0x00000002 /* newly initialized vnode */
67 #define UI_HASOBJREF 0x00000004 /* hold a reference on object */
68 #define UI_WASMAPPED 0x00000008 /* vnode was mapped */
69 #define UI_DONTCACHE 0x00000010 /* do not cache object */
70
71 /*
72 * exported primitives for loadable file systems.
73 */
74
75 __BEGIN_DECLS
76 int ubc_info_init __P((struct vnode *));
77 void ubc_info_free __P((struct vnode *));
78 int ubc_setsize __P((struct vnode *, off_t));
79 off_t ubc_getsize __P((struct vnode *));
80 int ubc_uncache __P((struct vnode *));
81 int ubc_umount __P((struct mount *));
82 void ubc_unmountall __P(());
83 int ubc_setcred __P((struct vnode *, struct proc *));
84 struct ucred *ubc_getcred __P((struct vnode *));
85 void *ubc_getpager __P((struct vnode *));
86 void *ubc_getobject __P((struct vnode *, int));
87 int ubc_setpager __P((struct vnode *, void *));
88 int ubc_setflags __P((struct vnode *, int));
89 int ubc_clearflags __P((struct vnode *, int));
90 int ubc_issetflags __P((struct vnode *, int));
91 off_t ubc_blktooff __P((struct vnode *, daddr_t));
92 daddr_t ubc_offtoblk __P((struct vnode *, off_t));
93 int ubc_clean __P((struct vnode *, int));
94 int ubc_pushdirty __P((struct vnode *));
95 int ubc_hold __P((struct vnode *));
96 void ubc_rele __P((struct vnode *));
97 void ubc_map __P((struct vnode *));
98 int ubc_release __P((struct vnode *));
99 int ubc_invalidate __P((struct vnode *, off_t, size_t));
100 int ubc_isinuse __P((struct vnode *, int));
101
102 /* cluster IO routines */
103 int cluster_read __P((struct vnode *, struct uio *, off_t, int, int));
104 int advisory_read __P((struct vnode *, off_t, off_t, int, int));
105 int cluster_write __P((struct vnode *, struct uio*, off_t, off_t,
106 off_t, off_t, int, int));
107 int cluster_push __P((struct vnode *));
108 int cluster_pageout __P((struct vnode *, upl_t, vm_offset_t, off_t, int,
109 off_t, int, int));
110 int cluster_pagein __P((struct vnode *, upl_t, vm_offset_t, off_t, int,
111 off_t, int, int));
112 int cluster_bp __P((struct buf *));
113 __END_DECLS
114
115 #define UBCINFOMISSING(vp) \
116 ((vp) && ((vp)->v_type == VREG) && ((vp)->v_ubcinfo == UBC_INFO_NULL))
117
118 #define UBCINFORECLAIMED(vp) \
119 ((vp) && ((vp)->v_type == VREG) && ((vp)->v_ubcinfo == UBC_NOINFO))
120
121 #define UBCINFOEXISTS(vp) \
122 ((vp) && ((vp)->v_type == VREG) && \
123 ((vp)->v_ubcinfo) && ((vp)->v_ubcinfo != UBC_NOINFO))
124
125 #define UBCISVALID(vp) \
126 ((vp) && ((vp)->v_type == VREG) && !((vp)->v_flag & VSYSTEM))
127
128 #define UBCINVALID(vp) \
129 (((vp) == NULL) || ((vp) && ((vp)->v_type != VREG)) \
130 || ((vp) && ((vp)->v_flag & VSYSTEM)))
131
132 #define UBCINFOCHECK(fun, vp) \
133 if ((vp) && ((vp)->v_type == VREG) && \
134 (((vp)->v_ubcinfo == UBC_INFO_NULL) \
135 || ((vp)->v_ubcinfo == UBC_NOINFO))) \
136 panic("%s: lost ubc_info", (fun));
137
138 /* Flags for ubc_getobject() */
139 #define UBC_HOLDOBJECT 0x0001
140 #define UBC_NOREACTIVATE 0x0002
141 #define UBC_PAGINGOP 0x0004
142
143
144 #endif /* _SYS_UBC_H_ */
145