mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-17 15:27:36 +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:
parent
940acbaba3
commit
b13391ced2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=225529
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -37,14 +38,14 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define NBBY 8
|
#define NBBY 8
|
||||||
|
|
||||||
void
|
void
|
||||||
pager_output(const char *line)
|
pager_output(const char *line)
|
||||||
{
|
{
|
||||||
printf("%s", line);
|
fprintf(stderr, "%s", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "zfsimpl.c"
|
#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;
|
int fd = *(int *) priv;
|
||||||
|
|
||||||
if (pread(fd, buf, bytes, off) != bytes)
|
if (pread(fd, buf, bytes, off) != bytes)
|
||||||
return -1;
|
return (-1);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
n = size;
|
||||||
if (off + n > zp->zp_size)
|
if (off + n > zp->zp_size)
|
||||||
n = zp->zp_size - off;
|
n = zp->zp_size - off;
|
||||||
|
|
||||||
rc = dnode_read(spa, dn, off, buf, n);
|
rc = dnode_read(spa, dn, off, buf, n);
|
||||||
if (rc)
|
if (rc)
|
||||||
return (rc);
|
return (-rc);
|
||||||
|
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
@ -80,22 +81,24 @@ zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off)
|
|||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int i, n, off;
|
|
||||||
int fd[99];
|
|
||||||
spa_t *spa;
|
|
||||||
dnode_phys_t dn;
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
int fd[100];
|
||||||
|
struct stat sb;
|
||||||
|
dnode_phys_t dn;
|
||||||
|
spa_t *spa;
|
||||||
|
int i, n, off;
|
||||||
|
|
||||||
zfs_init();
|
zfs_init();
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
static char *av[] = {
|
static char *av[] = {
|
||||||
"zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
|
"zfstest", "COPYRIGHT",
|
||||||
|
"/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
argc = 4;
|
argc = 5;
|
||||||
argv = av;
|
argv = av;
|
||||||
}
|
}
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 2; i < argc; i++) {
|
||||||
fd[i] = open(argv[i], O_RDONLY);
|
fd[i] = open(argv[i], O_RDONLY);
|
||||||
if (fd[i] < 0)
|
if (fd[i] < 0)
|
||||||
continue;
|
continue;
|
||||||
@ -105,16 +108,37 @@ main(int argc, char** argv)
|
|||||||
spa_all_status();
|
spa_all_status();
|
||||||
|
|
||||||
spa = STAILQ_FIRST(&zfs_pools);
|
spa = STAILQ_FIRST(&zfs_pools);
|
||||||
if (!spa || zfs_mount_pool(spa))
|
if (spa == NULL) {
|
||||||
|
fprintf(stderr, "no pools\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (zfs_lookup(spa, "zfs.c", &dn))
|
if (zfs_mount_pool(spa)) {
|
||||||
|
fprintf(stderr, "can't mount pool\n");
|
||||||
exit(1);
|
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;
|
off = 0;
|
||||||
do {
|
do {
|
||||||
n = zfs_read(spa, &dn, buf, 512, off);
|
n = zfs_read(spa, &dn, buf, 512, off);
|
||||||
|
if (n < 0) {
|
||||||
|
fprintf(stderr, "zfs_read failed\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
write(1, buf, n);
|
write(1, buf, n);
|
||||||
off += n;
|
off += n;
|
||||||
} while (n == 512);
|
} while (off < sb.st_size);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user