// IEMappedFile.h by Monty Zukowski 1/20/93 version 1.0
//Copyright 1993 Intuitive Edge
//You are free to use and modify this as long as you acknowledge me in your
//program somewhere
//email me: monty@IntuitiveEdge.com, I'm interested in uses and modifications.
/* An IEMappedFile creates an fd and memory map of a given filename.
It also keeps track of the size, last modify time and filename.
Instances are created with the +newForFilename: method to insure that
only one instance is created for a given filename. The fd is created
with open(filename,O_RDONLY,mode).
The -dataUpdated method first checks to see if the file has been
modified and if it has, it remaps the fd. It is not clear in the docs,
but I think the virtual memory handler checks to see if the file has
changed and pages in memory if it has. The 3.0 OS release notes say:
• If a file is being written on client A, and read on client B, changes appended to the file from client A after client B opens the file will not be seen by client B. This is only true for the read() system call. Changes can be seen if the file is remapped via the map_fd() system call. Use map_fd(), and check for changes to the file via fstat(). If the file has changed, remap.
The memory is mapped with map_fd(), and is copy-on-write. To change
the file, write() must be used. This object does not support changing the
memory. Note that if you do try to write to the memory, only as much
memory as needed for the file size when opened has been allocated.
This object is meant to be used for read only files, which is why
it keeps track of the names of files which are open. If you need to write
to the memory and then write it to disk, consider using NXMapFile() and
NXSaveToFile(), or look at the source and write your own object to use
map_fd().
Notes on using:
-read: can return an inactivated object, as can -dataUpdated if there
are any problems with the file. Always check return values from -data
and -dataUpdated! If the file changes and you use -data and not
-dataUpdated or the file changes before you check with -dataUpdated again,
the result depends on what map_fd() does in those cases, which does
not seem to be documented in the manual.
IEMappedFile.
+newForFilename: will never return an inactivated object. If an
instance already exists for the filename, it will be returned. So even if
you use the +newForFilename method, use the -dataUpdated method to be
sure that it is in sync.
*/
#import <objc/Object.h>
#import <objc/Storage.h>
#import <objc/hashtable.h>
#import <objc/HashTable.h>
#import <sys/types.h>
@interface IEMappedFile:Object
{
int fd;
int size;
NXAtom name;
void *data;
time_t lastModifyTime;
}
+_removeFromHashTable:(IEMappedFile *)obj;
+_addName:(NXAtom) theName andObject:obj;
+(HashTable *) instances;
+newForFilename:(const char *) filename;
-free;
-(const void *) data;
-(const void *) dataUpdated;//use if file may be appended to