Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 198DtE-0006Kd-00 for qemu-devel@nongnu.org; Wed, 23 Apr 2003 02:37:56 -0400 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 198Dsb-0005vK-00 for qemu-devel@nongnu.org; Wed, 23 Apr 2003 02:37:20 -0400 Received: from dp.samba.org ([66.70.73.150] helo=lists.samba.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 198Dsb-0005vD-00 for qemu-devel@nongnu.org; Wed, 23 Apr 2003 02:37:17 -0400 From: Rusty Russell Date: Wed, 23 Apr 2003 16:35:54 +1000 Sender: rusty@rustcorp.com.au Message-Id: <20030423063717.47A3B2C01A@lists.samba.org> Subject: [Qemu-devel] [PATCH] flock support List-Id: List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , To: Fabrice Bellard Cc: qemu-devel@nongnu.org I thought about using thunk stuff, but if glibc plays games with struct flock, that'll break badly, so I opencoded it. Cheers! Rusty. diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal qemu-0.1.6-debug/syscall-i386.h qemu-0.1.6-fcntl/syscall-i386.h --- qemu-0.1.6-debug/syscall-i386.h 2003-04-11 16:13:59.000000000 +1000 +++ qemu-0.1.6-fcntl/syscall-i386.h 2003-04-11 16:40:47.000000000 +1000 @@ -935,6 +935,22 @@ union target_semun { unsigned int __pad; /* really void* */ }; +struct target_flock { + short l_type; + short l_whence; + target_ulong l_start; + target_ulong l_len; + int l_pid; +}; + +struct target_flock64 { + short l_type; + short l_whence; + unsigned long long l_start; + unsigned long long l_len; + int l_pid; +}; + /* soundcard defines (XXX: move them to generic file syscall_defs.h) */ #define TARGET_SNDCTL_COPR_HALT 0xc0144307 diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal qemu-0.1.6-debug/syscall.c qemu-0.1.6-fcntl/syscall.c --- qemu-0.1.6-debug/syscall.c 2003-04-11 16:14:51.000000000 +1000 +++ qemu-0.1.6-fcntl/syscall.c 2003-04-11 17:47:27.000000000 +1000 @@ -1414,16 +1414,42 @@ long do_syscall(void *cpu_env, int num, ret = do_ioctl(arg1, arg2, arg3); break; case TARGET_NR_fcntl: + { + struct flock fl; + struct target_flock *target_fl = (void *)arg3; + switch(arg2) { case F_GETLK: + ret = get_errno(fcntl(arg1, arg2, &fl)); + if (ret == 0) { + target_fl->l_type = tswap16(fl.l_type); + target_fl->l_whence = tswap16(fl.l_whence); + target_fl->l_start = tswapl(fl.l_start); + target_fl->l_len = tswapl(fl.l_len); + target_fl->l_pid = tswapl(fl.l_pid); + } + break; + case F_SETLK: case F_SETLKW: + fl.l_type = tswap16(target_fl->l_type); + fl.l_whence = tswap16(target_fl->l_whence); + fl.l_start = tswapl(target_fl->l_start); + fl.l_len = tswapl(target_fl->l_len); + fl.l_pid = tswapl(target_fl->l_pid); + ret = get_errno(fcntl(arg1, arg2, &fl)); + break; + + case F_GETLK64: + case F_SETLK64: + case F_SETLKW64: goto unimplemented; default: ret = get_errno(fcntl(arg1, arg2, arg3)); break; } break; + } case TARGET_NR_mpx: goto unimplemented; case TARGET_NR_setpgid: @@ -2356,16 +2382,37 @@ long do_syscall(void *cpu_env, int num, goto unimplemented; #if TARGET_LONG_BITS == 32 case TARGET_NR_fcntl64: + { + struct flock64 fl; + struct target_flock64 *target_fl = (void *)arg3; + switch(arg2) { case F_GETLK64: + ret = get_errno(fcntl(arg1, arg2, &fl)); + if (ret == 0) { + target_fl->l_type = tswap16(fl.l_type); + target_fl->l_whence = tswap16(fl.l_whence); + target_fl->l_start = tswap64(fl.l_start); + target_fl->l_len = tswap64(fl.l_len); + target_fl->l_pid = tswapl(fl.l_pid); + } + break; + case F_SETLK64: case F_SETLKW64: - goto unimplemented; + fl.l_type = tswap16(target_fl->l_type); + fl.l_whence = tswap16(target_fl->l_whence); + fl.l_start = tswap64(target_fl->l_start); + fl.l_len = tswap64(target_fl->l_len); + fl.l_pid = tswapl(target_fl->l_pid); + ret = get_errno(fcntl(arg1, arg2, &fl)); + break; default: ret = get_errno(fcntl(arg1, arg2, arg3)); break; } - break; + break; + } #endif case TARGET_NR_security: goto unimplemented; -- Anyone who quotes me in their sig is an idiot. -- Rusty Russell.