1 /* 2 * Copyright 2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hugo Santos <hugosantos@gmail.com> 7 */ 8 9 #include <sys/sockio.h> 10 #include <termios.h> 11 #include <Drivers.h> 12 #include <tty.h> 13 #include <scsi.h> 14 15 #include "strace.h" 16 #include "Syscall.h" 17 #include "TypeHandler.h" 18 19 struct ioctl_info { 20 int index; 21 const char *name; 22 TypeHandler *handler; 23 }; 24 25 #define IOCTL_INFO_ENTRY(name) \ 26 { name, #name, NULL } 27 28 #define IOCTL_INFO_ENTRY_TYPE(name, type) \ 29 { name, #name, TypeHandlerFactory<type>::Create() } 30 31 static const ioctl_info kIOCtls[] = { 32 // <Drivers.h> 33 IOCTL_INFO_ENTRY_TYPE(B_GET_DEVICE_SIZE, size_t *), 34 IOCTL_INFO_ENTRY_TYPE(B_SET_DEVICE_SIZE, size_t *), 35 IOCTL_INFO_ENTRY(B_SET_NONBLOCKING_IO), 36 IOCTL_INFO_ENTRY(B_SET_BLOCKING_IO), 37 IOCTL_INFO_ENTRY(B_GET_READ_STATUS), 38 IOCTL_INFO_ENTRY(B_GET_WRITE_STATUS), 39 IOCTL_INFO_ENTRY(B_GET_GEOMETRY), 40 IOCTL_INFO_ENTRY(B_GET_DRIVER_FOR_DEVICE), 41 IOCTL_INFO_ENTRY(B_GET_PARTITION_INFO), 42 IOCTL_INFO_ENTRY(B_SET_PARTITION), 43 IOCTL_INFO_ENTRY(B_FORMAT_DEVICE), 44 IOCTL_INFO_ENTRY(B_EJECT_DEVICE), 45 IOCTL_INFO_ENTRY(B_GET_ICON), 46 IOCTL_INFO_ENTRY(B_GET_BIOS_GEOMETRY), 47 IOCTL_INFO_ENTRY(B_GET_MEDIA_STATUS), 48 IOCTL_INFO_ENTRY(B_LOAD_MEDIA), 49 IOCTL_INFO_ENTRY(B_GET_BIOS_DRIVE_ID), 50 IOCTL_INFO_ENTRY(B_SET_UNINTERRUPTABLE_IO), 51 IOCTL_INFO_ENTRY(B_SET_INTERRUPTABLE_IO), 52 IOCTL_INFO_ENTRY(B_FLUSH_DRIVE_CACHE), 53 IOCTL_INFO_ENTRY(B_GET_PATH_FOR_DEVICE), 54 IOCTL_INFO_ENTRY(B_GET_NEXT_OPEN_DEVICE), 55 IOCTL_INFO_ENTRY(B_ADD_FIXED_DRIVER), 56 IOCTL_INFO_ENTRY(B_REMOVE_FIXED_DRIVER), 57 58 /* 59 IOCTL_INFO_ENTRY(B_AUDIO_DRIVER_BASE), // conflicts 60 IOCTL_INFO_ENTRY(B_MIDI_DRIVER_BASE), 61 IOCTL_INFO_ENTRY(B_JOYSTICK_DRIVER_BASE), 62 IOCTL_INFO_ENTRY(B_GRAPHIC_DRIVER_BASE), 63 IOCTL_INFO_ENTRY(B_DEVICE_OP_CODES_END), 64 */ 65 66 // <sys/sockio.h> 67 IOCTL_INFO_ENTRY(SIOCADDRT), 68 IOCTL_INFO_ENTRY(SIOCDELRT), 69 IOCTL_INFO_ENTRY_TYPE(SIOCSIFADDR, struct ifreq *), 70 IOCTL_INFO_ENTRY_TYPE(SIOCGIFADDR, struct ifreq *), 71 IOCTL_INFO_ENTRY_TYPE(SIOCSIFDSTADDR, struct ifreq *), 72 IOCTL_INFO_ENTRY_TYPE(SIOCGIFDSTADDR, struct ifreq *), 73 IOCTL_INFO_ENTRY_TYPE(SIOCSIFFLAGS, struct ifreq *), 74 IOCTL_INFO_ENTRY_TYPE(SIOCGIFFLAGS, struct ifreq *), 75 IOCTL_INFO_ENTRY_TYPE(SIOCGIFBRDADDR, struct ifreq *), 76 IOCTL_INFO_ENTRY_TYPE(SIOCSIFBRDADDR, struct ifreq *), 77 IOCTL_INFO_ENTRY(SIOCGIFCOUNT), 78 IOCTL_INFO_ENTRY_TYPE(SIOCGIFCONF, struct ifconf *), 79 IOCTL_INFO_ENTRY_TYPE(SIOCGIFINDEX, struct ifreq *), 80 IOCTL_INFO_ENTRY(SIOCGIFNAME), 81 IOCTL_INFO_ENTRY(SIOCGIFNETMASK), 82 IOCTL_INFO_ENTRY(SIOCSIFNETMASK), 83 IOCTL_INFO_ENTRY_TYPE(SIOCGIFMETRIC, struct ifreq *), 84 IOCTL_INFO_ENTRY_TYPE(SIOCSIFMETRIC, struct ifreq *), 85 IOCTL_INFO_ENTRY_TYPE(SIOCDIFADDR, struct ifreq *), 86 IOCTL_INFO_ENTRY_TYPE(SIOCAIFADDR, struct ifreq *), 87 IOCTL_INFO_ENTRY(SIOCADDMULTI), 88 IOCTL_INFO_ENTRY(SIOCDELMULTI), 89 IOCTL_INFO_ENTRY_TYPE(SIOCGIFMTU, struct ifreq *), 90 IOCTL_INFO_ENTRY_TYPE(SIOCSIFMTU, struct ifreq *), 91 IOCTL_INFO_ENTRY(SIOCSIFMEDIA), 92 IOCTL_INFO_ENTRY(SIOCGIFMEDIA), 93 IOCTL_INFO_ENTRY(SIOCGRTSIZE), 94 IOCTL_INFO_ENTRY(SIOCGRTTABLE), 95 IOCTL_INFO_ENTRY_TYPE(SIOCGIFSTATS, struct ifreq *), 96 IOCTL_INFO_ENTRY_TYPE(SIOCGIFPARAM, struct ifreq *), 97 IOCTL_INFO_ENTRY(SIOCGIFTYPE), 98 IOCTL_INFO_ENTRY(SIOCSPACKETCAP), 99 IOCTL_INFO_ENTRY(SIOCCPACKETCAP), 100 IOCTL_INFO_ENTRY(SIOCSHIWAT), 101 IOCTL_INFO_ENTRY(SIOCGHIWAT), 102 IOCTL_INFO_ENTRY(SIOCSLOWAT), 103 IOCTL_INFO_ENTRY(SIOCGLOWAT), 104 IOCTL_INFO_ENTRY(SIOCATMARK), 105 IOCTL_INFO_ENTRY(SIOCSPGRP), 106 107 // termios ioctls 108 IOCTL_INFO_ENTRY(TCGETA), 109 IOCTL_INFO_ENTRY(TCSETA), 110 IOCTL_INFO_ENTRY(TCSETAF), 111 IOCTL_INFO_ENTRY(TCSETAW), 112 IOCTL_INFO_ENTRY(TCWAITEVENT), 113 IOCTL_INFO_ENTRY(TCSBRK), 114 IOCTL_INFO_ENTRY(TCFLSH), 115 IOCTL_INFO_ENTRY(TCXONC), 116 IOCTL_INFO_ENTRY(TCQUERYCONNECTED), 117 IOCTL_INFO_ENTRY(TCGETBITS), 118 IOCTL_INFO_ENTRY(TCSETDTR), 119 IOCTL_INFO_ENTRY(TCSETRTS), 120 IOCTL_INFO_ENTRY(TIOCGWINSZ), 121 IOCTL_INFO_ENTRY(TIOCSWINSZ), 122 IOCTL_INFO_ENTRY(TCVTIME), 123 IOCTL_INFO_ENTRY(TIOCGPGRP), 124 IOCTL_INFO_ENTRY(TIOCSPGRP), 125 // private termios 126 IOCTL_INFO_ENTRY(B_IOCTL_GET_TTY_INDEX), 127 IOCTL_INFO_ENTRY(B_IOCTL_GRANT_TTY), 128 129 // scsi ioctls 130 IOCTL_INFO_ENTRY(B_SCSI_SCAN_FOR_DEVICES), 131 IOCTL_INFO_ENTRY(B_SCSI_ENABLE_PROFILING), 132 IOCTL_INFO_ENTRY(B_SCSI_INQUIRY), 133 IOCTL_INFO_ENTRY(B_SCSI_EJECT), 134 IOCTL_INFO_ENTRY(B_SCSI_PREVENT_ALLOW), 135 IOCTL_INFO_ENTRY(B_RAW_DEVICE_COMMAND), 136 IOCTL_INFO_ENTRY(B_SCSI_GET_TOC), 137 IOCTL_INFO_ENTRY(B_SCSI_PLAY_TRACK), 138 IOCTL_INFO_ENTRY(B_SCSI_PLAY_POSITION), 139 IOCTL_INFO_ENTRY(B_SCSI_STOP_AUDIO), 140 IOCTL_INFO_ENTRY(B_SCSI_PAUSE_AUDIO), 141 IOCTL_INFO_ENTRY(B_SCSI_RESUME_AUDIO), 142 IOCTL_INFO_ENTRY(B_SCSI_GET_POSITION), 143 IOCTL_INFO_ENTRY(B_SCSI_SET_VOLUME), 144 IOCTL_INFO_ENTRY(B_SCSI_GET_VOLUME), 145 IOCTL_INFO_ENTRY(B_SCSI_READ_CD), 146 IOCTL_INFO_ENTRY(B_SCSI_SCAN), 147 IOCTL_INFO_ENTRY(B_SCSI_DATA_MODE), 148 149 { -1, NULL, NULL } 150 }; 151 152 static EnumTypeHandler::EnumMap kIoctlNames; 153 static TypeHandlerSelector::SelectMap kIoctlTypeHandlers; 154 155 void 156 patch_ioctl() 157 { 158 for (int i = 0; kIOCtls[i].name != NULL; i++) { 159 kIoctlNames[kIOCtls[i].index] = kIOCtls[i].name; 160 if (kIOCtls[i].handler != NULL) 161 kIoctlTypeHandlers[kIOCtls[i].index] = kIOCtls[i].handler; 162 } 163 164 Syscall *ioctl = get_syscall("_kern_ioctl"); 165 166 ioctl->GetParameter("cmd")->SetHandler( 167 new EnumTypeHandler(kIoctlNames)); 168 ioctl->GetParameter("data")->SetHandler( 169 new TypeHandlerSelector(kIoctlTypeHandlers, 170 1, TypeHandlerFactory<void *>::Create())); 171 } 172 173