this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Translate remaining filio ioctls (#115)

+167 -67
+1
src/kernel/emulation/linux/CMakeLists.txt
··· 144 144 time/getitimer.c 145 145 ioctl/ioctl.c 146 146 ioctl/termios.c 147 + ioctl/filio.c 147 148 ext/uname.c 148 149 ext/epoll_create.c 149 150 ext/epoll_create1.c
+157
src/kernel/emulation/linux/ioctl/filio.c
··· 1 + #include "ioctl.h" 2 + #include "filio.h" 3 + #include "../fcntl/fcntl.h" 4 + #include "../fcntl/open.h" 5 + #include "../../../../../platform-include/sys/errno.h" 6 + #include "../errno.h" 7 + #include "../unistd/readlink.h" 8 + #include <stddef.h> 9 + #include <stdbool.h> 10 + 11 + #define D_TAPE 1 12 + #define D_DISK 2 13 + #define D_TTY 3 14 + 15 + 16 + extern int sprintf(char* buf, const char* fmt, ...); 17 + extern int strncmp(const char *, const char *, __SIZE_TYPE__); 18 + static bool get_fd_path(int fd, char* buf, size_t len) 19 + { 20 + char proc[32]; 21 + int ret; 22 + 23 + sprintf(proc, "/proc/self/fd/%d", fd); 24 + ret = sys_readlink(proc, buf, len-1); 25 + 26 + if (ret <= 0) 27 + return false; 28 + 29 + buf[ret] = 0; 30 + return true; 31 + } 32 + 33 + 34 + int handle_filio(int fd, int cmd, void* arg, int* retval) 35 + { 36 + switch (cmd) 37 + { 38 + case BSD_FIODTYPE: 39 + { 40 + char orig_path[256]; 41 + int* iarg = (int*) arg; 42 + 43 + if (iarg == NULL) 44 + { 45 + *retval = -EFAULT; 46 + return IOCTL_HANDLED; 47 + } 48 + 49 + if (!get_fd_path(fd, orig_path, sizeof(orig_path))) 50 + { 51 + *retval = -EBADF; 52 + return IOCTL_HANDLED; 53 + } 54 + 55 + *retval = 0; 56 + if (strncmp(orig_path, "/dev/pts", 8) == 0 57 + || strncmp(orig_path, "/dev/tty", 8) == 0) 58 + { 59 + *iarg = D_TTY; 60 + } 61 + else if (strncmp(orig_path, "/dev/st", 7) == 0 62 + || strncmp(orig_path, "/dev/nst", 8) == 0) 63 + { 64 + *iarg = D_TAPE; 65 + } 66 + else 67 + { 68 + *iarg = D_DISK; 69 + } 70 + return IOCTL_HANDLED; 71 + } 72 + case BSD_FIONBIO: 73 + { 74 + *retval = __real_ioctl(fd, 0x5421, arg); 75 + if (*retval < 0) 76 + *retval = errno_linux_to_bsd(*retval); 77 + 78 + return IOCTL_HANDLED; 79 + } 80 + case BSD_FIOASYNC: 81 + { 82 + *retval = __real_ioctl(fd, 0x5452, arg); 83 + if (*retval < 0) 84 + *retval = errno_linux_to_bsd(*retval); 85 + 86 + return IOCTL_HANDLED; 87 + } 88 + case BSD_FIOCLEX: 89 + { 90 + *retval = __real_ioctl(fd, 0x5451, arg); 91 + if (*retval < 0) 92 + *retval = errno_linux_to_bsd(*retval); 93 + 94 + return IOCTL_HANDLED; 95 + } 96 + case BSD_FIONCLEX: 97 + { 98 + *retval = __real_ioctl(fd, 0x5450, arg); 99 + if (*retval < 0) 100 + *retval = errno_linux_to_bsd(*retval); 101 + 102 + return IOCTL_HANDLED; 103 + } 104 + case BSD_FIONREAD: 105 + { 106 + *retval = __real_ioctl(fd, 0x541B, arg); 107 + if (*retval < 0) 108 + *retval = errno_linux_to_bsd(*retval); 109 + 110 + return IOCTL_HANDLED; 111 + } 112 + case BSD_FIOGETOWN: 113 + { 114 + *retval = __real_ioctl(fd, 0x8903, arg); 115 + if (*retval < 0) 116 + *retval = errno_linux_to_bsd(*retval); 117 + 118 + return IOCTL_HANDLED; 119 + } 120 + case BSD_FIOSETOWN: 121 + { 122 + *retval = __real_ioctl(fd, 0x8901, arg); 123 + if (*retval < 0) 124 + *retval = errno_linux_to_bsd(*retval); 125 + 126 + return IOCTL_HANDLED; 127 + } 128 + /* 129 + case BSD_FIOASYNC: 130 + { 131 + int flags; 132 + int* iarg = (int*) arg; 133 + 134 + if (!iarg) 135 + *retval = -EINVAL; 136 + 137 + *retval = sys_fcntl(fd, F_GETFL, 0); 138 + if (*retval < 0) 139 + return IOCTL_HANDLED; 140 + 141 + flags = *retval; 142 + 143 + if (*iarg) 144 + flags |= BSD_O_ASYNC; 145 + else 146 + flags &= ~BSD_O_ASYNC; 147 + 148 + *retval = sys_fcntl(fd, F_SETFL, flags); 149 + 150 + return IOCTL_HANDLED; 151 + } 152 + */ 153 + default: 154 + return IOCTL_PASS; 155 + } 156 + } 157 +
+7
src/kernel/emulation/linux/ioctl/filio.h
··· 1 + #ifndef FILIO_H 2 + #define FILIO_H 3 + 4 + int handle_filio(int fd, int cmd, void* arg, int* retval); 5 + 6 + #endif /* FILIO_H */ 7 +
+1 -66
src/kernel/emulation/linux/ioctl/ioctl.c
··· 1 1 #include "ioctl.h" 2 2 #include "../base.h" 3 - #include "../unistd/readlink.h" 4 3 #include "../../../../../platform-include/sys/errno.h" 5 4 #include <stddef.h> 6 5 #include <stdbool.h> 7 6 #include "termios.h" 8 - 9 - #define D_TAPE 1 10 - #define D_DISK 2 11 - #define D_TTY 3 7 + #include "filio.h" 12 8 13 9 #define IOCTL_STEP(x) { int state, retval; state = (x); \ 14 10 if (state == IOCTL_HANDLED) return retval; } 15 - 16 - static int handle_filio(int fd, int cmd, void* arg, int* retval); 17 11 18 12 // Emulated ioctl implementation 19 13 VISIBLE ··· 26 20 return __real_ioctl(fd, cmd, arg); 27 21 } 28 22 29 - extern int sprintf(char* buf, const char* fmt, ...); 30 - extern int strncmp(const char *, const char *, __SIZE_TYPE__); 31 - static bool get_fd_path(int fd, char* buf, size_t len) 32 - { 33 - char proc[32]; 34 - int ret; 35 - 36 - sprintf(proc, "/proc/self/fd/%d", fd); 37 - ret = sys_readlink(proc, buf, len-1); 38 - 39 - if (ret <= 0) 40 - return false; 41 - 42 - buf[ret] = 0; 43 - return true; 44 - } 45 - 46 - static int handle_filio(int fd, int cmd, void* arg, int* retval) 47 - { 48 - switch (cmd) 49 - { 50 - case BSD_FIODTYPE: 51 - { 52 - char orig_path[256]; 53 - int* iarg = (int*) arg; 54 - 55 - if (iarg == NULL) 56 - { 57 - *retval = -EFAULT; 58 - return IOCTL_HANDLED; 59 - } 60 - 61 - if (!get_fd_path(fd, orig_path, sizeof(orig_path))) 62 - { 63 - *retval = -EBADF; 64 - return IOCTL_HANDLED; 65 - } 66 - 67 - *retval = 0; 68 - if (strncmp(orig_path, "/dev/pts", 8) == 0 69 - || strncmp(orig_path, "/dev/tty", 8) == 0) 70 - { 71 - *iarg = D_TTY; 72 - } 73 - else if (strncmp(orig_path, "/dev/st", 7) == 0 74 - || strncmp(orig_path, "/dev/nst", 8) == 0) 75 - { 76 - *iarg = D_TAPE; 77 - } 78 - else 79 - { 80 - *iarg = D_DISK; 81 - } 82 - return IOCTL_HANDLED; 83 - } 84 - default: 85 - return IOCTL_PASS; 86 - } 87 - } 88 23 89 24
+1 -1
src/kernel/emulation/linux/ioctl/ioctl.h
··· 23 23 #define BSD_IOC_DIRMASK (uint32_t)0xe0000000 24 24 25 25 #define BSD_IOC(inout,group,num,len) \ 26 - (inout | ((len & BSD_IOCPARM_MASK) << 16) | ((group) << 8) | (num)) 26 + (int)(inout | ((len & BSD_IOCPARM_MASK) << 16) | ((group) << 8) | (num)) 27 27 #define BSD_IO(g,n) BSD_IOC(BSD_IOC_VOID, (g), (n), 0) 28 28 #define BSD_IOR(g,n,t) BSD_IOC(BSD_IOC_OUT, (g), (n), sizeof(t)) 29 29 #define BSD_IOW(g,n,t) BSD_IOC(BSD_IOC_IN, (g), (n), sizeof(t))