2 * Copyright (c) 2010 Doug Rabson
3 * Copyright (c) 2011 Andriy Gapon
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/param.h>
30 #include <sys/queue.h>
44 pager_output(const char *line)
46 fprintf(stderr, "%s", line);
50 #define printf(...) fprintf(stderr, __VA_ARGS__)
55 vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
57 int fd = *(int *) priv;
59 if (pread(fd, buf, bytes, off) != bytes)
65 zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off)
67 const znode_phys_t *zp = (const znode_phys_t *) dn->dn_bonus;
72 if (off + n > zp->zp_size)
73 n = zp->zp_size - off;
75 rc = dnode_read(spa, dn, off, buf, n);
83 main(int argc, char** argv)
97 "zfstest", "COPYRIGHT",
98 "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
104 for (i = 2; i < argc; i++) {
105 fd[i] = open(argv[i], O_RDONLY);
108 if (vdev_probe(vdev_read, &fd[i], NULL) != 0)
113 spa = STAILQ_FIRST(&zfs_pools);
115 fprintf(stderr, "no pools\n");
119 if (zfs_mount_pool(spa)) {
120 fprintf(stderr, "can't mount pool\n");
124 if (zfs_lookup(spa, argv[1], &dn)) {
125 fprintf(stderr, "can't lookup\n");
129 if (zfs_dnode_stat(spa, &dn, &sb)) {
130 fprintf(stderr, "can't stat\n");
137 n = sb.st_size - off;
138 n = n > sizeof(buf) ? sizeof(buf) : n;
139 n = zfs_read(spa, &dn, buf, n, off);
141 fprintf(stderr, "zfs_read failed\n");
146 } while (off < sb.st_size);