this repo has no description
1
fork

Configure Feed

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

Implement F_{GET,SET,SETW}LK in fcntl

+75 -23
+59 -23
src/kernel/emulation/linux/fcntl/fcntl.c
··· 24 24 extern int sprintf(char *str, const char *format, ...); 25 25 long sys_readlink(const char* path, char* buf, unsigned long bsize); 26 26 27 + static short int flock_type_linux_to_bsd(short int linux) { 28 + switch (linux) { 29 + case LINUX_F_RDLCK: return F_RDLCK; 30 + case LINUX_F_WRLCK: return F_WRLCK; 31 + case LINUX_F_UNLCK: return F_UNLCK; 32 + default: return -1; 33 + }; 34 + }; 35 + 36 + static short int flock_type_bsd_to_linux(short int bsd) { 37 + switch (bsd) { 38 + case F_RDLCK: return LINUX_F_RDLCK; 39 + case F_WRLCK: return LINUX_F_WRLCK; 40 + case F_UNLCK: return LINUX_F_UNLCK; 41 + default: return -1; 42 + }; 43 + }; 44 + 45 + static int cmd_bsd_to_linux(int bsd) { 46 + switch (bsd) { 47 + case F_DUPFD: return LINUX_F_DUPFD; 48 + case F_GETFD: return LINUX_F_GETFD; 49 + case F_SETFD: return LINUX_F_SETFD; 50 + case F_GETFL: return LINUX_F_GETFL; 51 + case F_SETFL: return LINUX_F_SETFL; 52 + case F_GETOWN: return LINUX_F_GETOWN; 53 + case F_SETOWN: return LINUX_F_SETOWN; 54 + case F_SETLK: return LINUX_F_SETLK; 55 + case F_SETLKW: return LINUX_F_SETLKW; 56 + case F_GETLK: return LINUX_F_GETLK; 57 + default: return -1; 58 + }; 59 + }; 60 + 27 61 long sys_fcntl(int fd, int cmd, long arg) 28 62 { 29 63 CANCELATION_POINT(); ··· 32 66 33 67 long sys_fcntl_nocancel(int fd, int cmd, long arg) 34 68 { 35 - int ret, linux_cmd; 69 + int ret, linux_cmd = cmd_bsd_to_linux(cmd); 70 + long original_arg = arg; 36 71 37 72 switch (cmd) 38 73 { 39 74 case F_CHECK_LV: 40 75 return 0; 41 - case F_DUPFD: 42 - linux_cmd = LINUX_F_DUPFD; 43 - break; 44 - case F_GETFD: 45 - linux_cmd = LINUX_F_GETFD; 46 - break; 47 76 case F_SETFD: 48 - linux_cmd = LINUX_F_SETFD; 49 - 50 77 if (arg & ~FD_CLOEXEC) 51 78 return -EINVAL; 52 79 break; 53 - case F_GETFL: 54 - linux_cmd = LINUX_F_GETFL; 55 - break; 56 80 case F_SETFL: 57 - linux_cmd = LINUX_F_SETFL; 58 81 arg = oflags_bsd_to_linux(arg); 59 82 break; 60 - case F_GETOWN: 61 - linux_cmd = LINUX_F_GETOWN; 62 - break; 63 - case F_SETOWN: 64 - linux_cmd = LINUX_F_SETOWN; 65 - break; 66 83 case F_GETPATH: 67 84 { 68 85 ret = fdpath(fd, arg, MAXPATHLEN); ··· 73 90 } 74 91 case F_SETLK: 75 92 case F_SETLKW: 76 - case F_GETLK: 77 - // TODO 78 - return 0; 93 + case F_GETLK: { 94 + struct bsd_flock* bsd_struct = arg; 95 + struct linux_flock* linux_struct = __builtin_alloca(sizeof(struct linux_flock)); 96 + linux_struct->l_type = flock_type_bsd_to_linux(bsd_struct->l_type); 97 + linux_struct->l_whence = bsd_struct->l_whence; 98 + linux_struct->l_start = bsd_struct->l_start; 99 + linux_struct->l_len = bsd_struct->l_len; 100 + linux_struct->l_pid = bsd_struct->l_pid; 101 + arg = linux_struct; 102 + } break; 79 103 case F_FULLFSYNC: { 80 104 ret = LINUX_SYSCALL1(__NR_fsync, fd); 81 105 if (ret < 0) ··· 84 108 }; 85 109 // TODO: implement remaining commands 86 110 default: 87 - return -EINVAL; 111 + if (linux_cmd == -1) 112 + return -EINVAL; 88 113 } 89 114 90 115 #ifdef __NR_fcntl64 ··· 103 128 case F_GETFL: 104 129 ret = oflags_linux_to_bsd(ret); 105 130 break; 131 + case F_SETLK: 132 + case F_SETLKW: 133 + case F_GETLK: { 134 + struct bsd_flock* bsd_struct = original_arg; 135 + struct linux_flock* linux_struct = arg; 136 + bsd_struct->l_type = flock_type_linux_to_bsd(linux_struct->l_type); 137 + bsd_struct->l_whence = linux_struct->l_whence; 138 + bsd_struct->l_start = linux_struct->l_start; 139 + bsd_struct->l_len = linux_struct->l_len; 140 + bsd_struct->l_pid = linux_struct->l_pid; 141 + } break; 106 142 } 107 143 108 144 return ret;
+16
src/kernel/emulation/linux/fcntl/fcntl.h
··· 64 64 # define FD_CLOEXEC 1 65 65 #endif 66 66 67 + struct bsd_flock { 68 + long long l_start; 69 + long long l_len; 70 + int l_pid; 71 + short l_type; 72 + short l_whence; 73 + }; 74 + 75 + struct linux_flock { 76 + short int l_type; 77 + short int l_whence; 78 + long int l_start; 79 + long int l_len; 80 + int l_pid; 81 + }; 82 + 67 83 #endif 68 84