Esempio n. 1
0
File: psort.c Progetto: BWK/os161
static
void
validate(void)
{
	int smallest, largest, prev_largest;
	int i, fd;
	const char *name;

	doforkall("Validation", dovalidate);
	checksize_valid();

	prev_largest = 1;

	for (i=0; i<numprocs; i++) {
		name = validname(i);
		fd = doopen(name, O_RDONLY, 0);

		doexactread(name, fd, &smallest, sizeof(int));
		doexactread(name, fd, &largest, sizeof(int));

		if (smallest < 1) {
			complainx("Validation: block %d: bad SMALLEST", i);
			exit(1);
		}
		if (largest >= RANDOM_MAX) {
			complainx("Validation: block %d: bad LARGEST", i);
			exit(1);
		}
		if (smallest > largest) {
			complainx("Validation: block %d: SMALLEST > LARGEST",
				  i);
			exit(1);
		}

		if (smallest < prev_largest) {
			complain("Validation: block %d smallest key %d",
				 i, smallest);
			complain("Validation: previous block largest key %d",
				 prev_largest);
			complain("Validation failed");
			exit(1);
		}
	}


	for (i=0; i<numprocs; i++) {
		doremove(validname(i));
	}
}
Esempio n. 2
0
File: dev.c Progetto: 8l/inferno
/*
 * check that the name in a wstat is plausible
 */
void
validwstatname(char *name)
{
	validname(name, 0);
	if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		error(Efilename);
}
Esempio n. 3
0
void
validstat(uint8_t *s, usize n)
{
	usize m;
	char buf[64];

	if(statcheck(s, n) < 0)
		error(Ebadstat);
	/* verify that name entry is acceptable */
	s += STATFIXLEN - 4*BIT16SZ;	/* location of first string */
	/*
	 * s now points at count for first string.
	 * if it's too long, let the server decide; this is
	 * only for his protection anyway. otherwise
	 * we'd have to allocate and waserror.
	 */
	m = GBIT16(s);
	s += BIT16SZ;
	if(m+1 > sizeof buf)
		return;
	memmove(buf, s, m);
	buf[m] = '\0';
	/* name could be '/' */
	if(strcmp(buf, "/") != 0)
		validname(buf, 0);
}
Esempio n. 4
0
File: psort.c Progetto: BWK/os161
static
void
dovalidate(void)
{
	const char *name;
	int fd, i, mykeys, keys_done, keys_to_do;
	int key, smallest, largest;

	name = PATH_SORTED;
	fd = doopen(name, O_RDONLY, 0);

	mykeys = getmykeys();
	seekmyplace(name, fd);

	smallest = RANDOM_MAX;
	largest = 0;

	keys_done = 0;
	while (keys_done < mykeys) {
		keys_to_do = mykeys - keys_done;
		if (keys_to_do > WORKNUM) {
			keys_to_do = WORKNUM;
		}

		doexactread(name, fd, workspace, keys_to_do * sizeof(int));

		for (i=0; i<keys_to_do; i++) {
			key = workspace[i];

			if (key < 0) {
				complain("%s: found negative key", name);
				exit(1);
			}
			if (key == 0) {
				complain("%s: found zero key", name);
				exit(1);
			}
			if (key >= RANDOM_MAX) {
				complain("%s: found too-large key", name);
				exit(1);
			}

			if (key < smallest) {
				smallest = key;
			}
			if (key > largest) {
				largest = key;
			}
		}

		keys_done += keys_to_do;
	}
	doclose(name, fd);

	name = validname(me);
	fd = doopen(name, O_WRONLY|O_CREAT|O_TRUNC, 0664);
	dowrite(name, fd, &smallest, sizeof(smallest));
	dowrite(name, fd, &largest, sizeof(largest));
	doclose(name, fd);
}
Esempio n. 5
0
static long
dsoaction(char** args, int nargs){
	long r = 0;

	// Comprobar que no introdujo '/'
	if(nargs > 1)
		validname(args[1],0);

	// Bloqueo al introducir nuevo dispositivos
	qlock(&fichLock);

	if(strcmp(args[0],"+") == 0){
		if(nargs > 3)
			r = dsoconcat(args,nargs);
		else{
			qunlock(&fichLock);
			error("#Q: USO: + <dest> <origen1> ... <origenN>");
		}
	}else
	if(strcmp(args[0],"p") == 0){
		if(nargs == 5)
			r = dsopart(args,nargs);
		else{
			qunlock(&fichLock);
			error("#Q: USO: p <dest> <offset> <size> <origen>");
		}
	}else
	if(strcmp(args[0],"m") == 0){
		if(nargs > 3)
			r = dsomirror(args,nargs);
		else{
			qunlock(&fichLock);
			error("#Q: USO: m <dest> <origen1> ... <origenN>");
		}
	}else
	if(strcmp(args[0],"i") == 0){
		if(nargs > 3)
			r = dsointerl(args,nargs);
		else{
			qunlock(&fichLock);
			error("#Q: USO: i <dest> <origen1> ... <origenN>");
		}
	}else{
		qunlock(&fichLock);
		error("#Q: Comando invalido");
	}

	qunlock(&fichLock);
	return r;
}
Esempio n. 6
0
File: psort.c Progetto: BWK/os161
static
void
checksize_valid(void)
{
	off_t totvsize, correctvsize;
	int i;

	correctvsize = (off_t) numprocs*2*sizeof(int);

	totvsize = 0;
	for (i=0; i<numprocs; i++) {
		totvsize += getsize(validname(i));
	}
	if (totvsize != correctvsize) {
		complainx("Sum of validation sizes is wrong "
			  "(%ld, should be %ld)",
			  (long) totvsize, (long) correctvsize);
		exit(1);
	}
}
Esempio n. 7
0
int sysfauth(int fd, char *aname)
{
	ERRSTACK(2);
	struct chan *c, *ac;

	if (waserror()) {
		poperror();
		return -1;
	}

	validname(aname, 0);
	c = fdtochan(&current->open_files, fd, O_RDWR, 0, 1);
	if (waserror()) {
		cclose(c);
		nexterror();
	}

	ac = mntauth(c, aname);

	/* at this point ac is responsible for keeping c alive */
	poperror();	/* c */
	cclose(c);

	if (waserror()) {
		cclose(ac);
		nexterror();
	}

	fd = newfd(ac, 0);
	if (fd < 0)
		error(-fd, ERROR_FIXME);
	poperror();	/* ac */

	poperror();

	return fd;
}
Esempio n. 8
0
File: dev.c Progetto: anandab/akaros
/*
 * check that the name in a wstat is plausible
 */
