1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-30 12:04:07 +00:00

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
This commit is contained in:
Andriy Gapon 2011-09-13 14:01:35 +00:00
parent 940acbaba3
commit b13391ced2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=225529

View File

@ -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);
}