]> git.saurik.com Git - apple/xnu.git/blame - bsd/vm/vnode_pager.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / vm / vnode_pager.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * Mach Operating System
32 * Copyright (c) 1987 Carnegie-Mellon University
33 * All rights reserved. The CMU software License Agreement specifies
34 * the terms and conditions for use and redistribution.
35 */
36
37#ifndef _VNODE_PAGER_
38#define _VNODE_PAGER_ 1
39
40#include <mach/kern_return.h>
41#include <sys/types.h>
42#include <kern/queue.h>
43
44#ifdef KERNEL
1c79356b 45#include <mach/boolean.h>
91447636
A
46#include <mach/memory_object_types.h>
47#include <mach/vm_types.h>
1c79356b
A
48#include <vm/vm_pager.h>
49
91447636 50vm_pager_t vnode_pager_setup(struct vnode *, memory_object_t);
1c79356b
A
51
52/*
53 * Vstructs are the internal (to us) description of a unit of backing store.
54 * The are the link between memory objects and the backing store they represent.
55 * For the vnode pager, backing store comes in two flavors: normal files and
56 * swap files.
57 *
58 * For objects that page to and from normal files (e.g. objects that represent
59 * program text segments), we maintain some simple parameters that allow us to
60 * access the file's contents directly through the vnode interface.
61 *
62 * Data for objects without associated vnodes is maintained in the swap files.
63 * Each object that uses one of these as backing store has a vstruct indicating
64 * the swap file of preference (vs_pf) and a mapping between contiguous object
65 * offsets and swap file offsets (vs_pmap). Each entry in this mapping specifies
66 * the pager file to use, and the offset of the page in that pager file. These
67 * mapping entries are of type pfMapEntry.
68 */
69
70/*
71 * Pager file structure. One per swap file.
72 */
73typedef struct pager_file {
74 queue_chain_t pf_chain; /* link to other paging files */
75 struct vnode *pf_vp; /* vnode of paging file */
76 u_int pf_count; /* Number of vstruct using this file */
77 u_char *pf_bmap; /* Map of used blocks */
78 long pf_npgs; /* Size of file in pages */
79 long pf_pfree; /* Number of unused pages */
80 long pf_lowat; /* Low water page */
81 long pf_hipage; /* Highest page allocated */
82 long pf_hint; /* Lowest page unallocated */
83 char *pf_name; /* Filename of this file */
84 boolean_t pf_prefer;
85 int pf_index; /* index into the pager_file array */
86 void * pf_lock; /* Lock for alloc and dealloc */
87} *pager_file_t;
88
89#define PAGER_FILE_NULL (pager_file_t) 0
90
91#define MAXPAGERFILES 16
92
93#define MAX_BACKING_STORE 100
94
95struct bs_map {
96 struct vnode *vp;
97 void *bs;
98};
91447636 99extern struct bs_map bs_port_table[];
1c79356b
A
100
101
102
103/*
104 * Pager file data structures.
105 */
106#define INDEX_NULL 0
107typedef struct {
108 unsigned int index:8; /* paging file this block is in */
109 unsigned int offset:24; /* page number where block resides */
110} pf_entry;
111
112typedef enum {
113 IS_INODE, /* Local disk */
114 IS_RNODE /* NFS */
115 } vpager_fstype;
116
117/*
118 * Basic vnode pager structure. One per object, backing-store pair.
119 */
120typedef struct vstruct {
121 boolean_t is_device; /* Must be first - see vm_pager.h */
122 pager_file_t vs_pf; /* Pager file this uses */
123 pf_entry **vs_pmap; /* Map of pages into paging file */
124 unsigned int
125 /* boolean_t */ vs_swapfile:1; /* vnode is a swapfile */
126 short vs_count; /* use count */
127 int vs_size; /* size of this chunk in pages*/
128 struct vnode *vs_vp; /* vnode to page to */
129} *vnode_pager_t;
130
131#define VNODE_PAGER_NULL ((vnode_pager_t) 0)
132
133
91447636
A
134pager_return_t vnode_pagein(struct vnode *, upl_t,
135 upl_offset_t, vm_object_offset_t,
136 upl_size_t, int, int *);
137pager_return_t vnode_pageout(struct vnode *, upl_t,
138 upl_offset_t, vm_object_offset_t,
139 upl_size_t, int, int *);
1c79356b 140
91447636
A
141extern vm_object_offset_t vnode_pager_get_filesize(
142 struct vnode *vp);
1c79356b 143
5d5c5d0d
A
144extern kern_return_t vnode_pager_get_pathname(
145 struct vnode *vp,
146 char *pathname,
147 vm_size_t *length_p);
148
149extern kern_return_t vnode_pager_get_filename(
150 struct vnode *vp,
151 char **filename);
152
1c79356b
A
153#endif /* KERNEL */
154
155#endif /* _VNODE_PAGER_ */