COMMENT @----------------------------------------------------------------------

	Copyright (c) GeoWorks 1989 -- All Rights Reserved

PROJECT:	PC GEOS

FILE:		vm.def

DECLARER:	Kernel

DESCRIPTION:
	This file defines vmem structures and routines.

	$Id: vm.def,v 1.1 97/04/04 14:23:30 newdeal Exp $

------------------------------------------------------------------------------@

SetDef	__VMEM

StartKernel

global VMLock:far
global VMUnlock:far
global VMAlloc:far
global VMFind:far
global VMFree:far
global VMDirty:far
global VMModifyUserID:far
global VMInfo:far
global VMGetDirtyState:far

global VMGetMapBlock:far
global VMSetMapBlock:far

global VMOpen:far
global VMUpdate:far
global VMClose:far
global VMGetAttributes:far
global VMSetAttributes:far
global VMGrabExclusive:far
global VMReleaseExclusive:far

global VMSetReloc:far

global VMAttach:far
global VMDetach:far

global VMMemBlockToVMBlock:far
global VMVMBlockToMemBlock:far

global VMSave:far
global VMSaveAs:far
global VMRevert:far
global VMCopyVMChain:far
global VMFreeVMChain:far
global VMCompareVMChains:far
global VMCopyVMBlock:far
global VMCheckForModifications:far
global VMPreserveBlocksHandle:far
global VMSetExecThread:far
global VMAllocLMem:far

global VMGetDirtySize:far		;internal (currently Redwood only)
global VMGetUsedSize:far		;internal, used by Redwood

global VMGetHeaderInfo:far

global VMDiscardDirtyBlocks:far

global VMInfoVMChain:far

global VMTestDirtySizeForModeChange:far
global VMSetDirtyLimit:far
global VMEnforceHandleLimits:far
;-

global VMLOCK:far
global VMUNLOCK:far
global VMDIRTY:far
global VMALLOC:far
global VMFIND:far
global VMFREE:far
global VMMODIFYUSERID:far
global VMINFO:far
global VMGETDIRTYSTATE:far
global VMGETMAPBLOCK:far
global VMSETMAPBLOCK:far
global VMGETMAPEXTRA:far
global VMSETMAPEXTRA:far
global VMOPEN:far
global VMUPDATE:far
global VMCLOSE:far
global VMGETATTRIBUTES:far
global VMSETATTRIBUTES:far
global VMGRABEXCLUSIVE:far
global VMRELEASEEXCLUSIVE:far
global VMSETRELOC:far
global VMATTACH:far
global VMDETACH:far
global VMMEMBLOCKTOVMBLOCK:far
global VMVMBLOCKTOMEMBLOCK:far
global VMSAVE:far
global VMSAVEAS:far
global VMREVERT:far
global VMCOPYVMCHAIN:far
global VMFREEVMCHAIN:far
global VMCOMPAREVMCHAINS:far
global VMCOPYVMBLOCK:far
global VMCHECKFORMODIFICATIONS:far
global VMPRESERVEBLOCKSHANDLE:far
global VMSETEXECTHREAD:far
global VMALLOCLMEM:far
global VMGETHEADERINFO:far
global VMDISCARDDIRTYBLOCKS:far
global VMINFOVMCHAIN:far
global VMSETDIRTYLIMIT:far
global VMENFORCEHANDLELIMITS:far

;---------------------------------------------------------------------------
;		Parameters passed to VM routines
;---------------------------------------------------------------------------

;	VMOpen/VMSaveAs operation flag

VMOpenType	etype	byte
VMO_OPEN	enum	VMOpenType	; Open existing
VMO_TEMP_FILE	enum	VMOpenType	; Create temp file -- name is directory
VMO_CREATE	enum	VMOpenType	; Create or open existing
VMO_CREATE_ONLY	enum	VMOpenType	; Create, give error if already exists
VMO_CREATE_TRUNCATE enum VMOpenType	; Create, truncate any existing file

	;
	; Or this flag in to the VMOpenType when calling VMOpen and the
	; file will be created with a name that is compatible with the
	; host file-system. This allows you to create VM files in DOS whose
	; names can be checked without requiring you to actually open the
	; file in order to get at the GEOS name.
	;
