Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jun 2017 18:06:20 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320278 - in head: . lib/libc/include lib/libc/sys
Message-ID:  <201706231806.v5NI6KCZ052221@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Fri Jun 23 18:06:20 2017
New Revision: 320278
URL: https://svnweb.freebsd.org/changeset/base/320278

Log:
  Forward compatibility for ino64.
  
  Add forward compatibility so that new binaries can run on old
  kernels. If the new system call from ino64 isn't available on your
  system, then the old one will be used and the results translated.  The
  stat and statfs families of functions are fully emulated. While not
  required by policy, in this case it is helpful to our users to provide
  this compatibility. In this case, it allows rollback of the kernel
  after installing a new userland should a problem be discovered. It
  also prevents foot-shooting if a user does an install before rebooting
  with the new kernel. Finally, it allows the use case where one needs
  to run new binaries on an old kernel as part of an upgrade process.
  
  The getdirentries family uses tricks that may not work on remote
  filesystems. Specifically, it uses a buffer 1/4 the size requested to
  get the data from he old syscall.
  
  The code carefully uses direct syscalls for old system calls to avoid
  referencing freebsd11_* symbols, which contaminate ld-elf.so.1's
  export table due to its use of stat functions, which causes errno to
  be incorrect in client programs due to the wrong *stat* function being
  resolved in some cases.
  
  This code should removed sometime after 12 is branched.
  
  Tested on: 12-current binaries on a 10.3-beta kernel run and return
         consistent results. 12-current kernel and userland with
         packages from before ino64 was committed also work.
  
  Differential Revision: https://reviews.freebsd.org/D11185
  Reviewed by: kib@, emaste@

Added:
  head/lib/libc/sys/compat-ino64.h   (contents, props changed)
  head/lib/libc/sys/fstat.c
     - copied, changed from r320250, head/lib/libc/sys/stat.c
  head/lib/libc/sys/fstatat.c
     - copied, changed from r320250, head/lib/libc/sys/stat.c
  head/lib/libc/sys/fstatfs.c
     - copied, changed from r320250, head/lib/libc/sys/lstat.c
  head/lib/libc/sys/getdirentries.c   (contents, props changed)
  head/lib/libc/sys/getfsstat.c
     - copied, changed from r320250, head/lib/libc/sys/lstat.c
  head/lib/libc/sys/statfs.c
     - copied, changed from r320250, head/lib/libc/sys/stat.c
Modified:
  head/UPDATING
  head/lib/libc/include/libc_private.h
  head/lib/libc/sys/Makefile.inc
  head/lib/libc/sys/getdents.c
  head/lib/libc/sys/lstat.c
  head/lib/libc/sys/stat.c

Modified: head/UPDATING
==============================================================================
--- head/UPDATING	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/UPDATING	Fri Jun 23 18:06:20 2017	(r320278)
@@ -55,6 +55,14 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW:
 	Switch back to the BSDL dtc (Device Tree Compiler). Set WITH_GPL_DTC
 	if you require the GPL compiler.
 
+20170619:
+	Forward compatibility for the "ino64" project have been committed. This
+	will allow most new binaries to run on older kernels in a limited
+	fashion.  This prevents many of the common foot-shooting actions in the
+	upgrade as well as the limited ability to roll back the kernel across
+	the ino64 upgrade. Complicated use cases may not work properly, though
+	enough simpler ones work to allow recovery in most situations.
+
 20170618:
 	The internal ABI used for communication between the NFS kernel modules
 	was changed by r320085, so __FreeBSD_version was bumped to

Modified: head/lib/libc/include/libc_private.h
==============================================================================
--- head/lib/libc/include/libc_private.h	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/lib/libc/include/libc_private.h	Fri Jun 23 18:06:20 2017	(r320278)
@@ -311,6 +311,7 @@ struct rusage;
 struct sigaction;
 struct sockaddr;
 struct stat;
+struct statfs;
 struct timespec;
 struct timeval;
 struct timezone;
