1/* 2 * Copyright (c) 2000-2004 Apple Computer, 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 * Mach Operating System 30 * Copyright (c) 1987 Carnegie-Mellon University 31 * All rights reserved. The CMU software License Agreement specifies 32 * the terms and conditions for use and redistribution. 33 */ 34 35#ifndef _VNODE_PAGER_ 36#define _VNODE_PAGER_ 1 37 38#include <mach/kern_return.h> 39#include <sys/types.h> 40#include <kern/queue.h> 41 42#ifdef KERNEL 43#include <mach/boolean.h> 44#include <mach/memory_object_types.h> 45#include <mach/vm_types.h> 46#include <vm/vm_protos.h> 47#include <vm/vm_pager.h> 48 49/* 50 * Vstructs are the internal (to us) description of a unit of backing store. 51 * The are the link between memory objects and the backing store they represent. 52 * For the vnode pager, backing store comes in two flavors: normal files and 53 * swap files. 54 * 55 * For objects that page to and from normal files (e.g. objects that represent 56 * program text segments), we maintain some simple parameters that allow us to 57 * access the file's contents directly through the vnode interface. 58 * 59 * Data for objects without associated vnodes is maintained in the swap files. 60 * Each object that uses one of these as backing store has a vstruct indicating 61 * the swap file of preference (vs_pf) and a mapping between contiguous object 62 * offsets and swap file offsets (vs_pmap). Each entry in this mapping specifies 63 * the pager file to use, and the offset of the page in that pager file. These 64 * mapping entries are of type pfMapEntry. 65 */ 66 67/* 68 * Pager file structure. One per swap file. 69 */ 70typedef struct pager_file { 71 queue_chain_t pf_chain; /* link to other paging files */ 72 struct vnode *pf_vp; /* vnode of paging file */ 73 u_int pf_count; /* Number of vstruct using this file */ 74 u_char *pf_bmap; /* Map of used blocks */ 75 long pf_npgs; /* Size of file in pages */ 76 long pf_pfree; /* Number of unused pages */ 77 long pf_lowat; /* Low water page */ 78 long pf_hipage; /* Highest page allocated */ 79 long pf_hint; /* Lowest page unallocated */ 80 char *pf_name; /* Filename of this file */ 81 boolean_t pf_prefer; 82 int pf_index; /* index into the pager_file array */ 83 void * pf_lock; /* Lock for alloc and dealloc */ 84} *pager_file_t; 85 86#define PAGER_FILE_NULL (pager_file_t) 0 87 88#define MAXPAGERFILES 16 89 90#define MAX_BACKING_STORE 100 91 92struct bs_map { 93 struct vnode *vp; 94 void *bs; 95}; 96extern struct bs_map bs_port_table[]; 97 98 99 100/* 101 * Pager file data structures. 102 */ 103#define INDEX_NULL 0 104typedef struct { 105 unsigned int index:8; /* paging file this block is in */ 106 unsigned int offset:24; /* page number where block resides */ 107} pf_entry; 108 109typedef enum { 110 IS_INODE, /* Local disk */ 111 IS_RNODE /* NFS */ 112 } vpager_fstype; 113 114/* 115 * Basic vnode pager structure. One per object, backing-store pair. 116 */ 117typedef struct vstruct { 118 boolean_t is_device; /* Must be first - see vm_pager.h */ 119 pager_file_t vs_pf; /* Pager file this uses */ 120 pf_entry **vs_pmap; /* Map of pages into paging file */ 121 unsigned int 122 /* boolean_t */ vs_swapfile:1; /* vnode is a swapfile */ 123 short vs_count; /* use count */ 124 int vs_size; /* size of this chunk in pages*/ 125 struct vnode *vs_vp; /* vnode to page to */ 126} *vnode_pager_t; 127 128#define VNODE_PAGER_NULL ((vnode_pager_t) 0) 129 130#endif /* KERNEL */ 131 132#endif /* _VNODE_PAGER_ */ 133