1 /* 2 * fundamental constants 3 */ 4 #define ERRREC 64 /* size of a ascii erro message */ 5 #define DIRREC 116 /* size of a directory ascii record */ 6 #define NAMELEN 28 /* size of names */ 7 #define NDBLOCK 6 /* number of direct blocks in Dentry */ 8 #define MAXDAT 8192 /* max allowable data message */ 9 #define MAXMSG 128 /* max size protocol message sans data */ 10 #define NTLOCK 200 /* number of active file Tlocks */ 11 12 #include <auth.h> 13 14 typedef struct Fbuf Fbuf; 15 typedef struct Super1 Super1; 16 typedef struct Superb Superb; 17 typedef struct Qid Qid; 18 typedef struct Dentry Dentry; 19 typedef struct Tag Tag; 20 21 typedef struct Device Device; 22 typedef struct Fcall Fcall; 23 typedef struct File File; 24 typedef struct Filsys Filsys; 25 typedef struct Filta Filta; 26 typedef struct Filter Filter; 27 typedef ulong Float; 28 typedef struct Hiob Hiob; 29 typedef struct Iobuf Iobuf; 30 typedef struct P9call P9call; 31 typedef struct Tlock Tlock; 32 typedef struct Tm Tm; 33 typedef struct Uid Uid; 34 typedef struct Wpath Wpath; 35 36 /* 37 * DONT TOUCH -- data structures stored on disk 38 */ 39 /* DONT TOUCH, this is the disk structure */ 40 struct Qid 41 { 42 long path; 43 long version; 44 }; 45 46 /* DONT TOUCH, this is the disk structure */ 47 struct Dentry 48 { 49 char name[NAMELEN]; 50 short uid; 51 short gid; 52 ushort mode; 53 #define DALLOC 0x8000 54 #define DDIR 0x4000 55 #define DAPND 0x2000 56 #define DLOCK 0x1000 57 #define DREAD 0x4 58 #define DWRITE 0x2 59 #define DEXEC 0x1 60 Qid qid; 61 long size; 62 long dblock[NDBLOCK]; 63 long iblock; 64 long diblock; 65 long atime; 66 long mtime; 67 }; 68 69 /* DONT TOUCH, this is the disk structure */ 70 struct Tag 71 { 72 short pad; 73 short tag; 74 long path; 75 }; 76 77 /* DONT TOUCH, this is the disk structure */ 78 struct Super1 79 { 80 long fstart; 81 long fsize; 82 long tfree; 83 long qidgen; /* generator for unique ids */ 84 85 long fsok; /* file system ok */ 86 87 /* 88 * garbage for WWC device 89 */ 90 long roraddr; /* dump root addr */ 91 long last; /* last super block addr */ 92 long next; /* next super block addr */ 93 }; 94 95 /* DONT TOUCH, this is the disk structure */ 96 struct Fbuf 97 { 98 long nfree; 99 long free[1]; /* changes based on BUFSIZE */ 100 }; 101 102 /* DONT TOUCH, this is the disk structure */ 103 struct Superb 104 { 105 Super1; 106 Fbuf fbuf; 107 }; 108 109 struct Device 110 { 111 char type; 112 char ctrl; 113 char unit; 114 char part; 115 }; 116 117 /* 118 * for load stats 119 */ 120 struct Filter 121 { 122 ulong count; /* count and old count kept separate */ 123 ulong oldcount; /* so interrput can read them */ 124 Float filter[3]; /* filters for 1m 10m 100m */ 125 }; 126 127 struct Filta 128 { 129 Filter* f; 130 int scale; 131 }; 132 133 /* 134 * array of qids that are locked 135 */ 136 struct Tlock 137 { 138 Device dev; 139 long time; 140 long qpath; 141 File* file; 142 }; 143 144 struct File 145 { 146 QLock; 147 Qid qid; 148 Wpath* wpath; 149 Chan* cp; /* null means a free slot */ 150 Tlock* tlock; /* if file is locked */ 151 File* next; /* in cp->flist */ 152 Filsys* fs; 153 long addr; 154 long slot; 155 long lastra; /* read ahead address */ 156 short fid; 157 short uid; 158 char open; 159 #define FREAD 1 160 #define FWRITE 2 161 #define FREMOV 4 162 }; 163 164 struct Filsys 165 { 166 char* name; /* name of filsys */ 167 Device dev; /* device that filsys is on */ 168 int flags; 169 #define FREAM (1<<1) /* mkfs */ 170 #define FRECOVER (1<<2) /* install last dump */ 171 }; 172 173 struct Hiob 174 { 175 Iobuf* link; 176 Lock; 177 }; 178 179 struct Iobuf 180 { 181 QLock; 182 Device dev; 183 Iobuf *next; /* for hash */ 184 Iobuf *fore; /* for lru */ 185 Iobuf *back; /* for lru */ 186 char *iobuf; /* only active while locked */ 187 char *xiobuf; /* "real" buffer pointer */ 188 long addr; 189 int flags; 190 }; 191 192 struct P9call 193 { 194 uchar calln; 195 uchar rxflag; 196 short msize; 197 void (*func)(Chan*, int); 198 }; 199 200 struct Tm 201 { 202 /* see ctime(3) */ 203 int sec; 204 int min; 205 int hour; 206 int mday; 207 int mon; 208 int year; 209 int wday; 210 int yday; 211 int isdst; 212 }; 213 214 struct Uid 215 { 216 short uid; /* user id */ 217 short lead; /* leader of group */ 218 short offset; /* byte offset in uidspace */ 219 }; 220 221 struct Wpath 222 { 223 Wpath *up; /* pointer upwards in path */ 224 long addr; /* directory entry addr */ 225 long slot; /* directory entry slot */ 226 short refs; /* number of files using this structure */ 227 }; 228 229 struct Fcall 230 { 231 char type; 232 short fid; 233 short err; 234 short tag; 235 union 236 { 237 struct 238 { 239 short uid; /* T-Userstr */ 240 short oldtag; /* T-nFlush */ 241 Qid qid; /* R-Attach, R-Clwalk, R-Walk, 242 * R-Open, R-Create */ 243 char rauth[AUTHENTLEN]; /* R-attach */ 244 }; 245 struct 246 { 247 char uname[NAMELEN]; /* T-nAttach */ 248 char aname[NAMELEN]; /* T-nAttach */ 249 char ticket[TICKETLEN]; /* T-attach */ 250 char auth[AUTHENTLEN]; /* T-attach */ 251 }; 252 struct 253 { 254 char ename[ERRREC]; /* R-nError */ 255 char chal[CHALLEN]; /* T-session, R-session */ 256 char authid[NAMELEN]; /* R-session */ 257 char authdom[DOMLEN]; /* R-session */ 258 }; 259 struct 260 { 261 char name[NAMELEN]; /* T-Walk, T-Clwalk, T-Create, T-Remove */ 262 long perm; /* T-Create */ 263 short newfid; /* T-Clone, T-Clwalk */ 264 char mode; /* T-Create, T-Open */ 265 }; 266 struct 267 { 268 long offset; /* T-Read, T-Write */ 269 long count; /* T-Read, T-Write, R-Read */ 270 char* data; /* T-Write, R-Read */ 271 }; 272 struct 273 { 274 char stat[DIRREC]; /* T-Wstat, R-Stat */ 275 }; 276 }; 277 }; 278 279 #define MAXFDATA 8192 280 281 enum 282 { 283 Tmux = 48, 284 Rmux, /* illegal */ 285 Tnop = 50, 286 Rnop, 287 Tosession = 52, /* illegal */ 288 Rosession, /* illegal */ 289 Terror = 54, /* illegal */ 290 Rerror, 291 Tflush = 56, 292 Rflush, 293 Toattach = 58, /* illegal */ 294 Roattach, /* illegal */ 295 Tclone = 60, 296 Rclone, 297 Twalk = 62, 298 Rwalk, 299 Topen = 64, 300 Ropen, 301 Tcreate = 66, 302 Rcreate, 303 Tread = 68, 304 Rread, 305 Twrite = 70, 306 Rwrite, 307 Tclunk = 72, 308 Rclunk, 309 Tremove = 74, 310 Rremove, 311 Tstat = 76, 312 Rstat, 313 Twstat = 78, 314 Rwstat, 315 Tclwalk = 80, 316 Rclwalk, 317 Tauth = 82, /* illegal */ 318 Rauth, /* illegal */ 319 Tsession = 84, 320 Rsession, 321 Tattach = 86, 322 Rattach, 323 324 MAXSYSCALL 325 }; 326 327 /* 328 * error codes generated from the file server 329 */ 330 enum 331 { 332 Ebadspc = 1, 333 Efid, 334 Echar, 335 Eopen, 336 Ecount, 337 Ealloc, 338 Eqid, 339 Eauth, 340 Eaccess, 341 Eentry, 342 Emode, 343 Edir1, 344 Edir2, 345 Ephase, 346 Eexist, 347 Edot, 348 Eempty, 349 Ebadu, 350 Enotu, 351 Enotg, 352 Ename, 353 Ewalk, 354 Eronly, 355 Efull, 356 Eoffset, 357 Elocked, 358 Ebroken, 359 360 MAXERR 361 }; 362 363 /* 364 * devnone block numbers 365 */ 366 enum 367 { 368 Cwio1 = 1, 369 Cwio2, 370 Cwxx1, 371 Cwxx2, 372 Cwxx3, 373 Cwxx4, 374 Cwdump1, 375 Cwdump2, 376 Cuidbuf, 377 }; 378 379 /* 380 * tags on block 381 */ 382 enum 383 { 384 Tnone = 0, 385 Tsuper, /* the super block */ 386 Tdir, /* directory contents */ 387 Tind1, /* points to blocks */ 388 Tind2, /* points to Tind1 */ 389 Tfile, /* file contents */ 390 Tfree, /* in free list */ 391 Tbuck, /* cache fs bucket */ 392 Tvirgo, /* fake worm virgin bits */ 393 Tcache, /* cw cache things */ 394 MAXTAG 395 }; 396 397 /* 398 * flags to getbuf 399 */ 400 enum 401 { 402 Bread = (1<<0), /* read the block if miss */ 403 Bprobe = (1<<1), /* return null if miss */ 404 Bmod = (1<<2), /* set modified bit in buffer */ 405 Bimm = (1<<3), /* set immediate bit in buffer */ 406 Bres = (1<<4), /* reserved, never renammed */ 407 }; 408 409 /* 410 * open modes passed into P9 open/create 411 */ 412 enum 413 { 414 MREAD = 0, 415 MWRITE, 416 MBOTH, 417 MEXEC, 418 MTRUNC = (1<<4), /* truncate on open */ 419 MCEXEC = (1<<5), /* close on exec (host) */ 420 MRCLOSE = (1<<6), /* remove on close */ 421 }; 422 423 /* 424 * check flags 425 */ 426 enum 427 { 428 Crdall = (1<<0), /* read all files */ 429 Ctag = (1<<1), /* rebuild tags */ 430 Cpfile = (1<<2), /* print files */ 431 Cpdir = (1<<3), /* print directories */ 432 Cfree = (1<<4), /* rebuild free list */ 433 Cream = (1<<6), /* clear all bad tags */ 434 Cbad = (1<<7), /* clear all bad blocks */ 435 Ctouch = (1<<8), /* touch old dir and indir */ 436 Cquiet = (1<<9), /* report just nasty things */ 437 }; 438 439 /* 440 * buffer size variables 441 */ 442 extern int RBUFSIZE; 443 extern int BUFSIZE; 444 extern int DIRPERBUF; 445 extern int INDPERBUF; 446 extern int INDPERBUF2; 447 extern int FEPERBUF; 448