-# $OpenBSD: Makefile.inc,v 1.1 2017/05/29 11:01:16 sf Exp $
+# $OpenBSD: Makefile.inc,v 1.2 2017/05/29 13:49:40 bluhm Exp $
TESTS= create read mmap
FILEOPS_MNT= /mnt/regress-fileops
FILEOPS_PROG= ${.OBJDIR}/../fileops
-IMG= ${.OBJDIR}/diskimage
-CLEANFILES= ${IMG} stamp-*
-
+CLEANFILES= diskimage stamp-*
.poison !defined (MOUNT)
.poison !defined (NEWFS)
.PHONY: disk mount unconfig clean
disk: unconfig
- dd if=/dev/urandom of=${IMG} bs=1M count=32
- vnconfig vnd0 ${IMG}
+ dd if=/dev/urandom of=diskimage bs=1M count=32
+ vnconfig vnd0 diskimage
${NEWFS} /dev/rvnd0c
mount: disk
-umount -f /dev/vnd0c 2>/dev/null || true
-rmdir ${FILEOPS_MNT} 2>/dev/null || true
-vnconfig -u vnd0 2>/dev/null || true
- -rm -f stamp-setup ${IMG}
+ -rm -f stamp-setup diskimage
stamp-setup:
@echo '\n======== $@ ========'
-/* $OpenBSD: fileops.c,v 1.1 2017/05/29 11:01:16 sf Exp $ */
+/* $OpenBSD: fileops.c,v 1.2 2017/05/29 13:49:40 bluhm Exp $ */
/*
* Copyright (c) 2017 Stefan Fritsch <sf@sfritsch.de>
*
#define BUFSIZE (16 * 1024)
#define HOLESIZE (16 * BUFSIZE)
-#define myerr(rc, fmt, ...) \
- do { err(rc, fmt "\nFAILED", ## __VA_ARGS__); } while (0)
-#define myerrx(rc, fmt, ...) \
- do { errx(rc, fmt "\nFAILED", ## __VA_ARGS__); } while (0)
-
static int debug = 0;
static int fd = -1;
static off_t curpos = 0;
const uint32_t *ibuf = buf;
for (size_t i = 0; i < size / 4; i++) {
if (ibuf[i] != seed + i) {
- myerrx(3, "%s: pos %zd/%zd: expected %#08zx got %#08x\n", __func__, 4 * i, size, seed + i, ibuf[i]);
+ errx(3, "%s: pos %zd/%zd: expected %#08zx got %#08x",
+ __func__, 4 * i, size, seed + i, ibuf[i]);
}
}
}
const uint32_t *ibuf = buf;
for (size_t i = 0; i < size / 4; i++) {
if (ibuf[i] != 0) {
- myerrx(3, "%s: pos %zd/%zd: expected 0 got %#08x\n", __func__, 4 * i, size, ibuf[i]);
+ errx(3, "%s: pos %zd/%zd: expected 0 got %#08x",
+ __func__, 4 * i, size, ibuf[i]);
}
}
}
{
if (have != want) {
if (have == -1)
- myerr(2, "%s returned %lld, expected %lld", what, have, want);
+ err(2, "%s returned %lld, expected %lld",
+ what, have, want);
else
- myerrx(2, "%s returned %lld, expected %lld", what, have, want);
+ errx(2, "%s returned %lld, expected %lld",
+ what, have, want);
}
if (debug)
curpos += offset;
break;
default:
- myerrx(1, "c_lseek not supported");
+ errx(1, "c_lseek not supported");
}
check("lseek", ret, curpos);
if (debug)
{
mbuf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, curpos);
if (mbuf == MAP_FAILED)
- myerr(2, "mmap %zd pos %lld failed", size, (long long)curpos);
+ err(2, "mmap %zd pos %lld failed", size, (long long)curpos);
curpos += size;
if (debug)
printf("mmap: %p\n", mbuf);
{
int ret = munmap(mbuf, size);
if (ret != 0)
- myerr(2, "munmap");
+ err(2, "munmap");
}
void
{
fd = open(fname, flags, S_IRUSR|S_IWUSR);
if (fd == -1)
- myerr(1, "open");
+ err(1, "open");
}
void
void
usage(void)
{
- myerrx(1, "usage: fileops (create|read|mmap) filename");
+ errx(1, "usage: fileops (create|read|mmap) filename");
}
int main(int argc, char **argv)
fname = argv[2];
gbuf = malloc(BUFSIZE);
if (gbuf == NULL)
- myerrx(1, "malloc");
+ err(1, "malloc");
if (strcmp(argv[1], "create") == 0) {
do_create();
usage();
}
- printf("ok\n");
+ printf("pass\n");
return 0;
}