1 /* $MirOS: contrib/code/jupp/vfile.h,v 1.3 2012/06/08 16:55:29 tg Exp $ */
3 * Software virtual memory system
5 * (C) 1992 Joseph H. Allen
7 * This file is part of JOE (Joe's Own Editor)
10 #define _JOE_VFILE_H 1
17 * Should we remove size checking from rc()? Would make it faster...
19 * Should be able to open more than one stream on a file so that vseek
20 * doesn't have to get called so much when more than one user is involed
22 * Also should have dupopen call to make more streams for a file
26 * Should have a version which will use memory mapped files, if they exist
29 * Would be nice if we could transparantly open non-file streams and pipes.
30 * Should there be an buffering option for that? So we can seek on pipes to
31 * get previously read data?
34 extern unsigned char *vbase; /* Data first entry in vheader refers to */
35 extern VPAGE **vheaders; /* Array of headers */
39 * Open a temporary virtual file. File goes away when closed. No actual
40 * file is generated if everything fits in memory.
42 VFILE *vtmp PARAMS((void));
44 /* long vsize(VFILE *);
49 #define vsize(vfile) \
51 (vfile)->left<(vfile)->lv ? \
52 (vfile)->alloc+(vfile)->lv-(vfile)->left \
57 /* void vclose(VFILE *vfile);
61 void vclose PARAMS((VFILE *vfile));
65 * Write all changed pages to the disk
68 void vflsh PARAMS((void));
70 /* void vflshf(VFILE *vfile);
72 * Write changed pages for a specific file to the disk
75 void vflshf PARAMS((VFILE *vfile));
77 /* char *vlock(VFILE *vfile,long addr);
79 * Translate virtual address to physical address. 'addr' does not have
80 * to be on any particular alignment, but if you wish to access more than
81 * a single byte, you have to be aware of where page boundaries are (virtual
82 * address multiples of PGSIZE).
84 * The page containing the data is locked in memory (so that it won't be
85 * freed or used for something else) until 'vunlock' is used.
87 * Warning: If you allocate more than one page and use (change) them out of
88 * order, vflsh will screw up if writing past the end of a file is illegal
89 * in the host filesystem.
91 * Also: This function does not allocate space to the file. Use valloc()
92 * for that. You can vlock() pages past the allocated size of the file, but
93 * be careful when you do this (you normally shouldn't- the only time you
94 * ever might want to is to implement your own version of valloc()).
97 unsigned char *vlock PARAMS((VFILE *vfile, unsigned long addr));
99 /* VPAGE *vheader(char *);
100 * Return address of page header for given page
103 #define vheader(p) (vheaders[(physical((unsigned char *)(p))-physical(vbase))>>LPGSIZE])
105 /* void vchanged(char *);
107 * Indicate that a vpage was changed so that it will be written back to the
108 * file. Any physical address which falls within the page may be given.
111 #define vchanged(vpage) ( vheader(vpage)->dirty=1 )
113 /* void vunlock(char *);
114 * Unreference a vpage (call one vunlock for every vlock)
115 * Any physical address which falls within the page may be given.
118 #define vunlock(vpage) ( --vheader(vpage)->count )
120 /* void vupcount(char *);
121 * Indicate that another reference is being made to a vpage
124 #define vupcount(vpage) ( ++vheader(vpage)->count )
126 /* long valloc(VFILE *vfile,long size);
128 * Allocate space at end of file
130 * Returns file address of beginning of allocated space
133 long my_valloc PARAMS((VFILE *vfile, long int size));