home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / Classes / IEMappedFile / IEMappedFile.h next >
Text File  |  1993-01-26  |  3KB  |  76 lines

  1. // IEMappedFile.h by Monty Zukowski 1/20/93  version 1.0
  2. //Copyright 1993 Intuitive Edge
  3. //You are free to use and modify this as long as you acknowledge me in your 
  4. //program somewhere
  5. //email me: monty@IntuitiveEdge.com, I'm interested in uses and modifications.
  6.  
  7. /*        An IEMappedFile creates an fd and memory map of a given filename.
  8.     It also keeps track of the size, last modify time and filename.
  9.         Instances are created with the +newForFilename: method to insure that
  10.     only one instance is created for a given filename.  The fd is created 
  11.     with open(filename,O_RDONLY,mode).
  12.         The -dataUpdated method first checks to see if the file has been 
  13.     modified and if it has, it remaps the fd.  It is not clear in the docs,
  14.     but I think the virtual memory handler checks to see if the file has 
  15.     changed and pages in memory if it has.  The 3.0 OS release notes say:
  16.     •    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.
  17.  
  18.         The memory is mapped with map_fd(), and is copy-on-write.  To change
  19.     the file, write() must be used.  This object does not support changing the
  20.     memory.  Note that if you do try to write to the memory, only as much
  21.     memory as needed for the file size when opened has been allocated.
  22.         This object is meant to be used for read only files, which is why
  23.     it keeps track of the names of files which are open.  If you need to write
  24.     to the memory and then write it to disk, consider using NXMapFile() and
  25.     NXSaveToFile(), or look at the source and write your own object to use
  26.     map_fd().
  27.     
  28.     Notes on using:
  29.         -read: can return an inactivated object, as can -dataUpdated if there
  30.     are any problems with the file.  Always check return values from -data
  31.     and -dataUpdated!  If the file changes and you use -data and not
  32.     -dataUpdated or the file changes before you check with -dataUpdated again,
  33.     the result depends on what map_fd() does in those cases, which does
  34.     not seem to be documented in the manual.
  35.     IEMappedFile.
  36.         +newForFilename: will never return an inactivated object.  If an
  37.     instance already exists for the filename, it will be returned.  So even if
  38.     you use the +newForFilename method, use the -dataUpdated method to be
  39.     sure that it is in sync.
  40. */
  41.  
  42. #import <objc/Object.h>
  43. #import <objc/Storage.h>
  44. #import <objc/hashtable.h>
  45. #import <objc/HashTable.h>
  46. #import <sys/types.h>
  47.  
  48. @interface IEMappedFile:Object
  49. {
  50.     int    fd;
  51.     int    size;
  52.     NXAtom    name;
  53.     void    *data;
  54.     time_t    lastModifyTime;
  55. }
  56.  
  57. +_removeFromHashTable:(IEMappedFile *)obj;
  58. +_addName:(NXAtom) theName andObject:obj;
  59.  
  60. +(HashTable *) instances;
  61. +newForFilename:(const char *) filename;
  62. -free;
  63.  
  64. -(const void *) data;
  65. -(const void *) dataUpdated;//use if file may be appended to
  66. -(int) fd;
  67. -(int) size;
  68. -(NXAtom) name;
  69. -(time_t) lastModifyTime;
  70.  
  71. -write:(NXTypedStream *) typedStream;
  72. -read:(NXTypedStream *) typedStream;
  73. -finishUnarchiving;
  74. -_initFromName;
  75. -_inactivate;
  76. @end