this repo has no description
1
fork

Configure Feed

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

Added readlink() and initial fcntl() code

+208
+2
src/kernel/emulation/linux/CMakeLists.txt
··· 40 40 unistd/lseek.c 41 41 unistd/ftruncate.c 42 42 unistd/access.c 43 + unistd/readlink.c 43 44 signal/duct_signals.c 44 45 signal/kill.c 45 46 signal/sigaltstack.c ··· 48 49 misc/sysctl.c 49 50 misc/getrlimit.c 50 51 fcntl/open.c 52 + fcntl/fcntl.c 51 53 network/socket.c 52 54 network/connect.c 53 55 stat/fstat.c
+97
src/kernel/emulation/linux/fcntl/fcntl.c
··· 1 + #include "fcntl.h" 2 + #include "open.h" 3 + #include "../base.h" 4 + #include "../errno.h" 5 + #include <asm/unistd.h> 6 + #include "../../../../../platform-include/sys/errno.h" 7 + 8 + #ifndef O_NOFOLLOW 9 + # define O_NOFOLLOW 0x0100 10 + #endif 11 + #ifndef O_CLOEXEC 12 + # define O_CLOEXEC 0x1000000 13 + #endif 14 + #ifndef O_DIRECTORY 15 + # define O_DIRECTORY 0x100000 16 + #endif 17 + #ifndef MAXPATHLEN 18 + # define MAXPATHLEN 1024 19 + #endif 20 + 21 + int oflags_bsd_to_linux(int flags); 22 + int oflags_linux_to_bsd(int flags); 23 + 24 + extern int sprintf(char *str, const char *format, ...); 25 + long sys_readlink(const char* path, char* buf, unsigned long bsize); 26 + 27 + long sys_fcntl(int fd, int cmd, long arg) 28 + { 29 + int ret, linux_cmd; 30 + 31 + switch (cmd) 32 + { 33 + case F_DUPFD: 34 + linux_cmd = LINUX_F_DUPFD; 35 + break; 36 + case F_GETFD: 37 + linux_cmd = LINUX_F_GETFD; 38 + break; 39 + case F_SETFD: 40 + linux_cmd = LINUX_F_SETFD; 41 + 42 + if (arg & ~O_CLOEXEC) 43 + return -EINVAL; 44 + if (arg & O_CLOEXEC) 45 + arg = LINUX_O_CLOEXEC; 46 + else 47 + arg = 0; 48 + break; 49 + case F_GETFL: 50 + linux_cmd = LINUX_F_GETFL; 51 + break; 52 + case F_SETFL: 53 + linux_cmd = LINUX_F_SETFL; 54 + arg = oflags_bsd_to_linux(arg); 55 + break; 56 + case F_GETOWN: 57 + linux_cmd = LINUX_F_GETOWN; 58 + break; 59 + case F_SETOWN: 60 + linux_cmd = LINUX_F_SETOWN; 61 + break; 62 + case F_GETPATH: 63 + { 64 + char buf[100]; 65 + 66 + sprintf(buf, "/proc/self/fd/%d", fd); 67 + return sys_readlink(buf, (char*) arg, MAXPATHLEN); 68 + } 69 + // TODO: implement remaining commands 70 + default: 71 + return -EINVAL; 72 + } 73 + 74 + ret = LINUX_SYSCALL(__NR_fcntl, fd, linux_cmd, arg); 75 + if (ret < 0) 76 + { 77 + ret = errno_linux_to_bsd(ret); 78 + return ret; 79 + } 80 + 81 + switch (cmd) 82 + { 83 + case F_GETFD: 84 + if (ret & LINUX_O_CLOEXEC) 85 + ret = O_CLOEXEC; 86 + else 87 + ret = 0; 88 + break; 89 + 90 + case F_GETFL: 91 + ret = oflags_linux_to_bsd(ret); 92 + break; 93 + } 94 + 95 + return ret; 96 + } 97 +
+49
src/kernel/emulation/linux/fcntl/fcntl.h
··· 1 + #ifndef LINUX_FCNTL_H 2 + #define LINUX_FCNTL_H 3 + 4 + long sys_fcntl(int fd, int cmd, long arg); 5 + 6 + enum { 7 + LINUX_F_DUPFD = 0, 8 + LINUX_F_GETFD, 9 + LINUX_F_SETFD, 10 + LINUX_F_GETFL, 11 + LINUX_F_SETFL, 12 + LINUX_F_GETLK, 13 + LINUX_F_SETLK, 14 + LINUX_F_SETLKW, 15 + LINUX_F_SETOWN, 16 + LINUX_F_GETOWN, 17 + LINUX_F_SETSIG, 18 + LINUX_F_GETSIG, 19 + LINUX_F_GETLK64, 20 + LINUX_F_SETLK64, 21 + LINUX_F_SETLKW64, 22 + LINUX_F_SETOWN_EX, 23 + LINUX_F_GETOWN_EX, 24 + LINUX_F_GETOWNER_UIDS, 25 + }; 26 + 27 + enum { 28 + F_DUPFD = 0, 29 + F_GETFD, 30 + F_SETFD, 31 + F_GETFL, 32 + F_SETFL, 33 + F_GETOWN, 34 + F_SETOWN, 35 + F_GETLK, 36 + F_SETLK, 37 + F_SETLKW, 38 + F_SETLKWTIMEOUT, 39 + F_FLUSH_DATA = 40, 40 + F_CHKCLEAN, 41 + F_PREALLOCATE, 42 + F_SETSIZE, 43 + F_RDADVISE, 44 + F_RDAHEAD, 45 + F_GETPATH = 50, 46 + }; 47 + 48 + #endif 49 +
+31
src/kernel/emulation/linux/fcntl/open.c
··· 80 80 return linux_flags; 81 81 } 82 82 83 + int oflags_linux_to_bsd(int flags) 84 + { 85 + int bsd_flags = 0; 86 + 87 + if (flags & LINUX_O_RDONLY) /* always false */ 88 + bsd_flags |= O_RDONLY; 89 + if (flags & LINUX_O_WRONLY) 90 + bsd_flags |= O_WRONLY; 91 + if (flags & LINUX_O_RDWR) 92 + bsd_flags |= O_RDWR; 93 + if (flags & LINUX_O_NONBLOCK) 94 + bsd_flags |= O_NONBLOCK; 95 + if (flags & LINUX_O_APPEND) 96 + bsd_flags |= O_APPEND; 97 + if (flags & LINUX_O_CREAT) 98 + bsd_flags |= O_CREAT; 99 + if (flags & LINUX_O_TRUNC) 100 + bsd_flags |= O_TRUNC; 101 + if (flags & LINUX_O_EXCL) 102 + bsd_flags |= O_EXCL; 103 + if (flags & LINUX_O_CLOEXEC) 104 + bsd_flags |= O_CLOEXEC; 105 + if (flags & LINUX_O_NOFOLLOW) 106 + bsd_flags |= O_NOFOLLOW; 107 + if (flags & LINUX_O_DIRECTORY) 108 + bsd_flags |= O_DIRECTORY; 109 + if (flags & LINUX_O_CLOEXEC) 110 + bsd_flags |= O_CLOEXEC; 111 + 112 + return bsd_flags; 113 + }
+4
src/kernel/emulation/linux/syscalls.c
··· 27 27 #include "unistd/access.h" 28 28 #include "unistd/lseek.h" 29 29 #include "unistd/ftruncate.h" 30 + #include "unistd/readlink.h" 30 31 #include "signal/kill.h" 31 32 #include "signal/sigaltstack.h" 32 33 #include "misc/ioctl.h" ··· 34 35 #include "misc/thread_selfid.h" 35 36 #include "misc/sysctl.h" 36 37 #include "fcntl/open.h" 38 + #include "fcntl/fcntl.h" 37 39 #include "network/socket.h" 38 40 #include "network/connect.h" 39 41 #include "dirent/getdirentries.h" ··· 59 61 [41] = sys_dup, 60 62 [53] = sys_sigaltstack, 61 63 [54] = sys_ioctl, 64 + [58] = sys_readlink, 62 65 [73] = sys_munmap, 63 66 [74] = sys_mprotect, 64 67 [78] = sys_mincore, 65 68 [90] = sys_dup2, 69 + [92] = sys_fcntl, 66 70 [95] = sys_fsync, 67 71 [97] = sys_socket, 68 72 [98] = sys_connect,
+18
src/kernel/emulation/linux/unistd/readlink.c
··· 1 + #include "readlink.h" 2 + #include "../base.h" 3 + #include "../errno.h" 4 + #include <asm/unistd.h> 5 + 6 + long sys_readlink(const char* path, char* buf, int count) 7 + { 8 + int ret; 9 + 10 + // TODO: case translation 11 + 12 + ret = LINUX_SYSCALL(__NR_readlink, path, buf, count); 13 + if (ret < 0) 14 + ret = errno_linux_to_bsd(ret); 15 + 16 + return ret; 17 + } 18 +
+7
src/kernel/emulation/linux/unistd/readlink.h
··· 1 + #ifndef LINUX_READLINK_H 2 + #define LINUX_READLINK_H 3 + 4 + long sys_readlink(const char* path, char* buf, int count); 5 + 6 + #endif 7 +