1 /* 2 * fscfs 3 */ 4 5 typedef struct Attach Attach; 6 typedef struct Auth Auth; 7 typedef struct Data Data; 8 typedef struct Dref Dref; 9 typedef struct Fid Fid; 10 typedef struct File File; 11 typedef struct Host Host; 12 typedef struct Path Path; 13 typedef struct P9fs P9fs; 14 typedef struct Req Req; 15 typedef struct SFid SFid; 16 typedef struct String String; 17 18 #pragma incomplete P9fs 19 20 typedef u32int Tag; 21 22 struct String 23 { 24 Ref; 25 int len; 26 char* s; 27 String* next; /* hash chain */ 28 }; 29 30 struct Dref 31 { 32 int inuse; /* reference count locally */ 33 int faruse; /* remote references */ 34 Tag tag; /* remote object tag */ 35 Host* loc; /* location of object (nil if here) */ 36 Host* src; /* source of object reference (nil if here) */ 37 int depth; /* 0 if here or loc == src */ 38 int weight; /* proxy weight */ 39 }; 40 41 enum{ 42 FidHash= 1<<8, 43 }; 44 45 struct Attach 46 { 47 /* parameters and result of a Tattach */ 48 u32int fid; 49 char* uname; 50 char* aname; 51 Path* root; /* qid from attach is root->qid, root->sfid is server fid */ 52 Attach* next; 53 }; 54 55 struct Auth 56 { 57 /* could probably use a Ref */ 58 SFid* afid; 59 char* uname; 60 char* aname; 61 char* error; 62 Auth* next; 63 int active; /* active until attached, with or without success */ 64 Req* pending; /* later Auth requests with same parameters, and flush requests */ 65 }; 66 67 struct Host 68 { 69 Ref; 70 71 QLock; 72 int fd; /* link to host */ 73 char* name; /* symbolic name (mainly for diagnostics) */ 74 Fid* fids[FidHash]; /* fids active for this host */ 75 /* might need per-host auth/attach fid/afid for authentication? */ 76 /* implies separation of fid spaces, and thus separate Fids but not Files and Paths */ 77 }; 78 79 struct Path 80 { 81 Ref; 82 char* name; 83 Qid qid; 84 Path* parent; 85 Path* child; 86 Path* next; /* sibling */ 87 uint nxtime; /* zero (if exists) or last time we checked */ 88 char* inval; /* walk error if invalid */ 89 File* file; /* file data, if open */ 90 SFid* sfid; /* walked to this fid on server */ 91 }; 92 93 struct Data 94 { 95 /* cached portion of a file */ 96 uint min; /* offsets */ 97 uint max; 98 uint size; /* size of buffer (power of 2) */ 99 uchar* base; 100 101 /* LRU stuff */ 102 Data* forw; 103 Data* back; 104 File* owner; 105 uint n; /* index in owner's cache */ 106 }; 107 108 struct SFid 109 { 110 Ref; /* by client fids */ 111 u32int fid; /* fid on server */ 112 SFid* next; /* on free or LRU list */ 113 }; 114 115 struct Fid 116 { 117 u32int fid; /* fid on Host */ 118 Qid qid; 119 Path* path; /* shared data about file */ 120 SFid* opened; /* server fid once opened */ 121 uint mode; /* open mode (OREAD, OWRITE, ORDWR) */ 122 Fid* next; /* in fid hash list */ 123 }; 124 125 struct File 126 { 127 Ref; 128 129 SFid* open[3]; /* cached sfids: OREAD, OWRITE, ORDWR */ 130 131 /* data from Dir */ 132 uint mode; /* permissions */ 133 uint atime; /* last read time */ 134 uint mtime; /* last write time */ 135 u64int length; /* file length from stat or 0 => use clength */ 136 String* uid; /* owner name */ 137 String* gid; /* group name */ 138 String* muid; /* last modifier name */ 139 140 Qid qid; 141 u32int iounit; 142 u64int clength; /* known length in cache */ 143 uint ndata; /* size of cache array */ 144 Data** cached; 145 146 /* Dref for local and remote references */ 147 /* possibly put expired ones on LRU? */ 148 File* next; 149 }; 150 151 struct Req 152 { 153 u32int tag; 154 Fcall t; 155 SFid* fid; /* also afid in Tauth */ 156 SFid* newfid; /* also afid in Tattach */ 157 Fcall r; 158 uchar* buf; 159 uint msize; 160 Req* flush; 161 Req* next; /* in tag list, or flush list of another Req */ 162 }; 163