Exemple #1
0
void
ctlwrite(Req *r)
{
	int i;
	Cmdbuf *cb;
	vlong start, end;

	r->ofcall.count = r->ifcall.count;
	cb = parsecmd(r->ifcall.data, r->ifcall.count);
	if(cb->nf < 1){
		respond(r, "empty control message");
		free(cb);
		return;
	}

	if(strcmp(cb->f[0], "part") == 0){
		if(cb->nf != 4){
			respondcmderror(r, cb, "part takes 3 args");
			free(cb);
			return;
		}
		start = strtoll(cb->f[2], 0, 0);
		end = strtoll(cb->f[3], 0, 0);
		if(addpart(cb->f[1], start, end) < 0){
			respondcmderror(r, cb, "%r");
			free(cb);
			return;
		}
	}
	else if(strcmp(cb->f[0], "delpart") == 0){
		if(cb->nf != 2){
			respondcmderror(r, cb, "delpart takes 1 arg");
			free(cb);
			return;
		}
		if(delpart(cb->f[1]) < 0){
			respondcmderror(r, cb, "%r");
			free(cb);
			return;
		}
	}
	else if(strcmp(cb->f[0], "inquiry") == 0){
		if(cb->nf != 2){
			respondcmderror(r, cb, "inquiry takes 1 arg");
			free(cb);
			return;
		}
		free(inquiry);
		inquiry = estrdup9p(cb->f[1]);
	}
	else if(strcmp(cb->f[0], "geometry") == 0){
		if(cb->nf != 6){
			respondcmderror(r, cb, "geometry takes 5 args");
			free(cb);
			return;
		}
		nsect = strtoll(cb->f[1], 0, 0);
		sectsize = strtoll(cb->f[2], 0, 0);
		c = strtoll(cb->f[3], 0, 0);
		h = strtoll(cb->f[4], 0, 0);
		s = strtoll(cb->f[5], 0, 0);
		if(tab[0].inuse && strcmp(tab[0].name, "data") == 0 && tab[0].vers == 0){
			tab[0].offset = 0;
			tab[0].length = nsect;
		}
		for(i=0; i<nelem(tab); i++){
			if(tab[i].inuse && tab[i].offset+tab[i].length > nsect){
				tab[i].inuse = 0;
				free(tab[i].name);
				tab[i].name = 0;
			}
		}
	}
	else{
		respondcmderror(r, cb, "unknown control message");
		free(cb);
		return;
	}

	free(cb);
	respond(r, nil);
}
Exemple #2
0
static void
ctlwrite0(Req *r, char *msg, Cmdbuf *cb)
{
	vlong start, end;
	Part *p;

	r->ofcall.count = r->ifcall.count;

	if(cb->nf < 1){
		respond(r, "empty control message");
		return;
	}

	if(strcmp(cb->f[0], "part") == 0){
		if(cb->nf != 4){
			respondcmderror(r, cb, "part takes 3 args");
			return;
		}
		start = strtoll(cb->f[2], 0, 0);
		end = strtoll(cb->f[3], 0, 0);
		if(addpart(cb->f[1], start, end) < 0){
			respondcmderror(r, cb, "%r");
			return;
		}
	}
	else if(strcmp(cb->f[0], "delpart") == 0){
		if(cb->nf != 2){
			respondcmderror(r, cb, "delpart takes 1 arg");
			return;
		}
		if(delpart(cb->f[1]) < 0){
			respondcmderror(r, cb, "%r");
			return;
		}
	}
	else if(strcmp(cb->f[0], "inquiry") == 0){
		if(cb->nf != 2){
			respondcmderror(r, cb, "inquiry takes 1 arg");
			return;
		}
		free(inquiry);
		inquiry = estrdup9p(cb->f[1]);
	}
	else if(strcmp(cb->f[0], "geometry") == 0){
		if(cb->nf != 3){
			respondcmderror(r, cb, "geometry takes 2 args");
			return;
		}
		nsect = strtoll(cb->f[1], 0, 0);
		sectsize = strtoll(cb->f[2], 0, 0);
		if(tab[0].inuse && strcmp(tab[0].name, "data") == 0 &&
		    tab[0].vers == 0){
			tab[0].offset = 0;
			tab[0].length = nsect;
		}
		for(p = tab; p < tab + nelem(tab); p++)
			if(p->inuse && p->offset + p->length > nsect){
				p->inuse = 0;
				free(p->name);
				p->name = nil;
			}
	} else
		/* pass through to underlying ctl file, if any */
		if (write(ctlfd, msg, r->ifcall.count) != r->ifcall.count) {
			respondcmderror(r, cb, "%r");
			return;
		}
	respond(r, nil);
}