View | Details | Raw Unified | Return to bug 218320 | Differences between
and this patch

Collapse All | Expand All

(-)b/TODO.ino64 (+4 lines)
Added Link Here
1
Commit checklist: see /preapply.sh
2
3
After commit checklist:
4
1. Regen and commit sys/kern and sys/compat/freebsd32 sysents.
(-)b/abi.sh (+50 lines)
Added Link Here
1
#!/bin/sh
2
3
set -e
4
PATH=$HOME/bin:$PATH
5
6
PRISTINE_BASE=/scratch/tmp/kib/obj/scratch/tmp/kib/ino64_master/
7
CHANGED_BASE=/scratch/tmp/kib/obj/scratch/tmp/kib/ino64/
8
objs=$(find $CHANGED_BASE \! -regex '.*test.*' \! -regex '.*private.*' \
9
    -type f -name '*.so.*.full' | sed 's@^'${CHANGED_BASE}'@@' )
10
11
exclude_list="libhx509.so.11 libgssapi_ntlm.so.10"
12
subs_list="libarchive.so.6@libarchive.so.7 libmilter.so.5@libmilter.so.6 libzfs.so.2@libzfs.so.3"
13
14
mkdir -p tmp
15
rm -rf compat_reports tmp/*
16
troubles=
17
for obj in $objs; do
18
#	    -public-headers ${PRISTINE_BASE}/tmp/usr/include
19
    if echo $obj | grep world32 ; then
20
	suffix=-32
21
    else
22
	suffix=""
23
    fi
24
    libname1=$(basename ${obj} | sed 's/\.full//')
25
    libname=${libname1}${suffix}
26
    for x in $exclude_list; do
27
	if [ ${x}${suffix} \= $libname ] ; then
28
		continue 2
29
	fi
30
    done
31
    changed_obj=${CHANGED_BASE}/${obj}
32
    pristine_obj=$(echo ${changed_obj} | sed s/ino64/ino64_master/g)
33
    for x in ${subs_list} ; do
34
	name1=$(echo ${x} | sed 's/@.*$//')
35
	name2=$(echo ${x} | sed 's/^.*@//')
36
	if [ ${name2} \= ${libname1} ]
37
	   $pristine_obj=$(echo ${pristine_obj} | sed s/${name2}/${name1}/)
38
    fi
39
    abi-dumper.pl ${pristine_obj} \
40
      -lver pristine -o tmp/${libname}-pristine.dump
41
    abi-dumper.pl ${changed_obj} \
42
      -lver ino64 -o tmp/${libname}-ino64.dump
43
    if abi-compliance-checker.pl -l ${libname} \
44
      -old tmp/${libname}-pristine.dump \
45
      -new tmp/${libname}-ino64.dump ; then : ; else
46
	troubles="${troubles} ${libname}"
47
    fi
48
done
49
50
echo "Troublesome libraries: " ${troubles}
(-)b/cddl/lib/libzfs/Makefile (+1 lines)
Lines 37-42 SRCS+= libzfs_changelist.c \ Link Here
37
	zprop_common.c \
37
	zprop_common.c \
38
38
39
WARNS?=	0
39
WARNS?=	0
40
SHLIB_MAJOR= 3
40
CSTD=	c99
41
CSTD=	c99
41
CFLAGS+= -DZFS_NO_ACL
42
CFLAGS+= -DZFS_NO_ACL
42
CFLAGS+= -I${SRCTOP}/sbin/mount
43
CFLAGS+= -I${SRCTOP}/sbin/mount
(-)b/contrib/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc (-3 / +7 lines)
Lines 223-229 static void kernel_stat_to_stat(struct kernel_stat *in, struct stat *out) { Link Here
223
223
224
uptr internal_stat(const char *path, void *buf) {
224
uptr internal_stat(const char *path, void *buf) {
225
#if SANITIZER_FREEBSD
225
#if SANITIZER_FREEBSD
226
  return internal_syscall(SYSCALL(stat), path, buf);
226
  return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
227
                          (uptr)buf, 0);
227
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
228
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
228
  return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
229
  return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
229
                          (uptr)buf, 0);
230
                          (uptr)buf, 0);
Lines 247-253 uptr internal_stat(const char *path, void *buf) { Link Here
247
248
248
uptr internal_lstat(const char *path, void *buf) {
249
uptr internal_lstat(const char *path, void *buf) {
249
#if SANITIZER_FREEBSD
250
#if SANITIZER_FREEBSD
250
  return internal_syscall(SYSCALL(lstat), path, buf);
251
  return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path,
252
                         (uptr)buf, AT_SYMLINK_NOFOLLOW);
251
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
253
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
252
  return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
254
  return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path,
253
                         (uptr)buf, AT_SYMLINK_NOFOLLOW);
255
                         (uptr)buf, AT_SYMLINK_NOFOLLOW);
Lines 590-596 uptr internal_getppid() { Link Here
590
}
592
}
591
593
592
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
594
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
593
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
595
#if SANITIZER_FREEBSD
596
  return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
597
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
594
  return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count);
598
  return internal_syscall(SYSCALL(getdents64), fd, (uptr)dirp, count);
595
#else
599
#else
596
  return internal_syscall(SYSCALL(getdents), fd, (uptr)dirp, count);
600
  return internal_syscall(SYSCALL(getdents), fd, (uptr)dirp, count);
(-)b/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h (-1 / +2 lines)
Lines 489-495 namespace __sanitizer { Link Here
489
  };
489
  };
490
#elif SANITIZER_FREEBSD
490
#elif SANITIZER_FREEBSD
491
  struct __sanitizer_dirent {
491
  struct __sanitizer_dirent {
492
    unsigned int d_fileno;
492
    unsigned long long d_fileno;
493
    unsigned long long d_off;
493
    unsigned short d_reclen;
494
    unsigned short d_reclen;
494
    // more fields that we don't care about
495
    // more fields that we don't care about
495
  };
496
  };
(-)b/contrib/openbsm/libbsm/bsm_wrappers.c (-1 / +3 lines)
Lines 264-275 audit_set_terminal_host(uint32_t *m) Link Here
264
int
264
int
265
audit_set_terminal_id(au_tid_t *tid)
265
audit_set_terminal_id(au_tid_t *tid)
266
{
266
{
267
	dev_t port;
267
	int ret;
268
	int ret;
268
269
269
	if (tid == NULL)
270
	if (tid == NULL)
270
		return (kAUBadParamErr);
271
		return (kAUBadParamErr);
271
	if ((ret = audit_set_terminal_port(&tid->port)) != kAUNoErr)
272
	if ((ret = audit_set_terminal_port(&port)) != kAUNoErr)
272
		return (ret);
273
		return (ret);
274
	tid->port = port;
273
	return (audit_set_terminal_host(&tid->machine));
275
	return (audit_set_terminal_host(&tid->machine));
274
}
276
}
275
277
(-)b/include/dirent.h (-2 / +17 lines)
Lines 41-46 Link Here
41
#include <sys/_types.h>
41
#include <sys/_types.h>
42
#include <sys/dirent.h>
42
#include <sys/dirent.h>
43
43
44
#ifndef _SIZE_T_DECLARED
45
typedef	__size_t	size_t;
46
#define	_SIZE_T_DECLARED
47
#endif
48
49
#ifndef _SSIZE_T_DECLARED
50
typedef	__ssize_t	ssize_t;
51
#define	_SSIZE_T_DECLARED
52
#endif
53
54
#ifndef _OFF_T_DECLARED
55
typedef	__off_t		off_t;
56
#define	_OFF_T_DECLARED
57
#endif
58
44
#if __XSI_VISIBLE
59
#if __XSI_VISIBLE
45
60
46
#ifndef _INO_T_DECLARED
61
#ifndef _INO_T_DECLARED
Lines 89-96 int dirfd(DIR *); Link Here
89
#if __BSD_VISIBLE
104
#if __BSD_VISIBLE
90
DIR	*__opendir2(const char *, int);
105
DIR	*__opendir2(const char *, int);
91
int	 fdclosedir(DIR *);
106
int	 fdclosedir(DIR *);
92
int	 getdents(int, char *, int);
107
ssize_t	 getdents(int, char *, size_t);
93
int	 getdirentries(int, char *, int, long *);
108
ssize_t	 getdirentries(int, char *, size_t, off_t *);
94
#endif
109
#endif
95
DIR	*opendir(const char *);
110
DIR	*opendir(const char *);
96
DIR	*fdopendir(int);
111
DIR	*fdopendir(int);
(-)b/lib/libarchive/Makefile (-1 / +1 lines)
Lines 11-17 CFLAGS+= -DHAVE_BZLIB_H=1 -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 Link Here
11
11
12
# FreeBSD SHLIB_MAJOR value is managed as part of the FreeBSD system.
12
# FreeBSD SHLIB_MAJOR value is managed as part of the FreeBSD system.
13
# It has no real relation to the libarchive version number.
13
# It has no real relation to the libarchive version number.
14
SHLIB_MAJOR= 6
14
SHLIB_MAJOR= 7
15
15
16
CFLAGS+=	-DPLATFORM_CONFIG_H=\"${.CURDIR}/config_freebsd.h\"
16
CFLAGS+=	-DPLATFORM_CONFIG_H=\"${.CURDIR}/config_freebsd.h\"
17
CFLAGS+=	-I${.OBJDIR}
17
CFLAGS+=	-I${.OBJDIR}
(-)b/lib/libc/gen/Makefile.inc (-1 / +9 lines)
Lines 148-154 SRCS+= __getosreldate.c \ Link Here
148
	waitid.c \
148
	waitid.c \
149
	wordexp.c
149
	wordexp.c
150
.if ${MK_SYMVER} == yes
150
.if ${MK_SYMVER} == yes
151
SRCS+=	fts-compat.c \
151
SRCS+=	devname-compat11.c \
152
	fts-compat.c \
153
	fts-compat11.c \
154
	ftw-compat11.c \
155
	getmntinfo-compat11.c \
156
	glob-compat11.c \
157
	nftw-compat11.c \
158
	readdir-compat11.c \
159
	scandir-compat11.c \
152
	unvis-compat.c
160
	unvis-compat.c
153
.endif
161
.endif
154
162
(-)b/lib/libc/gen/Symbol.map (-20 / +20 lines)
Lines 75-82 FBSD_1.0 { Link Here
75
	ctermid;
75
	ctermid;
76
	ctermid_r;
76
	ctermid_r;
77
	daemon;
77
	daemon;
78
	devname;
79
	devname_r;
80
	getdiskbyname;
78
	getdiskbyname;
81
	dladdr;
79
	dladdr;
82
	dlclose;
80
	dlclose;
Lines 128-136 FBSD_1.0 { Link Here
128
	setfsent;
126
	setfsent;
129
	endfsent;
127
	endfsent;
130
	ftok;
128
	ftok;
131
	ftw;
132
	glob;
133
	globfree;
134
	getbootfile;
129
	getbootfile;
135
	getbsize;
130
	getbsize;
136
	cgetset;
131
	cgetset;
Lines 163-169 FBSD_1.0 { Link Here
163
	getloadavg;
158
	getloadavg;
164
	getlogin;
159
	getlogin;
165
	getlogin_r;
160
	getlogin_r;
166
	getmntinfo;
167
	setnetgrent;
161
	setnetgrent;
168
	getnetgrent;
162
	getnetgrent;
169
	endnetgrent;
163
	endnetgrent;
Lines 209-215 FBSD_1.0 { Link Here
209
	lrand48;
203
	lrand48;
210
	modf;
204
	modf;
211
	mrand48;
205
	mrand48;
212
	nftw;
213
	nice;
206
	nice;
214
	nlist;
207
	nlist;
215
	nrand48;
208
	nrand48;
Lines 220-232 FBSD_1.0 { Link Here
220
	pclose;
213
	pclose;
221
	psignal;
214
	psignal;
222
	raise;
215
	raise;
223
	readdir;
224
	readdir_r;
225
	readpassphrase;
216
	readpassphrase;
226
	getpass;
217
	getpass;
227
	rewinddir;
218
	rewinddir;
228
	scandir;
229
	alphasort;
230
	seed48;
219
	seed48;
231
	seekdir;
220
	seekdir;
232
	user_from_uid;
221
	user_from_uid;
Lines 314-327 FBSD_1.1 { Link Here
314
	fdevname_r;
303
	fdevname_r;
315
	fdopendir;
304
	fdopendir;
316
	feature_present;
305
	feature_present;
317
	fts_children;
318
	fts_close;
319
	fts_get_clientptr;
320
	fts_get_stream;
321
	fts_open;
322
	fts_read;
323
	fts_set;
324
	fts_set_clientptr;
325
	posix_spawn;
306
	posix_spawn;
326
	posix_spawn_file_actions_addclose;
307
	posix_spawn_file_actions_addclose;
327
	posix_spawn_file_actions_adddup2;
308
	posix_spawn_file_actions_adddup2;
Lines 408-420 FBSD_1.4 { Link Here
408
	pthread_mutex_consistent;
389
	pthread_mutex_consistent;
409
	pthread_mutexattr_getrobust;
390
	pthread_mutexattr_getrobust;
410
	pthread_mutexattr_setrobust;
391
	pthread_mutexattr_setrobust;
411
	scandir_b;
412
	stravis;
392
	stravis;
413
};
393
};
414
394
415
FBSD_1.5 {
395
FBSD_1.5 {
396
	alphasort;
416
	basename;
397
	basename;
398
	devname;
399
	devname_r;
417
	dirname;
400
	dirname;
401
	fts_children;
402
	fts_close;
403
	fts_get_clientptr;
404
	fts_get_stream;
405
	fts_open;
406
	fts_read;
407
	fts_set;
408
	fts_set_clientptr;
409
	ftw;
410
	getmntinfo;
411
	glob;
412
	globfree;
413
	nftw;
414
	readdir;
415
	readdir_r;
416
	scandir;
417
	scandir_b;
418
	sem_clockwait_np;
418
	sem_clockwait_np;
419
};
419
};
420
420
(-)b/lib/libc/gen/closedir.c (+1 lines)
Lines 59-64 fdclosedir(DIR *dirp) Link Here
59
	dirp->dd_fd = -1;
59
	dirp->dd_fd = -1;
60
	dirp->dd_loc = 0;
60
	dirp->dd_loc = 0;
61
	free((void *)dirp->dd_buf);
61
	free((void *)dirp->dd_buf);
62
	free(dirp->dd_compat_de);
62
	_reclaim_telldir(dirp);
63
	_reclaim_telldir(dirp);
63
	if (__isthreaded) {
64
	if (__isthreaded) {
64
		_pthread_mutex_unlock(&dirp->dd_lock);
65
		_pthread_mutex_unlock(&dirp->dd_lock);
(-)b/lib/libc/gen/devname-compat11.c (+50 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2011 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
#include <sys/types.h>
31
#include <sys/stat.h>
32
#include <stdlib.h>
33
#include "gen-compat.h"
34
35
char *
36
freebsd11_devname(uint32_t dev, mode_t type)
37
{
38
39
	return (devname(dev, type));
40
}
41
42
char *
43
freebsd11_devname_r(uint32_t dev, mode_t type, char *buf, int len)
44
{
45
46
	return (devname_r(dev, type, buf, len));
47
}
48
49
__sym_compat(devname, freebsd11_devname, FBSD_1.0);
50
__sym_compat(devname_r, freebsd11_devname_r, FBSD_1.0);
(-)b/lib/libc/gen/fts-compat.c (-14 / +19 lines)
Lines 40-54 __FBSDID("$FreeBSD$"); Link Here
40
40
41
#include "namespace.h"
41
#include "namespace.h"
42
#include <sys/param.h>
42
#include <sys/param.h>
43
#define	_WANT_FREEBSD11_STATFS
43
#include <sys/mount.h>
44
#include <sys/mount.h>
45
#define	_WANT_FREEBSD11_STAT
44
#include <sys/stat.h>
46
#include <sys/stat.h>
45
47
48
#define	_WANT_FREEBSD11_DIRENT
46
#include <dirent.h>
49
#include <dirent.h>
47
#include <errno.h>
50
#include <errno.h>
48
#include <fcntl.h>
51
#include <fcntl.h>
49
#include <stdlib.h>
52
#include <stdlib.h>
50
#include <string.h>
53
#include <string.h>
51
#include <unistd.h>
54
#include <unistd.h>
55
#include "gen-compat.h"
52
#include "fts-compat.h"
56
#include "fts-compat.h"
53
#include "un-namespace.h"
57
#include "un-namespace.h"
54
58
Lines 96-103 static int fts_ufslinks(FTS *, const FTSENT *); Link Here
96
 */
100
 */
97
struct _fts_private {
101
struct _fts_private {
98
	FTS		ftsp_fts;
102
	FTS		ftsp_fts;
99
	struct statfs	ftsp_statfs;
103
	struct freebsd11_statfs	ftsp_statfs;
100
	dev_t		ftsp_dev;
104
	uint32_t	ftsp_dev;
101
	int		ftsp_linksreliable;
105
	int		ftsp_linksreliable;
102
};
106
};
103
107
Lines 626-632 __fts_set_clientptr_44bsd(FTS *sp, void *clientptr) Link Here
626
static FTSENT *
630
static FTSENT *
627
fts_build(FTS *sp, int type)
631
fts_build(FTS *sp, int type)
628
{
632
{
629
	struct dirent *dp;
633
	struct freebsd11_dirent *dp;
630
	FTSENT *p, *head;
634
	FTSENT *p, *head;
631
	int nitems;
635
	int nitems;
632
	FTSENT *cur, *tail;
636
	FTSENT *cur, *tail;
Lines 738-744 fts_build(FTS *sp, int type) Link Here
738
742
739
	/* Read the directory, attaching each entry to the `link' pointer. */
743
	/* Read the directory, attaching each entry to the `link' pointer. */
740
	doadjust = 0;
744
	doadjust = 0;
741
	for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
745
	for (head = tail = NULL, nitems = 0;
746
	    dirp && (dp = freebsd11_readdir(dirp));) {
742
		dnamlen = dp->d_namlen;
747
		dnamlen = dp->d_namlen;
743
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
748
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
744
			continue;
749
			continue;
Lines 891-899 static u_short Link Here
891
fts_stat(FTS *sp, FTSENT *p, int follow)
896
fts_stat(FTS *sp, FTSENT *p, int follow)
892
{
897
{
893
	FTSENT *t;
898
	FTSENT *t;
894
	dev_t dev;
899
	uint32_t dev;
895
	ino_t ino;
900
	uint32_t ino;
896
	struct stat *sbp, sb;
901
	struct freebsd11_stat *sbp, sb;
897
	int saved_errno;
902
	int saved_errno;
898
903
899
	/* If user needs stat info, stat buffer already allocated. */
904
	/* If user needs stat info, stat buffer already allocated. */
Lines 916-931 fts_stat(FTS *sp, FTSENT *p, int follow) Link Here
916
	 * fail, set the errno from the stat call.
921
	 * fail, set the errno from the stat call.
917
	 */
922
	 */
918
	if (ISSET(FTS_LOGICAL) || follow) {
923
	if (ISSET(FTS_LOGICAL) || follow) {
919
		if (stat(p->fts_accpath, sbp)) {
924
		if (freebsd11_stat(p->fts_accpath, sbp)) {
920
			saved_errno = errno;
925
			saved_errno = errno;
921
			if (!lstat(p->fts_accpath, sbp)) {
926
			if (!freebsd11_lstat(p->fts_accpath, sbp)) {
922
				errno = 0;
927
				errno = 0;
923
				return (FTS_SLNONE);
928
				return (FTS_SLNONE);
924
			}
929
			}
925
			p->fts_errno = saved_errno;
930
			p->fts_errno = saved_errno;
926
			goto err;
931
			goto err;
927
		}
932
		}
928
	} else if (lstat(p->fts_accpath, sbp)) {
933
	} else if (freebsd11_lstat(p->fts_accpath, sbp)) {
929
		p->fts_errno = errno;
934
		p->fts_errno = errno;
930
err:		memset(sbp, 0, sizeof(struct stat));
935
err:		memset(sbp, 0, sizeof(struct stat));
931
		return (FTS_NS);
936
		return (FTS_NS);
Lines 1019-1025 fts_alloc(FTS *sp, char *name, int namelen) Link Here
1019
1024
1020
	struct ftsent_withstat {
1025
	struct ftsent_withstat {
1021
		FTSENT	ent;
1026
		FTSENT	ent;
1022
		struct	stat statbuf;
1027
		struct	freebsd11_stat statbuf;
1023
	};
1028
	};
1024
1029
1025
	/*
1030
	/*
Lines 1145-1158 static int Link Here
1145
fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
1150
fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
1146
{
1151
{
1147
	int ret, oerrno, newfd;
1152
	int ret, oerrno, newfd;
1148
	struct stat sb;
1153
	struct freebsd11_stat sb;
1149
1154
1150
	newfd = fd;
1155
	newfd = fd;
1151
	if (ISSET(FTS_NOCHDIR))
1156
	if (ISSET(FTS_NOCHDIR))
1152
		return (0);
1157
		return (0);
1153
	if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0)
1158
	if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0)
1154
		return (-1);
1159
		return (-1);
1155
	if (_fstat(newfd, &sb)) {
1160
	if (freebsd11_fstat(newfd, &sb)) {
1156
		ret = -1;
1161
		ret = -1;
1157
		goto bail;
1162
		goto bail;
1158
	}
1163
	}
Lines 1187-1193 fts_ufslinks(FTS *sp, const FTSENT *ent) Link Here
1187
	 * avoidance.
1192
	 * avoidance.
1188
	 */
1193
	 */
1189
	if (priv->ftsp_dev != ent->fts_dev) {
1194
	if (priv->ftsp_dev != ent->fts_dev) {
1190
		if (statfs(ent->fts_path, &priv->ftsp_statfs) != -1) {
1195
		if (freebsd11_statfs(ent->fts_path, &priv->ftsp_statfs) != -1) {
1191
			priv->ftsp_dev = ent->fts_dev;
1196
			priv->ftsp_dev = ent->fts_dev;
1192
			priv->ftsp_linksreliable = 0;
1197
			priv->ftsp_linksreliable = 0;
1193
			for (cpp = ufslike_filesystems; *cpp; cpp++) {
1198
			for (cpp = ufslike_filesystems; *cpp; cpp++) {
(-)b/lib/libc/gen/fts-compat.h (-5 / +5 lines)
Lines 37-43 typedef struct { Link Here
37
	struct _ftsent *fts_cur;	/* current node */
37
	struct _ftsent *fts_cur;	/* current node */
38
	struct _ftsent *fts_child;	/* linked list of children */
38
	struct _ftsent *fts_child;	/* linked list of children */
39
	struct _ftsent **fts_array;	/* sort array */
39
	struct _ftsent **fts_array;	/* sort array */
40
	dev_t fts_dev;			/* starting device # */
40
	uint32_t fts_dev;		/* starting device # */
41
	char *fts_path;			/* path for this descent */
41
	char *fts_path;			/* path for this descent */
42
	int fts_rfd;			/* fd for root */
42
	int fts_rfd;			/* fd for root */
43
	int fts_pathlen;		/* sizeof(path) */
43
	int fts_pathlen;		/* sizeof(path) */
Lines 82-90 typedef struct _ftsent { Link Here
82
	u_short fts_pathlen;		/* strlen(fts_path) */
82
	u_short fts_pathlen;		/* strlen(fts_path) */
83
	u_short fts_namelen;		/* strlen(fts_name) */
83
	u_short fts_namelen;		/* strlen(fts_name) */
84
84
85
	ino_t fts_ino;			/* inode */
85
	uint32_t fts_ino;		/* inode */
86
	dev_t fts_dev;			/* device */
86
	uint32_t fts_dev;		/* device */
87
	nlink_t fts_nlink;		/* link count */
87
	uint16_t fts_nlink;		/* link count */
88
88
89
#define	FTS_ROOTPARENTLEVEL	-1
89
#define	FTS_ROOTPARENTLEVEL	-1
90
#define	FTS_ROOTLEVEL		 0
90
#define	FTS_ROOTLEVEL		 0
Lines 117-123 typedef struct _ftsent { Link Here
117
#define	FTS_SKIP	 4		/* discard node */
117
#define	FTS_SKIP	 4		/* discard node */
118
	u_short fts_instr;		/* fts_set() instructions */
118
	u_short fts_instr;		/* fts_set() instructions */
119
119
120
	struct stat *fts_statp;		/* stat(2) information */
120
	struct freebsd11_stat *fts_statp; /* stat(2) information */
121
	char *fts_name;			/* file name */
121
	char *fts_name;			/* file name */
122
	FTS *fts_fts;			/* back pointer to main FTS */
122
	FTS *fts_fts;			/* back pointer to main FTS */
123
} FTSENT;
123
} FTSENT;
(-)b/lib/libc/gen/fts-compat11.c (+1199 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 1990, 1993, 1994
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 * from: $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
30
 */
31
32
#if 0
33
#if defined(LIBC_SCCS) && !defined(lint)
34
static char sccsid[] = "@(#)fts.c	8.6 (Berkeley) 8/14/94";
35
#endif /* LIBC_SCCS and not lint */
36
#endif
37
38
#include <sys/cdefs.h>
39
__FBSDID("$FreeBSD$");
40
41
#include "namespace.h"
42
#include <sys/param.h>
43
#define	_WANT_FREEBSD11_STATFS
44
#include <sys/mount.h>
45
#define	_WANT_FREEBSD11_STAT
46
#include <sys/stat.h>
47
48
#define	_WANT_FREEBSD11_DIRENT
49
#include <dirent.h>
50
#include <errno.h>
51
#include <fcntl.h>
52
#include <fts.h>
53
#include <stdlib.h>
54
#include <string.h>
55
#include <unistd.h>
56
#include "gen-compat.h"
57
#include "fts-compat11.h"
58
#include "un-namespace.h"
59
60
#include "gen-private.h"
61
62
static FTSENT11	*fts_alloc(FTS11 *, char *, size_t);
63
static FTSENT11	*fts_build(FTS11 *, int);
64
static void	 fts_lfree(FTSENT11 *);
65
static void	 fts_load(FTS11 *, FTSENT11 *);
66
static size_t	 fts_maxarglen(char * const *);
67
static void	 fts_padjust(FTS11 *, FTSENT11 *);
68
static int	 fts_palloc(FTS11 *, size_t);
69
static FTSENT11	*fts_sort(FTS11 *, FTSENT11 *, size_t);
70
static int	 fts_stat(FTS11 *, FTSENT11 *, int, int);
71
static int	 fts_safe_changedir(FTS11 *, FTSENT11 *, int, char *);
72
static int	 fts_ufslinks(FTS11 *, const FTSENT11 *);
73
74
#define	ISDOT(a)	(a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
75
76
#define	CLR(opt)	(sp->fts_options &= ~(opt))
77
#define	ISSET(opt)	(sp->fts_options & (opt))
78
#define	SET(opt)	(sp->fts_options |= (opt))
79
80
#define	FCHDIR(sp, fd)	(!ISSET(FTS_NOCHDIR) && fchdir(fd))
81
82
/* fts_build flags */
83
#define	BCHILD		1		/* fts_children */
84
#define	BNAMES		2		/* fts_children, names only */
85
#define	BREAD		3		/* fts_read */
86
87
/*
88
 * Internal representation of an FTS, including extra implementation
89
 * details.  The FTS returned from fts_open points to this structure's
90
 * ftsp_fts member (and can be cast to an _fts_private as required)
91
 */
92
struct _fts_private11 {
93
	FTS11		ftsp_fts;
94
	struct freebsd11_statfs	ftsp_statfs;
95
	uint32_t	ftsp_dev;
96
	int		ftsp_linksreliable;
97
};
98
99
/*
100
 * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it
101
 * knows that a directory could not possibly have subdirectories.  This
102
 * is decided by looking at the link count: a subdirectory would
103
 * increment its parent's link count by virtue of its own ".." entry.
104
 * This assumption only holds for UFS-like filesystems that implement
105
 * links and directories this way, so we must punt for others.
106
 */
107
108
static const char *ufslike_filesystems[] = {
109
	"ufs",
110
	"zfs",
111
	"nfs",
112
	"ext2fs",
113
	0
114
};
115
116
FTS11 *
117
freebsd11_fts_open(char * const *argv, int options,
118
    int (*compar)(const FTSENT11 * const *, const FTSENT11 * const *))
119
{
120
	struct _fts_private11 *priv;
121
	FTS11 *sp;
122
	FTSENT11 *p, *root;
123
	FTSENT11 *parent, *tmp;
124
	size_t len, nitems;
125
126
	/* Options check. */
127
	if (options & ~FTS_OPTIONMASK) {
128
		errno = EINVAL;
129
		return (NULL);
130
	}
131
132
	/* fts_open() requires at least one path */
133
	if (*argv == NULL) {
134
		errno = EINVAL;
135
		return (NULL);
136
	}
137
138
	/* Allocate/initialize the stream. */
139
	if ((priv = calloc(1, sizeof(*priv))) == NULL)
140
		return (NULL);
141
	sp = &priv->ftsp_fts;
142
	sp->fts_compar = compar;
143
	sp->fts_options = options;
144
145
	/* Shush, GCC. */
146
	tmp = NULL;
147
148
	/* Logical walks turn on NOCHDIR; symbolic links are too hard. */
149
	if (ISSET(FTS_LOGICAL))
150
		SET(FTS_NOCHDIR);
151
152
	/*
153
	 * Start out with 1K of path space, and enough, in any case,
154
	 * to hold the user's paths.
155
	 */
156
	if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN)))
157
		goto mem1;
158
159
	/* Allocate/initialize root's parent. */
160
	if ((parent = fts_alloc(sp, "", 0)) == NULL)
161
		goto mem2;
162
	parent->fts_level = FTS_ROOTPARENTLEVEL;
163
164
	/* Allocate/initialize root(s). */
165
	for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) {
166
		len = strlen(*argv);
167
168
		p = fts_alloc(sp, *argv, len);
169
		p->fts_level = FTS_ROOTLEVEL;
170
		p->fts_parent = parent;
171
		p->fts_accpath = p->fts_name;
172
		p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
173
174
		/* Command-line "." and ".." are real directories. */
175
		if (p->fts_info == FTS_DOT)
176
			p->fts_info = FTS_D;
177
178
		/*
179
		 * If comparison routine supplied, traverse in sorted
180
		 * order; otherwise traverse in the order specified.
181
		 */
182
		if (compar) {
183
			p->fts_link = root;
184
			root = p;
185
		} else {
186
			p->fts_link = NULL;
187
			if (root == NULL)
188
				tmp = root = p;
189
			else {
190
				tmp->fts_link = p;
191
				tmp = p;
192
			}
193
		}
194
	}
195
	if (compar && nitems > 1)
196
		root = fts_sort(sp, root, nitems);
197
198
	/*
199
	 * Allocate a dummy pointer and make fts_read think that we've just
200
	 * finished the node before the root(s); set p->fts_info to FTS_INIT
201
	 * so that everything about the "current" node is ignored.
202
	 */
203
	if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
204
		goto mem3;
205
	sp->fts_cur->fts_link = root;
206
	sp->fts_cur->fts_info = FTS_INIT;
207
208
	/*
209
	 * If using chdir(2), grab a file descriptor pointing to dot to ensure
210
	 * that we can get back here; this could be avoided for some paths,
211
	 * but almost certainly not worth the effort.  Slashes, symbolic links,
212
	 * and ".." are all fairly nasty problems.  Note, if we can't get the
213
	 * descriptor we run anyway, just more slowly.
214
	 */
215
	if (!ISSET(FTS_NOCHDIR) &&
216
	    (sp->fts_rfd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
217
		SET(FTS_NOCHDIR);
218
219
	return (sp);
220
221
mem3:	fts_lfree(root);
222
	free(parent);
223
mem2:	free(sp->fts_path);
224
mem1:	free(sp);
225
	return (NULL);
226
}
227
228
static void
229
fts_load(FTS11 *sp, FTSENT11 *p)
230
{
231
	size_t len;
232
	char *cp;
233
234
	/*
235
	 * Load the stream structure for the next traversal.  Since we don't
236
	 * actually enter the directory until after the preorder visit, set
237
	 * the fts_accpath field specially so the chdir gets done to the right
238
	 * place and the user can access the first node.  From fts_open it's
239
	 * known that the path will fit.
240
	 */
241
	len = p->fts_pathlen = p->fts_namelen;
242
	memmove(sp->fts_path, p->fts_name, len + 1);
243
	if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
244
		len = strlen(++cp);
245
		memmove(p->fts_name, cp, len + 1);
246
		p->fts_namelen = len;
247
	}
248
	p->fts_accpath = p->fts_path = sp->fts_path;
249
	sp->fts_dev = p->fts_dev;
250
}
251
252
int
253
freebsd11_fts_close(FTS11 *sp)
254
{
255
	FTSENT11 *freep, *p;
256
	int saved_errno;
257
258
	/*
259
	 * This still works if we haven't read anything -- the dummy structure
260
	 * points to the root list, so we step through to the end of the root
261
	 * list which has a valid parent pointer.
262
	 */
263
	if (sp->fts_cur) {
264
		for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
265
			freep = p;
266
			p = p->fts_link != NULL ? p->fts_link : p->fts_parent;
267
			free(freep);
268
		}
269
		free(p);
270
	}
271
272
	/* Free up child linked list, sort array, path buffer. */
273
	if (sp->fts_child)
274
		fts_lfree(sp->fts_child);
275
	if (sp->fts_array)
276
		free(sp->fts_array);
277
	free(sp->fts_path);
278
279
	/* Return to original directory, save errno if necessary. */
280
	if (!ISSET(FTS_NOCHDIR)) {
281
		saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
282
		(void)_close(sp->fts_rfd);
283
284
		/* Set errno and return. */
285
		if (saved_errno != 0) {
286
			/* Free up the stream pointer. */
287
			free(sp);
288
			errno = saved_errno;
289
			return (-1);
290
		}
291
	}
292
293
	/* Free up the stream pointer. */
294
	free(sp);
295
	return (0);
296
}
297
298
/*
299
 * Special case of "/" at the end of the path so that slashes aren't
300
 * appended which would cause paths to be written as "....//foo".
301
 */
302
#define	NAPPEND(p)							\
303
	(p->fts_path[p->fts_pathlen - 1] == '/'				\
304
	    ? p->fts_pathlen - 1 : p->fts_pathlen)
305
306
FTSENT11 *
307
freebsd11_fts_read(FTS11 *sp)
308
{
309
	FTSENT11 *p, *tmp;
310
	int instr;
311
	char *t;
312
	int saved_errno;
313
314
	/* If finished or unrecoverable error, return NULL. */
315
	if (sp->fts_cur == NULL || ISSET(FTS_STOP))
316
		return (NULL);
317
318
	/* Set current node pointer. */
319
	p = sp->fts_cur;
320
321
	/* Save and zero out user instructions. */
322
	instr = p->fts_instr;
323
	p->fts_instr = FTS_NOINSTR;
324
325
	/* Any type of file may be re-visited; re-stat and re-turn. */
326
	if (instr == FTS_AGAIN) {
327
		p->fts_info = fts_stat(sp, p, 0, -1);
328
		return (p);
329
	}
330
331
	/*
332
	 * Following a symlink -- SLNONE test allows application to see
333
	 * SLNONE and recover.  If indirecting through a symlink, have
334
	 * keep a pointer to current location.  If unable to get that
335
	 * pointer, follow fails.
336
	 */
337
	if (instr == FTS_FOLLOW &&
338
	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
339
		p->fts_info = fts_stat(sp, p, 1, -1);
340
		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
341
			if ((p->fts_symfd = _open(".", O_RDONLY | O_CLOEXEC,
342
			    0)) < 0) {
343
				p->fts_errno = errno;
344
				p->fts_info = FTS_ERR;
345
			} else
346
				p->fts_flags |= FTS_SYMFOLLOW;
347
		}
348
		return (p);
349
	}
350
351
	/* Directory in pre-order. */
352
	if (p->fts_info == FTS_D) {
353
		/* If skipped or crossed mount point, do post-order visit. */
354
		if (instr == FTS_SKIP ||
355
		    (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
356
			if (p->fts_flags & FTS_SYMFOLLOW)
357
				(void)_close(p->fts_symfd);
358
			if (sp->fts_child) {
359
				fts_lfree(sp->fts_child);
360
				sp->fts_child = NULL;
361
			}
362
			p->fts_info = FTS_DP;
363
			return (p);
364
		}
365
366
		/* Rebuild if only read the names and now traversing. */
367
		if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) {
368
			CLR(FTS_NAMEONLY);
369
			fts_lfree(sp->fts_child);
370
			sp->fts_child = NULL;
371
		}
372
373
		/*
374
		 * Cd to the subdirectory.
375
		 *
376
		 * If have already read and now fail to chdir, whack the list
377
		 * to make the names come out right, and set the parent errno
378
		 * so the application will eventually get an error condition.
379
		 * Set the FTS_DONTCHDIR flag so that when we logically change
380
		 * directories back to the parent we don't do a chdir.
381
		 *
382
		 * If haven't read do so.  If the read fails, fts_build sets
383
		 * FTS_STOP or the fts_info field of the node.
384
		 */
385
		if (sp->fts_child != NULL) {
386
			if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
387
				p->fts_errno = errno;
388
				p->fts_flags |= FTS_DONTCHDIR;
389
				for (p = sp->fts_child; p != NULL;
390
				    p = p->fts_link)
391
					p->fts_accpath =
392
					    p->fts_parent->fts_accpath;
393
			}
394
		} else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
395
			if (ISSET(FTS_STOP))
396
				return (NULL);
397
			return (p);
398
		}
399
		p = sp->fts_child;
400
		sp->fts_child = NULL;
401
		goto name;
402
	}
403
404
	/* Move to the next node on this level. */
405
next:	tmp = p;
406
	if ((p = p->fts_link) != NULL) {
407
		/*
408
		 * If reached the top, return to the original directory (or
409
		 * the root of the tree), and load the paths for the next root.
410
		 */
411
		if (p->fts_level == FTS_ROOTLEVEL) {
412
			if (FCHDIR(sp, sp->fts_rfd)) {
413
				SET(FTS_STOP);
414
				return (NULL);
415
			}
416
			free(tmp);
417
			fts_load(sp, p);
418
			return (sp->fts_cur = p);
419
		}
420
421
		/*
422
		 * User may have called fts_set on the node.  If skipped,
423
		 * ignore.  If followed, get a file descriptor so we can
424
		 * get back if necessary.
425
		 */
426
		if (p->fts_instr == FTS_SKIP) {
427
			free(tmp);
428
			goto next;
429
		}
430
		if (p->fts_instr == FTS_FOLLOW) {
431
			p->fts_info = fts_stat(sp, p, 1, -1);
432
			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
433
				if ((p->fts_symfd =
434
				    _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0) {
435
					p->fts_errno = errno;
436
					p->fts_info = FTS_ERR;
437
				} else
438
					p->fts_flags |= FTS_SYMFOLLOW;
439
			}
440
			p->fts_instr = FTS_NOINSTR;
441
		}
442
443
		free(tmp);
444
445
name:		t = sp->fts_path + NAPPEND(p->fts_parent);
446
		*t++ = '/';
447
		memmove(t, p->fts_name, p->fts_namelen + 1);
448
		return (sp->fts_cur = p);
449
	}
450
451
	/* Move up to the parent node. */
452
	p = tmp->fts_parent;
453
454
	if (p->fts_level == FTS_ROOTPARENTLEVEL) {
455
		/*
456
		 * Done; free everything up and set errno to 0 so the user
457
		 * can distinguish between error and EOF.
458
		 */
459
		free(tmp);
460
		free(p);
461
		errno = 0;
462
		return (sp->fts_cur = NULL);
463
	}
464
465
	/* NUL terminate the pathname. */
466
	sp->fts_path[p->fts_pathlen] = '\0';
467
468
	/*
469
	 * Return to the parent directory.  If at a root node or came through
470
	 * a symlink, go back through the file descriptor.  Otherwise, cd up
471
	 * one directory.
472
	 */
473
	if (p->fts_level == FTS_ROOTLEVEL) {
474
		if (FCHDIR(sp, sp->fts_rfd)) {
475
			SET(FTS_STOP);
476
			return (NULL);
477
		}
478
	} else if (p->fts_flags & FTS_SYMFOLLOW) {
479
		if (FCHDIR(sp, p->fts_symfd)) {
480
			saved_errno = errno;
481
			(void)_close(p->fts_symfd);
482
			errno = saved_errno;
483
			SET(FTS_STOP);
484
			return (NULL);
485
		}
486
		(void)_close(p->fts_symfd);
487
	} else if (!(p->fts_flags & FTS_DONTCHDIR) &&
488
	    fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
489
		SET(FTS_STOP);
490
		return (NULL);
491
	}
492
	free(tmp);
493
	p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
494
	return (sp->fts_cur = p);
495
}
496
497
/*
498
 * Fts_set takes the stream as an argument although it's not used in this
499
 * implementation; it would be necessary if anyone wanted to add global
500
 * semantics to fts using fts_set.  An error return is allowed for similar
501
 * reasons.
502
 */
503
/* ARGSUSED */
504
int
505
freebsd11_fts_set(FTS11 *sp, FTSENT11 *p, int instr)
506
{
507
	if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
508
	    instr != FTS_NOINSTR && instr != FTS_SKIP) {
509
		errno = EINVAL;
510
		return (1);
511
	}
512
	p->fts_instr = instr;
513
	return (0);
514
}
515
516
FTSENT11 *
517
freebsd11_fts_children(FTS11 *sp, int instr)
518
{
519
	FTSENT11 *p;
520
	int fd, rc, serrno;
521
522
	if (instr != 0 && instr != FTS_NAMEONLY) {
523
		errno = EINVAL;
524
		return (NULL);
525
	}
526
527
	/* Set current node pointer. */
528
	p = sp->fts_cur;
529
530
	/*
531
	 * Errno set to 0 so user can distinguish empty directory from
532
	 * an error.
533
	 */
534
	errno = 0;
535
536
	/* Fatal errors stop here. */
537
	if (ISSET(FTS_STOP))
538
		return (NULL);
539
540
	/* Return logical hierarchy of user's arguments. */
541
	if (p->fts_info == FTS_INIT)
542
		return (p->fts_link);
543
544
	/*
545
	 * If not a directory being visited in pre-order, stop here.  Could
546
	 * allow FTS_DNR, assuming the user has fixed the problem, but the
547
	 * same effect is available with FTS_AGAIN.
548
	 */
549
	if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
550
		return (NULL);
551
552
	/* Free up any previous child list. */
553
	if (sp->fts_child != NULL)
554
		fts_lfree(sp->fts_child);
555
556
	if (instr == FTS_NAMEONLY) {
557
		SET(FTS_NAMEONLY);
558
		instr = BNAMES;
559
	} else
560
		instr = BCHILD;
561
562
	/*
563
	 * If using chdir on a relative path and called BEFORE fts_read does
564
	 * its chdir to the root of a traversal, we can lose -- we need to
565
	 * chdir into the subdirectory, and we don't know where the current
566
	 * directory is, so we can't get back so that the upcoming chdir by
567
	 * fts_read will work.
568
	 */
569
	if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
570
	    ISSET(FTS_NOCHDIR))
571
		return (sp->fts_child = fts_build(sp, instr));
572
573
	if ((fd = _open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
574
		return (NULL);
575
	sp->fts_child = fts_build(sp, instr);
576
	serrno = (sp->fts_child == NULL) ? errno : 0;
577
	rc = fchdir(fd);
578
	if (rc < 0 && serrno == 0)
579
		serrno = errno;
580
	(void)_close(fd);
581
	errno = serrno;
582
	if (rc < 0)
583
		return (NULL);
584
	return (sp->fts_child);
585
}
586
587
#ifndef freebsd11_fts_get_clientptr
588
#error "freebsd11_fts_get_clientptr not defined"
589
#endif
590
591
void *
592
(freebsd11_fts_get_clientptr)(FTS11 *sp)
593
{
594
595
	return (freebsd11_fts_get_clientptr(sp));
596
}
597
598
#ifndef freebsd11_fts_get_stream
599
#error "freebsd11_fts_get_stream not defined"
600
#endif
601
602
FTS11 *
603
(freebsd11_fts_get_stream)(FTSENT11 *p)
604
{
605
	return (freebsd11_fts_get_stream(p));
606
}
607
608
void
609
freebsd11_fts_set_clientptr(FTS11 *sp, void *clientptr)
610
{
611
612
	sp->fts_clientptr = clientptr;
613
}
614
615
/*
616
 * This is the tricky part -- do not casually change *anything* in here.  The
617
 * idea is to build the linked list of entries that are used by fts_children
618
 * and fts_read.  There are lots of special cases.
619
 *
620
 * The real slowdown in walking the tree is the stat calls.  If FTS_NOSTAT is
621
 * set and it's a physical walk (so that symbolic links can't be directories),
622
 * we can do things quickly.  First, if it's a 4.4BSD file system, the type
623
 * of the file is in the directory entry.  Otherwise, we assume that the number
624
 * of subdirectories in a node is equal to the number of links to the parent.
625
 * The former skips all stat calls.  The latter skips stat calls in any leaf
626
 * directories and for any files after the subdirectories in the directory have
627
 * been found, cutting the stat calls by about 2/3.
628
 */
629
static FTSENT11 *
630
fts_build(FTS11 *sp, int type)
631
{
632
	struct freebsd11_dirent *dp;
633
	FTSENT11 *p, *head;
634
	FTSENT11 *cur, *tail;
635
	DIR *dirp;
636
	void *oldaddr;
637
	char *cp;
638
	int cderrno, descend, oflag, saved_errno, nostat, doadjust;
639
	long level;
640
	long nlinks;	/* has to be signed because -1 is a magic value */
641
	size_t dnamlen, len, maxlen, nitems;
642
643
	/* Set current node pointer. */
644
	cur = sp->fts_cur;
645
646
	/*
647
	 * Open the directory for reading.  If this fails, we're done.
648
	 * If being called from fts_read, set the fts_info field.
649
	 */
650
#ifdef FTS_WHITEOUT
651
	if (ISSET(FTS_WHITEOUT))
652
		oflag = DTF_NODUP | DTF_REWIND;
653
	else
654
		oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND;
655
#else
656
#define __opendir2(path, flag) opendir(path)
657
#endif
658
	if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
659
		if (type == BREAD) {
660
			cur->fts_info = FTS_DNR;
661
			cur->fts_errno = errno;
662
		}
663
		return (NULL);
664
	}
665
666
	/*
667
	 * Nlinks is the number of possible entries of type directory in the
668
	 * directory if we're cheating on stat calls, 0 if we're not doing
669
	 * any stat calls at all, -1 if we're doing stats on everything.
670
	 */
671
	if (type == BNAMES) {
672
		nlinks = 0;
673
		/* Be quiet about nostat, GCC. */
674
		nostat = 0;
675
	} else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
676
		if (fts_ufslinks(sp, cur))
677
			nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
678
		else
679
			nlinks = -1;
680
		nostat = 1;
681
	} else {
682
		nlinks = -1;
683
		nostat = 0;
684
	}
685
686
#ifdef notdef
687
	(void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
688
	(void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
689
	    ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
690
#endif
691
	/*
692
	 * If we're going to need to stat anything or we want to descend
693
	 * and stay in the directory, chdir.  If this fails we keep going,
694
	 * but set a flag so we don't chdir after the post-order visit.
695
	 * We won't be able to stat anything, but we can still return the
696
	 * names themselves.  Note, that since fts_read won't be able to
697
	 * chdir into the directory, it will have to return different path
698
	 * names than before, i.e. "a/b" instead of "b".  Since the node
699
	 * has already been visited in pre-order, have to wait until the
700
	 * post-order visit to return the error.  There is a special case
701
	 * here, if there was nothing to stat then it's not an error to
702
	 * not be able to stat.  This is all fairly nasty.  If a program
703
	 * needed sorted entries or stat information, they had better be
704
	 * checking FTS_NS on the returned nodes.
705
	 */
706
	cderrno = 0;
707
	if (nlinks || type == BREAD) {
708
		if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) {
709
			if (nlinks && type == BREAD)
710
				cur->fts_errno = errno;
711
			cur->fts_flags |= FTS_DONTCHDIR;
712
			descend = 0;
713
			cderrno = errno;
714
		} else
715
			descend = 1;
716
	} else
717
		descend = 0;
718
719
	/*
720
	 * Figure out the max file name length that can be stored in the
721
	 * current path -- the inner loop allocates more path as necessary.
722
	 * We really wouldn't have to do the maxlen calculations here, we
723
	 * could do them in fts_read before returning the path, but it's a
724
	 * lot easier here since the length is part of the dirent structure.
725
	 *
726
	 * If not changing directories set a pointer so that can just append
727
	 * each new name into the path.
728
	 */
729
	len = NAPPEND(cur);
730
	if (ISSET(FTS_NOCHDIR)) {
731
		cp = sp->fts_path + len;
732
		*cp++ = '/';
733
	} else {
734
		/* GCC, you're too verbose. */
735
		cp = NULL;
736
	}
737
	len++;
738
	maxlen = sp->fts_pathlen - len;
739
740
	level = cur->fts_level + 1;
741
742
	/* Read the directory, attaching each entry to the `link' pointer. */
743
	doadjust = 0;
744
	for (head = tail = NULL, nitems = 0;
745
	    dirp && (dp = freebsd11_readdir(dirp));) {
746
		dnamlen = dp->d_namlen;
747
		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
748
			continue;
749
750
		if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL)
751
			goto mem1;
752
		if (dnamlen >= maxlen) {	/* include space for NUL */
753
			oldaddr = sp->fts_path;
754
			if (fts_palloc(sp, dnamlen + len + 1)) {
755
				/*
756
				 * No more memory for path or structures.  Save
757
				 * errno, free up the current structure and the
758
				 * structures already allocated.
759
				 */
760
mem1:				saved_errno = errno;
761
				if (p)
762
					free(p);
763
				fts_lfree(head);
764
				(void)closedir(dirp);
765
				cur->fts_info = FTS_ERR;
766
				SET(FTS_STOP);
767
				errno = saved_errno;
768
				return (NULL);
769
			}
770
			/* Did realloc() change the pointer? */
771
			if (oldaddr != sp->fts_path) {
772
				doadjust = 1;
773
				if (ISSET(FTS_NOCHDIR))
774
					cp = sp->fts_path + len;
775
			}
776
			maxlen = sp->fts_pathlen - len;
777
		}
778
779
		p->fts_level = level;
780
		p->fts_parent = sp->fts_cur;
781
		p->fts_pathlen = len + dnamlen;
782
783
#ifdef FTS_WHITEOUT
784
		if (dp->d_type == DT_WHT)
785
			p->fts_flags |= FTS_ISW;
786
#endif
787
788
		if (cderrno) {
789
			if (nlinks) {
790
				p->fts_info = FTS_NS;
791
				p->fts_errno = cderrno;
792
			} else
793
				p->fts_info = FTS_NSOK;
794
			p->fts_accpath = cur->fts_accpath;
795
		} else if (nlinks == 0
796
#ifdef DT_DIR
797
		    || (nostat &&
798
		    dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
799
#endif
800
		    ) {
801
			p->fts_accpath =
802
			    ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
803
			p->fts_info = FTS_NSOK;
804
		} else {
805
			/* Build a file name for fts_stat to stat. */
806
			if (ISSET(FTS_NOCHDIR)) {
807
				p->fts_accpath = p->fts_path;
808
				memmove(cp, p->fts_name, p->fts_namelen + 1);
809
				p->fts_info = fts_stat(sp, p, 0, _dirfd(dirp));
810
			} else {
811
				p->fts_accpath = p->fts_name;
812
				p->fts_info = fts_stat(sp, p, 0, -1);
813
			}
814
815
			/* Decrement link count if applicable. */
816
			if (nlinks > 0 && (p->fts_info == FTS_D ||
817
			    p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
818
				--nlinks;
819
		}
820
821
		/* We walk in directory order so "ls -f" doesn't get upset. */
822
		p->fts_link = NULL;
823
		if (head == NULL)
824
			head = tail = p;
825
		else {
826
			tail->fts_link = p;
827
			tail = p;
828
		}
829
		++nitems;
830
	}
831
	if (dirp)
832
		(void)closedir(dirp);
833
834
	/*
835
	 * If realloc() changed the address of the path, adjust the
836
	 * addresses for the rest of the tree and the dir list.
837
	 */
838
	if (doadjust)
839
		fts_padjust(sp, head);
840
841
	/*
842
	 * If not changing directories, reset the path back to original
843
	 * state.
844
	 */
845
	if (ISSET(FTS_NOCHDIR))
846
		sp->fts_path[cur->fts_pathlen] = '\0';
847
848
	/*
849
	 * If descended after called from fts_children or after called from
850
	 * fts_read and nothing found, get back.  At the root level we use
851
	 * the saved fd; if one of fts_open()'s arguments is a relative path
852
	 * to an empty directory, we wind up here with no other way back.  If
853
	 * can't get back, we're done.
854
	 */
855
	if (descend && (type == BCHILD || !nitems) &&
856
	    (cur->fts_level == FTS_ROOTLEVEL ?
857
	    FCHDIR(sp, sp->fts_rfd) :
858
	    fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
859
		fts_lfree(head);
860
		cur->fts_info = FTS_ERR;
861
		SET(FTS_STOP);
862
		return (NULL);
863
	}
864
865
	/* If didn't find anything, return NULL. */
866
	if (!nitems) {
867
		if (type == BREAD)
868
			cur->fts_info = FTS_DP;
869
		return (NULL);
870
	}
871
872
	/* Sort the entries. */
873
	if (sp->fts_compar && nitems > 1)
874
		head = fts_sort(sp, head, nitems);
875
	return (head);
876
}
877
878
static int
879
fts_stat(FTS11 *sp, FTSENT11 *p, int follow, int dfd)
880
{
881
	FTSENT11 *t;
882
	uint32_t dev;
883
	uint32_t ino;
884
	struct freebsd11_stat *sbp, sb;
885
	int saved_errno;
886
	const char *path;
887
888
	if (dfd == -1)
889
		path = p->fts_accpath, dfd = AT_FDCWD;
890
	else
891
		path = p->fts_name;
892
893
	/* If user needs stat info, stat buffer already allocated. */
894
	sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
895
896
#ifdef FTS_WHITEOUT
897
	/* Check for whiteout. */
898
	if (p->fts_flags & FTS_ISW) {
899
		if (sbp != &sb) {
900
			memset(sbp, '\0', sizeof(*sbp));
901
			sbp->st_mode = S_IFWHT;
902
		}
903
		return (FTS_W);
904
	}
905
#endif
906
907
	/*
908
	 * If doing a logical walk, or application requested FTS_FOLLOW, do
909
	 * a stat(2).  If that fails, check for a non-existent symlink.  If
910
	 * fail, set the errno from the stat call.
911
	 */
912
	if (ISSET(FTS_LOGICAL) || follow) {
913
		if (freebsd11_fstatat(dfd, path, sbp, 0)) {
914
			saved_errno = errno;
915
			if (freebsd11_fstatat(dfd, path, sbp,
916
			    AT_SYMLINK_NOFOLLOW)) {
917
				p->fts_errno = saved_errno;
918
				goto err;
919
			}
920
			errno = 0;
921
			if (S_ISLNK(sbp->st_mode))
922
				return (FTS_SLNONE);
923
		}
924
	} else if (freebsd11_fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
925
		p->fts_errno = errno;
926
err:		memset(sbp, 0, sizeof(*sbp));
927
		return (FTS_NS);
928
	}
929
930
	if (S_ISDIR(sbp->st_mode)) {
931
		/*
932
		 * Set the device/inode.  Used to find cycles and check for
933
		 * crossing mount points.  Also remember the link count, used
934
		 * in fts_build to limit the number of stat calls.  It is
935
		 * understood that these fields are only referenced if fts_info
936
		 * is set to FTS_D.
937
		 */
938
		dev = p->fts_dev = sbp->st_dev;
939
		ino = p->fts_ino = sbp->st_ino;
940
		p->fts_nlink = sbp->st_nlink;
941
942
		if (ISDOT(p->fts_name))
943
			return (FTS_DOT);
944
945
		/*
946
		 * Cycle detection is done by brute force when the directory
947
		 * is first encountered.  If the tree gets deep enough or the
948
		 * number of symbolic links to directories is high enough,
949
		 * something faster might be worthwhile.
950
		 */
951
		for (t = p->fts_parent;
952
		    t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
953
			if (ino == t->fts_ino && dev == t->fts_dev) {
954
				p->fts_cycle = t;
955
				return (FTS_DC);
956
			}
957
		return (FTS_D);
958
	}
959
	if (S_ISLNK(sbp->st_mode))
960
		return (FTS_SL);
961
	if (S_ISREG(sbp->st_mode))
962
		return (FTS_F);
963
	return (FTS_DEFAULT);
964
}
965
966
/*
967
 * The comparison function takes pointers to pointers to FTSENT structures.
968
 * Qsort wants a comparison function that takes pointers to void.
969
 * (Both with appropriate levels of const-poisoning, of course!)
970
 * Use a trampoline function to deal with the difference.
971
 */
972
static int
973
fts_compar(const void *a, const void *b)
974
{
975
	FTS11 *parent;
976
977
	parent = (*(const FTSENT11 * const *)a)->fts_fts;
978
	return (*parent->fts_compar)(a, b);
979
}
980
981
static FTSENT11 *
982
fts_sort(FTS11 *sp, FTSENT11 *head, size_t nitems)
983
{
984
	FTSENT11 **ap, *p;
985
986
	/*
987
	 * Construct an array of pointers to the structures and call qsort(3).
988
	 * Reassemble the array in the order returned by qsort.  If unable to
989
	 * sort for memory reasons, return the directory entries in their
990
	 * current order.  Allocate enough space for the current needs plus
991
	 * 40 so don't realloc one entry at a time.
992
	 */
993
	if (nitems > sp->fts_nitems) {
994
		sp->fts_nitems = nitems + 40;
995
		if ((sp->fts_array = reallocf(sp->fts_array,
996
		    sp->fts_nitems * sizeof(FTSENT11 *))) == NULL) {
997
			sp->fts_nitems = 0;
998
			return (head);
999
		}
1000
	}
1001
	for (ap = sp->fts_array, p = head; p; p = p->fts_link)
1002
		*ap++ = p;
1003
	qsort(sp->fts_array, nitems, sizeof(FTSENT11 *), fts_compar);
1004
	for (head = *(ap = sp->fts_array); --nitems; ++ap)
1005
		ap[0]->fts_link = ap[1];
1006
	ap[0]->fts_link = NULL;
1007
	return (head);
1008
}
1009
1010
static FTSENT11 *
1011
fts_alloc(FTS11 *sp, char *name, size_t namelen)
1012
{
1013
	FTSENT11 *p;
1014
	size_t len;
1015
1016
	struct ftsent11_withstat {
1017
		FTSENT11	ent;
1018
		struct	freebsd11_stat statbuf;
1019
	};
1020
1021
	/*
1022
	 * The file name is a variable length array and no stat structure is
1023
	 * necessary if the user has set the nostat bit.  Allocate the FTSENT
1024
	 * structure, the file name and the stat structure in one chunk, but
1025
	 * be careful that the stat structure is reasonably aligned.
1026
	 */
1027
	if (ISSET(FTS_NOSTAT))
1028
		len = sizeof(FTSENT11) + namelen + 1;
1029
	else
1030
		len = sizeof(struct ftsent11_withstat) + namelen + 1;
1031
1032
	if ((p = malloc(len)) == NULL)
1033
		return (NULL);
1034
1035
	if (ISSET(FTS_NOSTAT)) {
1036
		p->fts_name = (char *)(p + 1);
1037
		p->fts_statp = NULL;
1038
	} else {
1039
		p->fts_name = (char *)((struct ftsent11_withstat *)p + 1);
1040
		p->fts_statp = &((struct ftsent11_withstat *)p)->statbuf;
1041
	}
1042
1043
	/* Copy the name and guarantee NUL termination. */
1044
	memcpy(p->fts_name, name, namelen);
1045
	p->fts_name[namelen] = '\0';
1046
	p->fts_namelen = namelen;
1047
	p->fts_path = sp->fts_path;
1048
	p->fts_errno = 0;
1049
	p->fts_flags = 0;
1050
	p->fts_instr = FTS_NOINSTR;
1051
	p->fts_number = 0;
1052
	p->fts_pointer = NULL;
1053
	p->fts_fts = sp;
1054
	return (p);
1055
}
1056
1057
static void
1058
fts_lfree(FTSENT11 *head)
1059
{
1060
	FTSENT11 *p;
1061
1062
	/* Free a linked list of structures. */
1063
	while ((p = head)) {
1064
		head = head->fts_link;
1065
		free(p);
1066
	}
1067
}
1068
1069
/*
1070
 * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
1071
 * Most systems will allow creation of paths much longer than MAXPATHLEN, even
1072
 * though the kernel won't resolve them.  Add the size (not just what's needed)
1073
 * plus 256 bytes so don't realloc the path 2 bytes at a time.
1074
 */
1075
static int
1076
fts_palloc(FTS11 *sp, size_t more)
1077
{
1078
1079
	sp->fts_pathlen += more + 256;
1080
	sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen);
1081
	return (sp->fts_path == NULL);
1082
}
1083
1084
/*
1085
 * When the path is realloc'd, have to fix all of the pointers in structures
1086
 * already returned.
1087
 */
1088
static void
1089
fts_padjust(FTS11 *sp, FTSENT11 *head)
1090
{
1091
	FTSENT11 *p;
1092
	char *addr = sp->fts_path;
1093
1094
#define	ADJUST(p) do {							\
1095
	if ((p)->fts_accpath != (p)->fts_name) {			\
1096
		(p)->fts_accpath =					\
1097
		    (char *)addr + ((p)->fts_accpath - (p)->fts_path);	\
1098
	}								\
1099
	(p)->fts_path = addr;						\
1100
} while (0)
1101
	/* Adjust the current set of children. */
1102
	for (p = sp->fts_child; p; p = p->fts_link)
1103
		ADJUST(p);
1104
1105
	/* Adjust the rest of the tree, including the current level. */
1106
	for (p = head; p->fts_level >= FTS_ROOTLEVEL;) {
1107
		ADJUST(p);
1108
		p = p->fts_link ? p->fts_link : p->fts_parent;
1109
	}
1110
}
1111
1112
static size_t
1113
fts_maxarglen(char * const *argv)
1114
{
1115
	size_t len, max;
1116
1117
	for (max = 0; *argv; ++argv)
1118
		if ((len = strlen(*argv)) > max)
1119
			max = len;
1120
	return (max + 1);
1121
}
1122
1123
/*
1124
 * Change to dir specified by fd or p->fts_accpath without getting
1125
 * tricked by someone changing the world out from underneath us.
1126
 * Assumes p->fts_dev and p->fts_ino are filled in.
1127
 */
1128
static int
1129
fts_safe_changedir(FTS11 *sp, FTSENT11 *p, int fd, char *path)
1130
{
1131
	int ret, oerrno, newfd;
1132
	struct freebsd11_stat sb;
1133
1134
	newfd = fd;
1135
	if (ISSET(FTS_NOCHDIR))
1136
		return (0);
1137
	if (fd < 0 && (newfd = _open(path, O_RDONLY | O_DIRECTORY |
1138
	    O_CLOEXEC, 0)) < 0)
1139
		return (-1);
1140
	if (freebsd11_fstat(newfd, &sb)) {
1141
		ret = -1;
1142
		goto bail;
1143
	}
1144
	if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
1145
		errno = ENOENT;		/* disinformation */
1146
		ret = -1;
1147
		goto bail;
1148
	}
1149
	ret = fchdir(newfd);
1150
bail:
1151
	oerrno = errno;
1152
	if (fd < 0)
1153
		(void)_close(newfd);
1154
	errno = oerrno;
1155
	return (ret);
1156
}
1157
1158
/*
1159
 * Check if the filesystem for "ent" has UFS-style links.
1160
 */
1161
static int
1162
fts_ufslinks(FTS11 *sp, const FTSENT11 *ent)
1163
{
1164
	struct _fts_private11 *priv;
1165
	const char **cpp;
1166
1167
	priv = (struct _fts_private11 *)sp;
1168
	/*
1169
	 * If this node's device is different from the previous, grab
1170
	 * the filesystem information, and decide on the reliability
1171
	 * of the link information from this filesystem for stat(2)
1172
	 * avoidance.
1173
	 */
1174
	if (priv->ftsp_dev != ent->fts_dev) {
1175
		if (freebsd11_statfs(ent->fts_path, &priv->ftsp_statfs) != -1) {
1176
			priv->ftsp_dev = ent->fts_dev;
1177
			priv->ftsp_linksreliable = 0;
1178
			for (cpp = ufslike_filesystems; *cpp; cpp++) {
1179
				if (strcmp(priv->ftsp_statfs.f_fstypename,
1180
				    *cpp) == 0) {
1181
					priv->ftsp_linksreliable = 1;
1182
					break;
1183
				}
1184
			}
1185
		} else {
1186
			priv->ftsp_linksreliable = 0;
1187
		}
1188
	}
1189
	return (priv->ftsp_linksreliable);
1190
}
1191
1192
__sym_compat(fts_open, freebsd11_fts_open, FBSD_1.1);
1193
__sym_compat(fts_close, freebsd11_fts_close, FBSD_1.1);
1194
__sym_compat(fts_read, freebsd11_fts_read, FBSD_1.1);
1195
__sym_compat(fts_set, freebsd11_fts_set, FBSD_1.1);
1196
__sym_compat(fts_children, freebsd11_fts_children, FBSD_1.1);
1197
__sym_compat(fts_get_clientptr, freebsd11_fts_get_clientptr, FBSD_1.1);
1198
__sym_compat(fts_get_stream, freebsd11_fts_get_stream, FBSD_1.1);
1199
__sym_compat(fts_set_clientptr, freebsd11_fts_set_clientptr, FBSD_1.1);
(-)b/lib/libc/gen/fts-compat11.h (+95 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1989, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 *	@(#)fts.h	8.3 (Berkeley) 8/14/94
30
 * $FreeBSD$
31
 */
32
33
#ifndef	_FTS_COPMAT11_H_
34
#define	_FTS_COPMAT11_H_
35
36
typedef struct {
37
	struct _ftsent11 *fts_cur;	/* current node */
38
	struct _ftsent11 *fts_child;	/* linked list of children */
39
	struct _ftsent11 **fts_array;	/* sort array */
40
	uint32_t fts_dev;		/* starting device # */
41
	char *fts_path;			/* path for this descent */
42
	int fts_rfd;			/* fd for root */
43
	__size_t fts_pathlen;		/* sizeof(path) */
44
	__size_t fts_nitems;		/* elements in the sort array */
45
	int (*fts_compar)		/* compare function */
46
	    (const struct _ftsent11 * const *,
47
	    const struct _ftsent11 * const *);
48
	int fts_options;		/* fts_open options, global flags */
49
	void *fts_clientptr;		/* thunk for sort function */
50
} FTS11;
51
52
typedef struct _ftsent11 {
53
	struct _ftsent11 *fts_cycle;	/* cycle node */
54
	struct _ftsent11 *fts_parent;	/* parent directory */
55
	struct _ftsent11 *fts_link;	/* next file in directory */
56
	long long fts_number;		/* local numeric value */
57
	void *fts_pointer;		/* local address value */
58
	char *fts_accpath;		/* access path */
59
	char *fts_path;			/* root path */
60
	int fts_errno;			/* errno for this node */
61
	int fts_symfd;			/* fd for symlink */
62
	__size_t fts_pathlen;		/* strlen(fts_path) */
63
	__size_t fts_namelen;		/* strlen(fts_name) */
64
65
	uint32_t fts_ino;		/* inode */
66
	uint32_t fts_dev;		/* device */
67
	uint16_t fts_nlink;		/* link count */
68
69
	long fts_level;			/* depth (-1 to N) */
70
71
	int fts_info;			/* user status for FTSENT structure */
72
73
	unsigned fts_flags;		/* private flags for FTSENT structure */
74
75
	int fts_instr;			/* fts_set() instructions */
76
77
	struct freebsd11_stat *fts_statp; /* stat(2) information */
78
	char *fts_name;			/* file name */
79
	FTS11 *fts_fts;			/* back pointer to main FTS */
80
} FTSENT11;
81
82
FTSENT11	*freebsd11_fts_children(FTS11 *, int);
83
int		 freebsd11_fts_close(FTS11 *);
84
void		*freebsd11_fts_get_clientptr(FTS11 *);
85
#define	freebsd11_fts_get_clientptr(fts)	((fts)->fts_clientptr)
86
FTS11		*freebsd11_fts_get_stream(FTSENT11 *);
87
#define	freebsd11_fts_get_stream(ftsent)	((ftsent)->fts_fts)
88
FTS11		*freebsd11_fts_open(char * const *, int,
89
		    int (*)(const FTSENT11 * const *,
90
		    const FTSENT11 * const *));
91
FTSENT11	*freebsd11_fts_read(FTS11 *);
92
int		 freebsd11_fts_set(FTS11 *, FTSENT11 *, int);
93
void		 freebsd11_fts_set_clientptr(FTS11 *, void *);
94
95
#endif /* !_FTS_COMPAT11_H_ */
(-)b/lib/libc/gen/ftw-compat11.c (+98 lines)
Added Link Here
1
/*	$OpenBSD: ftw.c,v 1.5 2005/08/08 08:05:34 espie Exp $	*/
2
3
/*
4
 * Copyright (c) 2003, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 *
18
 * Sponsored in part by the Defense Advanced Research Projects
19
 * Agency (DARPA) and Air Force Research Laboratory, Air Force
20
 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21
 *
22
 * from: $FreeBSD$
23
 */
24
25
#include <sys/cdefs.h>
26
__FBSDID("$FreeBSD$");
27
28
#include <sys/types.h>
29
#include <sys/stat.h>
30
#include <errno.h>
31
#include <fts.h>
32
#include <ftw.h>
33
34
#include "fts-compat11.h"
35
36
int
37
freebsd11_ftw(const char *path,
38
    int (*fn)(const char *, const struct freebsd11_stat *, int), int nfds)
39
{
40
	char * const paths[2] = { (char *)path, NULL };
41
	FTSENT11 *cur;
42
	FTS11 *ftsp;
43
	int error = 0, fnflag, sverrno;
44
45
	/* XXX - nfds is currently unused */
46
	if (nfds < 1) {
47
		errno = EINVAL;
48
		return (-1);
49
	}
50
51
	ftsp = freebsd11_fts_open(paths,
52
	    FTS_LOGICAL | FTS_COMFOLLOW | FTS_NOCHDIR, NULL);
53
	if (ftsp == NULL)
54
		return (-1);
55
	while ((cur = freebsd11_fts_read(ftsp)) != NULL) {
56
		switch (cur->fts_info) {
57
		case FTS_D:
58
			fnflag = FTW_D;
59
			break;
60
		case FTS_DNR:
61
			fnflag = FTW_DNR;
62
			break;
63
		case FTS_DP:
64
			/* we only visit in preorder */
65
			continue;
66
		case FTS_F:
67
		case FTS_DEFAULT:
68
			fnflag = FTW_F;
69
			break;
70
		case FTS_NS:
71
		case FTS_NSOK:
72
		case FTS_SLNONE:
73
			fnflag = FTW_NS;
74
			break;
75
		case FTS_SL:
76
			fnflag = FTW_SL;
77
			break;
78
		case FTS_DC:
79
			errno = ELOOP;
80
			/* FALLTHROUGH */
81
		default:
82
			error = -1;
83
			goto done;
84
		}
85
		error = fn(cur->fts_path, cur->fts_statp, fnflag);
86
		if (error != 0)
87
			break;
88
	}
89
done:
90
	sverrno = errno;
91
	if (freebsd11_fts_close(ftsp) != 0 && error == 0)
92
		error = -1;
93
	else
94
		errno = sverrno;
95
	return (error);
96
}
97
98
__sym_compat(ftw, freebsd11_ftw, FBSD_1.0);
(-)b/lib/libc/gen/gen-compat.h (+57 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 *
26
 * $FreeBSD$
27
 */
28
29
#ifndef	_GEN_COMPAT_H_
30
#define	_GEN_COMPAT_H_
31
32
#include <dirent.h>
33
34
#define FREEBSD11_DIRSIZ(dp)						\
35
	(sizeof(struct freebsd11_dirent) - sizeof((dp)->d_name) +	\
36
	    (((dp)->d_namlen + 1 + 3) &~ 3))
37
38
struct freebsd11_dirent;
39
struct freebsd11_stat;
40
struct freebsd11_statfs;
41
42
struct freebsd11_dirent *freebsd11_readdir(DIR *);
43
int	freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
44
	    struct freebsd11_dirent **);
45
int	freebsd11_stat(const char *, struct freebsd11_stat *);
46
int	freebsd11_lstat(const char *, struct freebsd11_stat *);
47
int	freebsd11_fstat(int, struct freebsd11_stat *);
48
int	freebsd11_fstatat(int, const char *, struct freebsd11_stat *, int);
49
50
int	freebsd11_statfs(const char *, struct freebsd11_statfs *);
51
int	freebsd11_getfsstat(struct freebsd11_statfs *, long, int);
52
int	freebsd11_getmntinfo(struct freebsd11_statfs **, int);
53
54
char	*freebsd11_devname(__uint32_t dev, __mode_t type);
55
char	*freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf, int len);
56
57
#endif /* _GEN_COMPAT_H_ */
(-)b/lib/libc/gen/gen-private.h (-1 / +5 lines)
Lines 47-58 struct _dirdesc { Link Here
47
	long	dd_size;	/* amount of data returned by getdirentries */
47
	long	dd_size;	/* amount of data returned by getdirentries */
48
	char	*dd_buf;	/* data buffer */
48
	char	*dd_buf;	/* data buffer */
49
	int	dd_len;		/* size of data buffer */
49
	int	dd_len;		/* size of data buffer */
50
	long	dd_seek;	/* magic cookie returned by getdirentries */
50
	off_t	dd_seek;	/* magic cookie returned by getdirentries */
51
	int	dd_flags;	/* flags for readdir */
51
	int	dd_flags;	/* flags for readdir */
52
	struct pthread_mutex	*dd_lock;	/* lock */
52
	struct pthread_mutex	*dd_lock;	/* lock */
53
	struct _telldir *dd_td;	/* telldir position recording */
53
	struct _telldir *dd_td;	/* telldir position recording */
54
	void	*dd_compat_de;	/* compat dirent */
54
};
55
};
55
56
56
#define	_dirfd(dirp)	((dirp)->dd_fd)
57
#define	_dirfd(dirp)	((dirp)->dd_fd)
57
58
59
struct dirent;
60
int __readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
61
58
#endif /* !_GEN_PRIVATE_H_ */
62
#endif /* !_GEN_PRIVATE_H_ */
(-)b/lib/libc/gen/getmntinfo-compat11.c (+72 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1989, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
30
#if defined(LIBC_SCCS) && !defined(lint)
31
static char sccsid[] = "@(#)getmntinfo.c	8.1 (Berkeley) 6/4/93";
32
#endif /* LIBC_SCCS and not lint */
33
#include <sys/cdefs.h>
34
__FBSDID("$FreeBSD$");
35
36
#include <sys/param.h>
37
#include <sys/ucred.h>
38
#define	_WANT_FREEBSD11_STATFS
39
#include <sys/mount.h>
40
#include <stdlib.h>
41
#include "gen-compat.h"
42
43
/*
44
 * Return information about mounted filesystems.
45
 */
46
int
47
freebsd11_getmntinfo(struct freebsd11_statfs **mntbufp, int flags)
48
{
49
	static struct freebsd11_statfs *mntbuf;
50
	static int mntsize;
51
	static long bufsize;
52
53
	if (mntsize <= 0 &&
54
	    (mntsize = freebsd11_getfsstat(0, 0, MNT_NOWAIT)) < 0)
55
		return (0);
56
	if (bufsize > 0 &&
57
	    (mntsize = freebsd11_getfsstat(mntbuf, bufsize, flags)) < 0)
58
		return (0);
59
	while (bufsize <= mntsize * sizeof(struct freebsd11_statfs)) {
60
		if (mntbuf)
61
			free(mntbuf);
62
		bufsize = (mntsize + 1) * sizeof(struct freebsd11_statfs);
63
		if ((mntbuf = (struct freebsd11_statfs *)malloc(bufsize)) == 0)
64
			return (0);
65
		if ((mntsize = freebsd11_getfsstat(mntbuf, bufsize, flags)) < 0)
66
			return (0);
67
	}
68
	*mntbufp = mntbuf;
69
	return (mntsize);
70
}
71
72
__sym_compat(getmntinfo, freebsd11_getmntinfo, FBSD_1.0);
(-)b/lib/libc/gen/glob-compat11.c (+1093 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1989, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * This code is derived from software contributed to Berkeley by
6
 * Guido van Rossum.
7
 *
8
 * Copyright (c) 2011 The FreeBSD Foundation
9
 * All rights reserved.
10
 * Portions of this software were developed by David Chisnall
11
 * under sponsorship from the FreeBSD Foundation.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions
15
 * are met:
16
 * 1. Redistributions of source code must retain the above copyright
17
 *    notice, this list of conditions and the following disclaimer.
18
 * 2. Redistributions in binary form must reproduce the above copyright
19
 *    notice, this list of conditions and the following disclaimer in the
20
 *    documentation and/or other materials provided with the distribution.
21
 * 3. Neither the name of the University nor the names of its contributors
22
 *    may be used to endorse or promote products derived from this software
23
 *    without specific prior written permission.
24
 *
25
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35
 * SUCH DAMAGE.
36
 *
37
 * from: $FreeBSD$
38
 */
39
40
#if defined(LIBC_SCCS) && !defined(lint)
41
static char sccsid[] = "@(#)glob.c	8.3 (Berkeley) 10/13/93";
42
#endif /* LIBC_SCCS and not lint */
43
#include <sys/cdefs.h>
44
__FBSDID("$FreeBSD$");
45
46
#include <sys/param.h>
47
#define	_WANT_FREEBSD11_STAT
48
#include <sys/stat.h>
49
50
#include <ctype.h>
51
#define	_WANT_FREEBSD11_DIRENT
52
#include <dirent.h>
53
#include <errno.h>
54
#include <glob.h>
55
#include <limits.h>
56
#include <pwd.h>
57
#include <stdint.h>
58
#include <stdio.h>
59
#include <stdlib.h>
60
#include <string.h>
61
#include <unistd.h>
62
#include <wchar.h>
63
64
#include "collate.h"
65
#include "gen-compat.h"
66
#include "glob-compat11.h"
67
68
/*
69
 * glob(3) expansion limits. Stop the expansion if any of these limits
70
 * is reached. This caps the runtime in the face of DoS attacks. See
71
 * also CVE-2010-2632
72
 */
73
#define	GLOB_LIMIT_BRACE	128	/* number of brace calls */
74
#define	GLOB_LIMIT_PATH		65536	/* number of path elements */
75
#define	GLOB_LIMIT_READDIR	16384	/* number of readdirs */
76
#define	GLOB_LIMIT_STAT		1024	/* number of stat system calls */
77
#define	GLOB_LIMIT_STRING	ARG_MAX	/* maximum total size for paths */
78
79
struct glob_limit {
80
	size_t	l_brace_cnt;
81
	size_t	l_path_lim;
82
	size_t	l_readdir_cnt;	
83
	size_t	l_stat_cnt;	
84
	size_t	l_string_cnt;
85
};
86
87
#define	DOT		L'.'
88
#define	EOS		L'\0'
89
#define	LBRACKET	L'['
90
#define	NOT		L'!'
91
#define	QUESTION	L'?'
92
#define	QUOTE		L'\\'
93
#define	RANGE		L'-'
94
#define	RBRACKET	L']'
95
#define	SEP		L'/'
96
#define	STAR		L'*'
97
#define	TILDE		L'~'
98
#define	LBRACE		L'{'
99
#define	RBRACE		L'}'
100
#define	COMMA		L','
101
102
#define	M_QUOTE		0x8000000000ULL
103
#define	M_PROTECT	0x4000000000ULL
104
#define	M_MASK		0xffffffffffULL
105
#define	M_CHAR		0x00ffffffffULL
106
107
typedef uint_fast64_t Char;
108
109
#define	CHAR(c)		((Char)((c)&M_CHAR))
110
#define	META(c)		((Char)((c)|M_QUOTE))
111
#define	UNPROT(c)	((c) & ~M_PROTECT)
112
#define	M_ALL		META(L'*')
113
#define	M_END		META(L']')
114
#define	M_NOT		META(L'!')
115
#define	M_ONE		META(L'?')
116
#define	M_RNG		META(L'-')
117
#define	M_SET		META(L'[')
118
#define	ismeta(c)	(((c)&M_QUOTE) != 0)
119
#ifdef DEBUG
120
#define	isprot(c)	(((c)&M_PROTECT) != 0)
121
#endif
122
123
static int	 compare(const void *, const void *);
124
static int	 g_Ctoc(const Char *, char *, size_t);
125
static int	 g_lstat(Char *, struct freebsd11_stat *, glob11_t *);
126
static DIR	*g_opendir(Char *, glob11_t *);
127
static const Char *g_strchr(const Char *, wchar_t);
128
#ifdef notdef
129
static Char	*g_strcat(Char *, const Char *);
130
#endif
131
static int	 g_stat(Char *, struct freebsd11_stat *, glob11_t *);
132
static int	 glob0(const Char *, glob11_t *, struct glob_limit *,
133
    const char *);
134
static int	 glob1(Char *, glob11_t *, struct glob_limit *);
135
static int	 glob2(Char *, Char *, Char *, Char *, glob11_t *,
136
    struct glob_limit *);
137
static int	 glob3(Char *, Char *, Char *, Char *, Char *, glob11_t *,
138
    struct glob_limit *);
139
static int	 globextend(const Char *, glob11_t *, struct glob_limit *,
140
    const char *);
141
static const Char *
142
		 globtilde(const Char *, Char *, size_t, glob11_t *);
143
static int	 globexp0(const Char *, glob11_t *, struct glob_limit *,
144
    const char *);
145
static int	 globexp1(const Char *, glob11_t *, struct glob_limit *);
146
static int	 globexp2(const Char *, const Char *, glob11_t *,
147
    struct glob_limit *);
148
static int	 globfinal(glob11_t *, struct glob_limit *, size_t,
149
    const char *);
150
static int	 match(Char *, Char *, Char *);
151
static int	 err_nomatch(glob11_t *, struct glob_limit *, const char *);
152
static int	 err_aborted(glob11_t *, int, char *);
153
#ifdef DEBUG
154
static void	 qprintf(const char *, Char *);
155
#endif
156
157
int
158
freebsd11_glob(const char * __restrict pattern, int flags,
159
	 int (*errfunc)(const char *, int), glob11_t * __restrict pglob)
160
{
161
	struct glob_limit limit = { 0, 0, 0, 0, 0 };
162
	const char *patnext;
163
	Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
164
	mbstate_t mbs;
165
	wchar_t wc;
166
	size_t clen;
167
	int too_long;
168
169
	patnext = pattern;
170
	if (!(flags & GLOB_APPEND)) {
171
		pglob->gl_pathc = 0;
172
		pglob->gl_pathv = NULL;
173
		if (!(flags & GLOB_DOOFFS))
174
			pglob->gl_offs = 0;
175
	}
176
	if (flags & GLOB_LIMIT) {
177
		limit.l_path_lim = pglob->gl_matchc;
178
		if (limit.l_path_lim == 0)
179
			limit.l_path_lim = GLOB_LIMIT_PATH;
180
	}
181
	pglob->gl_flags = flags & ~GLOB_MAGCHAR;
182
	pglob->gl_errfunc = errfunc;
183
	pglob->gl_matchc = 0;
184
185
	bufnext = patbuf;
186
	bufend = bufnext + MAXPATHLEN - 1;
187
	too_long = 1;
188
	if (flags & GLOB_NOESCAPE) {
189
		memset(&mbs, 0, sizeof(mbs));
190
		while (bufnext <= bufend) {
191
			clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
192
			if (clen == (size_t)-1 || clen == (size_t)-2)
193
				return (err_nomatch(pglob, &limit, pattern));
194
			else if (clen == 0) {
195
				too_long = 0;
196
				break;
197
			}
198
			*bufnext++ = wc;
199
			patnext += clen;
200
		}
201
	} else {
202
		/* Protect the quoted characters. */
203
		memset(&mbs, 0, sizeof(mbs));
204
		while (bufnext <= bufend) {
205
			if (*patnext == '\\') {
206
				if (*++patnext == '\0') {
207
					*bufnext++ = QUOTE;
208
					continue;
209
				}
210
				prot = M_PROTECT;
211
			} else
212
				prot = 0;
213
			clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
214
			if (clen == (size_t)-1 || clen == (size_t)-2)
215
				return (err_nomatch(pglob, &limit, pattern));
216
			else if (clen == 0) {
217
				too_long = 0;
218
				break;
219
			}
220
			*bufnext++ = wc | prot;
221
			patnext += clen;
222
		}
223
	}
224
	if (too_long)
225
		return (err_nomatch(pglob, &limit, pattern));
226
	*bufnext = EOS;
227
228
	if (flags & GLOB_BRACE)
229
	    return (globexp0(patbuf, pglob, &limit, pattern));
230
	else
231
	    return (glob0(patbuf, pglob, &limit, pattern));
232
}
233
234
static int
235
globexp0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
236
    const char *origpat) {
237
	int rv;
238
	size_t oldpathc;
239
240
	/* Protect a single {}, for find(1), like csh */
241
	if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) {
242
		if ((pglob->gl_flags & GLOB_LIMIT) &&
243
		    limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
244
			errno = E2BIG;
245
			return (GLOB_NOSPACE);
246
		}
247
		return (glob0(pattern, pglob, limit, origpat));
248
	}
249
250
	oldpathc = pglob->gl_pathc;
251
252
	if ((rv = globexp1(pattern, pglob, limit)) != 0)
253
		return rv;
254
255
	return (globfinal(pglob, limit, oldpathc, origpat));
256
}
257
258
/*
259
 * Expand recursively a glob {} pattern. When there is no more expansion
260
 * invoke the standard globbing routine to glob the rest of the magic
261
 * characters
262
 */
263
static int
264
globexp1(const Char *pattern, glob11_t *pglob, struct glob_limit *limit)
265
{
266
	const Char* ptr;
267
268
	if ((ptr = g_strchr(pattern, LBRACE)) != NULL) {
269
		if ((pglob->gl_flags & GLOB_LIMIT) &&
270
		    limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
271
			errno = E2BIG;
272
			return (GLOB_NOSPACE);
273
		}
274
		return (globexp2(ptr, pattern, pglob, limit));
275
	}
276
277
	return (glob0(pattern, pglob, limit, NULL));
278
}
279
280
281
/*
282
 * Recursive brace globbing helper. Tries to expand a single brace.
283
 * If it succeeds then it invokes globexp1 with the new pattern.
284
 * If it fails then it tries to glob the rest of the pattern and returns.
285
 */
286
static int
287
globexp2(const Char *ptr, const Char *pattern, glob11_t *pglob,
288
    struct glob_limit *limit)
289
{
290
	int     i, rv;
291
	Char   *lm, *ls;
292
	const Char *pe, *pm, *pm1, *pl;
293
	Char    patbuf[MAXPATHLEN];
294
295
	/* copy part up to the brace */
296
	for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
297
		continue;
298
	*lm = EOS;
299
	ls = lm;
300
301
	/* Find the balanced brace */
302
	for (i = 0, pe = ++ptr; *pe != EOS; pe++)
303
		if (*pe == LBRACKET) {
304
			/* Ignore everything between [] */
305
			for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
306
				continue;
307
			if (*pe == EOS) {
308
				/*
309
				 * We could not find a matching RBRACKET.
310
				 * Ignore and just look for RBRACE
311
				 */
312
				pe = pm;
313
			}
314
		}
315
		else if (*pe == LBRACE)
316
			i++;
317
		else if (*pe == RBRACE) {
318
			if (i == 0)
319
				break;
320
			i--;
321
		}
322
323
	/* Non matching braces; just glob the pattern */
324
	if (i != 0 || *pe == EOS)
325
		return (glob0(pattern, pglob, limit, NULL));
326
327
	for (i = 0, pl = pm = ptr; pm <= pe; pm++)
328
		switch (*pm) {
329
		case LBRACKET:
330
			/* Ignore everything between [] */
331
			for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++)
332
				continue;
333
			if (*pm == EOS) {
334
				/*
335
				 * We could not find a matching RBRACKET.
336
				 * Ignore and just look for RBRACE
337
				 */
338
				pm = pm1;
339
			}
340
			break;
341
342
		case LBRACE:
343
			i++;
344
			break;
345
346
		case RBRACE:
347
			if (i) {
348
			    i--;
349
			    break;
350
			}
351
			/* FALLTHROUGH */
352
		case COMMA:
353
			if (i && *pm == COMMA)
354
				break;
355
			else {
356
				/* Append the current string */
357
				for (lm = ls; (pl < pm); *lm++ = *pl++)
358
					continue;
359
				/*
360
				 * Append the rest of the pattern after the
361
				 * closing brace
362
				 */
363
				for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
364
					continue;
365
366
				/* Expand the current pattern */
367
#ifdef DEBUG
368
				qprintf("globexp2:", patbuf);
369
#endif
370
				rv = globexp1(patbuf, pglob, limit);
371
				if (rv)
372
					return (rv);
373
374
				/* move after the comma, to the next string */
375
				pl = pm + 1;
376
			}
377
			break;
378
379
		default:
380
			break;
381
		}
382
	return (0);
383
}
384
385
386
387
/*
388
 * expand tilde from the passwd file.
389
 */
390
static const Char *
391
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob11_t *pglob)
392
{
393
	struct passwd *pwd;
394
	char *h, *sc;
395
	const Char *p;
396
	Char *b, *eb;
397
	wchar_t wc;
398
	wchar_t wbuf[MAXPATHLEN];
399
	wchar_t *wbufend, *dc;
400
	size_t clen;
401
	mbstate_t mbs;
402
	int too_long;
403
404
	if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
405
		return (pattern);
406
407
	/* 
408
	 * Copy up to the end of the string or / 
409
	 */
410
	eb = &patbuf[patbuf_len - 1];
411
	for (p = pattern + 1, b = patbuf;
412
	    b < eb && *p != EOS && UNPROT(*p) != SEP; *b++ = *p++)
413
		continue;
414
415
	if (*p != EOS && UNPROT(*p) != SEP)
416
		return (NULL);
417
418
	*b = EOS;
419
	h = NULL;
420
421
	if (patbuf[0] == EOS) {
422
		/*
423
		 * handle a plain ~ or ~/ by expanding $HOME first (iff
424
		 * we're not running setuid or setgid) and then trying
425
		 * the password file
426
		 */
427
		if (issetugid() != 0 ||
428
		    (h = getenv("HOME")) == NULL) {
429
			if (((h = getlogin()) != NULL &&
430
			     (pwd = getpwnam(h)) != NULL) ||
431
			    (pwd = getpwuid(getuid())) != NULL)
432
				h = pwd->pw_dir;
433
			else
434
				return (pattern);
435
		}
436
	}
437
	else {
438
		/*
439
		 * Expand a ~user
440
		 */
441
		if (g_Ctoc(patbuf, (char *)wbuf, sizeof(wbuf)))
442
			return (NULL);
443
		if ((pwd = getpwnam((char *)wbuf)) == NULL)
444
			return (pattern);
445
		else
446
			h = pwd->pw_dir;
447
	}
448
449
	/* Copy the home directory */
450
	dc = wbuf;
451
	sc = h;
452
	wbufend = wbuf + MAXPATHLEN - 1;
453
	too_long = 1;
454
	memset(&mbs, 0, sizeof(mbs));
455
	while (dc <= wbufend) {
456
		clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
457
		if (clen == (size_t)-1 || clen == (size_t)-2) {
458
			/* XXX See initial comment #2. */
459
			wc = (unsigned char)*sc;
460
			clen = 1;
461
			memset(&mbs, 0, sizeof(mbs));
462
		}
463
		if ((*dc++ = wc) == EOS) {
464
			too_long = 0;
465
			break;
466
		}
467
		sc += clen;
468
	}
469
	if (too_long)
470
		return (NULL);
471
472
	dc = wbuf;
473
	for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT)
474
		continue;
475
	if (*dc != EOS)
476
		return (NULL);
477
478
	/* Append the rest of the pattern */
479
	if (*p != EOS) {
480
		too_long = 1;
481
		while (b <= eb) {
482
			if ((*b++ = *p++) == EOS) {
483
				too_long = 0;
484
				break;
485
			}
486
		}
487
		if (too_long)
488
			return (NULL);
489
	} else
490
		*b = EOS;
491
492
	return (patbuf);
493
}
494
495
496
/*
497
 * The main glob() routine: compiles the pattern (optionally processing
498
 * quotes), calls glob1() to do the real pattern matching, and finally
499
 * sorts the list (unless unsorted operation is requested).  Returns 0
500
 * if things went well, nonzero if errors occurred.
501
 */
502
static int
503
glob0(const Char *pattern, glob11_t *pglob, struct glob_limit *limit,
504
    const char *origpat) {
505
	const Char *qpatnext;
506
	int err;
507
	size_t oldpathc;
508
	Char *bufnext, c, patbuf[MAXPATHLEN];
509
510
	qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
511
	if (qpatnext == NULL) {
512
		errno = E2BIG;
513
		return (GLOB_NOSPACE);
514
	}
515
	oldpathc = pglob->gl_pathc;
516
	bufnext = patbuf;
517
518
	/* We don't need to check for buffer overflow any more. */
519
	while ((c = *qpatnext++) != EOS) {
520
		switch (c) {
521
		case LBRACKET:
522
			c = *qpatnext;
523
			if (c == NOT)
524
				++qpatnext;
525
			if (*qpatnext == EOS ||
526
			    g_strchr(qpatnext+1, RBRACKET) == NULL) {
527
				*bufnext++ = LBRACKET;
528
				if (c == NOT)
529
					--qpatnext;
530
				break;
531
			}
532
			*bufnext++ = M_SET;
533
			if (c == NOT)
534
				*bufnext++ = M_NOT;
535
			c = *qpatnext++;
536
			do {
537
				*bufnext++ = CHAR(c);
538
				if (*qpatnext == RANGE &&
539
				    (c = qpatnext[1]) != RBRACKET) {
540
					*bufnext++ = M_RNG;
541
					*bufnext++ = CHAR(c);
542
					qpatnext += 2;
543
				}
544
			} while ((c = *qpatnext++) != RBRACKET);
545
			pglob->gl_flags |= GLOB_MAGCHAR;
546
			*bufnext++ = M_END;
547
			break;
548
		case QUESTION:
549
			pglob->gl_flags |= GLOB_MAGCHAR;
550
			*bufnext++ = M_ONE;
551
			break;
552
		case STAR:
553
			pglob->gl_flags |= GLOB_MAGCHAR;
554
			/* collapse adjacent stars to one,
555
			 * to avoid exponential behavior
556
			 */
557
			if (bufnext == patbuf || bufnext[-1] != M_ALL)
558
			    *bufnext++ = M_ALL;
559
			break;
560
		default:
561
			*bufnext++ = CHAR(c);
562
			break;
563
		}
564
	}
565
	*bufnext = EOS;
566
#ifdef DEBUG
567
	qprintf("glob0:", patbuf);
568
#endif
569
570
	if ((err = glob1(patbuf, pglob, limit)) != 0)
571
		return(err);
572
573
	if (origpat != NULL)
574
		return (globfinal(pglob, limit, oldpathc, origpat));
575
576
	return (0);
577
}
578
579
static int
580
globfinal(glob11_t *pglob, struct glob_limit *limit, size_t oldpathc,
581
    const char *origpat) {
582
	if (pglob->gl_pathc == oldpathc)
583
		return (err_nomatch(pglob, limit, origpat));
584
585
	if (!(pglob->gl_flags & GLOB_NOSORT))
586
		qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
587
		    pglob->gl_pathc - oldpathc, sizeof(char *), compare);
588
589
	return (0);
590
}
591
592
static int
593
compare(const void *p, const void *q)
594
{
595
	return (strcoll(*(char **)p, *(char **)q));
596
}
597
598
static int
599
glob1(Char *pattern, glob11_t *pglob, struct glob_limit *limit)
600
{
601
	Char pathbuf[MAXPATHLEN];
602
603
	/* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
604
	if (*pattern == EOS)
605
		return (0);
606
	return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
607
	    pattern, pglob, limit));
608
}
609
610
/*
611
 * The functions glob2 and glob3 are mutually recursive; there is one level
612
 * of recursion for each segment in the pattern that contains one or more
613
 * meta characters.
614
 */
615
static int
616
glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
617
      glob11_t *pglob, struct glob_limit *limit)
618
{
619
	struct freebsd11_stat sb;
620
	Char *p, *q;
621
	int anymeta;
622
623
	/*
624
	 * Loop over pattern segments until end of pattern or until
625
	 * segment with meta character found.
626
	 */
627
	for (anymeta = 0;;) {
628
		if (*pattern == EOS) {		/* End of pattern? */
629
			*pathend = EOS;
630
			if (g_lstat(pathbuf, &sb, pglob))
631
				return (0);
632
633
			if ((pglob->gl_flags & GLOB_LIMIT) &&
634
			    limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
635
				errno = E2BIG;
636
				return (GLOB_NOSPACE);
637
			}
638
			if ((pglob->gl_flags & GLOB_MARK) &&
639
			    UNPROT(pathend[-1]) != SEP &&
640
			    (S_ISDIR(sb.st_mode) ||
641
			    (S_ISLNK(sb.st_mode) &&
642
			    g_stat(pathbuf, &sb, pglob) == 0 &&
643
			    S_ISDIR(sb.st_mode)))) {
644
				if (pathend + 1 > pathend_last) {
645
					errno = E2BIG;
646
					return (GLOB_NOSPACE);
647
				}
648
				*pathend++ = SEP;
649
				*pathend = EOS;
650
			}
651
			++pglob->gl_matchc;
652
			return (globextend(pathbuf, pglob, limit, NULL));
653
		}
654
655
		/* Find end of next segment, copy tentatively to pathend. */
656
		q = pathend;
657
		p = pattern;
658
		while (*p != EOS && UNPROT(*p) != SEP) {
659
			if (ismeta(*p))
660
				anymeta = 1;
661
			if (q + 1 > pathend_last) {
662
				errno = E2BIG;
663
				return (GLOB_NOSPACE);
664
			}
665
			*q++ = *p++;
666
		}
667
668
		if (!anymeta) {		/* No expansion, do next segment. */
669
			pathend = q;
670
			pattern = p;
671
			while (UNPROT(*pattern) == SEP) {
672
				if (pathend + 1 > pathend_last) {
673
					errno = E2BIG;
674
					return (GLOB_NOSPACE);
675
				}
676
				*pathend++ = *pattern++;
677
			}
678
		} else			/* Need expansion, recurse. */
679
			return (glob3(pathbuf, pathend, pathend_last, pattern,
680
			    p, pglob, limit));
681
	}
682
	/* NOTREACHED */
683
}
684
685
static int
686
glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
687
      Char *pattern, Char *restpattern,
688
      glob11_t *pglob, struct glob_limit *limit)
689
{
690
	struct freebsd11_dirent *dp;
691
	DIR *dirp;
692
	int err, too_long, saverrno, saverrno2;
693
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
694
695
	struct freebsd11_dirent *(*readdirfunc)(DIR *);
696
697
	if (pathend > pathend_last) {
698
		errno = E2BIG;
699
		return (GLOB_NOSPACE);
700
	}
701
	*pathend = EOS;
702
	if (pglob->gl_errfunc != NULL &&
703
	    g_Ctoc(pathbuf, buf, sizeof(buf))) {
704
		errno = E2BIG;
705
		return (GLOB_NOSPACE);
706
	}
707
708
	saverrno = errno;
709
	errno = 0;
710
	if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
711
		if (errno == ENOENT || errno == ENOTDIR)
712
			return (0);
713
		err = err_aborted(pglob, errno, buf);
714
		if (errno == 0)
715
			errno = saverrno;
716
		return (err);
717
	}
718
719
	err = 0;
720
721
	/* pglob->gl_readdir takes a void *, fix this manually */
722
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
723
		readdirfunc =
724
		    (struct freebsd11_dirent *(*)(DIR *))pglob->gl_readdir;
725
	else
726
		readdirfunc = freebsd11_readdir;
727
728
	errno = 0;
729
	/* Search directory for matching names. */
730
	while ((dp = (*readdirfunc)(dirp)) != NULL) {
731
		char *sc;
732
		Char *dc;
733
		wchar_t wc;
734
		size_t clen;
735
		mbstate_t mbs;
736
737
		if ((pglob->gl_flags & GLOB_LIMIT) &&
738
		    limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) {
739
			errno = E2BIG;
740
			err = GLOB_NOSPACE;
741
			break;
742
		}
743
744
		/* Initial DOT must be matched literally. */
745
		if (dp->d_name[0] == '.' && UNPROT(*pattern) != DOT) {
746
			errno = 0;
747
			continue;
748
		}
749
		memset(&mbs, 0, sizeof(mbs));
750
		dc = pathend;
751
		sc = dp->d_name;
752
		too_long = 1;
753
		while (dc <= pathend_last) {
754
			clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
755
			if (clen == (size_t)-1 || clen == (size_t)-2) {
756
				/* XXX See initial comment #2. */
757
				wc = (unsigned char)*sc;
758
				clen = 1;
759
				memset(&mbs, 0, sizeof(mbs));
760
			}
761
			if ((*dc++ = wc) == EOS) {
762
				too_long = 0;
763
				break;
764
			}
765
			sc += clen;
766
		}
767
		if (too_long && (err = err_aborted(pglob, ENAMETOOLONG,
768
		    buf))) {
769
			errno = ENAMETOOLONG;
770
			break;
771
		}
772
		if (too_long || !match(pathend, pattern, restpattern)) {
773
			*pathend = EOS;
774
			errno = 0;
775
			continue;
776
		}
777
		if (errno == 0)
778
			errno = saverrno;
779
		err = glob2(pathbuf, --dc, pathend_last, restpattern,
780
		    pglob, limit);
781
		if (err)
782
			break;
783
		errno = 0;
784
	}
785
786
	saverrno2 = errno;
787
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
788
		(*pglob->gl_closedir)(dirp);
789
	else
790
		closedir(dirp);
791
	errno = saverrno2;
792
793
	if (err)
794
		return (err);
795
796
	if (dp == NULL && errno != 0 &&
797
	    (err = err_aborted(pglob, errno, buf)))
798
		return (err);
799
800
	if (errno == 0)
801
		errno = saverrno;
802
	return (0);
803
}
804
805
806
/*
807
 * Extend the gl_pathv member of a glob11_t structure to accommodate a new item,
808
 * add the new item, and update gl_pathc.
809
 *
810
 * This assumes the BSD realloc, which only copies the block when its size
811
 * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
812
 * behavior.
813
 *
814
 * Return 0 if new item added, error code if memory couldn't be allocated.
815
 *
816
 * Invariant of the glob11_t structure:
817
 *	Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
818
 *	gl_pathv points to (gl_offs + gl_pathc + 1) items.
819
 */
820
static int
821
globextend(const Char *path, glob11_t *pglob, struct glob_limit *limit,
822
    const char *origpat)
823
{
824
	char **pathv;
825
	size_t i, newn, len;
826
	char *copy;
827
	const Char *p;
828
829
	if ((pglob->gl_flags & GLOB_LIMIT) &&
830
	    pglob->gl_matchc > limit->l_path_lim) {
831
		errno = E2BIG;
832
		return (GLOB_NOSPACE);
833
	}
834
835
	newn = 2 + pglob->gl_pathc + pglob->gl_offs;
836
	/* reallocarray(NULL, newn, size) is equivalent to malloc(newn*size). */
837
	pathv = reallocarray(pglob->gl_pathv, newn, sizeof(*pathv));
838
	if (pathv == NULL)
839
		return (GLOB_NOSPACE);
840
841
	if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
842
		/* first time around -- clear initial gl_offs items */
843
		pathv += pglob->gl_offs;
844
		for (i = pglob->gl_offs + 1; --i > 0; )
845
			*--pathv = NULL;
846
	}
847
	pglob->gl_pathv = pathv;
848
849
	if (origpat != NULL)
850
		copy = strdup(origpat);
851
	else {
852
		for (p = path; *p++ != EOS;)
853
			continue;
854
		len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
855
		if ((copy = malloc(len)) != NULL) {
856
			if (g_Ctoc(path, copy, len)) {
857
				free(copy);
858
				errno = E2BIG;
859
				return (GLOB_NOSPACE);
860
			}
861
		}
862
	}
863
	if (copy != NULL) {
864
		limit->l_string_cnt += strlen(copy) + 1;
865
		if ((pglob->gl_flags & GLOB_LIMIT) &&
866
		    limit->l_string_cnt >= GLOB_LIMIT_STRING) {
867
			free(copy);
868
			errno = E2BIG;
869
			return (GLOB_NOSPACE);
870
		}
871
		pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
872
	}
873
	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
874
	return (copy == NULL ? GLOB_NOSPACE : 0);
875
}
876
877
/*
878
 * pattern matching function for filenames.
879
 */
880
static int
881
match(Char *name, Char *pat, Char *patend)
882
{
883
	int ok, negate_range;
884
	Char c, k, *nextp, *nextn;
885
	struct xlocale_collate *table =
886
		(struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
887
888
	nextn = NULL;
889
	nextp = NULL;
890
891
	while (1) {
892
		while (pat < patend) {
893
			c = *pat++;
894
			switch (c & M_MASK) {
895
			case M_ALL:
896
				if (pat == patend)
897
					return (1);
898
				if (*name == EOS)
899
					return (0);
900
				nextn = name + 1;
901
				nextp = pat - 1;
902
				break;
903
			case M_ONE:
904
				if (*name++ == EOS)
905
					goto fail;
906
				break;
907
			case M_SET:
908
				ok = 0;
909
				if ((k = *name++) == EOS)
910
					goto fail;
911
				negate_range = ((*pat & M_MASK) == M_NOT);
912
				if (negate_range != 0)
913
					++pat;
914
				while (((c = *pat++) & M_MASK) != M_END)
915
					if ((*pat & M_MASK) == M_RNG) {
916
						if (table->__collate_load_error ?
917
						    CHAR(c) <= CHAR(k) &&
918
						    CHAR(k) <= CHAR(pat[1]) :
919
						    __wcollate_range_cmp(CHAR(c),
920
						    CHAR(k)) <= 0 &&
921
						    __wcollate_range_cmp(CHAR(k),
922
						    CHAR(pat[1])) <= 0)
923
							ok = 1;
924
						pat += 2;
925
					} else if (c == k)
926
						ok = 1;
927
				if (ok == negate_range)
928
					goto fail;
929
				break;
930
			default:
931
				if (*name++ != c)
932
					goto fail;
933
				break;
934
			}
935
		}
936
		if (*name == EOS)
937
			return (1);
938
939
	fail:
940
		if (nextn == NULL)
941
			break;
942
		pat = nextp;
943
		name = nextn;
944
	}
945
	return (0);
946
}
947
948
/* Free allocated data belonging to a glob11_t structure. */
949
void
950
freebsd11_globfree(glob11_t *pglob)
951
{
952
	size_t i;
953
	char **pp;
954
955
	if (pglob->gl_pathv != NULL) {
956
		pp = pglob->gl_pathv + pglob->gl_offs;
957
		for (i = pglob->gl_pathc; i--; ++pp)
958
			if (*pp)
959
				free(*pp);
960
		free(pglob->gl_pathv);
961
		pglob->gl_pathv = NULL;
962
	}
963
}
964
965
static DIR *
966
g_opendir(Char *str, glob11_t *pglob)
967
{
968
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
969
970
	if (*str == EOS)
971
		strcpy(buf, ".");
972
	else {
973
		if (g_Ctoc(str, buf, sizeof(buf))) {
974
			errno = ENAMETOOLONG;
975
			return (NULL);
976
		}
977
	}
978
979
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
980
		return ((*pglob->gl_opendir)(buf));
981
982
	return (opendir(buf));
983
}
984
985
static int
986
g_lstat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
987
{
988
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
989
990
	if (g_Ctoc(fn, buf, sizeof(buf))) {
991
		errno = ENAMETOOLONG;
992
		return (-1);
993
	}
994
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
995
		return((*pglob->gl_lstat)(buf, sb));
996
	return (freebsd11_lstat(buf, sb));
997
}
998
999
static int
1000
g_stat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
1001
{
1002
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
1003
1004
	if (g_Ctoc(fn, buf, sizeof(buf))) {
1005
		errno = ENAMETOOLONG;
1006
		return (-1);
1007
	}
1008
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1009
		return ((*pglob->gl_stat)(buf, sb));
1010
	return (freebsd11_stat(buf, sb));
1011
}
1012
1013
static const Char *
1014
g_strchr(const Char *str, wchar_t ch)
1015
{
1016
1017
	do {
1018
		if (*str == ch)
1019
			return (str);
1020
	} while (*str++);
1021
	return (NULL);
1022
}
1023
1024
static int
1025
g_Ctoc(const Char *str, char *buf, size_t len)
1026
{
1027
	mbstate_t mbs;
1028
	size_t clen;
1029
1030
	memset(&mbs, 0, sizeof(mbs));
1031
	while (len >= MB_CUR_MAX) {
1032
		clen = wcrtomb(buf, CHAR(*str), &mbs);
1033
		if (clen == (size_t)-1) {
1034
			/* XXX See initial comment #2. */
1035
			*buf = (char)CHAR(*str);
1036
			clen = 1;
1037
			memset(&mbs, 0, sizeof(mbs));
1038
		}
1039
		if (CHAR(*str) == EOS)
1040
			return (0);
1041
		str++;
1042
		buf += clen;
1043
		len -= clen;
1044
	}
1045
	return (1);
1046
}
1047
1048
static int
1049
err_nomatch(glob11_t *pglob, struct glob_limit *limit, const char *origpat) {
1050
	/*
1051
	 * If there was no match we are going to append the origpat
1052
	 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
1053
	 * and the origpat did not contain any magic characters
1054
	 * GLOB_NOMAGIC is there just for compatibility with csh.
1055
	 */
1056
	if ((pglob->gl_flags & GLOB_NOCHECK) ||
1057
	    ((pglob->gl_flags & GLOB_NOMAGIC) &&
1058
	    !(pglob->gl_flags & GLOB_MAGCHAR)))
1059
		return (globextend(NULL, pglob, limit, origpat));
1060
	return (GLOB_NOMATCH);
1061
}
1062
1063
static int
1064
err_aborted(glob11_t *pglob, int err, char *buf) {
1065
	if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) ||
1066
	    (pglob->gl_flags & GLOB_ERR))
1067
		return (GLOB_ABORTED);
1068
	return (0);
1069
}
1070
1071
#ifdef DEBUG
1072
static void
1073
qprintf(const char *str, Char *s)
1074
{
1075
	Char *p;
1076
1077
	(void)printf("%s\n", str);
1078
	if (s != NULL) {
1079
		for (p = s; *p != EOS; p++)
1080
			(void)printf("%c", (char)CHAR(*p));
1081
		(void)printf("\n");
1082
		for (p = s; *p != EOS; p++)
1083
			(void)printf("%c", (isprot(*p) ? '\\' : ' '));
1084
		(void)printf("\n");
1085
		for (p = s; *p != EOS; p++)
1086
			(void)printf("%c", (ismeta(*p) ? '_' : ' '));
1087
		(void)printf("\n");
1088
	}
1089
}
1090
#endif
1091
1092
__sym_compat(glob, freebsd11_glob, FBSD_1.0);
1093
__sym_compat(globfree, freebsd11_globfree, FBSD_1.0);
(-)b/lib/libc/gen/glob-compat11.h (+72 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1989, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * This code is derived from software contributed to Berkeley by
6
 * Guido van Rossum.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. Neither the name of the University nor the names of its contributors
17
 *    may be used to endorse or promote products derived from this software
18
 *    without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
 * SUCH DAMAGE.
31
 *
32
 *	@(#)glob.h	8.1 (Berkeley) 6/2/93
33
 * from: $FreeBSD$
34
 * $FreeBSD$
35
 */
36
37
#ifndef _GLOB_COMPAT11_H_
38
#define	_GLOB_COMPAT11_H_
39
40
#include <sys/cdefs.h>
41
#include <sys/types.h>
42
#include <glob.h>
43
44
struct freebsd11_stat;
45
typedef struct {
46
	size_t gl_pathc;	/* Count of total paths so far. */
47
	size_t gl_matchc;	/* Count of paths matching pattern. */
48
	size_t gl_offs;		/* Reserved at beginning of gl_pathv. */
49
	int gl_flags;		/* Copy of flags parameter to glob. */
50
	char **gl_pathv;	/* List of paths matching pattern. */
51
				/* Copy of errfunc parameter to glob. */
52
	int (*gl_errfunc)(const char *, int);
53
54
	/*
55
	 * Alternate filesystem access methods for glob; replacement
56
	 * versions of closedir(3), readdir(3), opendir(3), stat(2)
57
	 * and lstat(2).
58
	 */
59
	void (*gl_closedir)(void *);
60
	struct freebsd11_dirent *(*gl_readdir)(void *);
61
	void *(*gl_opendir)(const char *);
62
	int (*gl_lstat)(const char *, struct freebsd11_stat *);
63
	int (*gl_stat)(const char *, struct freebsd11_stat *);
64
} glob11_t;
65
66
__BEGIN_DECLS
67
int	freebsd11_glob(const char * __restrict, int,
68
	int (*)(const char *, int), glob11_t * __restrict);
69
void	freebsd11_globfree(glob11_t *);
70
__END_DECLS
71
72
#endif /* !_GLOB_COMPAT11_H_ */
(-)b/lib/libc/gen/nftw-compat11.c (+115 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2003, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 *
16
 * Sponsored in part by the Defense Advanced Research Projects
17
 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18
 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
19
 *
20
 * from: $OpenBSD: nftw.c,v 1.7 2006/03/31 19:41:44 millert Exp $
21
 * from: $FreeBSD$
22
 */
23
24
#include <sys/cdefs.h>
25
__FBSDID("$FreeBSD$");
26
27
#include <sys/types.h>
28
#include <sys/stat.h>
29
#include <errno.h>
30
#include <fts.h>
31
#include <ftw.h>
32
33
#include "fts-compat11.h"
34
35
int
36
freebsd11_nftw(const char *path,
37
    int (*fn)(const char *, const struct freebsd11_stat *, int, struct FTW *),
38
    int nfds, int ftwflags)
39
{
40
	char * const paths[2] = { (char *)path, NULL };
41
	struct FTW ftw;
42
	FTSENT11 *cur;
43
	FTS11 *ftsp;
44
	int error = 0, ftsflags, fnflag, postorder, sverrno;
45
46
	/* XXX - nfds is currently unused */
47
	if (nfds < 1) {
48
		errno = EINVAL;
49
		return (-1);
50
	}
51
52
	ftsflags = FTS_COMFOLLOW;
53
	if (!(ftwflags & FTW_CHDIR))
54
		ftsflags |= FTS_NOCHDIR;
55
	if (ftwflags & FTW_MOUNT)
56
		ftsflags |= FTS_XDEV;
57
	if (ftwflags & FTW_PHYS)
58
		ftsflags |= FTS_PHYSICAL;
59
	else
60
		ftsflags |= FTS_LOGICAL;
61
	postorder = (ftwflags & FTW_DEPTH) != 0;
62
	ftsp = freebsd11_fts_open(paths, ftsflags, NULL);
63
	if (ftsp == NULL)
64
		return (-1);
65
	while ((cur = freebsd11_fts_read(ftsp)) != NULL) {
66
		switch (cur->fts_info) {
67
		case FTS_D:
68
			if (postorder)
69
				continue;
70
			fnflag = FTW_D;
71
			break;
72
		case FTS_DC:
73
			continue;
74
		case FTS_DNR:
75
			fnflag = FTW_DNR;
76
			break;
77
		case FTS_DP:
78
			if (!postorder)
79
				continue;
80
			fnflag = FTW_DP;
81
			break;
82
		case FTS_F:
83
		case FTS_DEFAULT:
84
			fnflag = FTW_F;
85
			break;
86
		case FTS_NS:
87
		case FTS_NSOK:
88
			fnflag = FTW_NS;
89
			break;
90
		case FTS_SL:
91
			fnflag = FTW_SL;
92
			break;
93
		case FTS_SLNONE:
94
			fnflag = FTW_SLN;
95
			break;
96
		default:
97
			error = -1;
98
			goto done;
99
		}
100
		ftw.base = cur->fts_pathlen - cur->fts_namelen;
101
		ftw.level = cur->fts_level;
102
		error = fn(cur->fts_path, cur->fts_statp, fnflag, &ftw);
103
		if (error != 0)
104
			break;
105
	}
106
done:
107
	sverrno = errno;
108
	if (freebsd11_fts_close(ftsp) != 0 && error == 0)
109
		error = -1;
110
	else
111
		errno = sverrno;
112
	return (error);
113
}
114
115
__sym_compat(nftw, freebsd11_nftw, FBSD_1.0);
(-)b/lib/libc/gen/opendir.c (+1 lines)
Lines 296-301 __opendir_common(int fd, int flags, bool use_current_pos) Link Here
296
	dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
296
	dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
297
	LIST_INIT(&dirp->dd_td->td_locq);
297
	LIST_INIT(&dirp->dd_td->td_locq);
298
	dirp->dd_td->td_loccnt = 0;
298
	dirp->dd_td->td_loccnt = 0;
299
	dirp->dd_compat_de = NULL;
299
300
300
	/*
301
	/*
301
	 * Use the system page size if that is a multiple of DIRBLKSIZ.
302
	 * Use the system page size if that is a multiple of DIRBLKSIZ.
(-)b/lib/libc/gen/readdir-compat11.c (+112 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1983, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 * from:
30
 * $FreeBSD$
31
 */
32
33
#if defined(LIBC_SCCS) && !defined(lint)
34
static char sccsid[] = "@(#)readdir.c	8.3 (Berkeley) 9/29/94";
35
#endif /* LIBC_SCCS and not lint */
36
#include <sys/cdefs.h>
37
__FBSDID("$FreeBSD$");
38
39
#include "namespace.h"
40
#include <sys/param.h>
41
#define	_WANT_FREEBSD11_DIRENT
42
#include <dirent.h>
43
#include <errno.h>
44
#include <stddef.h>
45
#include <stdlib.h>
46
#include <string.h>
47
#include <pthread.h>
48
#include "un-namespace.h"
49
50
#include "libc_private.h"
51
#include "gen-private.h"
52
#include "telldir.h"
53
54
#include "gen-compat.h"
55
56
static void
57
freebsd11_cvtdirent(struct freebsd11_dirent *dstdp, struct dirent *srcdp)
58
{
59
60
	dstdp->d_type = srcdp->d_type;
61
	dstdp->d_namlen = srcdp->d_namlen;
62
	dstdp->d_fileno = srcdp->d_fileno;		/* truncate */
63
	dstdp->d_reclen = FREEBSD11_DIRSIZ(dstdp);
64
	bcopy(srcdp->d_name, dstdp->d_name, dstdp->d_namlen);
65
	bzero(dstdp->d_name + dstdp->d_namlen,
66
	    dstdp->d_reclen - offsetof(struct freebsd11_dirent, d_name) -
67
	    dstdp->d_namlen);
68
}
69
70
struct freebsd11_dirent *
71
freebsd11_readdir(DIR *dirp)
72
{
73
	struct freebsd11_dirent *dstdp;
74
	struct dirent *dp;
75
76
	if (__isthreaded)
77
		_pthread_mutex_lock(&dirp->dd_lock);
78
	dp = _readdir_unlocked(dirp, 1);
79
	if (dp != NULL) {
80
		if (dirp->dd_compat_de == NULL)
81
			dirp->dd_compat_de = malloc(sizeof(struct
82
			    freebsd11_dirent));
83
		freebsd11_cvtdirent(dirp->dd_compat_de, dp);
84
		dstdp = dirp->dd_compat_de;
85
	} else
86
		dstdp = NULL;
87
	if (__isthreaded)
88
		_pthread_mutex_unlock(&dirp->dd_lock);
89
90
	return (dstdp);
91
}
92
93
int
94
freebsd11_readdir_r(DIR *dirp, struct freebsd11_dirent *entry,
95
    struct freebsd11_dirent **result)
96
{
97
	struct dirent xentry, *xresult;
98
	int error;
99
100
	error = __readdir_r(dirp, &xentry, &xresult);
101
	if (error != 0)
102
		return (error);
103
	if (xresult != NULL) {
104
		freebsd11_cvtdirent(entry, &xentry);
105
		*result = entry;
106
	} else
107
		*result = NULL;
108
	return (0);
109
}
110
111
__sym_compat(readdir, freebsd11_readdir, FBSD_1.0);
112
__sym_compat(readdir_r, freebsd11_readdir_r, FBSD_1.0);
(-)b/lib/libc/gen/readdir.c (-1 / +3 lines)
Lines 104-110 readdir(DIR *dirp) Link Here
104
}
104
}
105
105
106
int
106
int
107
readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
107
__readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
108
{
108
{
109
	struct dirent *dp;
109
	struct dirent *dp;
110
	int saved_errno;
110
	int saved_errno;
Lines 133-135 readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) Link Here
133
133
134
	return (0);
134
	return (0);
135
}
135
}
136
137
__strong_reference(__readdir_r, readdir_r);
(-)b/lib/libc/gen/scandir-compat11.c (+174 lines)
Added Link Here
1
/*
2
 * Copyright (c) 1983, 1993
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 *
29
 * from:
30
 * $FreeBSD$
31
 */
32
33
#if defined(LIBC_SCCS) && !defined(lint)
34
static char sccsid[] = "@(#)scandir.c	8.3 (Berkeley) 1/2/94";
35
#endif /* LIBC_SCCS and not lint */
36
#include <sys/cdefs.h>
37
__FBSDID("$FreeBSD$");
38
39
/*
40
 * Scan the directory dirname calling select to make a list of selected
41
 * directory entries then sort using qsort and compare routine dcomp.
42
 * Returns the number of entries and a pointer to a list of pointers to
43
 * struct dirent (through namelist). Returns -1 if there were any errors.
44
 */
45
46
#include "namespace.h"
47
#define	_WANT_FREEBSD11_DIRENT
48
#include <dirent.h>
49
#include <stdlib.h>
50
#include <string.h>
51
#include "un-namespace.h"
52
53
#include "gen-compat.h"
54
55
#ifdef	I_AM_SCANDIR_B
56
#include "block_abi.h"
57
#define	SELECT(x)	CALL_BLOCK(select, x)
58
#ifndef __BLOCKS__
59
void
60
qsort_b(void *, size_t, size_t, void*);
61
#endif
62
#else
63
#define	SELECT(x)	select(x)
64
#endif
65
66
static int freebsd11_alphasort_thunk(void *thunk, const void *p1,
67
    const void *p2);
68
69
int
70
#ifdef I_AM_SCANDIR_B
71
freebsd11_scandir_b(const char *dirname, struct freebsd11_dirent ***namelist,
72
    DECLARE_BLOCK(int, select, const struct freebsd11_dirent *),
73
    DECLARE_BLOCK(int, dcomp, const struct freebsd11_dirent **,
74
    const struct freebsd11_dirent **))
75
#else
76
freebsd11_scandir(const char *dirname, struct freebsd11_dirent ***namelist,
77
    int (*select)(const struct freebsd11_dirent *),
78
    int (*dcomp)(const struct freebsd11_dirent **,
79
	const struct freebsd11_dirent **))
80
#endif
81
{
82
	struct freebsd11_dirent *d, *p, **names = NULL;
83
	size_t arraysz, numitems;
84
	DIR *dirp;
85
86
	if ((dirp = opendir(dirname)) == NULL)
87
		return(-1);
88
89
	numitems = 0;
90
	arraysz = 32;	/* initial estimate of the array size */
91
	names = (struct freebsd11_dirent **)malloc(
92
	    arraysz * sizeof(struct freebsd11_dirent *));
93
	if (names == NULL)
94
		goto fail;
95
96
	while ((d = freebsd11_readdir(dirp)) != NULL) {
97
		if (select != NULL && !SELECT(d))
98
			continue;	/* just selected names */
99
		/*
100
		 * Make a minimum size copy of the data
101
		 */
102
		p = (struct freebsd11_dirent *)malloc(FREEBSD11_DIRSIZ(d));
103
		if (p == NULL)
104
			goto fail;
105
		p->d_fileno = d->d_fileno;
106
		p->d_type = d->d_type;
107
		p->d_reclen = d->d_reclen;
108
		p->d_namlen = d->d_namlen;
109
		bcopy(d->d_name, p->d_name, p->d_namlen + 1);
110
		/*
111
		 * Check to make sure the array has space left and
112
		 * realloc the maximum size.
113
		 */
114
		if (numitems >= arraysz) {
115
			struct freebsd11_dirent **names2;
116
117
			names2 = reallocarray(names, arraysz,
118
			    2 * sizeof(struct freebsd11_dirent *));
119
			if (names2 == NULL) {
120
				free(p);
121
				goto fail;
122
			}
123
			names = names2;
124
			arraysz *= 2;
125
		}
126
		names[numitems++] = p;
127
	}
128
	closedir(dirp);
129
	if (numitems && dcomp != NULL)
130
#ifdef I_AM_SCANDIR_B
131
		qsort_b(names, numitems, sizeof(struct freebsd11_dirent *),
132
		    (void*)dcomp);
133
#else
134
		qsort_r(names, numitems, sizeof(struct freebsd11_dirent *),
135
		    &dcomp, freebsd11_alphasort_thunk);
136
#endif
137
	*namelist = names;
138
	return (numitems);
139
140
fail:
141
	while (numitems > 0)
142
		free(names[--numitems]);
143
	free(names);
144
	closedir(dirp);
145
	return (-1);
146
}
147
148
/*
149
 * Alphabetic order comparison routine for those who want it.
150
 * POSIX 2008 requires that alphasort() uses strcoll().
151
 */
152
int
153
freebsd11_alphasort(const struct freebsd11_dirent **d1,
154
    const struct freebsd11_dirent **d2)
155
{
156
157
	return (strcoll((*d1)->d_name, (*d2)->d_name));
158
}
159
160
static int
161
freebsd11_alphasort_thunk(void *thunk, const void *p1, const void *p2)
162
{
163
	int (*dc)(const struct freebsd11_dirent **, const struct
164
	    freebsd11_dirent **);
165
166
	dc = *(int (**)(const struct freebsd11_dirent **,
167
	    const struct freebsd11_dirent **))thunk;
168
	return (dc((const struct freebsd11_dirent **)p1,
169
	    (const struct freebsd11_dirent **)p2));
170
}
171
172
__sym_compat(alphasort, freebsd11_alphasort, FBSD_1.0);
173
__sym_compat(scandir, freebsd11_scandir, FBSD_1.0);
174
__sym_compat(scandir_b, freebsd11_scandir_b, FBSD_1.4);
(-)b/lib/libc/gen/scandir.c (-12 / +1 lines)
Lines 59-75 qsort_b(void *, size_t, size_t, void*); Link Here
59
59
60
static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
60
static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
61
61
62
/*
63
 * The DIRSIZ macro is the minimum record length which will hold the directory
64
 * entry.  This requires the amount of space in struct dirent without the
65
 * d_name field, plus enough space for the name and a terminating nul byte
66
 * (dp->d_namlen + 1), rounded up to a 4 byte boundary.
67
 */
68
#undef DIRSIZ
69
#define DIRSIZ(dp)							\
70
	((sizeof(struct dirent) - sizeof(dp)->d_name) +			\
71
	    (((dp)->d_namlen + 1 + 3) &~ 3))
72
73
int
62
int
74
#ifdef I_AM_SCANDIR_B
63
#ifdef I_AM_SCANDIR_B
75
scandir_b(const char *dirname, struct dirent ***namelist,
64
scandir_b(const char *dirname, struct dirent ***namelist,
Lines 100-106 scandir(const char *dirname, struct dirent ***namelist, Link Here
100
		/*
89
		/*
101
		 * Make a minimum size copy of the data
90
		 * Make a minimum size copy of the data
102
		 */
91
		 */
103
		p = (struct dirent *)malloc(DIRSIZ(d));
92
		p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d));
104
		if (p == NULL)
93
		if (p == NULL)
105
			goto fail;
94
			goto fail;
106
		p->d_fileno = d->d_fileno;
95
		p->d_fileno = d->d_fileno;
(-)b/lib/libc/gen/telldir.h (-1 / +1 lines)
Lines 47-53 Link Here
47
struct ddloc {
47
struct ddloc {
48
	LIST_ENTRY(ddloc) loc_lqe; /* entry in list */
48
	LIST_ENTRY(ddloc) loc_lqe; /* entry in list */
49
	long	loc_index;	/* key associated with structure */
49
	long	loc_index;	/* key associated with structure */
50
	long	loc_seek;	/* magic cookie returned by getdirentries */
50
	off_t	loc_seek;	/* magic cookie returned by getdirentries */
51
	long	loc_loc;	/* offset of entry in buffer */
51
	long	loc_loc;	/* offset of entry in buffer */
52
};
52
};
53
53
(-)b/lib/libc/include/compat.h (+21 lines)
Lines 44-49 __sym_compat(msgctl, freebsd7_msgctl, FBSD_1.0); Link Here
44
__sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0);
44
__sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0);
45
#endif
45
#endif
46
46
47
__sym_compat(nfstat, freebsd11_nfstat, FBSD_1.0);
48
__sym_compat(nlstat, freebsd11_nlstat, FBSD_1.0);
49
__sym_compat(nstat, freebsd11_nstat, FBSD_1.0);
50
51
__sym_compat(fhstat, freebsd11_fhstat, FBSD_1.0);
52
__sym_compat(fstat, freebsd11_fstat, FBSD_1.0);
53
__sym_compat(fstatat, freebsd11_fstatat, FBSD_1.1);
54
__sym_compat(lstat, freebsd11_lstat, FBSD_1.0);
55
__sym_compat(stat, freebsd11_stat, FBSD_1.0);
56
57
__sym_compat(getdents, freebsd11_getdents, FBSD_1.0);
58
__sym_compat(getdirentries, freebsd11_getdirentries, FBSD_1.0);
59
60
__sym_compat(getfsstat, freebsd11_getfsstat, FBSD_1.0);
61
__sym_compat(fhstatfs, freebsd11_fhstatfs, FBSD_1.0);
62
__sym_compat(fstatfs, freebsd11_fstatfs, FBSD_1.0);
63
__sym_compat(statfs, freebsd11_statfs, FBSD_1.0);
64
65
__sym_compat(mknod, freebsd11_mknod, FBSD_1.0);
66
__sym_compat(mknodat, freebsd11_mknodat, FBSD_1.1);
67
47
#undef __sym_compat
68
#undef __sym_compat
48
69
49
#define	__weak_reference(sym,alias)	\
70
#define	__weak_reference(sym,alias)	\
(-)b/lib/libc/include/libc_private.h (+3 lines)
Lines 307-312 struct pollfd; Link Here
307
struct rusage;
307
struct rusage;
308
struct sigaction;
308
struct sigaction;
309
struct sockaddr;
309
struct sockaddr;
310
struct stat;
310
struct timespec;
311
struct timespec;
311
struct timeval;
312
struct timeval;
312
struct timezone;
313
struct timezone;
Lines 323-330 int __sys_clock_nanosleep(__clockid_t, int, Link Here
323
		    const struct timespec *, struct timespec *);
324
		    const struct timespec *, struct timespec *);
324
int		__sys_close(int);
325
int		__sys_close(int);
325
int		__sys_connect(int, const struct sockaddr *, __socklen_t);
326
int		__sys_connect(int, const struct sockaddr *, __socklen_t);
327
__ssize_t	__sys_getdirentries(int, char *, __size_t, __off_t *);
326
int		__sys_fcntl(int, int, ...);
328
int		__sys_fcntl(int, int, ...);
327
int		__sys_fdatasync(int);
329
int		__sys_fdatasync(int);
330
int		__sys_fstatat(int, const char *, struct stat *, int);
328
int		__sys_fsync(int);
331
int		__sys_fsync(int);
329
__pid_t		__sys_fork(void);
332
__pid_t		__sys_fork(void);
330
int		__sys_ftruncate(int, __off_t);
333
int		__sys_ftruncate(int, __off_t);
(-)b/lib/libc/sys/Makefile.inc (+2 lines)
Lines 35-40 SRCS+= \ Link Here
35
	__error.c \
35
	__error.c \
36
	interposing_table.c
36
	interposing_table.c
37
37
38
SRCS+= getdents.c lstat.c mknod.c stat.c
39
38
SRCS+= futimens.c utimensat.c
40
SRCS+= futimens.c utimensat.c
39
NOASM+= futimens.o utimensat.o
41
NOASM+= futimens.o utimensat.o
40
PSEUDO+= _futimens.o _utimensat.o
42
PSEUDO+= _futimens.o _utimensat.o
(-)b/lib/libc/sys/Symbol.map (-28 / +13 lines)
Lines 85-110 FBSD_1.0 { Link Here
85
	fchown;
85
	fchown;
86
	fcntl;
86
	fcntl;
87
	fhopen;
87
	fhopen;
88
	fhstat;
89
	fhstatfs;
90
	flock;
88
	flock;
91
	fork;
89
	fork;
92
	fpathconf;
90
	fpathconf;
93
	fstat;
94
	fstatfs;
95
	fsync;
91
	fsync;
96
	futimes;
92
	futimes;
97
	getaudit;
93
	getaudit;
98
	getaudit_addr;
94
	getaudit_addr;
99
	getauid;
95
	getauid;
100
	getcontext;
96
	getcontext;
101
	getdents;
102
	getdirentries;
103
	getdtablesize;
97
	getdtablesize;
104
	getegid;
98
	getegid;
105
	geteuid;
99
	geteuid;
106
	getfh;
100
	getfh;
107
	getfsstat;
108
	getgid;
101
	getgid;
109
	getgroups;
102
	getgroups;
110
	getitimer;
103
	getitimer;
Lines 163-169 FBSD_1.0 { Link Here
163
	link;
156
	link;
164
	lio_listio;
157
	lio_listio;
165
	listen;
158
	listen;
166
	lstat;
167
	lutimes;
159
	lutimes;
168
	mac_syscall;
160
	mac_syscall;
169
	madvise;
161
	madvise;
Lines 171-177 FBSD_1.0 { Link Here
171
	minherit;
163
	minherit;
172
	mkdir;
164
	mkdir;
173
	mkfifo;
165
	mkfifo;
174
	mknod;
175
	mlock;
166
	mlock;
176
	mlockall;
167
	mlockall;
177
	modfind;
168
	modfind;
Lines 192-201 FBSD_1.0 { Link Here
192
	netbsd_lchown;
183
	netbsd_lchown;
193
	netbsd_msync;
184
	netbsd_msync;
194
	nfssvc;
185
	nfssvc;
195
	nfstat;
196
	nlstat;
197
	nmount;
186
	nmount;
198
	nstat;
199
	ntp_adjtime;
187
	ntp_adjtime;
200
	ntp_gettime;
188
	ntp_gettime;
201
	open;
189
	open;
Lines 275-282 FBSD_1.0 { Link Here
275
	sigwaitinfo;
263
	sigwaitinfo;
276
	socket;
264
	socket;
277
	socketpair;
265
	socketpair;
278
	stat;
279
	statfs;
280
	swapoff;
266
	swapoff;
281
	swapon;
267
	swapon;
282
	symlink;
268
	symlink;
Lines 330-336 FBSD_1.1 { Link Here
330
	fchmodat;
316
	fchmodat;
331
	fchownat;
317
	fchownat;
332
	fexecve;
318
	fexecve;
333
	fstatat;
334
	futimesat;
319
	futimesat;
335
	jail_get;
320
	jail_get;
336
	jail_set;
321
	jail_set;
Lines 339-345 FBSD_1.1 { Link Here
339
	lpathconf;
324
	lpathconf;
340
	mkdirat;
325
	mkdirat;
341
	mkfifoat;
326
	mkfifoat;
342
	mknodat;
343
	msgctl;
327
	msgctl;
344
	readlinkat;
328
	readlinkat;
345
	renameat;
329
	renameat;
Lines 401-406 FBSD_1.4 { Link Here
401
FBSD_1.5 {
385
FBSD_1.5 {
402
	clock_nanosleep;
386
	clock_nanosleep;
403
	fdatasync;
387
	fdatasync;
388
	fhstat;
389
	fhstatfs;
390
	fstat;
391
	fstatat;
392
	fstatfs;
393
	getdents;
394
	getdirentries;
395
	getfsstat;
396
	lstat;
397
	mknod;
398
	mknodat;
399
	stat;
400
	statfs;
404
};
401
};
405
402
406
FBSDprivate_1.0 {
403
FBSDprivate_1.0 {
Lines 606-613 FBSDprivate_1.0 { Link Here
606
	__sys_getauid;
603
	__sys_getauid;
607
	_getcontext;
604
	_getcontext;
608
	__sys_getcontext;
605
	__sys_getcontext;
609
	_getdents;
610
	__sys_getdents;
611
	_getdirentries;
606
	_getdirentries;
612
	__sys_getdirentries;
607
	__sys_getdirentries;
613
	_getdtablesize;
608
	_getdtablesize;
Lines 736-743 FBSDprivate_1.0 { Link Here
736
	__sys_lio_listio;
731
	__sys_lio_listio;
737
	_listen;
732
	_listen;
738
	__sys_listen;
733
	__sys_listen;
739
	_lstat;
740
	__sys_lstat;
741
	_lutimes;
734
	_lutimes;
742
	__sys_lutimes;
735
	__sys_lutimes;
743
	_mac_syscall;
736
	_mac_syscall;
Lines 796-809 FBSDprivate_1.0 { Link Here
796
	__sys_netbsd_msync;
789
	__sys_netbsd_msync;
797
	_nfssvc;
790
	_nfssvc;
798
	__sys_nfssvc;
791
	__sys_nfssvc;
799
	_nfstat;
800
	__sys_nfstat;
801
	_nlstat;
802
	__sys_nlstat;
803
	_nmount;
792
	_nmount;
804
	__sys_nmount;
793
	__sys_nmount;
805
	_nstat;
806
	__sys_nstat;
807
	_ntp_adjtime;
794
	_ntp_adjtime;
808
	__sys_ntp_adjtime;
795
	__sys_ntp_adjtime;
809
	_ntp_gettime;
796
	_ntp_gettime;
Lines 971-978 FBSDprivate_1.0 { Link Here
971
	__sys_socket;
958
	__sys_socket;
972
	_socketpair;
959
	_socketpair;
973
	__sys_socketpair;
960
	__sys_socketpair;
974
	_stat;
975
	__sys_stat;
976
	_statfs;
961
	_statfs;
977
	__sys_statfs;
962
	__sys_statfs;
978
	_swapcontext;
963
	_swapcontext;
(-)b/lib/libc/sys/getdents.c (+41 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
#include "namespace.h"
31
#include <sys/param.h>
32
#include <sys/syscall.h>
33
#include <dirent.h>
34
#include "libc_private.h"
35
36
ssize_t
37
getdents(int fd, char *buf, size_t nbytes)
38
{
39
40
	return (__sys_getdirentries(fd, buf, nbytes, NULL));
41
}
(-)b/lib/libc/sys/getdirentries.2 (-4 / +4 lines)
Lines 40-49 Link Here
40
.Sh SYNOPSIS
40
.Sh SYNOPSIS
41
.In sys/types.h
41
.In sys/types.h
42
.In dirent.h
42
.In dirent.h
43
.Ft int
43
.Ft ssize_t
44
.Fn getdirentries "int fd" "char *buf" "int nbytes" "long *basep"
44
.Fn getdirentries "int fd" "char *buf" "size_t nbytes" "off_t *basep"
45
.Ft int
45
.Ft ssize_t
46
.Fn getdents "int fd" "char *buf" "int nbytes"
46
.Fn getdents "int fd" "char *buf" "size_t nbytes"
47
.Sh DESCRIPTION
47
.Sh DESCRIPTION
48
The
48
The
49
.Fn getdirentries
49
.Fn getdirentries
(-)b/lib/libc/sys/lstat.c (+43 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
#include "namespace.h"
31
#include <sys/param.h>
32
#include <sys/fcntl.h>
33
#include <sys/syscall.h>
34
#include <sys/stat.h>
35
#include <unistd.h>
36
#include "libc_private.h"
37
38
int
39
lstat(const char *path, struct stat *sb)
40
{
41
42
	return (__sys_fstatat(AT_FDCWD, path, sb, AT_SYMLINK_NOFOLLOW));
43
}
(-)b/lib/libc/sys/mknod.c (+45 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2011 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
#include "namespace.h"
31
#include <sys/param.h>
32
#include <sys/fcntl.h>
33
#include <sys/syscall.h>
34
#include <sys/stat.h>
35
#include <unistd.h>
36
#include "libc_private.h"
37
38
int __sys_mknodat(int, const char *, mode_t, dev_t);
39
40
int
41
mknod(const char *path, mode_t mode, dev_t dev)
42
{
43
44
	return (__sys_mknodat(AT_FDCWD, path, mode, dev));
45
}
(-)b/lib/libc/sys/stat.c (+43 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2012 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
27
#include <sys/cdefs.h>
28
__FBSDID("$FreeBSD$");
29
30
#include "namespace.h"
31
#include <sys/param.h>
32
#include <sys/fcntl.h>
33
#include <sys/syscall.h>
34
#include <sys/stat.h>
35
#include <unistd.h>
36
#include "libc_private.h"
37
38
int
39
stat(const char *path, struct stat *sb)
40
{
41
42
	return (__sys_fstatat(AT_FDCWD, path, sb, 0));
43
}
(-)b/lib/libc/sys/statfs.2 (-3 / +3 lines)
Lines 28-34 Link Here
28
.\"	@(#)statfs.2	8.5 (Berkeley) 5/24/95
28
.\"	@(#)statfs.2	8.5 (Berkeley) 5/24/95
29
.\" $FreeBSD$
29
.\" $FreeBSD$
30
.\"
30
.\"
31
.Dd November 1, 2006
31
.Dd February 13, 2017
32
.Dt STATFS 2
32
.Dt STATFS 2
33
.Os
33
.Os
34
.Sh NAME
34
.Sh NAME
Lines 66-73 typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ Link Here
66
 */
66
 */
67
67
68
#define	MFSNAMELEN	16		/* length of type name including null */
68
#define	MFSNAMELEN	16		/* length of type name including null */
69
#define	MNAMELEN	88		/* size of on/from name bufs */
69
#define	MNAMELEN	1024		/* size of on/from name bufs */
70
#define	STATFS_VERSION	0x20030518	/* current version number */
70
#define	STATFS_VERSION	0x20140518	/* current version number */
71
71
72
struct statfs {
72
struct statfs {
73
uint32_t f_version;		/* structure version number */
73
uint32_t f_version;		/* structure version number */
(-)b/lib/libkvm/kvm_proc.c (+1 lines)
Lines 452-457 nopgrp: Link Here
452
		} else {
452
		} else {
453
			kp->ki_stat = SZOMB;
453
			kp->ki_stat = SZOMB;
454
		}
454
		}
455
		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
455
		bcopy(&kinfo_proc, bp, sizeof(kinfo_proc));
456
		bcopy(&kinfo_proc, bp, sizeof(kinfo_proc));
456
		++bp;
457
		++bp;
457
		++cnt;
458
		++cnt;
(-)b/lib/libmilter/Makefile (+1 lines)
Lines 29-34 SRCS+= main.c engine.c listener.c handler.c comm.c monitor.c smfi.c \ Link Here
29
CLEANFILES+=sm_os.h
29
CLEANFILES+=sm_os.h
30
30
31
WARNS?=	0
31
WARNS?=	0
32
SHLIB_MAJOR= 6
32
33
33
sm_os.h: ${SENDMAIL_DIR}/include/sm/os/sm_os_freebsd.h .NOMETA
34
sm_os.h: ${SENDMAIL_DIR}/include/sm/os/sm_os_freebsd.h .NOMETA
34
	ln -sf ${.ALLSRC} ${.TARGET}
35
	ln -sf ${.ALLSRC} ${.TARGET}
(-)b/lib/libprocstat/Makefile (+4 lines)
Lines 13-18 SRCS= cd9660.c \ Link Here
13
	smbfs.c		\
13
	smbfs.c		\
14
	udf.c
14
	udf.c
15
15
16
.if ${MK_SYMVER} == yes
17
SRCS+=	libprocstat_compat.c
18
.endif
19
16
VERSION_DEF=	${LIBCSRCDIR}/Versions.def
20
VERSION_DEF=	${LIBCSRCDIR}/Versions.def
17
SYMBOL_MAPS=	${.CURDIR}/Symbol.map
21
SYMBOL_MAPS=	${.CURDIR}/Symbol.map
18
22
(-)b/lib/libprocstat/Symbol.map (-4 / +4 lines)
Lines 6-14 FBSD_1.2 { Link Here
6
	procstat_freefiles;
6
	procstat_freefiles;
7
	procstat_freeprocs;
7
	procstat_freeprocs;
8
	procstat_get_pipe_info;
8
	procstat_get_pipe_info;
9
	procstat_get_pts_info;
10
	procstat_get_socket_info;
9
	procstat_get_socket_info;
11
	procstat_get_vnode_info;
12
	procstat_getfiles;
10
	procstat_getfiles;
13
	procstat_getprocs;
11
	procstat_getprocs;
14
	procstat_open_kvm;
12
	procstat_open_kvm;
Lines 22-29 FBSD_1.3 { Link Here
22
	procstat_freegroups;
20
	procstat_freegroups;
23
	procstat_freekstack;
21
	procstat_freekstack;
24
	procstat_freevmmap;
22
	procstat_freevmmap;
25
	procstat_get_sem_info;
26
	procstat_get_shm_info;
27
	procstat_getargv;
23
	procstat_getargv;
28
	procstat_getauxv;
24
	procstat_getauxv;
29
	procstat_getenvv;
25
	procstat_getenvv;
Lines 40-43 FBSD_1.3 { Link Here
40
FBSD_1.5 {
36
FBSD_1.5 {
41
	procstat_freeptlwpinfo;
37
	procstat_freeptlwpinfo;
42
	procstat_getptlwpinfo;
38
	procstat_getptlwpinfo;
39
	procstat_get_pts_info;
40
	procstat_get_sem_info;
41
	procstat_get_shm_info;
42
	procstat_get_vnode_info;
43
};
43
};
(-)b/lib/libprocstat/libprocstat.c (-5 / +7 lines)
Lines 1337-1348 procstat_get_vnode_info_sysctl(struct filestat *fst, struct vnstat *vn, Link Here
1337
	struct statfs stbuf;
1337
	struct statfs stbuf;
1338
	struct kinfo_file *kif;
1338
	struct kinfo_file *kif;
1339
	struct kinfo_vmentry *kve;
1339
	struct kinfo_vmentry *kve;
1340
	char *name, *path;
1340
	uint64_t fileid;
1341
	uint64_t fileid;
1341
	uint64_t size;
1342
	uint64_t size;
1342
	char *name, *path;
1343
	uint64_t fsid;
1343
	uint32_t fsid;
1344
	uint64_t rdev;
1344
	uint16_t mode;
1345
	uint16_t mode;
1345
	uint32_t rdev;
1346
	int vntype;
1346
	int vntype;
1347
	int status;
1347
	int status;
1348
1348
Lines 1545-1552 procstat_get_socket_info_sysctl(struct filestat *fst, struct sockstat *sock, Link Here
1545
	sock->dom_family = kif->kf_sock_domain;
1545
	sock->dom_family = kif->kf_sock_domain;
1546
	sock->so_pcb = kif->kf_un.kf_sock.kf_sock_pcb;
1546
	sock->so_pcb = kif->kf_un.kf_sock.kf_sock_pcb;
1547
	strlcpy(sock->dname, kif->kf_path, sizeof(sock->dname));
1547
	strlcpy(sock->dname, kif->kf_path, sizeof(sock->dname));
1548
	bcopy(&kif->kf_sa_local, &sock->sa_local, kif->kf_sa_local.ss_len);
1548
	bcopy(&kif->kf_un.kf_sock.kf_sa_local, &sock->sa_local,
1549
	bcopy(&kif->kf_sa_peer, &sock->sa_peer, kif->kf_sa_peer.ss_len);
1549
	    kif->kf_un.kf_sock.kf_sa_local.ss_len);
1550
	bcopy(&kif->kf_un.kf_sock.kf_sa_peer, &sock->sa_peer,
1551
	    kif->kf_un.kf_sock.kf_sa_peer.ss_len);
1550
1552
1551
	/*
1553
	/*
1552
	 * Protocol specific data.
1554
	 * Protocol specific data.
(-)b/lib/libprocstat/libprocstat.h (-3 / +3 lines)
Lines 120-134 struct filestat { Link Here
120
struct vnstat {
120
struct vnstat {
121
	uint64_t	vn_fileid;
121
	uint64_t	vn_fileid;
122
	uint64_t	vn_size;
122
	uint64_t	vn_size;
123
	uint64_t	vn_dev;
124
	uint64_t	vn_fsid;
123
	char		*vn_mntdir;
125
	char		*vn_mntdir;
124
	uint32_t	vn_dev;
125
	uint32_t	vn_fsid;
126
	int		vn_type;
126
	int		vn_type;
127
	uint16_t	vn_mode;
127
	uint16_t	vn_mode;
128
	char		vn_devname[SPECNAMELEN + 1];
128
	char		vn_devname[SPECNAMELEN + 1];
129
};
129
};
130
struct ptsstat {
130
struct ptsstat {
131
	uint32_t	dev;
131
	uint64_t	dev;
132
	char		devname[SPECNAMELEN + 1];
132
	char		devname[SPECNAMELEN + 1];
133
};
133
};
134
struct pipestat {
134
struct pipestat {
(-)b/lib/libprocstat/libprocstat_compat.c (+144 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2014 Gleb Kurtsou <gleb@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 *
26
 * $FreeBSD$
27
 */
28
29
#include <sys/cdefs.h>
30
__FBSDID("$FreeBSD$");
31
32
#include <sys/param.h>
33
#include <sys/user.h>
34
#include <sys/socket.h>
35
#include <string.h>
36
37
#include "libprocstat.h"
38
39
struct freebsd11_ptsstat {
40
	uint32_t	dev;
41
	char		devname[SPECNAMELEN + 1];
42
};
43
44
struct freebsd11_vnstat {
45
	uint64_t	vn_fileid;
46
	uint64_t	vn_size;
47
	char		*vn_mntdir;
48
	uint32_t	vn_dev;
49
	uint32_t	vn_fsid;
50
	int		vn_type;
51
	uint16_t	vn_mode;
52
	char		vn_devname[SPECNAMELEN + 1];
53
};
54
struct freebsd11_semstat {
55
	uint32_t	value;
56
	uint16_t	mode;
57
};
58
struct freebsd11_shmstat {
59
	uint64_t	size;
60
	uint16_t	mode;
61
};
62
63
int	freebsd11_procstat_get_pts_info(struct procstat *procstat,
64
    struct filestat *fst, struct freebsd11_ptsstat *pts, char *errbuf);
65
int	freebsd11_procstat_get_sem_info(struct procstat *procstat,
66
    struct filestat *fst, struct freebsd11_semstat *sem, char *errbuf);
67
int	freebsd11_procstat_get_shm_info(struct procstat *procstat,
68
    struct filestat *fst, struct freebsd11_shmstat *shm, char *errbuf);
69
int	freebsd11_procstat_get_vnode_info(struct procstat *procstat,
70
    struct filestat *fst, struct freebsd11_vnstat *vn, char *errbuf);
71
72
int
73
freebsd11_procstat_get_pts_info(struct procstat *procstat,
74
    struct filestat *fst, struct freebsd11_ptsstat *pts_compat, char *errbuf)
75
{
76
	struct ptsstat pts;
77
	int r;
78
79
	r = procstat_get_pts_info(procstat, fst, &pts, errbuf);
80
	if (r != 0)
81
		return (r);
82
	pts_compat->dev = pts.dev;
83
	memcpy(pts_compat->devname, pts.devname,
84
	    sizeof(pts_compat->devname));
85
	return (0);
86
}
87
88
int
89
freebsd11_procstat_get_sem_info(struct procstat *procstat,
90
    struct filestat *fst, struct freebsd11_semstat *sem_compat, char *errbuf)
91
{
92
	struct semstat sem;
93
	int r;
94
95
	r = procstat_get_sem_info(procstat, fst, &sem, errbuf);
96
	if (r != 0)
97
		return (r);
98
	sem_compat->value = sem.value;
99
	sem_compat->mode = sem.mode;
100
	return (0);
101
}
102
103
int
104
freebsd11_procstat_get_shm_info(struct procstat *procstat,
105
    struct filestat *fst, struct freebsd11_shmstat *shm_compat, char *errbuf)
106
{
107
	struct shmstat shm;
108
	int r;
109
110
	r = procstat_get_shm_info(procstat, fst, &shm, errbuf);
111
	if (r != 0)
112
		return (r);
113
	shm_compat->size = shm.size;
114
	shm_compat->mode = shm.mode;
115
	return (0);
116
}
117
118
int
119
freebsd11_procstat_get_vnode_info(struct procstat *procstat,
120
    struct filestat *fst, struct freebsd11_vnstat *vn_compat, char *errbuf)
121
{
122
	struct vnstat vn;
123
	int r;
124
125
	r = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
126
	if (r != 0)
127
		return (r);
128
	vn_compat->vn_fileid = vn.vn_fileid;
129
	vn_compat->vn_size = vn.vn_size;
130
	vn_compat->vn_mntdir = vn.vn_mntdir;
131
	vn_compat->vn_dev = vn.vn_dev;
132
	vn_compat->vn_fsid = vn.vn_fsid;
133
	vn_compat->vn_type = vn.vn_type;
134
	vn_compat->vn_mode = vn.vn_mode;
135
	memcpy(vn_compat->vn_devname, vn.vn_devname,
136
	    sizeof(vn_compat->vn_devname));
137
	return (0);
138
}
139
140
__sym_compat(procstat_get_pts_info, freebsd11_procstat_get_pts_info, FBSD_1.2);
141
__sym_compat(procstat_get_vnode_info, freebsd11_procstat_get_vnode_info,
142
    FBSD_1.2);
143
__sym_compat(procstat_get_sem_info, freebsd11_procstat_get_sem_info, FBSD_1.3);
144
__sym_compat(procstat_get_shm_info, freebsd11_procstat_get_shm_info, FBSD_1.3);
(-)b/lib/libufs/libufs.h (-2 / +2 lines)
Lines 45-52 struct uufsd { Link Here
45
	ufs2_daddr_t d_sblock;	/* superblock location */
45
	ufs2_daddr_t d_sblock;	/* superblock location */
46
	struct csum *d_sbcsum;	/* Superblock summary info */
46
	struct csum *d_sbcsum;	/* Superblock summary info */
47
	caddr_t d_inoblock;	/* inode block */
47
	caddr_t d_inoblock;	/* inode block */
48
	ino_t d_inomin;		/* low inode */
48
	uint32_t d_inomin;	/* low inode (not ino_t for ABI compat) */
49
	ino_t d_inomax;		/* high inode */
49
	uint32_t d_inomax;	/* high inode (not ino_t for ABI compat) */
50
	union {
50
	union {
51
		struct fs d_fs;	/* filesystem information */
51
		struct fs d_fs;	/* filesystem information */
52
		char d_sb[MAXBSIZE];
52
		char d_sb[MAXBSIZE];
(-)b/preapply.sh (+55 lines)
Added Link Here
1
Index: devel/libgtop/files/patch-ino64
2
===================================================================
3
--- devel/libgtop/files/patch-ino64	(nonexistent)
4
+++ devel/libgtop/files/patch-ino64	(working copy)
5
@@ -0,0 +1,41 @@
6
+--- sysdeps/freebsd/procopenfiles.c.orig	2014-10-12 07:17:26.000000000 +0000
7
++++ sysdeps/freebsd/procopenfiles.c	2017-04-22 17:17:54.862169000 +0000
8
+@@ -322,12 +322,12 @@
9
+ 				struct sockaddr_un *sun;
10
+ 
11
+ 				entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
12
+-				sun = (struct sockaddr_un *)&kif->kf_sa_local;
Added Link Here
1
#!/bin/sh
2
if [ x"$INO64GIT" = x ]; then
3
    echo "set INO64GIT env var to point to the git mirror of ino64"
4
    exit 1
5
fi
6
xxx=$(svn st 2>&1)
7
if [ x"$xxx" \!= x ]; then
8
    echo "working directory is not clean, check with svn status"
9
    exit 1
10
fi
11
set -e
12
svn cp include/fts.h lib/libc/gen/fts-compat11.h
13
rm lib/libc/gen/fts-compat11.h
14
svn cp include/glob.h lib/libc/gen/glob-compat11.h
15
rm lib/libc/gen/glob-compat11.h
16
svn cp lib/libc/gen/fts.c lib/libc/gen/fts-compat11.c
17
rm lib/libc/gen/fts-compat11.c
18
svn cp lib/libc/gen/ftw.c lib/libc/gen/ftw-compat11.c
19
rm lib/libc/gen/ftw-compat11.c
20
svn cp lib/libc/gen/nftw.c lib/libc/gen/nftw-compat11.c
21
rm lib/libc/gen/nftw-compat11.c
22
svn cp lib/libc/gen/glob.c lib/libc/gen/glob-compat11.c
23
rm lib/libc/gen/glob-compat11.c
24
svn cp lib/libc/gen/getmntinfo.c lib/libc/gen/getmntinfo-compat11.c
25
rm lib/libc/gen/getmntinfo-compat11.c
26
svn cp lib/libc/gen/readdir.c lib/libc/gen/readdir-compat11.c
27
rm lib/libc/gen/readdir-compat11.c
28
svn cp lib/libc/gen/scandir.c lib/libc/gen/scandir-compat11.c
29
rm lib/libc/gen/scandir-compat11.c
30
(cd $INO64GIT && git diff origin/master ino64) | gpatch -p1
31
add_files="lib/libc/sys/getdents.c lib/libc/sys/lstat.c"
32
add_files="$add_files lib/libc/sys/mknod.c lib/libc/sys/stat.c"
33
add_files="$add_files lib/libc/gen/gen-compat.h lib/libc/gen/devname-compat11.c"
34
add_files="$add_files lib/libprocstat/libprocstat_compat.c"
35
svn add $add_files
36
svn propset svn:keywords 'FreeBSD=%H' $add_files
37
rm -f TODO.ino64 preapply.sh abi.sh ports.patch
38
xxx=$(svn st | awk '$1 ~ /^\?$/ {print $2}')
39
if [ x"$xxx" \!= x ]; then
40
    echo "unmanaged files were found after patching, check"
41
    exit 1
42
fi
43
echo "Looks good"
(-)b/sbin/badsect/badsect.c (-12 / +1 lines)
Lines 129-147 main(int argc, char *argv[]) Link Here
129
			err(8, "%s", *argv);
129
			err(8, "%s", *argv);
130
		if (chkuse(number, 1))
130
		if (chkuse(number, 1))
131
			continue;
131
			continue;
132
		/*
133
		 * Print a warning if converting the block number to a dev_t
134
		 * will truncate it.  badsect was not very useful in versions
135
		 * of BSD before 4.4 because dev_t was 16 bits and another
136
		 * bit was lost by bogus sign extensions.
137
		 */
138
		diskbn = dbtofsb(fs, number);
132
		diskbn = dbtofsb(fs, number);
139
		if ((dev_t)diskbn != diskbn) {
133
		if (mknod(*argv, IFMT|0600, (dev_t)diskbn) < 0) {
140
			printf("sector %ld cannot be represented as a dev_t\n",
141
			    (long)number);
142
			errs++;
143
		}
144
		else if (mknod(*argv, IFMT|0600, (dev_t)diskbn) < 0) {
145
			warn("%s", *argv);
134
			warn("%s", *argv);
146
			errs++;
135
			errs++;
147
		}
136
		}
(-)b/sbin/fsck_ffs/suj.c (-4 / +4 lines)
Lines 1347-1354 ino_adjust(struct suj_ino *sino) Link Here
1347
	struct suj_ino *stmp;
1347
	struct suj_ino *stmp;
1348
	union dinode *ip;
1348
	union dinode *ip;
1349
	nlink_t nlink;
1349
	nlink_t nlink;
1350
	nlink_t reqlink;
1350
	int recmode;
1351
	int recmode;
1351
	int reqlink;
1352
	int isdot;
1352
	int isdot;
1353
	int mode;
1353
	int mode;
1354
	ino_t ino;
1354
	ino_t ino;
Lines 1635-1643 ino_check(struct suj_ino *sino) Link Here
1635
	struct suj_rec *srec;
1635
	struct suj_rec *srec;
1636
	struct jrefrec *rrec;
1636
	struct jrefrec *rrec;
1637
	nlink_t dotlinks;
1637
	nlink_t dotlinks;
1638
	int newlinks;
1638
	nlink_t newlinks;
1639
	int removes;
1639
	nlink_t removes;
1640
	int nlink;
1640
	nlink_t nlink;
1641
	ino_t ino;
1641
	ino_t ino;
1642
	int isdot;
1642
	int isdot;
1643
	int isat;
1643
	int isat;
(-)b/share/man/man5/acct.5 (-4 / +4 lines)
Lines 28-34 Link Here
28
.\"     @(#)acct.5	8.1 (Berkeley) 6/5/93
28
.\"     @(#)acct.5	8.1 (Berkeley) 6/5/93
29
.\" $FreeBSD$
29
.\" $FreeBSD$
30
.\"
30
.\"
31
.Dd May 15, 2007
31
.Dd February 13, 2017
32
.Dt ACCT 5
32
.Dt ACCT 5
33
.Os
33
.Os
34
.Sh NAME
34
.Sh NAME
Lines 51-62 to the accounting file. Link Here
51
#define AC_COMM_LEN 16
51
#define AC_COMM_LEN 16
52
52
53
/*
53
/*
54
 * Accounting structure version 2 (current).
54
 * Accounting structure version 3 (current).
55
 * The first byte is always zero.
55
 * The first byte is always zero.
56
 * Time units are microseconds.
56
 * Time units are microseconds.
57
 */
57
 */
58
58
59
struct acctv2 {
59
struct acctv3 {
60
	uint8_t  ac_zero;		/* zero identifies new version */
60
	uint8_t  ac_zero;		/* zero identifies new version */
61
	uint8_t  ac_version;		/* record version number */
61
	uint8_t  ac_version;		/* record version number */
62
	uint16_t ac_len;		/* record length */
62
	uint16_t ac_len;		/* record length */
Lines 74-80 struct acctv2 { Link Here
74
74
75
	uint16_t ac_len2;		/* record length */
75
	uint16_t ac_len2;		/* record length */
76
	union {
76
	union {
77
		__dev_t	  ac_align;	/* force v1 compatible alignment */
77
		uint32_t  ac_align;	/* force v1 compatible alignment */
78
78
79
#define	AFORK	0x01			/* forked but not exec'ed */
79
#define	AFORK	0x01			/* forked but not exec'ed */
80
/* ASU is no longer supported */
80
/* ASU is no longer supported */
(-)b/share/man/man5/dir.5 (-10 / +21 lines)
Lines 28-34 Link Here
28
.\"     @(#)dir.5	8.3 (Berkeley) 4/19/94
28
.\"     @(#)dir.5	8.3 (Berkeley) 4/19/94
29
.\" $FreeBSD$
29
.\" $FreeBSD$
30
.\"
30
.\"
31
.Dd April 19, 1994
31
.Dd February 13, 2017
32
.Dt DIR 5
32
.Dt DIR 5
33
.Os
33
.Os
34
.Sh NAME
34
.Sh NAME
Lines 93-110 The directory entry format is defined in the file Link Here
93
 * contained in the entry.  These are followed by the name padded to a 4
93
 * contained in the entry.  These are followed by the name padded to a 4
94
 * byte boundary with null bytes.  All names are guaranteed null terminated.
94
 * byte boundary with null bytes.  All names are guaranteed null terminated.
95
 * The maximum length of a name in a directory is MAXNAMLEN.
95
 * The maximum length of a name in a directory is MAXNAMLEN.
96
 * Explicit pad is added between the last member of the header and
97
 * d_name, to avoid having the ABI padding in the end of dirent on
98
 * LP64 arches.  There is code depending on d_name being last.  Also,
99
 * keeping this pad for ILP32 architectures simplifies compat32 layer.
96
 */
100
 */
97
101
98
struct dirent {
102
struct dirent {
99
	__uint32_t d_fileno;		/* file number of entry */
103
	ino_t      d_fileno;		/* file number of entry */
104
	off_t      d_off;		/* directory offset of entry */
100
	__uint16_t d_reclen;		/* length of this record */
105
	__uint16_t d_reclen;		/* length of this record */
101
	__uint8_t  d_type; 		/* file type, see below */
106
	__uint8_t  d_type;		/* file type, see below */
102
	__uint8_t  d_namlen;		/* length of string in d_name */
107
	__uint8_t  d_namlen;		/* length of string in d_name */
103
#ifdef _POSIX_SOURCE
108
	__uint32_t d_pad0;
104
	char	d_name[255 + 1];	/* name must be no longer than this */
109
#if __BSD_VISIBLE
105
#else
106
#define	MAXNAMLEN	255
110
#define	MAXNAMLEN	255
107
	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
111
	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
112
#else
113
	char	d_name[255 + 1];	/* name must be no longer than this */
108
#endif
114
#endif
109
};
115
};
110
116
Lines 129-140 struct dirent { Link Here
129
135
130
/*
136
/*
131
 * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
137
 * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
132
 * the directory entry.  This requires the amount of space in struct direct
138
 * the directory entry.  This returns the amount of space in struct direct
133
 * without the d_name field, plus enough space for the name with a terminating
139
 * without the d_name field, plus enough space for the name with a terminating
134
 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
140
 * null byte (dp->d_namlen+1), rounded up to a 8 byte boundary.
141
 *
142
 * XXX although this macro is in the implementation namespace, it requires
143
 * a manifest constant that is not.
135
 */
144
 */
136
#define	_GENERIC_DIRSIZ(dp) \
145
#define	_GENERIC_DIRLEN(namlen)					\
137
    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
146
	((__offsetof(struct dirent, d_name) + (namlen) + 1 + 7) & ~7)
147
#define	_GENERIC_DIRSIZ(dp)	_GENERIC_DIRLEN((dp)->d_namlen)
148
#endif /* __BSD_VISIBLE */
138
149
139
#ifdef _KERNEL
150
#ifdef _KERNEL
140
#define	GENERIC_DIRSIZ(dp)	_GENERIC_DIRSIZ(dp)
151
#define	GENERIC_DIRSIZ(dp)	_GENERIC_DIRSIZ(dp)
(-)b/sys/bsm/audit.h (-2 / +2 lines)
Lines 183-195 typedef u_int32_t au_class_t; Link Here
183
typedef	u_int64_t	au_asflgs_t __attribute__ ((aligned (8)));
183
typedef	u_int64_t	au_asflgs_t __attribute__ ((aligned (8)));
184
184
185
struct au_tid {
185
struct au_tid {
186
	dev_t		port;
186
	u_int32_t	port;		/* XXX dev_t compatibility */
187
	u_int32_t	machine;
187
	u_int32_t	machine;
188
};
188
};
189
typedef	struct au_tid	au_tid_t;
189
typedef	struct au_tid	au_tid_t;
190
190
191
struct au_tid_addr {
191
struct au_tid_addr {
192
	dev_t		at_port;
192
	u_int32_t	at_port;	/* XXX dev_t compatibility */
193
	u_int32_t	at_type;
193
	u_int32_t	at_type;
194
	u_int32_t	at_addr[4];
194
	u_int32_t	at_addr[4];
195
};
195
};
(-)b/sys/cddl/compat/opensolaris/sys/dirent.h (-3 / +1 lines)
Lines 40-47 typedef ino_t ino64_t; Link Here
40
40
41
#define	d_ino	d_fileno
41
#define	d_ino	d_fileno
42
42
43
#define	DIRENT64_RECLEN(len)	((sizeof(struct dirent) -		\
43
#define	DIRENT64_RECLEN(len)	_GENERIC_DIRLEN(len)
44
				 sizeof(((struct dirent *)NULL)->d_name) + \
45
				 (len) + 1 + 3) & ~3)
46
44
47
#endif	/* !_OPENSOLARIS_SYS_DIRENT_H_ */
45
#endif	/* !_OPENSOLARIS_SYS_DIRENT_H_ */
(-)b/sys/compat/freebsd32/capabilities.conf (+5 lines)
Lines 94-99 freebsd32_fexecve Link Here
94
flock
94
flock
95
fork
95
fork
96
fpathconf
96
fpathconf
97
freebsd11_freebsd32_fstat
98
freebsd11_freebsd32_fstatat
99
freebsd11_freebsd32_getdirentries
100
freebsd11_freebsd32_fstatfs
101
freebsd11_freebsd32_mknodat
97
freebsd6_freebsd32_ftruncate
102
freebsd6_freebsd32_ftruncate
98
freebsd6_freebsd32_lseek
103
freebsd6_freebsd32_lseek
99
freebsd6_freebsd32_mmap
104
freebsd6_freebsd32_mmap
(-)b/sys/compat/freebsd32/freebsd32.h (-9 / +48 lines)
Lines 107-113 struct itimerval32 { Link Here
107
	struct timeval32 it_value;
107
	struct timeval32 it_value;
108
};
108
};
109
109
110
#define FREEBSD4_MNAMELEN        (88 - 2 * sizeof(int32_t)) /* size of on/from name bufs */
110
#define FREEBSD4_MFSNAMELEN	16
111
#define FREEBSD4_MNAMELEN	(88 - 2 * sizeof(int32_t))
111
112
112
/* 4.x version */
113
/* 4.x version */
113
struct statfs32 {
114
struct statfs32 {
Lines 125-131 struct statfs32 { Link Here
125
	int32_t	f_flags;
126
	int32_t	f_flags;
126
	int32_t	f_syncwrites;
127
	int32_t	f_syncwrites;
127
	int32_t	f_asyncwrites;
128
	int32_t	f_asyncwrites;
128
	char	f_fstypename[MFSNAMELEN];
129
	char	f_fstypename[FREEBSD4_MFSNAMELEN];
129
	char	f_mntonname[FREEBSD4_MNAMELEN];
130
	char	f_mntonname[FREEBSD4_MNAMELEN];
130
	int32_t	f_syncreads;
131
	int32_t	f_syncreads;
131
	int32_t	f_asyncreads;
132
	int32_t	f_asyncreads;
Lines 159-172 struct msghdr32 { Link Here
159
	int		 msg_flags;
160
	int		 msg_flags;
160
};
161
};
161
162
163
#if defined(__amd64__)
164
#define	__STAT32_TIME_T_EXT	1
165
#endif
166
162
struct stat32 {
167
struct stat32 {
163
	dev_t	st_dev;
168
	dev_t st_dev;
164
	ino_t	st_ino;
169
	ino_t st_ino;
170
	nlink_t st_nlink;
171
	mode_t	st_mode;
172
	u_int16_t st_padding0;
173
	uid_t	st_uid;
174
	gid_t	st_gid;
175
	u_int32_t st_padding1;
176
	dev_t st_rdev;
177
#ifdef	__STAT32_TIME_T_EXT
178
	__int32_t st_atim_ext;
179
#endif
180
	struct timespec32 st_atim;
181
#ifdef	__STAT32_TIME_T_EXT
182
	__int32_t st_mtim_ext;
183
#endif
184
	struct timespec32 st_mtim;
185
#ifdef	__STAT32_TIME_T_EXT
186
	__int32_t st_ctim_ext;
187
#endif
188
	struct timespec32 st_ctim;
189
#ifdef	__STAT32_TIME_T_EXT
190
	__int32_t st_btim_ext;
191
#endif
192
	struct timespec32 st_birthtim;
193
	off_t	st_size;
194
	int64_t	st_blocks;
195
	u_int32_t st_blksize;
196
	u_int32_t st_flags;
197
	u_int64_t st_gen;
198
	u_int64_t st_spare[10];
199
};
200
struct freebsd11_stat32 {
201
	u_int32_t st_dev;
202
	u_int32_t st_ino;
165
	mode_t	st_mode;
203
	mode_t	st_mode;
166
	nlink_t	st_nlink;
204
	u_int16_t st_nlink;
167
	uid_t	st_uid;
205
	uid_t	st_uid;
168
	gid_t	st_gid;
206
	gid_t	st_gid;
169
	dev_t	st_rdev;
207
	u_int32_t st_rdev;
170
	struct timespec32 st_atim;
208
	struct timespec32 st_atim;
171
	struct timespec32 st_mtim;
209
	struct timespec32 st_mtim;
172
	struct timespec32 st_ctim;
210
	struct timespec32 st_ctim;
Lines 183-191 struct stat32 { Link Here
183
221
184
struct ostat32 {
222
struct ostat32 {
185
	__uint16_t st_dev;
223
	__uint16_t st_dev;
186
	ino_t	st_ino;
224
	__uint32_t st_ino;
187
	mode_t	st_mode;
225
	mode_t	st_mode;
188
	nlink_t	st_nlink;
226
	__uint16_t st_nlink;
189
	__uint16_t st_uid;
227
	__uint16_t st_uid;
190
	__uint16_t st_gid;
228
	__uint16_t st_gid;
191
	__uint16_t st_rdev;
229
	__uint16_t st_rdev;
Lines 270-276 struct kinfo_proc32 { Link Here
270
	pid_t	ki_tsid;
308
	pid_t	ki_tsid;
271
	short	ki_jobc;
309
	short	ki_jobc;
272
	short	ki_spare_short1;
310
	short	ki_spare_short1;
273
	dev_t	ki_tdev;
311
	uint32_t ki_tdev_freebsd11;
274
	sigset_t ki_siglist;
312
	sigset_t ki_siglist;
275
	sigset_t ki_sigmask;
313
	sigset_t ki_sigmask;
276
	sigset_t ki_sigignore;
314
	sigset_t ki_sigignore;
Lines 318-323 struct kinfo_proc32 { Link Here
318
	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
356
	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
319
	char	ki_sparestrings[46];
357
	char	ki_sparestrings[46];
320
	int	ki_spareints[KI_NSPARE_INT];
358
	int	ki_spareints[KI_NSPARE_INT];
359
	uint64_t ki_tdev;
321
	int	ki_oncpu;
360
	int	ki_oncpu;
322
	int	ki_lastcpu;
361
	int	ki_lastcpu;
323
	int	ki_tracer;
362
	int	ki_tracer;
(-)b/sys/compat/freebsd32/freebsd32_misc.c (-23 / +189 lines)
Lines 123-129 CTASSERT(sizeof(struct kevent32) == 20); Link Here
123
CTASSERT(sizeof(struct iovec32) == 8);
123
CTASSERT(sizeof(struct iovec32) == 8);
124
CTASSERT(sizeof(struct msghdr32) == 28);
124
CTASSERT(sizeof(struct msghdr32) == 28);
125
#ifndef __mips__
125
#ifndef __mips__
126
CTASSERT(sizeof(struct stat32) == 96);
126
CTASSERT(sizeof(struct stat32) == 208);
127
CTASSERT(sizeof(struct freebsd11_stat32) == 96);
127
#endif
128
#endif
128
CTASSERT(sizeof(struct sigaction32) == 24);
129
CTASSERT(sizeof(struct sigaction32) == 24);
129
130
Lines 448-453 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap) Link Here
448
	return (error);
449
	return (error);
449
}
450
}
450
451
452
#if defined(COMPAT_FREEBSD11)
453
int
454
freebsd11_freebsd32_mknod(struct thread *td,
455
    struct freebsd11_freebsd32_mknod_args *uap)
456
{
457
458
	return (kern_mknodat(td, AT_FDCWD, uap->path, UIO_USERSPACE, uap->mode,
459
	    uap->dev));
460
}
461
462
int
463
freebsd11_freebsd32_mknodat(struct thread *td,
464
    struct freebsd11_freebsd32_mknodat_args *uap)
465
{
466
467
	return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode,
468
	    uap->dev));
469
}
470
#endif /* COMPAT_FREEBSD11 */
471
451
int
472
int
452
freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
473
freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
453
{
474
{
Lines 1519-1524 ofreebsd32_getdirentries(struct thread *td, Link Here
1519
}
1540
}
1520
#endif
1541
#endif
1521
1542
1543
#if defined(COMPAT_FREEBSD11)
1544
int
1545
freebsd11_freebsd32_getdirentries(struct thread *td,
1546
    struct freebsd11_freebsd32_getdirentries_args *uap)
1547
{
1548
	long base;
1549
	int32_t base32;
1550
	int error;
1551
1552
	error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
1553
	    &base, NULL);
1554
	if (error)
1555
		return (error);
1556
	if (uap->basep != NULL) {
1557
		base32 = base;
1558
		error = copyout(&base32, uap->basep, sizeof(int32_t));
1559
	}
1560
	return (error);
1561
}
1562
1563
int
1564
freebsd11_freebsd32_getdents(struct thread *td,
1565
    struct freebsd11_freebsd32_getdents_args *uap)
1566
{
1567
	struct freebsd11_freebsd32_getdirentries_args ap;
1568
1569
	ap.fd = uap->fd;
1570
	ap.buf = uap->buf;
1571
	ap.count = uap->count;
1572
	ap.basep = NULL;
1573
	return (freebsd11_freebsd32_getdirentries(td, &ap));
1574
}
1575
#endif /* COMPAT_FREEBSD11 */
1576
1522
int
1577
int
1523
freebsd32_getdirentries(struct thread *td,
1578
freebsd32_getdirentries(struct thread *td,
1524
    struct freebsd32_getdirentries_args *uap)
1579
    struct freebsd32_getdirentries_args *uap)
Lines 1709-1714 copy_stat(struct stat *in, struct stat32 *out) Link Here
1709
	CP(*in, *out, st_flags);
1764
	CP(*in, *out, st_flags);
1710
	CP(*in, *out, st_gen);
1765
	CP(*in, *out, st_gen);
1711
	TS_CP(*in, *out, st_birthtim);
1766
	TS_CP(*in, *out, st_birthtim);
1767
	out->st_padding0 = 0;
1768
	out->st_padding1 = 0;
1769
#ifdef __STAT32_TIME_T_EXT
1770
	out->st_atim_ext = 0;
1771
	out->st_mtim_ext = 0;
1772
	out->st_ctim_ext = 0;
1773
	out->st_btim_ext = 0;
1774
#endif
1775
	bzero(out->st_spare, sizeof(out->st_spare));
1712
}
1776
}
1713
1777
1714
#ifdef COMPAT_43
1778
#ifdef COMPAT_43
Lines 1734-1755 copy_ostat(struct stat *in, struct ostat32 *out) Link Here
1734
}
1798
}
1735
#endif
1799
#endif
1736
1800
1737
int
1738
freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1739
{
1740
	struct stat sb;
1741
	struct stat32 sb32;
1742
	int error;
1743
1744
	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1745
	    &sb, NULL);
1746
	if (error)
1747
		return (error);
1748
	copy_stat(&sb, &sb32);
1749
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1750
	return (error);
1751
}
1752
1753
#ifdef COMPAT_43
1801
#ifdef COMPAT_43
1754
int
1802
int
1755
ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1803
ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
Lines 1816-1853 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap) Link Here
1816
	return (error);
1864
	return (error);
1817
}
1865
}
1818
1866
1867
#ifdef COMPAT_43
1819
int
1868
int
1820
freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1869
ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1821
{
1870
{
1822
	struct stat sb;
1871
	struct stat sb;
1823
	struct stat32 sb32;
1872
	struct ostat32 sb32;
1824
	int error;
1873
	int error;
1825
1874
1826
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1875
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1827
	    UIO_USERSPACE, &sb, NULL);
1876
	    UIO_USERSPACE, &sb, NULL);
1828
	if (error)
1877
	if (error)
1829
		return (error);
1878
		return (error);
1879
	copy_ostat(&sb, &sb32);
1880
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1881
	return (error);
1882
}
1883
#endif
1884
1885
int
1886
freebsd32_fhstat(struct thread *td, struct freebsd32_fhstat_args *uap)
1887
{
1888
	struct stat sb;
1889
	struct stat32 sb32;
1890
	struct fhandle fh;
1891
	int error;
1892
1893
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
1894
        if (error != 0)
1895
                return (error);
1896
	error = kern_fhstat(td, fh, &sb);
1897
	if (error != 0)
1898
		return (error);
1830
	copy_stat(&sb, &sb32);
1899
	copy_stat(&sb, &sb32);
1900
	error = copyout(&sb32, uap->sb, sizeof (sb32));
1901
	return (error);
1902
}
1903
1904
#if defined(COMPAT_FREEBSD11)
1905
static void
1906
freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
1907
{
1908
1909
	CP(*in, *out, st_ino);
1910
	CP(*in, *out, st_nlink);
1911
	CP(*in, *out, st_dev);
1912
	CP(*in, *out, st_mode);
1913
	CP(*in, *out, st_uid);
1914
	CP(*in, *out, st_gid);
1915
	CP(*in, *out, st_rdev);
1916
	TS_CP(*in, *out, st_atim);
1917
	TS_CP(*in, *out, st_mtim);
1918
	TS_CP(*in, *out, st_ctim);
1919
	CP(*in, *out, st_size);
1920
	CP(*in, *out, st_blocks);
1921
	CP(*in, *out, st_blksize);
1922
	CP(*in, *out, st_flags);
1923
	CP(*in, *out, st_gen);
1924
	TS_CP(*in, *out, st_birthtim);
1925
	out->st_lspare = 0;
1926
	bzero((char *)&out->st_birthtim + sizeof(out->st_birthtim),
1927
	    sizeof(*out) - offsetof(struct freebsd11_stat32,
1928
	    st_birthtim) - sizeof(out->st_birthtim));
1929
}
1930
1931
int
1932
freebsd11_freebsd32_stat(struct thread *td,
1933
    struct freebsd11_freebsd32_stat_args *uap)
1934
{
1935
	struct stat sb;
1936
	struct freebsd11_stat32 sb32;
1937
	int error;
1938
1939
	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1940
	    &sb, NULL);
1941
	if (error != 0)
1942
		return (error);
1943
	freebsd11_cvtstat32(&sb, &sb32);
1831
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1944
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1832
	return (error);
1945
	return (error);
1833
}
1946
}
1834
1947
1835
#ifdef COMPAT_43
1836
int
1948
int
1837
ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1949
freebsd11_freebsd32_fstat(struct thread *td,
1950
    struct freebsd11_freebsd32_fstat_args *uap)
1838
{
1951
{
1839
	struct stat sb;
1952
	struct stat sb;
1840
	struct ostat32 sb32;
1953
	struct freebsd11_stat32 sb32;
1954
	int error;
1955
1956
	error = kern_fstat(td, uap->fd, &sb);
1957
	if (error != 0)
1958
		return (error);
1959
	freebsd11_cvtstat32(&sb, &sb32);
1960
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1961
	return (error);
1962
}
1963
1964
int
1965
freebsd11_freebsd32_fstatat(struct thread *td,
1966
    struct freebsd11_freebsd32_fstatat_args *uap)
1967
{
1968
	struct stat sb;
1969
	struct freebsd11_stat32 sb32;
1970
	int error;
1971
1972
	error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1973
	    &sb, NULL);
1974
	if (error != 0)
1975
		return (error);
1976
	freebsd11_cvtstat32(&sb, &sb32);
1977
	error = copyout(&sb32, uap->buf, sizeof (sb32));
1978
	return (error);
1979
}
1980
1981
int
1982
freebsd11_freebsd32_lstat(struct thread *td,
1983
    struct freebsd11_freebsd32_lstat_args *uap)
1984
{
1985
	struct stat sb;
1986
	struct freebsd11_stat32 sb32;
1841
	int error;
1987
	int error;
1842
1988
1843
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1989
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1844
	    UIO_USERSPACE, &sb, NULL);
1990
	    UIO_USERSPACE, &sb, NULL);
1845
	if (error)
1991
	if (error)
1846
		return (error);
1992
		return (error);
1847
	copy_ostat(&sb, &sb32);
1993
	freebsd11_cvtstat32(&sb, &sb32);
1848
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1994
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1849
	return (error);
1995
	return (error);
1850
}
1996
}
1997
1998
int
1999
freebsd11_freebsd32_fhstat(struct thread *td,
2000
    struct freebsd11_freebsd32_fhstat_args *uap)
2001
{
2002
	struct stat sb;
2003
	struct freebsd11_stat32 sb32;
2004
	struct fhandle fh;
2005
	int error;
2006
2007
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2008
        if (error != 0)
2009
                return (error);
2010
	error = kern_fhstat(td, fh, &sb);
2011
	if (error != 0)
2012
		return (error);
2013
	freebsd11_cvtstat32(&sb, &sb32);
2014
	error = copyout(&sb32, uap->sb, sizeof (sb32));
2015
	return (error);
2016
}
1851
#endif
2017
#endif
1852
2018
1853
int
2019
int
(-)b/sys/compat/freebsd32/syscalls.master (-25 / +52 lines)
Lines 13-19 Link Here
13
;		case where the event exists, but we don't want auditing, the
13
;		case where the event exists, but we don't want auditing, the
14
;		event should be #defined to AUE_NULL in audit_kevents.h.
14
;		event should be #defined to AUE_NULL in audit_kevents.h.
15
;	type	one of STD, OBSOL, UNIMPL, COMPAT, COMPAT4, COMPAT6,
15
;	type	one of STD, OBSOL, UNIMPL, COMPAT, COMPAT4, COMPAT6,
16
;		COMPAT7, NODEF, NOARGS, NOPROTO, NOSTD
16
;		COMPAT7, COMPAT11, NODEF, NOARGS, NOPROTO, NOSTD
17
;		The COMPAT* options may be combined with one or more NO*
17
;		The COMPAT* options may be combined with one or more NO*
18
;		options separated by '|' with no spaces (e.g. COMPAT|NOARGS)
18
;		options separated by '|' with no spaces (e.g. COMPAT|NOARGS)
19
;	name	psuedo-prototype of syscall routine
19
;	name	psuedo-prototype of syscall routine
Lines 30-35 Link Here
30
;	COMPAT6	included on COMPAT6 #ifdef (FreeBSD 6 compat)
30
;	COMPAT6	included on COMPAT6 #ifdef (FreeBSD 6 compat)
31
;	COMPAT7	included on COMPAT7 #ifdef (FreeBSD 7 compat)
31
;	COMPAT7	included on COMPAT7 #ifdef (FreeBSD 7 compat)
32
;	COMPAT10 included on COMPAT10 #ifdef (FreeBSD 10 compat)
32
;	COMPAT10 included on COMPAT10 #ifdef (FreeBSD 10 compat)
33
;	COMPAT11 included on COMPAT11 #ifdef (FreeBSD 11 compat)
33
;	OBSOL	obsolete, not included in system, only specifies name
34
;	OBSOL	obsolete, not included in system, only specifies name
34
;	UNIMPL	not implemented, placeholder only
35
;	UNIMPL	not implemented, placeholder only
35
;	NOSTD	implemented but as a lkm that can be statically
36
;	NOSTD	implemented but as a lkm that can be statically
Lines 82-88 Link Here
82
11	AUE_NULL	OBSOL	execv
83
11	AUE_NULL	OBSOL	execv
83
12	AUE_CHDIR	NOPROTO	{ int chdir(char *path); }
84
12	AUE_CHDIR	NOPROTO	{ int chdir(char *path); }
84
13	AUE_FCHDIR	NOPROTO	{ int fchdir(int fd); }
85
13	AUE_FCHDIR	NOPROTO	{ int fchdir(int fd); }
85
14	AUE_MKNOD	NOPROTO	{ int mknod(char *path, int mode, int dev); }
86
14	AUE_MKNOD	COMPAT11 { int freebsd32_mknod(char *path, \
87
					int mode, int dev); }
86
15	AUE_CHMOD	NOPROTO	{ int chmod(char *path, int mode); }
88
15	AUE_CHMOD	NOPROTO	{ int chmod(char *path, int mode); }
87
16	AUE_CHOWN	NOPROTO	{ int chown(char *path, int uid, int gid); }
89
16	AUE_CHOWN	NOPROTO	{ int chown(char *path, int uid, int gid); }
88
17	AUE_NULL	NOPROTO	{ int obreak(char *nsize); } break \
90
17	AUE_NULL	NOPROTO	{ int obreak(char *nsize); } break \
Lines 348-359 Link Here
348
185	AUE_NULL	UNIMPL	lfs_markv
350
185	AUE_NULL	UNIMPL	lfs_markv
349
186	AUE_NULL	UNIMPL	lfs_segclean
351
186	AUE_NULL	UNIMPL	lfs_segclean
350
187	AUE_NULL	UNIMPL	lfs_segwait
352
187	AUE_NULL	UNIMPL	lfs_segwait
351
188	AUE_STAT	STD	{ int freebsd32_stat(char *path, \
353
188	AUE_STAT	COMPAT11 { int freebsd32_stat(char *path, \
352
				    struct stat32 *ub); }
354
				    struct freebsd11_stat32 *ub); }
353
189	AUE_FSTAT	STD	{ int freebsd32_fstat(int fd, \
355
189	AUE_FSTAT	COMPAT11 { int freebsd32_fstat(int fd, \
354
				    struct stat32 *ub); }
356
				    struct freebsd11_stat32 *ub); }
355
190	AUE_LSTAT	STD	{ int freebsd32_lstat(char *path, \
357
190	AUE_LSTAT	COMPAT11 { int freebsd32_lstat(char *path, \
356
				    struct stat32 *ub); }
358
				    struct freebsd11_stat32 *ub); }
357
191	AUE_PATHCONF	NOPROTO	{ int pathconf(char *path, int name); }
359
191	AUE_PATHCONF	NOPROTO	{ int pathconf(char *path, int name); }
358
192	AUE_FPATHCONF	NOPROTO	{ int fpathconf(int fd, int name); }
360
192	AUE_FPATHCONF	NOPROTO	{ int fpathconf(int fd, int name); }
359
193	AUE_NULL	UNIMPL	nosys
361
193	AUE_NULL	UNIMPL	nosys
Lines 363-369 Link Here
363
195	AUE_SETRLIMIT	NOPROTO	{ int setrlimit(u_int which, \
365
195	AUE_SETRLIMIT	NOPROTO	{ int setrlimit(u_int which, \
364
				    struct rlimit *rlp); } setrlimit \
366
				    struct rlimit *rlp); } setrlimit \
365
				    __setrlimit_args int
367
				    __setrlimit_args int
366
196	AUE_GETDIRENTRIES	STD	{ int freebsd32_getdirentries(int fd, \
368
196	AUE_GETDIRENTRIES COMPAT11 { int freebsd32_getdirentries(int fd, \
367
				    char *buf, u_int count, int32_t *basep); }
369
				    char *buf, u_int count, int32_t *basep); }
368
197	AUE_MMAP	COMPAT6	{ caddr_t freebsd32_mmap(caddr_t addr, \
370
197	AUE_MMAP	COMPAT6	{ caddr_t freebsd32_mmap(caddr_t addr, \
369
				    size_t len, int prot, int flags, int fd, \
371
				    size_t len, int prot, int flags, int fd, \
Lines 501-508 Link Here
501
269	AUE_NULL	UNIMPL	nosys
503
269	AUE_NULL	UNIMPL	nosys
502
270	AUE_NULL	UNIMPL	nosys
504
270	AUE_NULL	UNIMPL	nosys
503
271	AUE_NULL	UNIMPL	nosys
505
271	AUE_NULL	UNIMPL	nosys
504
272	AUE_O_GETDENTS	NOPROTO	{ int getdents(int fd, char *buf, \
506
272	AUE_O_GETDENTS	COMPAT11 { int freebsd32_getdents(int fd, char *buf, \
505
				    size_t count); }
507
				    int count); }
506
273	AUE_NULL	UNIMPL	nosys
508
273	AUE_NULL	UNIMPL	nosys
507
274	AUE_LCHMOD	NOPROTO	{ int lchmod(char *path, mode_t mode); }
509
274	AUE_LCHMOD	NOPROTO	{ int lchmod(char *path, mode_t mode); }
508
275	AUE_LCHOWN	NOPROTO	{ int lchown(char *path, uid_t uid, \
510
275	AUE_LCHOWN	NOPROTO	{ int lchown(char *path, uid_t uid, \
Lines 512-520 Link Here
512
				    struct timeval32 *tptr); }
514
				    struct timeval32 *tptr); }
513
277	AUE_MSYNC	NOPROTO	{ int msync(void *addr, size_t len, \
515
277	AUE_MSYNC	NOPROTO	{ int msync(void *addr, size_t len, \
514
				    int flags); } netbsd_msync msync_args int
516
				    int flags); } netbsd_msync msync_args int
515
278	AUE_STAT	NOPROTO	{ int nstat(char *path, struct nstat *ub); }
517
278	AUE_STAT  COMPAT11|NOPROTO { int nstat(char *path, struct nstat *ub); }
516
279	AUE_FSTAT	NOPROTO	{ int nfstat(int fd, struct nstat *sb); }
518
279	AUE_FSTAT COMPAT11|NOPROTO { int nfstat(int fd, struct nstat *sb); }
517
280	AUE_LSTAT	NOPROTO	{ int nlstat(char *path, struct nstat *ub); }
519
280	AUE_LSTAT COMPAT11|NOPROTO { int nlstat(char *path, struct nstat *ub); }
518
281	AUE_NULL	UNIMPL	nosys
520
281	AUE_NULL	UNIMPL	nosys
519
282	AUE_NULL	UNIMPL	nosys
521
282	AUE_NULL	UNIMPL	nosys
520
283	AUE_NULL	UNIMPL	nosys
522
283	AUE_NULL	UNIMPL	nosys
Lines 544-551 Link Here
544
				    struct statfs32 *buf); }
546
				    struct statfs32 *buf); }
545
298	AUE_FHOPEN	NOPROTO	{ int fhopen(const struct fhandle *u_fhp, \
547
298	AUE_FHOPEN	NOPROTO	{ int fhopen(const struct fhandle *u_fhp, \
546
			 	    int flags); }
548
			 	    int flags); }
547
299	AUE_FHSTAT	NOPROTO	{ int fhstat(const struct fhandle *u_fhp, \
549
299	AUE_FHSTAT	COMPAT11 { int freebsd32_fhstat( \
548
				    struct stat *sb); }
550
				    const struct fhandle *u_fhp, \
551
				    struct freebsd11_stat32 *sb); }
549
; syscall numbers for FreeBSD
552
; syscall numbers for FreeBSD
550
300	AUE_NULL	NOPROTO	{ int modnext(int modid); }
553
300	AUE_NULL	NOPROTO	{ int modnext(int modid); }
551
301	AUE_NULL	STD	{ int freebsd32_modstat(int modid, \
554
301	AUE_NULL	STD	{ int freebsd32_modstat(int modid, \
Lines 713-725 Link Here
713
				    size_t nbytes, struct sf_hdtr32 *hdtr, \
716
				    size_t nbytes, struct sf_hdtr32 *hdtr, \
714
				    off_t *sbytes, int flags); }
717
				    off_t *sbytes, int flags); }
715
394	AUE_NULL	UNIMPL	mac_syscall
718
394	AUE_NULL	UNIMPL	mac_syscall
716
395	AUE_GETFSSTAT	NOPROTO	{ int getfsstat(struct statfs *buf, \
719
395	AUE_GETFSSTAT	COMPAT11|NOPROTO	{ int getfsstat( \
720
				    struct freebsd11_statfs *buf, \
717
				    long bufsize, int mode); }
721
				    long bufsize, int mode); }
718
396	AUE_STATFS	NOPROTO	{ int statfs(char *path, \
722
396	AUE_STATFS	COMPAT11|NOPROTO	{ int statfs(char *path, \
719
				    struct statfs *buf); }
720
397	AUE_FSTATFS	NOPROTO	{ int fstatfs(int fd, struct statfs *buf); }
721
398	AUE_FHSTATFS	NOPROTO	{ int fhstatfs(const struct fhandle *u_fhp, \
722
				    struct statfs *buf); }
723
				    struct statfs *buf); }
724
397	AUE_FSTATFS	COMPAT11|NOPROTO	{ int fstatfs(int fd, \
725
				    struct freebsd11_statfs *buf); }
726
398	AUE_FHSTATFS	COMPAT11|NOPROTO	{ int fhstatfs( \
727
				    const struct fhandle *u_fhp, \
728
				    struct freebsd11_statfs *buf); }
723
399	AUE_NULL	UNIMPL	nosys
729
399	AUE_NULL	UNIMPL	nosys
724
400	AUE_SEMCLOSE	NOSTD|NOPROTO	{ int ksem_close(semid_t id); }
730
400	AUE_SEMCLOSE	NOSTD|NOPROTO	{ int ksem_close(semid_t id); }
725
401	AUE_SEMPOST	NOSTD|NOPROTO	{ int ksem_post(semid_t id); }
731
401	AUE_SEMPOST	NOSTD|NOPROTO	{ int ksem_post(semid_t id); }
Lines 936-943 Link Here
936
				    gid_t gid, int flag); }
942
				    gid_t gid, int flag); }
937
492	AUE_FEXECVE	STD	{ int freebsd32_fexecve(int fd, \
943
492	AUE_FEXECVE	STD	{ int freebsd32_fexecve(int fd, \
938
				    uint32_t *argv, uint32_t *envv); }
944
				    uint32_t *argv, uint32_t *envv); }
939
493	AUE_FSTATAT	STD	{ int freebsd32_fstatat(int fd, char *path, \
945
493	AUE_FSTATAT	COMPAT11 { int freebsd32_fstatat(int fd, \
940
				    struct stat *buf, int flag); }
946
				    char *path, struct freebsd11_stat32 *buf, \
947
				    int flag); }
941
494	AUE_FUTIMESAT	STD	{ int freebsd32_futimesat(int fd, char *path, \
948
494	AUE_FUTIMESAT	STD	{ int freebsd32_futimesat(int fd, char *path, \
942
				    struct timeval *times); }
949
				    struct timeval *times); }
943
495	AUE_LINKAT	NOPROTO	{ int linkat(int fd1, char *path1, int fd2, \
950
495	AUE_LINKAT	NOPROTO	{ int linkat(int fd1, char *path1, int fd2, \
Lines 946-953 Link Here
946
				    mode_t mode); }
953
				    mode_t mode); }
947
497	AUE_MKFIFOAT	NOPROTO	{ int mkfifoat(int fd, char *path, \
954
497	AUE_MKFIFOAT	NOPROTO	{ int mkfifoat(int fd, char *path, \
948
				    mode_t mode); }
955
				    mode_t mode); }
949
498	AUE_MKNODAT	NOPROTO	{ int mknodat(int fd, char *path, \
956
498	AUE_MKNODAT	COMPAT11 { int freebsd32_mknodat(int fd, char *path, \
950
				    mode_t mode, dev_t dev); }
957
				    mode_t mode, uint32_t dev); }
951
499	AUE_OPENAT_RWTC	NOPROTO	{ int openat(int fd, char *path, int flag, \
958
499	AUE_OPENAT_RWTC	NOPROTO	{ int openat(int fd, char *path, int flag, \
952
				    mode_t mode); }
959
				    mode_t mode); }
953
500	AUE_READLINKAT	NOPROTO	{ int readlinkat(int fd, char *path, char *buf, \
960
500	AUE_READLINKAT	NOPROTO	{ int readlinkat(int fd, char *path, char *buf, \
Lines 1084-1086 Link Here
1084
				    id_t id, \
1091
				    id_t id, \
1085
				    const struct vm_domain_policy *policy); }
1092
				    const struct vm_domain_policy *policy); }
1086
550	AUE_FSYNC	NOPROTO	{ int fdatasync(int fd); }
1093
550	AUE_FSYNC	NOPROTO	{ int fdatasync(int fd); }
1094
551	AUE_FSTAT	STD	{ int freebsd32_fstat(int fd, \
1095
				    struct stat32 *ub); }
1096
552	AUE_FSTATAT	STD	{ int freebsd32_fstatat(int fd, \
1097
				    char *path, struct stat32 *buf, \
1098
				    int flag); }
1099
553	AUE_FHSTAT	STD	{ int freebsd32_fhstat( \
1100
				    const struct fhandle *u_fhp, \
1101
				    struct stat32 *sb); }
1102
554	AUE_GETDIRENTRIES STD	{ ssize_t freebsd32_getdirentries( \
1103
				    int fd, char *buf, size_t count, \
1104
				    int32_t *basep); }
1105
555	AUE_STATFS	NOPROTO	{ int statfs(char *path, \
1106
				    struct statfs32 *buf); }
1107
556	AUE_FSTATFS	NOPROTO	{ int fstatfs(int fd, struct statfs32 *buf); }
1108
557	AUE_GETFSSTAT	NOPROTO	{ int getfsstat(struct statfs32 *buf, \
1109
				    long bufsize, int mode); }
1110
558	AUE_FHSTATFS	NOPROTO	{ int fhstatfs(const struct fhandle *u_fhp, \
1111
				    struct statfs32 *buf); }
1112
559	AUE_MKNODAT	NOPROTO	{ int mknodat(int fd, char *path, mode_t mode, \
1113
				    dev_t dev); }
(-)b/sys/compat/linux/linux_file.c (-9 / +13 lines)
Lines 1087-1106 int Link Here
1087
linux_mount(struct thread *td, struct linux_mount_args *args)
1087
linux_mount(struct thread *td, struct linux_mount_args *args)
1088
{
1088
{
1089
	char fstypename[MFSNAMELEN];
1089
	char fstypename[MFSNAMELEN];
1090
	char mntonname[MNAMELEN], mntfromname[MNAMELEN];
1090
	char *mntonname, *mntfromname;
1091
	int error;
1091
	int error, fsflags;
1092
	int fsflags;
1093
1092
1093
	mntonname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
1094
	mntfromname = malloc(MNAMELEN, M_TEMP, M_WAITOK);
1094
	error = copyinstr(args->filesystemtype, fstypename, MFSNAMELEN - 1,
1095
	error = copyinstr(args->filesystemtype, fstypename, MFSNAMELEN - 1,
1095
	    NULL);
1096
	    NULL);
1096
	if (error)
1097
	if (error != 0)
1097
		return (error);
1098
		goto out;
1098
	error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL);
1099
	error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL);
1099
	if (error)
1100
	if (error != 0)
1100
		return (error);
1101
		goto out;
1101
	error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL);
1102
	error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL);
1102
	if (error)
1103
	if (error != 0)
1103
		return (error);
1104
		goto out;
1104
1105
1105
#ifdef DEBUG
1106
#ifdef DEBUG
1106
	if (ldebug(mount))
1107
	if (ldebug(mount))
Lines 1138-1143 linux_mount(struct thread *td, struct linux_mount_args *args) Link Here
1138
	    "fspath", mntonname,
1139
	    "fspath", mntonname,
1139
	    "from", mntfromname,
1140
	    "from", mntfromname,
1140
	    NULL);
1141
	    NULL);
1142
out:
1143
	free(mntonname, M_TEMP);
1144
	free(mntfromname, M_TEMP);
1141
	return (error);
1145
	return (error);
1142
}
1146
}
1143
1147
(-)b/sys/dev/snp/snp.c (+8 lines)
Lines 60-65 SX_SYSINIT(snp_register_lock, &snp_register_lock, Link Here
60
#define	SNP_UNLOCK()	sx_xunlock(&snp_register_lock)
60
#define	SNP_UNLOCK()	sx_xunlock(&snp_register_lock)
61
#endif
61
#endif
62
62
63
#define	SNPGTYY_32DEV	_IOR('T', 89, uint32_t)
64
63
/*
65
/*
64
 * There is no need to have a big input buffer. In most typical setups,
66
 * There is no need to have a big input buffer. In most typical setups,
65
 * we won't inject much data into the TTY, because users can't type
67
 * we won't inject much data into the TTY, because users can't type
Lines 275-280 snp_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, Link Here
275
		else
277
		else
276
			*(dev_t *)data = tty_udev(ss->snp_tty);
278
			*(dev_t *)data = tty_udev(ss->snp_tty);
277
		return (0);
279
		return (0);
280
	case SNPGTYY_32DEV:
281
		if (ss->snp_tty == NULL)
282
			*(uint32_t *)data = -1;
283
		else
284
			*(uint32_t *)data = tty_udev(ss->snp_tty); /* trunc */
285
		return (0);
278
	case FIONREAD:
286
	case FIONREAD:
279
		tp = ss->snp_tty;
287
		tp = ss->snp_tty;
280
		if (tp != NULL) {
288
		if (tp != NULL) {
(-)b/sys/fs/devfs/devfs_devs.c (-1 / +13 lines)
Lines 28-33 Link Here
28
 * $FreeBSD$
28
 * $FreeBSD$
29
 */
29
 */
30
30
31
#include "opt_compat.h"
32
31
#include <sys/param.h>
33
#include <sys/param.h>
32
#include <sys/systm.h>
34
#include <sys/systm.h>
33
#include <sys/conf.h>
35
#include <sys/conf.h>
Lines 80-89 sysctl_devname(SYSCTL_HANDLER_ARGS) Link Here
80
{
82
{
81
	int error;
83
	int error;
82
	dev_t ud;
84
	dev_t ud;
85
#ifdef COMPAT_FREEBSD11
86
	uint32_t ud_compat;
87
#endif
83
	struct cdev_priv *cdp;
88
	struct cdev_priv *cdp;
84
	struct cdev *dev;
89
	struct cdev *dev;
85
90
86
	error = SYSCTL_IN(req, &ud, sizeof (ud));
91
#ifdef COMPAT_FREEBSD11
92
	if (req->newlen == sizeof(ud_compat)) {
93
		error = SYSCTL_IN(req, &ud_compat, sizeof(ud_compat));
94
		if (error == 0)
95
			ud = ud_compat == (uint32_t)NODEV ? NODEV : ud_compat;
96
	} else
97
#endif
98
		error = SYSCTL_IN(req, &ud, sizeof (ud));
87
	if (error)
99
	if (error)
88
		return (error);
100
		return (error);
89
	if (ud == NODEV)
101
	if (ud == NODEV)
(-)b/sys/fs/devfs/devfs_vnops.c (+1 lines)
Lines 1315-1320 devfs_readdir(struct vop_readdir_args *ap) Link Here
1315
		else
1315
		else
1316
			de = dd;
1316
			de = dd;
1317
		dp = dd->de_dirent;
1317
		dp = dd->de_dirent;
1318
		MPASS(dp->d_reclen == GENERIC_DIRSIZ(dp));
1318
		if (dp->d_reclen > uio->uio_resid)
1319
		if (dp->d_reclen > uio->uio_resid)
1319
			break;
1320
			break;
1320
		dp->d_fileno = de->de_inode;
1321
		dp->d_fileno = de->de_inode;
(-)b/sys/fs/fdescfs/fdesc_vnops.c (-1 / +1 lines)
Lines 485-491 fdesc_setattr(struct vop_setattr_args *ap) Link Here
485
	return (error);
485
	return (error);
486
}
486
}
487
487
488
#define UIO_MX 16
488
#define UIO_MX _GENERIC_DIRLEN(10) /* number of symbols in INT_MAX printout */
489
489
490
static int
490
static int
491
fdesc_readdir(struct vop_readdir_args *ap)
491
fdesc_readdir(struct vop_readdir_args *ap)
(-)b/sys/fs/nandfs/nandfs_fs.h (-1 / +1 lines)
Lines 537-543 struct nandfs_bdesc { Link Here
537
537
538
#ifndef _KERNEL
538
#ifndef _KERNEL
539
#ifndef	MNAMELEN
539
#ifndef	MNAMELEN
540
#define	MNAMELEN	88
540
#define	MNAMELEN	1024
541
#endif
541
#endif
542
#endif
542
#endif
543
543
(-)b/sys/fs/nfs/nfsport.h (-6 lines)
Lines 730-741 int nfsmsleep(void *, void *, int, const char *, struct timespec *); Link Here
730
#define	NFSMINOR(d)		minor(d)
730
#define	NFSMINOR(d)		minor(d)
731
731
732
/*
732
/*
733
 * Define this to be the macro that returns the minimum size required
734
 * for a directory entry.
735
 */
736
#define	DIRENT_SIZE(dp)		GENERIC_DIRSIZ(dp)
737
738
/*
739
 * The vnode tag for nfsv4root.
733
 * The vnode tag for nfsv4root.
740
 */
734
 */
741
#define	VT_NFSV4ROOT		"nfsv4root"
735
#define	VT_NFSV4ROOT		"nfsv4root"
(-)b/sys/fs/nfsclient/nfs_clrpcops.c (-29 / +39 lines)
Lines 72-78 short nfsv4_cbport = NFSV4_CBPORT; Link Here
72
int nfstest_openallsetattr = 0;
72
int nfstest_openallsetattr = 0;
73
#endif	/* !APPLEKEXT */
73
#endif	/* !APPLEKEXT */
74
74
75
#define	DIRHDSIZ	(sizeof (struct dirent) - (MAXNAMLEN + 1))
75
#define	DIRHDSIZ	offsetof(struct dirent, d_name)
76
76
77
/*
77
/*
78
 * nfscl_getsameserver() can return one of three values:
78
 * nfscl_getsameserver() can return one of three values:
Lines 2861-2877 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2861
			if (error)
2861
			if (error)
2862
			    return (error);
2862
			    return (error);
2863
			nd->nd_mrep = NULL;
2863
			nd->nd_mrep = NULL;
2864
			dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
2864
			dp = (struct dirent *)uio_iov_base(uiop);
2865
			dp->d_off = 0;
2865
			dp->d_type = DT_DIR;
2866
			dp->d_type = DT_DIR;
2866
			dp->d_fileno = dotfileid;
2867
			dp->d_fileno = dotfileid;
2867
			dp->d_namlen = 1;
2868
			dp->d_namlen = 1;
2869
			*((uint64_t *)dp->d_name) = 0;	/* Zero pad it. */
2868
			dp->d_name[0] = '.';
2870
			dp->d_name[0] = '.';
2869
			dp->d_name[1] = '\0';
2871
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
2870
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
2871
			/*
2872
			/*
2872
			 * Just make these offset cookie 0.
2873
			 * Just make these offset cookie 0.
2873
			 */
2874
			 */
2874
			tl = (u_int32_t *)&dp->d_name[4];
2875
			tl = (u_int32_t *)&dp->d_name[8];
2875
			*tl++ = 0;
2876
			*tl++ = 0;
2876
			*tl = 0;
2877
			*tl = 0;
2877
			blksiz += dp->d_reclen;
2878
			blksiz += dp->d_reclen;
Lines 2879-2896 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2879
			uiop->uio_offset += dp->d_reclen;
2880
			uiop->uio_offset += dp->d_reclen;
2880
			uio_iov_base_add(uiop, dp->d_reclen);
2881
			uio_iov_base_add(uiop, dp->d_reclen);
2881
			uio_iov_len_add(uiop, -(dp->d_reclen));
2882
			uio_iov_len_add(uiop, -(dp->d_reclen));
2882
			dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
2883
			dp = (struct dirent *)uio_iov_base(uiop);
2884
			dp->d_off = 0;
2883
			dp->d_type = DT_DIR;
2885
			dp->d_type = DT_DIR;
2884
			dp->d_fileno = dotdotfileid;
2886
			dp->d_fileno = dotdotfileid;
2885
			dp->d_namlen = 2;
2887
			dp->d_namlen = 2;
2888
			*((uint64_t *)dp->d_name) = 0;
2886
			dp->d_name[0] = '.';
2889
			dp->d_name[0] = '.';
2887
			dp->d_name[1] = '.';
2890
			dp->d_name[1] = '.';
2888
			dp->d_name[2] = '\0';
2891
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
2889
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
2890
			/*
2892
			/*
2891
			 * Just make these offset cookie 0.
2893
			 * Just make these offset cookie 0.
2892
			 */
2894
			 */
2893
			tl = (u_int32_t *)&dp->d_name[4];
2895
			tl = (u_int32_t *)&dp->d_name[8];
2894
			*tl++ = 0;
2896
			*tl++ = 0;
2895
			*tl = 0;
2897
			*tl = 0;
2896
			blksiz += dp->d_reclen;
2898
			blksiz += dp->d_reclen;
Lines 2987-2997 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2987
				error = EBADRPC;
2989
				error = EBADRPC;
2988
				goto nfsmout;
2990
				goto nfsmout;
2989
			}
2991
			}
2990
			tlen = NFSM_RNDUP(len);
2992
			tlen = roundup2(len, 8);
2991
			if (tlen == len)
2993
			if (tlen == len)
2992
				tlen += 4;  /* To ensure null termination */
2994
				tlen += 8;  /* To ensure null termination. */
2993
			left = DIRBLKSIZ - blksiz;
2995
			left = DIRBLKSIZ - blksiz;
2994
			if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > left) {
2996
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER > left) {
2995
				dp->d_reclen += left;
2997
				dp->d_reclen += left;
2996
				uio_iov_base_add(uiop, left);
2998
				uio_iov_base_add(uiop, left);
2997
				uio_iov_len_add(uiop, -(left));
2999
				uio_iov_len_add(uiop, -(left));
Lines 2999-3010 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2999
				uiop->uio_offset += left;
3001
				uiop->uio_offset += left;
3000
				blksiz = 0;
3002
				blksiz = 0;
3001
			}
3003
			}
3002
			if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop))
3004
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER >
3005
			    uio_uio_resid(uiop))
3003
				bigenough = 0;
3006
				bigenough = 0;
3004
			if (bigenough) {
3007
			if (bigenough) {
3005
				dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
3008
				dp = (struct dirent *)uio_iov_base(uiop);
3009
				dp->d_off = 0;
3006
				dp->d_namlen = len;
3010
				dp->d_namlen = len;
3007
				dp->d_reclen = tlen + DIRHDSIZ + NFSX_HYPER;
3011
				dp->d_reclen = _GENERIC_DIRLEN(len) +
3012
				    NFSX_HYPER;
3008
				dp->d_type = DT_UNKNOWN;
3013
				dp->d_type = DT_UNKNOWN;
3009
				blksiz += dp->d_reclen;
3014
				blksiz += dp->d_reclen;
3010
				if (blksiz == DIRBLKSIZ)
3015
				if (blksiz == DIRBLKSIZ)
Lines 3016-3022 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3016
				error = nfsm_mbufuio(nd, uiop, len);
3021
				error = nfsm_mbufuio(nd, uiop, len);
3017
				if (error)
3022
				if (error)
3018
					goto nfsmout;
3023
					goto nfsmout;
3019
				cp = CAST_DOWN(caddr_t, uio_iov_base(uiop));
3024
				cp = uio_iov_base(uiop);
3020
				tlen -= len;
3025
				tlen -= len;
3021
				*cp = '\0';	/* null terminate */
3026
				*cp = '\0';	/* null terminate */
3022
				cp += tlen;	/* points to cookie storage */
3027
				cp += tlen;	/* points to cookie storage */
Lines 3131-3138 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3131
	/*
3136
	/*
3132
	 * Add extra empty records to any remaining DIRBLKSIZ chunks.
3137
	 * Add extra empty records to any remaining DIRBLKSIZ chunks.
3133
	 */
3138
	 */
3134
	while (uio_uio_resid(uiop) > 0 && ((size_t)(uio_uio_resid(uiop))) != tresid) {
3139
	while (uio_uio_resid(uiop) > 0 && uio_uio_resid(uiop) != tresid) {
3135
		dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
3140
		dp = (struct dirent *)uio_iov_base(uiop);
3136
		dp->d_type = DT_UNKNOWN;
3141
		dp->d_type = DT_UNKNOWN;
3137
		dp->d_fileno = 0;
3142
		dp->d_fileno = 0;
3138
		dp->d_namlen = 0;
3143
		dp->d_namlen = 0;
Lines 3289-3304 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3289
			    return (error);
3294
			    return (error);
3290
			nd->nd_mrep = NULL;
3295
			nd->nd_mrep = NULL;
3291
			dp = (struct dirent *)uio_iov_base(uiop);
3296
			dp = (struct dirent *)uio_iov_base(uiop);
3297
			dp->d_off = 0;
3292
			dp->d_type = DT_DIR;
3298
			dp->d_type = DT_DIR;
3293
			dp->d_fileno = dotfileid;
3299
			dp->d_fileno = dotfileid;
3294
			dp->d_namlen = 1;
3300
			dp->d_namlen = 1;
3301
			*((uint64_t *)dp->d_name) = 0;	/* Zero pad it. */
3295
			dp->d_name[0] = '.';
3302
			dp->d_name[0] = '.';
3296
			dp->d_name[1] = '\0';
3303
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
3297
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
3298
			/*
3304
			/*
3299
			 * Just make these offset cookie 0.
3305
			 * Just make these offset cookie 0.
3300
			 */
3306
			 */
3301
			tl = (u_int32_t *)&dp->d_name[4];
3307
			tl = (u_int32_t *)&dp->d_name[8];
3302
			*tl++ = 0;
3308
			*tl++ = 0;
3303
			*tl = 0;
3309
			*tl = 0;
3304
			blksiz += dp->d_reclen;
3310
			blksiz += dp->d_reclen;
Lines 3307-3323 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3307
			uio_iov_base_add(uiop, dp->d_reclen);
3313
			uio_iov_base_add(uiop, dp->d_reclen);
3308
			uio_iov_len_add(uiop, -(dp->d_reclen));
3314
			uio_iov_len_add(uiop, -(dp->d_reclen));
3309
			dp = (struct dirent *)uio_iov_base(uiop);
3315
			dp = (struct dirent *)uio_iov_base(uiop);
3316
			dp->d_off = 0;
3310
			dp->d_type = DT_DIR;
3317
			dp->d_type = DT_DIR;
3311
			dp->d_fileno = dotdotfileid;
3318
			dp->d_fileno = dotdotfileid;
3312
			dp->d_namlen = 2;
3319
			dp->d_namlen = 2;
3320
			*((uint64_t *)dp->d_name) = 0;
3313
			dp->d_name[0] = '.';
3321
			dp->d_name[0] = '.';
3314
			dp->d_name[1] = '.';
3322
			dp->d_name[1] = '.';
3315
			dp->d_name[2] = '\0';
3323
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
3316
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
3317
			/*
3324
			/*
3318
			 * Just make these offset cookie 0.
3325
			 * Just make these offset cookie 0.
3319
			 */
3326
			 */
3320
			tl = (u_int32_t *)&dp->d_name[4];
3327
			tl = (u_int32_t *)&dp->d_name[8];
3321
			*tl++ = 0;
3328
			*tl++ = 0;
3322
			*tl = 0;
3329
			*tl = 0;
3323
			blksiz += dp->d_reclen;
3330
			blksiz += dp->d_reclen;
Lines 3395-3405 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3395
				error = EBADRPC;
3402
				error = EBADRPC;
3396
				goto nfsmout;
3403
				goto nfsmout;
3397
			}
3404
			}
3398
			tlen = NFSM_RNDUP(len);
3405
			tlen = roundup2(len, 8);
3399
			if (tlen == len)
3406
			if (tlen == len)
3400
				tlen += 4;  /* To ensure null termination */
3407
				tlen += 8;  /* To ensure null termination. */
3401
			left = DIRBLKSIZ - blksiz;
3408
			left = DIRBLKSIZ - blksiz;
3402
			if ((tlen + DIRHDSIZ + NFSX_HYPER) > left) {
3409
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER > left) {
3403
				dp->d_reclen += left;
3410
				dp->d_reclen += left;
3404
				uio_iov_base_add(uiop, left);
3411
				uio_iov_base_add(uiop, left);
3405
				uio_iov_len_add(uiop, -(left));
3412
				uio_iov_len_add(uiop, -(left));
Lines 3407-3418 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3407
				uiop->uio_offset += left;
3414
				uiop->uio_offset += left;
3408
				blksiz = 0;
3415
				blksiz = 0;
3409
			}
3416
			}
3410
			if ((tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop))
3417
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER >
3418
			    uio_uio_resid(uiop))
3411
				bigenough = 0;
3419
				bigenough = 0;
3412
			if (bigenough) {
3420
			if (bigenough) {
3413
				dp = (struct dirent *)uio_iov_base(uiop);
3421
				dp = (struct dirent *)uio_iov_base(uiop);
3422
				dp->d_off = 0;
3414
				dp->d_namlen = len;
3423
				dp->d_namlen = len;
3415
				dp->d_reclen = tlen + DIRHDSIZ + NFSX_HYPER;
3424
				dp->d_reclen = _GENERIC_DIRLEN(len) +
3425
				    NFSX_HYPER;
3416
				dp->d_type = DT_UNKNOWN;
3426
				dp->d_type = DT_UNKNOWN;
3417
				blksiz += dp->d_reclen;
3427
				blksiz += dp->d_reclen;
3418
				if (blksiz == DIRBLKSIZ)
3428
				if (blksiz == DIRBLKSIZ)
(-)b/sys/fs/nfsclient/nfs_clvnops.c (-2 lines)
Lines 207-214 static int nfs_renameit(struct vnode *sdvp, struct vnode *svp, Link Here
207
/*
207
/*
208
 * Global variables
208
 * Global variables
209
 */
209
 */
210
#define	DIRHDSIZ	(sizeof (struct dirent) - (MAXNAMLEN + 1))
211
212
SYSCTL_DECL(_vfs_nfs);
210
SYSCTL_DECL(_vfs_nfs);
213
211
214
static int	nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
212
static int	nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
(-)b/sys/fs/nfsserver/nfs_nfsdport.c (-11 / +28 lines)
Lines 2020-2036 again: Link Here
2020
	}
2020
	}
2021
2021
2022
	/*
2022
	/*
2023
	 * For now ZFS requires VOP_LOOKUP as a workaround.  Until ino_t is changed
2023
	 * Check to see if entries in this directory can be safely acquired
2024
	 * to 64 bit type a ZFS filesystem with over 1 billion files in it
2024
	 * via VFS_VGET() or if a switch to VOP_LOOKUP() is required.
2025
	 * will suffer from 64bit -> 32bit truncation.
2025
	 * ZFS snapshot directories need VOP_LOOKUP(), so that any
2026
	 * automount of the snapshot directory that is required will
2027
	 * be done.
2028
	 * This needs to be done here for NFSv4, since NFSv4 never does
2029
	 * a VFS_VGET() for "." or "..".
2026
	 */
2030
	 */
2027
	if (is_zfs == 1)
2031
	if (is_zfs == 1) {
2028
		usevget = 0;
2032
		r = VFS_VGET(mp, at.na_fileid, LK_SHARED, &nvp);
2029
2033
		if (r == EOPNOTSUPP) {
2030
	cn.cn_nameiop = LOOKUP;
2034
			usevget = 0;
2031
	cn.cn_lkflags = LK_SHARED | LK_RETRY;
2035
			cn.cn_nameiop = LOOKUP;
2032
	cn.cn_cred = nd->nd_cred;
2036
			cn.cn_lkflags = LK_SHARED | LK_RETRY;
2033
	cn.cn_thread = p;
2037
			cn.cn_cred = nd->nd_cred;
2038
			cn.cn_thread = p;
2039
		} else if (r == 0)
2040
			vput(nvp);
2041
	}
2034
2042
2035
	/*
2043
	/*
2036
	 * Save this position, in case there is an error before one entry
2044
	 * Save this position, in case there is an error before one entry
Lines 2099-2105 again: Link Here
2099
					else
2107
					else
2100
						r = EOPNOTSUPP;
2108
						r = EOPNOTSUPP;
2101
					if (r == EOPNOTSUPP) {
2109
					if (r == EOPNOTSUPP) {
2102
						usevget = 0;
2110
						if (usevget) {
2111
							usevget = 0;
2112
							cn.cn_nameiop = LOOKUP;
2113
							cn.cn_lkflags =
2114
							    LK_SHARED |
2115
							    LK_RETRY;
2116
							cn.cn_cred =
2117
							    nd->nd_cred;
2118
							cn.cn_thread = p;
2119
						}
2103
						cn.cn_nameptr = dp->d_name;
2120
						cn.cn_nameptr = dp->d_name;
2104
						cn.cn_namelen = nlen;
2121
						cn.cn_namelen = nlen;
2105
						cn.cn_flags = ISLASTCN |
2122
						cn.cn_flags = ISLASTCN |
(-)b/sys/kern/capabilities.conf (+5 lines)
Lines 197-202 fpathconf Link Here
197
## Allow various file descriptor-based I/O operations, subject to capability
197
## Allow various file descriptor-based I/O operations, subject to capability
198
## rights.
198
## rights.
199
##
199
##
200
freebsd11_fstat
201
freebsd11_fstatat
202
freebsd11_getdirentries
203
freebsd11_fstatfs
204
freebsd11_mknodat
200
freebsd6_ftruncate
205
freebsd6_ftruncate
201
freebsd6_lseek
206
freebsd6_lseek
202
freebsd6_mmap
207
freebsd6_mmap
(-)b/sys/kern/kern_acct.c (-2 / +7 lines)
Lines 96-101 __FBSDID("$FreeBSD$"); Link Here
96
96
97
#include <security/mac/mac_framework.h>
97
#include <security/mac/mac_framework.h>
98
98
99
_Static_assert(sizeof(struct acctv3) - offsetof(struct acctv3, ac_trailer) ==
100
    sizeof(struct acctv2) - offsetof(struct acctv2, ac_trailer), "trailer");
101
_Static_assert(sizeof(struct acctv3) - offsetof(struct acctv3, ac_len2) ==
102
    sizeof(struct acctv2) - offsetof(struct acctv2, ac_len2), "len2");
103
99
/*
104
/*
100
 * The routines implemented in this file are described in:
105
 * The routines implemented in this file are described in:
101
 *      Leffler, et al.: The Design and Implementation of the 4.3BSD
106
 *      Leffler, et al.: The Design and Implementation of the 4.3BSD
Lines 339-345 acct_disable(struct thread *td, int logging) Link Here
339
int
344
int
340
acct_process(struct thread *td)
345
acct_process(struct thread *td)
341
{
346
{
342
	struct acctv2 acct;
347
	struct acctv3 acct;
343
	struct timeval ut, st, tmp;
348
	struct timeval ut, st, tmp;
344
	struct plimit *oldlim;
349
	struct plimit *oldlim;
345
	struct proc *p;
350
	struct proc *p;
Lines 421-427 acct_process(struct thread *td) Link Here
421
	/* Setup ancillary structure fields. */
426
	/* Setup ancillary structure fields. */
422
	acct.ac_flagx |= ANVER;
427
	acct.ac_flagx |= ANVER;
423
	acct.ac_zero = 0;
428
	acct.ac_zero = 0;
424
	acct.ac_version = 2;
429
	acct.ac_version = 3;
425
	acct.ac_len = acct.ac_len2 = sizeof(acct);
430
	acct.ac_len = acct.ac_len2 = sizeof(acct);
426
431
427
	/*
432
	/*
(-)b/sys/kern/kern_descrip.c (-9 / +44 lines)
Lines 1304-1309 ofstat(struct thread *td, struct ofstat_args *uap) Link Here
1304
}
1304
}
1305
#endif /* COMPAT_43 */
1305
#endif /* COMPAT_43 */
1306
1306
1307
#if defined(COMPAT_FREEBSD11)
1308
int
1309
freebsd11_fstat(struct thread *td, struct freebsd11_fstat_args *uap)
1310
{
1311
	struct stat sb;
1312
	struct freebsd11_stat osb;
1313
	int error;
1314
1315
	error = kern_fstat(td, uap->fd, &sb);
1316
	if (error != 0)
1317
		return (error);
1318
	freebsd11_cvtstat(&sb, &osb);
1319
	error = copyout(&osb, uap->sb, sizeof(osb));
1320
	return (error);
1321
}
1322
#endif	/* COMPAT_FREEBSD11 */
1323
1307
/*
1324
/*
1308
 * Return status information about a file descriptor.
1325
 * Return status information about a file descriptor.
1309
 */
1326
 */
Lines 1347-1367 kern_fstat(struct thread *td, int fd, struct stat *sbp) Link Here
1347
	if (error == 0 && KTRPOINT(td, KTR_STRUCT))
1364
	if (error == 0 && KTRPOINT(td, KTR_STRUCT))
1348
		ktrstat(sbp);
1365
		ktrstat(sbp);
1349
#endif
1366
#endif
1367
#ifdef __STAT_TIME_T_EXT
1368
	if (error == 0) {
1369
		sb.st_atim_ext = 0;
1370
		sb.st_mtim_ext = 0;
1371
		sb.st_ctim_ext = 0;
1372
		sb.st_btim_ext = 0;
1373
	}
1374
#endif
1350
	return (error);
1375
	return (error);
1351
}
1376
}
1352
1377
1378
#if defined(COMPAT_FREEBSD11)
1353
/*
1379
/*
1354
 * Return status information about a file descriptor.
1380
 * Return status information about a file descriptor.
1355
 */
1381
 */
1356
#ifndef _SYS_SYSPROTO_H_
1382
#ifndef _SYS_SYSPROTO_H_
1357
struct nfstat_args {
1383
struct freebsd11_nfstat_args {
1358
	int	fd;
1384
	int	fd;
1359
	struct	nstat *sb;
1385
	struct	nstat *sb;
1360
};
1386
};
1361
#endif
1387
#endif
1362
/* ARGSUSED */
1388
/* ARGSUSED */
1363
int
1389
int
1364
sys_nfstat(struct thread *td, struct nfstat_args *uap)
1390
freebsd11_nfstat(struct thread *td, struct freebsd11_nfstat_args *uap)
1365
{
1391
{
1366
	struct nstat nub;
1392
	struct nstat nub;
1367
	struct stat ub;
1393
	struct stat ub;
Lines 1369-1379 sys_nfstat(struct thread *td, struct nfstat_args *uap) Link Here
1369
1395
1370
	error = kern_fstat(td, uap->fd, &ub);
1396
	error = kern_fstat(td, uap->fd, &ub);
1371
	if (error == 0) {
1397
	if (error == 0) {
1372
		cvtnstat(&ub, &nub);
1398
		freebsd11_cvtnstat(&ub, &nub);
1373
		error = copyout(&nub, uap->sb, sizeof(nub));
1399
		error = copyout(&nub, uap->sb, sizeof(nub));
1374
	}
1400
	}
1375
	return (error);
1401
	return (error);
1376
}
1402
}
1403
#endif /* COMPAT_FREEBSD11 */
1377
1404
1378
/*
1405
/*
1379
 * Return pathconf information about a file descriptor.
1406
 * Return pathconf information about a file descriptor.
Lines 3590-3602 kinfo_to_okinfo(struct kinfo_file *kif, struct kinfo_ofile *okif) Link Here
3590
	    KF_FLAG_APPEND | KF_FLAG_ASYNC | KF_FLAG_FSYNC | KF_FLAG_NONBLOCK |
3617
	    KF_FLAG_APPEND | KF_FLAG_ASYNC | KF_FLAG_FSYNC | KF_FLAG_NONBLOCK |
3591
	    KF_FLAG_DIRECT | KF_FLAG_HASLOCK);
3618
	    KF_FLAG_DIRECT | KF_FLAG_HASLOCK);
3592
	okif->kf_offset = kif->kf_offset;
3619
	okif->kf_offset = kif->kf_offset;
3593
	okif->kf_vnode_type = kif->kf_vnode_type;
3620
	if (kif->kf_type == KF_TYPE_VNODE)
3594
	okif->kf_sock_domain = kif->kf_sock_domain;
3621
		okif->kf_vnode_type = kif->kf_un.kf_file.kf_file_type;
3595
	okif->kf_sock_type = kif->kf_sock_type;
3622
	else
3596
	okif->kf_sock_protocol = kif->kf_sock_protocol;
3623
		okif->kf_vnode_type = KF_VTYPE_VNON;
3597
	strlcpy(okif->kf_path, kif->kf_path, sizeof(okif->kf_path));
3624
	strlcpy(okif->kf_path, kif->kf_path, sizeof(okif->kf_path));
3598
	okif->kf_sa_local = kif->kf_sa_local;
3625
	if (kif->kf_type == KF_TYPE_SOCKET) {
3599
	okif->kf_sa_peer = kif->kf_sa_peer;
3626
		okif->kf_sock_domain = kif->kf_un.kf_sock.kf_sock_domain0;
3627
		okif->kf_sock_type = kif->kf_un.kf_sock.kf_sock_type0;
3628
		okif->kf_sock_protocol = kif->kf_un.kf_sock.kf_sock_protocol0;
3629
		okif->kf_sa_local = kif->kf_un.kf_sock.kf_sa_local;
3630
		okif->kf_sa_peer = kif->kf_un.kf_sock.kf_sa_peer;
3631
	} else {
3632
		okif->kf_sa_local.ss_family = AF_UNSPEC;
3633
		okif->kf_sa_peer.ss_family = AF_UNSPEC;
3634
	}
3600
}
3635
}
3601
3636
3602
static int
3637
static int
(-)b/sys/kern/kern_proc.c (-1 / +10 lines)
Lines 986-996 fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp) Link Here
986
	}
986
	}
987
	if ((p->p_flag & P_CONTROLT) && tp != NULL) {
987
	if ((p->p_flag & P_CONTROLT) && tp != NULL) {
988
		kp->ki_tdev = tty_udev(tp);
988
		kp->ki_tdev = tty_udev(tp);
989
		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
989
		kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
990
		kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
990
		if (tp->t_session)
991
		if (tp->t_session)
991
			kp->ki_tsid = tp->t_session->s_sid;
992
			kp->ki_tsid = tp->t_session->s_sid;
992
	} else
993
	} else {
993
		kp->ki_tdev = NODEV;
994
		kp->ki_tdev = NODEV;
995
		kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
996
	}
994
	if (p->p_comm[0] != '\0')
997
	if (p->p_comm[0] != '\0')
995
		strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
998
		strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
996
	if (p->p_sysent && p->p_sysent->sv_name != NULL &&
999
	if (p->p_sysent && p->p_sysent->sv_name != NULL &&
Lines 1232-1237 freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32) Link Here
1232
	CP(*ki, *ki32, ki_tsid);
1235
	CP(*ki, *ki32, ki_tsid);
1233
	CP(*ki, *ki32, ki_jobc);
1236
	CP(*ki, *ki32, ki_jobc);
1234
	CP(*ki, *ki32, ki_tdev);
1237
	CP(*ki, *ki32, ki_tdev);
1238
	CP(*ki, *ki32, ki_tdev_freebsd11);
1235
	CP(*ki, *ki32, ki_siglist);
1239
	CP(*ki, *ki32, ki_siglist);
1236
	CP(*ki, *ki32, ki_sigmask);
1240
	CP(*ki, *ki32, ki_sigmask);
1237
	CP(*ki, *ki32, ki_sigignore);
1241
	CP(*ki, *ki32, ki_sigignore);
Lines 2204-2209 sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) Link Here
2204
				vn_lock(vp, LK_SHARED | LK_RETRY);
2208
				vn_lock(vp, LK_SHARED | LK_RETRY);
2205
				if (VOP_GETATTR(vp, &va, cred) == 0) {
2209
				if (VOP_GETATTR(vp, &va, cred) == 0) {
2206
					kve->kve_fileid = va.va_fileid;
2210
					kve->kve_fileid = va.va_fileid;
2211
					/* truncate */
2207
					kve->kve_fsid = va.va_fsid;
2212
					kve->kve_fsid = va.va_fsid;
2208
				}
2213
				}
2209
				vput(vp);
2214
				vput(vp);
Lines 2443-2452 kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) Link Here
2443
				if (VOP_GETATTR(vp, &va, cred) == 0) {
2448
				if (VOP_GETATTR(vp, &va, cred) == 0) {
2444
					kve->kve_vn_fileid = va.va_fileid;
2449
					kve->kve_vn_fileid = va.va_fileid;
2445
					kve->kve_vn_fsid = va.va_fsid;
2450
					kve->kve_vn_fsid = va.va_fsid;
2451
					kve->kve_vn_fsid_freebsd11 =
2452
					    kve->kve_vn_fsid; /* truncate */
2446
					kve->kve_vn_mode =
2453
					kve->kve_vn_mode =
2447
					    MAKEIMODE(va.va_type, va.va_mode);
2454
					    MAKEIMODE(va.va_type, va.va_mode);
2448
					kve->kve_vn_size = va.va_size;
2455
					kve->kve_vn_size = va.va_size;
2449
					kve->kve_vn_rdev = va.va_rdev;
2456
					kve->kve_vn_rdev = va.va_rdev;
2457
					kve->kve_vn_rdev_freebsd11 =
2458
					    kve->kve_vn_rdev; /* truncate */
2450
					kve->kve_status = KF_ATTR_VALID;
2459
					kve->kve_status = KF_ATTR_VALID;
2451
				}
2460
				}
2452
				vput(vp);
2461
				vput(vp);
(-)b/sys/kern/makesyscalls.sh (-4 / +33 lines)
Lines 10-15 compat4=COMPAT_FREEBSD4 Link Here
10
compat6=COMPAT_FREEBSD6
10
compat6=COMPAT_FREEBSD6
11
compat7=COMPAT_FREEBSD7
11
compat7=COMPAT_FREEBSD7
12
compat10=COMPAT_FREEBSD10
12
compat10=COMPAT_FREEBSD10
13
compat11=COMPAT_FREEBSD11
13
14
14
# output files:
15
# output files:
15
sysnames="syscalls.c"
16
sysnames="syscalls.c"
Lines 36-41 syscompat7="sysent.compat7.$$" Link Here
36
syscompat7dcl="sysent.compat7dcl.$$"
37
syscompat7dcl="sysent.compat7dcl.$$"
37
syscompat10="sysent.compat10.$$"
38
syscompat10="sysent.compat10.$$"
38
syscompat10dcl="sysent.compat10dcl.$$"
39
syscompat10dcl="sysent.compat10dcl.$$"
40
syscompat11="sysent.compat11.$$"
41
syscompat11dcl="sysent.compat11dcl.$$"
39
sysent="sysent.switch.$$"
42
sysent="sysent.switch.$$"
40
sysinc="sysinc.switch.$$"
43
sysinc="sysinc.switch.$$"
41
sysarg="sysarg.switch.$$"
44
sysarg="sysarg.switch.$$"
Lines 50-58 else Link Here
50
	capenabled=""
53
	capenabled=""
51
fi
54
fi
52
55
53
trap "rm $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $syscompat7 $syscompat7dcl $syscompat10 $syscompat10dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp $systraceret" 0
56
trap "rm $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $syscompat7 $syscompat7dcl $syscompat10 $syscompat10dcl $syscompat11 $syscompat11dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp $systraceret" 0
54
57
55
touch $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $syscompat7 $syscompat7dcl $syscompat10 $syscompat10dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp $systraceret
58
touch $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $syscompat7 $syscompat7dcl $syscompat10 $syscompat10dcl $syscompat11 $syscompat11dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp $systraceret
56
59
57
case $# in
60
case $# in
58
    0)	echo "usage: $0 input-file <config-file>" 1>&2
61
    0)	echo "usage: $0 input-file <config-file>" 1>&2
Lines 92-97 sed -e ' Link Here
92
		syscompat7dcl = \"$syscompat7dcl\"
95
		syscompat7dcl = \"$syscompat7dcl\"
93
		syscompat10 = \"$syscompat10\"
96
		syscompat10 = \"$syscompat10\"
94
		syscompat10dcl = \"$syscompat10dcl\"
97
		syscompat10dcl = \"$syscompat10dcl\"
98
		syscompat11 = \"$syscompat11\"
99
		syscompat11dcl = \"$syscompat11dcl\"
95
		sysent = \"$sysent\"
100
		sysent = \"$sysent\"
96
		syssw = \"$syssw\"
101
		syssw = \"$syssw\"
97
		sysinc = \"$sysinc\"
102
		sysinc = \"$sysinc\"
Lines 107-112 sed -e ' Link Here
107
		compat6 = \"$compat6\"
112
		compat6 = \"$compat6\"
108
		compat7 = \"$compat7\"
113
		compat7 = \"$compat7\"
109
		compat10 = \"$compat10\"
114
		compat10 = \"$compat10\"
115
		compat11 = \"$compat11\"
110
		syscallprefix = \"$syscallprefix\"
116
		syscallprefix = \"$syscallprefix\"
111
		switchname = \"$switchname\"
117
		switchname = \"$switchname\"
112
		namesname = \"$namesname\"
118
		namesname = \"$namesname\"
Lines 155-160 sed -e ' Link Here
155
		printf "\n#ifdef %s\n\n", compat6 > syscompat6
161
		printf "\n#ifdef %s\n\n", compat6 > syscompat6
156
		printf "\n#ifdef %s\n\n", compat7 > syscompat7
162
		printf "\n#ifdef %s\n\n", compat7 > syscompat7
157
		printf "\n#ifdef %s\n\n", compat10 > syscompat10
163
		printf "\n#ifdef %s\n\n", compat10 > syscompat10
164
		printf "\n#ifdef %s\n\n", compat11 > syscompat11
158
165
159
		printf "/*\n * System call names.\n *\n" > sysnames
166
		printf "/*\n * System call names.\n *\n" > sysnames
160
		printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
167
		printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
Lines 205-210 sed -e ' Link Here
205
		print > syscompat6
212
		print > syscompat6
206
		print > syscompat7
213
		print > syscompat7
207
		print > syscompat10
214
		print > syscompat10
215
		print > syscompat11
208
		print > sysnames
216
		print > sysnames
209
		print > systrace
217
		print > systrace
210
		print > systracetmp
218
		print > systracetmp
Lines 221-226 sed -e ' Link Here
221
		print > syscompat6
229
		print > syscompat6
222
		print > syscompat7
230
		print > syscompat7
223
		print > syscompat10
231
		print > syscompat10
232
		print > syscompat11
224
		print > sysnames
233
		print > sysnames
225
		print > systrace
234
		print > systrace
226
		print > systracetmp
235
		print > systracetmp
Lines 237-242 sed -e ' Link Here
237
		print > syscompat6
246
		print > syscompat6
238
		print > syscompat7
247
		print > syscompat7
239
		print > syscompat10
248
		print > syscompat10
249
		print > syscompat11
240
		print > sysnames
250
		print > sysnames
241
		print > systrace
251
		print > systrace
242
		print > systracetmp
252
		print > systracetmp
Lines 345-350 sed -e ' Link Here
345
				argalias = "freebsd7_" argalias
355
				argalias = "freebsd7_" argalias
346
			if (flag("COMPAT10"))
356
			if (flag("COMPAT10"))
347
				argalias = "freebsd10_" argalias
357
				argalias = "freebsd10_" argalias
358
			if (flag("COMPAT11"))
359
				argalias = "freebsd11_" argalias
348
		}
360
		}
349
		f++
361
		f++
350
362
Lines 497-503 sed -e ' Link Here
497
		next
509
		next
498
	}
510
	}
499
	type("COMPAT") || type("COMPAT4") || type("COMPAT6") || \
511
	type("COMPAT") || type("COMPAT4") || type("COMPAT6") || \
500
	    type("COMPAT7") || type("COMPAT10") {
512
	    type("COMPAT7") || type("COMPAT10") || type("COMPAT11") {
501
		if (flag("COMPAT")) {
513
		if (flag("COMPAT")) {
502
			ncompat++
514
			ncompat++
503
			out = syscompat
515
			out = syscompat
Lines 533-538 sed -e ' Link Here
533
			wrap = "compat10"
545
			wrap = "compat10"
534
			prefix = "freebsd10_"
546
			prefix = "freebsd10_"
535
			descr = "freebsd10"
547
			descr = "freebsd10"
548
		} else if (flag("COMPAT11")) {
549
			ncompat11++
550
			out = syscompat11
551
			outdcl = syscompat11dcl
552
			wrap = "compat11"
553
			prefix = "freebsd11_"
554
			descr = "freebsd11"
536
		}
555
		}
537
		parseline()
556
		parseline()
538
		if (argc != 0 && !flag("NOARGS") && !flag("NOPROTO") && \
557
		if (argc != 0 && !flag("NOARGS") && !flag("NOPROTO") && \
Lines 608-614 sed -e ' Link Here
608
	END {
627
	END {
609
		printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
628
		printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
610
629
611
		if (ncompat != 0 || ncompat4 != 0 || ncompat6 != 0 || ncompat7 != 0 || ncompat10 != 0)
630
		if (ncompat != 0 || ncompat4 != 0 || ncompat6 != 0 || ncompat7 != 0 || ncompat10 != 0 || ncompat11 != 0)
612
			printf "#include \"opt_compat.h\"\n\n" > syssw
631
			printf "#include \"opt_compat.h\"\n\n" > syssw
613
632
614
		if (ncompat != 0) {
633
		if (ncompat != 0) {
Lines 649-659 sed -e ' Link Here
649
			printf "#define compat10(n, name) 0, (sy_call_t *)nosys\n" > sysinc
668
			printf "#define compat10(n, name) 0, (sy_call_t *)nosys\n" > sysinc
650
			printf "#endif\n" > sysinc
669
			printf "#endif\n" > sysinc
651
		}
670
		}
671
		if (ncompat11 != 0) {
672
			printf "\n#ifdef %s\n", compat11 > sysinc
673
			printf "#define compat11(n, name) n, (sy_call_t *)__CONCAT(freebsd11_,name)\n" > sysinc
674
			printf "#else\n" > sysinc
675
			printf "#define compat11(n, name) 0, (sy_call_t *)nosys\n" > sysinc
676
			printf "#endif\n" > sysinc
677
		}
678
652
		printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
679
		printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
653
		printf("\n#endif /* %s */\n\n", compat4) > syscompat4dcl
680
		printf("\n#endif /* %s */\n\n", compat4) > syscompat4dcl
654
		printf("\n#endif /* %s */\n\n", compat6) > syscompat6dcl
681
		printf("\n#endif /* %s */\n\n", compat6) > syscompat6dcl
655
		printf("\n#endif /* %s */\n\n", compat7) > syscompat7dcl
682
		printf("\n#endif /* %s */\n\n", compat7) > syscompat7dcl
656
		printf("\n#endif /* %s */\n\n", compat10) > syscompat10dcl
683
		printf("\n#endif /* %s */\n\n", compat10) > syscompat10dcl
684
		printf("\n#endif /* %s */\n\n", compat11) > syscompat11dcl
657
685
658
		printf("\n#undef PAD_\n") > sysprotoend
686
		printf("\n#undef PAD_\n") > sysprotoend
659
		printf("#undef PADL_\n") > sysprotoend
687
		printf("#undef PADL_\n") > sysprotoend
Lines 677-682 cat $sysarg $sysdcl \ Link Here
677
	$syscompat6 $syscompat6dcl \
705
	$syscompat6 $syscompat6dcl \
678
	$syscompat7 $syscompat7dcl \
706
	$syscompat7 $syscompat7dcl \
679
	$syscompat10 $syscompat10dcl \
707
	$syscompat10 $syscompat10dcl \
708
	$syscompat11 $syscompat11dcl \
680
	$sysaue $sysprotoend > $sysproto
709
	$sysaue $sysprotoend > $sysproto
681
cat $systracetmp >> $systrace
710
cat $systracetmp >> $systrace
682
cat $systraceret >> $systrace
711
cat $systraceret >> $systrace
(-)b/sys/kern/sys_socket.c (-9 / +12 lines)
Lines 346-359 soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp) Link Here
346
346
347
	kif->kf_type = KF_TYPE_SOCKET;
347
	kif->kf_type = KF_TYPE_SOCKET;
348
	so = fp->f_data;
348
	so = fp->f_data;
349
	kif->kf_sock_domain = so->so_proto->pr_domain->dom_family;
349
	kif->kf_un.kf_sock.kf_sock_domain0 =
350
	kif->kf_sock_type = so->so_type;
350
	    so->so_proto->pr_domain->dom_family;
351
	kif->kf_sock_protocol = so->so_proto->pr_protocol;
351
	kif->kf_un.kf_sock.kf_sock_type0 = so->so_type;
352
	kif->kf_un.kf_sock.kf_sock_protocol0 = so->so_proto->pr_protocol;
352
	kif->kf_un.kf_sock.kf_sock_pcb = (uintptr_t)so->so_pcb;
353
	kif->kf_un.kf_sock.kf_sock_pcb = (uintptr_t)so->so_pcb;
353
	switch (kif->kf_sock_domain) {
354
	switch (kif->kf_un.kf_sock.kf_sock_domain0) {
354
	case AF_INET:
355
	case AF_INET:
355
	case AF_INET6:
356
	case AF_INET6:
356
		if (kif->kf_sock_protocol == IPPROTO_TCP) {
357
		if (kif->kf_un.kf_sock.kf_sock_protocol0 == IPPROTO_TCP) {
357
			if (so->so_pcb != NULL) {
358
			if (so->so_pcb != NULL) {
358
				inpcb = (struct inpcb *)(so->so_pcb);
359
				inpcb = (struct inpcb *)(so->so_pcb);
359
				kif->kf_un.kf_sock.kf_sock_inpcb =
360
				kif->kf_un.kf_sock.kf_sock_inpcb =
Lines 376-388 soo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp) Link Here
376
		break;
377
		break;
377
	}
378
	}
378
	error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
379
	error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
379
	if (error == 0 && sa->sa_len <= sizeof(kif->kf_sa_local)) {
380
	if (error == 0 &&
380
		bcopy(sa, &kif->kf_sa_local, sa->sa_len);
381
	    sa->sa_len <= sizeof(kif->kf_un.kf_sock.kf_sa_local)) {
382
		bcopy(sa, &kif->kf_un.kf_sock.kf_sa_local, sa->sa_len);
381
		free(sa, M_SONAME);
383
		free(sa, M_SONAME);
382
	}
384
	}
383
	error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa);
385
	error = so->so_proto->pr_usrreqs->pru_peeraddr(so, &sa);
384
	if (error == 0 && sa->sa_len <= sizeof(kif->kf_sa_peer)) {
386
	if (error == 0 &&
385
		bcopy(sa, &kif->kf_sa_peer, sa->sa_len);
387
	    sa->sa_len <= sizeof(kif->kf_un.kf_sock.kf_sa_peer)) {
388
		bcopy(sa, &kif->kf_un.kf_sock.kf_sa_peer, sa->sa_len);
386
		free(sa, M_SONAME);
389
		free(sa, M_SONAME);
387
	}
390
	}
388
	strncpy(kif->kf_path, so->so_proto->pr_domain->dom_name,
391
	strncpy(kif->kf_path, so->so_proto->pr_domain->dom_name,
(-)b/sys/kern/syscalls.master (-22 / +42 lines)
Lines 12-18 Link Here
12
;		case where the event exists, but we don't want auditing, the
12
;		case where the event exists, but we don't want auditing, the
13
;		event should be #defined to AUE_NULL in audit_kevents.h.
13
;		event should be #defined to AUE_NULL in audit_kevents.h.
14
;	type	one of STD, OBSOL, UNIMPL, COMPAT, COMPAT4, COMPAT6,
14
;	type	one of STD, OBSOL, UNIMPL, COMPAT, COMPAT4, COMPAT6,
15
;		COMPAT7, NODEF, NOARGS, NOPROTO, NOSTD
15
;		COMPAT7, COMPAT11, NODEF, NOARGS, NOPROTO, NOSTD
16
;		The COMPAT* options may be combined with one or more NO*
16
;		The COMPAT* options may be combined with one or more NO*
17
;		options separated by '|' with no spaces (e.g. COMPAT|NOARGS)
17
;		options separated by '|' with no spaces (e.g. COMPAT|NOARGS)
18
;	name	psuedo-prototype of syscall routine
18
;	name	psuedo-prototype of syscall routine
Lines 29-34 Link Here
29
;	COMPAT6	included on COMPAT_FREEBSD6 #ifdef (FreeBSD 6 compat)
29
;	COMPAT6	included on COMPAT_FREEBSD6 #ifdef (FreeBSD 6 compat)
30
;	COMPAT7	included on COMPAT_FREEBSD7 #ifdef (FreeBSD 7 compat)
30
;	COMPAT7	included on COMPAT_FREEBSD7 #ifdef (FreeBSD 7 compat)
31
;	COMPAT10 included on COMPAT_FREEBSD10 #ifdef (FreeBSD 10 compat)
31
;	COMPAT10 included on COMPAT_FREEBSD10 #ifdef (FreeBSD 10 compat)
32
;	COMPAT11 included on COMPAT11 #ifdef (FreeBSD 11 compat)
32
;	OBSOL	obsolete, not included in system, only specifies name
33
;	OBSOL	obsolete, not included in system, only specifies name
33
;	UNIMPL	not implemented, placeholder only
34
;	UNIMPL	not implemented, placeholder only
34
;	NOSTD	implemented but as a lkm that can be statically
35
;	NOSTD	implemented but as a lkm that can be statically
Lines 79-85 Link Here
79
11	AUE_NULL	OBSOL	execv
80
11	AUE_NULL	OBSOL	execv
80
12	AUE_CHDIR	STD	{ int chdir(char *path); }
81
12	AUE_CHDIR	STD	{ int chdir(char *path); }
81
13	AUE_FCHDIR	STD	{ int fchdir(int fd); }
82
13	AUE_FCHDIR	STD	{ int fchdir(int fd); }
82
14	AUE_MKNOD	STD	{ int mknod(char *path, int mode, int dev); }
83
14	AUE_MKNOD	COMPAT11 { int mknod(char *path, int mode, int dev); }
83
15	AUE_CHMOD	STD	{ int chmod(char *path, int mode); }
84
15	AUE_CHMOD	STD	{ int chmod(char *path, int mode); }
84
16	AUE_CHOWN	STD	{ int chown(char *path, int uid, int gid); }
85
16	AUE_CHOWN	STD	{ int chown(char *path, int uid, int gid); }
85
17	AUE_NULL	STD	{ int obreak(char *nsize); } break \
86
17	AUE_NULL	STD	{ int obreak(char *nsize); } break \
Lines 363-371 Link Here
363
185	AUE_NULL	UNIMPL	lfs_markv
364
185	AUE_NULL	UNIMPL	lfs_markv
364
186	AUE_NULL	UNIMPL	lfs_segclean
365
186	AUE_NULL	UNIMPL	lfs_segclean
365
187	AUE_NULL	UNIMPL	lfs_segwait
366
187	AUE_NULL	UNIMPL	lfs_segwait
366
188	AUE_STAT	STD	{ int stat(char *path, struct stat *ub); }
367
188	AUE_STAT	COMPAT11 { int stat(char *path, \
367
189	AUE_FSTAT	STD	{ int fstat(int fd, struct stat *sb); }
368
				    struct freebsd11_stat *ub); }
368
190	AUE_LSTAT	STD	{ int lstat(char *path, struct stat *ub); }
369
189	AUE_FSTAT	COMPAT11 { int fstat(int fd, \
370
				    struct freebsd11_stat *sb); }
371
190	AUE_LSTAT	COMPAT11 { int lstat(char *path, \
372
				    struct freebsd11_stat *ub); }
369
191	AUE_PATHCONF	STD	{ int pathconf(char *path, int name); }
373
191	AUE_PATHCONF	STD	{ int pathconf(char *path, int name); }
370
192	AUE_FPATHCONF	STD	{ int fpathconf(int fd, int name); }
374
192	AUE_FPATHCONF	STD	{ int fpathconf(int fd, int name); }
371
193	AUE_NULL	UNIMPL	nosys
375
193	AUE_NULL	UNIMPL	nosys
Lines 375-381 Link Here
375
195	AUE_SETRLIMIT	STD	{ int setrlimit(u_int which, \
379
195	AUE_SETRLIMIT	STD	{ int setrlimit(u_int which, \
376
				    struct rlimit *rlp); } setrlimit \
380
				    struct rlimit *rlp); } setrlimit \
377
				    __setrlimit_args int
381
				    __setrlimit_args int
378
196	AUE_GETDIRENTRIES	STD	{ int getdirentries(int fd, char *buf, \
382
196	AUE_GETDIRENTRIES	COMPAT11 { int getdirentries(int fd, char *buf, \
379
				    u_int count, long *basep); }
383
				    u_int count, long *basep); }
380
197	AUE_MMAP	COMPAT6	{ caddr_t mmap(caddr_t addr, \
384
197	AUE_MMAP	COMPAT6	{ caddr_t mmap(caddr_t addr, \
381
				    size_t len, int prot, int flags, int fd, \
385
				    size_t len, int prot, int flags, int fd, \
Lines 496-502 Link Here
496
269	AUE_NULL	UNIMPL	nosys
500
269	AUE_NULL	UNIMPL	nosys
497
270	AUE_NULL	UNIMPL	nosys
501
270	AUE_NULL	UNIMPL	nosys
498
271	AUE_NULL	UNIMPL	nosys
502
271	AUE_NULL	UNIMPL	nosys
499
272	AUE_O_GETDENTS	STD	{ int getdents(int fd, char *buf, \
503
272	AUE_O_GETDENTS	COMPAT11 { int getdents(int fd, char *buf, \
500
				    size_t count); }
504
				    size_t count); }
501
273	AUE_NULL	UNIMPL	nosys
505
273	AUE_NULL	UNIMPL	nosys
502
274	AUE_LCHMOD	STD	{ int lchmod(char *path, mode_t mode); }
506
274	AUE_LCHMOD	STD	{ int lchmod(char *path, mode_t mode); }
Lines 507-515 Link Here
507
				    struct timeval *tptr); }
511
				    struct timeval *tptr); }
508
277	AUE_MSYNC	NOPROTO	{ int msync(void *addr, size_t len, \
512
277	AUE_MSYNC	NOPROTO	{ int msync(void *addr, size_t len, \
509
				    int flags); } netbsd_msync msync_args int
513
				    int flags); } netbsd_msync msync_args int
510
278	AUE_STAT	STD	{ int nstat(char *path, struct nstat *ub); }
514
278	AUE_STAT	COMPAT11 { int nstat(char *path, struct nstat *ub); }
511
279	AUE_FSTAT	STD	{ int nfstat(int fd, struct nstat *sb); }
515
279	AUE_FSTAT	COMPAT11 { int nfstat(int fd, struct nstat *sb); }
512
280	AUE_LSTAT	STD	{ int nlstat(char *path, struct nstat *ub); }
516
280	AUE_LSTAT	COMPAT11 { int nlstat(char *path, struct nstat *ub); }
513
281	AUE_NULL	UNIMPL	nosys
517
281	AUE_NULL	UNIMPL	nosys
514
282	AUE_NULL	UNIMPL	nosys
518
282	AUE_NULL	UNIMPL	nosys
515
283	AUE_NULL	UNIMPL	nosys
519
283	AUE_NULL	UNIMPL	nosys
Lines 535-542 Link Here
535
				    struct ostatfs *buf); }
539
				    struct ostatfs *buf); }
536
298	AUE_FHOPEN	STD	{ int fhopen(const struct fhandle *u_fhp, \
540
298	AUE_FHOPEN	STD	{ int fhopen(const struct fhandle *u_fhp, \
537
				    int flags); }
541
				    int flags); }
538
299	AUE_FHSTAT	STD	{ int fhstat(const struct fhandle *u_fhp, \
542
299	AUE_FHSTAT	COMPAT11 { int fhstat(const struct fhandle *u_fhp, \
539
				    struct stat *sb); }
543
				    struct freebsd11_stat *sb); }
540
; syscall numbers for FreeBSD
544
; syscall numbers for FreeBSD
541
300	AUE_NULL	STD	{ int modnext(int modid); }
545
300	AUE_NULL	STD	{ int modnext(int modid); }
542
301	AUE_NULL	STD	{ int modstat(int modid, \
546
301	AUE_NULL	STD	{ int modstat(int modid, \
Lines 707-719 Link Here
707
				    off_t *sbytes, int flags); }
711
				    off_t *sbytes, int flags); }
708
394	AUE_NULL	STD	{ int mac_syscall(const char *policy, \
712
394	AUE_NULL	STD	{ int mac_syscall(const char *policy, \
709
				    int call, void *arg); }
713
				    int call, void *arg); }
710
395	AUE_GETFSSTAT	STD	{ int getfsstat(struct statfs *buf, \
714
395	AUE_GETFSSTAT	COMPAT11 { int getfsstat(struct freebsd11_statfs *buf, \
711
				    long bufsize, int mode); }
715
				    long bufsize, int mode); }
712
396	AUE_STATFS	STD	{ int statfs(char *path, \
716
396	AUE_STATFS	COMPAT11 { int statfs(char *path, \
713
				    struct statfs *buf); }
717
				    struct freebsd11_statfs *buf); }
714
397	AUE_FSTATFS	STD	{ int fstatfs(int fd, struct statfs *buf); }
718
397	AUE_FSTATFS	COMPAT11 { int fstatfs(int fd, \
715
398	AUE_FHSTATFS	STD	{ int fhstatfs(const struct fhandle *u_fhp, \
719
				    struct freebsd11_statfs *buf); }
716
				    struct statfs *buf); }
720
398	AUE_FHSTATFS	COMPAT11 { int fhstatfs(const struct fhandle *u_fhp, \
721
				    struct freebsd11_statfs *buf); }
717
399	AUE_NULL	UNIMPL	nosys
722
399	AUE_NULL	UNIMPL	nosys
718
400	AUE_SEMCLOSE	NOSTD	{ int ksem_close(semid_t id); }
723
400	AUE_SEMCLOSE	NOSTD	{ int ksem_close(semid_t id); }
719
401	AUE_SEMPOST	NOSTD	{ int ksem_post(semid_t id); }
724
401	AUE_SEMPOST	NOSTD	{ int ksem_post(semid_t id); }
Lines 883-898 Link Here
883
				    gid_t gid, int flag); }
888
				    gid_t gid, int flag); }
884
492	AUE_FEXECVE	STD	{ int fexecve(int fd, char **argv, \
889
492	AUE_FEXECVE	STD	{ int fexecve(int fd, char **argv, \
885
				    char **envv); }
890
				    char **envv); }
886
493	AUE_FSTATAT	STD	{ int fstatat(int fd, char *path, \
891
493	AUE_FSTATAT	COMPAT11 { int fstatat(int fd, char *path, \
887
				    struct stat *buf, int flag); }
892
				    struct freebsd11_stat *buf, int flag); }
888
494	AUE_FUTIMESAT	STD	{ int futimesat(int fd, char *path, \
893
494	AUE_FUTIMESAT	STD	{ int futimesat(int fd, char *path, \
889
				    struct timeval *times); }
894
				    struct timeval *times); }
890
495	AUE_LINKAT	STD	{ int linkat(int fd1, char *path1, int fd2, \
895
495	AUE_LINKAT	STD	{ int linkat(int fd1, char *path1, int fd2, \
891
				    char *path2, int flag); }
896
				    char *path2, int flag); }
892
496	AUE_MKDIRAT	STD	{ int mkdirat(int fd, char *path, mode_t mode); }
897
496	AUE_MKDIRAT	STD	{ int mkdirat(int fd, char *path, mode_t mode); }
893
497	AUE_MKFIFOAT	STD	{ int mkfifoat(int fd, char *path, mode_t mode); }
898
497	AUE_MKFIFOAT	STD	{ int mkfifoat(int fd, char *path, mode_t mode); }
894
498	AUE_MKNODAT	STD	{ int mknodat(int fd, char *path, mode_t mode, \
899
498	AUE_MKNODAT	COMPAT11 { int mknodat(int fd, char *path, mode_t mode, \
895
				    dev_t dev); }
900
				    uint32_t dev); }
896
; XXX: see the comment for open
901
; XXX: see the comment for open
897
499	AUE_OPENAT_RWTC	STD	{ int openat(int fd, char *path, int flag, \
902
499	AUE_OPENAT_RWTC	STD	{ int openat(int fd, char *path, int flag, \
898
				    mode_t mode); }
903
				    mode_t mode); }
Lines 997-1002 Link Here
997
				    id_t id, const struct \
1002
				    id_t id, const struct \
998
				    vm_domain_policy_entry *policy); }
1003
				    vm_domain_policy_entry *policy); }
999
550	AUE_FSYNC	STD	{ int fdatasync(int fd); }
1004
550	AUE_FSYNC	STD	{ int fdatasync(int fd); }
1005
551	AUE_FSTAT	STD	{ int fstat(int fd, struct stat *sb); }
1006
552	AUE_FSTATAT	STD	{ int fstatat(int fd, char *path, \
1007
				    struct stat *buf, int flag); }
1008
553	AUE_FHSTAT	STD	{ int fhstat(const struct fhandle *u_fhp, \
1009
				    struct stat *sb); }
1010
554	AUE_GETDIRENTRIES STD	{ ssize_t getdirentries(int fd, char *buf, \
1011
				    size_t count, off_t *basep); }
1012
555	AUE_STATFS	STD	{ int statfs(char *path, struct statfs *buf); }
1013
556	AUE_FSTATFS	STD	{ int fstatfs(int fd, struct statfs *buf); }
1014
557	AUE_GETFSSTAT	STD	{ int getfsstat(struct statfs *buf, \
1015
				    long bufsize, int mode); }
1016
558	AUE_FHSTATFS	STD	{ int fhstatfs(const struct fhandle *u_fhp, \
1017
				    struct statfs *buf); }
1018
559	AUE_MKNODAT	STD	{ int mknodat(int fd, char *path, mode_t mode, \
1019
				    dev_t dev); }
1000
1020
1001
; Please copy any additions and changes to the following compatability tables:
1021
; Please copy any additions and changes to the following compatability tables:
1002
; sys/compat/freebsd32/syscalls.master
1022
; sys/compat/freebsd32/syscalls.master
(-)b/sys/kern/tty.c (-1 / +1 lines)
Lines 1205-1211 tty_to_xtty(struct tty *tp, struct xtty *xt) Link Here
1205
	xt->xt_pgid = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
1205
	xt->xt_pgid = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
1206
	xt->xt_sid = tp->t_session ? tp->t_session->s_sid : 0;
1206
	xt->xt_sid = tp->t_session ? tp->t_session->s_sid : 0;
1207
	xt->xt_flags = tp->t_flags;
1207
	xt->xt_flags = tp->t_flags;
1208
	xt->xt_dev = tp->t_dev ? dev2udev(tp->t_dev) : NODEV;
1208
	xt->xt_dev = tp->t_dev ? dev2udev(tp->t_dev) : (uint32_t)NODEV;
1209
}
1209
}
1210
1210
1211
static int
1211
static int
(-)b/sys/kern/tty_pts.c (+2 lines)
Lines 592-597 ptsdev_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp) Link Here
592
	kif->kf_type = KF_TYPE_PTS;
592
	kif->kf_type = KF_TYPE_PTS;
593
	tp = fp->f_data;
593
	tp = fp->f_data;
594
	kif->kf_un.kf_pts.kf_pts_dev = tty_udev(tp);
594
	kif->kf_un.kf_pts.kf_pts_dev = tty_udev(tp);
595
	kif->kf_un.kf_pts.kf_pts_dev_freebsd11 =
596
	    kif->kf_un.kf_pts.kf_pts_dev; /* truncate */
595
	strlcpy(kif->kf_path, tty_devname(tp), sizeof(kif->kf_path));
597
	strlcpy(kif->kf_path, tty_devname(tp), sizeof(kif->kf_path));
596
	return (0);
598
	return (0);
597
}
599
}
(-)b/sys/kern/vfs_syscalls.c (-243 / +393 lines)
Lines 550-556 restart: Link Here
550
/*
550
/*
551
 * Get old format filesystem statistics.
551
 * Get old format filesystem statistics.
552
 */
552
 */
553
static void cvtstatfs(struct statfs *, struct ostatfs *);
553
static void freebsd4_cvtstatfs(struct statfs *, struct ostatfs *);
554
554
555
#ifndef _SYS_SYSPROTO_H_
555
#ifndef _SYS_SYSPROTO_H_
556
struct freebsd4_statfs_args {
556
struct freebsd4_statfs_args {
Lines 573-579 freebsd4_statfs(td, uap) Link Here
573
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
573
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
574
	error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp);
574
	error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp);
575
	if (error == 0) {
575
	if (error == 0) {
576
		cvtstatfs(sfp, &osb);
576
		freebsd4_cvtstatfs(sfp, &osb);
577
		error = copyout(&osb, uap->buf, sizeof(osb));
577
		error = copyout(&osb, uap->buf, sizeof(osb));
578
	}
578
	}
579
	free(sfp, M_STATFS);
579
	free(sfp, M_STATFS);
Lines 604-610 freebsd4_fstatfs(td, uap) Link Here
604
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
604
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
605
	error = kern_fstatfs(td, uap->fd, sfp);
605
	error = kern_fstatfs(td, uap->fd, sfp);
606
	if (error == 0) {
606
	if (error == 0) {
607
		cvtstatfs(sfp, &osb);
607
		freebsd4_cvtstatfs(sfp, &osb);
608
		error = copyout(&osb, uap->buf, sizeof(osb));
608
		error = copyout(&osb, uap->buf, sizeof(osb));
609
	}
609
	}
610
	free(sfp, M_STATFS);
610
	free(sfp, M_STATFS);
Lines 643-653 freebsd4_getfsstat(td, uap) Link Here
643
	size = count * sizeof(struct statfs);
643
	size = count * sizeof(struct statfs);
644
	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE,
644
	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE,
645
	    uap->mode);
645
	    uap->mode);
646
	td->td_retval[0] = count;
646
	if (error == 0)
647
		td->td_retval[0] = count;
647
	if (size != 0) {
648
	if (size != 0) {
648
		sp = buf;
649
		sp = buf;
649
		while (count != 0 && error == 0) {
650
		while (count != 0 && error == 0) {
650
			cvtstatfs(sp, &osb);
651
			freebsd4_cvtstatfs(sp, &osb);
651
			error = copyout(&osb, uap->buf, sizeof(osb));
652
			error = copyout(&osb, uap->buf, sizeof(osb));
652
			sp++;
653
			sp++;
653
			uap->buf++;
654
			uap->buf++;
Lines 686-692 freebsd4_fhstatfs(td, uap) Link Here
686
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
687
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
687
	error = kern_fhstatfs(td, fh, sfp);
688
	error = kern_fhstatfs(td, fh, sfp);
688
	if (error == 0) {
689
	if (error == 0) {
689
		cvtstatfs(sfp, &osb);
690
		freebsd4_cvtstatfs(sfp, &osb);
690
		error = copyout(&osb, uap->buf, sizeof(osb));
691
		error = copyout(&osb, uap->buf, sizeof(osb));
691
	}
692
	}
692
	free(sfp, M_STATFS);
693
	free(sfp, M_STATFS);
Lines 697-703 freebsd4_fhstatfs(td, uap) Link Here
697
 * Convert a new format statfs structure to an old format statfs structure.
698
 * Convert a new format statfs structure to an old format statfs structure.
698
 */
699
 */
699
static void
700
static void
700
cvtstatfs(nsp, osp)
701
freebsd4_cvtstatfs(nsp, osp)
701
	struct statfs *nsp;
702
	struct statfs *nsp;
702
	struct ostatfs *osp;
703
	struct ostatfs *osp;
703
{
704
{
Lines 728-733 cvtstatfs(nsp, osp) Link Here
728
}
729
}
729
#endif /* COMPAT_FREEBSD4 */
730
#endif /* COMPAT_FREEBSD4 */
730
731
732
#if defined(COMPAT_FREEBSD11)
733
/*
734
 * Get old format filesystem statistics.
735
 */
736
static void freebsd11_cvtstatfs(struct statfs *, struct freebsd11_statfs *);
737
738
int
739
freebsd11_statfs(struct thread *td, struct freebsd11_statfs_args *uap)
740
{
741
	struct freebsd11_statfs osb;
742
	struct statfs *sfp;
743
	int error;
744
745
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
746
	error = kern_statfs(td, uap->path, UIO_USERSPACE, sfp);
747
	if (error == 0) {
748
		freebsd11_cvtstatfs(sfp, &osb);
749
		error = copyout(&osb, uap->buf, sizeof(osb));
750
	}
751
	free(sfp, M_STATFS);
752
	return (error);
753
}
754
755
/*
756
 * Get filesystem statistics.
757
 */
758
int
759
freebsd11_fstatfs(struct thread *td, struct freebsd11_fstatfs_args *uap)
760
{
761
	struct freebsd11_statfs osb;
762
	struct statfs *sfp;
763
	int error;
764
765
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
766
	error = kern_fstatfs(td, uap->fd, sfp);
767
	if (error == 0) {
768
		freebsd11_cvtstatfs(sfp, &osb);
769
		error = copyout(&osb, uap->buf, sizeof(osb));
770
	}
771
	free(sfp, M_STATFS);
772
	return (error);
773
}
774
775
/*
776
 * Get statistics on all filesystems.
777
 */
778
int
779
freebsd11_getfsstat(struct thread *td, struct freebsd11_getfsstat_args *uap)
780
{
781
	struct freebsd11_statfs osb;
782
	struct statfs *buf, *sp;
783
	size_t count, size;
784
	int error;
785
786
	count = uap->bufsize / sizeof(struct ostatfs);
787
	size = count * sizeof(struct statfs);
788
	error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE,
789
	    uap->mode);
790
	if (error == 0)
791
		td->td_retval[0] = count;
792
	if (size > 0) {
793
		sp = buf;
794
		while (count > 0 && error == 0) {
795
			freebsd11_cvtstatfs(sp, &osb);
796
			error = copyout(&osb, uap->buf, sizeof(osb));
797
			sp++;
798
			uap->buf++;
799
			count--;
800
		}
801
		free(buf, M_STATFS);
802
	}
803
	return (error);
804
}
805
806
/*
807
 * Implement fstatfs() for (NFS) file handles.
808
 */
809
int
810
freebsd11_fhstatfs(struct thread *td, struct freebsd11_fhstatfs_args *uap)
811
{
812
	struct freebsd11_statfs osb;
813
	struct statfs *sfp;
814
	fhandle_t fh;
815
	int error;
816
817
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
818
	if (error)
819
		return (error);
820
	sfp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
821
	error = kern_fhstatfs(td, fh, sfp);
822
	if (error == 0) {
823
		freebsd11_cvtstatfs(sfp, &osb);
824
		error = copyout(&osb, uap->buf, sizeof(osb));
825
	}
826
	free(sfp, M_STATFS);
827
	return (error);
828
}
829
830
/*
831
 * Convert a new format statfs structure to an old format statfs structure.
832
 */
833
static void
834
freebsd11_cvtstatfs(nsp, osp)
835
	struct statfs *nsp;
836
	struct freebsd11_statfs *osp;
837
{
838
	bzero(osp, sizeof(*osp));
839
	osp->f_version = FREEBSD11_STATFS_VERSION;
840
	osp->f_type = nsp->f_type;
841
	osp->f_flags = nsp->f_flags;
842
	osp->f_bsize = nsp->f_bsize;
843
	osp->f_iosize = nsp->f_iosize;
844
	osp->f_blocks = nsp->f_blocks;
845
	osp->f_bfree = nsp->f_bfree;
846
	osp->f_bavail = nsp->f_bavail;
847
	osp->f_files = nsp->f_files;
848
	osp->f_ffree = nsp->f_ffree;
849
	osp->f_syncwrites = nsp->f_syncwrites;
850
	osp->f_asyncwrites = nsp->f_asyncwrites;
851
	osp->f_syncreads = nsp->f_syncreads;
852
	osp->f_asyncreads = nsp->f_asyncreads;
853
	osp->f_namemax = nsp->f_namemax;
854
	osp->f_owner = nsp->f_owner;
855
	osp->f_fsid = nsp->f_fsid;
856
	strlcpy(osp->f_fstypename, nsp->f_fstypename,
857
	    MIN(MFSNAMELEN, sizeof(osp->f_fstypename)));
858
	strlcpy(osp->f_mntonname, nsp->f_mntonname,
859
	    MIN(MNAMELEN, sizeof(osp->f_mntonname)));
860
	strlcpy(osp->f_mntfromname, nsp->f_mntfromname,
861
	    MIN(MNAMELEN, sizeof(osp->f_mntfromname)));
862
}
863
#endif /* COMPAT_FREEBSD11 */
864
731
/*
865
/*
732
 * Change current working directory to a given file descriptor.
866
 * Change current working directory to a given file descriptor.
733
 */
867
 */
Lines 1133-1177 ocreat(td, uap) Link Here
1133
 * Create a special file.
1267
 * Create a special file.
1134
 */
1268
 */
1135
#ifndef _SYS_SYSPROTO_H_
1269
#ifndef _SYS_SYSPROTO_H_
1136
struct mknod_args {
1270
struct mknodat_args {
1271
	int	fd;
1137
	char	*path;
1272
	char	*path;
1138
	int	mode;
1273
	mode_t	mode;
1139
	int	dev;
1274
	dev_t	dev;
1140
};
1275
};
1141
#endif
1276
#endif
1142
int
1277
int
1143
sys_mknod(td, uap)
1278
sys_mknodat(struct thread *td, struct mknodat_args *uap)
1144
	struct thread *td;
1279
{
1145
	register struct mknod_args /* {
1280
1146
		char *path;
1281
	return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode,
1147
		int mode;
1282
	    uap->dev));
1148
		int dev;
1283
}
1149
	} */ *uap;
1284
1285
#if defined(COMPAT_FREEBSD11)
1286
int
1287
freebsd11_mknod(struct thread *td,
1288
    struct freebsd11_mknod_args *uap)
1150
{
1289
{
1151
1290
1152
	return (kern_mknodat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1291
	return (kern_mknodat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1153
	    uap->mode, uap->dev));
1292
	    uap->mode, uap->dev));
1154
}
1293
}
1155
1294
1156
#ifndef _SYS_SYSPROTO_H_
1157
struct mknodat_args {
1158
	int	fd;
1159
	char	*path;
1160
	mode_t	mode;
1161
	dev_t	dev;
1162
};
1163
#endif
1164
int
1295
int
1165
sys_mknodat(struct thread *td, struct mknodat_args *uap)
1296
freebsd11_mknodat(struct thread *td,
1297
    struct freebsd11_mknodat_args *uap)
1166
{
1298
{
1167
1299
1168
	return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode,
1300
	return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE, uap->mode,
1169
	    uap->dev));
1301
	    uap->dev));
1170
}
1302
}
1303
#endif /* COMPAT_FREEBSD11 */
1171
1304
1172
int
1305
int
1173
kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
1306
kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
1174
    int mode, int dev)
1307
    int mode, dev_t dev)
1175
{
1308
{
1176
	struct vnode *vp;
1309
	struct vnode *vp;
1177
	struct mount *mp;
1310
	struct mount *mp;
Lines 2090-2122 cvtstat(st, ost) Link Here
2090
}
2223
}
2091
#endif /* COMPAT_43 */
2224
#endif /* COMPAT_43 */
2092
2225
2093
/*
2226
#if defined(COMPAT_FREEBSD11)
2094
 * Get file status; this version follows links.
2227
void
2095
 */
2228
freebsd11_cvtstat(struct stat *st, struct freebsd11_stat *ost)
2096
#ifndef _SYS_SYSPROTO_H_
2229
{
2097
struct stat_args {
2230
2098
	char	*path;
2231
	ost->st_dev = st->st_dev;
2099
	struct stat *ub;
2232
	ost->st_ino = st->st_ino;		/* truncate */
2100
};
2233
	ost->st_mode = st->st_mode;
2101
#endif
2234
	ost->st_nlink = st->st_nlink;		/* truncate */
2235
	ost->st_uid = st->st_uid;
2236
	ost->st_gid = st->st_gid;
2237
	ost->st_rdev = st->st_rdev;
2238
	ost->st_atim = st->st_atim;
2239
	ost->st_mtim = st->st_mtim;
2240
	ost->st_ctim = st->st_ctim;
2241
	ost->st_size = st->st_size;
2242
	ost->st_blocks = st->st_blocks;
2243
	ost->st_blksize = st->st_blksize;
2244
	ost->st_flags = st->st_flags;
2245
	ost->st_gen = st->st_gen;
2246
	ost->st_lspare = 0;
2247
	ost->st_birthtim = st->st_birthtim;
2248
	bzero((char *)&ost->st_birthtim + sizeof(ost->st_birthtim),
2249
	    sizeof(*ost) - offsetof(struct freebsd11_stat,
2250
	    st_birthtim) - sizeof(ost->st_birthtim));
2251
}
2252
2102
int
2253
int
2103
sys_stat(td, uap)
2254
freebsd11_stat(struct thread *td, struct freebsd11_stat_args* uap)
2104
	struct thread *td;
2105
	register struct stat_args /* {
2106
		char *path;
2107
		struct stat *ub;
2108
	} */ *uap;
2109
{
2255
{
2110
	struct stat sb;
2256
	struct stat sb;
2257
	struct freebsd11_stat osb;
2111
	int error;
2258
	int error;
2112
2259
2113
	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
2260
	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
2114
	    &sb, NULL);
2261
	    &sb, NULL);
2115
	if (error == 0)
2262
	if (error != 0)
2116
		error = copyout(&sb, uap->ub, sizeof (sb));
2263
		return (error);
2264
	freebsd11_cvtstat(&sb, &osb);
2265
	error = copyout(&osb, uap->ub, sizeof(osb));
2117
	return (error);
2266
	return (error);
2118
}
2267
}
2119
2268
2269
int
2270
freebsd11_lstat(struct thread *td, struct freebsd11_lstat_args* uap)
2271
{
2272
	struct stat sb;
2273
	struct freebsd11_stat osb;
2274
	int error;
2275
2276
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2277
	    UIO_USERSPACE, &sb, NULL);
2278
	if (error != 0)
2279
		return (error);
2280
	freebsd11_cvtstat(&sb, &osb);
2281
	error = copyout(&osb, uap->ub, sizeof(osb));
2282
	return (error);
2283
}
2284
2285
int
2286
freebsd11_fhstat(struct thread *td, struct freebsd11_fhstat_args* uap)
2287
{
2288
	struct fhandle fh;
2289
	struct stat sb;
2290
	struct freebsd11_stat osb;
2291
	int error;
2292
2293
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2294
	if (error != 0)
2295
		return (error);
2296
	error = kern_fhstat(td, fh, &sb);
2297
	if (error != 0)
2298
		return (error);
2299
	freebsd11_cvtstat(&sb, &osb);
2300
	error = copyout(&osb, uap->sb, sizeof(osb));
2301
	return (error);
2302
}
2303
2304
int
2305
freebsd11_fstatat(struct thread *td, struct freebsd11_fstatat_args* uap)
2306
{
2307
	struct stat sb;
2308
	struct freebsd11_stat osb;
2309
	int error;
2310
2311
	error = kern_statat(td, uap->flag, uap->fd, uap->path,
2312
	    UIO_USERSPACE, &sb, NULL);
2313
	if (error != 0)
2314
		return (error);
2315
	freebsd11_cvtstat(&sb, &osb);
2316
	error = copyout(&osb, uap->buf, sizeof(osb));
2317
	return (error);
2318
}
2319
#endif	/* COMPAT_FREEBSD11 */
2320
2321
/*
2322
 * Get file status
2323
 */
2120
#ifndef _SYS_SYSPROTO_H_
2324
#ifndef _SYS_SYSPROTO_H_
2121
struct fstatat_args {
2325
struct fstatat_args {
2122
	int	fd;
2326
	int	fd;
Lines 2169-2174 kern_statat(struct thread *td, int flag, int fd, char *path, Link Here
2169
	vput(nd.ni_vp);
2373
	vput(nd.ni_vp);
2170
	if (error != 0)
2374
	if (error != 0)
2171
		return (error);
2375
		return (error);
2376
#ifdef __STAT_TIME_T_EXT
2377
	sb.st_atim_ext = 0;
2378
	sb.st_mtim_ext = 0;
2379
	sb.st_ctim_ext = 0;
2380
	sb.st_btim_ext = 0;
2381
#endif
2172
	*sbp = sb;
2382
	*sbp = sb;
2173
#ifdef KTRACE
2383
#ifdef KTRACE
2174
	if (KTRPOINT(td, KTR_STRUCT))
2384
	if (KTRPOINT(td, KTR_STRUCT))
Lines 2177-2219 kern_statat(struct thread *td, int flag, int fd, char *path, Link Here
2177
	return (0);
2387
	return (0);
2178
}
2388
}
2179
2389
2180
/*
2390
#if defined(COMPAT_FREEBSD11)
2181
 * Get file status; this version does not follow links.
2182
 */
2183
#ifndef _SYS_SYSPROTO_H_
2184
struct lstat_args {
2185
	char	*path;
2186
	struct stat *ub;
2187
};
2188
#endif
2189
int
2190
sys_lstat(td, uap)
2191
	struct thread *td;
2192
	register struct lstat_args /* {
2193
		char *path;
2194
		struct stat *ub;
2195
	} */ *uap;
2196
{
2197
	struct stat sb;
2198
	int error;
2199
2200
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2201
	    UIO_USERSPACE, &sb, NULL);
2202
	if (error == 0)
2203
		error = copyout(&sb, uap->ub, sizeof (sb));
2204
	return (error);
2205
}
2206
2207
/*
2391
/*
2208
 * Implementation of the NetBSD [l]stat() functions.
2392
 * Implementation of the NetBSD [l]stat() functions.
2209
 */
2393
 */
2210
void
2394
void
2211
cvtnstat(sb, nsb)
2395
freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb)
2212
	struct stat *sb;
2213
	struct nstat *nsb;
2214
{
2396
{
2215
2397
2216
	bzero(nsb, sizeof *nsb);
2398
	bzero(nsb, sizeof(*nsb));
2217
	nsb->st_dev = sb->st_dev;
2399
	nsb->st_dev = sb->st_dev;
2218
	nsb->st_ino = sb->st_ino;
2400
	nsb->st_ino = sb->st_ino;
2219
	nsb->st_mode = sb->st_mode;
2401
	nsb->st_mode = sb->st_mode;
Lines 2233-2247 cvtnstat(sb, nsb) Link Here
2233
}
2415
}
2234
2416
2235
#ifndef _SYS_SYSPROTO_H_
2417
#ifndef _SYS_SYSPROTO_H_
2236
struct nstat_args {
2418
struct freebsd11_nstat_args {
2237
	char	*path;
2419
	char	*path;
2238
	struct nstat *ub;
2420
	struct nstat *ub;
2239
};
2421
};
2240
#endif
2422
#endif
2241
int
2423
int
2242
sys_nstat(td, uap)
2424
freebsd11_nstat(td, uap)
2243
	struct thread *td;
2425
	struct thread *td;
2244
	register struct nstat_args /* {
2426
	register struct freebsd11_nstat_args /* {
2245
		char *path;
2427
		char *path;
2246
		struct nstat *ub;
2428
		struct nstat *ub;
2247
	} */ *uap;
2429
	} */ *uap;
Lines 2254-2260 sys_nstat(td, uap) Link Here
2254
	    &sb, NULL);
2436
	    &sb, NULL);
2255
	if (error != 0)
2437
	if (error != 0)
2256
		return (error);
2438
		return (error);
2257
	cvtnstat(&sb, &nsb);
2439
	freebsd11_cvtnstat(&sb, &nsb);
2258
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2440
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2259
}
2441
}
2260
2442
Lines 2262-2276 sys_nstat(td, uap) Link Here
2262
 * NetBSD lstat.  Get file status; this version does not follow links.
2444
 * NetBSD lstat.  Get file status; this version does not follow links.
2263
 */
2445
 */
2264
#ifndef _SYS_SYSPROTO_H_
2446
#ifndef _SYS_SYSPROTO_H_
2265
struct lstat_args {
2447
struct freebsd11_nlstat_args {
2266
	char	*path;
2448
	char	*path;
2267
	struct stat *ub;
2449
	struct stat *ub;
2268
};
2450
};
2269
#endif
2451
#endif
2270
int
2452
int
2271
sys_nlstat(td, uap)
2453
freebsd11_nlstat(td, uap)
2272
	struct thread *td;
2454
	struct thread *td;
2273
	register struct nlstat_args /* {
2455
	register struct freebsd11_nlstat_args /* {
2274
		char *path;
2456
		char *path;
2275
		struct nstat *ub;
2457
		struct nstat *ub;
2276
	} */ *uap;
2458
	} */ *uap;
Lines 2283-2291 sys_nlstat(td, uap) Link Here
2283
	    UIO_USERSPACE, &sb, NULL);
2465
	    UIO_USERSPACE, &sb, NULL);
2284
	if (error != 0)
2466
	if (error != 0)
2285
		return (error);
2467
		return (error);
2286
	cvtnstat(&sb, &nsb);
2468
	freebsd11_cvtnstat(&sb, &nsb);
2287
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2469
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2288
}
2470
}
2471
#endif /* COMPAT_FREEBSD11 */
2289
2472
2290
/*
2473
/*
2291
 * Get configurable pathname variables.
2474
 * Get configurable pathname variables.
Lines 3751-3757 out: Link Here
3751
	return (error);
3934
	return (error);
3752
}
3935
}
3753
3936
3937
#if defined(COMPAT_43) || defined(COMPAT_FREEBSD11)
3938
int
3939
freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int count,
3940
    long *basep, void (*func)(struct freebsd11_dirent *))
3941
{
3942
	struct freebsd11_dirent dstdp;
3943
	struct dirent *dp, *edp;
3944
	char *dirbuf;
3945
	off_t base;
3946
	ssize_t resid, ucount;
3947
	int error;
3948
3949
	/* XXX arbitrary sanity limit on `count'. */
3950
	count = min(count, 64 * 1024);
3951
3952
	dirbuf = malloc(count, M_TEMP, M_WAITOK);
3953
3954
	error = kern_getdirentries(td, fd, dirbuf, count, &base, &resid,
3955
	    UIO_SYSSPACE);
3956
	if (error != 0)
3957
		goto done;
3958
	if (basep != NULL)
3959
		*basep = base;
3960
3961
	ucount = 0;
3962
	for (dp = (struct dirent *)dirbuf,
3963
	    edp = (struct dirent *)&dirbuf[count - resid];
3964
	    ucount < count && dp < edp; ) {
3965
		if (dp->d_reclen == 0)
3966
			break;
3967
		MPASS(dp->d_reclen >= _GENERIC_DIRLEN(0));
3968
		if (dp->d_namlen > sizeof(dstdp.d_name) - 1)
3969
			continue;
3970
		dstdp.d_type = dp->d_type;
3971
		dstdp.d_namlen = dp->d_namlen;
3972
		dstdp.d_fileno = dp->d_fileno;		/* truncate */
3973
		dstdp.d_reclen = sizeof(dstdp) - sizeof(dstdp.d_name) +
3974
		    ((dp->d_namlen + 1 + 3) &~ 3);
3975
		bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
3976
		bzero(dstdp.d_name + dstdp.d_namlen,
3977
		    dstdp.d_reclen - offsetof(struct freebsd11_dirent, d_name) -
3978
		    dstdp.d_namlen);
3979
		MPASS(dstdp.d_reclen <= dp->d_reclen);
3980
		MPASS(ucount + dstdp.d_reclen <= count);
3981
		if (func != NULL)
3982
			func(&dstdp);
3983
		error = copyout(&dstdp, ubuf + ucount, dstdp.d_reclen);
3984
		if (error != 0)
3985
			break;
3986
		dp = (struct dirent *)((char *)dp + dp->d_reclen);
3987
		ucount += dstdp.d_reclen;
3988
	}
3989
3990
done:
3991
	free(dirbuf, M_TEMP);
3992
	if (error == 0)
3993
		td->td_retval[0] = ucount;
3994
	return (error);
3995
}
3996
#endif /* COMPAT */
3997
3754
#ifdef COMPAT_43
3998
#ifdef COMPAT_43
3999
static void
4000
ogetdirentries_cvt(struct freebsd11_dirent *dp)
4001
{
4002
#if (BYTE_ORDER == LITTLE_ENDIAN)
4003
	/*
4004
	 * The expected low byte of dp->d_namlen is our dp->d_type.
4005
	 * The high MBZ byte of dp->d_namlen is our dp->d_namlen.
4006
	 */
4007
	dp->d_type = dp->d_namlen;
4008
	dp->d_namlen = 0;
4009
#else
4010
	/*
4011
	 * The dp->d_type is the high byte of the expected dp->d_namlen,
4012
	 * so must be zero'ed.
4013
	 */
4014
	dp->d_type = 0;
4015
#endif
4016
}
4017
3755
/*
4018
/*
3756
 * Read a block of directory entries in a filesystem independent format.
4019
 * Read a block of directory entries in a filesystem independent format.
3757
 */
4020
 */
Lines 3779-3916 int Link Here
3779
kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
4042
kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
3780
    long *ploff)
4043
    long *ploff)
3781
{
4044
{
3782
	struct vnode *vp;
4045
	long base;
3783
	struct file *fp;
4046
	int error;
3784
	struct uio auio, kuio;
3785
	struct iovec aiov, kiov;
3786
	struct dirent *dp, *edp;
3787
	cap_rights_t rights;
3788
	caddr_t dirbuf;
3789
	int error, eofflag, readcnt;
3790
	long loff;
3791
	off_t foffset;
3792
4047
3793
	/* XXX arbitrary sanity limit on `count'. */
4048
	/* XXX arbitrary sanity limit on `count'. */
3794
	if (uap->count > 64 * 1024)
4049
	if (uap->count > 64 * 1024)
3795
		return (EINVAL);
4050
		return (EINVAL);
3796
	error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
4051
3797
	if (error != 0)
4052
	error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
3798
		return (error);
4053
	    &base, ogetdirentries_cvt);
3799
	if ((fp->f_flag & FREAD) == 0) {
4054
3800
		fdrop(fp, td);
4055
	if (error == 0 && uap->basep != NULL)
3801
		return (EBADF);
4056
		error = copyout(&base, uap->basep, sizeof(long));
3802
	}
4057
3803
	vp = fp->f_vnode;
3804
	foffset = foffset_lock(fp, 0);
3805
unionread:
3806
	if (vp->v_type != VDIR) {
3807
		foffset_unlock(fp, foffset, 0);
3808
		fdrop(fp, td);
3809
		return (EINVAL);
3810
	}
3811
	aiov.iov_base = uap->buf;
3812
	aiov.iov_len = uap->count;
3813
	auio.uio_iov = &aiov;
3814
	auio.uio_iovcnt = 1;
3815
	auio.uio_rw = UIO_READ;
3816
	auio.uio_segflg = UIO_USERSPACE;
3817
	auio.uio_td = td;
3818
	auio.uio_resid = uap->count;
3819
	vn_lock(vp, LK_SHARED | LK_RETRY);
3820
	loff = auio.uio_offset = foffset;
3821
#ifdef MAC
3822
	error = mac_vnode_check_readdir(td->td_ucred, vp);
3823
	if (error != 0) {
3824
		VOP_UNLOCK(vp, 0);
3825
		foffset_unlock(fp, foffset, FOF_NOUPDATE);
3826
		fdrop(fp, td);
3827
		return (error);
3828
	}
3829
#endif
3830
#	if (BYTE_ORDER != LITTLE_ENDIAN)
3831
		if (vp->v_mount->mnt_maxsymlinklen <= 0) {
3832
			error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
3833
			    NULL, NULL);
3834
			foffset = auio.uio_offset;
3835
		} else
3836
#	endif
3837
	{
3838
		kuio = auio;
3839
		kuio.uio_iov = &kiov;
3840
		kuio.uio_segflg = UIO_SYSSPACE;
3841
		kiov.iov_len = uap->count;
3842
		dirbuf = malloc(uap->count, M_TEMP, M_WAITOK);
3843
		kiov.iov_base = dirbuf;
3844
		error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
3845
			    NULL, NULL);
3846
		foffset = kuio.uio_offset;
3847
		if (error == 0) {
3848
			readcnt = uap->count - kuio.uio_resid;
3849
			edp = (struct dirent *)&dirbuf[readcnt];
3850
			for (dp = (struct dirent *)dirbuf; dp < edp; ) {
3851
#				if (BYTE_ORDER == LITTLE_ENDIAN)
3852
					/*
3853
					 * The expected low byte of
3854
					 * dp->d_namlen is our dp->d_type.
3855
					 * The high MBZ byte of dp->d_namlen
3856
					 * is our dp->d_namlen.
3857
					 */
3858
					dp->d_type = dp->d_namlen;
3859
					dp->d_namlen = 0;
3860
#				else
3861
					/*
3862
					 * The dp->d_type is the high byte
3863
					 * of the expected dp->d_namlen,
3864
					 * so must be zero'ed.
3865
					 */
3866
					dp->d_type = 0;
3867
#				endif
3868
				if (dp->d_reclen > 0) {
3869
					dp = (struct dirent *)
3870
					    ((char *)dp + dp->d_reclen);
3871
				} else {
3872
					error = EIO;
3873
					break;
3874
				}
3875
			}
3876
			if (dp >= edp)
3877
				error = uiomove(dirbuf, readcnt, &auio);
3878
		}
3879
		free(dirbuf, M_TEMP);
3880
	}
3881
	if (error != 0) {
3882
		VOP_UNLOCK(vp, 0);
3883
		foffset_unlock(fp, foffset, 0);
3884
		fdrop(fp, td);
3885
		return (error);
3886
	}
3887
	if (uap->count == auio.uio_resid &&
3888
	    (vp->v_vflag & VV_ROOT) &&
3889
	    (vp->v_mount->mnt_flag & MNT_UNION)) {
3890
		struct vnode *tvp = vp;
3891
		vp = vp->v_mount->mnt_vnodecovered;
3892
		VREF(vp);
3893
		fp->f_vnode = vp;
3894
		fp->f_data = vp;
3895
		foffset = 0;
3896
		vput(tvp);
3897
		goto unionread;
3898
	}
3899
	VOP_UNLOCK(vp, 0);
3900
	foffset_unlock(fp, foffset, 0);
3901
	fdrop(fp, td);
3902
	td->td_retval[0] = uap->count - auio.uio_resid;
3903
	if (error == 0)
3904
		*ploff = loff;
3905
	return (error);
4058
	return (error);
3906
}
4059
}
3907
#endif /* COMPAT_43 */
4060
#endif /* COMPAT_43 */
3908
4061
3909
/*
4062
#if defined(COMPAT_FREEBSD11)
3910
 * Read a block of directory entries in a filesystem independent format.
3911
 */
3912
#ifndef _SYS_SYSPROTO_H_
4063
#ifndef _SYS_SYSPROTO_H_
3913
struct getdirentries_args {
4064
struct freebsd11_getdirentries_args {
3914
	int	fd;
4065
	int	fd;
3915
	char	*buf;
4066
	char	*buf;
3916
	u_int	count;
4067
	u_int	count;
Lines 3918-3954 struct getdirentries_args { Link Here
3918
};
4069
};
3919
#endif
4070
#endif
3920
int
4071
int
3921
sys_getdirentries(td, uap)
4072
freebsd11_getdirentries(struct thread *td,
3922
	struct thread *td;
4073
    struct freebsd11_getdirentries_args *uap)
3923
	register struct getdirentries_args /* {
3924
		int fd;
3925
		char *buf;
3926
		u_int count;
3927
		long *basep;
3928
	} */ *uap;
3929
{
4074
{
3930
	long base;
4075
	long base;
3931
	int error;
4076
	int error;
3932
4077
4078
	error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
4079
	    &base, NULL);
4080
4081
	if (error == 0 && uap->basep != NULL)
4082
		error = copyout(&base, uap->basep, sizeof(long));
4083
	return (error);
4084
}
4085
4086
int
4087
freebsd11_getdents(struct thread *td, struct freebsd11_getdents_args *uap)
4088
{
4089
	struct freebsd11_getdirentries_args ap;
4090
4091
	ap.fd = uap->fd;
4092
	ap.buf = uap->buf;
4093
	ap.count = uap->count;
4094
	ap.basep = NULL;
4095
	return (freebsd11_getdirentries(td, &ap));
4096
}
4097
#endif /* COMPAT_FREEBSD11 */
4098
4099
/*
4100
 * Read a block of directory entries in a filesystem independent format.
4101
 */
4102
int
4103
sys_getdirentries(struct thread *td, struct getdirentries_args *uap)
4104
{
4105
	off_t base;
4106
	int error;
4107
3933
	error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
4108
	error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
3934
	    NULL, UIO_USERSPACE);
4109
	    NULL, UIO_USERSPACE);
3935
	if (error != 0)
4110
	if (error != 0)
3936
		return (error);
4111
		return (error);
3937
	if (uap->basep != NULL)
4112
	if (uap->basep != NULL)
3938
		error = copyout(&base, uap->basep, sizeof(long));
4113
		error = copyout(&base, uap->basep, sizeof(off_t));
3939
	return (error);
4114
	return (error);
3940
}
4115
}
3941
4116
3942
int
4117
int
3943
kern_getdirentries(struct thread *td, int fd, char *buf, u_int count,
4118
kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
3944
    long *basep, ssize_t *residp, enum uio_seg bufseg)
4119
    off_t *basep, ssize_t *residp, enum uio_seg bufseg)
3945
{
4120
{
3946
	struct vnode *vp;
4121
	struct vnode *vp;
3947
	struct file *fp;
4122
	struct file *fp;
3948
	struct uio auio;
4123
	struct uio auio;
3949
	struct iovec aiov;
4124
	struct iovec aiov;
3950
	cap_rights_t rights;
4125
	cap_rights_t rights;
3951
	long loff;
4126
	off_t loff;
3952
	int error, eofflag;
4127
	int error, eofflag;
3953
	off_t foffset;
4128
	off_t foffset;
3954
4129
Lines 4015-4045 fail: Link Here
4015
	return (error);
4190
	return (error);
4016
}
4191
}
4017
4192
4018
#ifndef _SYS_SYSPROTO_H_
4019
struct getdents_args {
4020
	int fd;
4021
	char *buf;
4022
	size_t count;
4023
};
4024
#endif
4025
int
4026
sys_getdents(td, uap)
4027
	struct thread *td;
4028
	register struct getdents_args /* {
4029
		int fd;
4030
		char *buf;
4031
		u_int count;
4032
	} */ *uap;
4033
{
4034
	struct getdirentries_args ap;
4035
4036
	ap.fd = uap->fd;
4037
	ap.buf = uap->buf;
4038
	ap.count = uap->count;
4039
	ap.basep = NULL;
4040
	return (sys_getdirentries(td, &ap));
4041
}
4042
4043
/*
4193
/*
4044
 * Set the mode mask for creation of filesystem nodes.
4194
 * Set the mode mask for creation of filesystem nodes.
4045
 */
4195
 */
(-)b/sys/kern/vfs_vnops.c (-1 / +5 lines)
Lines 2354-2360 vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif) Link Here
2354
	char *fullpath, *freepath;
2354
	char *fullpath, *freepath;
2355
	int error;
2355
	int error;
2356
2356
2357
	kif->kf_vnode_type = vntype_to_kinfo(vp->v_type);
2357
	kif->kf_un.kf_file.kf_file_type = vntype_to_kinfo(vp->v_type);
2358
	freepath = NULL;
2358
	freepath = NULL;
2359
	fullpath = "-";
2359
	fullpath = "-";
2360
	error = vn_fullpath(curthread, vp, &fullpath, &freepath);
2360
	error = vn_fullpath(curthread, vp, &fullpath, &freepath);
Lines 2383-2392 vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif) Link Here
2383
	else
2383
	else
2384
		kif->kf_un.kf_file.kf_file_fsid =
2384
		kif->kf_un.kf_file.kf_file_fsid =
2385
		    vp->v_mount->mnt_stat.f_fsid.val[0];
2385
		    vp->v_mount->mnt_stat.f_fsid.val[0];
2386
	kif->kf_un.kf_file.kf_file_fsid_freebsd11 =
2387
	    kif->kf_un.kf_file.kf_file_fsid; /* truncate */
2386
	kif->kf_un.kf_file.kf_file_fileid = va.va_fileid;
2388
	kif->kf_un.kf_file.kf_file_fileid = va.va_fileid;
2387
	kif->kf_un.kf_file.kf_file_mode = MAKEIMODE(va.va_type, va.va_mode);
2389
	kif->kf_un.kf_file.kf_file_mode = MAKEIMODE(va.va_type, va.va_mode);
2388
	kif->kf_un.kf_file.kf_file_size = va.va_size;
2390
	kif->kf_un.kf_file.kf_file_size = va.va_size;
2389
	kif->kf_un.kf_file.kf_file_rdev = va.va_rdev;
2391
	kif->kf_un.kf_file.kf_file_rdev = va.va_rdev;
2392
	kif->kf_un.kf_file.kf_file_rdev_freebsd11 =
2393
	    kif->kf_un.kf_file.kf_file_rdev; /* truncate */
2390
	return (0);
2394
	return (0);
2391
}
2395
}
2392
2396
(-)b/sys/nlm/nlm_advlock.c (-2 / +3 lines)
Lines 202-208 nlm_advlock_internal(struct vnode *vp, void *id, int op, struct flock *fl, Link Here
202
	union nfsfh fh;
202
	union nfsfh fh;
203
	struct sockaddr *sa;
203
	struct sockaddr *sa;
204
	struct sockaddr_storage ss;
204
	struct sockaddr_storage ss;
205
	char servername[MNAMELEN];
205
	char *servername;
206
	struct timeval timo;
206
	struct timeval timo;
207
	int retries;
207
	int retries;
208
	rpcvers_t vers;
208
	rpcvers_t vers;
Lines 218-223 nlm_advlock_internal(struct vnode *vp, void *id, int op, struct flock *fl, Link Here
218
218
219
	ASSERT_VOP_LOCKED(vp, "nlm_advlock_1");
219
	ASSERT_VOP_LOCKED(vp, "nlm_advlock_1");
220
220
221
	servername = malloc(MNAMELEN, M_TEMP, M_WAITOK); /* XXXKIB vp locked */
221
	nmp = VFSTONFS(vp->v_mount);
222
	nmp = VFSTONFS(vp->v_mount);
222
	/*
223
	/*
223
	 * Push any pending writes to the server and flush our cache
224
	 * Push any pending writes to the server and flush our cache
Lines 381-387 nlm_advlock_internal(struct vnode *vp, void *id, int op, struct flock *fl, Link Here
381
	AUTH_DESTROY(auth);
382
	AUTH_DESTROY(auth);
382
383
383
	nlm_host_release(host);
384
	nlm_host_release(host);
384
385
	free(servername, M_TEMP);
385
	return (error);
386
	return (error);
386
}
387
}
387
388
(-)b/sys/security/audit/audit_private.h (-4 / +4 lines)
Lines 107-115 struct vnode_au_info { Link Here
107
	mode_t	vn_mode;
107
	mode_t	vn_mode;
108
	uid_t	vn_uid;
108
	uid_t	vn_uid;
109
	gid_t	vn_gid;
109
	gid_t	vn_gid;
110
	dev_t	vn_dev;
110
	u_int32_t vn_dev;		/* XXX dev_t compatibility */
111
	long	vn_fsid;
111
	long	vn_fsid;		/* XXX uint64_t compatibility */
112
	long	vn_fileid;
112
	long	vn_fileid;		/* XXX ino_t compatibility */
113
	long	vn_gen;
113
	long	vn_gen;
114
};
114
};
115
115
Lines 210-216 struct audit_record { Link Here
210
	int			ar_arg_atfd2;
210
	int			ar_arg_atfd2;
211
	int			ar_arg_fflags;
211
	int			ar_arg_fflags;
212
	mode_t			ar_arg_mode;
212
	mode_t			ar_arg_mode;
213
	int			ar_arg_dev;
213
	int			ar_arg_dev;	/* XXX dev_t compatibility */
214
	long			ar_arg_value;
214
	long			ar_arg_value;
215
	void			*ar_arg_addr;
215
	void			*ar_arg_addr;
216
	int			ar_arg_len;
216
	int			ar_arg_len;
(-)b/sys/sys/_types.h (-3 / +3 lines)
Lines 43-55 typedef __uint64_t __fsblkcnt_t; Link Here
43
typedef	__uint64_t	__fsfilcnt_t;
43
typedef	__uint64_t	__fsfilcnt_t;
44
typedef	__uint32_t	__gid_t;
44
typedef	__uint32_t	__gid_t;
45
typedef	__int64_t	__id_t;		/* can hold a gid_t, pid_t, or uid_t */
45
typedef	__int64_t	__id_t;		/* can hold a gid_t, pid_t, or uid_t */
46
typedef	__uint32_t	__ino_t;	/* inode number */
46
typedef	__uint64_t	__ino_t;	/* inode number */
47
typedef	long		__key_t;	/* IPC key (for Sys V IPC) */
47
typedef	long		__key_t;	/* IPC key (for Sys V IPC) */
48
typedef	__int32_t	__lwpid_t;	/* Thread ID (a.k.a. LWP) */
48
typedef	__int32_t	__lwpid_t;	/* Thread ID (a.k.a. LWP) */
49
typedef	__uint16_t	__mode_t;	/* permissions */
49
typedef	__uint16_t	__mode_t;	/* permissions */
50
typedef	int		__accmode_t;	/* access permissions */
50
typedef	int		__accmode_t;	/* access permissions */
51
typedef	int		__nl_item;
51
typedef	int		__nl_item;
52
typedef	__uint16_t	__nlink_t;	/* link count */
52
typedef	__uint64_t	__nlink_t;	/* link count */
53
typedef	__int64_t	__off_t;	/* file offset */
53
typedef	__int64_t	__off_t;	/* file offset */
54
typedef	__int64_t	__off64_t;	/* file offset (alias) */
54
typedef	__int64_t	__off64_t;	/* file offset (alias) */
55
typedef	__int32_t	__pid_t;	/* process [group] */
55
typedef	__int32_t	__pid_t;	/* process [group] */
Lines 105-111 typedef struct { Link Here
105
	long double __max_align2 __aligned(_Alignof(long double));
105
	long double __max_align2 __aligned(_Alignof(long double));
106
} __max_align_t;
106
} __max_align_t;
107
107
108
typedef	__uint32_t	__dev_t;	/* device number */
108
typedef	__uint64_t	__dev_t;	/* device number */
109
109
110
typedef	__uint32_t	__fixpt_t;	/* fixed point number */
110
typedef	__uint32_t	__fixpt_t;	/* fixed point number */
111
111
(-)b/sys/sys/acct.h (-5 / +27 lines)
Lines 45-56 Link Here
45
#define AC_COMM_LEN 16
45
#define AC_COMM_LEN 16
46
46
47
/*
47
/*
48
 * Accounting structure version 2 (current).
48
 * Accounting structure version 3 (current).
49
 * The first byte is always zero.
49
 * The first byte is always zero.
50
 * Time units are microseconds.
50
 * Time units are microseconds.
51
 */
51
 */
52
52
53
struct acctv2 {
53
struct acctv3 {
54
	uint8_t   ac_zero;		/* zero identifies new version */
54
	uint8_t   ac_zero;		/* zero identifies new version */
55
	uint8_t   ac_version;		/* record version number */
55
	uint8_t   ac_version;		/* record version number */
56
	uint16_t  ac_len;		/* record length */
56
	uint16_t  ac_len;		/* record length */
Lines 65-74 struct acctv2 { Link Here
65
	float	  ac_mem;		/* average memory usage */
65
	float	  ac_mem;		/* average memory usage */
66
	float	  ac_io;		/* count of IO blocks */
66
	float	  ac_io;		/* count of IO blocks */
67
	__dev_t   ac_tty;		/* controlling tty */
67
	__dev_t   ac_tty;		/* controlling tty */
68
68
	uint32_t  ac_pad0;
69
	uint16_t  ac_len2;		/* record length */
69
	uint16_t  ac_len2;		/* record length */
70
	union {
70
	union {
71
		__dev_t	  ac_align;	/* force v1 compatible alignment */
71
		uint32_t  ac_align;	/* force v1 compatible alignment */
72
72
73
#define	AFORK	0x01			/* forked but not exec'ed */
73
#define	AFORK	0x01			/* forked but not exec'ed */
74
/* ASU is no longer supported */
74
/* ASU is no longer supported */
Lines 84-89 struct acctv2 { Link Here
84
#define ac_flagx ac_trailer.ac_flag
84
#define ac_flagx ac_trailer.ac_flag
85
};
85
};
86
86
87
struct acctv2 {
88
	uint8_t   ac_zero;		/* zero identifies new version */
89
	uint8_t   ac_version;		/* record version number */
90
	uint16_t  ac_len;		/* record length */
91
92
	char	  ac_comm[AC_COMM_LEN];	/* command name */
93
	float	  ac_utime;		/* user time */
94
	float	  ac_stime;		/* system time */
95
	float	  ac_etime;		/* elapsed time */
96
	time_t	  ac_btime;		/* starting time */
97
	uid_t	  ac_uid;		/* user id */
98
	gid_t	  ac_gid;		/* group id */
99
	float	  ac_mem;		/* average memory usage */
100
	float	  ac_io;		/* count of IO blocks */
101
	uint32_t  ac_tty;		/* controlling tty */
102
103
	uint16_t  ac_len2;		/* record length */
104
	union {
105
		uint32_t   ac_align;	/* force v1 compatible alignment */
106
		uint8_t   ac_flag;	/* accounting flags */
107
	} ac_trailer;
108
};
87
109
88
/*
110
/*
89
 * Legacy accounting structure (rev. 1.5-1.18).
111
 * Legacy accounting structure (rev. 1.5-1.18).
Lines 105-111 struct acctv1 { Link Here
105
	gid_t	  ac_gid;		/* group id */
127
	gid_t	  ac_gid;		/* group id */
106
	uint16_t  ac_mem;		/* average memory usage */
128
	uint16_t  ac_mem;		/* average memory usage */
107
	comp_t	  ac_io;		/* count of IO blocks */
129
	comp_t	  ac_io;		/* count of IO blocks */
108
	__dev_t   ac_tty;		/* controlling tty */
130
	uint32_t  ac_tty;		/* controlling tty */
109
	uint8_t   ac_flag;		/* accounting flags */
131
	uint8_t   ac_flag;		/* accounting flags */
110
};
132
};
111
133
(-)b/sys/sys/dirent.h (-6 / +35 lines)
Lines 36-57 Link Here
36
#include <sys/cdefs.h>
36
#include <sys/cdefs.h>
37
#include <sys/_types.h>
37
#include <sys/_types.h>
38
38
39
#ifndef _INO_T_DECLARED
40
typedef	__ino_t		ino_t;
41
#define	_INO_T_DECLARED
42
#endif
43
44
#ifndef _OFF_T_DECLARED
45
typedef	__off_t		off_t;
46
#define	_OFF_T_DECLARED
47
#endif
48
39
/*
49
/*
40
 * The dirent structure defines the format of directory entries returned by
50
 * The dirent structure defines the format of directory entries returned by
41
 * the getdirentries(2) system call.
51
 * the getdirentries(2) system call.
42
 *
52
 *
43
 * A directory entry has a struct dirent at the front of it, containing its
53
 * A directory entry has a struct dirent at the front of it, containing its
44
 * inode number, the length of the entry, and the length of the name
54
 * inode number, the length of the entry, and the length of the name
45
 * contained in the entry.  These are followed by the name padded to a 4
55
 * contained in the entry.  These are followed by the name padded to an 8
46
 * byte boundary with null bytes.  All names are guaranteed null terminated.
56
 * byte boundary with null bytes.  All names are guaranteed null terminated.
47
 * The maximum length of a name in a directory is MAXNAMLEN.
57
 * The maximum length of a name in a directory is MAXNAMLEN.
58
 *
59
 * Explicit padding between the last member of the header (d_namelen) and
60
 * d_name avoids ABI padding at the end of dirent on LP64 architectures.
61
 * There is code depending on d_name being last.  Also, retaining this
62
 * padding on ILP32 architectures simplifies the compat32 layer.
48
 */
63
 */
49
64
50
struct dirent {
65
struct dirent {
51
	__uint32_t d_fileno;		/* file number of entry */
66
	ino_t      d_fileno;		/* file number of entry */
67
	off_t      d_off;		/* directory offset of entry */
52
	__uint16_t d_reclen;		/* length of this record */
68
	__uint16_t d_reclen;		/* length of this record */
53
	__uint8_t  d_type; 		/* file type, see below */
69
	__uint8_t  d_type;		/* file type, see below */
54
	__uint8_t  d_namlen;		/* length of string in d_name */
70
	__uint8_t  d_namlen;		/* length of string in d_name */
71
	__uint32_t d_pad0;
55
#if __BSD_VISIBLE
72
#if __BSD_VISIBLE
56
#define	MAXNAMLEN	255
73
#define	MAXNAMLEN	255
57
	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
74
	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
Lines 60-66 struct dirent { Link Here
60
#endif
77
#endif
61
};
78
};
62
79
80
#if defined(_WANT_FREEBSD11_DIRENT) || defined(_KERNEL)
81
struct freebsd11_dirent {
82
	__uint32_t d_fileno;		/* file number of entry */
83
	__uint16_t d_reclen;		/* length of this record */
84
	__uint8_t  d_type;		/* file type, see below */
85
	__uint8_t  d_namlen;		/* length of string in d_name */
86
	char	d_name[255 + 1];	/* name must be no longer than this */
87
};
88
#endif /* _WANT_FREEBSD11_DIRENT || _KERNEL */
89
63
#if __BSD_VISIBLE
90
#if __BSD_VISIBLE
91
64
/*
92
/*
65
 * File types
93
 * File types
66
 */
94
 */
Lines 84-96 struct dirent { Link Here
84
 * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
112
 * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold
85
 * the directory entry.  This returns the amount of space in struct direct
113
 * the directory entry.  This returns the amount of space in struct direct
86
 * without the d_name field, plus enough space for the name with a terminating
114
 * without the d_name field, plus enough space for the name with a terminating
87
 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
115
 * null byte (dp->d_namlen+1), rounded up to a 8 byte boundary.
88
 *
116
 *
89
 * XXX although this macro is in the implementation namespace, it requires
117
 * XXX although this macro is in the implementation namespace, it requires
90
 * a manifest constant that is not.
118
 * a manifest constant that is not.
91
 */
119
 */
92
#define	_GENERIC_DIRSIZ(dp) \
120
#define	_GENERIC_DIRLEN(namlen)					\
93
    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
121
	((__offsetof(struct dirent, d_name) + (namlen) + 1 + 7) & ~7)
122
#define	_GENERIC_DIRSIZ(dp)	_GENERIC_DIRLEN((dp)->d_namlen)
94
#endif /* __BSD_VISIBLE */
123
#endif /* __BSD_VISIBLE */
95
124
96
#ifdef _KERNEL
125
#ifdef _KERNEL
(-)b/sys/sys/mount.h (-2 / +30 lines)
Lines 65-72 struct fid { Link Here
65
 * filesystem statistics
65
 * filesystem statistics
66
 */
66
 */
67
#define	MFSNAMELEN	16		/* length of type name including null */
67
#define	MFSNAMELEN	16		/* length of type name including null */
68
#define	MNAMELEN	88		/* size of on/from name bufs */
68
#define	MNAMELEN	1024		/* size of on/from name bufs */
69
#define	STATFS_VERSION	0x20030518	/* current version number */
69
#define	STATFS_VERSION	0x20140518	/* current version number */
70
struct statfs {
70
struct statfs {
71
	uint32_t f_version;		/* structure version number */
71
	uint32_t f_version;		/* structure version number */
72
	uint32_t f_type;		/* type of filesystem */
72
	uint32_t f_type;		/* type of filesystem */
Lines 92-97 struct statfs { Link Here
92
	char	  f_mntonname[MNAMELEN];    /* directory on which mounted */
92
	char	  f_mntonname[MNAMELEN];    /* directory on which mounted */
93
};
93
};
94
94
95
#if defined(_WANT_FREEBSD11_STATFS) || defined(_KERNEL)
96
#define	FREEBSD11_STATFS_VERSION	0x20030518 /* current version number */
97
struct freebsd11_statfs {
98
	uint32_t f_version;		/* structure version number */
99
	uint32_t f_type;		/* type of filesystem */
100
	uint64_t f_flags;		/* copy of mount exported flags */
101
	uint64_t f_bsize;		/* filesystem fragment size */
102
	uint64_t f_iosize;		/* optimal transfer block size */
103
	uint64_t f_blocks;		/* total data blocks in filesystem */
104
	uint64_t f_bfree;		/* free blocks in filesystem */
105
	int64_t	 f_bavail;		/* free blocks avail to non-superuser */
106
	uint64_t f_files;		/* total file nodes in filesystem */
107
	int64_t	 f_ffree;		/* free nodes avail to non-superuser */
108
	uint64_t f_syncwrites;		/* count of sync writes since mount */
109
	uint64_t f_asyncwrites;		/* count of async writes since mount */
110
	uint64_t f_syncreads;		/* count of sync reads since mount */
111
	uint64_t f_asyncreads;		/* count of async reads since mount */
112
	uint64_t f_spare[10];		/* unused spare */
113
	uint32_t f_namemax;		/* maximum filename length */
114
	uid_t	  f_owner;		/* user that mounted the filesystem */
115
	fsid_t	  f_fsid;		/* filesystem id */
116
	char	  f_charspare[80];	/* spare string space */
117
	char	  f_fstypename[16];	/* filesystem type name */
118
	char	  f_mntfromname[88];	/* mounted filesystem */
119
	char	  f_mntonname[88];	/* directory on which mounted */
120
};
121
#endif /* _WANT_FREEBSD11_STATFS || _KERNEL */
122
95
#ifdef _KERNEL
123
#ifdef _KERNEL
96
#define	OMFSNAMELEN	16	/* length of fs type name, including null */
124
#define	OMFSNAMELEN	16	/* length of fs type name, including null */
97
#define	OMNAMELEN	(88 - 2 * sizeof(long))	/* size of on/from name bufs */
125
#define	OMNAMELEN	(88 - 2 * sizeof(long))	/* size of on/from name bufs */
(-)b/sys/sys/stat.h (-11 / +52 lines)
Lines 102-110 typedef __uid_t uid_t; Link Here
102
#ifdef _KERNEL
102
#ifdef _KERNEL
103
struct ostat {
103
struct ostat {
104
	__uint16_t st_dev;		/* inode's device */
104
	__uint16_t st_dev;		/* inode's device */
105
	ino_t	  st_ino;		/* inode's number */
105
	__uint32_t st_ino;		/* inode's number */
106
	mode_t	  st_mode;		/* inode protection mode */
106
	mode_t	  st_mode;		/* inode protection mode */
107
	nlink_t	  st_nlink;		/* number of hard links */
107
	__uint16_t st_nlink;		/* number of hard links */
108
	__uint16_t st_uid;		/* user ID of the file's owner */
108
	__uint16_t st_uid;		/* user ID of the file's owner */
109
	__uint16_t st_gid;		/* group ID of the file's group */
109
	__uint16_t st_gid;		/* group ID of the file's group */
110
	__uint16_t st_rdev;		/* device type */
110
	__uint16_t st_rdev;		/* device type */
Lines 119-132 struct ostat { Link Here
119
};
119
};
120
#endif
120
#endif
121
121
122
struct stat {
122
#if defined(_WANT_FREEBSD11_STAT) || defined(_KERNEL)
123
	__dev_t   st_dev;		/* inode's device */
123
struct freebsd11_stat {
124
	ino_t	  st_ino;		/* inode's number */
124
	__uint32_t st_dev;		/* inode's device */
125
	__uint32_t st_ino;		/* inode's number */
125
	mode_t	  st_mode;		/* inode protection mode */
126
	mode_t	  st_mode;		/* inode protection mode */
126
	nlink_t	  st_nlink;		/* number of hard links */
127
	__uint16_t st_nlink;		/* number of hard links */
127
	uid_t	  st_uid;		/* user ID of the file's owner */
128
	uid_t	  st_uid;		/* user ID of the file's owner */
128
	gid_t	  st_gid;		/* group ID of the file's group */
129
	gid_t	  st_gid;		/* group ID of the file's group */
129
	__dev_t   st_rdev;		/* device type */
130
	__uint32_t st_rdev;		/* device type */
130
	struct	timespec st_atim;	/* time of last access */
131
	struct	timespec st_atim;	/* time of last access */
131
	struct	timespec st_mtim;	/* time of last data modification */
132
	struct	timespec st_mtim;	/* time of last data modification */
132
	struct	timespec st_ctim;	/* time of last file status change */
133
	struct	timespec st_ctim;	/* time of last file status change */
Lines 148-163 struct stat { Link Here
148
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
149
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
149
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
150
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
150
};
151
};
152
#endif /* _WANT_FREEBSD11_STAT || _KERNEL */
153
154
#if defined(__i386__)
155
#define	__STAT_TIME_T_EXT	1
156
#endif
157
158
struct stat {
159
	dev_t     st_dev;		/* inode's device */
160
	ino_t	  st_ino;		/* inode's number */
161
	nlink_t	  st_nlink;		/* number of hard links */
162
	mode_t	  st_mode;		/* inode protection mode */
163
	__int16_t st_padding0;
164
	uid_t	  st_uid;		/* user ID of the file's owner */
165
	gid_t	  st_gid;		/* group ID of the file's group */
166
	__int32_t st_padding1;
167
	dev_t     st_rdev;		/* device type */
168
#ifdef	__STAT_TIME_T_EXT
169
	__int32_t st_atim_ext;
170
#endif
171
	struct	timespec st_atim;	/* time of last access */
172
#ifdef	__STAT_TIME_T_EXT
173
	__int32_t st_mtim_ext;
174
#endif
175
	struct	timespec st_mtim;	/* time of last data modification */
176
#ifdef	__STAT_TIME_T_EXT
177
	__int32_t st_ctim_ext;
178
#endif
179
	struct	timespec st_ctim;	/* time of last file status change */
180
#ifdef	__STAT_TIME_T_EXT
181
	__int32_t st_btim_ext;
182
#endif
183
	struct	timespec st_birthtim;	/* time of file creation */
184
	off_t	  st_size;		/* file size, in bytes */
185
	blkcnt_t st_blocks;		/* blocks allocated for file */
186
	blksize_t st_blksize;		/* optimal blocksize for I/O */
187
	fflags_t  st_flags;		/* user defined flags for file */
188
	__uint64_t st_gen;		/* file generation number */
189
	__uint64_t st_spare[10];
190
};
151
191
152
#ifdef _KERNEL
192
#ifdef _KERNEL
153
struct nstat {
193
struct nstat {
154
	__dev_t   st_dev;		/* inode's device */
194
	__uint32_t st_dev;		/* inode's device */
155
	ino_t	  st_ino;		/* inode's number */
195
	__uint32_t st_ino;		/* inode's number */
156
	__uint32_t st_mode;		/* inode protection mode */
196
	__uint32_t st_mode;		/* inode protection mode */
157
	__uint32_t st_nlink;		/* number of hard links */
197
	__uint32_t st_nlink;		/* number of hard links */
158
	uid_t	  st_uid;		/* user ID of the file's owner */
198
	uid_t	  st_uid;		/* user ID of the file's owner */
159
	gid_t	  st_gid;		/* group ID of the file's group */
199
	gid_t	  st_gid;		/* group ID of the file's group */
160
	__dev_t   st_rdev;		/* device type */
200
	__uint32_t st_rdev;		/* device type */
161
	struct	timespec st_atim;	/* time of last access */
201
	struct	timespec st_atim;	/* time of last access */
162
	struct	timespec st_mtim;	/* time of last data modification */
202
	struct	timespec st_mtim;	/* time of last data modification */
163
	struct	timespec st_ctim;	/* time of last file status change */
203
	struct	timespec st_ctim;	/* time of last file status change */
Lines 168-174 struct nstat { Link Here
168
	__uint32_t st_gen;		/* file generation number */
208
	__uint32_t st_gen;		/* file generation number */
169
	struct timespec st_birthtim;	/* time of file creation */
209
	struct timespec st_birthtim;	/* time of file creation */
170
	/*
210
	/*
171
	 * See above about the following padding.
211
	 * See comment in the definition of struct freebsd11_stat
212
	 * above about the following padding.
172
	 */
213
	 */
173
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
214
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
174
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
215
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
(-)b/sys/sys/syscallsubr.h (-3 / +8 lines)
Lines 117-124 int kern_futimes(struct thread *td, int fd, struct timeval *tptr, Link Here
117
	    enum uio_seg tptrseg);
117
	    enum uio_seg tptrseg);
118
int	kern_futimens(struct thread *td, int fd, struct timespec *tptr,
118
int	kern_futimens(struct thread *td, int fd, struct timespec *tptr,
119
	    enum uio_seg tptrseg);
119
	    enum uio_seg tptrseg);
120
int	kern_getdirentries(struct thread *td, int fd, char *buf, u_int count,
120
int	kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
121
	    long *basep, ssize_t *residp, enum uio_seg bufseg);
121
	    off_t *basep, ssize_t *residp, enum uio_seg bufseg);
122
int	kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
122
int	kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
123
	    size_t *countp, enum uio_seg bufseg, int mode);
123
	    size_t *countp, enum uio_seg bufseg, int mode);
124
int	kern_getitimer(struct thread *, u_int, struct itimerval *);
124
int	kern_getitimer(struct thread *, u_int, struct itimerval *);
Lines 158-164 int kern_mkdirat(struct thread *td, int fd, char *path, Link Here
158
int	kern_mkfifoat(struct thread *td, int fd, char *path,
158
int	kern_mkfifoat(struct thread *td, int fd, char *path,
159
	    enum uio_seg pathseg, int mode);
159
	    enum uio_seg pathseg, int mode);
160
int	kern_mknodat(struct thread *td, int fd, char *path,
160
int	kern_mknodat(struct thread *td, int fd, char *path,
161
	    enum uio_seg pathseg, int mode, int dev);
161
	    enum uio_seg pathseg, int mode, dev_t dev);
162
int	kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr,
162
int	kern_mlock(struct proc *proc, struct ucred *cred, uintptr_t addr,
163
	    size_t len);
163
	    size_t len);
164
int	kern_mmap(struct thread *td, uintptr_t addr, size_t size, int prot,
164
int	kern_mmap(struct thread *td, uintptr_t addr, size_t size, int prot,
Lines 292-295 int kern_socketpair(struct thread *td, int domain, int type, int protocol, Link Here
292
#define	KSA_OSIGSET	0x0001	/* uses osigact_t */
292
#define	KSA_OSIGSET	0x0001	/* uses osigact_t */
293
#define	KSA_FREEBSD4	0x0002	/* uses ucontext4 */
293
#define	KSA_FREEBSD4	0x0002	/* uses ucontext4 */
294
294
295
struct freebsd11_dirent;
296
297
int	freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int
298
	    count, long *basep, void (*func)(struct freebsd11_dirent *));
299
295
#endif /* !_SYS_SYSCALLSUBR_H_ */
300
#endif /* !_SYS_SYSCALLSUBR_H_ */
(-)b/sys/sys/tty.h (-1 / +1 lines)
Lines 148-154 struct xtty { Link Here
148
	pid_t	xt_pgid;	/* Foreground process group. */
148
	pid_t	xt_pgid;	/* Foreground process group. */
149
	pid_t	xt_sid;		/* Session. */
149
	pid_t	xt_sid;		/* Session. */
150
	unsigned int xt_flags;	/* Terminal option flags. */
150
	unsigned int xt_flags;	/* Terminal option flags. */
151
	dev_t	xt_dev;		/* Userland device. */
151
	uint32_t xt_dev;	/* Userland device. XXXKIB truncated */
152
};
152
};
153
153
154
#ifdef _KERNEL
154
#ifdef _KERNEL
(-)b/sys/sys/user.h (-20 / +54 lines)
Lines 84-90 Link Here
84
 * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
84
 * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
85
 * function kvm_proclist in lib/libkvm/kvm_proc.c .
85
 * function kvm_proclist in lib/libkvm/kvm_proc.c .
86
 */
86
 */
87
#define	KI_NSPARE_INT	4
87
#define	KI_NSPARE_INT	2
88
#define	KI_NSPARE_LONG	12
88
#define	KI_NSPARE_LONG	12
89
#define	KI_NSPARE_PTR	6
89
#define	KI_NSPARE_PTR	6
90
90
Lines 135-141 struct kinfo_proc { Link Here
135
	pid_t	ki_tsid;		/* Terminal session ID */
135
	pid_t	ki_tsid;		/* Terminal session ID */
136
	short	ki_jobc;		/* job control counter */
136
	short	ki_jobc;		/* job control counter */
137
	short	ki_spare_short1;	/* unused (just here for alignment) */
137
	short	ki_spare_short1;	/* unused (just here for alignment) */
138
	dev_t	ki_tdev;		/* controlling tty dev */
138
	uint32_t ki_tdev_freebsd11;	/* controlling tty dev */
139
	sigset_t ki_siglist;		/* Signals arrived but not delivered */
139
	sigset_t ki_siglist;		/* Signals arrived but not delivered */
140
	sigset_t ki_sigmask;		/* Current signal mask */
140
	sigset_t ki_sigmask;		/* Current signal mask */
141
	sigset_t ki_sigignore;		/* Signals being ignored */
141
	sigset_t ki_sigignore;		/* Signals being ignored */
Lines 188-193 struct kinfo_proc { Link Here
188
	 */
188
	 */
189
	char	ki_sparestrings[46];	/* spare string space */
189
	char	ki_sparestrings[46];	/* spare string space */
190
	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
190
	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
191
	uint64_t ki_tdev;		/* controlling tty dev */
191
	int	ki_oncpu;		/* Which cpu we are on */
192
	int	ki_oncpu;		/* Which cpu we are on */
192
	int	ki_lastcpu;		/* Last cpu we were on */
193
	int	ki_lastcpu;		/* Last cpu we were on */
193
	int	ki_tracer;		/* Pid of tracing process */
194
	int	ki_tracer;		/* Pid of tracing process */
Lines 341-354 struct kinfo_file { Link Here
341
	int		kf_flags;		/* Flags. */
342
	int		kf_flags;		/* Flags. */
342
	int		kf_pad0;		/* Round to 64 bit alignment. */
343
	int		kf_pad0;		/* Round to 64 bit alignment. */
343
	int64_t		kf_offset;		/* Seek location. */
344
	int64_t		kf_offset;		/* Seek location. */
344
	int		kf_vnode_type;		/* Vnode type. */
345
	int		kf_sock_domain;		/* Socket domain. */
346
	int		kf_sock_type;		/* Socket type. */
347
	int		kf_sock_protocol;	/* Socket protocol. */
348
	struct sockaddr_storage kf_sa_local;	/* Socket address. */
349
	struct sockaddr_storage	kf_sa_peer;	/* Peer address. */
350
	union {
345
	union {
351
		struct {
346
		struct {
347
			uint32_t	kf_spareint;
348
			/* Socket domain. */
349
			int		kf_sock_domain0;
350
			/* Socket type. */
351
			int		kf_sock_type0;
352
			/* Socket protocol. */
353
			int		kf_sock_protocol0;
354
			/* Socket address. */
355
			struct sockaddr_storage kf_sa_local;
356
			/* Peer address. */
357
			struct sockaddr_storage	kf_sa_peer;
352
			/* Address of so_pcb. */
358
			/* Address of so_pcb. */
353
			uint64_t	kf_sock_pcb;
359
			uint64_t	kf_sock_pcb;
354
			/* Address of inp_ppcb. */
360
			/* Address of inp_ppcb. */
Lines 363-376 struct kinfo_file { Link Here
363
			uint32_t	kf_sock_pad0;
369
			uint32_t	kf_sock_pad0;
364
		} kf_sock;
370
		} kf_sock;
365
		struct {
371
		struct {
372
			/* Vnode type. */
373
			int		kf_file_type;
374
			/* Space for future use */
375
			int		kf_spareint[3];
376
			uint64_t	kf_spareint64[30];
377
			/* Vnode filesystem id. */
378
			uint64_t	kf_file_fsid;
379
			/* File device. */
380
			uint64_t	kf_file_rdev;
366
			/* Global file id. */
381
			/* Global file id. */
367
			uint64_t	kf_file_fileid;
382
			uint64_t	kf_file_fileid;
368
			/* File size. */
383
			/* File size. */
369
			uint64_t	kf_file_size;
384
			uint64_t	kf_file_size;
370
			/* Vnode filesystem id. */
385
			/* Vnode filesystem id, FreeBSD 11 compat. */
371
			uint32_t	kf_file_fsid;
386
			uint32_t	kf_file_fsid_freebsd11;
372
			/* File device. */
387
			/* File device, FreeBSD 11 compat. */
373
			uint32_t	kf_file_rdev;
388
			uint32_t	kf_file_rdev_freebsd11;
374
			/* File mode. */
389
			/* File mode. */
375
			uint16_t	kf_file_mode;
390
			uint16_t	kf_file_mode;
376
			/* Round to 64 bit alignment. */
391
			/* Round to 64 bit alignment. */
Lines 378-387 struct kinfo_file { Link Here
378
			uint32_t	kf_file_pad1;
393
			uint32_t	kf_file_pad1;
379
		} kf_file;
394
		} kf_file;
380
		struct {
395
		struct {
396
			uint32_t	kf_spareint[4];
397
			uint64_t	kf_spareint64[32];
381
			uint32_t	kf_sem_value;
398
			uint32_t	kf_sem_value;
382
			uint16_t	kf_sem_mode;
399
			uint16_t	kf_sem_mode;
383
		} kf_sem;
400
		} kf_sem;
384
		struct {
401
		struct {
402
			uint32_t	kf_spareint[4];
403
			uint64_t	kf_spareint64[32];
385
			uint64_t	kf_pipe_addr;
404
			uint64_t	kf_pipe_addr;
386
			uint64_t	kf_pipe_peer;
405
			uint64_t	kf_pipe_peer;
387
			uint32_t	kf_pipe_buffer_cnt;
406
			uint32_t	kf_pipe_buffer_cnt;
Lines 389-399 struct kinfo_file { Link Here
389
			uint32_t	kf_pipe_pad0[3];
408
			uint32_t	kf_pipe_pad0[3];
390
		} kf_pipe;
409
		} kf_pipe;
391
		struct {
410
		struct {
392
			uint32_t	kf_pts_dev;
411
			uint32_t	kf_spareint[4];
412
			uint64_t	kf_spareint64[32];
413
			uint32_t	kf_pts_dev_freebsd11;
414
			uint32_t	kf_pts_pad0;
415
			uint64_t	kf_pts_dev;
393
			/* Round to 64 bit alignment. */
416
			/* Round to 64 bit alignment. */
394
			uint32_t	kf_pts_pad0[7];
417
			uint32_t	kf_pts_pad1[4];
395
		} kf_pts;
418
		} kf_pts;
396
		struct {
419
		struct {
420
			uint32_t	kf_spareint[4];
421
			uint64_t	kf_spareint64[32];
397
			pid_t		kf_pid;
422
			pid_t		kf_pid;
398
		} kf_proc;
423
		} kf_proc;
399
	} kf_un;
424
	} kf_un;
Lines 405-410 struct kinfo_file { Link Here
405
	/* Truncated before copyout in sysctl */
430
	/* Truncated before copyout in sysctl */
406
	char		kf_path[PATH_MAX];	/* Path to file, if any. */
431
	char		kf_path[PATH_MAX];	/* Path to file, if any. */
407
};
432
};
433
#ifndef _KERNEL
434
#define	kf_vnode_type	kf_un.kf_file.kf_file_type
435
#define	kf_sock_domain	kf_un.kf_sock.kf_sock_domain0
436
#define	kf_sock_type	kf_un.kf_sock.kf_sock_type0
437
#define	kf_sock_protocol	kf_un.kf_sock.kf_sock_protocol0
438
#endif
408
439
409
/*
440
/*
410
 * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
441
 * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
Lines 454-460 struct kinfo_ovmentry { Link Here
454
	void	*_kve_pspare[8];		/* Space for more stuff. */
485
	void	*_kve_pspare[8];		/* Space for more stuff. */
455
	off_t	 kve_offset;			/* Mapping offset in object */
486
	off_t	 kve_offset;			/* Mapping offset in object */
456
	uint64_t kve_fileid;			/* inode number if vnode */
487
	uint64_t kve_fileid;			/* inode number if vnode */
457
	dev_t	 kve_fsid;			/* dev_t of vnode location */
488
	uint32_t kve_fsid;			/* dev_t of vnode location */
458
	int	 _kve_ispare[3];		/* Space for more stuff. */
489
	int	 _kve_ispare[3];		/* Space for more stuff. */
459
};
490
};
460
491
Lines 469-475 struct kinfo_vmentry { Link Here
469
	uint64_t kve_end;			/* Finishing address. */
500
	uint64_t kve_end;			/* Finishing address. */
470
	uint64_t kve_offset;			/* Mapping offset in object */
501
	uint64_t kve_offset;			/* Mapping offset in object */
471
	uint64_t kve_vn_fileid;			/* inode number if vnode */
502
	uint64_t kve_vn_fileid;			/* inode number if vnode */
472
	uint32_t kve_vn_fsid;			/* dev_t of vnode location */
503
	uint32_t kve_vn_fsid_freebsd11;		/* dev_t of vnode location */
473
	int	 kve_flags;			/* Flags on map entry. */
504
	int	 kve_flags;			/* Flags on map entry. */
474
	int	 kve_resident;			/* Number of resident pages. */
505
	int	 kve_resident;			/* Number of resident pages. */
475
	int	 kve_private_resident;		/* Number of private pages. */
506
	int	 kve_private_resident;		/* Number of private pages. */
Lines 478-487 struct kinfo_vmentry { Link Here
478
	int	 kve_shadow_count;		/* VM obj shadow count. */
509
	int	 kve_shadow_count;		/* VM obj shadow count. */
479
	int	 kve_vn_type;			/* Vnode type. */
510
	int	 kve_vn_type;			/* Vnode type. */
480
	uint64_t kve_vn_size;			/* File size. */
511
	uint64_t kve_vn_size;			/* File size. */
481
	uint32_t kve_vn_rdev;			/* Device id if device. */
512
	uint32_t kve_vn_rdev_freebsd11;		/* Device id if device. */
482
	uint16_t kve_vn_mode;			/* File mode. */
513
	uint16_t kve_vn_mode;			/* File mode. */
483
	uint16_t kve_status;			/* Status flags. */
514
	uint16_t kve_status;			/* Status flags. */
484
	int	 _kve_ispare[12];		/* Space for more stuff. */
515
	uint64_t kve_vn_fsid;			/* dev_t of vnode location */
516
	uint64_t kve_vn_rdev;			/* Device id if device. */
517
	int	 _kve_ispare[8];		/* Space for more stuff. */
485
	/* Truncated before copyout in sysctl */
518
	/* Truncated before copyout in sysctl */
486
	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
519
	char	 kve_path[PATH_MAX];		/* Path to VM obj, if any. */
487
};
520
};
Lines 495-508 struct kinfo_vmobject { Link Here
495
	int	kvo_type;			/* Object type: KVME_TYPE_*. */
528
	int	kvo_type;			/* Object type: KVME_TYPE_*. */
496
	uint64_t kvo_size;			/* Object size in pages. */
529
	uint64_t kvo_size;			/* Object size in pages. */
497
	uint64_t kvo_vn_fileid;			/* inode number if vnode. */
530
	uint64_t kvo_vn_fileid;			/* inode number if vnode. */
498
	uint32_t kvo_vn_fsid;			/* dev_t of vnode location. */
531
	uint32_t kvo_vn_fsid_freebsd11;		/* dev_t of vnode location. */
499
	int	kvo_ref_count;			/* Reference count. */
532
	int	kvo_ref_count;			/* Reference count. */
500
	int	kvo_shadow_count;		/* Shadow count. */
533
	int	kvo_shadow_count;		/* Shadow count. */
501
	int	kvo_memattr;			/* Memory attribute. */
534
	int	kvo_memattr;			/* Memory attribute. */
502
	uint64_t kvo_resident;			/* Number of resident pages. */
535
	uint64_t kvo_resident;			/* Number of resident pages. */
503
	uint64_t kvo_active;			/* Number of active pages. */
536
	uint64_t kvo_active;			/* Number of active pages. */
504
	uint64_t kvo_inactive;			/* Number of inactive pages. */
537
	uint64_t kvo_inactive;			/* Number of inactive pages. */
505
	uint64_t _kvo_qspare[8];
538
	uint64_t kvo_vn_fsid;
539
	uint64_t _kvo_qspare[7];
506
	uint32_t _kvo_ispare[8];
540
	uint32_t _kvo_ispare[8];
507
	char	kvo_path[PATH_MAX];		/* Pathname, if any. */
541
	char	kvo_path[PATH_MAX];		/* Pathname, if any. */
508
};
542
};
(-)b/sys/sys/vnode.h (-3 / +6 lines)
Lines 266-276 struct xvnode { Link Here
266
struct vattr {
266
struct vattr {
267
	enum vtype	va_type;	/* vnode type (for create) */
267
	enum vtype	va_type;	/* vnode type (for create) */
268
	u_short		va_mode;	/* files access mode and type */
268
	u_short		va_mode;	/* files access mode and type */
269
	short		va_nlink;	/* number of references to file */
269
	u_short		va_padding0;
270
	uid_t		va_uid;		/* owner user id */
270
	uid_t		va_uid;		/* owner user id */
271
	gid_t		va_gid;		/* owner group id */
271
	gid_t		va_gid;		/* owner group id */
272
	nlink_t		va_nlink;	/* number of references to file */
272
	dev_t		va_fsid;	/* filesystem id */
273
	dev_t		va_fsid;	/* filesystem id */
273
	long		va_fileid;	/* file id */
274
	ino_t		va_fileid;	/* file id */
274
	u_quad_t	va_size;	/* file size in bytes */
275
	u_quad_t	va_size;	/* file size in bytes */
275
	long		va_blocksize;	/* blocksize preferred for i/o */
276
	long		va_blocksize;	/* blocksize preferred for i/o */
276
	struct timespec	va_atime;	/* time of last access */
277
	struct timespec	va_atime;	/* time of last access */
Lines 585-590 struct file; Link Here
585
struct mount;
586
struct mount;
586
struct nameidata;
587
struct nameidata;
587
struct ostat;
588
struct ostat;
589
struct freebsd11_stat;
588
struct thread;
590
struct thread;
589
struct proc;
591
struct proc;
590
struct stat;
592
struct stat;
Lines 613-619 void cache_purge_negative(struct vnode *vp); Link Here
613
void	cache_purgevfs(struct mount *mp, bool force);
615
void	cache_purgevfs(struct mount *mp, bool force);
614
int	change_dir(struct vnode *vp, struct thread *td);
616
int	change_dir(struct vnode *vp, struct thread *td);
615
void	cvtstat(struct stat *st, struct ostat *ost);
617
void	cvtstat(struct stat *st, struct ostat *ost);
616
void	cvtnstat(struct stat *sb, struct nstat *nsb);
618
void	freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb);
619
void	freebsd11_cvtstat(struct stat *st, struct freebsd11_stat *ost);
617
int	getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
620
int	getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
618
	    struct vnode **vpp);
621
	    struct vnode **vpp);
619
void	getnewvnode_reserve(u_int count);
622
void	getnewvnode_reserve(u_int count);
(-)b/sys/vm/swap_pager.c (-1 / +26 lines)
Lines 69-74 Link Here
69
#include <sys/cdefs.h>
69
#include <sys/cdefs.h>
70
__FBSDID("$FreeBSD$");
70
__FBSDID("$FreeBSD$");
71
71
72
#include "opt_compat.h"
72
#include "opt_swap.h"
73
#include "opt_swap.h"
73
#include "opt_vm.h"
74
#include "opt_vm.h"
74
75
Lines 2417-2426 swap_dev_info(int name, struct xswdev *xs, char *devname, size_t len) Link Here
2417
	return (error);
2418
	return (error);
2418
}
2419
}
2419
2420
2421
#if defined(COMPAT_FREEBSD11)
2422
#define XSWDEV_VERSION_11	1
2423
struct xswdev11 {
2424
	u_int	xsw_version;
2425
	uint32_t xsw_dev;
2426
	int	xsw_flags;
2427
	int	xsw_nblks;
2428
	int     xsw_used;
2429
};
2430
#endif
2431
2420
static int
2432
static int
2421
sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
2433
sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
2422
{
2434
{
2423
	struct xswdev xs;
2435
	struct xswdev xs;
2436
#if defined(COMPAT_FREEBSD11)
2437
	struct xswdev11 xs11;
2438
#endif
2424
	int error;
2439
	int error;
2425
2440
2426
	if (arg2 != 1)			/* name length */
2441
	if (arg2 != 1)			/* name length */
Lines 2428-2434 sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS) Link Here
2428
	error = swap_dev_info(*(int *)arg1, &xs, NULL, 0);
2443
	error = swap_dev_info(*(int *)arg1, &xs, NULL, 0);
2429
	if (error != 0)
2444
	if (error != 0)
2430
		return (error);
2445
		return (error);
2431
	error = SYSCTL_OUT(req, &xs, sizeof(xs));
2446
#if defined(COMPAT_FREEBSD11)
2447
	if (req->oldlen == sizeof(xs11)) {
2448
		xs11.xsw_version = XSWDEV_VERSION_11;
2449
		xs11.xsw_dev = xs.xsw_dev; /* truncation */
2450
		xs11.xsw_flags = xs.xsw_flags;
2451
		xs11.xsw_nblks = xs.xsw_nblks;
2452
		xs11.xsw_used = xs.xsw_used;
2453
		error = SYSCTL_OUT(req, &xs11, sizeof(xs11));
2454
	} else
2455
#endif
2456
		error = SYSCTL_OUT(req, &xs, sizeof(xs));
2432
	return (error);
2457
	return (error);
2433
}
2458
}
2434
2459
(-)b/sys/vm/vm_object.c (+3 lines)
Lines 2342-2347 sysctl_vm_object_list(SYSCTL_HANDLER_ARGS) Link Here
2342
2342
2343
		kvo.kvo_vn_fileid = 0;
2343
		kvo.kvo_vn_fileid = 0;
2344
		kvo.kvo_vn_fsid = 0;
2344
		kvo.kvo_vn_fsid = 0;
2345
		kvo.kvo_vn_fsid_freebsd11 = 0;
2345
		freepath = NULL;
2346
		freepath = NULL;
2346
		fullpath = "";
2347
		fullpath = "";
2347
		vp = NULL;
2348
		vp = NULL;
Lines 2383-2388 sysctl_vm_object_list(SYSCTL_HANDLER_ARGS) Link Here
2383
			if (VOP_GETATTR(vp, &va, curthread->td_ucred) == 0) {
2384
			if (VOP_GETATTR(vp, &va, curthread->td_ucred) == 0) {
2384
				kvo.kvo_vn_fileid = va.va_fileid;
2385
				kvo.kvo_vn_fileid = va.va_fileid;
2385
				kvo.kvo_vn_fsid = va.va_fsid;
2386
				kvo.kvo_vn_fsid = va.va_fsid;
2387
				kvo.kvo_vn_fsid_freebsd11 = va.va_fsid;
2388
								/* truncate */
2386
			}
2389
			}
2387
			vput(vp);
2390
			vput(vp);
2388
		}
2391
		}
(-)b/sys/vm/vm_param.h (-1 / +1 lines)
Lines 89-95 Link Here
89
/*
89
/*
90
 * Structure for swap device statistics
90
 * Structure for swap device statistics
91
 */
91
 */
92
#define XSWDEV_VERSION	1
92
#define XSWDEV_VERSION	2
93
struct xswdev {
93
struct xswdev {
94
	u_int	xsw_version;
94
	u_int	xsw_version;
95
	dev_t	xsw_dev;
95
	dev_t	xsw_dev;
(-)b/testing.txt (+236 lines)
Added Link Here
1
To: freebsd-current, freebsd-fs, freebsd-ports
2
Subject: 64-bit inodes (ino64) Status Update and Call for Testing
3
4
Inodes are data structures corresponding to objects in a file system,
5
such as files and directories. FreeBSD has historically used 32-bit
6
values to identify inodes, which limits file systems to somewhat under
7
2^32 objects. Many modern file systems internally use 64-bit identifiers
8
and FreeBSD needs to follow suit to properly and fully support these
9
file systems.
10
11
The 64-bit inode project, also known as ino64, started life many years
12
ago as a project by Gleb Kurtsou (gleb@).  After that time several
13
people have had a hand in updating it and addressing regressions, after
14
mckusick@ picked up and updated the patch, and acted as a flag-waver.
15
16
Sponsored by the FreeBSD Foundation I have spent a significant effort
17
on outstanding issues and integration -- fixing compat32 ABI, NFS and
18
ZFS, addressing ABI compat issues and investigating and fixing ports
19
failures.  rmacklem@ provided feedback on NFS changes, emaste@ and
20
jhb@ provided feedback and review on the ABI transition support. pho@
21
performed extensive testing and identified a number of issues that
22
have now been fixed.  kris@ performed an initial ports investigation
23
followed by an exp-run by antoine@. emaste@ helped with organization
24
of the process.
25
26
This note explains how to perform useful testing of the ino64 branch,
27
beyond typical smoke tests.
28
29
1. Overview.
30
31
The ino64 branch extends the basic system types ino_t and dev_t from
32
32-bit to 64-bit, and nlink_t from 16-bit to 64-bit.  The struct dirent
33
layout is modified due to the larger size of ino_t, and also gains a
34
d_off (directory offset) member. As ino64 implies an ABI change anyway
35
the struct statfs f_mntfromname[] and f_mntonname[] array length
36
MNAMELEN is increased from 88 to 1024, to allow for longer mount path
37
names.
38
39
ABI breakage is mitigated by providing compatibility using versioned
40
symbols, ingenious use of the existing padding in structures, and by
41
employing other tricks.  Unfortunately, not everything can be fixed,
42
especially outside the base system.  For instance, third-party APIs
43
which pass struct stat around are broken in backward and forward-
44
incompatible way.
45
46
2. Motivation.
47
48
The main risk of the ino64 change is the uncontrolled ABI breakage.
49
Due to expansion of the basic types dev_t, ino_t and struct dirent,
50
the impact is not limited to one part of the system, but affects:
51
- kernel/userspace interface (syscalls ABI, mostly stat(2), kinfo
52
  and more)
53
- libc interface (mostly related to the readdir(3), FTS(3))
54
- collateral damage in other libraries that happens to use changed types
55
  in the interfaces.  See, for instance, libprocstat, for which compat
56
  was provided using symbol versioning, and libutil, which shlib version
57
  was bumped.
58
59
3. Quirks.
60
61
We handled kinfo sysctl MIBs, but there is no general mechanism to
62
handle other sysctl MIBS which return structures where the layout has
63
changed. It was considered that the breakage is either in the management
64
interfaces, where we usually allow ABI slip, or is not important.
65
66
Struct xvnode changed layout, no compat shims are provided.
67
68
For struct xtty, dev_t tty device member was reduced to uint32_t.  It
69
was decided that keeping ABI compat in this case is more useful than
70
reporting 64bit dev_t, for the sake of pstat.
71
72
4. Testing procedure.
73
74
The ino64 project can be tested by cloning the project branch from
75
GitHub or by applying the patch <from the Phabricator review | located
76
at URL | attached> to a working tree.  The authorative source is the
77
GitHub, I do not promise to update the review for each update.
78
79
To clone from GitHub:
80
% git clone -b ino64 https://github.com/FreeBSDFoundation/freebsd.git ino64
81
82
To fetch the patch from Phabricator:
83
- Visit https://reviews.freebsd.org/D10439
84
- Click "Download Raw Diff" at the upper right of the page
85
86
Or
87
% arc patch D10439
88
89
After that, in the checkout directory do
90
% (cd sys/kern && touch syscalls.master && make sysent)
91
% (cd sys/compat/freebsd32 && touch syscalls.master && make sysent)
92
If you use custom kernel configuration, ensure that
93
	options COMPAT_FREEBSD11
94
is included into the config.  Then build world and kernel in the
95
usual way, install kernel, reboot, install new world.  Do not make
96
shortcuts in the update procedure.
97
98
4.1 New kernel, old world.
99
100
Build and install pristine HEAD world, apply patch and only build and
101
install updated kernel. The system must work same as with the pristine
102
kernel.
103
104
4.2 New kernel, new world, old third-party applications.
105
106
Build and install patched kernel and world.  Applications compiled on the
107
pristine HEAD (e.g. installed by pkg from the regular portmgr builds) must
108
work without a regression.
109
110
4.3 32bit compat.
111
112
Same as 4.1 and 4.2, but for 32bit (i386) binaries on the amd64 host.
113
Note that big-endian host, like powerpc, might expose additional
114
bugs in the 32bit compat with the patch, but the testing is too cumbersome
115
to arrange.
116
117
4.4 Targeted tests.
118
119
Useful programs to check items 4.1, 4.2 and 4.3 are versions of the
120
following programs, taken from the pristine system:
121
122
  stat(8). Use it on regular file, file in /dev, socket, pipe and so
123
  on. For both native and 32bit compat, stat(8) must print reasonable
124
  information.
125
126
  procstat(1). Use it with the -f option to examine processes files.
127
  kinfo(9) data must be returned in the format acceptable for older
128
  apps.
129
130
  Use pristine find(1) binary with many arbitrary options on a system with
131
  installed patched world, in particular, libc. Find examines FTS(3),
132
  and compat shims in libc are non-trivial.
133
134
4.5 NFS server and client test.
135
136
Check that the NFS server in the patched kernel operates correctly and without
137
performance regressions.  Same for client.
138
NFS should be checked for all four combination of patched/unpatched
139
kernel server/client, because the filehandle format includes inode number.
140
141
4.6 Other filesystems
142
143
Generally, filesystems should see no change in the system behaviour,
144
since patch goal is to provide space to grow in the ABI.  In
145
particular, local filesystem layout must stay same.  Of course, it is
146
possible that some reliance on the exact sizes of the changed types
147
was left unnoticed during the patch review, in which case e.g. on-disk
148
format would be broken.  We do not expect this to slip in, but it is
149
possible and should be watched for.
150
151
4.7 Test accounting
152
153
The process accounting, as documented in acct(5), changed format of
154
the records due to dev_t increase.  Verify that the programs like
155
sa(8) and accton(8) correctly work with both old and new accounting
156
records.
157
158
5. Ports Status with ino64
159
160
A ports exp-run for ino64 is open in PR 218320. The failing ports each
161
responsible for more than 1 skipped port are:
162
163
lang/ghc			497
164
multimedia/webcamd		62
165
lang/gcc6-aux			54
166
devel/libgtop			39
167
sysutils/py-psutil		13
168
devel/llvm38			6
169
lang/rust			4
170
sysutils/py-psutil121		3
171
172
Patches are available for lang/llvm39, lang/llvm40, lang/ghc, and
173
lang/rust in the topic branch as ports.patch, and llvm38 can be fixed
174
in the same way as llvm39 and llvm40. Assistance with investigating
175
and fixing the port failures will be greatly appreciated.
176
177
Below is an overview of the problems and proposed solutions, probably
178
mostly relevant to the ports maintainers.
179
180
5.1. LLVM
181
182
LLVM includes a component called Address Sanitizer or ASAN, which tries
183
to intercept syscalls, and contains knowledge of the layout of many
184
system structures.  Since stat and lstat syscalls were removed and
185
several types and structures changed, this has to be reflected in the
186
ASAN hacks.
187
188
5.2. lang/ghc
189
190
The ghc compiler and parts of the runtime are written in Haskell,
191
which means that to compile ghc, you need a working Haskell compiler
192
for bootstrap.  By default for ghc, the runtime is provided in the form
193
of static libraries.  Static libraries reference default versions of
194
libc symbols, which are assigned the ELF symbol version at the final
195
linking stage.  As result, using such libraries results in using the
196
updated syscall, but internally the code still uses old system types.
197
The end result is the random memory corruption because both libc and
198
kernel assume new types.
199
200
This situation cannot be fixed by symbol versioning, because versioning
201
acts too late.  Instead, we hacked the bootstrap compiler by providing
202
symbols for modified syscalls in the shipped static libraries, which
203
symbols direct execution to the compat variants of the syscalls.  This
204
allows the bootstrap compiler to generate working code.  After the
205
stage0, compiler operates on new structures and things stabilize.
206
207
The real solution is, of course, to re-package the bootstrap compiler,
208
but for some time we need to support pre-ino64 HEAD in ports.  Also,
209
learning full scope of GHC maintainance duties, required for that,
210
is too much for the ino64 task.
211
212
5.3. lang/rust
213
214
Rustc has a similar structure to GHC, and same issue.  The same solution
215
of patching the bootstrap was done.
216
217
Also rust libstd and liblibc provide rustified definitions of the
218
system structures, which were updated to reflect the updated layout.
219
I failed to understand why e.g. struct stat has to be defined in 3
220
places at least, but all found locations were patched.
221
222
6. Next Steps
223
224
The tentative schedule for the ino64 project:
225
226
2017-04-20 Post wide call for testing
227
228
           Investigate and address port failures with maintainer support
229
230
2017-05-05 Request second exp-run with initial patches applied
231
232
           Investigate and address port failures with maintainer support
233
234
2017-05-19 Commit to HEAD
235
236
           Address post-commit failures where feasible
(-)b/usr.bin/kdump/kdump.c (-1 lines)
Lines 932-938 ktrsyscall(struct ktr_syscall *ktr, u_int sv_flags) Link Here
932
				ip++;
932
				ip++;
933
				narg--;
933
				narg--;
934
				break;
934
				break;
935
			case SYS_mknod:
936
			case SYS_mknodat:
935
			case SYS_mknodat:
937
				print_number(ip, narg, c);
936
				print_number(ip, narg, c);
938
				putchar(',');
937
				putchar(',');
(-)b/usr.bin/lastcomm/lastcomm.c (-6 / +6 lines)
Lines 61-69 __FBSDID("$FreeBSD$"); Link Here
61
time_t	 expand(u_int);
61
time_t	 expand(u_int);
62
char	*flagbits(int);
62
char	*flagbits(int);
63
const	 char *getdev(dev_t);
63
const	 char *getdev(dev_t);
64
int	 readrec_forward(FILE *f, struct acctv2 *av2);
64
int	 readrec_forward(FILE *f, struct acctv3 *av3);
65
int	 readrec_backward(FILE *f, struct acctv2 *av2);
65
int	 readrec_backward(FILE *f, struct acctv3 *av3);
66
int	 requested(char *[], struct acctv2 *);
66
int	 requested(char *[], struct acctv3 *);
67
static	 void usage(void);
67
static	 void usage(void);
68
68
69
#define AC_UTIME 1 /* user */
69
#define AC_UTIME 1 /* user */
Lines 77-86 static void usage(void); Link Here
77
int
77
int
78
main(int argc, char *argv[])
78
main(int argc, char *argv[])
79
{
79
{
80
	struct acctv2 ab;
80
	struct acctv3 ab;
81
	char *p;
81
	char *p;
82
	FILE *fp;
82
	FILE *fp;
83
	int (*readrec)(FILE *f, struct acctv2 *av2);
83
	int (*readrec)(FILE *f, struct acctv3 *av3);
84
	time_t t;
84
	time_t t;
85
	int ch, rv;
85
	int ch, rv;
86
	const char *acctfile, *format;
86
	const char *acctfile, *format;
Lines 234-240 flagbits(int f) Link Here
234
}
234
}
235
235
236
int
236
int
237
requested(char *argv[], struct acctv2 *acp)
237
requested(char *argv[], struct acctv3 *acp)
238
{
238
{
239
	const char *p;
239
	const char *p;
240
240
(-)b/usr.bin/lastcomm/readrec.c (-29 / +65 lines)
Lines 38-45 __FBSDID("$FreeBSD$"); Link Here
38
#include <stdio.h>
38
#include <stdio.h>
39
#include <string.h>
39
#include <string.h>
40
40
41
int	 readrec_forward(FILE *f, struct acctv2 *av2);
41
int	 readrec_forward(FILE *f, struct acctv3 *av2);
42
int	 readrec_backward(FILE *f, struct acctv2 *av2);
42
int	 readrec_backward(FILE *f, struct acctv3 *av2);
43
43
44
/*
44
/*
45
 * Reverse offsetof: return the offset of field f
45
 * Reverse offsetof: return the offset of field f
Lines 90-116 decode_comp(comp_t v) Link Here
90
 * Return EOF on error or end-of-file.
90
 * Return EOF on error or end-of-file.
91
 */
91
 */
92
static int
92
static int
93
readrec_v1(FILE *f, struct acctv2 *av2)
93
readrec_v1(FILE *f, struct acctv3 *av3)
94
{
94
{
95
	struct acctv1 av1;
95
	struct acctv1 av1;
96
	int rv;
96
	int rv;
97
97
98
	if ((rv = fread_record(&av1, sizeof(av1), f)) == EOF)
98
	if ((rv = fread_record(&av1, sizeof(av1), f)) == EOF)
99
		return (EOF);
99
		return (EOF);
100
	av2->ac_zero = 0;
100
	av3->ac_zero = 0;
101
	av2->ac_version = 2;
101
	av3->ac_version = 3;
102
	av2->ac_len = av2->ac_len2 = sizeof(*av2);
102
	av3->ac_len = av3->ac_len2 = sizeof(*av3);
103
	memcpy(av2->ac_comm, av1.ac_comm, AC_COMM_LEN);
103
	memcpy(av3->ac_comm, av1.ac_comm, AC_COMM_LEN);
104
	av2->ac_utime = decode_comp(av1.ac_utime) * 1000000;
104
	av3->ac_utime = decode_comp(av1.ac_utime) * 1000000;
105
	av2->ac_stime = decode_comp(av1.ac_stime) * 1000000;
105
	av3->ac_stime = decode_comp(av1.ac_stime) * 1000000;
106
	av2->ac_etime = decode_comp(av1.ac_etime) * 1000000;
106
	av3->ac_etime = decode_comp(av1.ac_etime) * 1000000;
107
	av2->ac_btime = av1.ac_btime;
107
	av3->ac_btime = av1.ac_btime;
108
	av2->ac_uid = av1.ac_uid;
108
	av3->ac_uid = av1.ac_uid;
109
	av2->ac_gid = av1.ac_gid;
109
	av3->ac_gid = av1.ac_gid;
110
	av2->ac_mem = av1.ac_mem;
110
	av3->ac_mem = av1.ac_mem;
111
	av2->ac_io = decode_comp(av1.ac_io);
111
	av3->ac_io = decode_comp(av1.ac_io);
112
	av2->ac_tty = av1.ac_tty;
112
	av3->ac_tty = av1.ac_tty;
113
	av2->ac_flagx = av1.ac_flag | ANVER;
113
	av3->ac_flagx = av1.ac_flag | ANVER;
114
	return (0);
114
	return (0);
115
}
115
}
116
116
Lines 120-128 readrec_v1(FILE *f, struct acctv2 *av2) Link Here
120
 * Return EOF on error or end-of-file.
120
 * Return EOF on error or end-of-file.
121
 */
121
 */
122
static int
122
static int
123
readrec_v2(FILE *f, struct acctv2 *av2)
123
readrec_v2(FILE *f, struct acctv3 *av3)
124
{
124
{
125
	return (fread_record(av2, sizeof(*av2), f));
125
	struct acctv2 av2;
126
	int rv;
127
128
	if ((rv = fread_record(&av2, sizeof(av2), f)) == EOF)
129
		return (EOF);
130
	av3->ac_zero = 0;
131
	av3->ac_version = 3;
132
	av3->ac_len = av3->ac_len2 = sizeof(*av3);
133
	memcpy(av3->ac_comm, av2.ac_comm, AC_COMM_LEN);
134
	av3->ac_utime = av2.ac_utime;
135
	av3->ac_stime = av2.ac_stime;
136
	av3->ac_etime = av2.ac_etime;
137
	av3->ac_btime = av2.ac_btime;
138
	av3->ac_uid = av2.ac_uid;
139
	av3->ac_gid = av2.ac_gid;
140
	av3->ac_mem = av2.ac_mem;
141
	av3->ac_io = av2.ac_io;
142
	av3->ac_tty = av2.ac_tty;
143
	av3->ac_flagx = av2.ac_flagx;
144
	return (0);
145
}
146
147
/*
148
 * Read an v2 accounting record stored at the current
149
 * position of stream f.
150
 * Return EOF on error or end-of-file.
151
 */
152
static int
153
readrec_v3(FILE *f, struct acctv3 *av3)
154
{
155
156
	return (fread_record(av3, sizeof(*av3), f));
126
}
157
}
127
158
128
/*
159
/*
Lines 132-138 readrec_v2(FILE *f, struct acctv2 *av2) Link Here
132
 * Return EOF on error or end-of-file.
163
 * Return EOF on error or end-of-file.
133
 */
164
 */
134
static int
165
static int
135
readrec_vx(FILE *f, struct acctv2 *av2)
166
readrec_vx(FILE *f, struct acctv3 *av3)
136
{
167
{
137
	uint8_t magic, version;
168
	uint8_t magic, version;
138
169
Lines 143-149 readrec_vx(FILE *f, struct acctv2 *av2) Link Here
143
		return (EOF);
174
		return (EOF);
144
	switch (version) {
175
	switch (version) {
145
	case 2:
176
	case 2:
146
		return (readrec_v2(f, av2));
177
		return (readrec_v2(f, av3));
178
	case 3:
179
		return (readrec_v3(f, av3));
147
180
148
	/* Add handling for more versions here. */
181
	/* Add handling for more versions here. */
149
182
Lines 162-168 readrec_vx(FILE *f, struct acctv2 *av2) Link Here
162
 * or EOF on error.
195
 * or EOF on error.
163
 */
196
 */
164
int
197
int
165
readrec_forward(FILE *f, struct acctv2 *av2)
198
readrec_forward(FILE *f, struct acctv3 *av3)
166
{
199
{
167
	int magic, rv;
200
	int magic, rv;
168
201
Lines 172-181 readrec_forward(FILE *f, struct acctv2 *av2) Link Here
172
		return (EOF);
205
		return (EOF);
173
	if (magic != 0)
206
	if (magic != 0)
174
		/* Old record format. */
207
		/* Old record format. */
175
		rv = readrec_v1(f, av2);
208
		rv = readrec_v1(f, av3);
176
	else
209
	else
177
		/* New record formats. */
210
		/* New record formats. */
178
		rv = readrec_vx(f, av2);
211
		rv = readrec_vx(f, av3);
179
	return (rv == EOF ? EOF : 1);
212
	return (rv == EOF ? EOF : 1);
180
}
213
}
181
214
Lines 190-196 readrec_forward(FILE *f, struct acctv2 *av2) Link Here
190
 * or EOF on error.
223
 * or EOF on error.
191
 */
224
 */
192
int
225
int
193
readrec_backward(FILE *f, struct acctv2 *av2)
226
readrec_backward(FILE *f, struct acctv3 *av3)
194
{
227
{
195
	off_t pos;
228
	off_t pos;
196
	int c;
229
	int c;
Lines 200-216 readrec_backward(FILE *f, struct acctv2 *av2) Link Here
200
		return (EOF);
233
		return (EOF);
201
	if (pos == 0)
234
	if (pos == 0)
202
		return (0);
235
		return (0);
203
	if (fseek(f, -roffsetof(struct acctv2, ac_trailer),
236
	if (fseek(f, -roffsetof(struct acctv3, ac_trailer),
204
	    SEEK_CUR) == EOF ||
237
	    SEEK_CUR) == EOF ||
205
	    (c = getc(f)) == EOF)
238
	    (c = getc(f)) == EOF)
206
		return (EOF);
239
		return (EOF);
207
	if (c & ANVER) {
240
	if (c & ANVER) {
208
		/* New record formats. */
241
		/*
242
		 * New record formats.  For v2 and v3 offset from the
243
		 * end for ac_len2 should be same.
244
		 */
209
		if (fseeko(f, pos - roffsetof(struct acctv2, ac_len2),
245
		if (fseeko(f, pos - roffsetof(struct acctv2, ac_len2),
210
		    SEEK_SET) == EOF ||
246
		    SEEK_SET) == EOF ||
211
		    fread_record(&len, sizeof(len), f) == EOF ||
247
		    fread_record(&len, sizeof(len), f) == EOF ||
212
		    fseeko(f, pos - len, SEEK_SET) == EOF ||
248
		    fseeko(f, pos - len, SEEK_SET) == EOF ||
213
		    readrec_vx(f, av2) == EOF ||
249
		    readrec_vx(f, av3) == EOF ||
214
		    fseeko(f, pos - len, SEEK_SET) == EOF)
250
		    fseeko(f, pos - len, SEEK_SET) == EOF)
215
			return (EOF);
251
			return (EOF);
216
		else
252
		else
Lines 218-224 readrec_backward(FILE *f, struct acctv2 *av2) Link Here
218
	} else {
254
	} else {
219
		/* Old record format. */
255
		/* Old record format. */
220
		if (fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF ||
256
		if (fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF ||
221
		    readrec_v1(f, av2) == EOF ||
257
		    readrec_v1(f, av3) == EOF ||
222
		    fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF)
258
		    fseeko(f, pos - sizeof(struct acctv1), SEEK_SET) == EOF)
223
			return (EOF);
259
			return (EOF);
224
		else
260
		else
(-)b/usr.sbin/pstat/pstat.c (-1 / +1 lines)
Lines 255-261 ttymode_kvm(void) Link Here
255
		/* xt.xt_pgid = ... */
255
		/* xt.xt_pgid = ... */
256
		/* xt.xt_sid = ... */
256
		/* xt.xt_sid = ... */
257
		xt.xt_flags = tty.t_flags;
257
		xt.xt_flags = tty.t_flags;
258
		xt.xt_dev = NODEV;
258
		xt.xt_dev = (uint32_t)NODEV;
259
		ttyprt(&xt);
259
		ttyprt(&xt);
260
		tp = TAILQ_NEXT(&tty, t_list);
260
		tp = TAILQ_NEXT(&tty, t_list);
261
	}
261
	}
(-)b/usr.sbin/sa/extern.h (-1 / +1 lines)
Lines 79-85 int pacct_update(void); Link Here
79
void	pacct_print(void);
79
void	pacct_print(void);
80
80
81
/* external functions in readrec.c */
81
/* external functions in readrec.c */
82
int	readrec_forward(FILE *f, struct acctv2 *av2);
82
int	readrec_forward(FILE *f, struct acctv3 *av2);
83
83
84
/* external functions in usrdb.c */
84
/* external functions in usrdb.c */
85
int	usracct_init(void);
85
int	usracct_init(void);
(-)b/usr.sbin/sa/main.c (-1 / +1 lines)
Lines 310-316 usage(void) Link Here
310
static FILE *
310
static FILE *
311
acct_load(const char *pn, int wr)
311
acct_load(const char *pn, int wr)
312
{
312
{
313
	struct acctv2 ac;
313
	struct acctv3 ac;
314
	struct cmdinfo ci;
314
	struct cmdinfo ci;
315
	ssize_t rv;
315
	ssize_t rv;
316
	FILE *f;
316
	FILE *f;

Return to bug 218320