mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
lib9pclient: add support for 9P2000.u
This commit is contained in:
parent
ac5a97e6b3
commit
382ae73f24
5 changed files with 17 additions and 12 deletions
|
@ -4,9 +4,10 @@
|
|||
#include <libc.h>
|
||||
#include <fcall.h>
|
||||
#include <9pclient.h>
|
||||
#include "fsimpl.h"
|
||||
|
||||
static long
|
||||
dirpackage(uchar *buf, long ts, Dir **d)
|
||||
dirpackage(uchar *buf, long ts, Dir **d, int dotu)
|
||||
{
|
||||
char *s;
|
||||
long ss, i, n, nn, m;
|
||||
|
@ -22,7 +23,7 @@ dirpackage(uchar *buf, long ts, Dir **d)
|
|||
n = 0;
|
||||
for(i = 0; i < ts; i += m){
|
||||
m = BIT16SZ + GBIT16(&buf[i]);
|
||||
if(statcheck(&buf[i], m) < 0)
|
||||
if(statchecku(&buf[i], m, dotu) < 0)
|
||||
break;
|
||||
ss += m;
|
||||
n++;
|
||||
|
@ -42,7 +43,7 @@ dirpackage(uchar *buf, long ts, Dir **d)
|
|||
nn = 0;
|
||||
for(i = 0; i < ts; i += m){
|
||||
m = BIT16SZ + GBIT16((uchar*)&buf[i]);
|
||||
if(nn >= n || convM2D(&buf[i], m, *d + nn, s) != m){
|
||||
if(nn >= n || convM2Du(&buf[i], m, *d + nn, s, dotu) != m){
|
||||
free(*d);
|
||||
*d = nil;
|
||||
return -1;
|
||||
|
@ -65,7 +66,7 @@ fsdirread(CFid *fid, Dir **d)
|
|||
return -1;
|
||||
ts = fsread(fid, buf, DIRMAX);
|
||||
if(ts >= 0)
|
||||
ts = dirpackage(buf, ts, d);
|
||||
ts = dirpackage(buf, ts, d, fid->fs->dotu);
|
||||
free(buf);
|
||||
return ts;
|
||||
}
|
||||
|
@ -91,9 +92,9 @@ fsdirreadall(CFid *fid, Dir **d)
|
|||
ts += n;
|
||||
}
|
||||
if(ts >= 0){
|
||||
ts = dirpackage(buf, ts, d);
|
||||
ts = dirpackage(buf, ts, d, fid->fs->dotu);
|
||||
if(ts < 0)
|
||||
werrstr("malformed directory contents");
|
||||
werrstr("malformed directory contents [dotu=%d]", fid->fs->dotu);
|
||||
}
|
||||
free(buf);
|
||||
if(ts == 0 && n < 0)
|
||||
|
|
|
@ -49,12 +49,15 @@ fsinit(int fd)
|
|||
fs->iosend = ioproc();
|
||||
muxinit(&fs->mux);
|
||||
|
||||
strcpy(fs->version, "9P2000");
|
||||
strcpy(fs->version, "9P2000.u");
|
||||
if((n = fsversion(fs, 8192, fs->version, sizeof fs->version)) < 0){
|
||||
werrstr("fsversion: %r");
|
||||
_fsunmount(fs);
|
||||
return nil;
|
||||
}
|
||||
if(strcmp(fs->version, "9P2000.u") == 0)
|
||||
fs->dotu = 1;
|
||||
fprint(2, "speaking %d\n", fs->dotu);
|
||||
fs->msize = n;
|
||||
return fs;
|
||||
}
|
||||
|
@ -215,7 +218,7 @@ _fsrpc(CFsys *fs, Fcall *tx, Fcall *rx, void **freep)
|
|||
tx->tag = 0;
|
||||
if(chatty9pclient)
|
||||
fprint(2, "<- %F\n", tx);
|
||||
nn = convS2M(tx, tpkt, n);
|
||||
nn = convS2Mu(tx, tpkt, n, fs->dotu);
|
||||
if(nn != n){
|
||||
free(tpkt);
|
||||
werrstr("lib9pclient: sizeS2M convS2M mismatch");
|
||||
|
@ -229,7 +232,7 @@ _fsrpc(CFsys *fs, Fcall *tx, Fcall *rx, void **freep)
|
|||
return -1;
|
||||
}
|
||||
n = GBIT32((uchar*)rpkt);
|
||||
nn = convM2S(rpkt, n, rx);
|
||||
nn = convM2Su(rpkt, n, rx, fs->dotu);
|
||||
if(nn != n){
|
||||
free(rpkt);
|
||||
werrstr("lib9pclient: convM2S packet size mismatch %d %d", n, nn);
|
||||
|
|
|
@ -14,6 +14,7 @@ void *_fsnbqrecv(Queue*);
|
|||
struct CFsys
|
||||
{
|
||||
char version[20];
|
||||
int dotu;
|
||||
int msize;
|
||||
QLock lk;
|
||||
int fd;
|
||||
|
|
|
@ -42,7 +42,7 @@ fsdirfstat(CFid *fid)
|
|||
free(freep);
|
||||
return nil;
|
||||
}
|
||||
n = convM2D(rx.stat, rx.nstat, d, (char*)&d[1]);
|
||||
n = convM2Du(rx.stat, rx.nstat, d, (char*)&d[1], fs->dotu);
|
||||
free(freep);
|
||||
if(n != rx.nstat){
|
||||
free(d);
|
||||
|
|
|
@ -28,11 +28,11 @@ fsdirfwstat(CFid *fid, Dir *d)
|
|||
int n, nn;
|
||||
Fcall tx, rx;
|
||||
|
||||
n = sizeD2M(d);
|
||||
n = sizeD2Mu(d, fid->fs->dotu);
|
||||
a = malloc(n);
|
||||
if(a == nil)
|
||||
return -1;
|
||||
nn = convD2M(d, a, n);
|
||||
nn = convD2Mu(d, a, n, fid->fs->dotu);
|
||||
if(n != nn){
|
||||
werrstr("convD2M and sizeD2M disagree");
|
||||
free(a);
|
||||
|
|
Loading…
Reference in a new issue