Exemple #1
0
void
entryPack(Entry *e, uchar *p, int index)
{
	ulong t32;
	int flags;

	p += index * VtEntrySize;

	U32PUT(p, e->gen);
	U16PUT(p+4, e->psize);
	U16PUT(p+6, e->dsize);
	flags = e->flags | ((e->depth << VtEntryDepthShift) & VtEntryDepthMask);
	U8PUT(p+8, flags);
	memset(p+9, 0, 5);
	U48PUT(p+14, e->size, t32);

	if(flags & VtEntryLocal){
		if(globalToLocal(e->score) == NilBlock)
			abort();
		memset(p+20, 0, 7);
		U8PUT(p+27, e->archive);
		U32PUT(p+28, e->snap);
		U32PUT(p+32, e->tag);
		memmove(p+36, e->score+16, 4);
	}else
		memmove(p+20, e->score, VtScoreSize);
}
Exemple #2
0
void
labelPack(Label *l, uchar *p, int i)
{
	p += i*LabelSize;
	U8PUT(p, l->state);
	U8PUT(p+1, l->type);
	U32PUT(p+2, l->epoch);
	U32PUT(p+6, l->epochClose);
	U32PUT(p+10, l->tag);
}
Exemple #3
0
void
headerPack(Header *h, uchar *p)
{
	memset(p, 0, HeaderSize);
	U32PUT(p, HeaderMagic);
	U16PUT(p+4, HeaderVersion);
	U16PUT(p+6, h->blockSize);
	U32PUT(p+8, h->super);
	U32PUT(p+12, h->label);
	U32PUT(p+16, h->data);
	U32PUT(p+20, h->end);
}
Exemple #4
0
void
dePack(DirEntry *dir, MetaEntry *me)
{
	uchar *p;
	ulong t32;

	p = me->p;

	U32PUT(p, DirMagic);
	U16PUT(p+4, 9);		/* version */
	p += 6;

	p += stringPack(dir->elem, p);

	U32PUT(p, dir->entry);
	U32PUT(p+4, dir->gen);
	U32PUT(p+8, dir->mentry);
	U32PUT(p+12, dir->mgen);
	U64PUT(p+16, dir->qid, t32);
	p += 24;

	p += stringPack(dir->uid, p);
	p += stringPack(dir->gid, p);
	p += stringPack(dir->mid, p);

	U32PUT(p, dir->mtime);
	U32PUT(p+4, dir->mcount);
	U32PUT(p+8, dir->ctime);
	U32PUT(p+12, dir->atime);
	U32PUT(p+16, dir->mode);
	p += 5*4;

	if(dir->qidSpace){
		U8PUT(p, DeQidSpace);
		U16PUT(p+1, 2*8);
		p += 3;
		U64PUT(p, dir->qidOffset, t32);
		U64PUT(p+8, dir->qidMax, t32);
		p += 16;
	}

	assert(p == me->p + me->size);
}
Exemple #5
0
void
mbPack(MetaBlock *mb)
{
	uchar *p;

	p = mb->buf;

	assert(!mb->botch);

	U32PUT(p, MetaMagic);
	U16PUT(p+4, mb->size);
	U16PUT(p+6, mb->free);
	U16PUT(p+8, mb->maxindex);
	U16PUT(p+10, mb->nindex);
}
Exemple #6
0
void
vtentrypack(VtEntry *e, uchar *p, int index)
{
	ulong t32;
	int flags;
	uchar *op;
	int depth;
	int psize, dsize;

	p += index * VtEntrySize;
	op = p;

	depth = e->type&VtTypeDepthMask;
	flags = (e->flags&~(_VtEntryDir|_VtEntryDepthMask));
	flags |= depth << _VtEntryDepthShift;
	if(e->type - depth == VtDirType)
		flags |= _VtEntryDir;
	U32PUT(p, e->gen);
	p += 4;
	psize = e->psize;
	dsize = e->dsize;
	if(psize >= (1<<16) || dsize >= (1<<16)) {
		flags |= _VtEntryBig;
		psize = vttobig(psize);
		dsize = vttobig(dsize);
		if(psize < 0 || dsize < 0)
			sysfatal("invalid entry psize/dsize: %ld/%ld", e->psize, e->dsize);
	}
	U16PUT(p, psize);
	p += 2;
	U16PUT(p, dsize);
	p += 2;
	U8PUT(p, flags);
	p++;
	memset(p, 0, 5);
	p += 5;
	U48PUT(p, e->size, t32);
	p += 6;
	memmove(p, e->score, VtScoreSize);
	p += VtScoreSize;

	assert(p-op == VtEntrySize);
}
Exemple #7
0
/*
 * write out a single bucket
 */
