]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/ubc_internal.h
xnu-1228.5.18.tar.gz
[apple/xnu.git] / bsd / sys / ubc_internal.h
1 /*
2 * Copyright (c) 1999-2007 Apple 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 /*
29 * File: ubc.h
30 * Author: Umesh Vaishampayan [umeshv@apple.com]
31 * 05-Aug-1999 umeshv Created.
32 *
33 * Header file for Unified Buffer Cache.
34 *
35 */
36
37 #ifndef _SYS_UBC_INTERNAL_H_
38 #define _SYS_UBC_INTERNAL_H_
39
40 #include <sys/appleapiopts.h>
41 #include <sys/types.h>
42 #include <sys/kernel_types.h>
43 #include <sys/ucred.h>
44 #include <sys/vnode.h>
45 #include <sys/ubc.h>
46 #include <sys/mman.h>
47
48 #include <sys/cdefs.h>
49
50 #include <kern/locks.h>
51 #include <mach/memory_object_types.h>
52
53 #include <libkern/crypto/sha1.h>
54
55
56 #define UBC_INFO_NULL ((struct ubc_info *) 0)
57
58
59 extern struct zone *ubc_info_zone;
60
61
62 #define MAX_CLUSTERS 4 /* maximum number of vfs clusters per vnode */
63
64 struct cl_extent {
65 daddr64_t b_addr;
66 daddr64_t e_addr;
67 };
68
69 struct cl_wextent {
70 daddr64_t b_addr;
71 daddr64_t e_addr;
72 int io_flags;
73 };
74
75 struct cl_readahead {
76 lck_mtx_t cl_lockr;
77 daddr64_t cl_lastr; /* last block read by client */
78 daddr64_t cl_maxra; /* last block prefetched by the read ahead */
79 int cl_ralen; /* length of last prefetch */
80 };
81
82 struct cl_writebehind {
83 lck_mtx_t cl_lockw;
84 void * cl_scmap; /* pointer to sparse cluster map */
85 int cl_scdirty; /* number of dirty pages in the sparse cluster map */
86 int cl_number; /* number of packed write behind clusters currently valid */
87 struct cl_wextent cl_clusters[MAX_CLUSTERS]; /* packed write behind clusters */
88 };
89
90
91 struct cs_blob {
92 struct cs_blob *csb_next;
93 cpu_type_t csb_cpu_type;
94 unsigned int csb_flags;
95 off_t csb_base_offset;
96 off_t csb_start_offset;
97 off_t csb_end_offset;
98 ipc_port_t csb_mem_handle;
99 vm_size_t csb_mem_size;
100 vm_offset_t csb_mem_offset;
101 vm_address_t csb_mem_kaddr;
102 unsigned char csb_sha1[SHA1_RESULTLEN];
103 };
104
105 /*
106 * The following data structure keeps the information to associate
107 * a vnode to the correspondig VM objects.
108 */
109 struct ubc_info {
110 memory_object_t ui_pager; /* pager */
111 memory_object_control_t ui_control; /* VM control for the pager */
112 long ui_flags; /* flags */
113 vnode_t ui_vnode; /* vnode for this ubc_info */
114 kauth_cred_t ui_ucred; /* holds credentials for NFS paging */
115 off_t ui_size; /* file size for the vnode */
116
117 struct cl_readahead *cl_rahead; /* cluster read ahead context */
118 struct cl_writebehind *cl_wbehind; /* cluster write behind context */
119
120 struct cs_blob *cs_blobs; /* for CODE SIGNING */
121 };
122
123 /* Defines for ui_flags */
124 #define UI_NONE 0x00000000 /* none */
125 #define UI_HASPAGER 0x00000001 /* has a pager associated */
126 #define UI_INITED 0x00000002 /* newly initialized vnode */
127 #define UI_HASOBJREF 0x00000004 /* hold a reference on object */
128 #define UI_WASMAPPED 0x00000008 /* vnode was mapped */
129 #define UI_ISMAPPED 0x00000010 /* vnode is currently mapped */
130 #define UI_MAPBUSY 0x00000020 /* vnode is being mapped or unmapped */
131 #define UI_MAPWAITING 0x00000040 /* someone waiting for UI_MAPBUSY */
132
133 /*
134 * exported primitives for loadable file systems.
135 */
136
137 __BEGIN_DECLS
138 __private_extern__ void ubc_init(void);
139 __private_extern__ int ubc_umount(mount_t mp);
140 __private_extern__ void ubc_unmountall(void);
141 __private_extern__ memory_object_t ubc_getpager(vnode_t);
142 __private_extern__ int ubc_map(vnode_t, int);
143 __private_extern__ void ubc_destroy_named(vnode_t);
144
145 /* internal only */
146 __private_extern__ void cluster_release(struct ubc_info *);
147 __private_extern__ uint32_t cluster_max_io_size(mount_t, int);
148
149
150
151 /* Flags for ubc_getobject() */
152 #define UBC_FLAGS_NONE 0x0000
153 #define UBC_HOLDOBJECT 0x0001
154 #define UBC_FOR_PAGEOUT 0x0002
155
156 memory_object_control_t ubc_getobject(vnode_t, int);
157
158 int ubc_info_init(vnode_t);
159 int ubc_info_init_withsize(vnode_t, off_t);
160 void ubc_info_deallocate(struct ubc_info *);
161
162 int ubc_isinuse(vnode_t, int);
163 int ubc_isinuse_locked(vnode_t, int, int);
164
165 int ubc_page_op(vnode_t, off_t, int, ppnum_t *, int *);
166 int ubc_range_op(vnode_t, off_t, off_t, int, int *);
167
168 int ubc_getcdhash(vnode_t, off_t, unsigned char *);
169
170 int UBCINFOEXISTS(vnode_t);
171
172 __END_DECLS
173
174
175 #endif /* _SYS_UBC_INTERNAL_H_ */
176