vac.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. typedef struct DirEntry DirEntry;
  2. typedef struct MetaBlock MetaBlock;
  3. typedef struct MetaEntry MetaEntry;
  4. enum {
  5. MetaMagic = 0x5656fc7a,
  6. MetaHeaderSize = 12,
  7. MetaIndexSize = 4,
  8. IndexEntrySize = 8,
  9. DirMagic = 0x1c4d9072,
  10. };
  11. /*
  12. * Mode bits
  13. */
  14. enum {
  15. ModeOtherExec = (1<<0),
  16. ModeOtherWrite = (1<<1),
  17. ModeOtherRead = (1<<2),
  18. ModeGroupExec = (1<<3),
  19. ModeGroupWrite = (1<<4),
  20. ModeGroupRead = (1<<5),
  21. ModeOwnerExec = (1<<6),
  22. ModeOwnerWrite = (1<<7),
  23. ModeOwnerRead = (1<<8),
  24. ModeSticky = (1<<9),
  25. ModeSetUid = (1<<10),
  26. ModeSetGid = (1<<11),
  27. ModeAppend = (1<<12), /* append only file */
  28. ModeExclusive = (1<<13), /* lock file - plan 9 */
  29. ModeLink = (1<<14), /* sym link */
  30. ModeDir = (1<<15), /* duplicate of DirEntry */
  31. ModeHidden = (1<<16), /* MS-DOS */
  32. ModeSystem = (1<<17), /* MS-DOS */
  33. ModeArchive = (1<<18), /* MS-DOS */
  34. ModeTemporary = (1<<19), /* MS-DOS */
  35. ModeSnapshot = (1<<20), /* read only snapshot */
  36. };
  37. /* optional directory entry fields */
  38. enum {
  39. DePlan9 = 1, /* not valid in version >= 9 */
  40. DeNT, /* not valid in version >= 9 */
  41. DeQidSpace,
  42. DeGen, /* not valid in version >= 9 */
  43. };
  44. struct DirEntry {
  45. char *elem; /* path element */
  46. ulong entry; /* entry in directory for data */
  47. ulong gen; /* generation of data entry */
  48. ulong mentry; /* entry in directory for meta */
  49. ulong mgen; /* generation of meta entry */
  50. uvlong size; /* size of file */
  51. uvlong qid; /* unique file id */
  52. char *uid; /* owner id */
  53. char *gid; /* group id */
  54. char *mid; /* last modified by */
  55. ulong mtime; /* last modified time */
  56. ulong mcount; /* number of modifications: can wrap! */
  57. ulong ctime; /* directory entry last changed */
  58. ulong atime; /* last time accessed */
  59. ulong mode; /* various mode bits */
  60. /* plan 9 */
  61. int plan9;
  62. uvlong p9path;
  63. ulong p9version;
  64. /* sub space of qid */
  65. int qidSpace;
  66. uvlong qidOffset; /* qid offset */
  67. uvlong qidMax; /* qid maximum */
  68. };
  69. struct MetaEntry {
  70. uchar *p;
  71. ushort size;
  72. };
  73. struct MetaBlock {
  74. int maxsize; /* size of block */
  75. int size; /* size used */
  76. int free; /* free space within used size */
  77. int maxindex; /* entries allocated for table */
  78. int nindex; /* amount of table used */
  79. int botch; /* compensate for my stupidity */
  80. uchar *buf;
  81. };
  82. void deCleanup(DirEntry*);
  83. void deCopy(DirEntry*, DirEntry*);
  84. int deSize(DirEntry*);
  85. void dePack(DirEntry*, MetaEntry*);
  86. int deUnpack(DirEntry*, MetaEntry*);
  87. void mbInit(MetaBlock*, uchar*, int, int);
  88. int mbUnpack(MetaBlock*, uchar*, int);
  89. void mbInsert(MetaBlock*, int, MetaEntry*);
  90. void mbDelete(MetaBlock*, int);
  91. void mbPack(MetaBlock*);
  92. uchar *mbAlloc(MetaBlock*, int);
  93. int mbResize(MetaBlock*, MetaEntry*, int);
  94. int mbSearch(MetaBlock*, char*, int*, MetaEntry*);
  95. void meUnpack(MetaEntry*, MetaBlock*, int);