History

refactor whitespace

Matus Skvarla committed 1 year ago

Commit b2e028c1 parent 2a541121 file · +84 −77Browse files

Unified · Split

9pfs.c+84−77
@@ -39,27 +39,27 @@ enum · 38 unmodified lines
39 Msize = 32768,39 Msize = 32768,
40};40};
41 41
42void dir2stat(struct stat*, Dir*);42void dir2stat(struct stat*, Dir*);
43Dir *iscached(const char*);43Dir *iscached(const char*);
44Dir *addtocache(const char*);44Dir *addtocache(const char*);
45void clearcache(const char*);45void clearcache(const char*);
46int iscachectl(const char*);46int iscachectl(const char*);
47char *breakpath(char*);47char *breakpath(char*);
48void usage(void);48void usage(void);
49 49
50Dir *rootdir;50Dir *rootdir;
51FILE *logfile;51FILE *logfile;
52FFid *rootfid;52FFid *rootfid;
53FFid *authfid;53FFid *authfid;
54int msize;54int msize;
55int infd, outfd;55int infd, outfd;
56int debug;56int debug;
57 57
58int58int
59fsstat(const char *path, struct stat *st)59fsstat(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
76int76int
77fsgetattr(const char *path, struct stat *st)77fsgetattr(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
104int104int
105fsreleasedir(const char *path, struct fuse_file_info *ffi)105fsreleasedir(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
117int117int
118fstruncate(const char *path, off_t off)118fstruncate(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
151int151int
152fsrename(const char *opath, const char *npath)152fsrename(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
189int189int
190fsopen(const char *path, struct fuse_file_info *ffi)190fsopen(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
210int210int
211fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi)211fscreate(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
246int246int
247fsmknod(const char *path, mode_t perm, dev_t dev)247fsmknod(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
270int271int
271fsunlink(const char *path)272fsunlink(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
286fsread(const char *path, char *buf, size_t size, off_t off,287fsread(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
311fswrite(const char *path, const char *buf, size_t size, off_t off,312fswrite(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
331int332int
332fsopendir(const char *path, struct fuse_file_info *ffi)333fsopendir(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
355int356int
356fsmkdir(const char *path, mode_t perm)357fsmkdir(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
381int382int
382fsrmdir(const char *path)383fsrmdir(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
399fsreaddir(const char *path, void *data, fuse_fill_dir_t ffd,400fsreaddir(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
425int426int
426fschmod(const char *path, mode_t perm)427fschmod(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
449struct fuse_operations fsops = {450struct 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 = fschmod466 .chmod = fschmod
466};467};
467 468
468static int uflag, tflag, vflag;469static int uflag, tflag, vflag;
@@ -470,13 +471,13 @@ static int uflag, tflag, vflag; · 1 unmodified line
470static void471static void
471doconnect(char *name, char *port)472doconnect(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#endif477#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
563err:565err:
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
568main(int argc, char *argv[])570main(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
659void666void
660dir2stat(struct stat *s, Dir *d)667dir2stat(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
683void690void
684clearcache(const char *path)691clearcache(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
695Dir*702Dir*
696iscached(const char *path)703iscached(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
716Dir*723Dir*
717addtocache(const char *path)724addtocache(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
759char*766char*
760breakpath(char *dname)767breakpath(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';

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t