@@ -327,13 +328,16 @@ int		__sys_clock_nanosleep(__clockid_t, int,
 		    const struct timespec *, struct timespec *);
 int		__sys_close(int);
 int		__sys_connect(int, const struct sockaddr *, __socklen_t);
-__ssize_t	__sys_getdirentries(int, char *, __size_t, __off_t *);
 int		__sys_fcntl(int, int, ...);
 int		__sys_fdatasync(int);
+int		__sys_fstat(int fd, struct stat *);
+int		__sys_fstatfs(int fd, struct statfs *);
 int		__sys_fstatat(int, const char *, struct stat *, int);
 int		__sys_fsync(int);
 __pid_t		__sys_fork(void);
 int		__sys_ftruncate(int, __off_t);
+__ssize_t	__sys_getdirentries(int, char *, __size_t, __off_t *);
+int		__sys_getfsstat(struct statfs *, long, int);
 int		__sys_gettimeofday(struct timeval *, struct timezone *);
 int		__sys_kevent(int, const struct kevent *, int, struct kevent *,
 		    int, const struct timespec *);
@@ -372,6 +376,7 @@ int		__sys_sigtimedwait(const __sigset_t *, struct __s
 		    const struct timespec *);
 int		__sys_sigwait(const __sigset_t *, int *);
 int		__sys_sigwaitinfo(const __sigset_t *, struct __siginfo *);
+int		__sys_statfs(const char *, struct statfs *);
 int		__sys_swapcontext(struct __ucontext *,
 		    const struct __ucontext *);
 int		__sys_thr_kill(long, int);

Modified: head/lib/libc/sys/Makefile.inc
==============================================================================
--- head/lib/libc/sys/Makefile.inc	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/lib/libc/sys/Makefile.inc	Fri Jun 23 18:06:20 2017	(r320278)
@@ -37,6 +37,14 @@ SRCS+=	\
 
 SRCS+= getdents.c lstat.c mknod.c stat.c
 
+SRCS+= fstat.c fstatat.c fstatfs.c getfsstat.c statfs.c
+NOASM+= fstat.o fstatat.o fstatfs.o getfsstat.o statfs.o
+PSEUDO+= _fstat.o _fstatat.o _fstatfs.o _getfsstat.o _statfs.o
+
+SRCS+= getdirentries.c
+NOASM+= getdirentries.o
+PSEUDO+= _getdirentries.o
+
 SRCS+= pipe.c
 
 INTERPOSED = \

