Module Name:    src
Committed By:   snj
Date:           Wed Mar 18 17:20:09 UTC 2015

Modified Files:
        src/sys/compat/linux32/arch/amd64 [netbsd-5]: syscalls.master
        src/sys/compat/linux32/common [netbsd-5]: linux32_misc.c linux32_stat.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #1149):
        sys/compat/linux32/arch/amd64/syscalls.master: revisions 1.52, 1.53 via 
patch
        sys/compat/linux32/common/linux32_misc.c: revision 1.17 via patch
        sys/compat/linux32/common/linux32_stat.c: revision 1.14-1.16 via patch
Fix inverted lst_ino/__lst_ino assignment in linux32_from_stat().
--
Cleanup (no functional changes).
Kill some unneeded variables and return stattement.
Rename linux32_from_stat() to better bsd_to_linux32_stat64().
Fix some types.
Add stat/lstat/fstat syscalls.
--
Add fstatfs syscall.


To generate a diff of this commit:
cvs rdiff -u -r1.38.4.1 -r1.38.4.2 \
    src/sys/compat/linux32/arch/amd64/syscalls.master
cvs rdiff -u -r1.12 -r1.12.6.1 src/sys/compat/linux32/common/linux32_misc.c
cvs rdiff -u -r1.11 -r1.11.14.1 src/sys/compat/linux32/common/linux32_stat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/linux32/arch/amd64/syscalls.master
diff -u src/sys/compat/linux32/arch/amd64/syscalls.master:1.38.4.1 src/sys/compat/linux32/arch/amd64/syscalls.master:1.38.4.2
--- src/sys/compat/linux32/arch/amd64/syscalls.master:1.38.4.1	Thu Nov 20 03:03:05 2008
+++ src/sys/compat/linux32/arch/amd64/syscalls.master	Wed Mar 18 17:20:09 2015
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.38.4.1 2008/11/20 03:03:05 snj Exp $
+	$NetBSD: syscalls.master,v 1.38.4.2 2015/03/18 17:20:09 snj Exp $
 
 ; NetBSD i386 COMPAT_LINUX32 system call name/number "master" file.
 ; (See syscalls.conf to see what it is processed into.)
@@ -199,7 +199,7 @@
 98	UNIMPL	profil
 99	STD	{ int linux32_sys_statfs(netbsd32_charp path, \
 		    linux32_statfsp sp); }
-100	UNIMPL	fstatfs
+100	STD	{ int linux32_sys_fstatfs(int fd, linux32_statfsp sp); }
 101	UNIMPL	ioperm
 102	STD	{ int linux32_sys_socketcall(int what, netbsd32_voidp args); }
 103	UNIMPL	syslog
@@ -207,9 +207,11 @@
 		    netbsd32_itimervalp_t itv, netbsd32_itimervalp_t oitv); }
 105	NOARGS	{ int netbsd32_getitimer(int which, \
 		    netbsd32_itimervalp_t itv); }
-106	UNIMPL	stat
-107	UNIMPL	lstat
-108	UNIMPL	fstat
+106	STD	{ int linux32_sys_stat(netbsd32_charp path, \
+		    linux32_statp sp); }
+107	STD	{ int linux32_sys_lstat(netbsd32_charp path, \
+		    linux32_statp sp); }
+108	STD	{ int linux32_sys_fstat(int fd, linux32_statp sp); }
 109	STD	{ int linux32_sys_olduname(linux32_oldutsnamep_t up); }
 110	UNIMPL	iopl
 111	UNIMPL	vhangup

Index: src/sys/compat/linux32/common/linux32_misc.c
diff -u src/sys/compat/linux32/common/linux32_misc.c:1.12 src/sys/compat/linux32/common/linux32_misc.c:1.12.6.1
--- src/sys/compat/linux32/common/linux32_misc.c:1.12	Wed Jun 18 22:58:21 2008
+++ src/sys/compat/linux32/common/linux32_misc.c	Wed Mar 18 17:20:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_misc.c,v 1.12 2008/06/18 22:58:21 njoly Exp $	*/
+/*	$NetBSD: linux32_misc.c,v 1.12.6.1 2015/03/18 17:20:09 snj Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.12 2008/06/18 22:58:21 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.12.6.1 2015/03/18 17:20:09 snj Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ptrace.h"
@@ -90,6 +90,28 @@ linux32_sys_statfs(struct lwp *l, const 
 	return error;
 }
 
+int
+linux32_sys_fstatfs(struct lwp *l, const struct linux32_sys_fstatfs_args *uap, register_t *retval)
+{
+	/* {
+		syscallarg(int) fd;
+		syscallarg(linux32_statfsp) sp;
+	} */
+	struct statvfs *sb;
+	struct linux_statfs ltmp;
+	int error;
+
+	sb = STATVFSBUF_GET();
+	error = do_sys_fstatvfs(l, SCARG(uap, fd), ST_WAIT, sb);
+	if (error == 0) {
+		bsd_to_linux_statfs(sb, &ltmp);
+		error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
+	}
+	STATVFSBUF_PUT(sb);
+
+	return error;
+}
+
 extern const int linux_ptrace_request_map[];
 
 int

