vac.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct VacFs VacFs;
  10. typedef struct VacDir VacDir;
  11. typedef struct VacFile VacFile;
  12. typedef struct VacDirEnum VacDirEnum;
  13. #pragma incomplete VacFile
  14. #pragma incomplete VacDirEnum
  15. /*
  16. * Mode bits
  17. */
  18. enum
  19. {
  20. ModeOtherExec = (1<<0),
  21. ModeOtherWrite = (1<<1),
  22. ModeOtherRead = (1<<2),
  23. ModeGroupExec = (1<<3),
  24. ModeGroupWrite = (1<<4),
  25. ModeGroupRead = (1<<5),
  26. ModeOwnerExec = (1<<6),
  27. ModeOwnerWrite = (1<<7),
  28. ModeOwnerRead = (1<<8),
  29. ModeSticky = (1<<9),
  30. ModeSetUid = (1<<10),
  31. ModeSetGid = (1<<11),
  32. ModeAppend = (1<<12), /* append only file */
  33. ModeExclusive = (1<<13), /* lock file - plan 9 */
  34. ModeLink = (1<<14), /* sym link */
  35. ModeDir = (1<<15), /* duplicate of DirEntry */
  36. ModeHidden = (1<<16), /* MS-DOS */
  37. ModeSystem = (1<<17), /* MS-DOS */
  38. ModeArchive = (1<<18), /* MS-DOS */
  39. ModeTemporary = (1<<19), /* MS-DOS */
  40. ModeSnapshot = (1<<20), /* read only snapshot */
  41. ModeDevice = (1<<21), /* Unix device */
  42. ModeNamedPipe = (1<<22) /* Unix named pipe */
  43. };
  44. enum
  45. {
  46. MetaMagic = 0x5656fc79,
  47. MetaHeaderSize = 12,
  48. MetaIndexSize = 4,
  49. IndexEntrySize = 8,
  50. DirMagic = 0x1c4d9072
  51. };
  52. enum
  53. {
  54. DirPlan9Entry = 1, /* not valid in version >= 9 */
  55. DirNTEntry, /* not valid in version >= 9 */
  56. DirQidSpaceEntry,
  57. DirGenEntry /* not valid in version >= 9 */
  58. };
  59. struct VacDir
  60. {
  61. char *elem; /* path element */
  62. uint32_t entry; /* entry in directory for data */
  63. uint32_t gen; /* generation of data entry */
  64. uint32_t mentry; /* entry in directory for meta */
  65. uint32_t mgen; /* generation of meta entry */
  66. uvlong size; /* size of file */
  67. uvlong qid; /* unique file id */
  68. char *uid; /* owner id */
  69. char *gid; /* group id */
  70. char *mid; /* last modified by */
  71. uint32_t mtime; /* last modified time */
  72. uint32_t mcount; /* number of modifications: can wrap! */
  73. uint32_t ctime; /* directory entry last changed */
  74. uint32_t atime; /* last time accessed */
  75. uint32_t mode; /* various mode bits */
  76. /* plan 9 */
  77. int plan9;
  78. uvlong p9path;
  79. uint32_t p9version;
  80. /* sub space of qid */
  81. int qidspace;
  82. uvlong qidoffset; /* qid offset */
  83. uvlong qidmax; /* qid maximum */
  84. };
  85. struct VacFs
  86. {
  87. char name[128];
  88. uchar score[VtScoreSize];
  89. VacFile *root;
  90. VtConn *z;
  91. int mode;
  92. int bsize;
  93. uvlong qid;
  94. VtCache *cache;
  95. };
  96. VacFs *vacfsopen(VtConn *z, char *file, int mode, int ncache);
  97. VacFs *vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache);
  98. VacFs *vacfscreate(VtConn *z, int bsize, int ncache);
  99. void vacfsclose(VacFs *fs);
  100. int vacfssync(VacFs *fs);
  101. int vacfssnapshot(VacFs *fs, char *src, char *dst);
  102. int vacfsgetscore(VacFs *fs, u8int *score);
  103. int vacfsgetmaxqid(VacFs*, uvlong*);
  104. void vacfsjumpqid(VacFs*, uvlong);
  105. VacFile *vacfsgetroot(VacFs *fs);
  106. VacFile *vacfileopen(VacFs *fs, char *path);
  107. VacFile *vacfilecreate(VacFile *file, char *elem, uint32_t perm);
  108. VacFile *vacfilewalk(VacFile *file, char *elem);
  109. int vacfileremove(VacFile *file);
  110. int vacfileread(VacFile *file, void *buf, int n, vlong offset);
  111. int vacfileblockscore(VacFile *file, u32int, u8int*);
  112. int vacfilewrite(VacFile *file, void *buf, int n, vlong offset);
  113. uvlong vacfilegetid(VacFile *file);
  114. uint32_t vacfilegetmcount(VacFile *file);
  115. int vacfileisdir(VacFile *file);
  116. int vacfileisroot(VacFile *file);
  117. uint32_t vacfilegetmode(VacFile *file);
  118. int vacfilegetsize(VacFile *file, uvlong *size);
  119. int vacfilegetdir(VacFile *file, VacDir *dir);
  120. int vacfilesetdir(VacFile *file, VacDir *dir);
  121. VacFile *vacfilegetparent(VacFile *file);
  122. int vacfileflush(VacFile*, int);
  123. VacFile *vacfileincref(VacFile*);
  124. int vacfiledecref(VacFile*);
  125. int vacfilesetsize(VacFile *f, uvlong size);
  126. int vacfilegetentries(VacFile *f, VtEntry *e, VtEntry *me);
  127. int vacfilesetentries(VacFile *f, VtEntry *e, VtEntry *me);
  128. void vdcleanup(VacDir *dir);
  129. void vdcopy(VacDir *dst, VacDir *src);
  130. int vacfilesetqidspace(VacFile*, u64int, u64int);
  131. uvlong vacfilegetqidoffset(VacFile*);
  132. VacDirEnum *vdeopen(VacFile*);
  133. int vderead(VacDirEnum*, VacDir *);
  134. void vdeclose(VacDirEnum*);
  135. int vdeunread(VacDirEnum*);
  136. int vacfiledsize(VacFile *f);
  137. int sha1matches(VacFile *f, uint32_t b, uchar *buf, int n);