/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* memfile.c: Contains the functions for handling blocks of memory which can
* be stored in a file. This is the implementation of a sort of virtual memory.
*
* A memfile consists of a sequence of blocks. The blocks numbered from 0
* upwards have been assigned a place in the actual file. The block number
* is equal to the page number in the file. The
* blocks with negative numbers are currently in memory only. They can be
* assigned a place in the file when too much memory is being used. At that
* moment they get a new, positive, number. A list is used for translation of
* negative to positive numbers.
*
* The size of a block is a multiple of a page size, normally the page size of
* the device the file is on. Most blocks are 1 page long. A Block of multiple
* pages is used for a line that does not fit in a single page.
*
* Each block can be in memory and/or in a file. The block stays in memory
* as long as it is locked. If it is no longer locked it can be swapped out to
* the file. It is only written to the file if it has been changed.
*
* Under normal operation the file is created when opening the memory file and
* deleted when closing the memory file. Only with recovery an existing memory
* file is opened.
*/
#include "vim.h"
/*
* Some systems have the page size in statfs.f_bsize, some in stat.st_blksize
*/
#ifdef HAVE_ST_BLKSIZE
# define STATFS stat
# define F_BSIZE st_blksize
# define fstatfs(fd, buf, len, nul) mch_fstat((fd), (buf))
#else
# ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
# define STATFS statfs
# define F_BSIZE f_bsize
# endif
#endif
/*
* for Amiga Dos 2.0x we use Flush
*/
#ifdef AMIGA
# ifdef FEAT_ARP
extern int dos2; // this is in os_amiga.c
# endif
# ifdef SASC
# include <proto/dos.h>
# include <ios1.h> // for chkufb()
# endif
#endif
#define MEMFILE_PAGE_SIZE 4096 // default page size
static long_u total_mem_used = 0; // total memory used for memfiles
static void mf_ins_hash(memfile_T *, bhdr_T