VMO_NATIVE_WITH_EXT_ATTRS	equ	0x80


VMAccessFlags	record
    VMAF_FORCE_READ_ONLY:1
	; If set then force the file to be opened read only, even if
	; the default would be to open the file read/write.
    VMAF_FORCE_READ_WRITE:1
	; If set then force the file to be opened read-write, even if
	; the default would be to open the file read-only
    VMAF_ALLOW_SHARED_MEMORY:1
	; If set then use shared memory locally (unless otherwise impossible)
    VMAF_FORCE_DENY_WRITE:1
	; If set then open file deny write
    VMAF_DISALLOW_SHARED_MULTIPLE:1
	; If set then files with the SHARED_MULTIPLE attribute cannot be
	; opened
    VMAF_USE_BLOCK_LEVEL_SYNCHRONIZATION:1
	; If set then block the block level synchronization of the VM
	; code is assumed to be sufficient and the {Start/End}Exclusive
	; mechanism is not used.  This is primarily intended for system
	; software.
    VMAF_FORCE_SHARED_MULTIPLE:1
	; If set, the file is opened as if it had the SHARED_MULTIPLE attribute
	; even if it didn't. This is useful for data VM files that need to
	; always be opened as if SHARED_MULTIPLE were set, even when they're
	; first created. Without this, there's a nasty race condition
	; following the creation where the creator has to mark the file
	; SHARED_MULTIPLE, close it, and reopen it again.
    VMAF_NO_DEMAND_PAGING:1
	; Internal (currently Redwood-only), force demand paging off, so that
	; the entire file is kept in memory.
VMAccessFlags	end

;	VMOpen status codes

VMStatus	etype	word, 256
VM_OPEN_OK_READ_ONLY			enum	VMStatus
VM_OPEN_OK_TEMPLATE			enum	VMStatus
VM_OPEN_OK_READ_WRITE_NOT_SHARED	enum	VMStatus
VM_OPEN_OK_READ_WRITE_SINGLE		enum	VMStatus
VM_OPEN_OK_READ_WRITE_MULTIPLE		enum	VMStatus
VM_OPEN_OK_BLOCK_LEVEL			enum	VMStatus
VM_CREATE_OK				enum	VMStatus

;	VM error codes

VM_FILE_EXISTS				enum	VMStatus
VM_FILE_NOT_FOUND			enum	VMStatus
VM_SHARING_DENIED			enum	VMStatus
VM_OPEN_INVALID_VM_FILE			enum	VMStatus
VM_CANNOT_CREATE			enum	VMStatus
VM_TRUNCATE_FAILED			enum	VMStatus
VM_WRITE_PROTECTED			enum	VMStatus
VM_CANNOT_OPEN_SHARED_MULTIPLE		enum	VMStatus
VM_FILE_FORMAT_MISMATCH			enum	VMStatus

;	VMUpdate status codes

VM_UPDATE_NOTHING_DIRTY			enum	VMStatus
VM_UPDATE_INSUFFICIENT_DISK_SPACE	enum	VMStatus
VM_UPDATE_BLOCK_WAS_LOCKED		enum	VMStatus

;	VMUpdate status codes

VM_DISCARD_CANNOT_DISCARD_BLOCK		enum	VMStatus

;	VM file attributes

