| 4585 | } |
| 4586 | |
| 4587 | static int |
| 4588 | dump_label(const char *dev) |
| 4589 | { |
| 4590 | char path[MAXPATHLEN]; |
| 4591 | zdb_label_t labels[VDEV_LABELS]; |
| 4592 | uint64_t psize, ashift, l2cache; |
| 4593 | struct stat64 statbuf; |
| 4594 | boolean_t config_found = B_FALSE; |
| 4595 | boolean_t error = B_FALSE; |
| 4596 | boolean_t read_l2arc_header = B_FALSE; |
| 4597 | avl_tree_t config_tree; |
| 4598 | avl_tree_t uberblock_tree; |
| 4599 | void *node, *cookie; |
| 4600 | int fd; |
| 4601 | |
| 4602 | bzero(labels, sizeof (labels)); |
| 4603 | |
| 4604 | /* |
| 4605 | * Check if we were given absolute path and use it as is. |
| 4606 | * Otherwise if the provided vdev name doesn't point to a file, |
| 4607 | * try prepending expected disk paths and partition numbers. |
| 4608 | */ |
| 4609 | (void) strlcpy(path, dev, sizeof (path)); |
| 4610 | if (dev[0] != '/' && stat64(path, &statbuf) != 0) { |
| 4611 | int error; |
| 4612 | |
| 4613 | error = zfs_resolve_shortname(dev, path, MAXPATHLEN); |
| 4614 | if (error == 0 && zfs_dev_is_whole_disk(path)) { |
| 4615 | if (zfs_append_partition(path, MAXPATHLEN) == -1) |
| 4616 | error = ENOENT; |
| 4617 | } |
| 4618 | |
| 4619 | if (error || (stat64(path, &statbuf) != 0)) { |
| 4620 | (void) printf("failed to find device %s, try " |
| 4621 | "specifying absolute path instead\n", dev); |
| 4622 | return (1); |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | if ((fd = open64(path, O_RDONLY)) < 0) { |
| 4627 | (void) printf("cannot open '%s': %s\n", path, strerror(errno)); |
| 4628 | exit(1); |
| 4629 | } |
| 4630 | |
| 4631 | if (fstat64_blk(fd, &statbuf) != 0) { |
| 4632 | (void) printf("failed to stat '%s': %s\n", path, |
| 4633 | strerror(errno)); |
| 4634 | (void) close(fd); |
| 4635 | exit(1); |
| 4636 | } |
| 4637 | |
| 4638 | if (S_ISBLK(statbuf.st_mode) && zfs_dev_flush(fd) != 0) |
| 4639 | (void) printf("failed to invalidate cache '%s' : %s\n", path, |
| 4640 | strerror(errno)); |
| 4641 | |
| 4642 | avl_create(&config_tree, cksum_record_compare, |
| 4643 | sizeof (cksum_record_t), offsetof(cksum_record_t, link)); |
| 4644 | avl_create(&uberblock_tree, cksum_record_compare, |
no test coverage detected