Added: head/lib/libc/sys/compat-ino64.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libc/sys/compat-ino64.h	Fri Jun 23 18:06:20 2017	(r320278)
@@ -0,0 +1,102 @@
+/*-
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Forward compatibility shim to convert old stat buffer to
+ * new so we can call the old system call, but return data in
+ * the new system call's format.
+ */
+#define _WANT_FREEBSD11_STATFS
+#include <sys/fcntl.h>
+#include <sys/mount.h>
+
+#define _WANT_FREEBSD11_STAT
+#include <sys/stat.h>
+
+#include <string.h>
+
+#define INO64_FIRST 1200031
+
+static __inline void
+__stat11_to_stat(const struct freebsd11_stat *sb11, struct stat *sb)
+{
+
+	sb->st_dev = sb11->st_dev;
+	sb->st_ino = sb11->st_ino;
+	sb->st_nlink = sb11->st_nlink;
+	sb->st_mode = sb11->st_mode;
+	sb->st_uid = sb11->st_uid;
+	sb->st_gid = sb11->st_gid;
+	sb->st_rdev = sb11->st_rdev;
+	sb->st_atim = sb11->st_atim;
+	sb->st_mtim = sb11->st_mtim;
+	sb->st_ctim = sb11->st_ctim;
+#ifdef __STAT_TIME_T_EXT
+	sb->st_atim_ext = 0;
+	sb->st_mtim_ext = 0;
+	sb->st_ctim_ext = 0;
+	sb->st_btim_ext = 0;
+#endif
+	sb->st_birthtim = sb11->st_birthtim;
+	sb->st_size = sb11->st_size;
+	sb->st_blocks = sb11->st_blocks;
+	sb->st_blksize = sb11->st_blksize;
+	sb->st_flags = sb11->st_flags;
+	sb->st_gen = sb11->st_gen;
+	sb->st_padding0 = 0;
+	sb->st_padding1 = 0;
+	memset(sb->st_spare, 0, sizeof(sb->st_spare));
+}
+
+static __inline void
+__statfs11_to_statfs(const struct freebsd11_statfs *sf11, struct statfs *sf)
+{
+
+	sf->f_version = STATFS_VERSION;
+	sf->f_type = sf11->f_type;
+	sf->f_flags = sf11->f_flags;
+	sf->f_bsize = sf11->f_bsize;
+	sf->f_iosize = sf11->f_iosize;
+	sf->f_blocks = sf11->f_blocks;
+	sf->f_bfree = sf11->f_bfree;
+	sf->f_bavail = sf11->f_bavail;
+	sf->f_files = sf11->f_files;
+	sf->f_ffree = sf11->f_ffree;
+	sf->f_syncwrites = sf11->f_syncwrites;
+	sf->f_asyncwrites = sf11->f_asyncwrites;
+	sf->f_syncreads = sf11->f_syncreads;
+	sf->f_asyncreads = sf11->f_asyncreads;
+	sf->f_namemax = sf11->f_namemax;
+	sf->f_owner = sf11->f_owner;
+	sf->f_fsid = sf11->f_fsid;
+	memset(sf->f_spare, 0, sizeof(sf->f_spare));
+	memset(sf->f_charspare, 0, sizeof(sf->f_charspare));
+	strlcpy(sf->f_fstypename, sf11->f_fstypename, sizeof(sf->f_fstypename));
+	strlcpy(sf->f_mntfromname, sf11->f_mntfromname, sizeof(sf->f_mntfromname));
+	strlcpy(sf->f_mntonname, sf11->f_mntonname, sizeof(sf->f_mntonname));
+}

Copied and modified: head/lib/libc/sys/fstat.c (from r320250, head/lib/libc/sys/stat.c)
==============================================================================
--- head/lib/libc/sys/stat.c	Thu Jun 22 22:53:10 2017	(r320250, copy source)
+++ head/lib/libc/sys/fstat.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,26 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
+#undef fstat
+__weak_reference(_fstat, fstat);
+
+#pragma weak _fstat
 int
-stat(const char *path, struct stat *sb)
+_fstat(int fd, struct stat *sb)
 {
+	struct freebsd11_stat stat11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, 0));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_fstat(fd, sb));
+	rv = syscall(SYS_freebsd11_fstat, fd, &stat11);
+	if (rv == 0)
+		__stat11_to_stat(&stat11, sb);
+	return (rv);
 }

Copied and modified: head/lib/libc/sys/fstatat.c (from r320250, head/lib/libc/sys/stat.c)
==============================================================================
--- head/lib/libc/sys/stat.c	Thu Jun 22 22:53:10 2017	(r320250, copy source)
+++ head/lib/libc/sys/fstatat.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,22 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
 int
-stat(const char *path, struct stat *sb)
+fstatat(int fd, const char *path, struct stat *sb, int flag)
 {
+	struct freebsd11_stat stat11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, 0));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_fstatat(fd, path, sb, flag));
+	rv = syscall(SYS_freebsd11_fstatat, fd, path, &stat11, flag);
+	if (rv == 0)
+		__stat11_to_stat(&stat11, sb);
+	return (rv);
 }

Copied and modified: head/lib/libc/sys/fstatfs.c (from r320250, head/lib/libc/sys/lstat.c)
==============================================================================
--- head/lib/libc/sys/lstat.c	Thu Jun 22 22:53:10 2017	(r320250, copy source)
+++ head/lib/libc/sys/fstatfs.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,26 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
+#undef fstatfs
+__weak_reference(_fstatfs, fstatfs);
+
+#pragma weak _fstatfs
 int
