FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
/*
 * By "whole disk" we mean an entire physical disk (something we can
 * label, toggle the write cache on, etc.) as opposed to the full
 * capacity of a pseudo-device such as lofi or did.  We act as if we
 * are labeling the disk, which should be a pretty good test of whether
 * it's a viable device or not.  Returns B_TRUE if it is and B_FALSE if
 * it isn't.
 */
By "whole disk" we mean an entire physical disk (something we can
label, toggle the write cache on, etc.) as opposed to the full
capacity of a pseudo-device such as lofi or did.  We act as if we
are labeling the disk, which should be a pretty good test of whether
it's a viable device or not.  Returns B_TRUE if it is and B_FALSE if
it isn't.
By " whole disk " we mean an entire physical disk ( something we can label toggle the write cache on etc . ) as opposed to the full capacity of a pseudo - device such as lofi or did . We act as if we are labeling the disk which should be a pretty good test of whether it ' s a viable device or not . Returns B_TRUE if it is and B_FALSE if it isn ' t .
static boolean_t
is_whole_disk(const char *arg)
{
#ifdef illumos
	struct dk_gpt *label;
	int	fd;
	char	path[MAXPATHLEN];
	(void) snprintf(path, sizeof (path), "%s%s%s",
	    ZFS_RDISK_ROOT, strrchr(arg, '/'), BACKUP_SLICE);
	if ((fd = open(path, O_RDWR | O_NDELAY)) < 0)
		return (B_FALSE);
	if (efi_alloc_and_init(fd, EFI_NUMPAR, &label) != 0) {
		(void) close(fd);
		return (B_FALSE);
	}
	efi_free(label);
	(void) close(fd);
	return (B_TRUE);
#else
	int fd;
	fd = g_open(arg, 0);
	if (fd >= 0) {
		g_close(fd);
		return (B_TRUE);
	}
	return (B_FALSE);
#endif
}
static boolean_t is_whole_disk ( const char * arg ) { #ifdef illumos struct dk_gpt * label ; int fd ; char path [ MAXPATHLEN ] ; ( void ) snprintf ( path , sizeof ( path ) , " " , ZFS_RDISK_ROOT , strrchr ( arg , ' ' ) , BACKUP_SLICE ) ; if ( ( fd = open ( path , O_RDWR | O_NDELAY ) ) < 0 ) return ( B_FALSE ) ; if ( efi_alloc_and_init ( fd , EFI_NUMPAR , & label ) != 0 ) { ( void ) close ( fd ) ; return ( B_FALSE ) ; } efi_free ( label ) ; ( void ) close ( fd ) ; return ( B_TRUE ) ; #else int fd ; fd = g_open ( arg , 0 ) ; if ( fd >= 0 ) { g_close ( fd ) ; return ( B_TRUE ) ; } return ( B_FALSE ) ; #endif }
By "whole disk" we mean an entire physical disk (something we can
 label, toggle the write cache on, etc.)
By " whole disk " we mean an entire physical disk ( something we can label toggle the write cache on etc . )