X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=lib%2Flibzfs%2Flibzfs_import.c;h=9e79bd9348999d13c4b977a8243ee3abe95bc6fc;hb=a36bf1149d7408fde273851350c0ef6c0e4fe989;hp=791aaad535e525288c89d00e1683a8fab0e181ab;hpb=295304bed6fa6744b8d011e36b9c2180311cedb2;p=zfs.git diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c index 791aaad..9e79bd9 100644 --- a/lib/libzfs/libzfs_import.c +++ b/lib/libzfs/libzfs_import.c @@ -862,7 +862,7 @@ zpool_read_label(int fd, nvlist_t **config) *config = NULL; - if (fstat64(fd, &statbuf) == -1) + if (fstat64_blk(fd, &statbuf) == -1) return (0); size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t); @@ -900,6 +900,36 @@ zpool_read_label(int fd, nvlist_t **config) return (0); } +/* + * Given a file descriptor, clear (zero) the label information. This function + * is used in the appliance stack as part of the ZFS sysevent module and + * to implement the "zpool labelclear" command. + */ +int +zpool_clear_label(int fd) +{ + struct stat64 statbuf; + int l; + vdev_label_t *label; + uint64_t size; + + if (fstat64_blk(fd, &statbuf) == -1) + return (0); + size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t); + + if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL) + return (-1); + + for (l = 0; l < VDEV_LABELS; l++) { + if (pwrite64(fd, label, sizeof (vdev_label_t), + label_offset(size, l)) != sizeof (vdev_label_t)) + return (-1); + } + + free(label); + return (0); +} + #ifdef HAVE_LIBBLKID /* * Use libblkid to quickly search for zfs devices