fixed stat problem, as claimed in the manual page, stat is really containes twice, weird!

This commit is contained in:
Anselm R. Garbe 2006-01-20 18:48:19 +02:00
parent cfc11bd5d4
commit a6462e8ed6
5 changed files with 33 additions and 19 deletions

View File

@ -312,7 +312,7 @@ xopen(IXPServer * s, IXPConn * c)
static unsigned int
mkstat(Stat *stat, char *name, unsigned long long length)
{
stat->mode = 0xff;
stat->mode = 0xfff;
stat->atime = stat->mtime = time(0);
cext_strlcpy(stat->uid, getenv("USER"), sizeof(stat->uid));
cext_strlcpy(stat->gid, getenv("USER"), sizeof(stat->gid));
@ -322,7 +322,7 @@ mkstat(Stat *stat, char *name, unsigned long long length)
stat->length = length;
mkqid(&root_qid, name, &stat->qid);
return ixp_sizeof_stat(stat) + sizeof(unsigned short);
return ixp_sizeof_stat(stat);
}
static int
@ -341,15 +341,20 @@ xread(IXPServer * s, IXPConn * c)
switch (qpath_type(map->qid.path)) {
default:
case Droot:
s->fcall.count = mkstat(&stat, "display", strlen(align));
s->fcall.count = mkstat(&stat, "display", strlen(align)) + sizeof(unsigned short);
p = ixp_enc_u16(p, ixp_sizeof_stat(&stat));
p = ixp_enc_stat(p, &stat);
s->fcall.count += mkstat(&stat, "font", strlen(font));
s->fcall.count += mkstat(&stat, "font", strlen(font)) + sizeof(unsigned short);
p = ixp_enc_u16(p, ixp_sizeof_stat(&stat));
p = ixp_enc_stat(p, &stat);
s->fcall.count += mkstat(&stat, "new", 0);
s->fcall.count += mkstat(&stat, "new", 0) + sizeof(unsigned short);
p = ixp_enc_u16(p, ixp_sizeof_stat(&stat));
p = ixp_enc_stat(p, &stat);
s->fcall.count += mkstat(&stat, "event", 0);
s->fcall.count += mkstat(&stat, "event", 0) + sizeof(unsigned short);
p = ixp_enc_u16(p, ixp_sizeof_stat(&stat));
p = ixp_enc_stat(p, &stat);
s->fcall.count += mkstat(&stat, "default", 0);
s->fcall.count += mkstat(&stat, "default", 0) + sizeof(unsigned short);
p = ixp_enc_u16(p, ixp_sizeof_stat(&stat));
p = ixp_enc_stat(p, &stat);
/* todo: add all labels */
s->fcall.id = RREAD;
@ -385,9 +390,12 @@ xstat(IXPServer * s, IXPConn * c)
s->errstr = "invalid fid";
return -1;
}
s->fcall.id = RSTAT;
s->fcall.stat.mode = 0xff;
s->fcall.stat.mode = 0xfff;
s->fcall.stat.atime = s->fcall.stat.mtime = time(0);
fprintf(stderr, "atime=%ld\n", s->fcall.stat.atime);
cext_strlcpy(s->fcall.stat.uid, getenv("USER"), sizeof(s->fcall.stat.uid));
cext_strlcpy(s->fcall.stat.gid, getenv("USER"), sizeof(s->fcall.stat.gid));
cext_strlcpy(s->fcall.stat.muid, getenv("USER"), sizeof(s->fcall.stat.muid));
@ -397,9 +405,11 @@ xstat(IXPServer * s, IXPConn * c)
default:
case Droot:
s->fcall.stat.name[0] = '/';
s->fcall.stat.name[1] = 0;
s->fcall.stat.name[1] = '\0';
s->fcall.stat.length = 0;
s->fcall.stat.qid = root_qid;
fprintf(stderr, "stat: %ld %ld \n", s->fcall.stat.type, s->fcall.stat.dev);
fprintf(stderr, "qid: %ld %ld %lld\n", root_qid.type, root_qid.version, root_qid.path);
break;
case Ditem:
break;

View File

