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