Ejemplo n.º 1
0
static
void
docreate(const char *file, const char *sizespec, int doforce)
{
    int fd;
    off_t size;

    if (!doforce) {
        fd = open(file, O_RDONLY);
        if (fd >= 0) {
            fprintf(stderr, "disk161: %s: %s\n", file,
                    strerror(EEXIST));
            exit(1);
        }
    }

    fd = doopen(file, O_RDWR|O_CREAT|O_TRUNC, 0664);
    doflock(file, fd, LOCK_EX);
    size = getsize(sizespec);
    checksize(size);
    dotruncate(file, fd, HEADERSIZE + size);
    writeheader(file, fd);
    doflock(file, fd, LOCK_UN);
    close(fd);
}
Ejemplo n.º 2
0
static
void
doresize(const char *file, const char *sizespec)
{
    enum { M_SET, M_PLUS, M_MINUS } mode;
    off_t oldsize, newsize;
    int fd;

    if (*sizespec == '+') {
        sizespec++;
        mode = M_PLUS;
    }
    else if (*sizespec == '-') {
        sizespec++;
        mode = M_MINUS;
    }
    else {
        mode = M_SET;
    }

    newsize = getsize(sizespec);
    fd = doopen(file, O_RDWR, 0);
    doflock(file, fd, LOCK_EX);
    checkheader(file, fd);
    oldsize = filesize(file, fd);
    oldsize -= HEADERSIZE;
    switch (mode) {
    case M_SET:
        break;
    case M_PLUS:
        if (oldsize + newsize < oldsize) {
            /* overflow */
            fprintf(stderr, "+%s: Result too large\n", sizespec);
            exit(1);
        }
        newsize = oldsize + newsize;
        break;
    case M_MINUS:
        if (oldsize < newsize) {
            /* underflow */
            fprintf(stderr, "-%s: Result too small\n", sizespec);
            exit(1);
        }
        newsize = oldsize - newsize;
        break;
    }

    checksize(newsize);
    dotruncate(file, fd, HEADERSIZE + newsize);
    doflock(file, fd, LOCK_UN);
    close(fd);
}
Ejemplo n.º 3
0
void
test(void)
{
	unsigned long	offset;
	unsigned long	size = maxoplen;
	unsigned long	rv = random();
	unsigned long	op;

	if (simulatedopcount > 0 && testcalls == simulatedopcount)
		writefileimage();

	testcalls++;

	if (closeprob)
		closeopen = (rv >> 3) < (1u << 28) / (unsigned)closeprob;

	if (debugstart > 0 && testcalls >= debugstart)
		debug = 1;

	if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
		prt("%lu...\n", testcalls);

	offset = random();
	if (randomoplen)
		size = random() % (maxoplen + 1);

	/* calculate appropriate op to run */
	if (lite)
		op = rv % OP_MAX_LITE;
	else
		op = rv % OP_MAX_FULL;

	switch (op) {
	case OP_MAPREAD:
		if (!mapped_reads)
			op = OP_READ;
		break;
	case OP_MAPWRITE:
		if (!mapped_writes)
			op = OP_WRITE;
		break;
	case OP_FALLOCATE:
		if (!fallocate_calls) {
			log4(OP_SKIPPED, OP_FALLOCATE, offset, size);
			goto out;
		}
		break;
	case OP_PUNCH_HOLE:
		if (!punch_hole_calls) {
			log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, size);
			goto out;
		}
		break;
	}

	switch (op) {
	case OP_READ:
		TRIM_OFF_LEN(offset, size, file_size);
		doread(offset, size);
		break;

	case OP_WRITE:
		TRIM_OFF_LEN(offset, size, maxfilelen);
		dowrite(offset, size);
		break;

	case OP_MAPREAD:
		TRIM_OFF_LEN(offset, size, file_size);
		exit(183);
		break;

	case OP_MAPWRITE:
		TRIM_OFF_LEN(offset, size, maxfilelen);
		exit(182);
		break;

	case OP_TRUNCATE:
		if (!style)
			size = random() % maxfilelen;
		dotruncate(size);
		break;

	case OP_PUNCH_HOLE:
		TRIM_OFF_LEN(offset, size, file_size);
		do_punch_hole(offset, size);
		break;
	default:
		prterr("test: unknown operation");
		report_failure(42);
		break;
	}

out:
	if (sizechecks && testcalls > simulatedopcount)
		check_size();
	if (closeopen)
		docloseopen();
}
Ejemplo n.º 4
0
void
test(void)
{
	unsigned long	offset;
	unsigned long	size = maxoplen;
	unsigned long	rv = random();
	unsigned long	op = rv % (3 + !lite + mapped_writes);

        /* turn off the map read if necessary */

        if (op == 2 && !mapped_reads)
            op = 0;

	if (simulatedopcount > 0 && testcalls == simulatedopcount)
		writefileimage();

	testcalls++;

	if (closeprob)
		closeopen = (rv >> 3) < (1 << 28) / closeprob;

	if (debugstart > 0 && testcalls >= debugstart)
		debug = 1;

	if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
		prt("%lu...\n", testcalls);

	/*
	 * READ:	op = 0
	 * WRITE:	op = 1
	 * MAPREAD:     op = 2
	 * TRUNCATE:	op = 3
	 * MAPWRITE:    op = 3 or 4
	 */
	if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
		dotruncate(random() % maxfilelen);
	else {
		if (randomoplen)
			size = random() % (maxoplen+1);
		if (lite ? 0 : op == 3)
			dotruncate(size);
		else {
			offset = random();
			if (op == 1 || op == (lite ? 3 : 4)) {
				offset %= maxfilelen;
				if (offset + size > maxfilelen)
					size = maxfilelen - offset;
				if (op != 1)
					domapwrite(offset, size);
				else
					dowrite(offset, size);
			} else {
				if (file_size)
					offset %= file_size;
				else
					offset = 0;
				if (offset + size > file_size)
					size = file_size - offset;
				if (op != 0)
					domapread(offset, size);
				else
					doread(offset, size);
			}
		}
	}
	if (sizechecks && testcalls > simulatedopcount)
		check_size();
	if (closeopen)
		docloseopen();
}