1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2019 Joyent, Inc.
14 */
15
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <fcntl.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <errno.h>
22#include <string.h>
23#include <unistd.h>
24#include <sys/dkio.h>
25
26int
27main(int argc, char **argv)
28{
29	int umap, fd;
30
31	if (argc < 2) {
32		fprintf(stderr, "missing disk name\n");
33		exit(2);
34	}
35
36	if ((fd = open(argv[1], O_RDONLY)) == -1) {
37		fprintf(stderr, "couldn't open %s: %s\n", argv[1],
38		    strerror(errno));
39		exit(2);
40	}
41
42	if (ioctl(fd, DKIOC_CANFREE, &umap) < 0) {
43		fprintf(stderr, "ioctl failed %s: %s\n", argv[1],
44		    strerror(errno));
45		exit(2);
46	}
47
48	(void) close(fd);
49
50	return (umap ? 0 : 1);
51}
52