@ -97,7 +97,8 @@ print_dir(void *result, unsigned int msize)
unsigned int len = 0;
unsigned short size;
do {
p = ixp_dec_stat(p, &stat, &size);
p = ixp_dec_u16(p, &size);
p = ixp_dec_stat(p, &stat);
len += size + sizeof(unsigned short);
if(stat.qid.type == IXP_QTDIR)
fprintf(stdout, "%s/\n", stat.name);

View File

@ -164,7 +164,7 @@ ixp_dec_qid(unsigned char *msg, Qid * qid)
void *
ixp_enc_stat(unsigned char *msg, Stat * stat)
{
msg = ixp_enc_u16(msg, ixp_sizeof_stat(stat));
msg = ixp_enc_u16(msg, ixp_sizeof_stat(stat) - sizeof(unsigned short));
msg = ixp_enc_u16(msg, stat->type);
msg = ixp_enc_u32(msg, stat->dev);
msg = ixp_enc_qid(msg, &stat->qid);
@ -179,10 +179,10 @@ ixp_enc_stat(unsigned char *msg, Stat * stat)
}
void *
ixp_dec_stat(unsigned char *msg, Stat * stat, unsigned short *len)
ixp_dec_stat(unsigned char *msg, Stat * stat)
{
unsigned short dummy;
msg = ixp_dec_u16(msg, len);
msg += sizeof(unsigned short);
msg = ixp_dec_u16(msg, &stat->type);
msg = ixp_dec_u32(msg, &stat->dev);
msg = ixp_dec_qid(msg, &stat->qid);

View File

@ -255,7 +255,7 @@ void *ixp_dec_prefix(unsigned char *msg, unsigned int *size,
void *ixp_enc_qid(unsigned char *msg, Qid * qid);
void *ixp_dec_qid(unsigned char *msg, Qid * qid);
void *ixp_enc_stat(unsigned char *msg, Stat * stat);
void *ixp_dec_stat(unsigned char *msg, Stat * stat, unsigned short *len);
void *ixp_dec_stat(unsigned char *msg, Stat * stat);
/* message.c */
unsigned short ixp_sizeof_stat(Stat * stat);

View File

@ -21,7 +21,7 @@ unsigned short
ixp_sizeof_stat(Stat * stat)
{
return IXP_QIDSZ
+ sizeof(unsigned short)
+ 2 * sizeof(unsigned short)
+ 4 * sizeof(unsigned int)
+ sizeof(unsigned long long)
+ sizeof_string(stat->name)
@ -194,10 +194,12 @@ ixp_fcall_to_msg(Fcall * fcall, void *msg, unsigned int msglen)
p = ixp_enc_u32(p, fcall->fid);
break;
case RSTAT:
p = ixp_enc_u16(p, ixp_sizeof_stat(&fcall->stat));
p = ixp_enc_stat(p, &fcall->stat);
break;
case TWSTAT:
p = ixp_enc_u32(p, fcall->fid);
p = ixp_enc_u16(p, ixp_sizeof_stat(&fcall->stat));
p = ixp_enc_stat(p, &fcall->stat);
break;
}
@ -221,8 +223,7 @@ ixp_msg_to_fcall(void *msg, unsigned int msglen, Fcall * fcall)
case TVERSION:
case RVERSION:
p = ixp_dec_u32(p, &fcall->maxmsg);
p = ixp_dec_string(p, fcall->version, sizeof(fcall->version),
&len);
p = ixp_dec_string(p, fcall->version, sizeof(fcall->version), &len);
break;
case TAUTH:
p = ixp_dec_u32(p, &fcall->afid);
@ -300,11 +301,13 @@ ixp_msg_to_fcall(void *msg, unsigned int msglen, Fcall * fcall)
p = ixp_dec_u32(p, &fcall->fid);
break;
case RSTAT:
p = ixp_dec_stat(p, &fcall->stat, &len);
p = ixp_dec_u16(p, &len);
p = ixp_dec_stat(p, &fcall->stat);
break;
case TWSTAT:
p = ixp_dec_u32(p, &fcall->fid);
p = ixp_dec_stat(p, &fcall->stat, &len);
p = ixp_dec_u16(p, &len);
p = ixp_dec_stat(p, &fcall->stat);
break;
}