📄 sysfile.c
字号:
long_syschdir(char *name){ Chan *c; validaddr(name, 1, 0); c = namec(name, Atodir, 0, 0); cclose(up->dot); up->dot = c; return 0;}longbindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char* spec){ int ret; Chan *c0, *c1, *ac, *bc; struct{ Chan *chan; Chan *authchan; char *spec; int flags; }bogus; if((flag&~MMASK) || (flag&MORDER)==(MBEFORE|MAFTER)) error(Ebadarg); bogus.flags = flag & MCACHE; if(ismount){ if(up->pgrp->noattach) error(Enoattach); ac = nil; bc = fdtochan(fd, ORDWR, 0, 1); if(waserror()) { if(ac) cclose(ac); cclose(bc); nexterror(); } if(afd >= 0) ac = fdtochan(afd, ORDWR, 0, 1); bogus.chan = bc; bogus.authchan = ac; validaddr((ulong)spec, 1, 0); bogus.spec = spec; if(waserror()) error(Ebadspec); validname(spec, 1); poperror(); ret = devno('M', 0); c0 = devtab[ret]->attach((char*)&bogus); poperror(); if(ac) cclose(ac); cclose(bc); }else{ bogus.spec = 0; validaddr((ulong)arg0, 1, 0); c0 = namec(arg0, Abind, 0, 0); } if(waserror()){ cclose(c0); nexterror(); } validaddr((ulong)arg1, 1, 0); c1 = namec(arg1, Amount, 0, 0); if(waserror()){ cclose(c1); nexterror(); } ret = cmount(&c0, c1, flag, bogus.spec); poperror(); cclose(c1); poperror(); cclose(c0); if(ismount) fdclose(fd, 0); return ret;}long_sysbind(char *old, char *new, int flag){ return bindmount(0, -1, -1, old, new, flag, nil);}long_sysmount(int fd, int afd, char *new, int flag, char *spec){ return bindmount(1, fd, afd, nil, new, flag, spec);}long_sysunmount(char *old, char *new){ Chan *cmount, *cmounted; cmounted = 0; cmount = namec(new, Amount, 0, 0); if(old) { if(waserror()) { cclose(cmount); nexterror(); } validaddr(old, 1, 0); /* * This has to be namec(..., Aopen, ...) because * if arg[0] is something like /srv/cs or /fd/0, * opening it is the only way to get at the real * Chan underneath. */ cmounted = namec(old, Aopen, OREAD, 0); poperror(); } if(waserror()) { cclose(cmount); if(cmounted) cclose(cmounted); nexterror(); } cunmount(cmount, cmounted); cclose(cmount); if(cmounted) cclose(cmounted); poperror(); return 0;}long_syscreate(char *name, int mode, ulong perm){ int fd; Chan *c = 0; openmode(mode&~OEXCL); /* error check only; OEXCL okay here */ if(waserror()) { if(c) cclose(c); nexterror(); } validaddr(name, 1, 0); c = namec(name, Acreate, mode, perm); fd = newfd(c); if(fd < 0) error(Enofd); poperror(); return fd;}long_sysremove(char *name){ Chan *c; c = namec(name, Aremove, 0, 0); if(waserror()){ c->type = 0; /* see below */ cclose(c); nexterror(); } devtab[c->type]->remove(c); /* * Remove clunks the fid, but we need to recover the Chan * so fake it up. rootclose() is known to be a nop. */ c->type = 0; poperror(); cclose(c); return 0;}long_syswstat(char *name, void *buf, long n){ Chan *c; uint l; l = n; validstat(buf, l); validaddr(name, 1, 0); c = namec(name, Aaccess, 0, 0); if(waserror()){ cclose(c); nexterror(); } l = devtab[c->type]->wstat(c, buf, l); poperror(); cclose(c); return l;}long_sysfwstat(int fd, void *buf, long n){ Chan *c; uint l; l = n; validaddr(buf, l, 0); validstat(buf, l); c = fdtochan(fd, -1, 1, 1); if(waserror()) { cclose(c); nexterror(); } l = devtab[c->type]->wstat(c, buf, l); poperror(); cclose(c); return l;}static voidstarterror(void){ assert(up->nerrlab == 0);}static void_syserror(void){ char *p; p = up->syserrstr; up->syserrstr = up->errstr; up->errstr = p;}static voidenderror(void){ assert(up->nerrlab == 1); poperror();}intsysbind(char *old, char *new, int flag){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysbind(old, new, flag); enderror(); return n;}intsyschdir(char *path){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _syschdir(path); enderror(); return n;}intsysclose(int fd){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysclose(fd); enderror(); return n;}intsyscreate(char *name, int mode, ulong perm){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _syscreate(name, mode, perm); enderror(); return n;}intsysdup(int fd0, int fd1){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysdup(fd0, fd1); enderror(); return n;}intsysfstat(int fd, uchar *buf, int n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _sysfstat(fd, buf, n); enderror(); return n;}intsysfwstat(int fd, uchar *buf, int n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _sysfwstat(fd, buf, n); enderror(); return n;}intsysmount(int fd, int afd, char *new, int flag, char *spec){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysmount(fd, afd, new, flag, spec); enderror(); return n;}intsysunmount(char *old, char *new){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysunmount(old, new); enderror(); return n;}intsysopen(char *name, int mode){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysopen(name, mode); enderror(); return n;}intsyspipe(int *fd){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _syspipe(fd); enderror(); return n;}longsyspread(int fd, void *buf, long n, vlong off){ starterror(); if(waserror()){ _syserror(); return -1; } n = _syspread(fd, buf, n, off); enderror(); return n;}longsyspwrite(int fd, void *buf, long n, vlong off){ starterror(); if(waserror()){ _syserror(); return -1; } n = _syspwrite(fd, buf, n, off); enderror(); return n;}longsysread(int fd, void *buf, long n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _syspread(fd, buf, n, (uvlong) ~0); enderror(); return n;}intsysremove(char *path){ int n; starterror(); if(waserror()){ _syserror(); return -1; } n = _sysremove(path); enderror(); return n;}vlongsysseek(int fd, vlong off, int whence){ starterror(); if(waserror()){ _syserror(); return -1; } off = _sysseek(fd, off, whence); enderror(); return off;}intsysstat(char *name, uchar *buf, int n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _sysstat(name, buf, n); enderror(); return n;}longsyswrite(int fd, void *buf, long n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _syspwrite(fd, buf, n, (uvlong) ~0); enderror(); return n;}intsyswstat(char *name, uchar *buf, int n){ starterror(); if(waserror()){ _syserror(); return -1; } n = _syswstat(name, buf, n); enderror(); return n;}voidwerrstr(char *f, ...){ char buf[ERRMAX]; va_list arg; va_start(arg, f); vsnprint(buf, sizeof buf, f, arg); va_end(arg); if(up->nerrlab) strecpy(up->errstr, up->errstr+ERRMAX, buf); else strecpy(up->syserrstr, up->syserrstr+ERRMAX, buf);}int__errfmt(Fmt *fmt){ if(up->nerrlab) return fmtstrcpy(fmt, up->errstr); else return fmtstrcpy(fmt, up->syserrstr);}interrstr(char *buf, uint n){ char tmp[ERRMAX]; char *p; p = up->nerrlab ? up->errstr : up->syserrstr; memmove(tmp, p, ERRMAX); utfecpy(p, p+ERRMAX, buf); utfecpy(buf, buf+n, tmp); return strlen(buf);}intrerrstr(char *buf, uint n){ char *p; p = up->nerrlab ? up->errstr : up->syserrstr; utfecpy(buf, buf+n, p); return strlen(buf);}void*_sysrendezvous(void* arg0, void* arg1){ void *tag, *val; Proc *p, **l; tag = arg0; l = &REND(up->rgrp, (uintptr)tag); up->rendval = (void*)~0; lock(&up->rgrp->ref.lk); for(p = *l; p; p = p->rendhash) { if(p->rendtag == tag) { *l = p->rendhash; val = p->rendval; p->rendval = arg1; while(p->mach != 0) ; procwakeup(p); unlock(&up->rgrp->ref.lk); return val; } l = &p->rendhash; } /* Going to sleep here */ up->rendtag = tag; up->rendval = arg1; up->rendhash = *l; *l = up; up->state = Rendezvous; unlock(&up->rgrp->ref.lk); procsleep(); return up->rendval;}void*sysrendezvous(void *tag, void *val){ void *n; starterror(); if(waserror()){ _syserror(); return (void*)~0; } n = _sysrendezvous(tag, val); enderror(); return n;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -