1 #include <errno.h> 2 #include <fcntl.h> 3 #include <stdio.h> 4 #include <unistd.h> 5 6 #include <drivers/device_manager.h> 7 8 #include "config_driver.h" 9 #include "dm_wrapper.h" 10 11 static int fd; 12 13 status_t init_dm_wrapper(void) 14 { 15 static const char device[] = "/dev/" DM_DEVICE_NAME; 16 17 fd = open(device, 0); 18 if (fd < 0) 19 return errno; 20 return B_OK; 21 } 22 23 status_t uninit_dm_wrapper(void) 24 { 25 close(fd); 26 return B_OK; 27 } 28 29 status_t get_child(void) 30 { 31 struct dm_ioctl_data params; 32 33 params.magic = DM_GET_CHILD; 34 params.attr = NULL; 35 36 return ioctl(fd, params.magic, ¶ms, sizeof(params)); 37 } 38 39 status_t get_next_child(void) 40 { 41 struct dm_ioctl_data params; 42 43 params.magic = DM_GET_NEXT_CHILD; 44 params.attr = NULL; 45 46 return ioctl(fd, params.magic, ¶ms, sizeof(params)); 47 } 48 49 status_t get_parent(void) 50 { 51 struct dm_ioctl_data params; 52 53 params.magic = DM_GET_PARENT; 54 params.attr = NULL; 55 56 return ioctl(fd, params.magic, ¶ms, sizeof(params)); 57 } 58 59 status_t dm_get_next_attr(void) 60 { 61 struct dm_ioctl_data params; 62 63 params.magic = DM_GET_NEXT_ATTRIBUTE; 64 params.attr = NULL; 65 66 return ioctl(fd, params.magic, ¶ms, sizeof(params)); 67 } 68 69 status_t dm_retrieve_attr(struct dev_attr *attr) 70 { 71 struct dm_ioctl_data params; 72 73 params.magic = DM_RETRIEVE_ATTRIBUTE; 74 params.attr = attr; 75 76 return ioctl(fd, params.magic, ¶ms, sizeof(params)); 77 } 78 79