Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (40 sloc) 0.821 kb
0124521 @joshwilsdon Fix gcc -Wall warning and add removable_disk and disklist to manifest.
joshwilsdon authored
1 #include <stdio.h>
4e042ff @JohnSonnenschein add disklist utility
JohnSonnenschein authored
2 #include <unistd.h>
3 #include <fcntl.h>
4 #include <sys/stat.h>
5 #include <sys/dkio.h>
6 #include <sys/vtoc.h>
7
8 void
9 usage(char* argv0) {
10 printf("Usage: %s [char dev]\n", argv0);
11 }
12
13 int
14 main(int argc, char* argv[]) {
15 char* devpath = argv[1];
fa1dcf1 @wesolows smartos-live#2 Fixed identation, spaces should be tabs
wesolows authored
16 int devnode;
4e042ff @JohnSonnenschein add disklist utility
JohnSonnenschein authored
17 struct stat buf;
18 int ret;
19 int removable;
20
21 if(argc != 2) {
22 usage(argv[0]);
23 return -1;
24 }
25
fa1dcf1 @wesolows smartos-live#2 Fixed identation, spaces should be tabs
wesolows authored
26 if ((devnode = open(devpath, O_RDONLY)) < 0 ) {
4e042ff @JohnSonnenschein add disklist utility
JohnSonnenschein authored
27 printf("Could not open %s\n", devpath);
28 usage(argv[0]);
29 return -1;
fa1dcf1 @wesolows smartos-live#2 Fixed identation, spaces should be tabs
wesolows authored
30 }
4e042ff @JohnSonnenschein add disklist utility
JohnSonnenschein authored
31
32 if (fstat(devnode, &buf) == -1 || !S_ISCHR(buf.st_mode)) {
33 printf("%s: not a character device\n", devpath);
34 usage(argv[0]);
35 close(devnode);
36 return -1;
37 }
38
39 ret = ioctl(devnode, DKIOCREMOVABLE, &removable);
40
41 if ((ret >= 0) && (removable != 0)) {
42 close(devnode);
43 return 0;
44 }
45
46 close(devnode);
47 return 1;
48 }
Something went wrong with that request. Please try again.