static int
flushiebuck(IEBucks *ib, int b, int reset)
{
	uint32_t n;

	if(ib->bucks[b].used == 0)
		return 0;
	n = ib->bucks[b].used;
	U32PUT(&ib->bucks[b].buf[n], ib->bucks[b].head);
	n += U32Size;
	USED(n);
	if(writepart(ib->part, (uint64_t)ib->chunks * ib->size, ib->bucks[b].buf, ib->size) < 0){
		seterr(EOk, "can't write sorting bucket to file: %r");
xabort();
		return -1;
	}
	ib->bucks[b].head = ib->chunks++;
	ib->bucks[b].total += ib->bucks[b].used;
	if(reset)
		ib->bucks[b].used = 0;
	return 0;
}
Exemple #8
0
void
superPack(Super *s, uchar *p)
{
	u32int t32;

	memset(p, 0, SuperSize);
	U32PUT(p, SuperMagic);
	assert(s->version == SuperVersion);
	U16PUT(p+4, s->version);
	U32PUT(p+6, s->epochLow);
	U32PUT(p+10, s->epochHigh);
	U64PUT(p+14, s->qid, t32);
	U32PUT(p+22, s->active);
	U32PUT(p+26, s->next);
	U32PUT(p+30, s->current);
	memmove(p+34, s->last, VtScoreSize);
	memmove(p+54, s->name, sizeof(s->name));
}
Exemple #9
0
void
localToGlobal(u32int addr, uchar score[VtScoreSize])
{
	memset(score, 0, VtScoreSize-4);
	U32PUT(score+VtScoreSize-4, addr);
}
Exemple #10
0
void
localToGlobal(uint32_t addr, uint8_t score[VtScoreSize])
{
	memset(score, 0, VtScoreSize-4);
	U32PUT(score+VtScoreSize-4, addr);
}
Exemple #11
0
int
convC2P(Pcall *c, uint8 *ap/*[Npkt]]*/)
{
	uint8 *p = ap;
	uint32 chk;
	uint size = sizeC2P[c->type];

	*p++ = c->type;
	*p++ = 0;
	*p++ = c->tag;
	*p++ = size;

	if(pumpchk(p-4, 4, &chk) < 0)
		return -1;

	U32PUTLE(p, chk);
	p += 4;

	/* Clear out our garbage. */
	memset(p, 0, Npkt-8);

	switch(c->type){
	default:	break;

	case Twakeup:
		*p++ = 0x49;
		*p++ = 0x01;
		*p++ = 0x2d;
		*p++ = 0x14;
		break;

	case Tbolus:
		if(c->bolus.minutes % 6 != 0){
			/* The pump does not seem to accept other durations. */
			werrstr("combo duration must be a multiple of 6");
			return -1;
		}

		*p++ = c->bolus.minutes == 0 ? 0x00 : 0x01;
		*p++ = 0x00;

		/* They seem to be in "extra careful" mode here. */
		U16PUTLE(p, c->bolus.insulin);
		p += 2;
		U16PUTLE(p, 0xffff^c->bolus.insulin);
		p += 2;
		*p++ = c->bolus.minutes/6;

		/* zeroes! (for now) */
		p += 28-7;

		break;

	case Tclearwarn:
		*p++ = 0xa7;
		*p++ = 0x01;
		break;
	}
	
	if(p-ap!=size+8)
		return -1;

	if(size > 0){
		chk = crc32(ap+8, size);
		U32PUT(p, chk);
	}

	return 0;
}