Пример #1
0
void
ixp_pstrings(IxpMsg *msg, ushort *num, char *strings[]) {
	uchar *s;
	uint i, size;
	ushort len;

	ixp_pu16(msg, num);
	if(*num > IXP_MAX_WELEM) {
		msg->pos = msg->end+1;
		return;
	}

	if(msg->mode == MsgUnpack) {
		s = msg->pos;
		size = 0;
		for(i=0; i < *num; i++) {
			ixp_pu16(msg, &len);
			msg->pos += len;
			size += len;
			if(msg->pos > msg->end)
				return;
		}
		msg->pos = s;
		size += *num;
		s = emalloc(size);
	}

	for(i=0; i < *num; i++) {
		if(msg->mode == MsgPack)
			len = strlen(strings[i]);
		ixp_pu16(msg, &len);

		if(msg->mode == MsgUnpack) {
			memcpy(s, msg->pos, len);
			strings[i] = (char*)s;
			s += len;
			msg->pos += len;
			*s++ = '\0';
		}else
			ixp_pdata(msg, &strings[i], len);
	}
}
Пример #2
0
void
ixp_pfcall(IxpMsg *msg, IxpFcall *fcall) {
	ixp_pu8(msg, &fcall->hdr.type);
	ixp_pu16(msg, &fcall->hdr.tag);

	switch (fcall->hdr.type) {
	case TVersion:
	case RVersion:
		ixp_pu32(msg, &fcall->version.msize);
		ixp_pstring(msg, &fcall->version.version);
		break;
	case TAuth:
		ixp_pu32(msg, &fcall->tauth.afid);
		ixp_pstring(msg, &fcall->tauth.uname);
		ixp_pstring(msg, &fcall->tauth.aname);
		break;
	case RAuth:
		ixp_pqid(msg, &fcall->rauth.aqid);
		break;
	case RAttach:
		ixp_pqid(msg, &fcall->rattach.qid);
		break;
	case TAttach:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu32(msg, &fcall->tattach.afid);
		ixp_pstring(msg, &fcall->tattach.uname);
		ixp_pstring(msg, &fcall->tattach.aname);
		break;
	case RError:
		ixp_pstring(msg, &fcall->error.ename);
		break;
	case TFlush:
		ixp_pu16(msg, &fcall->tflush.oldtag);
		break;
	case TWalk:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu32(msg, &fcall->twalk.newfid);
		ixp_pstrings(msg, &fcall->twalk.nwname, fcall->twalk.wname, nelem(fcall->twalk.wname));
		break;
	case RWalk:
		ixp_pqids(msg, &fcall->rwalk.nwqid, fcall->rwalk.wqid, nelem(fcall->rwalk.wqid));
		break;
	case TOpen:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu8(msg, &fcall->topen.mode);
		break;
	case ROpen:
	case RCreate:
		ixp_pqid(msg, &fcall->ropen.qid);
		ixp_pu32(msg, &fcall->ropen.iounit);
		break;
	case TCreate:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pstring(msg, &fcall->tcreate.name);
		ixp_pu32(msg, &fcall->tcreate.perm);
		ixp_pu8(msg, &fcall->tcreate.mode);
		break;
	case TRead:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu64(msg, &fcall->tread.offset);
		ixp_pu32(msg, &fcall->tread.count);
		break;
	case RRead:
		ixp_pu32(msg, &fcall->rread.count);
		ixp_pdata(msg, &fcall->rread.data, fcall->rread.count);
		break;
	case TWrite:
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu64(msg, &fcall->twrite.offset);
		ixp_pu32(msg, &fcall->twrite.count);
		ixp_pdata(msg, &fcall->twrite.data, fcall->twrite.count);
		break;
	case RWrite:
		ixp_pu32(msg, &fcall->rwrite.count);
		break;
	case TClunk:
	case TRemove:
	case TStat:
		ixp_pu32(msg, &fcall->hdr.fid);
		break;
	case RStat:
		ixp_pu16(msg, &fcall->rstat.nstat);
		ixp_pdata(msg, (char**)&fcall->rstat.stat, fcall->rstat.nstat);
		break;
	case TWStat: {
		uint16_t size;
		ixp_pu32(msg, &fcall->hdr.fid);
		ixp_pu16(msg, &size);
		ixp_pstat(msg, &fcall->twstat.stat);
		break;
		}
	}
}