diff options
author | Peter Holm <pho@FreeBSD.org> | 2021-11-25 11:44:59 +0000 |
---|---|---|
committer | Peter Holm <pho@FreeBSD.org> | 2021-11-25 11:44:59 +0000 |
commit | 171e56c19a11d39942929ea219b71b6b7b0398ae (patch) | |
tree | 324c9f303958efd73e6e45149c9b6ef959c2b9a0 | |
parent | b74fdaaf1cde6002b399ecfa99790e9368c8fc52 (diff) |
stress2: Added an option to set the file size. Added missing error checks
-rw-r--r-- | tools/test/stress2/tools/flip.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/tools/test/stress2/tools/flip.c b/tools/test/stress2/tools/flip.c index 816162947c45..8d01e9d78ea1 100644 --- a/tools/test/stress2/tools/flip.c +++ b/tools/test/stress2/tools/flip.c @@ -54,7 +54,7 @@ flip(void *ap, size_t len) { unsigned char *cp; int byte; - unsigned char bit, buf, mask, old; + unsigned char bit, buf, mask, old __unused; cp = (unsigned char *)ap; byte = random_long(0, len); @@ -75,15 +75,20 @@ main(int argc, char *argv[]) { struct stat st; off_t pos; + size_t size; int fd, i, times; char c; times = 1; - while ((c = getopt(argc, argv, "n:")) != -1) { + size = 0; + while ((c = getopt(argc, argv, "n:s:")) != -1) { switch (c) { case 'n': times = atoi(optarg); break; + case 's': + size = atol(optarg); + break; case '?': default: fprintf(stderr, @@ -103,18 +108,23 @@ main(int argc, char *argv[]) if ((fd = open(argv[0], O_RDWR)) == -1) err(1, "open(%s)", argv[0]); - if (fstat(fd, &st) == -1) - err(1, "stat %s", argv[0]); + if (size == 0) { + if (fstat(fd, &st) == -1) + err(1, "stat %s", argv[0]); + size = st.st_size; + } for (i = 0; i < times; i++) { - pos = arc4random() % st.st_size; + pos = arc4random() % size; if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek()"); - read(fd, &c, 1); + if (read(fd, &c, 1) != 1) + err(1, "read()"); flip(&c, 1); if (lseek(fd, pos, SEEK_SET) == -1) err(1, "lseek()"); - write(fd, &c, 1); + if (write(fd, &c, 1) != 1) + err(1, "write()"); } return (0); |