Unified · Split
| @@ -39,27 +39,27 @@ enum · 38 unmodified lines | |||
| 39 | Msize = 32768, | 39 | Msize = 32768, |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | void dir2stat(struct stat*, Dir*); | 42 | void dir2stat(struct stat*, Dir*); |
| 43 | Dir *iscached(const char*); | 43 | Dir *iscached(const char*); |
| 44 | Dir *addtocache(const char*); | 44 | Dir *addtocache(const char*); |
| 45 | void clearcache(const char*); | 45 | void clearcache(const char*); |
| 46 | int iscachectl(const char*); | 46 | int iscachectl(const char*); |
| 47 | char *breakpath(char*); | 47 | char *breakpath(char*); |
| 48 | void usage(void); | 48 | void usage(void); |
| 49 | 49 | ||
| 50 | Dir *rootdir; | 50 | Dir *rootdir; |
| 51 | FILE *logfile; | 51 | FILE *logfile; |
| 52 | FFid *rootfid; | 52 | FFid *rootfid; |
| 53 | FFid *authfid; | 53 | FFid *authfid; |
| 54 | int msize; | 54 | int msize; |
| 55 | int infd, outfd; | 55 | int infd, outfd; |
| 56 | int debug; | 56 | int debug; |
| 57 | 57 | ||
| 58 | int | 58 | int |
| 59 | fsstat(const char *path, struct stat *st) | 59 | fsstat(const char *path, struct stat *st) |
| 60 | { | 60 | { |
| 61 | FFid *f; | 61 | FFid *f; |
| 62 | Dir *d; | 62 | Dir *d; |
| 63 | 63 | ||
| 64 | if((f = _9pwalk(path)) == NULL) | 64 | if((f = _9pwalk(path)) == NULL) |
| 65 | return -EIO; | 65 | return -EIO; |
| @@ -76,7 +76,7 @@ fsstat(const char *path, struct stat *st) · 10 unmodified lines | |||
| 76 | int | 76 | int |
| 77 | fsgetattr(const char *path, struct stat *st) | 77 | fsgetattr(const char *path, struct stat *st) |
| 78 | { | 78 | { |
| 79 | Dir *d; | 79 | Dir *d; |
| 80 | 80 | ||
| 81 | if(iscachectl(path)){ | 81 | if(iscachectl(path)){ |
| 82 | st->st_mode = 0666 | S_IFREG; | 82 | st->st_mode = 0666 | S_IFREG; |
| @@ -104,7 +104,7 @@ fsrelease(const char *path, struct fuse_file_info *ffi) · 21 unmodified lines | |||
| 104 | int | 104 | int |
| 105 | fsreleasedir(const char *path, struct fuse_file_info *ffi) | 105 | fsreleasedir(const char *path, struct fuse_file_info *ffi) |
| 106 | { | 106 | { |
| 107 | FFid *f; | 107 | FFid *f; |
| 108 | 108 | ||
| 109 | f = FFIH(ffi); | 109 | f = FFIH(ffi); |
| 110 | if(f == NULL) | 110 | if(f == NULL) |
| @@ -117,8 +117,8 @@ fsreleasedir(const char *path, struct fuse_file_info *ffi) · 6 unmodified lines | |||
| 117 | int | 117 | int |
| 118 | fstruncate(const char *path, off_t off) | 118 | fstruncate(const char *path, off_t off) |
| 119 | { | 119 | { |
| 120 | FFid *f; | 120 | FFid *f; |
| 121 | Dir *d; | 121 | Dir *d; |
| 122 | 122 | ||
| 123 | if(iscachectl(path)) | 123 | if(iscachectl(path)) |
| 124 | return 0; | 124 | return 0; |
| @@ -151,9 +151,9 @@ fstruncate(const char *path, off_t off) · 26 unmodified lines | |||
| 151 | int | 151 | int |
| 152 | fsrename(const char *opath, const char *npath) | 152 | fsrename(const char *opath, const char *npath) |
| 153 | { | 153 | { |
| 154 | Dir *d; | 154 | Dir *d; |
| 155 | FFid *f; | 155 | FFid *f; |
| 156 | char *dname, *bname; | 156 | char *dname, *bname; |
| 157 | 157 | ||
| 158 | if(iscachectl(opath)) | 158 | if(iscachectl(opath)) |
| 159 | return -EACCES; | 159 | return -EACCES; |
| @@ -189,7 +189,7 @@ fsrename(const char *opath, const char *npath) · 29 unmodified lines | |||
| 189 | int | 189 | int |
| 190 | fsopen(const char *path, struct fuse_file_info *ffi) | 190 | fsopen(const char *path, struct fuse_file_info *ffi) |
| 191 | { | 191 | { |
| 192 | FFid *f; | 192 | FFid *f; |
| 193 | 193 | ||
| 194 | if(iscachectl(path)) | 194 | if(iscachectl(path)) |
| 195 | return 0; | 195 | return 0; |
| @@ -210,8 +210,8 @@ fsopen(const char *path, struct fuse_file_info *ffi) · 14 unmodified lines | |||
| 210 | int | 210 | int |
| 211 | fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi) | 211 | fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi) |
| 212 | { | 212 | { |
| 213 | FFid *f; | 213 | FFid *f; |
| 214 | char *dname, *bname; | 214 | char *dname, *bname; |
| 215 | 215 | ||
| 216 | if(iscachectl(path)) | 216 | if(iscachectl(path)) |
| 217 | return -EACCES; | 217 | return -EACCES; |
| @@ -246,8 +246,9 @@ fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi) · 28 unmodified lines | |||
| 246 | int | 246 | int |
| 247 | fsmknod(const char *path, mode_t perm, dev_t dev) | 247 | fsmknod(const char *path, mode_t perm, dev_t dev) |
| 248 | { | 248 | { |
| 249 | FFid *f; | 249 | FFid *f; |
| 250 | char *dname, *bname; | 250 | char *dname, *bname; |
| 251 | |||
| 251 | if(iscachectl(path)) | 252 | if(iscachectl(path)) |
| 252 | return -EACCES; | 253 | return -EACCES; |
| 253 | if((f = _9pwalk(path)) == NULL){ | 254 | if((f = _9pwalk(path)) == NULL){ |
| @@ -270,7 +271,7 @@ fsmknod(const char *path, mode_t perm, dev_t dev) · 16 unmodified lines | |||
| 270 | int | 271 | int |
| 271 | fsunlink(const char *path) | 272 | fsunlink(const char *path) |
| 272 | { | 273 | { |
| 273 | FFid *f; | 274 | FFid *f; |
| 274 | 275 | ||
| 275 | if(iscachectl(path)) | 276 | if(iscachectl(path)) |
| 276 | return 0; | 277 | return 0; |
| @@ -286,8 +287,8 @@ int · 9 unmodified lines | |||
| 286 | fsread(const char *path, char *buf, size_t size, off_t off, | 287 | fsread(const char *path, char *buf, size_t size, off_t off, |
| 287 | struct fuse_file_info *ffi) | 288 | struct fuse_file_info *ffi) |
| 288 | { | 289 | { |
| 289 | FFid *f; | 290 | FFid *f; |
| 290 | int r; | 291 | int r; |
| 291 | 292 | ||
| 292 | if(iscachectl(path)){ | 293 | if(iscachectl(path)){ |
| 293 | if(off >= CACHECTLSIZE) | 294 | if(off >= CACHECTLSIZE) |
| @@ -311,8 +312,8 @@ int · 17 unmodified lines | |||
| 311 | fswrite(const char *path, const char *buf, size_t size, off_t off, | 312 | fswrite(const char *path, const char *buf, size_t size, off_t off, |
| 312 | struct fuse_file_info *ffi) | 313 | struct fuse_file_info *ffi) |
| 313 | { | 314 | { |
| 314 | FFid *f; | 315 | FFid *f; |
| 315 | int r; | 316 | int r; |
| 316 | 317 | ||
| 317 | if(iscachectl(path)){ | 318 | if(iscachectl(path)){ |
| 318 | clearcache(path); | 319 | clearcache(path); |
| @@ -331,7 +332,7 @@ fswrite(const char *path, const char *buf, size_t size, off_t off, · 12 unmodified lines | |||
| 331 | int | 332 | int |
| 332 | fsopendir(const char *path, struct fuse_file_info *ffi) | 333 | fsopendir(const char *path, struct fuse_file_info *ffi) |
| 333 | { | 334 | { |
| 334 | FFid *f; | 335 | FFid *f; |
| 335 | 336 | ||
| 336 | if(lookupdir(path, GET) != NULL){ | 337 | if(lookupdir(path, GET) != NULL){ |
| 337 | ffi->fh = (uintptr_t)0; | 338 | ffi->fh = (uintptr_t)0; |
| @@ -355,8 +356,8 @@ fsopendir(const char *path, struct fuse_file_info *ffi) · 17 unmodified lines | |||
| 355 | int | 356 | int |
| 356 | fsmkdir(const char *path, mode_t perm) | 357 | fsmkdir(const char *path, mode_t perm) |
| 357 | { | 358 | { |
| 358 | FFid *f; | 359 | FFid *f; |
| 359 | char *dname, *bname; | 360 | char *dname, *bname; |
| 360 | 361 | ||
| 361 | if((f = _9pwalk(path)) != NULL){ | 362 | if((f = _9pwalk(path)) != NULL){ |
| 362 | _9pclunk(f); | 363 | _9pclunk(f); |
| @@ -381,7 +382,7 @@ fsmkdir(const char *path, mode_t perm) · 18 unmodified lines | |||
| 381 | int | 382 | int |
| 382 | fsrmdir(const char *path) | 383 | fsrmdir(const char *path) |
| 383 | { | 384 | { |
| 384 | FFid *f; | 385 | FFid *f; |
| 385 | 386 | ||
| 386 | if((f = _9pwalk(path)) == NULL) | 387 | if((f = _9pwalk(path)) == NULL) |
| 387 | return -ENOENT; | 388 | return -ENOENT; |
| @@ -399,10 +400,10 @@ int · 11 unmodified lines | |||
| 399 | fsreaddir(const char *path, void *data, fuse_fill_dir_t ffd, | 400 | fsreaddir(const char *path, void *data, fuse_fill_dir_t ffd, |
| 400 | off_t off, struct fuse_file_info *ffi) | 401 | off_t off, struct fuse_file_info *ffi) |
| 401 | { | 402 | { |
| 402 | FDir *f; | 403 | FDir *f; |
| 403 | Dir *d, *e; | 404 | Dir *d, *e; |
| 404 | long n; | 405 | long n; |
| 405 | struct stat s; | 406 | struct stat s; |
| 406 | 407 | ||
| 407 | ffd(data, ".", NULL, 0); | 408 | ffd(data, ".", NULL, 0); |
| 408 | ffd(data, "..", NULL, 0); | 409 | ffd(data, "..", NULL, 0); |
| @@ -425,8 +426,8 @@ fsreaddir(const char *path, void *data, fuse_fill_dir_t ffd, · 16 unmodified lines | |||
| 425 | int | 426 | int |
| 426 | fschmod(const char *path, mode_t perm) | 427 | fschmod(const char *path, mode_t perm) |
| 427 | { | 428 | { |
| 428 | FFid *f; | 429 | FFid *f; |
| 429 | Dir *d; | 430 | Dir *d; |
| 430 | 431 | ||
| 431 | if((f = _9pwalk(path)) == NULL) | 432 | if((f = _9pwalk(path)) == NULL) |
| 432 | return -ENOENT; | 433 | return -ENOENT; |
| @@ -447,22 +448,22 @@ fschmod(const char *path, mode_t perm) · 14 unmodified lines | |||
| 447 | } | 448 | } |
| 448 | 449 | ||
| 449 | struct fuse_operations fsops = { | 450 | struct fuse_operations fsops = { |
| 450 | .getattr = fsgetattr, | 451 | .getattr = fsgetattr, |
| 451 | .truncate = fstruncate, | 452 | .truncate = fstruncate, |
| 452 | .rename = fsrename, | 453 | .rename = fsrename, |
| 453 | .open = fsopen, | 454 | .open = fsopen, |
| 454 | .create = fscreate, | 455 | .create = fscreate, |
| 455 | .mknod = fsmknod, | 456 | .mknod = fsmknod, |
| 456 | .unlink = fsunlink, | 457 | .unlink = fsunlink, |
| 457 | .read = fsread, | 458 | .read = fsread, |
| 458 | .write = fswrite, | 459 | .write = fswrite, |
| 459 | .opendir = fsopendir, | 460 | .opendir = fsopendir, |
| 460 | .mkdir = fsmkdir, | 461 | .mkdir = fsmkdir, |
| 461 | .rmdir = fsrmdir, | 462 | .rmdir = fsrmdir, |
| 462 | .readdir = fsreaddir, | 463 | .readdir = fsreaddir, |
| 463 | .release = fsrelease, | 464 | .release = fsrelease, |
| 464 | .releasedir = fsreleasedir, | 465 | .releasedir = fsreleasedir, |
| 465 | .chmod = fschmod | 466 | .chmod = fschmod |
| 466 | }; | 467 | }; |
| 467 | 468 | ||
| 468 | static int uflag, tflag, vflag; | 469 | static int uflag, tflag, vflag; |
| @@ -470,13 +471,13 @@ static int uflag, tflag, vflag; · 1 unmodified line | |||
| 470 | static void | 471 | static void |
| 471 | doconnect(char *name, char *port) | 472 | doconnect(char *name, char *port) |
| 472 | { | 473 | { |
| 473 | struct sockaddr_un uaddr; | 474 | struct sockaddr_un uaddr; |
| 474 | #ifdef __linux__ | 475 | #ifdef __linux__ |
| 475 | struct sockaddr_vm vaddr; | 476 | struct sockaddr_vm vaddr; |
| 476 | #endif | 477 | #endif |
| 477 | struct addrinfo *a, *ainfo, hint; | 478 | struct addrinfo *a, *ainfo, hint; |
| 478 | int e, n, yes; | 479 | int e, n, yes; |
| 479 | int p1[2], p2[2]; | 480 | int p1[2], p2[2]; |
| 480 | 481 | ||
| 481 | if(tflag){ | 482 | if(tflag){ |
| 482 | if(pipe(p1) < 0 || pipe(p2) < 0) | 483 | if(pipe(p1) < 0 || pipe(p2) < 0) |
| @@ -560,6 +561,7 @@ doconnect(char *name, char *port) · 77 unmodified lines | |||
| 560 | freeaddrinfo(ainfo); | 561 | freeaddrinfo(ainfo); |
| 561 | if(infd >= 0) | 562 | if(infd >= 0) |
| 562 | return; | 563 | return; |
| 564 | |||
| 563 | err: | 565 | err: |
| 564 | err(1, "Could not connect to 9p server"); | 566 | err(1, "Could not connect to 9p server"); |
| 565 | } | 567 | } |
| @@ -568,9 +570,9 @@ int · 2 unmodified lines | |||
| 568 | main(int argc, char *argv[]) | 570 | main(int argc, char *argv[]) |
| 569 | { | 571 | { |
| 570 | AuthInfo *ai; | 572 | AuthInfo *ai; |
| 571 | struct passwd *pw; | 573 | struct passwd *pw; |
| 572 | char logstr[100], *fusearg[argc], **fargp, port[10], user[30], *aname; | 574 | char logstr[100], *fusearg[argc], **fargp, port[10], user[30], *aname; |
| 573 | int ch, doauth; | 575 | int ch, doauth; |
| 574 | 576 | ||
| 575 | fargp = fusearg; | 577 | fargp = fusearg; |
| 576 | *fargp++ = *argv; | 578 | *fargp++ = *argv; |
| @@ -616,7 +618,7 @@ main(int argc, char *argv[]) · 39 unmodified lines | |||
| 616 | case 'A': | 618 | case 'A': |
| 617 | aname = strdup(optarg); | 619 | aname = strdup(optarg); |
| 618 | break; | 620 | break; |
| 619 | case 'o': | 621 | case 'o': |
| 620 | *fargp++ = "-o"; | 622 | *fargp++ = "-o"; |
| 621 | *fargp++ = optarg; | 623 | *fargp++ = optarg; |
| 622 | break; | 624 | break; |
| @@ -629,8 +631,10 @@ main(int argc, char *argv[]) · 6 unmodified lines | |||
| 629 | argv += optind; | 631 | argv += optind; |
| 630 | if(argc != 2) | 632 | if(argc != 2) |
| 631 | usage(); | 633 | usage(); |
| 634 | |||
| 632 | *fargp++ = "-s"; | 635 | *fargp++ = "-s"; |
| 633 | *fargp++ = argv[1]; | 636 | *fargp++ = argv[1]; |
| 637 | |||
| 634 | if(debug){ | 638 | if(debug){ |
| 635 | snprintf(logstr, sizeof(logstr), "/tmp/9pfs-%d.log", getpid()); | 639 | snprintf(logstr, sizeof(logstr), "/tmp/9pfs-%d.log", getpid()); |
| 636 | if((logfile = fopen(logstr, "w")) == NULL) | 640 | if((logfile = fopen(logstr, "w")) == NULL) |
| @@ -641,6 +645,7 @@ main(int argc, char *argv[]) · 4 unmodified lines | |||
| 641 | doconnect(argv[0], port); | 645 | doconnect(argv[0], port); |
| 642 | init9p(); | 646 | init9p(); |
| 643 | msize = _9pversion(Msize); | 647 | msize = _9pversion(Msize); |
| 648 | |||
| 644 | if(doauth){ | 649 | if(doauth){ |
| 645 | authfid = _9pauth(AUTHFID, user, NULL); | 650 | authfid = _9pauth(AUTHFID, user, NULL); |
| 646 | ai = auth_proxy(authfid, auth_getkey, "proto=p9any role=client"); | 651 | ai = auth_proxy(authfid, auth_getkey, "proto=p9any role=client"); |
| @@ -648,9 +653,11 @@ main(int argc, char *argv[]) · 1 unmodified line | |||
| 648 | err(1, "Could not establish authentication"); | 653 | err(1, "Could not establish authentication"); |
| 649 | auth_freeAI(ai); | 654 | auth_freeAI(ai); |
| 650 | } | 655 | } |
| 656 | |||
| 651 | rootfid = _9pattach(ROOTFID, doauth ? AUTHFID : NOFID, user, aname); | 657 | rootfid = _9pattach(ROOTFID, doauth ? AUTHFID : NOFID, user, aname); |
| 652 | if((rootdir = _9pstat(rootfid)) == NULL) | 658 | if((rootdir = _9pstat(rootfid)) == NULL) |
| 653 | errx(1, "Could not stat root"); | 659 | errx(1, "Could not stat root"); |
| 660 | |||
| 654 | DPRINT("About to fuse_main\n"); | 661 | DPRINT("About to fuse_main\n"); |
| 655 | fuse_main(fargp - fusearg, fusearg, &fsops, NULL); | 662 | fuse_main(fargp - fusearg, fusearg, &fsops, NULL); |
| 656 | exit(0); | 663 | exit(0); |
| @@ -659,8 +666,8 @@ main(int argc, char *argv[]) · 2 unmodified lines | |||
| 659 | void | 666 | void |
| 660 | dir2stat(struct stat *s, Dir *d) | 667 | dir2stat(struct stat *s, Dir *d) |
| 661 | { | 668 | { |
| 662 | struct passwd *p; | 669 | struct passwd *p; |
| 663 | struct group *g; | 670 | struct group *g; |
| 664 | 671 | ||
| 665 | s->st_dev = d->dev; | 672 | s->st_dev = d->dev; |
| 666 | s->st_ino = d->qid.path; | 673 | s->st_ino = d->qid.path; |
| @@ -683,7 +690,7 @@ dir2stat(struct stat *s, Dir *d) · 16 unmodified lines | |||
| 683 | void | 690 | void |
| 684 | clearcache(const char *path) | 691 | clearcache(const char *path) |
| 685 | { | 692 | { |
| 686 | char *dname; | 693 | char *dname; |
| 687 | 694 | ||
| 688 | dname = estrdup(path); | 695 | dname = estrdup(path); |
| 689 | breakpath(dname); | 696 | breakpath(dname); |
| @@ -695,9 +702,9 @@ clearcache(const char *path) · 5 unmodified lines | |||
| 695 | Dir* | 702 | Dir* |
| 696 | iscached(const char *path) | 703 | iscached(const char *path) |
| 697 | { | 704 | { |
| 698 | FDir *fd; | 705 | FDir *fd; |
| 699 | Dir *d, e; | 706 | Dir *d, e; |
| 700 | char *dname, *bname; | 707 | char *dname, *bname; |
| 701 | 708 | ||
| 702 | if(strcmp(path, "/") == 0) | 709 | if(strcmp(path, "/") == 0) |
| 703 | return rootdir; | 710 | return rootdir; |
| @@ -716,9 +723,9 @@ iscached(const char *path) · 12 unmodified lines | |||
| 716 | Dir* | 723 | Dir* |
| 717 | addtocache(const char *path) | 724 | addtocache(const char *path) |
| 718 | { | 725 | { |
| 719 | FFid *f; | 726 | FFid *f; |
| 720 | Dir *d; | 727 | Dir *d; |
| 721 | char *dname; | 728 | char *dname; |
| 722 | 729 | ||
| 723 | DPRINT("addtocache %s\n", path); | 730 | DPRINT("addtocache %s\n", path); |
| 724 | dname = estrdup(path); | 731 | dname = estrdup(path); |
| @@ -759,7 +766,7 @@ iscachectl(const char *path) · 34 unmodified lines | |||
| 759 | char* | 766 | char* |
| 760 | breakpath(char *dname) | 767 | breakpath(char *dname) |
| 761 | { | 768 | { |
| 762 | char *bname; | 769 | char *bname; |
| 763 | 770 | ||
| 764 | bname = strrchr(dname, '/'); | 771 | bname = strrchr(dname, '/'); |
| 765 | *bname++ = '\0'; | 772 | *bname++ = '\0'; |