VMAttributes	record
    VMA_SYNC_UPDATE:1		;Allow syncronous updates only.  Tells the
				;system that it should not do asynchronous
				;updates of the VM file.  Ie. VMUpdateAndRidBlk
				;will be disabled for blocks belonging to the
				;given file if the blocks are dirty.  Clean VM
				;blocks may always be discarded.
				;Asynchronous updates are active by default
    VMA_BACKUP:1		;Maintain a backup copy of all data. The file
				;can be returned to its backup state by calling
				;VMRevert. The current state is made the backup
				;by calling VMSave.
    VMA_OBJECT_RELOC:1		;Use the built-in object relocation routines
    VMA_TEMP_ASYNC:1		;If set, in temporary Asynchronous update mode
    VMA_NOTIFY_DIRTY:1		;Notify all processes that have the file open
				;the first time a block becomes dirty after a
				;VMOpen, VMUpdate, VMSave or VMRevert
    VMA_NO_DISCARD_IF_IN_USE:1	;Do not discard LMem blocks of type
				;LMEM_TYPE_OBJ_BLOCK if OLMBH_inUseCount is
				;non-zero
    VMA_COMPACT_OBJ_BLOCK:1	;If set, call CompactObjBlock when doing a
				;unreloc before write (object blocks only)
				; -- allows generic objects in a VM file
    VMA_SINGLE_THREAD_ACCESS:1	;If set then only a single thread will access
				;the file, allowing optimizations in VMLock
VMAttributes	end

;
; Attribute bits that *must* be enabled if the file contains object blocks.
;
; In addition, VMA_SYNC_UPDATE is recommended, while VMA_BACKUP and
; VMA_NOTIFY_DIRTY are required if the file is being managed by the
; GenAppDocumentControl object.
;
VMA_OBJECT_ATTRS	equ mask VMA_OBJECT_RELOC or \
			    mask VMA_NO_DISCARD_IF_IN_USE or \
			    mask VMA_SINGLE_THREAD_ACCESS

; VMGrabExclusive return values

VMStartExclusiveReturnValue	etype	word
VMSERV_NO_CHANGES	enum	VMStartExclusiveReturnValue
VMSERV_CHANGES		enum	VMStartExclusiveReturnValue
VMSERV_TIMEOUT		enum	VMStartExclusiveReturnValue


; VM oeprations (for transaction based apps)

VMOperation	etype	word
VMO_READ		enum	VMOperation	;default state -- allows
						;readers not to modify the file
VMO_INTERNAL		enum	VMOperation
VMO_SAVE		enum	VMOperation
VMO_SAVE_AS		enum	VMOperation
VMO_REVERT		enum	VMOperation
VMO_UPDATE		enum	VMOperation
VMO_WRITE		enum	VMOperation	;for apps that don't want
						;their own special codes
VMO_FIRST_APP_CODE	enum	VMOperation, 0x8000

;	Values passed to VM relocation routine

VMRelocType	etype	word
VMRT_UNRELOCATE_BEFORE_WRITE	enum	VMRelocType
VMRT_RELOCATE_AFTER_READ	enum	VMRelocType
VMRT_RELOCATE_AFTER_WRITE	enum	VMRelocType

VMRT_RELOCATE_FROM_RESOURCE	enum	VMRelocType
VMRT_UNRELOCATE_FROM_RESOURCE	enum	VMRelocType

;---------------------------------------------------------------------------
;		System VM ID's
;---------------------------------------------------------------------------

; VM ID's from 0xff00 to 0xffff are reserved for use by the system and
; system libraries

SystemVMID	etype	word, 0xff00

SVMID_RANGE_DBASE	equ	0xff00	;Reserved for DB code

DB_MAP_ID		enum	SystemVMID 	; ID for DB map block
DB_GROUP_ID		enum	SystemVMID	; ID for new DB group
DB_ITEM_BLOCK_ID	enum	SystemVMID	; ID for new DB item block
SVMID_HA_DIR_ID		enum	SystemVMID	; ID for HugeArray dir blocks
SVMID_HA_BLOCK_ID	enum	SystemVMID	; ID for HugeArray data blocks
SVMID_DOCUMENT_NOTES	enum	SystemVMID	; ID for document note block

;---------------------------------------------------------------------------
;		Structure of a VM chain
;---------------------------------------------------------------------------

VM_CHAIN_TREE		equ	0xffff	;VM block handle that indicates
					;that this is a tree block

VMChainLink	struct
    VMCL_next	word
VMChainLink	ends

VMChainTree	struct
    VMCT_meta	VMChainLink
    VMCT_offset	nptr		;offset to first chain
    VMCT_count	word		;number of chains
VMChainTree	ends

EndKernel
