ref: 360f0e39c54d7085e90b06ac15caad2812a12514
parent: 4b8b6b57fdbce99d2962946b7638694594dfe607
author: 9ferno <gophone2015@gmail.com>
date: Wed Jan 11 08:26:58 EST 2023
added flags to Data header
--- a/9p.c
+++ b/9p.c
@@ -395,7 +395,7 @@
ch = cbuf->d;
checktag(cbuf, 1, Tdentry, ch->path);
- }while(ch->flags&Dsys || ch->tag == Tdentry && ch->path == Qpnone);
+ }while(ch->flags&Fsys || ch->tag == Tdentry && ch->path == Qpnone);
readname(d, ch->preli, &name, &namelen);
sbuf = emalloc9p(namelen + 1+ 3*(Userlen+1));
@@ -538,6 +538,7 @@
fswrite(Req *req)
{
s32 rv;
+ Aux *aux;
if(waserror()){
responderror(req);
@@ -562,8 +563,9 @@
if((req->fid->qid.type & QTDIR) != 0)
error(errstring[Einval]);
- rv = writefile(((Aux*)req->fid->aux)->dblkno, req->fid->qid.path,
- ((Aux*)req->fid->aux)->uid,
+ aux = (Aux*)req->fid->aux;
+ rv = writefile(aux->dblkno, req->fid->qid.path,
+ aux->uid,
req->ifcall.data, req->ifcall.count,
req->ifcall.offset);
if(rv == -3)
@@ -1431,7 +1433,7 @@
Iobuf *dbuf;
dbuf = egetmetachk(dblkno, Breadonly, Tdentry, qpath);
- filesize = dbuf->d->size;
+ filesize = dbuf->d->size+dbuf->appendsize;
putbuf(dbuf, 0);
return filesize;
}
@@ -1522,6 +1524,8 @@
/* allocate new blocks to copy on write */
newbuf = allocblocks(nblocks,Tdata, d->path);
newblkno = newbuf->blkno;
+ newbuf->io->dblkno = dblkno;
+ newbuf->io->flags = d->flags;
if(waserror()){
freeblocks(newblkno, nblocks, Tdata, d->path);
nexterror();
@@ -1560,6 +1564,7 @@
newbuf = allocblocks(Maxdatablockunits,Tdata, d->path);
newblkno = newbuf->blkno;
newbuf->io->dblkno = dblkno;
+ newbuf->io->flags = d->flags;
if(waserror()){
freeblocks(newblkno, Maxdatablockunits, Tdata, d->path);
nexterror();
@@ -1588,6 +1593,7 @@
newbuf = allocblocks(Maxdatablockunits, Tdata, d->path);
newblkno = newbuf->blkno;
newbuf->io->dblkno = dblkno;
+ newbuf->io->flags = d->flags;
newbufsize = 0;
if(waserror()){
freeblocks(newblkno, Maxdatablockunits, Tdata, d->path);
@@ -1668,6 +1674,7 @@
newbuf = allocblocks(newblocks,Tdata, d->path);
newblkno = newbuf->blkno;
newbuf->io->dblkno = dblkno;
+ newbuf->io->flags = dbuf->d->flags;
if(waserror()){
freeblocks(newblkno, newblocks, Tdata, d->path);
nexterror();
@@ -1694,6 +1701,7 @@
newblkno = newbuf->blkno;
newbufsize = 0;
newbuf->io->dblkno = dblkno;
+ newbuf->io->flags = dbuf->d->flags;
if(waserror()){
freeblocks(newblkno, newblocks, Tdata, d->path);
nexterror();
@@ -1786,6 +1794,7 @@
dbuf->appendsize = 0;
}
memcpy(dbuf->append, d->buf, d->size);
+ memset(d->buf, 0, Ddatasize);
dbuf->appendsize = d->size;
d->size = 0;
dowrite = 1;
--- a/blk.c
+++ b/blk.c
@@ -10,6 +10,7 @@
d = (Dentry*)buf;
// fprint(fd, "name %s\n", d->name);
+ fprint(fd, "flags 0x%hhux\n", d->flags);
fprint(fd, "uid %d\n", d->uid);
fprint(fd, "gid %d\n", d->gid);
fprint(fd, "muid %d\n", d->muid);
@@ -16,8 +17,9 @@
fprint(fd, "size %llud\n", d->size);
fprint(fd, "pdblkno %llud\n", d->pdblkno);
fprint(fd, "pqpath %llud\n", d->pqpath);
+ fprint(fd, "preli %llud\n", d->preli);
fprint(fd, "mtime %llud\n", d->mtime);
- fprint(fd, "path %llud\n", d->path);
+ fprint(fd, "qpath %llud\n", d->qpath);
fprint(fd, "version %ud\n", d->version);
fprint(fd, "mode %uo\n", d->mode);
}
@@ -43,8 +45,10 @@
void
showdentry(int fd, u8 *buf)
{
- int j;
+ int j, k;
Dentry *d;
+ u64 i;
+ Name *nm;
showdentryhdr(fd, buf);
d = (Dentry*)buf;
@@ -56,7 +60,17 @@
showmagic(fd, buf);
else if(d->size <= Ddatasize && (d->mode&DMDIR) == 0 &&
d->path != Qproot0){
- fprint(fd, "%s", d->buf);
+ if(d->preli == 0 && d->flags&~Fsys == Fn){
+ for(i = 0; i < d->size/sizeof(Name); i++){
+ nm = (Name*)d->buf+i;
+ fprint(fd, "%llud %hud ", i, nm->namelen);
+ for(k = 0; k < Nfirst; k++)
+ fprint(fd, "%c", nm->name[k]);
+ fprint(fd, " %llud\n", nm->noffset);
+ }
+ }else{
+ fprint(fd, "%s", d->buf);
+ }
}else{
fprint(fd, "direct blocks\n");
for(j = 0; j<Ndblock; j++)
@@ -79,10 +93,25 @@
void
showdata(int fd, u8 *buf)
{
- Data *c;
+ Data *da;
+ u64 i;
+ u8 k;
+ Name *nm;
- c = (Data*)buf;
- fprint(fd, "%s", (s8*)c->buf);
+ da = (Data*)buf;
+ if((da->flags&~Fsys) == Fn){
+ /* assuming that the names index will fit in 1048556 bytes */
+ /* else, we need to worry about the offset */
+ for(i = 0; i < (da->len*Blocksize -Ddataidssize)/sizeof(Name); i++){
+ nm = (Name*)da->buf+i;
+ fprint(fd, "%llud %hud ", i, nm->namelen);
+ for(k = 0; k < Nfirst; k++)
+ fprint(fd, "%c", nm->name[k]);
+ fprint(fd, " %llud\n", nm->noffset);
+ }
+ }else{
+ fprint(fd, "%s", (s8*)da->buf);
+ }
}
void
@@ -105,8 +134,9 @@
showdentry(fd, buf);
return;
}else if(tag == Tdata){
- fprint(fd, "%s qid.path %llud dblkno %llud len %d\n",
- tagnames[tag], ((u64*)buf)[t->len*Nu64perblock -1], t->dblkno, t->len);
+ fprint(fd, "%s qid.path %llud dblkno %llud len %d flags 0x%hhux\n",
+ tagnames[tag], ((u64*)buf)[t->len*Nu64perblock -1],
+ t->dblkno, t->len, t->flags);
showdata(fd, buf);
return;
}else if(tag < Maxtind)
--- a/dat.h
+++ b/dat.h
@@ -14,6 +14,7 @@
typedef struct Dentry Dentry;
typedef struct Datahdr Datahdr;
typedef struct Indirect Indirect;
+typedef struct Name Name;
typedef struct Super Super;
typedef struct Tlock Tlock;
typedef struct User User;
@@ -31,6 +32,7 @@
Noworld = 9999, /* conventional id for "noworld" group */
Userlen = 32,
Servicelen = 128,
+ Nfirst = 6, /* length of name stored in Name */
Nsec = 1000ULL*1000*1000,
Usec = 1000ULL*1000,
@@ -38,7 +40,10 @@
Nbkp = 1,
Nrefresh = 3*Nsec,
- Dsys = 1, /* for flagging .n, .nl and .nle files. Dentry.flags */
+ /* for Dentry.flags and Data.flags */
+ Fsys = 0x80,/* for flagging .n, .nl and .nle files. Dentry.flags */
+ Fn = 1, /* .n Name index file format */
+ Fe = 2, /* Binary extents file format. TODO we are using text extents now */
In = 0, /* reli of .n file */
Inl = 1, /* reli of .nl file */
@@ -157,7 +162,7 @@
struct Dentryhdr
{
u8 tag;
- u8 flags; /* attributes (names extents, names - hide system files) */
+ u8 flags; /* attributes (names extents, names - hide system files) */
s16 uid;
s16 gid;
s16 muid; /* 8 */
@@ -173,7 +178,7 @@
struct Datahdr
{
u8 tag;
- u8 unused; /* for alignment and future use */
+ u8 flags; /* 0 for text, 1 for In Name file, 2 for extents */
u16 len;
u64 dblkno; /* block number of the directory entry */
};
@@ -227,6 +232,12 @@
u8 buf[1]; /* upto Maxdatablocksize, followed by u64 qid.path */
/* u64 path; same as qid.path at the end of the data content - check consistency */
};
+struct Name
+{
+ u16 namelen;
+ s8 name[Nfirst]; /* first 6 bytes. If longer, use noffset */
+ u64 noffset; /* offset where the name is stored in .nl - long names file */
+};
#pragma pack off
/*
@@ -246,6 +257,7 @@
u64 pdblkno;/* block number of my parent's directory entry */
u64 pqpath;/* block number of my parent's directory entry */
u64 preli; /* my relative index in the parent's directory entry */
+ u8 flags; /* corresponds to Dentry.flags and Data.flags */
u16 uid;
u8 tlocked; /* for exclusive use files, flag to indicate lock */
u64 dri; /* directory index while reading a directory */
--- a/names.c
+++ b/names.c
@@ -1,20 +1,5 @@
#include "all.h"
-enum {
- Nquantum = 32, /* size of a Name is a multiple of 32 bytes */
- Nfirst = 6, /* length of name stored in Name */
-};
-
-typedef struct Name Name;
-#pragma pack on
-struct Name
-{
- u16 namelen;
- s8 name[Nfirst]; /* first 6 bytes. If longer, use noffset */
- u64 noffset; /* offset where the name is stored in .nl - long names file */
-};
-#pragma pack off
-
s8
searchnames(Dentry *d, char *searchname, u64 *relip)
{
@@ -89,7 +74,11 @@
iobuf = iobufs[i];
pd->dblocks[i] = iobuf->blkno;
d = iobuf->d;
- d->flags = Dsys;
+ if(i == In)
+ d->flags = Fn;
+ else if(i == Inle)
+ d->flags = Fe;
+ d->flags |= Fsys;
d->pdblkno = pdblkno;
d->pqpath = pd->qpath;
d->preli = i;
@@ -148,6 +137,7 @@
initextents(nes, esname, 0, 0, 2, nil, dprintfd, panic, malloc9p);
loadextentsfile(pd->dblocks[Inle], pd->qpath+1+Inle, nes);
ufree(nes, nm.noffset, nm.namelen);
+dprint("rmname preli %llud freed offset %llud len %llud\n", preli, nm.noffset, nm.namelen);
saveextentstofile(pd->dblocks[Inle], pd->qpath+1+Inle, uid, nes);
poperror();
freeextents(nes);
--- a/tests/sizes.c
+++ b/tests/sizes.c
@@ -12,10 +12,10 @@
print("Blocksize %llud Maxdatablockunits %d\n",
Blocksize, Maxdatablockunits);
print("Dentry size %d\n", sizeof(Dentry));
- print("Dentryhdr size %d Ddatasize %llud\n",
- sizeof(Dentryhdr), Ddatasize);
- print("Datahdr size %d Ddataidssize %d Maxdatablocksize %llud\n",
- sizeof(Datahdr), Ddataidssize, Maxdatablocksize);
+ print(" Dentryhdr size %d Ddatasize %llud trailing path %d\n",
+ sizeof(Dentryhdr), Ddatasize, sizeof(u64));
+ print("Datahdr size %d trailing path %d Ddataidssize %d Maxdatablocksize %llud\n",
+ sizeof(Datahdr), sizeof(u64), Ddataidssize, Maxdatablocksize);
print("Ndblock %d Niblock %d\n", Ndblock, Niblock);
print("Nindperblock %llud Maxdatablocksize %llud\n",
Nindperblock, Maxdatablocksize);