]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/ubc_internal.h
xnu-792.6.22.tar.gz
[apple/xnu.git] / bsd / sys / ubc_internal.h
1 /*
2 * Copyright (c) 1999-2004 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_INTERNAL_H_
32 #define _SYS_UBC_INTERNAL_H_
33
34 #include <sys/appleapiopts.h>
35 #include <sys/types.h>
36 #include <sys/kernel_types.h>
37 #include <sys/ucred.h>
38 #include <sys/vnode.h>
39 #include <sys/ubc.h>
40 #include <sys/mman.h>
41
42 #include <sys/cdefs.h>
43
44 #include <kern/locks.h>
45 #include <mach/memory_object_types.h>
46
47
48 #define UBC_INFO_NULL ((struct ubc_info *) 0)
49
50
51 extern struct zone *ubc_info_zone;
52
53
54 #define MAX_CLUSTERS 4 /* maximum number of vfs clusters per vnode */
55
56 struct cl_extent {
57 daddr64_t b_addr;
58 daddr64_t e_addr;
59 };
60
61 struct cl_wextent {
62 daddr64_t b_addr;
63 daddr64_t e_addr;
64 int io_nocache;
65 };
66
67 struct cl_readahead {
68 lck_mtx_t cl_lockr;
69 daddr64_t cl_lastr; /* last block read by client */
70 daddr64_t cl_maxra; /* last block prefetched by the read ahead */
71 int cl_ralen; /* length of last prefetch */
72 };
73
74 struct cl_writebehind {
75 lck_mtx_t cl_lockw;
76 int cl_hasbeenpaged; /* if set, indicates pager has cleaned pages associated with this file */
77 void * cl_scmap; /* pointer to sparse cluster map */
78 int cl_scdirty; /* number of dirty pages in the sparse cluster map */
79 int cl_number; /* number of packed write behind clusters currently valid */
80 struct cl_wextent cl_clusters[MAX_CLUSTERS]; /* packed write behind clusters */
81 };
82
83
84 /*
85 * The following data structure keeps the information to associate
86 * a vnode to the correspondig VM objects.
87 */
88 struct ubc_info {
89 memory_object_t ui_pager; /* pager */
90 memory_object_control_t ui_control; /* VM control for the pager */
91 long ui_flags; /* flags */
92 vnode_t *ui_vnode; /* The vnode for this ubc_info */
93 ucred_t *ui_ucred; /* holds credentials for NFS paging */
94 off_t ui_size; /* file size for the vnode */
95
96 struct cl_readahead *cl_rahead; /* cluster read ahead context */
97 struct cl_writebehind *cl_wbehind; /* cluster write behind context */
98 };
99
100 /* Defines for ui_flags */
101 #define UI_NONE 0x00000000 /* none */
102 #define UI_HASPAGER 0x00000001 /* has a pager associated */
103 #define UI_INITED 0x00000002 /* newly initialized vnode */
104 #define UI_HASOBJREF 0x00000004 /* hold a reference on object */
105 #define UI_WASMAPPED 0x00000008 /* vnode was mapped */
106 #define UI_ISMAPPED 0x00000010 /* vnode is currently mapped */
107
108 /*
109 * exported primitives for loadable file systems.
110 */
111
112 __BEGIN_DECLS
113 __private_extern__ int ubc_umount(struct mount *mp);
114 __private_extern__ void ubc_unmountall(void);
115 __private_extern__ memory_object_t ubc_getpager(struct vnode *);
116 __private_extern__ int ubc_map(struct vnode *, int);
117 __private_extern__ int ubc_destroy_named(struct vnode *);
118
119 /* internal only */
120 __private_extern__ void cluster_release(struct ubc_info *);
121
122
123 /* Flags for ubc_getobject() */
124 #define UBC_FLAGS_NONE 0x0000
125 #define UBC_HOLDOBJECT 0x0001
126 #define UBC_FOR_PAGEOUT 0x0002
127
128 memory_object_control_t ubc_getobject(struct vnode *, int);
129
130 int ubc_info_init(struct vnode *);
131 void ubc_info_deallocate (struct ubc_info *);
132
133 int ubc_isinuse(struct vnode *, int);
134
135 int ubc_page_op(vnode_t, off_t, int, ppnum_t *, int *);
136 int ubc_range_op(vnode_t, off_t, off_t, int, int *);
137
138
139 int cluster_copy_upl_data(struct uio *, upl_t, int, int);
140 int cluster_copy_ubc_data(vnode_t, struct uio *, int *, int);
141
142
143 int UBCINFOMISSING(vnode_t);
144 int UBCINFORECLAIMED(vnode_t);
145 int UBCINFOEXISTS(vnode_t);
146 int UBCISVALID(vnode_t);
147 int UBCINVALID(vnode_t);
148 int UBCINFOCHECK(const char *, vnode_t);
149
150 __END_DECLS
151
152
153 #endif /* _SYS_UBC_INTERNAL_H_ */
154