-lstat(const char *path, struct stat *sb)
+_fstatfs(int fd, struct statfs *buf)
 {
+	struct freebsd11_statfs statfs11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_fstatfs(fd, buf));
+	rv = syscall(SYS_freebsd11_fstatfs, fd, &statfs11);
+	if (rv == 0)
+		__statfs11_to_statfs(&statfs11, buf);
+	return (rv);
 }

Modified: head/lib/libc/sys/getdents.c
==============================================================================
--- head/lib/libc/sys/getdents.c	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/lib/libc/sys/getdents.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -36,6 +36,11 @@ __FBSDID("$FreeBSD$");
 ssize_t
 getdents(int fd, char *buf, size_t nbytes)
 {
+	/*
+	 * _getdirentries knows how to call the right thing and
+	 * return it in the new format. It assumes that the entire
+	 * libc expecting the new format.
+	 */
 
-	return (__sys_getdirentries(fd, buf, nbytes, NULL));
+	return (_getdirentries(fd, buf, nbytes, NULL));
 }

Added: head/lib/libc/sys/getdirentries.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libc/sys/getdirentries.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -0,0 +1,117 @@
+/*-
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#define _WANT_FREEBSD11_DIRENT
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <sys/syscall.h>
+#include "compat-ino64.h"
+#include <dirent.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "libc_private.h"
+
+static ssize_t
+__cvt_dirents_from11(const char *de11, ssize_t len11, char *de, ssize_t len)
+{
+	struct dirent *dst;
+	const struct freebsd11_dirent *src;
+	const char *edst, *esrc;
+	ssize_t rlen;
+
+	src = (const struct freebsd11_dirent *)de11;
+	dst = (struct dirent *)de;
+	esrc = de11 + len11;
+	edst = de + len;
+	while ((const char *)src < esrc && (const char *)dst < edst) {
+		rlen = roundup(offsetof(struct dirent, d_name) + src->d_namlen + 1, 8);
+		if ((const char *)dst + rlen >= edst)
+			break;
+		dst->d_fileno = src->d_fileno;
+		dst->d_off = 0;			/* nothing uses it yet, so safe for now */
+		dst->d_reclen = rlen;
+		dst->d_type = src->d_type;
+		dst->d_pad0 = 0;
+		dst->d_namlen = src->d_namlen;
+		dst->d_pad1 = 0;
+		memset(dst->d_name, 0, roundup(src->d_namlen + 1, 8));
+		memcpy(dst->d_name, src->d_name, src->d_namlen);
+		dst = (struct dirent *)((char *)dst + rlen);
+		src = (const struct freebsd11_dirent *)((const char *)src + src->d_reclen);
+	}
+	return ((char *)dst - de);
+}
+
+#undef getdirentries
+__weak_reference(_getdirentries, getdirentries);
+
+#pragma weak _getdirentries
+ssize_t
+_getdirentries(int fd, char *buf, size_t nbytes, off_t *basep)
+{
+	char *oldbuf;
+	size_t len;
+	ssize_t rv;
+
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_getdirentries(fd, buf, nbytes, basep));
+
+	/*
+	 * Because the old system call returns entries that are smaller than the
+	 * new, we could wind up in a situation where we have too many to fit in
+	 * the buffer with the new encoding. So sacrifice a small bit of
+	 * efficiency to ensure that never happens. We pick 1/4 the size round
+	 * up to the next DIRBLKSIZ. This will guarnatee enough room exists in
+	 * the dst buffer due to changes in efficiency in packing dirent
+	 * entries. We don't check against minimum block size to avoid a lot of
+	 * stat calls, we'll see if that's wise or not.
+	 * TBD: Will this difference matter to lseek?
+	 */
+	len = roundup(nbytes / 4, DIRBLKSIZ);
+	oldbuf = malloc(len);
+	if (oldbuf == NULL) {
+		errno = EINVAL;		/* ENOMEM not in possible list */
+		return (-1);
+	}
+	rv = syscall(SYS_freebsd11_getdirentries, fd, oldbuf, len, basep);
+	if (rv == -1) {
+		free(oldbuf);
+		return (rv);
+	}
+	if (rv > 0)
+		rv = __cvt_dirents_from11(oldbuf, rv, buf, nbytes);
+	free(oldbuf);
+
+	return (rv);
+}