Index: src/sys/compat/linux32/common/linux32_stat.c
diff -u src/sys/compat/linux32/common/linux32_stat.c:1.11 src/sys/compat/linux32/common/linux32_stat.c:1.11.14.1
--- src/sys/compat/linux32/common/linux32_stat.c:1.11	Fri Mar 21 21:54:58 2008
+++ src/sys/compat/linux32/common/linux32_stat.c	Wed Mar 18 17:20:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_stat.c,v 1.11 2008/03/21 21:54:58 ad Exp $ */
+/*	$NetBSD: linux32_stat.c,v 1.11.14.1 2015/03/18 17:20:09 snj Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_stat.c,v 1.11 2008/03/21 21:54:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_stat.c,v 1.11.14.1 2015/03/18 17:20:09 snj Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -72,15 +72,44 @@ __KERNEL_RCSID(0, "$NetBSD: linux32_stat
 #include <compat/linux32/common/linux32_socketcall.h>
 #include <compat/linux32/linux32_syscallargs.h>
 
-static inline void linux32_from_stat(struct stat *, struct linux32_stat64 *);
+static inline void bsd_to_linux32_stat(struct stat *, struct linux32_stat *);
+static inline void bsd_to_linux32_stat64(struct stat *, struct linux32_stat64 *);
 
 #define linux_fakedev(x,y) (x)
+
 static inline void
-linux32_from_stat(struct stat *st, struct linux32_stat64 *st32)
+bsd_to_linux32_stat(struct stat *st, struct linux32_stat *st32)
 {
-	bzero(st32, sizeof(*st32));
+	memset(st32, 0, sizeof(*st32));
 	st32->lst_dev = linux_fakedev(st->st_dev, 0);
-	st32->__lst_ino = st->st_ino;
+	st32->lst_ino = st->st_ino;
+	st32->lst_mode = st->st_mode;
+	if (st->st_nlink >= (1 << 15))
+		st32->lst_nlink = (1 << 15) - 1;
+	else
+		st32->lst_nlink = st->st_nlink;
+	st32->lst_uid = st->st_uid;
+	st32->lst_gid = st->st_gid;
+	st32->lst_rdev = linux_fakedev(st->st_rdev, 0);
+	st32->lst_size = st->st_size;
+	st32->lst_blksize = st->st_blksize;
+	st32->lst_blocks = st->st_blocks;
+	st32->lst_atime = st->st_atime;
+	st32->lst_mtime = st->st_mtime;
+	st32->lst_ctime = st->st_ctime;
+#ifdef LINUX32_STAT_HAS_NSEC
+	st32->lst_atime_nsec = st->st_atimensec;
+	st32->lst_mtime_nsec = st->st_mtimensec;
+	st32->lst_ctime_nsec = st->st_ctimensec;
+#endif
+}
+
+static inline void
+bsd_to_linux32_stat64(struct stat *st, struct linux32_stat64 *st32)
+{
+	memset(st32, 0, sizeof(*st32));
+	st32->lst_dev = linux_fakedev(st->st_dev, 0);
+	st32->lst_ino = st->st_ino;
 	st32->lst_mode = st->st_mode;
 	if (st->st_nlink >= (1 << 15))
 		st32->lst_nlink = (1 << 15) - 1;
@@ -101,14 +130,31 @@ linux32_from_stat(struct stat *st, struc
 	st32->lst_ctime_nsec = st->st_ctimensec;
 #endif
 #ifdef LINUX32_STAT64_HAS_BROKEN_ST_INO
-	st32->lst_ino = st->st_ino;
+	st32->__lst_ino = st->st_ino;
 #endif
+}
 
-	return;
+int
+linux32_sys_stat(struct lwp *l, const struct linux32_sys_stat_args *uap, register_t *retval)
+{
+	/* {
+	        syscallarg(netbsd32_charp) path;
+	        syscallarg(linux32_statp) sp;
+	} */
+	int error;
+	struct stat st;
+	struct linux32_stat st32;
+	
+	error = do_sys_stat(SCARG_P32(uap, path), FOLLOW, &st);
+	if (error != 0)
+		return error;
+
+	bsd_to_linux32_stat(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
 }
 
 int
