From e04fa0bd7e89674f9b3faf780f64d55dbd141dc5 Mon Sep 17 00:00:00 2001 From: felix Date: Fri, 17 Jan 2020 14:53:10 +0100 Subject: [PATCH 01/20] Added support for "-o" and "-f" options, which are passed further on to fuse_main(3) --- 9pfs.1 | 8 ++++++++ 9pfs.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/9pfs.1 b/9pfs.1 index e78be66..4547b11 100644 --- a/9pfs.1 +++ b/9pfs.1 @@ -44,6 +44,14 @@ The default is 564. .It Fl u Ar user Specifies the username to use on authentication and attach to the 9P service. +.It Fl d +Causes debug information for subsequent FUSE library calls to be +output to stderr. Implies -f. +.It Fl f +This flag indicates that the file system should not detach from the +controlling terminal and run in the foreground. +.It Fl o Ar option +Passes additional option to fuse_mount(3). .El .Pp 9pfs caches directories it reads which will cause diff --git a/9pfs.c b/9pfs.c index 2c481bd..65575a8 100644 --- a/9pfs.c +++ b/9pfs.c @@ -433,7 +433,7 @@ main(int argc, char *argv[]) struct sockaddr *addr; struct addrinfo *ainfo; struct passwd *pw; - char logstr[100], *fusearg[6], **fargp, port[10], user[30], *aname; + char logstr[100], *fusearg[argc], **fargp, port[10], user[30], *aname; int ch, doauth, uflag, n, alen, e; fargp = fusearg; @@ -445,7 +445,7 @@ main(int argc, char *argv[]) if((pw = getpwuid(getuid())) == NULL) errx(1, "Could not get user"); strecpy(user, user+sizeof(user), pw->pw_name); - while((ch = getopt(argc, argv, ":dnUap:u:A:")) != -1){ + while((ch = getopt(argc, argv, ":dnUap:u:A:o:f")) != -1){ switch(ch){ case 'd': debug++; @@ -459,6 +459,9 @@ main(int argc, char *argv[]) case 'a': doauth++; break; + case 'f': + *fargp++ = "-f"; + break; case 'p': strecpy(port, port+sizeof(port), optarg); break; @@ -468,6 +471,10 @@ main(int argc, char *argv[]) case 'A': aname = strdup(optarg); break; + case 'o': + *fargp++ = "-o"; + *fargp++ = optarg; + break; default: usage(); break; @@ -632,6 +639,6 @@ breakpath(char *dname) void usage(void) { - fprintf(stderr, "Usage: 9pfs [-anU] [-A aname] [-p port] [-u user] service mtpt\n"); + fprintf(stderr, "Usage: 9pfs [-anUfd] [-A aname] [-p port] [-u user] [-o option] service mtpt\n"); exit(2); } From 2aae8bca3b15b9f5ceb471e977e883095aeea8b1 Mon Sep 17 00:00:00 2001 From: felix Date: Sun, 19 Jan 2020 17:45:08 +0100 Subject: [PATCH 02/20] Add implementation of mknod as it seems to be required to create files on OpenBSD --- 9pfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/9pfs.c b/9pfs.c index 65575a8..3a43f78 100644 --- a/9pfs.c +++ b/9pfs.c @@ -228,6 +228,30 @@ fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi) return 0; } +int +fsmknod(const char *path, mode_t perm, dev_t dev) +{ + FFid *f; + char *dname, *bname; + if(iscachectl(path)) + return -EACCES; + if((f = _9pwalk(path)) == NULL){ + dname = estrdup(path); + bname = breakpath(dname); + if((f = _9pwalk(dname)) == NULL){ + free(dname); + return -ENOENT; + } + f = _9pcreate(f, bname, perm, 0); + free(dname); + if(f == NULL) + return -EACCES; + } + _9pclunk(f); + clearcache(path); + return 0; +} + int fsunlink(const char *path) { @@ -413,6 +437,7 @@ struct fuse_operations fsops = { .rename = fsrename, .open = fsopen, .create = fscreate, + .mknod = fsmknod, .unlink = fsunlink, .read = fsread, .write = fswrite, From b52527edecd400dc649d9d90dde9e7063d5a2689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sat, 20 Nov 2021 17:00:55 +0100 Subject: [PATCH 03/20] fix compilation --- .gitignore | 3 ++- 9pfs.c | 6 ++++++ 9pfs.h | 12 ++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1530978..3347665 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.o \ No newline at end of file +*.o +9pfs diff --git a/9pfs.c b/9pfs.c index 3a43f78..6a1e538 100644 --- a/9pfs.c +++ b/9pfs.c @@ -42,6 +42,12 @@ char *breakpath(char*); void usage(void); Dir *rootdir; +FILE *logfile; +FFid *rootfid; +FFid *authfid; +int msize; +int srvfd; +int debug; int fsstat(const char *path, struct stat *st) diff --git a/9pfs.h b/9pfs.h index 27ae80b..74e1637 100644 --- a/9pfs.h +++ b/9pfs.h @@ -32,13 +32,13 @@ struct FDir long ndirs; }; -FILE *logfile; +extern FILE *logfile; -FFid *rootfid; -FFid *authfid; -int msize; -int srvfd; -int debug; +extern FFid *rootfid; +extern FFid *authfid; +extern int msize; +extern int srvfd; +extern int debug; void init9p(); int _9pversion(u32int); From e7e0ff3ca5cd02804cb6367db29db382a0b3fb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Thu, 2 Dec 2021 02:36:35 +0100 Subject: [PATCH 04/20] remove useless assignments --- 9pfs.c | 6 ++---- lib/auth_rpc.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/9pfs.c b/9pfs.c index 6a1e538..08e84b7 100644 --- a/9pfs.c +++ b/9pfs.c @@ -322,9 +322,8 @@ int fsopendir(const char *path, struct fuse_file_info *ffi) { FFid *f; - FDir *d; - if((d = lookupdir(path, GET)) != NULL){ + if(lookupdir(path, GET) != NULL){ ffi->fh = (u64int)NULL; return 0; } @@ -622,7 +621,6 @@ addtocache(const char *path) FFid *f; Dir *d; char *dname; - long n; DPRINT("addtocache %s\n", path); dname = estrdup(path); @@ -637,7 +635,7 @@ addtocache(const char *path) return NULL; } DPRINT("addtocache about to dirread\n"); - if((n = _9pdirread(f, &d)) < 0){ + if(_9pdirread(f, &d) < 0){ free(dname); return NULL; } diff --git a/lib/auth_rpc.c b/lib/auth_rpc.c index 5017af1..61f0cf1 100644 --- a/lib/auth_rpc.c +++ b/lib/auth_rpc.c @@ -79,7 +79,7 @@ auth_rpc(AuthRpc *rpc, char *verb, void *a, int na) memmove(rpc->obuf, verb, l); rpc->obuf[l] = ' '; memmove(rpc->obuf+l+1, a, na); - if((n=write(rpc->afd, rpc->obuf, l+1+na)) != l+1+na) + if(write(rpc->afd, rpc->obuf, l+1+na) != l+1+na) return ARrpcfailure; if((n=read(rpc->afd, rpc->ibuf, AuthRpcMax)) < 0) From 47e91b81e657a502c3db7e01793e43a976546d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Wed, 26 Jan 2022 19:04:00 +0100 Subject: [PATCH 05/20] stop leaking fids (thanks Michael Forney) --- 9pfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/9pfs.c b/9pfs.c index 08e84b7..c7db8de 100644 --- a/9pfs.c +++ b/9pfs.c @@ -156,11 +156,13 @@ fsrename(const char *opath, const char *npath) dname = estrdup(npath); bname = strrchr(dname, '/'); if(strncmp(opath, npath, bname-dname) != 0){ + _9pclunk(f); free(dname); return -EACCES; } *bname++ = '\0'; if((d = _9pstat(f)) == NULL){ + _9pclunk(f); free(dname); return -EIO; } @@ -631,14 +633,17 @@ addtocache(const char *path) } f->mode |= O_RDONLY; if(_9popen(f) == -1){ + _9pclunk(f); free(dname); return NULL; } DPRINT("addtocache about to dirread\n"); if(_9pdirread(f, &d) < 0){ + _9pclunk(f); free(dname); return NULL; } + _9pclunk(f); free(dname); return iscached(path); } From 9980bcda4bbec286e08ef1c1684b40dda492383d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sun, 20 Feb 2022 21:59:31 +0100 Subject: [PATCH 06/20] update LICENSE (9front is MIT now) --- LICENSE | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index aefb826..e5f4a7d 100644 --- a/LICENSE +++ b/LICENSE @@ -14,14 +14,29 @@ All original work is released under the following license: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -The work in the lib directory is derived from plan9front and is owned -by: +The work in the lib directory is derived from plan9front and is released +under the following license: - * Copyright © 2002 Lucent Technologies Inc. - * All Rights Reserved - -and released under the terms of the Lucent Public License Version 1.02 -(see: http://9front.org/9front/lib/legal/lpl). + * Copyright © 2021 Plan 9 Foundation + * Copyright © 20XX 9front authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. The method "ereallocarray" is derived from OpenBSD "reallocarray" and is governed by the following license: From 650c7a3a42421eef27917d0ab46f7d58930050ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sun, 20 Feb 2022 23:23:51 +0100 Subject: [PATCH 07/20] fsopen: use direct io, fixes files generated on the fly (size == 0) --- 9pfs.1 | 5 ----- 9pfs.c | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/9pfs.1 b/9pfs.1 index 4547b11..e3dea3b 100644 --- a/9pfs.1 +++ b/9pfs.1 @@ -105,11 +105,6 @@ and are from Russ Cox's .Lk https://swtch.com/plan9port/ plan9port .Sh BUGS -Files of 0 reported size are not read correctly under Linux. This -prevents 9pfs from mounting a useful factotum. For a -work-around, use 9pfuse to mount factotum and then proceed with -9pfs authentication as usual. -.Pp OpenBSD does not display all the files in a very large directory. .Pp diff --git a/9pfs.c b/9pfs.c index c7db8de..efef8b0 100644 --- a/9pfs.c +++ b/9pfs.c @@ -197,6 +197,7 @@ fsopen(const char *path, struct fuse_file_info *ffi) return -EACCES; } ffi->fh = (u64int)f; + ffi->direct_io = 1; return 0; } From f0a39d7abf2ca4aa6918f720a0e992884cbfc4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sun, 20 Feb 2022 23:53:37 +0100 Subject: [PATCH 08/20] =?UTF-8?q?ulong=20=E2=86=92=20u32int=20(Plan=209=20?= =?UTF-8?q?ulong=20is=2032=20bit)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libc.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libc.h b/libc.h index 099adba..e2d9e41 100644 --- a/libc.h +++ b/libc.h @@ -65,7 +65,7 @@ typedef struct Qid { uvlong path; - ulong vers; + u32int vers; uchar type; } Qid; @@ -76,9 +76,9 @@ struct Dir { uint dev; /* server subtype */ /* file data */ Qid qid; /* unique id from server */ - ulong mode; /* permissions */ - ulong atime; /* last read time */ - ulong mtime; /* last write time */ + u32int mode; /* permissions */ + u32int atime; /* last read time */ + u32int mtime; /* last write time */ vlong length; /* file length */ char *name; /* last element of path */ char *uid; /* owner name */ From 7306107500e93605bfd2fe20b61ac65d20e91047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sun, 20 Feb 2022 23:57:35 +0100 Subject: [PATCH 09/20] =?UTF-8?q?MSIZE=20=E2=86=92=20Msize=20to=20avoid=20?= =?UTF-8?q?conflicts;=20set=20default=20Msize=20to=2032K=20(mostly=20NOP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 9pfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/9pfs.c b/9pfs.c index efef8b0..2379f9e 100644 --- a/9pfs.c +++ b/9pfs.c @@ -30,7 +30,7 @@ enum { CACHECTLSIZE = 8, /* sizeof("cleared\n") - 1 */ - MSIZE = 8192 + Msize = 32768, }; void dir2stat(struct stat*, Dir*); @@ -545,7 +545,7 @@ main(int argc, char *argv[]) freeaddrinfo(ainfo); init9p(); - msize = _9pversion(MSIZE); + msize = _9pversion(Msize); if(doauth){ authfid = _9pauth(AUTHFID, user, NULL); ai = auth_proxy(authfid, auth_getkey, "proto=p9any role=client"); From 64a7be95befb79ce2f77c18d904f2566fcefb4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 12:07:44 +0100 Subject: [PATCH 10/20] fix compilation warnings --- 9p.c | 56 ++++++++++++++++++++++++++++---------------------------- 9pfs.c | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/9p.c b/9p.c index 258a16f..2916f77 100644 --- a/9p.c +++ b/9p.c @@ -18,34 +18,34 @@ #include "util.h" char *calls2str[] = { - [Tversion] "Tversion", - [Tauth] "Tauth", - [Tattach] "Tattach", - [Terror] "Terror", - [Tflush] "Tflush", - [Twalk] "Twalk", - [Topen] "Topen", - [Tcreate] "Tcreate", - [Tread] "Tread", - [Twrite] "Twrite", - [Tclunk] "Tclunk", - [Tremove] "Tremove", - [Tstat] "Tstat", - [Twstat] "Twstat", - [Rversion] "Rversion", - [Rauth] "Rauth", - [Rattach] "Rattach", - [Rerror] "Rerror", - [Rflush] "Rflush", - [Rwalk] "Rwalk", - [Ropen] "Ropen", - [Rcreate] "Rcreate", - [Rread] "Rread", - [Rwrite] "Rwrite", - [Rclunk] "Rclunk", - [Rremove] "Rremove", - [Rstat] "Rstat", - [Rwstat] "Rwstat" + [Tversion]= "Tversion", + [Tauth]= "Tauth", + [Tattach]= "Tattach", + [Terror]= "Terror", + [Tflush]= "Tflush", + [Twalk]= "Twalk", + [Topen]= "Topen", + [Tcreate]= "Tcreate", + [Tread]= "Tread", + [Twrite]= "Twrite", + [Tclunk]= "Tclunk", + [Tremove]= "Tremove", + [Tstat]= "Tstat", + [Twstat]= "Twstat", + [Rversion]= "Rversion", + [Rauth]= "Rauth", + [Rattach]= "Rattach", + [Rerror]= "Rerror", + [Rflush]= "Rflush", + [Rwalk]= "Rwalk", + [Ropen]= "Ropen", + [Rcreate]= "Rcreate", + [Rread]= "Rread", + [Rwrite]= "Rwrite", + [Rclunk]= "Rclunk", + [Rremove]= "Rremove", + [Rstat]= "Rstat", + [Rwstat]= "Rwstat" }; void *tbuf, *rbuf; diff --git a/9pfs.c b/9pfs.c index 2379f9e..112b236 100644 --- a/9pfs.c +++ b/9pfs.c @@ -287,7 +287,7 @@ fsread(const char *path, char *buf, size_t size, off_t off, size = CACHECTLSIZE; if(off >= size) return 0; - memcpy(buf, "cleared\n" + off, size - off); + memcpy(buf, &"cleared\n"[off], size - off); clearcache(path); return size; } From 43fe24dfbf2ed9b6eaf693cc3a9be553f3354257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 12:08:33 +0100 Subject: [PATCH 11/20] rewrite Makefile, use pkg-config to use fuse, provide DESTDIR and PREFIX --- Makefile | 68 ++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 4d19b3c..392da26 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,17 @@ -BIN=/usr/local/bin -MAN=/usr/share/man/man1 TARG=9pfs -OBJS=9pfs.o\ +DESTDIR?= +PREFIX?=/usr/local +BIN=$(DESTDIR)$(PREFIX)/bin +MAN=$(DESTDIR)$(PREFIX)/share/man/man1 +CFLAGS?=-O2 -pipe -g -Wall +CFLAGS+=-D_FILE_OFFSET_BITS=64\ + -DFUSE_USE_VERSION=26\ + -D_GNU_SOURCE\ + $(shell pkg-config --cflags fuse) +LDFLAGS?= +LDFLAGS+=$(shell pkg-config --libs fuse) + +OBJS=\ 9p.o\ util.o\ lib/strecpy.o\ @@ -13,43 +23,27 @@ OBJS=9pfs.o\ lib/readn.o\ lib/auth_proxy.o\ lib/auth_rpc.o\ - lib/auth_getkey.o -HFILES=9pfs.h\ - auth.h\ - fcall.h\ - util.h\ - libc.h -CC= cc -DEBUG= -g -CFLAGS= -O2 -pipe\ - ${DEBUG} -Wall\ - -D_FILE_OFFSET_BITS=64\ - -DFUSE_USE_VERSION=26\ - -D_GNU_SOURCE -LDFLAGS= -LDADD= -lfuse - -all: ${TARG} - -install: ${TARG} ${TARG}.1 - install -s -m 555 -g bin ${TARG} ${BIN} - install -m 444 -g bin ${TARG}.1 ${MAN} - -installman: ${TARG}.1 - install -m 444 -g bin ${TARG}.1 ${MAN} + lib/auth_getkey.o\ + $(TARG).o\ -uninstall: - rm -f ${BIN}/${TARG} - rm -f ${MAN}/${TARG}.1 +.PHONY: all default install uninstall clean + +all: default -uninstallman: - rm -f ${MAN}/${TARG}.1 +default: $(TARG) -${TARG}: ${OBJS} ${HFILES} - ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} +install: $(TARG) $(TARG).1 + install -d $(BIN) + install -m 755 $(TARG) $(BIN) + install -d $(MAN) + install -m 644 $(TARG).1 $(MAN) + +uninstall: + rm -f $(BIN)/$(TARG) + rm -f $(MAN)/$(TARG).1 -.c.o: - ${CC} -c -o $@ ${CFLAGS} $< +$(TARG): $(OBJS) + ${CC} -o $@ ${OBJS} ${LDFLAGS} clean: - rm -f ${TARG} ${OBJS} + rm -f $(TARG) $(OBJS) From 4e790e65434b3153a150b90b3e27db157e5cd3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 15:43:04 +0100 Subject: [PATCH 12/20] convD2M: clean up --- lib/convD2M.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/convD2M.c b/lib/convD2M.c index e2134b4..40de622 100644 --- a/lib/convD2M.c +++ b/lib/convD2M.c @@ -8,31 +8,27 @@ uint sizeD2M(Dir *d) { - char *sv[5]; - int i, ns, nstr, fixlen; + char *sv[4]; + int i, ns; sv[0] = d->name; sv[1] = d->uid; sv[2] = d->gid; sv[3] = d->muid; - - fixlen = STATFIXLEN; - nstr = 4; - + ns = 0; - for(i = 0; i < nstr; i++) - if(sv[i]) - ns += strlen(sv[i]); + for(i = 0; i < nelem(sv); i++) + ns += sv[i] ? strlen(sv[i]) : 0; - return fixlen + ns; + return STATFIXLEN + ns; } uint convD2M(Dir *d, uchar *buf, uint nbuf) { uchar *p, *ebuf; - char *sv[5]; - int i, ns, nsv[5], ss, nstr, fixlen; + char *sv[4]; + int i, ns, nsv[4], ss; if(nbuf < BIT16SZ) return 0; @@ -45,19 +41,13 @@ convD2M(Dir *d, uchar *buf, uint nbuf) sv[2] = d->gid; sv[3] = d->muid; - fixlen = STATFIXLEN; - nstr = 4; - ns = 0; - for(i = 0; i < nstr; i++){ - if(sv[i]) - nsv[i] = strlen(sv[i]); - else - nsv[i] = 0; + for(i = 0; i < nelem(nsv); i++){ + nsv[i] = sv[i] ? strlen(sv[i]) : 0; ns += nsv[i]; } - ss = fixlen + ns; + ss = STATFIXLEN + ns; /* set size befor erroring, so user can know how much is needed */ /* note that length excludes count field itself */ @@ -86,7 +76,7 @@ convD2M(Dir *d, uchar *buf, uint nbuf) PBIT64(p, d->length); p += BIT64SZ; - for(i = 0; i < nstr; i++){ + for(i = 0; i < nelem(nsv); i++){ ns = nsv[i]; if(p + ns + BIT16SZ > ebuf) return 0; From f985a8b3239cc877ea51dbb4db53cf7e6599cc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 15:54:02 +0100 Subject: [PATCH 13/20] remove trailing whitespace --- 9p.c | 10 +++++----- 9pfs.c | 10 +++++----- fcall.h | 4 ++-- lib/convM2D.c | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/9p.c b/9p.c index 2916f77..29df554 100644 --- a/9p.c +++ b/9p.c @@ -105,7 +105,7 @@ do9p(Fcall *t, Fcall *r) r->type = Rerror; return -1; } - + int _9pversion(u32int m) { @@ -165,7 +165,7 @@ _9pattach(u32int fid, u32int afid, char* uname, char *aname) f->fid = fid; f->qid = rattach.qid; return f; -} +} FFid* _9pwalkr(FFid *r, char *path) @@ -262,7 +262,7 @@ int _9popen(FFid *f) { Fcall topen, ropen; - + topen.type = Topen; topen.fid = f->fid; topen.mode = f->mode; @@ -489,7 +489,7 @@ uniqfid(void) while((f = lookupfid(fid, PUT)) == NULL); return f; } - + FFid* lookupfid(u32int fid, int act) @@ -522,7 +522,7 @@ lookupfid(u32int fid, int act) f = FDEL; break; } - return f; + return f; } FFid* diff --git a/9pfs.c b/9pfs.c index 112b236..dc6b161 100644 --- a/9pfs.c +++ b/9pfs.c @@ -178,8 +178,8 @@ fsrename(const char *opath, const char *npath) free(d); clearcache(opath); return 0; -} - +} + int fsopen(const char *path, struct fuse_file_info *ffi) { @@ -559,7 +559,7 @@ main(int argc, char *argv[]) DPRINT("About to fuse_main\n"); fuse_main(fargp - fusearg, fusearg, &fsops, NULL); exit(0); -} +} void dir2stat(struct stat *s, Dir *d) @@ -583,7 +583,7 @@ dir2stat(struct stat *s, Dir *d) s->st_atime = d->atime; s->st_mtime = s->st_ctime = d->mtime; s->st_rdev = 0; -} +} void clearcache(const char *path) @@ -648,7 +648,7 @@ addtocache(const char *path) free(dname); return iscached(path); } - + int iscachectl(const char *path) { diff --git a/fcall.h b/fcall.h index 5bec770..d643e1d 100644 --- a/fcall.h +++ b/fcall.h @@ -17,7 +17,7 @@ struct Fcall u32int afid; /* Tauth, Tattach */ char *uname; /* Tauth, Tattach */ char *aname; /* Tauth, Tattach */ - u32int perm; /* Tcreate */ + u32int perm; /* Tcreate */ char *name; /* Tcreate */ uchar mode; /* Tcreate, Topen */ u32int newfid; /* Twalk */ @@ -31,7 +31,7 @@ struct Fcall ushort nstat; /* Twstat, Rstat */ uchar *stat; /* Twstat, Rstat */ int unixfd; /* Ropenfd */ - + /* 9P2000.u extensions */ int errornum; /* Rerror */ int uidnum; /* Tattach, Tauth */ diff --git a/lib/convM2D.c b/lib/convM2D.c index 480bd48..f96e2ec 100644 --- a/lib/convM2D.c +++ b/lib/convM2D.c @@ -41,7 +41,7 @@ convM2D(uchar *buf, uint nbuf, Dir *d, char *strs) int i, ns, nstr; if(nbuf < STATFIXLEN) - return 0; + return 0; p = buf; ebuf = buf + nbuf; @@ -82,7 +82,7 @@ convM2D(uchar *buf, uint nbuf, Dir *d, char *strs) } p += ns; } - + if(strs){ d->name = sv[0]; d->uid = sv[1]; @@ -94,6 +94,6 @@ convM2D(uchar *buf, uint nbuf, Dir *d, char *strs) d->gid = nullstring; d->muid = nullstring; } - + return p - buf; } From 94287d35c79ad22c5a445c71fb9d79bf25be6ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 15:54:14 +0100 Subject: [PATCH 14/20] remove unused ereallocarray --- LICENSE | 17 ----------------- util.c | 25 ------------------------- util.h | 1 - 3 files changed, 43 deletions(-) diff --git a/LICENSE b/LICENSE index e5f4a7d..1c29324 100644 --- a/LICENSE +++ b/LICENSE @@ -37,20 +37,3 @@ under the following license: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. - -The method "ereallocarray" is derived from OpenBSD "reallocarray" and -is governed by the following license: - - * Copyright (c) 2008 Otto Moerbeek - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/util.c b/util.c index 6e4e232..1db7e1a 100644 --- a/util.c +++ b/util.c @@ -41,31 +41,6 @@ ecalloc(size_t nmemb, size_t size) return v; } -#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) - -void* -ereallocarray(void *optr, size_t nmemb, size_t size) -{ - if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - errno = ENOMEM; - err(1, "erallocarray: out of memory"); - } - return erealloc(optr, size * nmemb); -} - -/* - *void* - *ereallocarray(void *ptr, size_t nmemb, size_t size) - *{ - * void *v; - * - * if((v = reallocarray(ptr, nmemb, size)) == NULL) - * err(1, "ereallocarray: out of memory"); - * return v; - *} - */ - char* estrdup(const char *s) { diff --git a/util.h b/util.h index ec94667..b875295 100644 --- a/util.h +++ b/util.h @@ -1,6 +1,5 @@ void *emalloc(size_t); void *erealloc(void*, size_t); -void *ereallocarray(void*, size_t, size_t); void *ecalloc(size_t, size_t); char *estrdup(const char *); void dprint(char*, ...); From cd42cad5413914af6a462be8dab135996aeffdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 16:02:41 +0100 Subject: [PATCH 15/20] auth.h: clean up --- auth.h | 83 ---------------------------------------------------------- 1 file changed, 83 deletions(-) diff --git a/auth.h b/auth.h index a05f1fa..4edce77 100644 --- a/auth.h +++ b/auth.h @@ -3,18 +3,10 @@ */ typedef struct AuthInfo AuthInfo; -typedef struct Chalstate Chalstate; -typedef struct Chapreply Chapreply; -typedef struct MSchapreply MSchapreply; -typedef struct UserPasswd UserPasswd; typedef struct AuthRpc AuthRpc; enum { - MAXCHLEN= 256, /* max challenge length */ - MAXNAMELEN= 256, /* maximum name length */ - MD5LEN= 16, - ARok = 0, /* rpc return values */ ARdone, ARerror, @@ -47,88 +39,13 @@ struct AuthInfo uchar *secret; /* secret */ }; -struct Chalstate -{ - char *user; - char chal[MAXCHLEN]; - int nchal; - void *resp; - int nresp; - -/* for implementation only */ - int afd; - AuthRpc *rpc; /* to factotum */ - char userbuf[MAXNAMELEN]; /* temp space if needed */ - int userinchal; /* user was sent to obtain challenge */ -}; - -struct Chapreply /* for protocol "chap" */ -{ - uchar id; - char resp[MD5LEN]; -}; - -struct MSchapreply /* for protocol "mschap" */ -{ - char LMresp[24]; /* Lan Manager response */ - char NTresp[24]; /* NT response */ -}; - -struct UserPasswd -{ - char *user; - char *passwd; -}; - -extern int newns(char*, char*); -extern int addns(char*, char*); - -extern int noworld(char*); -extern int amount(int, char*, int, char*); - -/* these two may get generalized away -rsc */ -extern int login(char*, char*, char*); -extern int httpauth(char*, char*); - -typedef struct Attr Attr; -enum { - AttrNameval, /* name=val -- when matching, must have name=val */ - AttrQuery, /* name? -- when matching, must be present */ - AttrDefault /* name:=val -- when matching, if present must match INTERNAL */ -}; -struct Attr -{ - int type; - Attr *next; - char *name; - char *val; -}; - typedef int AuthGetkey(char*); -Attr *_copyattr(Attr*); -Attr *_delattr(Attr*, char*); -Attr *_findattr(Attr*, char*); -void _freeattr(Attr*); -Attr *_mkattr(int, char*, char*, Attr*); -Attr *_parseattr(char*); -char *_strfindattr(Attr*, char*); - extern AuthInfo* fauth_proxy(FFid*, AuthRpc *rpc, AuthGetkey *getkey, char *params); extern AuthInfo* auth_proxy(FFid*, AuthGetkey *getkey, char *fmt, ...); extern int auth_getkey(char*); -extern int (*amount_getkey)(char*); extern void auth_freeAI(AuthInfo *ai); -extern int auth_chuid(AuthInfo *ai, char *ns); -extern Chalstate *auth_challenge(char*, ...); -extern AuthInfo* auth_response(Chalstate*); -extern int auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...); -extern void auth_freechal(Chalstate*); -extern AuthInfo* auth_userpasswd(char *user, char *passwd); -extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*, ...); extern AuthInfo* auth_getinfo(AuthRpc *rpc); extern AuthRpc* auth_allocrpc(int afd); -extern Attr* auth_attr(AuthRpc *rpc); extern void auth_freerpc(AuthRpc *rpc); extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int n); -extern int auth_wep(char*, char*, ...); From 25ef5b66b87c2e2ae350eb001cec60834e30840e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 16:08:22 +0100 Subject: [PATCH 16/20] init9p is (void), not () --- 9pfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9pfs.h b/9pfs.h index 74e1637..1655b6b 100644 --- a/9pfs.h +++ b/9pfs.h @@ -40,7 +40,7 @@ extern int msize; extern int srvfd; extern int debug; -void init9p(); +void init9p(void); int _9pversion(u32int); FFid *_9pauth(u32int, char*, char*); FFid *_9pattach(u32int, u32int, char*, char*); From 8bdd0db1963fd1a62b0887b37ebc108f5d87a967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 16:09:12 +0100 Subject: [PATCH 17/20] caps for readme --- readme.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename readme.md => README.md (100%) diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md From f0c0650f9cc7e1f0ca6bfc7356134b8817fcba43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 16:43:15 +0100 Subject: [PATCH 18/20] auth_proxy: check v?asprintf return values --- lib/auth_proxy.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/auth_proxy.c b/lib/auth_proxy.c index fbbcb23..53bdce4 100644 --- a/lib/auth_proxy.c +++ b/lib/auth_proxy.c @@ -181,19 +181,25 @@ fauth_proxy(FFid *f, AuthRpc *rpc, AuthGetkey *getkey, char *params) AuthInfo* auth_proxy(FFid *f, AuthGetkey *getkey, char *fmt, ...) { - int afd; + int afd, r; char *p, *ftm, *rpcpath; va_list arg; AuthInfo *ai; AuthRpc *rpc; va_start(arg, fmt); - vasprintf(&p, fmt, arg); + r = vasprintf(&p, fmt, arg); va_end(arg); + if(r < 0) + return nil; + ai = nil; ftm = getenv("FACTOTUM"); - asprintf(&rpcpath, "%s/rpc", ftm); + if(asprintf(&rpcpath, "%s/rpc", ftm) < 0){ + free(p); + return nil; + } afd = open(rpcpath, ORDWR); if(afd < 0){ free(p); From 0949fa294b8c87bcedb4ee763507123202e221dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Mon, 21 Feb 2022 16:55:10 +0100 Subject: [PATCH 19/20] fix ffi->fh bits/signedness confusion --- 9pfs.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/9pfs.c b/9pfs.c index dc6b161..4a1e1ee 100644 --- a/9pfs.c +++ b/9pfs.c @@ -26,6 +26,7 @@ #include "util.h" #define CACHECTL ".fscache" +#define FFIH(ffi) ((FFid*)(uintptr_t)(ffi)->fh) enum { @@ -92,7 +93,7 @@ fsgetattr(const char *path, struct stat *st) int fsrelease(const char *path, struct fuse_file_info *ffi) { - return _9pclunk((FFid*)ffi->fh); + return _9pclunk(FFIH(ffi)); } int @@ -100,9 +101,9 @@ fsreleasedir(const char *path, struct fuse_file_info *ffi) { FFid *f; - if((FFid*)ffi->fh == NULL) + f = FFIH(ffi); + if(f == NULL) return 0; - f = (FFid*)ffi->fh; if((f->qid.type & QTDIR) == 0) return -ENOTDIR; return _9pclunk(f); @@ -196,7 +197,7 @@ fsopen(const char *path, struct fuse_file_info *ffi) _9pclunk(f); return -EACCES; } - ffi->fh = (u64int)f; + ffi->fh = (uintptr_t)f; ffi->direct_io = 1; return 0; } @@ -232,7 +233,7 @@ fscreate(const char *path, mode_t perm, struct fuse_file_info *ffi) return -EIO; } } - ffi->fh = (u64int)f; + ffi->fh = (uintptr_t)f; clearcache(path); return 0; } @@ -291,7 +292,7 @@ fsread(const char *path, char *buf, size_t size, off_t off, clearcache(path); return size; } - f = (FFid*)ffi->fh; + f = FFIH(ffi); if(f->mode & O_WRONLY) return -EACCES; f->offset = off; @@ -311,7 +312,7 @@ fswrite(const char *path, const char *buf, size_t size, off_t off, clearcache(path); return size; } - f = (FFid*)ffi->fh; + f = FFIH(ffi); if(f->mode & O_RDONLY) return -EACCES; f->offset = off; @@ -327,7 +328,7 @@ fsopendir(const char *path, struct fuse_file_info *ffi) FFid *f; if(lookupdir(path, GET) != NULL){ - ffi->fh = (u64int)NULL; + ffi->fh = (uintptr_t)0; return 0; } if((f = _9pwalk(path)) == NULL) @@ -341,7 +342,7 @@ fsopendir(const char *path, struct fuse_file_info *ffi) _9pclunk(f); return -ENOTDIR; } - ffi->fh = (u64int)f; + ffi->fh = (uintptr_t)f; return 0; } @@ -404,7 +405,7 @@ fsreaddir(const char *path, void *data, fuse_fill_dir_t ffd, d = f->dirs; n = f->ndirs; }else{ - if((n = _9pdirread((FFid*)ffi->fh, &d)) < 0) + if((n = _9pdirread(FFIH(ffi), &d)) < 0) return -EIO; } for(e = d; e < d+n; e++){ From e2bbff524df0e9964af98c9e26e98fda15cc7b85 Mon Sep 17 00:00:00 2001 From: felix Date: Tue, 22 Feb 2022 17:03:53 +0100 Subject: [PATCH 20/20] Yeah, not everybody uses GNU make... Revert "rewrite Makefile, use pkg-config to use fuse, provide DESTDIR and PREFIX" This reverts commit 43fe24dfbf2ed9b6eaf693cc3a9be553f3354257. --- Makefile | 68 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 392da26..4d19b3c 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,7 @@ +BIN=/usr/local/bin +MAN=/usr/share/man/man1 TARG=9pfs -DESTDIR?= -PREFIX?=/usr/local -BIN=$(DESTDIR)$(PREFIX)/bin -MAN=$(DESTDIR)$(PREFIX)/share/man/man1 -CFLAGS?=-O2 -pipe -g -Wall -CFLAGS+=-D_FILE_OFFSET_BITS=64\ - -DFUSE_USE_VERSION=26\ - -D_GNU_SOURCE\ - $(shell pkg-config --cflags fuse) -LDFLAGS?= -LDFLAGS+=$(shell pkg-config --libs fuse) - -OBJS=\ +OBJS=9pfs.o\ 9p.o\ util.o\ lib/strecpy.o\ @@ -23,27 +13,43 @@ OBJS=\ lib/readn.o\ lib/auth_proxy.o\ lib/auth_rpc.o\ - lib/auth_getkey.o\ - $(TARG).o\ + lib/auth_getkey.o +HFILES=9pfs.h\ + auth.h\ + fcall.h\ + util.h\ + libc.h +CC= cc +DEBUG= -g +CFLAGS= -O2 -pipe\ + ${DEBUG} -Wall\ + -D_FILE_OFFSET_BITS=64\ + -DFUSE_USE_VERSION=26\ + -D_GNU_SOURCE +LDFLAGS= +LDADD= -lfuse + +all: ${TARG} + +install: ${TARG} ${TARG}.1 + install -s -m 555 -g bin ${TARG} ${BIN} + install -m 444 -g bin ${TARG}.1 ${MAN} + +installman: ${TARG}.1 + install -m 444 -g bin ${TARG}.1 ${MAN} -.PHONY: all default install uninstall clean - -all: default - -default: $(TARG) +uninstall: + rm -f ${BIN}/${TARG} + rm -f ${MAN}/${TARG}.1 -install: $(TARG) $(TARG).1 - install -d $(BIN) - install -m 755 $(TARG) $(BIN) - install -d $(MAN) - install -m 644 $(TARG).1 $(MAN) +uninstallman: + rm -f ${MAN}/${TARG}.1 -uninstall: - rm -f $(BIN)/$(TARG) - rm -f $(MAN)/$(TARG).1 +${TARG}: ${OBJS} ${HFILES} + ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} -$(TARG): $(OBJS) - ${CC} -o $@ ${OBJS} ${LDFLAGS} +.c.o: + ${CC} -c -o $@ ${CFLAGS} $< clean: - rm -f $(TARG) $(OBJS) + rm -f ${TARG} ${OBJS}