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/9p.c b/9p.c index 258a16f..29df554 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; @@ -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.1 b/9pfs.1 index e78be66..e3dea3b 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 @@ -97,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 2c481bd..4a1e1ee 100644 --- a/9pfs.c +++ b/9pfs.c @@ -26,11 +26,12 @@ #include "util.h" #define CACHECTL ".fscache" +#define FFIH(ffi) ((FFid*)(uintptr_t)(ffi)->fh) enum { CACHECTLSIZE = 8, /* sizeof("cleared\n") - 1 */ - MSIZE = 8192 + Msize = 32768, }; void dir2stat(struct stat*, Dir*); @@ -42,6 +43,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) @@ -86,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 @@ -94,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); @@ -150,11 +157,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; } @@ -170,8 +179,8 @@ fsrename(const char *opath, const char *npath) free(d); clearcache(opath); return 0; -} - +} + int fsopen(const char *path, struct fuse_file_info *ffi) { @@ -188,7 +197,8 @@ 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; } @@ -223,7 +233,31 @@ 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; +} + +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; } @@ -254,11 +288,11 @@ 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; } - f = (FFid*)ffi->fh; + f = FFIH(ffi); if(f->mode & O_WRONLY) return -EACCES; f->offset = off; @@ -278,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; @@ -292,10 +326,9 @@ int fsopendir(const char *path, struct fuse_file_info *ffi) { FFid *f; - FDir *d; - if((d = lookupdir(path, GET)) != NULL){ - ffi->fh = (u64int)NULL; + if(lookupdir(path, GET) != NULL){ + ffi->fh = (uintptr_t)0; return 0; } if((f = _9pwalk(path)) == NULL) @@ -309,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; } @@ -372,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++){ @@ -413,6 +446,7 @@ struct fuse_operations fsops = { .rename = fsrename, .open = fsopen, .create = fscreate, + .mknod = fsmknod, .unlink = fsunlink, .read = fsread, .write = fswrite, @@ -433,7 +467,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 +479,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 +493,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 +505,10 @@ main(int argc, char *argv[]) case 'A': aname = strdup(optarg); break; + case 'o': + *fargp++ = "-o"; + *fargp++ = optarg; + break; default: usage(); break; @@ -505,7 +546,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"); @@ -519,7 +560,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) @@ -543,7 +584,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) @@ -584,7 +625,6 @@ addtocache(const char *path) FFid *f; Dir *d; char *dname; - long n; DPRINT("addtocache %s\n", path); dname = estrdup(path); @@ -595,18 +635,21 @@ 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((n = _9pdirread(f, &d)) < 0){ + if(_9pdirread(f, &d) < 0){ + _9pclunk(f); free(dname); return NULL; } + _9pclunk(f); free(dname); return iscached(path); } - + int iscachectl(const char *path) { @@ -632,6 +675,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); } diff --git a/9pfs.h b/9pfs.h index 27ae80b..1655b6b 100644 --- a/9pfs.h +++ b/9pfs.h @@ -32,15 +32,15 @@ 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(); +void init9p(void); int _9pversion(u32int); FFid *_9pauth(u32int, char*, char*); FFid *_9pattach(u32int, u32int, char*, char*); diff --git a/LICENSE b/LICENSE index aefb826..1c29324 100644 --- a/LICENSE +++ b/LICENSE @@ -14,28 +14,26 @@ 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). - -The method "ereallocarray" is derived from OpenBSD "reallocarray" and -is governed by the following license: - - * Copyright (c) 2008 Otto Moerbeek + * Copyright © 2021 Plan 9 Foundation + * Copyright © 20XX 9front authors * - * 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. + * 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 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. + * 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. diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md 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*, ...); 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/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); 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) 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; 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; } 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 */ 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*, ...);