-linux32_sys_stat64(struct lwp *l, const struct linux32_sys_stat64_args *uap, register_t *retval)
+linux32_sys_lstat(struct lwp *l, const struct linux32_sys_lstat_args *uap, register_t *retval)
 {
 	/* {
 	        syscallarg(netbsd32_charp) path;
@@ -116,23 +162,37 @@ linux32_sys_stat64(struct lwp *l, const 
 	} */
 	int error;
 	struct stat st;
-	struct linux32_stat64 st32;
-	struct linux32_stat64 *st32p;
-	const char *path = SCARG_P32(uap, path);
+	struct linux32_stat st32;
 	
-	error = do_sys_stat(path, FOLLOW, &st);
+	error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &st);
 	if (error != 0)
 		return error;
 
-	linux32_from_stat(&st, &st32);
+	bsd_to_linux32_stat(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
+}
 
-	st32p = SCARG_P32(uap, sp);
+int
+linux32_sys_fstat(struct lwp *l, const struct linux32_sys_fstat_args *uap, register_t *retval)
+{
+	/* {
+	        syscallarg(int) fd;
+	        syscallarg(linux32_statp) sp;
+	} */
+	int error;
+	struct stat st;
+	struct linux32_stat st32;
+
+	error = do_sys_fstat(SCARG(uap, fd), &st);
+	if (error != 0)
+		return error;
 
-	return copyout(&st32, st32p, sizeof(*st32p));
+	bsd_to_linux32_stat(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
 }
 
 int
-linux32_sys_lstat64(struct lwp *l, const struct linux32_sys_lstat64_args *uap, register_t *retval)
+linux32_sys_stat64(struct lwp *l, const struct linux32_sys_stat64_args *uap, register_t *retval)
 {
 	/* {
 	        syscallarg(netbsd32_charp) path;
@@ -141,18 +201,32 @@ linux32_sys_lstat64(struct lwp *l, const
 	int error;
 	struct stat st;
 	struct linux32_stat64 st32;
-	struct linux32_stat64 *st32p;
-	const char *path = SCARG_P32(uap, path);
 	
-	error = do_sys_stat(path, NOFOLLOW, &st);
+	error = do_sys_stat(SCARG_P32(uap, path), FOLLOW, &st);
 	if (error != 0)
 		return error;
 
-	linux32_from_stat(&st, &st32);
+	bsd_to_linux32_stat64(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
+}
 
-	st32p = SCARG_P32(uap, sp);
+int
+linux32_sys_lstat64(struct lwp *l, const struct linux32_sys_lstat64_args *uap, register_t *retval)
+{
+	/* {
+	        syscallarg(netbsd32_charp) path;
+	        syscallarg(linux32_stat64p) sp;
+	} */
+	int error;
+	struct stat st;
+	struct linux32_stat64 st32;
+	
+	error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &st);
+	if (error != 0)
+		return error;
 
-	return copyout(&st32, st32p, sizeof(*st32p));
+	bsd_to_linux32_stat64(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
 }
 
 int
@@ -165,15 +239,11 @@ linux32_sys_fstat64(struct lwp *l, const
 	int error;
 	struct stat st;
 	struct linux32_stat64 st32;
-	struct linux32_stat64 *st32p;
 
 	error = do_sys_fstat(SCARG(uap, fd), &st);
 	if (error != 0)
 		return error;
 
-	linux32_from_stat(&st, &st32);
-
-	st32p = SCARG_P32(uap, sp);
-
-	return copyout(&st32, st32p, sizeof(*st32p));
+	bsd_to_linux32_stat64(&st, &st32);
+	return copyout(&st32, SCARG_P32(uap, sp), sizeof(st32));
 }

Reply via email to