int main(int argc, char** argv) { int i, n, off; int fd[99]; spa_t *spa; dnode_phys_t dn; char buf[512]; zfs_init(); if (argc == 1) { static char *av[] = { "zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", NULL, }; argc = 4; argv = av; } for (i = 1; i < argc; i++) { fd[i] = open(argv[i], O_RDONLY); if (fd[i] < 0) continue; if (vdev_probe(vdev_read, &fd[i], NULL) != 0) close(fd[i]); } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (!spa || zfs_mount_pool(spa)) exit(1); if (zfs_lookup(spa, "zfs.c", &dn)) exit(1); off = 0; do { n = zfs_read(spa, &dn, buf, 512, off); write(1, buf, n); off += n; } while (n == 512); }
int main(int argc, char** argv) { char buf[512]; int fd[100]; struct stat sb; dnode_phys_t dn; spa_t *spa; off_t off; ssize_t n; int i; zfs_init(); if (argc == 1) { static char *av[] = { "zfstest", "COPYRIGHT", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", NULL, }; argc = 5; argv = av; } for (i = 2; i < argc; i++) { fd[i] = open(argv[i], O_RDONLY); if (fd[i] < 0) continue; if (vdev_probe(vdev_read, &fd[i], NULL) != 0) close(fd[i]); } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (spa == NULL) { fprintf(stderr, "no pools\n"); exit(1); } 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 = sb.st_size - off; n = n > sizeof(buf) ? sizeof(buf) : n; n = zfs_read(spa, &dn, buf, n, off); if (n < 0) { fprintf(stderr, "zfs_read failed\n"); exit(1); } write(1, buf, n); off += n; } while (off < sb.st_size); return (0); }