void validwstatname(char *name)
{
	validname(name, 0);
	if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		error(EINVAL, ERROR_FIXME);
}
Esempio n. 9
0
long
bindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char* spec)
{
	int ret;
	Chan *c0, *c1, *ac, *bc;
	struct{
		Chan	*chan;
		Chan	*authchan;
		char	*spec;
		int	flags;
	}bogus;

	if((flag&~MMASK) || (flag&MORDER)==(MBEFORE|MAFTER))
		error(Ebadarg);

	bogus.flags = flag & MCACHE;

	if(ismount){
		if(up->pgrp->noattach)
			error(Enoattach);

		ac = nil;
		bc = fdtochan(fd, ORDWR, 0, 1);
		if(waserror()) {
			if(ac)
				cclose(ac);
			cclose(bc);
			nexterror();
		}

		if(afd >= 0)
			ac = fdtochan(afd, ORDWR, 0, 1);

		bogus.chan = bc;
		bogus.authchan = ac;

		validaddr((ulong)spec, 1, 0);
		bogus.spec = spec;
		if(waserror())
			error(Ebadspec);
		validname(spec, 1);
		poperror();

		ret = devno('M', 0);
		c0 = devtab[ret]->attach((char*)&bogus);

		poperror();
		if(ac)
			cclose(ac);
		cclose(bc);
	}else{
		bogus.spec = 0;
		validaddr((ulong)arg0, 1, 0);
		c0 = namec(arg0, Abind, 0, 0);
	}

	if(waserror()){
		cclose(c0);
		nexterror();
	}

	validaddr((ulong)arg1, 1, 0);
	c1 = namec(arg1, Amount, 0, 0);
	if(waserror()){
		cclose(c1);
		nexterror();
	}

	ret = cmount(&c0, c1, flag, bogus.spec);

	poperror();
	cclose(c1);
	poperror();
	cclose(c0);
	if(ismount)
		fdclose(fd, 0);

	return ret;
}
Esempio n. 10
0
/*
 * check that the name in a wstat is plausible
 */
void validwstatname(char *name)
{
	validname(name, 0);
	if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		error(EINVAL, NULL);
}