Blob


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