1 /* @(#)buffer.h 1.19 18/10/01 Copyright 1984, 1988, 1996-2018 J. Schilling */ 2 /* 3 * Definitions for the paged virtual memory susbsystem of ved 4 * The lower level routines are located in buffer.c, 5 * the higher level routines are located in storage.c 6 * 7 * Copyright (c) 1984, 1988, 1996-2018 J. Schilling 8 */ 9 /* 10 * The contents of this file are subject to the terms of the 11 * Common Development and Distribution License, Version 1.0 only 12 * (the "License"). You may not use this file except in compliance 13 * with the License. 14 * 15 * See the file CDDL.Schily.txt in this distribution for details. 16 * A copy of the CDDL is also available via the Internet at 17 * http://www.opensource.org/licenses/cddl1.txt 18 * 19 * When distributing Covered Code, include this CDDL HEADER in each 20 * file and include the License file CDDL.Schily.txt from this distribution. 21 */ 22 23 #ifndef _BUFFER_H 24 #define _BUFFER_H 25 26 /* 27 * The paged virtual memory subsystem is made of a linked list of headers 28 * that point to buffers which may be in memory or written out into the 29 * backup swap file. 30 * To make it easier to find a buffer that may be swapped out, a most recently 31 * list is maintained. The least recently buffer is used for swapping out. 32 * If the MODIFIED flag is not set, the buffer may simply be thrown away. 33 */ 34 35 #ifndef BUFFERSIZE 36 #ifdef __OLDSIZE 37 #define BUFFERSIZE 1024 /* size of a buffer page in virtual memory */ 38 #else 39 #define BUFFERSIZE 8192 /* size of a buffer page in virtual memory */ 40 #endif 41 #endif 42 43 #if (BUFFERSIZE > 4096) 44 #define MAXBUFFERS 10 /* # of incore buffers in virtual memory */ 45 #else 46 #define MAXBUFFERS 20 /* # of incore buffers in virtual memory */ 47 #endif 48 49 /* 50 * Header for a page in the paged virtual memory. 51 * One header is allocated for each BUFFERSIZE part of the file. 52 * Assuming large file support makes off_t size == 8. 53 * With 1024 bytes/buffer page and 32 bit pointers this uses 34 bytes/header. 54 * This is 34816 bytes per MB of the edited file. 55 * With 8192 bytes/buffer page and 32 bit pointers this uses 34 bytes/header. 56 * This is 4352 bytes per MB of the edited file. 57 * With 8192 bytes/buffer page and 64 bit pointers this uses 60 bytes/header. 58 * This is 7680 bytes per MB of the edited file. 59 */ 60 typedef struct _headr headr_t; 61 struct _headr { 62 headr_t *next; /* next header in the linked list */ 63 headr_t *prev; /* previous header in the linked list */ 64 headr_t *nextr; /* next header in most recently used list */ 65 headr_t *prevr; /* previous header in most recently used list */ 66 Uchar *buf; /* pointer to in-memory buffer */ 67 Uchar *cont; /* pointer to first valid char in the buffer */ 68 off_t fpos; /* position of the buffer in backup file */ 69 short size; /* number of valid characters in the buffer */ 70 short flags; /* flags see below */ 71 }; 72 73 /* 74 * Flags for each header. 75 */ 76 #define INMEMORY 0x0001 /* The buffer for this header is in memory */ 77 #define MODIFIED 0x0002 /* The buffer for this header is modified */ 78 #define INVALID 0x0004 /* This header is deleted (no longer valid) */ 79 #define ONSWAP 0x0008 /* This header was written to the swapfile */ 80 81 /* 82 * buffer.c 83 */ 84 extern void initbuffers __PR((ewin_t *wp, int nbuf)); 85 extern void termbuffers __PR((ewin_t *wp)); 86 extern headr_t *addbuffer __PR((ewin_t *wp, headr_t *prev)); 87 extern headr_t *deletebuffer __PR((ewin_t *wp, headr_t *linkp)); 88 extern void splitbuffer __PR((ewin_t *wp, headr_t *linkp, int pos)); 89 extern void compressbuffer __PR((ewin_t *wp, headr_t *linkp)); 90 extern void readybuffer __PR((ewin_t *wp, headr_t *linkp)); 91 extern void bufdebug __PR((ewin_t *wp)); 92 93 /* 94 * storage.c 95 */ 96 extern void clearifwpos __PR((ewin_t *wp, headr_t *this)); 97 extern void findpos __PR((ewin_t *wp, epos_t pos, 98 headr_t ** returnlink, 99 int *returnpos)); 100 101 #endif /* _BUFFER_H */ 102