summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2011-09-13 14:01:35 +0000
committeravg <avg@FreeBSD.org>2011-09-13 14:01:35 +0000
commitdab0468c873fe125b8dae06cd584e4933cfd69d1 (patch)
tree1b89fc8d634cb782a7d20e501a6c44e79a95dc5d /sys/boot
parent9d1d294a4a62c400092db17fe1e38ec33b8381a6 (diff)
downloadFreeBSD-src-dab0468c873fe125b8dae06cd584e4933cfd69d1.zip
FreeBSD-src-dab0468c873fe125b8dae06cd584e4933cfd69d1.tar.gz
zfstest: cleanup the code, improve functionality and diagnostics
The utility is not connected to the build, so it should be safe to update it. To do: move the utility to tools/. Some code is provided by Peter Jeremy <peterjeremy@acm.org> Tested by: Sebastian Chmielewski <chmielsster@gmail.com>, Peter Jeremy <peterjeremy@acm.org> (earlier versions) Approved by: re (kib) MFC after: 4 days
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/zfs/zfstest.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/sys/boot/zfs/zfstest.c b/sys/boot/zfs/zfstest.c
index 303ef5f..3e32da5 100644
--- a/sys/boot/zfs/zfstest.c
+++ b/sys/boot/zfs/zfstest.c
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/queue.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
@@ -37,14 +38,14 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
-#include <errno.h>
+#include <unistd.h>
#define NBBY 8
void
pager_output(const char *line)
{
- printf("%s", line);
+ fprintf(stderr, "%s", line);
}
#include "zfsimpl.c"
@@ -55,8 +56,8 @@ vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
int fd = *(int *) priv;
if (pread(fd, buf, bytes, off) != bytes)
- return -1;
- return 0;
+ return (-1);
+ return (0);
}
static int
@@ -69,10 +70,10 @@ zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off)
n = size;
if (off + n > zp->zp_size)
n = zp->zp_size - off;
-
+
rc = dnode_read(spa, dn, off, buf, n);
if (rc)
- return (rc);
+ return (-rc);
return (n);
}
@@ -80,22 +81,24 @@ zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off)
int
main(int argc, char** argv)
{
- int i, n, off;
- int fd[99];
- spa_t *spa;
- dnode_phys_t dn;
char buf[512];
+ int fd[100];
+ struct stat sb;
+ dnode_phys_t dn;
+ spa_t *spa;
+ int i, n, off;
zfs_init();
if (argc == 1) {
static char *av[] = {
- "zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
+ "zfstest", "COPYRIGHT",
+ "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
NULL,
};
- argc = 4;
+ argc = 5;
argv = av;
}
- for (i = 1; i < argc; i++) {
+ for (i = 2; i < argc; i++) {
fd[i] = open(argv[i], O_RDONLY);
if (fd[i] < 0)
continue;
@@ -105,16 +108,37 @@ main(int argc, char** argv)
spa_all_status();
spa = STAILQ_FIRST(&zfs_pools);
- if (!spa || zfs_mount_pool(spa))
+ if (spa == NULL) {
+ fprintf(stderr, "no pools\n");
exit(1);
+ }
- if (zfs_lookup(spa, "zfs.c", &dn))
+ if (zfs_mount_pool(spa)) {
+ fprintf(stderr, "can't mount pool\n");
exit(1);
+ }
+
+ if (zfs_lookup(spa, argv[1], &dn)) {
+ fprintf(stderr, "can't lookup\n");
+ exit(1);
+ }
+
+ if (zfs_dnode_stat(spa, &dn, &sb)) {
+ fprintf(stderr, "can't stat\n");
+ exit(1);
+ }
+
off = 0;
do {
n = zfs_read(spa, &dn, buf, 512, off);
+ if (n < 0) {
+ fprintf(stderr, "zfs_read failed\n");
+ exit(1);
+ }
write(1, buf, n);
off += n;
- } while (n == 512);
+ } while (off < sb.st_size);
+
+ return (0);
}
OpenPOWER on IntegriCloud