]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/ubc_internal.h
xnu-4903.221.2.tar.gz
[apple/xnu.git] / bsd / sys / ubc_internal.h
CommitLineData
91447636 1/*
b0d623f7 2 * Copyright (c) 1999-2008 Apple Inc. All rights reserved.
91447636 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
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>
3e170ce0 47#include <sys/codesign.h>
91447636
A
48
49#include <sys/cdefs.h>
50
51#include <kern/locks.h>
52#include <mach/memory_object_types.h>
53
54
55#define UBC_INFO_NULL ((struct ubc_info *) 0)
56
57
58extern struct zone *ubc_info_zone;
59
b7266188
A
60/*
61 * Maximum number of vfs clusters per vnode
62 */
63#define MAX_CLUSTERS CONFIG_MAX_CLUSTERS
91447636 64
b0d623f7
A
65#define SPARSE_PUSH_LIMIT 4 /* limit on number of concurrent sparse pushes outside of the cl_lockw */
66 /* once we reach this limit, we'll hold the lock */
91447636
A
67
68struct cl_extent {
69 daddr64_t b_addr;
70 daddr64_t e_addr;
71};
72
73struct cl_wextent {
74 daddr64_t b_addr;
75 daddr64_t e_addr;
2d21ac55 76 int io_flags;
91447636
A
77};
78
79struct cl_readahead {
80 lck_mtx_t cl_lockr;
81 daddr64_t cl_lastr; /* last block read by client */
82 daddr64_t cl_maxra; /* last block prefetched by the read ahead */
83 int cl_ralen; /* length of last prefetch */
84};
85
86struct cl_writebehind {
87 lck_mtx_t cl_lockw;
91447636 88 void * cl_scmap; /* pointer to sparse cluster map */
6d2010ae
A
89 off_t cl_last_write; /* offset of the end of the last write */
90 off_t cl_seq_written; /* sequentially written bytes */
b0d623f7
A
91 int cl_sparse_pushes; /* number of pushes outside of the cl_lockw in progress */
92 int cl_sparse_wait; /* synchronous push is in progress */
91447636
A
93 int cl_number; /* number of packed write behind clusters currently valid */
94 struct cl_wextent cl_clusters[MAX_CLUSTERS]; /* packed write behind clusters */
95};
96
3e170ce0 97struct cs_hash;
91447636 98
5ba3f43e
A
99uint8_t cs_hash_type(struct cs_hash const *);
100
2d21ac55
A
101struct cs_blob {
102 struct cs_blob *csb_next;
103 cpu_type_t csb_cpu_type;
104 unsigned int csb_flags;
b0d623f7
A
105 off_t csb_base_offset; /* Offset of Mach-O binary in fat binary */
106 off_t csb_start_offset; /* Blob coverage area start, from csb_base_offset */
107 off_t csb_end_offset; /* Blob coverage area end, from csb_base_offset */
2d21ac55
A
108 vm_size_t csb_mem_size;
109 vm_offset_t csb_mem_offset;
110 vm_address_t csb_mem_kaddr;
3e170ce0 111 unsigned char csb_cdhash[CS_CDHASH_LEN];
d190cdc3 112 const struct cs_hash *csb_hashtype;
39037602
A
113 vm_size_t csb_hash_pagesize; /* each hash entry represent this many bytes in the file */
114 vm_size_t csb_hash_pagemask;
115 vm_size_t csb_hash_pageshift;
116 vm_size_t csb_hash_firstlevel_pagesize; /* First hash this many bytes, then hash the hashes together */
490019cf 117 const CS_CodeDirectory *csb_cd;
fe8ab488 118 const char *csb_teamid;
39037602
A
119 const CS_GenericBlob *csb_entitlements_blob; /* raw blob, subrange of csb_mem_kaddr */
120 void * csb_entitlements; /* The entitlements as an OSDictionary */
5ba3f43e
A
121 unsigned int csb_signer_type;
122
d9a64523 123 unsigned int csb_reconstituted; /* signature has potentially been modified after validation */
5ba3f43e 124 /* The following two will be replaced by the csb_signer_type. */
3e170ce0
A
125 unsigned int csb_platform_binary:1;
126 unsigned int csb_platform_path:1;
d9a64523 127
2d21ac55
A
128};
129
91447636
A
130/*
131 * The following data structure keeps the information to associate
132 * a vnode to the correspondig VM objects.
133 */
134struct ubc_info {
2d21ac55
A
135 memory_object_t ui_pager; /* pager */
136 memory_object_control_t ui_control; /* VM control for the pager */
2d21ac55
A
137 vnode_t ui_vnode; /* vnode for this ubc_info */
138 kauth_cred_t ui_ucred; /* holds credentials for NFS paging */
139 off_t ui_size; /* file size for the vnode */
fe8ab488
A
140 uint32_t ui_flags; /* flags */
141 uint32_t cs_add_gen; /* generation count when csblob was validated */
2d21ac55
A
142
143 struct cl_readahead *cl_rahead; /* cluster read ahead context */
144 struct cl_writebehind *cl_wbehind; /* cluster write behind context */
145
15129b1c
A
146 struct timespec cs_mtime; /* modify time of file when
147 first cs_blob was loaded */
2d21ac55 148 struct cs_blob *cs_blobs; /* for CODE SIGNING */
6d2010ae
A
149#if CHECK_CS_VALIDATION_BITMAP
150 void *cs_valid_bitmap; /* right now: used only for signed files on the read-only root volume */
151 uint64_t cs_valid_bitmap_size; /* Save original bitmap size in case the file size changes.
152 * In the future, we may want to reconsider changing the
153 * underlying bitmap to reflect the new file size changes.
154 */
155#endif /* CHECK_CS_VALIDATION_BITMAP */
91447636
A
156};
157
158/* Defines for ui_flags */
2d21ac55
A
159#define UI_NONE 0x00000000 /* none */
160#define UI_HASPAGER 0x00000001 /* has a pager associated */
161#define UI_INITED 0x00000002 /* newly initialized vnode */
162#define UI_HASOBJREF 0x00000004 /* hold a reference on object */
163#define UI_WASMAPPED 0x00000008 /* vnode was mapped */
164#define UI_ISMAPPED 0x00000010 /* vnode is currently mapped */
165#define UI_MAPBUSY 0x00000020 /* vnode is being mapped or unmapped */
166#define UI_MAPWAITING 0x00000040 /* someone waiting for UI_MAPBUSY */
22ba694c 167#define UI_MAPPEDWRITE 0x00000080 /* it's mapped with PROT_WRITE */
91447636
A
168
169/*
170 * exported primitives for loadable file systems.
171 */
172
173__BEGIN_DECLS
39236c6e 174__private_extern__ void ubc_init(void);
2d21ac55 175__private_extern__ int ubc_umount(mount_t mp);
91447636 176__private_extern__ void ubc_unmountall(void);
2d21ac55 177__private_extern__ memory_object_t ubc_getpager(vnode_t);
2d21ac55 178__private_extern__ void ubc_destroy_named(vnode_t);
91447636
A
179
180/* internal only */
181__private_extern__ void cluster_release(struct ubc_info *);
39236c6e 182__private_extern__ uint32_t cluster_throttle_io_limit(vnode_t, uint32_t *);
b0d623f7 183
91447636
A
184
185/* Flags for ubc_getobject() */
186#define UBC_FLAGS_NONE 0x0000
187#define UBC_HOLDOBJECT 0x0001
188#define UBC_FOR_PAGEOUT 0x0002
189
2d21ac55 190memory_object_control_t ubc_getobject(vnode_t, int);
91447636 191
2d21ac55
A
192int ubc_info_init(vnode_t);
193int ubc_info_init_withsize(vnode_t, off_t);
194void ubc_info_deallocate(struct ubc_info *);
91447636 195
2d21ac55
A
196int ubc_isinuse(vnode_t, int);
197int ubc_isinuse_locked(vnode_t, int, int);
91447636 198
2d21ac55 199int ubc_getcdhash(vnode_t, off_t, unsigned char *);
91447636 200
b0d623f7 201#ifdef XNU_KERNEL_PRIVATE
fe8ab488 202int UBCINFOEXISTS(const struct vnode *);
b0d623f7 203#endif /* XNU_KERNEL_PRIVATE */
91447636 204
593a1d5f
A
205/* code signing */
206struct cs_blob;
39037602 207int ubc_cs_blob_add(vnode_t, cpu_type_t, off_t, vm_address_t *, vm_size_t, struct image_params *, int, struct cs_blob **);
39236c6e 208int ubc_cs_sigpup_add(vnode_t, vm_address_t, vm_size_t);
593a1d5f 209struct cs_blob *ubc_get_cs_blobs(vnode_t);
15129b1c 210void ubc_get_cs_mtime(vnode_t, struct timespec *);
593a1d5f
A
211int ubc_cs_getcdhash(vnode_t, off_t, unsigned char *);
212kern_return_t ubc_cs_blob_allocate(vm_offset_t *, vm_size_t *);
213void ubc_cs_blob_deallocate(vm_offset_t, vm_size_t);
39037602 214boolean_t ubc_cs_is_range_codesigned(vnode_t, mach_vm_offset_t, mach_vm_size_t);
593a1d5f 215
6d2010ae
A
216kern_return_t ubc_cs_validation_bitmap_allocate( vnode_t );
217void ubc_cs_validation_bitmap_deallocate( vnode_t );
91447636
A
218__END_DECLS
219
220
221#endif /* _SYS_UBC_INTERNAL_H_ */
222