Copied and modified: head/lib/libc/sys/getfsstat.c (from r320250, head/lib/libc/sys/lstat.c)
==============================================================================
--- head/lib/libc/sys/lstat.c	Thu Jun 22 22:53:10 2017	(r320250, copy source)
+++ head/lib/libc/sys/getfsstat.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,36 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
+#include "compat-ino64.h"
+#include <sys/errno.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include <stdlib.h>
 #include <unistd.h>
+
 #include "libc_private.h"
 
 int
-lstat(const char *path, struct stat *sb)
+getfsstat(struct statfs *buf, long bufsize, int flags)
 {
+	struct freebsd11_statfs *statfs11 = NULL;
+	ssize_t len = 0;
+	int rv, i;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_getfsstat(buf, bufsize, flags));
+	if (buf != NULL) {
+		len = sizeof(struct freebsd11_statfs) *	/* Round down on purpose to avoid */
+		    (bufsize / sizeof(struct statfs));	/* overflow on translation.	  */
+		statfs11 = malloc(len);
+		if (statfs11 == NULL) {
+			errno = ENOMEM;
+			return (-1);
+		}
+	}
+	rv = syscall(SYS_freebsd11_getfsstat, statfs11, len, flags);
+	if (rv != -1 && buf != NULL) {
+		for (i = 0; i < rv; i++)
+			__statfs11_to_statfs(&statfs11[i], &buf[i]);
+	}
+	return (rv);
 }

Modified: head/lib/libc/sys/lstat.c
==============================================================================
--- head/lib/libc/sys/lstat.c	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/lib/libc/sys/lstat.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,4 +1,5 @@
 /*-
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
  * All rights reserved.
  *
@@ -29,15 +30,22 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
 int
 lstat(const char *path, struct stat *sb)
 {
+	struct freebsd11_stat stat11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
+	rv = syscall(SYS_freebsd11_lstat, path, &stat11);
+	if (rv == 0)
+		__stat11_to_stat(&stat11, sb);
+	return (rv);
 }

Modified: head/lib/libc/sys/stat.c
==============================================================================
--- head/lib/libc/sys/stat.c	Fri Jun 23 17:39:00 2017	(r320277)
+++ head/lib/libc/sys/stat.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,4 +1,5 @@
 /*-
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
  * All rights reserved.
  *
@@ -29,15 +30,22 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
 int
 stat(const char *path, struct stat *sb)
 {
+	struct freebsd11_stat stat11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, 0));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_fstatat(AT_FDCWD, path, sb, 0));
+	rv = syscall(SYS_freebsd11_stat, path, &stat11);
+	if (rv == 0)
+		__stat11_to_stat(&stat11, sb);
+	return (rv);
 }

Copied and modified: head/lib/libc/sys/statfs.c (from r320250, head/lib/libc/sys/stat.c)
==============================================================================
--- head/lib/libc/sys/stat.c	Thu Jun 22 22:53:10 2017	(r320250, copy source)
+++ head/lib/libc/sys/statfs.c	Fri Jun 23 18:06:20 2017	(r320278)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
+ * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,22 @@ __FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/param.h>
-#include <sys/fcntl.h>
 #include <sys/syscall.h>
-#include <sys/stat.h>
+#include "compat-ino64.h"
 #include <unistd.h>
+
 #include "libc_private.h"
 
 int
-stat(const char *path, struct stat *sb)
+statfs(const char *path, struct statfs *buf)
 {
+	struct freebsd11_statfs statfs11;
+	int rv;
 
-	return (__sys_fstatat(AT_FDCWD, path, sb, 0));
+	if (__getosreldate() >= INO64_FIRST)
+		return (__sys_statfs(path, buf));
+	rv = syscall(SYS_freebsd11_statfs, path, &statfs11);
+	if (rv == 0)
+		__statfs11_to_statfs(&statfs11, buf);
+	return (rv);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706231806.v5NI6KCZ052221>