ref: cb8d69654c5d767dbf25d6d55e2b8d8e1c471c59
parent: db38a568c302f9d1820649849eeeaf4087b3c976
author: Ori Bernstein <[email protected]>
date: Wed Dec 15 11:37:07 EST 2021
tree: don't pack wstat into opcode It's a bit messy, and we have too many wstat flags to fit nicely into a byte.
--- a/check.c
+++ b/check.c
@@ -121,8 +121,8 @@
case Oclearb: /* delete kvp if exists */
break;
case Owstat: /* kvp dirent */
- if((my.statop & ~(Owsize|Owmode|Owmtime)) != 0){
- fprint(2, "invalid stat op %d\n", my.statop);
+ if((my.v[0] & ~(Owsize|Owmode|Owmtime)) != 0){
+ fprint(2, "invalid stat op %x\n", my.v[0]);
fail++;
}
break;
--- a/dat.h
+++ b/dat.h
@@ -406,7 +406,6 @@
struct Msg {
char op;
- char statop;
Kvp;
};
--- a/dump.c
+++ b/dump.c
@@ -44,7 +44,7 @@
}
static int
-showval(Fmt *fmt, Kvp *v, int op)
+showval(Fmt *fmt, Kvp *v, int op, int statop)
{
char *p;
Bptr bp;
@@ -83,15 +83,15 @@
break;
case Owstat:
p = v->v;
- if(op & Owmtime){
+ if(statop & Owmtime){
n += fmtprint(fmt, "mtime:%llx ", GBIT64(p));
p += 8;
}
- if(op & Owsize){
+ if(statop & Owsize){
n += fmtprint(fmt, "size:%llx ", GBIT64(p));
p += 8;
}
- if(op & Owmode){
+ if(statop & Owmode){
n += fmtprint(fmt, "mode:%o ", GBIT32(p));
p += 4;
}
@@ -140,15 +140,18 @@
[Owstat] "Owstat",
};
Msg *m;
- int n;
+ int n, o;
+ o = 0;
m = va_arg(fmt->args, Msg*);
if(m == nil)
return fmtprint(fmt, "Msg{nil}");
+ if(m->op == Owstat)
+ o = m->v[0];
n = fmtprint(fmt, "Msg(%s, ", opname[m->op]);
n += showkey(fmt, m);
n += fmtprint(fmt, ") => (");
- n += showval(fmt, m, m->statop);
+ n += showval(fmt, m, m->op, o);
n += fmtprint(fmt, ")");
return n;
}
@@ -166,7 +169,7 @@
n += showkey(fmt, kv);
n += fmtprint(fmt, ") => (");
if(kv->type == Vinl)
- n += showval(fmt, kv, Onop);
+ n += showval(fmt, kv, Onop, 0);
else
n += fmtprint(fmt, "(%B,%ud))", kv->bp, kv->fill);
n += fmtprint(fmt, ")");
--- a/fs.c
+++ b/fs.c
@@ -673,7 +673,7 @@
fswstat(Fmsg *m)
{
char *p, *e, strs[65535], rnbuf[Kvmax], opbuf[Kvmax], kvbuf[Kvmax];
- int nm, sync;
+ int op, nm, sync;
vlong up;
Fcall r;
Dent *de;
@@ -747,28 +747,29 @@
nm++;
}
- p = opbuf;
+ p = opbuf+1;
+ op = 0;
mb[nm].Key = k;
mb[nm].op = Owstat;
- mb[nm].statop = 0;
if(d.mode != ~0){
- mb[nm].statop |= Owmode;
+ op |= Owmode;
PBIT32(p, d.mode);
p += 4;
sync = 0;
}
if(d.length != ~0){
- mb[nm].statop |= Owsize;
+ op |= Owsize;
PBIT64(p, d.length);
p += 8;
sync = 0;
}
if(d.mtime != ~0){
- mb[nm].statop |= Owmtime;
+ op |= Owmtime;
PBIT64(p, (vlong)d.mtime*Nsec);
p += 8;
sync = 0;
}
+ opbuf[0] = op;
mb[nm].v = opbuf;
mb[nm].nv = p - opbuf;
nm++;
@@ -775,9 +776,6 @@
if(sync){
rerror(m, Eimpl);
}else{
-for(int i = 0; i < nm; i++){
-print("upsert %M\n", &mb[i]);
-}
if((e = btupsert(&f->mnt->root, mb, nm)) != nil){
rerror(m, e);
goto Out;
@@ -861,7 +859,6 @@
d.gid = "glenda";
d.muid = "glenda";
mb.op = Oinsert;
- mb.statop = 0;
if(dir2kv(f->qpath, &d, &mb, buf, sizeof(buf)) == -1){
rerror(m, Efs);
putfid(f);
@@ -1209,18 +1206,17 @@
c -= n;
}
+ p = sbuf;
kv[i].op = Owstat;
- kv[i].statop = 0;
kv[i].k = f->dent->k;
kv[i].nk = f->dent->nk;
- kv[i].v = sbuf;
- kv[i].nv = 0;
if(m->offset+m->count > f->dent->length){
- kv[i].statop = Owsize;
- kv[i].nv += 8;
- PBIT64(kv[i].v, m->offset+m->count);
+ *p++ = Owsize;
+ PBIT64(p, m->offset+m->count); p += 8;
f->dent->length = m->offset+m->count;
}
+ kv[i].v = sbuf;
+ kv[i].nv = p - sbuf;
if((e = btupsert(&f->mnt->root, kv, i+1)) != nil){
rerror(m, e);
putfid(f);
--- a/tree.c
+++ b/tree.c
@@ -37,7 +37,6 @@
cpmsg(Msg *dst, Msg *src, char *buf, int nbuf)
{
dst->op = src->op;
- dst->statop = src->statop;
cpkvp(dst, src, buf, nbuf);
}
@@ -155,8 +154,6 @@
p = b->data + Bufspc + o;
*p = m->op;
- if(m->op == Owstat)
- *p |= m->statop;
PBIT16(p + 1, m->nk);
memcpy(p + 3, m->k, m->nk);
PBIT16(p + 3 + m->nk, m->nv);
@@ -174,8 +171,7 @@
o = GBIT16(b->data + Pivspc + 2*i);
p = b->data + Pivspc + o;
m->type = Vinl;
- m->op = (*p & 0x0f);
- m->statop = (*p & 0xf0);
+ m->op = *p;
m->nk = GBIT16(p + 1);
m->k = p + 3;
m->nv = GBIT16(p + 3 + m->nk);
@@ -329,22 +325,24 @@
{
vlong v;
char *p;
+ int op;
p = m->v;
+ op = *p++;
/* bump version */
v = GBIT32(kv->v+8);
PBIT32(kv->v+8, v+1);
- if(m->statop & Owmtime){
+ if(op & Owmtime){
v = GBIT64(p);
p += 8;
PBIT32(kv->v+25, v);
}
- if(m->statop & Owsize){
+ if(op & Owsize){
v = GBIT64(p);
p += 8;
PBIT64(kv->v+33, v);
}
- if(m->statop & Owmode){
+ if(op & Owmode){
v = GBIT32(p);
p += 4;
PBIT32(kv->v+33, v);