DF-2940 / direct_remove.c
#include <sys/types.h> #include <sys/ioctl.h> #include <libprop/proplib.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #define DM_IOCTL 0xfd #define DM_IOCTL_CMD 0 #define NETBSD_DM_IOCTL _IOWR(DM_IOCTL, DM_IOCTL_CMD, struct plistref) int main(int argc, char **argv) { prop_dictionary_t dict, ret = NULL; prop_array_t ver; const char *cmd = (argc > 1) ? argv[1] : "remove"; const char *name = (argc > 2) ? argv[2] : "vol"; int fd, error; dict = prop_dictionary_create(); ver = prop_array_create(); prop_array_add_uint32(ver, 4); prop_array_add_uint32(ver, 0); prop_array_add_uint32(ver, 0); prop_dictionary_set(dict, "version", ver); prop_object_release(ver); prop_dictionary_set_cstring(dict, "command", cmd); prop_dictionary_set_cstring(dict, "name", name); prop_dictionary_set_uint32(dict, "flags", 4); /* DM_EXISTS_FLAG */ prop_dictionary_set_cstring(dict, "uuid", ""); fd = open("/dev/mapper/control", O_RDWR); if (fd < 0) { perror("open"); return 1; } error = prop_dictionary_sendrecv_ioctl(dict, fd, NETBSD_DM_IOCTL, &ret); printf("sendrecv(%s %s): error=%d errno=%d\n", cmd, name, error, errno); if (ret) { char *xml = prop_dictionary_externalize(ret); if (xml) { printf("reply: %.400s\n", xml); free(xml); } prop_object_release(ret); } return (error ? 1 : 0); } |