summaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-02-04 20:04:53 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-02-04 20:04:53 +0000
commitfe2dfdf30c1e3de5e3030595563fa3efff8022a5 (patch)
tree2a8ca2ea6c253d2a038355c4ccf7c02fac62fe2a /sys/compat
parent79e41f94496d2e21b3d34bb44023f669627758c9 (diff)
fcntl64 support; okay deraadt@
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linux/linux_dummy.c3
-rw-r--r--sys/compat/linux/linux_fcntl.h14
-rw-r--r--sys/compat/linux/linux_file64.c110
-rw-r--r--sys/compat/linux/linux_syscall.h6
-rw-r--r--sys/compat/linux/linux_syscallargs.h10
-rw-r--r--sys/compat/linux/linux_syscalls.c4
-rw-r--r--sys/compat/linux/linux_sysent.c6
-rw-r--r--sys/compat/linux/linux_types.h3
-rw-r--r--sys/compat/linux/syscalls.master4
9 files changed, 143 insertions, 17 deletions
diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c
index 3570e13a84d..1e3d7c6247a 100644
--- a/sys/compat/linux/linux_dummy.c
+++ b/sys/compat/linux/linux_dummy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_dummy.c,v 1.5 2001/07/04 19:59:47 jasoni Exp $ */
+/* $OpenBSD: linux_dummy.c,v 1.6 2002/02/04 20:04:52 provos Exp $ */
/*-
* Copyright (c) 1994-1995 Søren Schmidt
@@ -120,4 +120,3 @@ DUMMY(pivot_root); /* #217 */
DUMMY(mincore); /* #218 */
DUMMY(madvise); /* #219 */
DUMMY(getdents64); /* #220 */
-DUMMY(fcntl64); /* #221 */
diff --git a/sys/compat/linux/linux_fcntl.h b/sys/compat/linux/linux_fcntl.h
index 326e4c804df..9f3ea5ebd47 100644
--- a/sys/compat/linux/linux_fcntl.h
+++ b/sys/compat/linux/linux_fcntl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_fcntl.h,v 1.2 1996/04/17 05:23:48 mickey Exp $ */
+/* $OpenBSD: linux_fcntl.h,v 1.3 2002/02/04 20:04:52 provos Exp $ */
/* $NetBSD: linux_fcntl.h,v 1.1 1995/02/28 23:25:40 fvdl Exp $ */
/*
@@ -68,6 +68,10 @@
#define LINUX_F_SETOWN 8
#define LINUX_F_GETOWN 9
+#define LINUX_F_GETLK64 12
+#define LINUX_F_SETLK64 13
+#define LINUX_F_SETLKW64 14
+
#define LINUX_F_RDLCK 0
#define LINUX_F_WRLCK 1
#define LINUX_F_UNLCK 2
@@ -88,4 +92,12 @@ struct linux_flock {
linux_pid_t l_pid;
};
+struct linux_flock64 {
+ short l_type;
+ short l_whence;
+ linux_loff_t l_start;
+ linux_loff_t l_len;
+ linux_pid_t l_pid;
+};
+
#endif /* _LINUX_FCNTL_H */
diff --git a/sys/compat/linux/linux_file64.c b/sys/compat/linux/linux_file64.c
index a6172d0339b..3edb616ad7b 100644
--- a/sys/compat/linux/linux_file64.c
+++ b/sys/compat/linux/linux_file64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_file64.c,v 1.1 2000/12/22 07:34:02 jasoni Exp $ */
+/* $OpenBSD: linux_file64.c,v 1.2 2002/02/04 20:04:52 provos Exp $ */
/* $NetBSD: linux_file64.c,v 1.2 2000/12/12 22:24:56 jdolecek Exp $ */
/*-
@@ -67,6 +67,8 @@
#include <machine/linux_machdep.h>
+void bsd_to_linux_flock64 __P((struct flock *, struct linux_flock64 *));
+void linux_to_bsd_flock64 __P((struct linux_flock64 *, struct flock *));
static void bsd_to_linux_stat __P((struct stat *, struct linux_stat64 *));
static int linux_do_stat64 __P((struct proc *, void *, register_t *, int));
@@ -222,3 +224,109 @@ linux_sys_truncate64(p, v, retval)
return sys_truncate(p, uap, retval);
}
+
+/*
+ * The next two functions take care of converting the flock
+ * structure back and forth between Linux and OpenBSD format.
+ * The only difference in the structures is the order of
+ * the fields, and the 'whence' value.
+ */
+void
+bsd_to_linux_flock64(struct flock *bfp, struct linux_flock64 *lfp)
+{
+ lfp->l_start = bfp->l_start;
+ lfp->l_len = bfp->l_len;
+ lfp->l_pid = bfp->l_pid;
+ lfp->l_whence = bfp->l_whence;
+ switch (bfp->l_type) {
+ case F_RDLCK:
+ lfp->l_type = LINUX_F_RDLCK;
+ break;
+ case F_UNLCK:
+ lfp->l_type = LINUX_F_UNLCK;
+ break;
+ case F_WRLCK:
+ lfp->l_type = LINUX_F_WRLCK;
+ break;
+ }
+}
+
+void
+linux_to_bsd_flock64(struct linux_flock64 *lfp, struct flock *bfp)
+{
+ bfp->l_start = lfp->l_start;
+ bfp->l_len = lfp->l_len;
+ bfp->l_pid = lfp->l_pid;
+ bfp->l_whence = lfp->l_whence;
+ switch (lfp->l_type) {
+ case LINUX_F_RDLCK:
+ bfp->l_type = F_RDLCK;
+ break;
+ case LINUX_F_UNLCK:
+ bfp->l_type = F_UNLCK;
+ break;
+ case LINUX_F_WRLCK:
+ bfp->l_type = F_WRLCK;
+ break;
+ }
+}
+
+int
+linux_sys_fcntl64(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct linux_sys_fcntl64_args /* {
+ syscallarg(u_int) fd;
+ syscallarg(u_int) cmd;
+ syscallarg(void *) arg;
+ } */ *uap = v;
+ int fd, cmd, error;
+ caddr_t arg, sg;
+ struct linux_flock64 lfl;
+ struct flock *bfp, bfl;
+ struct sys_fcntl_args fca;
+
+ fd = SCARG(uap, fd);
+ cmd = SCARG(uap, cmd);
+ arg = (caddr_t) SCARG(uap, arg);
+
+ switch (cmd) {
+ case LINUX_F_GETLK64:
+ sg = stackgap_init(p->p_emul);
+ if ((error = copyin(arg, &lfl, sizeof lfl)))
+ return error;
+ linux_to_bsd_flock64(&lfl, &bfl);
+ bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
+ SCARG(&fca, fd) = fd;
+ SCARG(&fca, cmd) = F_GETLK;
+ SCARG(&fca, arg) = bfp;
+ if ((error = copyout(&bfl, bfp, sizeof bfl)))
+ return error;
+ if ((error = sys_fcntl(p, &fca, retval)))
+ return error;
+ if ((error = copyin(bfp, &bfl, sizeof bfl)))
+ return error;
+ bsd_to_linux_flock64(&bfl, &lfl);
+ error = copyout(&lfl, arg, sizeof lfl);
+ return (error);
+ case LINUX_F_SETLK64:
+ case LINUX_F_SETLKW64:
+ cmd = (cmd == LINUX_F_SETLK64 ? F_SETLK : F_SETLKW);
+ if ((error = copyin(arg, &lfl, sizeof lfl)))
+ return error;
+ linux_to_bsd_flock64(&lfl, &bfl);
+ sg = stackgap_init(p->p_emul);
+ bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
+ if ((error = copyout(&bfl, bfp, sizeof bfl)))
+ return error;
+ SCARG(&fca, fd) = fd;
+ SCARG(&fca, cmd) = cmd;
+ SCARG(&fca, arg) = bfp;
+ return (sys_fcntl(p, &fca, retval));
+ default:
+ return (linux_sys_fcntl(p, v, retval));
+ }
+ /* NOTREACHED */
+}
diff --git a/sys/compat/linux/linux_syscall.h b/sys/compat/linux/linux_syscall.h
index 6fd1d22981d..6bcbb8ef76b 100644
--- a/sys/compat/linux/linux_syscall.h
+++ b/sys/compat/linux/linux_syscall.h
@@ -1,10 +1,10 @@
-/* $OpenBSD: linux_syscall.h,v 1.31 2001/08/26 04:14:26 deraadt Exp $ */
+/* $OpenBSD: linux_syscall.h,v 1.32 2002/02/04 20:04:52 provos Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from OpenBSD: syscalls.master,v 1.31 2001/07/04 19:59:47 jasoni Exp
+ * created from OpenBSD: syscalls.master,v 1.30 2001/07/03 21:56:26 jasoni Exp
*/
/* syscall: "syscall" ret: "int" args: */
@@ -679,7 +679,7 @@
/* syscall: "getdents64" ret: "int" args: */
#define LINUX_SYS_getdents64 220
-/* syscall: "fcntl64" ret: "int" args: */
+/* syscall: "fcntl64" ret: "int" args: "u_int" "u_int" "void *" */
#define LINUX_SYS_fcntl64 221
#define LINUX_SYS_MAXSYSCALL 222
diff --git a/sys/compat/linux/linux_syscallargs.h b/sys/compat/linux/linux_syscallargs.h
index 229598ac4d8..f0c49a76ffa 100644
--- a/sys/compat/linux/linux_syscallargs.h
+++ b/sys/compat/linux/linux_syscallargs.h
@@ -1,10 +1,10 @@
-/* $OpenBSD: linux_syscallargs.h,v 1.32 2001/08/26 04:14:26 deraadt Exp $ */
+/* $OpenBSD: linux_syscallargs.h,v 1.33 2002/02/04 20:04:52 provos Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from OpenBSD: syscalls.master,v 1.31 2001/07/04 19:59:47 jasoni Exp
+ * created from OpenBSD: syscalls.master,v 1.30 2001/07/03 21:56:26 jasoni Exp
*/
#ifdef syscallarg
@@ -517,6 +517,12 @@ struct linux_sys_setfsuid_args {
syscallarg(uid_t) uid;
};
+struct linux_sys_fcntl64_args {
+ syscallarg(u_int) fd;
+ syscallarg(u_int) cmd;
+ syscallarg(void *) arg;
+};
+
/*
* System call prototypes.
*/
diff --git a/sys/compat/linux/linux_syscalls.c b/sys/compat/linux/linux_syscalls.c
index 556f582c4fb..de0fce33513 100644
--- a/sys/compat/linux/linux_syscalls.c
+++ b/sys/compat/linux/linux_syscalls.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: linux_syscalls.c,v 1.31 2001/08/26 04:14:26 deraadt Exp $ */
+/* $OpenBSD: linux_syscalls.c,v 1.32 2002/02/04 20:04:52 provos Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from OpenBSD: syscalls.master,v 1.31 2001/07/04 19:59:47 jasoni Exp
+ * created from OpenBSD: syscalls.master,v 1.30 2001/07/03 21:56:26 jasoni Exp
*/
char *linux_syscallnames[] = {
diff --git a/sys/compat/linux/linux_sysent.c b/sys/compat/linux/linux_sysent.c
index 10d0178b42d..7d785cd33aa 100644
--- a/sys/compat/linux/linux_sysent.c
+++ b/sys/compat/linux/linux_sysent.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: linux_sysent.c,v 1.32 2001/08/26 04:14:26 deraadt Exp $ */
+/* $OpenBSD: linux_sysent.c,v 1.33 2002/02/04 20:04:52 provos Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
- * created from OpenBSD: syscalls.master,v 1.31 2001/07/04 19:59:47 jasoni Exp
+ * created from OpenBSD: syscalls.master,v 1.30 2001/07/03 21:56:26 jasoni Exp
*/
#include <sys/param.h>
@@ -477,7 +477,7 @@ struct sysent linux_sysent[] = {
linux_sys_madvise }, /* 219 = madvise */
{ 0, 0,
linux_sys_getdents64 }, /* 220 = getdents64 */
- { 0, 0,
+ { 3, s(struct linux_sys_fcntl64_args),
linux_sys_fcntl64 }, /* 221 = fcntl64 */
};
diff --git a/sys/compat/linux/linux_types.h b/sys/compat/linux/linux_types.h
index 7cc183a66b8..368ddc04fa7 100644
--- a/sys/compat/linux/linux_types.h
+++ b/sys/compat/linux/linux_types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_types.h,v 1.4 2000/12/22 07:34:02 jasoni Exp $ */
+/* $OpenBSD: linux_types.h,v 1.5 2002/02/04 20:04:52 provos Exp $ */
/* $NetBSD: linux_types.h,v 1.5 1996/05/20 01:59:28 fvdl Exp $ */
/*
@@ -48,6 +48,7 @@ typedef unsigned short linux_nlink_t;
typedef long linux_time_t;
typedef long linux_clock_t;
typedef long linux_off_t;
+typedef u_int64_t linux_loff_t;
typedef int linux_pid_t;
struct linux_statfs {
diff --git a/sys/compat/linux/syscalls.master b/sys/compat/linux/syscalls.master
index 81e507329e0..4f82d6dffd6 100644
--- a/sys/compat/linux/syscalls.master
+++ b/sys/compat/linux/syscalls.master
@@ -1,4 +1,4 @@
- $OpenBSD: syscalls.master,v 1.31 2001/07/04 19:59:47 jasoni Exp $
+ $OpenBSD: syscalls.master,v 1.32 2002/02/04 20:04:52 provos Exp $
; $NetBSD: syscalls.master,v 1.15 1995/12/18 14:35:10 fvdl Exp $
; @(#)syscalls.master 8.1 (Berkeley) 7/19/93
@@ -346,4 +346,4 @@
218 NOARGS { int linux_sys_mincore(void); }
219 NOARGS { int linux_sys_madvise(void); }
220 NOARGS { int linux_sys_getdents64(void); }
-221 NOARGS { int linux_sys_fcntl64(void); }
+221 STD { int linux_sys_fcntl64(u_int fd, u_int cmd, void *arg); }