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/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 / +1 lines)
Lines 47-53 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 */
(-)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 (+1080 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.  Each occurrence of the *
879
 * pattern causes a recursion level.
880
 */
881
static int
882
match(Char *name, Char *pat, Char *patend)
883
{
884
	int ok, negate_range;
885
	Char c, k;
886
	struct xlocale_collate *table =
887
		(struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
888
889
	while (pat < patend) {
890
		c = *pat++;
891
		switch (c & M_MASK) {
892
		case M_ALL:
893
			if (pat == patend)
894
				return (1);
895
			do
896
			    if (match(name, pat, patend))
897
				    return (1);
898
			while (*name++ != EOS);
899
			return (0);
900
		case M_ONE:
901
			if (*name++ == EOS)
902
				return (0);
903
			break;
904
		case M_SET:
905
			ok = 0;
906
			if ((k = *name++) == EOS)
907
				return (0);
908
			if ((negate_range = ((*pat & M_MASK) == M_NOT)) != 0)
909
				++pat;
910
			while (((c = *pat++) & M_MASK) != M_END)
911
				if ((*pat & M_MASK) == M_RNG) {
912
					if (table->__collate_load_error ?
913
					    CHAR(c) <= CHAR(k) &&
914
					    CHAR(k) <= CHAR(pat[1]) :
915
					    __wcollate_range_cmp(CHAR(c),
916
					    CHAR(k)) <= 0 &&
917
					    __wcollate_range_cmp(CHAR(k),
918
					    CHAR(pat[1])) <= 0)
919
						ok = 1;
920
					pat += 2;
921
				} else if (c == k)
922
					ok = 1;
923
			if (ok == negate_range)
924
				return (0);
925
			break;
926
		default:
927
			if (*name++ != c)
928
				return (0);
929
			break;
930
		}
931
	}
932
	return (*name == EOS);
933
}
934
935
/* Free allocated data belonging to a glob11_t structure. */
936
void
937
freebsd11_globfree(glob11_t *pglob)
938
{
939
	size_t i;
940
	char **pp;
941
942
	if (pglob->gl_pathv != NULL) {
943
		pp = pglob->gl_pathv + pglob->gl_offs;
944
		for (i = pglob->gl_pathc; i--; ++pp)
945
			if (*pp)
946
				free(*pp);
947
		free(pglob->gl_pathv);
948
		pglob->gl_pathv = NULL;
949
	}
950
}
951
952
static DIR *
953
g_opendir(Char *str, glob11_t *pglob)
954
{
955
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
956
957
	if (*str == EOS)
958
		strcpy(buf, ".");
959
	else {
960
		if (g_Ctoc(str, buf, sizeof(buf))) {
961
			errno = ENAMETOOLONG;
962
			return (NULL);
963
		}
964
	}
965
966
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
967
		return ((*pglob->gl_opendir)(buf));
968
969
	return (opendir(buf));
970
}
971
972
static int
973
g_lstat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
974
{
975
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
976
977
	if (g_Ctoc(fn, buf, sizeof(buf))) {
978
		errno = ENAMETOOLONG;
979
		return (-1);
980
	}
981
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
982
		return((*pglob->gl_lstat)(buf, sb));
983
	return (freebsd11_lstat(buf, sb));
984
}
985
986
static int
987
g_stat(Char *fn, struct freebsd11_stat *sb, glob11_t *pglob)
988
{
989
	char buf[MAXPATHLEN + MB_LEN_MAX - 1];
990
991
	if (g_Ctoc(fn, buf, sizeof(buf))) {
992
		errno = ENAMETOOLONG;
993
		return (-1);
994
	}
995
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
996
		return ((*pglob->gl_stat)(buf, sb));
997
	return (freebsd11_stat(buf, sb));
998
}
999
1000
static const Char *
1001
g_strchr(const Char *str, wchar_t ch)
1002
{
1003
1004
	do {
1005
		if (*str == ch)
1006
			return (str);
1007
	} while (*str++);
1008
	return (NULL);
1009
}
1010
1011
static int
1012
g_Ctoc(const Char *str, char *buf, size_t len)
1013
{
1014
	mbstate_t mbs;
1015
	size_t clen;
1016
1017
	memset(&mbs, 0, sizeof(mbs));
1018
	while (len >= MB_CUR_MAX) {
1019
		clen = wcrtomb(buf, CHAR(*str), &mbs);
1020
		if (clen == (size_t)-1) {
1021
			/* XXX See initial comment #2. */
1022
			*buf = (char)CHAR(*str);
1023
			clen = 1;
1024
			memset(&mbs, 0, sizeof(mbs));
1025
		}
1026
		if (CHAR(*str) == EOS)
1027
			return (0);
1028
		str++;
1029
		buf += clen;
1030
		len -= clen;
1031
	}
1032
	return (1);
1033
}
1034
1035
static int
1036
err_nomatch(glob11_t *pglob, struct glob_limit *limit, const char *origpat) {
1037
	/*
1038
	 * If there was no match we are going to append the origpat
1039
	 * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
1040
	 * and the origpat did not contain any magic characters
1041
	 * GLOB_NOMAGIC is there just for compatibility with csh.
1042
	 */
1043
	if ((pglob->gl_flags & GLOB_NOCHECK) ||
1044
	    ((pglob->gl_flags & GLOB_NOMAGIC) &&
1045
	    !(pglob->gl_flags & GLOB_MAGCHAR)))
1046
		return (globextend(NULL, pglob, limit, origpat));
1047
	return (GLOB_NOMATCH);
1048
}
1049
1050
static int
1051
err_aborted(glob11_t *pglob, int err, char *buf) {
1052
	if ((pglob->gl_errfunc != NULL && pglob->gl_errfunc(buf, err)) ||
1053
	    (pglob->gl_flags & GLOB_ERR))
1054
		return (GLOB_ABORTED);
1055
	return (0);
1056
}
1057
1058
#ifdef DEBUG
1059
static void
1060
qprintf(const char *str, Char *s)
1061
{
1062
	Char *p;
1063
1064
	(void)printf("%s\n", str);
1065
	if (s != NULL) {
1066
		for (p = s; *p != EOS; p++)
1067
			(void)printf("%c", (char)CHAR(*p));
1068
		(void)printf("\n");
1069
		for (p = s; *p != EOS; p++)
1070
			(void)printf("%c", (isprot(*p) ? '\\' : ' '));
1071
		(void)printf("\n");
1072
		for (p = s; *p != EOS; p++)
1073
			(void)printf("%c", (ismeta(*p) ? '_' : ' '));
1074
		(void)printf("\n");
1075
	}
1076
}
1077
#endif
1078
1079
__sym_compat(glob, freebsd11_glob, FBSD_1.0);
1080
__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/readdir-compat11.c (+121 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 int
57
freebsd11_cvtdirent(struct freebsd11_dirent *dstdp, struct dirent *srcdp)
58
{
59
60
	if (srcdp->d_namlen > sizeof(dstdp->d_name) - 1)
61
		return (ENAMETOOLONG);
62
	dstdp->d_type = srcdp->d_type;
63
	dstdp->d_namlen = srcdp->d_namlen;
64
	dstdp->d_fileno = srcdp->d_fileno;		/* truncate */
65
	dstdp->d_reclen = FREEBSD11_DIRSIZ(dstdp);
66
	bcopy(srcdp->d_name, dstdp->d_name, dstdp->d_namlen);
67
	bzero(dstdp->d_name + dstdp->d_namlen,
68
	    dstdp->d_reclen - offsetof(struct freebsd11_dirent, d_name) -
69
	    dstdp->d_namlen);
70
	return (0);
71
}
72
73
struct freebsd11_dirent *
74
freebsd11_readdir(DIR *dirp)
75
{
76
	static struct freebsd11_dirent *compatbuf;
77
	struct freebsd11_dirent *dstdp;
78
	struct dirent *dp;
79
80
	if (__isthreaded)
81
		_pthread_mutex_lock(&dirp->dd_lock);
82
again:
83
	dp = _readdir_unlocked(dirp, 1);
84
	if (dp != NULL) {
85
		if (compatbuf == NULL)
86
			compatbuf = malloc(sizeof(struct freebsd11_dirent));
87
		if (freebsd11_cvtdirent(compatbuf, dp) != 0)
88
			goto again;
89
		dstdp = compatbuf;
90
	} else
91
		dstdp = NULL;
92
	if (__isthreaded)
93
		_pthread_mutex_unlock(&dirp->dd_lock);
94
95
	return (dstdp);
96
}
97
98
int
99
freebsd11_readdir_r(DIR *dirp, struct freebsd11_dirent *entry,
100
    struct freebsd11_dirent **result)
101
{
102
	struct dirent xentry;
103
	struct dirent *xresult;
104
	int error;
105
106
again:
107
	error = readdir_r(dirp, &xentry, &xresult);
108
109
	if (error != 0)
110
		return (error);
111
	if (xresult != NULL) {
112
		if (freebsd11_cvtdirent(entry, &xentry) != 0)
113
			goto again;
114
		*result = entry;
115
	} else
116
		*result = NULL;
117
	return (0);
118
}
119
120
__sym_compat(readdir, freebsd11_readdir, FBSD_1.0);
121
__sym_compat(readdir_r, freebsd11_readdir_r, FBSD_1.0);
(-)b/lib/libc/gen/scandir-compat11.c (+175 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 numitems;
84
	long arraysz;
85
	DIR *dirp;
86
87
	if ((dirp = opendir(dirname)) == NULL)
88
		return(-1);
89
90
	numitems = 0;
91
	arraysz = 32;	/* initial estimate of the array size */
92
	names = (struct freebsd11_dirent **)malloc(
93
	    arraysz * sizeof(struct freebsd11_dirent *));
94
	if (names == NULL)
95
		goto fail;
96
97
	while ((d = freebsd11_readdir(dirp)) != NULL) {
98
		if (select != NULL && !SELECT(d))
99
			continue;	/* just selected names */
100
		/*
101
		 * Make a minimum size copy of the data
102
		 */
103
		p = (struct freebsd11_dirent *)malloc(FREEBSD11_DIRSIZ(d));
104
		if (p == NULL)
105
			goto fail;
106
		p->d_fileno = d->d_fileno;
107
		p->d_type = d->d_type;
108
		p->d_reclen = d->d_reclen;
109
		p->d_namlen = d->d_namlen;
110
		bcopy(d->d_name, p->d_name, p->d_namlen + 1);
111
		/*
112
		 * Check to make sure the array has space left and
113
		 * realloc the maximum size.
114
		 */
115
		if (numitems >= arraysz) {
116
			struct freebsd11_dirent **names2;
117
118
			names2 = reallocarray(names, arraysz,
119
			    2 * sizeof(struct freebsd11_dirent *));
120
			if (names2 == NULL) {
121
				free(p);
122
				goto fail;
123
			}
124
			names = names2;
125
			arraysz *= 2;
126
		}
127
		names[numitems++] = p;
128
	}
129
	closedir(dirp);
130
	if (numitems && dcomp != NULL)
131
#ifdef I_AM_SCANDIR_B
132
		qsort_b(names, numitems, sizeof(struct freebsd11_dirent *),
133
		    (void*)dcomp);
134
#else
135
		qsort_r(names, numitems, sizeof(struct freebsd11_dirent *),
136
		    &dcomp, freebsd11_alphasort_thunk);
137
#endif
138
	*namelist = names;
139
	return (numitems);
140
141
fail:
142
	while (numitems > 0)
143
		free(names[--numitems]);
144
	free(names);
145
	closedir(dirp);
146
	return (-1);
147
}
148
149
/*
150
 * Alphabetic order comparison routine for those who want it.
151
 * POSIX 2008 requires that alphasort() uses strcoll().
152
 */
153
int
154
freebsd11_alphasort(const struct freebsd11_dirent **d1,
155
    const struct freebsd11_dirent **d2)
156
{
157
158
	return (strcoll((*d1)->d_name, (*d2)->d_name));
159
}
160
161
static int
162
freebsd11_alphasort_thunk(void *thunk, const void *p1, const void *p2)
163
{
164
	int (*dc)(const struct freebsd11_dirent **, const struct
165
	    freebsd11_dirent **);
166
167
	dc = *(int (**)(const struct freebsd11_dirent **,
168
	    const struct freebsd11_dirent **))thunk;
169
	return (dc((const struct freebsd11_dirent **)p1,
170
	    (const struct freebsd11_dirent **)p2));
171
}
172
173
__sym_compat(alphasort, freebsd11_alphasort, FBSD_1.0);
174
__sym_compat(scandir, freebsd11_scandir, FBSD_1.0);
175
__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 101-107 scandir(const char *dirname, struct dirent ***namelist, Link Here
101
		/*
90
		/*
102
		 * Make a minimum size copy of the data
91
		 * Make a minimum size copy of the data
103
		 */
92
		 */
104
		p = (struct dirent *)malloc(DIRSIZ(d));
93
		p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d));
105
		if (p == NULL)
94
		if (p == NULL)
106
			goto fail;
95
			goto fail;
107
		p->d_fileno = d->d_fileno;
96
		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 (+69 lines)
Added Link Here
1
Index: devel/llvm39/Makefile
2
===================================================================
3
--- devel/llvm39/Makefile	(revision 437547)
4
+++ devel/llvm39/Makefile	(working copy)
5
@@ -326,6 +326,7 @@
6
 
7
 post-patch-COMPILER_RT-on:
8
 	cd ${WRKSRC_compiler_rt} && patch < ${PATCHDIR}/compiler-rt-patch-svn-294806
9
+	cd ${WRKSRC_compiler_rt} && patch < ${PATCHDIR}/compiler-rt-patch-ino64
10
 
11
 post-build-COMPILER_RT-on:
12
 	${MKDIR} ${WRKDIR}/compiler-rt-build
13
Index: devel/llvm39/files/compiler-rt-patch-ino64
14
===================================================================
15
--- devel/llvm39/files/compiler-rt-patch-ino64	(nonexistent)
16
+++ devel/llvm39/files/compiler-rt-patch-ino64	(working copy)
17
@@ -0,0 +1,49 @@
18
+diff --git lib/sanitizer_common/sanitizer_linux.cc lib/sanitizer_common/sanitizer_linux.cc
19
+index 7328a5c0ac1..4b59a39ee27 100644
20
+--- lib/sanitizer_common/sanitizer_linux.cc
21
++++ lib/sanitizer_common/sanitizer_linux.cc
22
+@@ -223,7 +223,8 @@ static void kernel_stat_to_stat(struct kernel_stat *in, struct stat *out) {
23
+ 
24
+ uptr internal_stat(const char *path, void *buf) {
25
+ #if SANITIZER_FREEBSD
26
+-  return internal_syscall(SYSCALL(stat), path, buf);
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 / +32 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 160-172 struct msghdr32 { Link Here
160
};
161
};
161
162
162
struct stat32 {
163
struct stat32 {
163
	dev_t	st_dev;
164
	dev_t st_dev;
164
	ino_t	st_ino;
165
	ino_t st_ino;
166
	nlink_t st_nlink;
165
	mode_t	st_mode;
167
	mode_t	st_mode;
166
	nlink_t	st_nlink;
168
	u_int16_t st_padding0;
167
	uid_t	st_uid;
169
	uid_t	st_uid;
168
	gid_t	st_gid;
170
	gid_t	st_gid;
169
	dev_t	st_rdev;
171
	u_int32_t st_padding1;
172
	dev_t st_rdev;
173
	struct timespec32 st_atim;
174
	struct timespec32 st_mtim;
175
	struct timespec32 st_ctim;
176
	struct timespec32 st_birthtim;
177
	off_t	st_size;
178
	int64_t	st_blocks;
179
	u_int32_t st_blksize;
180
	u_int32_t st_flags;
181
	u_int64_t st_gen;
182
	u_int64_t st_spare[10];
183
};
184
struct freebsd11_stat32 {
185
	u_int32_t st_dev;
186
	u_int32_t st_ino;
187
	mode_t	st_mode;
188
	u_int16_t st_nlink;
189
	uid_t	st_uid;
190
	gid_t	st_gid;
191
	u_int32_t st_rdev;
170
	struct timespec32 st_atim;
192
	struct timespec32 st_atim;
171
	struct timespec32 st_mtim;
193
	struct timespec32 st_mtim;
172
	struct timespec32 st_ctim;
194
	struct timespec32 st_ctim;
Lines 183-191 struct stat32 { Link Here
183
205
184
struct ostat32 {
206
struct ostat32 {
185
	__uint16_t st_dev;
207
	__uint16_t st_dev;
186
	ino_t	st_ino;
208
	__uint32_t st_ino;
187
	mode_t	st_mode;
209
	mode_t	st_mode;
188
	nlink_t	st_nlink;
210
	__uint16_t st_nlink;
189
	__uint16_t st_uid;
211
	__uint16_t st_uid;
190
	__uint16_t st_gid;
212
	__uint16_t st_gid;
191
	__uint16_t st_rdev;
213
	__uint16_t st_rdev;
Lines 270-276 struct kinfo_proc32 { Link Here
270
	pid_t	ki_tsid;
292
	pid_t	ki_tsid;
271
	short	ki_jobc;
293
	short	ki_jobc;
272
	short	ki_spare_short1;
294
	short	ki_spare_short1;
273
	dev_t	ki_tdev;
295
	uint32_t ki_tdev_freebsd11;
274
	sigset_t ki_siglist;
296
	sigset_t ki_siglist;
275
	sigset_t ki_sigmask;
297
	sigset_t ki_sigmask;
276
	sigset_t ki_sigignore;
298
	sigset_t ki_sigignore;
Lines 318-323 struct kinfo_proc32 { Link Here
318
	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
340
	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
319
	char	ki_sparestrings[46];
341
	char	ki_sparestrings[46];
320
	int	ki_spareints[KI_NSPARE_INT];
342
	int	ki_spareints[KI_NSPARE_INT];
343
	uint64_t ki_tdev;
321
	int	ki_oncpu;
344
	int	ki_oncpu;
322
	int	ki_lastcpu;
345
	int	ki_lastcpu;
323
	int	ki_tracer;
346
	int	ki_tracer;
(-)b/sys/compat/freebsd32/freebsd32_misc.c (-23 / +183 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) == 192);
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
	bzero(out->st_spare, sizeof(out->st_spare));
1712
}
1770
}
1713
1771
1714
#ifdef COMPAT_43
1772
#ifdef COMPAT_43
Lines 1734-1755 copy_ostat(struct stat *in, struct ostat32 *out) Link Here
1734
}
1792
}
1735
#endif
1793
#endif
1736
1794
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
1795
#ifdef COMPAT_43
1754
int
1796
int
1755
ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1797
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);
1858
	return (error);
1817
}
1859
}
1818
1860
1861
#ifdef COMPAT_43
1819
int
1862
int
1820
freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1863
ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1821
{
1864
{
1822
	struct stat sb;
1865
	struct stat sb;
1823
	struct stat32 sb32;
1866
	struct ostat32 sb32;
1824
	int error;
1867
	int error;
1825
1868
1826
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1869
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1827
	    UIO_USERSPACE, &sb, NULL);
1870
	    UIO_USERSPACE, &sb, NULL);
1828
	if (error)
1871
	if (error)
1829
		return (error);
1872
		return (error);
1873
	copy_ostat(&sb, &sb32);
1874
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1875
	return (error);
1876
}
1877
#endif
1878
1879
int
1880
freebsd32_fhstat(struct thread *td, struct freebsd32_fhstat_args *uap)
1881
{
1882
	struct stat sb;
1883
	struct stat32 sb32;
1884
	struct fhandle fh;
1885
	int error;
1886
1887
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
1888
        if (error != 0)
1889
                return (error);
1890
	error = kern_fhstat(td, fh, &sb);
1891
	if (error != 0)
1892
		return (error);
1830
	copy_stat(&sb, &sb32);
1893
	copy_stat(&sb, &sb32);
1894
	error = copyout(&sb32, uap->sb, sizeof (sb32));
1895
	return (error);
1896
}
1897
1898
#if defined(COMPAT_FREEBSD11)
1899
static void
1900
freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
1901
{
1902
1903
	CP(*in, *out, st_ino);
1904
	CP(*in, *out, st_nlink);
1905
	CP(*in, *out, st_dev);
1906
	CP(*in, *out, st_mode);
1907
	CP(*in, *out, st_uid);
1908
	CP(*in, *out, st_gid);
1909
	CP(*in, *out, st_rdev);
1910
	TS_CP(*in, *out, st_atim);
1911
	TS_CP(*in, *out, st_mtim);
1912
	TS_CP(*in, *out, st_ctim);
1913
	CP(*in, *out, st_size);
1914
	CP(*in, *out, st_blocks);
1915
	CP(*in, *out, st_blksize);
1916
	CP(*in, *out, st_flags);
1917
	CP(*in, *out, st_gen);
1918
	TS_CP(*in, *out, st_birthtim);
1919
	out->st_lspare = 0;
1920
	bzero((char *)&out->st_birthtim + sizeof(out->st_birthtim),
1921
	    sizeof(*out) - offsetof(struct freebsd11_stat32,
1922
	    st_birthtim) - sizeof(out->st_birthtim));
1923
}
1924
1925
int
1926
freebsd11_freebsd32_stat(struct thread *td,
1927
    struct freebsd11_freebsd32_stat_args *uap)
1928
{
1929
	struct stat sb;
1930
	struct freebsd11_stat32 sb32;
1931
	int error;
1932
1933
	error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1934
	    &sb, NULL);
1935
	if (error != 0)
1936
		return (error);
1937
	freebsd11_cvtstat32(&sb, &sb32);
1831
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1938
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1832
	return (error);
1939
	return (error);
1833
}
1940
}
1834
1941
1835
#ifdef COMPAT_43
1836
int
1942
int
1837
ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1943
freebsd11_freebsd32_fstat(struct thread *td,
1944
    struct freebsd11_freebsd32_fstat_args *uap)
1838
{
1945
{
1839
	struct stat sb;
1946
	struct stat sb;
1840
	struct ostat32 sb32;
1947
	struct freebsd11_stat32 sb32;
1948
	int error;
1949
1950
	error = kern_fstat(td, uap->fd, &sb);
1951
	if (error != 0)
1952
		return (error);
1953
	freebsd11_cvtstat32(&sb, &sb32);
1954
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1955
	return (error);
1956
}
1957
1958
int
1959
freebsd11_freebsd32_fstatat(struct thread *td,
1960
    struct freebsd11_freebsd32_fstatat_args *uap)
1961
{
1962
	struct stat sb;
1963
	struct freebsd11_stat32 sb32;
1964
	int error;
1965
1966
	error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1967
	    &sb, NULL);
1968
	if (error != 0)
1969
		return (error);
1970
	freebsd11_cvtstat32(&sb, &sb32);
1971
	error = copyout(&sb32, uap->buf, sizeof (sb32));
1972
	return (error);
1973
}
1974
1975
int
1976
freebsd11_freebsd32_lstat(struct thread *td,
1977
    struct freebsd11_freebsd32_lstat_args *uap)
1978
{
1979
	struct stat sb;
1980
	struct freebsd11_stat32 sb32;
1841
	int error;
1981
	int error;
1842
1982
1843
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1983
	error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1844
	    UIO_USERSPACE, &sb, NULL);
1984
	    UIO_USERSPACE, &sb, NULL);
1845
	if (error)
1985
	if (error)
1846
		return (error);
1986
		return (error);
1847
	copy_ostat(&sb, &sb32);
1987
	freebsd11_cvtstat32(&sb, &sb32);
1848
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1988
	error = copyout(&sb32, uap->ub, sizeof (sb32));
1849
	return (error);
1989
	return (error);
1850
}
1990
}
1991
1992
int
1993
freebsd11_freebsd32_fhstat(struct thread *td,
1994
    struct freebsd11_freebsd32_fhstat_args *uap)
1995
{
1996
	struct stat sb;
1997
	struct freebsd11_stat32 sb32;
1998
	struct fhandle fh;
1999
	int error;
2000
2001
	error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2002
        if (error != 0)
2003
                return (error);
2004
	error = kern_fhstat(td, fh, &sb);
2005
	if (error != 0)
2006
		return (error);
2007
	freebsd11_cvtstat32(&sb, &sb32);
2008
	error = copyout(&sb32, uap->sb, sizeof (sb32));
2009
	return (error);
2010
}
1851
#endif
2011
#endif
1852
2012
1853
int
2013
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 2848-2864 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2848
			if (error)
2848
			if (error)
2849
			    return (error);
2849
			    return (error);
2850
			nd->nd_mrep = NULL;
2850
			nd->nd_mrep = NULL;
2851
			dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
2851
			dp = (struct dirent *)uio_iov_base(uiop);
2852
			dp->d_off = 0;
2852
			dp->d_type = DT_DIR;
2853
			dp->d_type = DT_DIR;
2853
			dp->d_fileno = dotfileid;
2854
			dp->d_fileno = dotfileid;
2854
			dp->d_namlen = 1;
2855
			dp->d_namlen = 1;
2856
			*((uint64_t *)dp->d_name) = 0;	/* Zero pad it. */
2855
			dp->d_name[0] = '.';
2857
			dp->d_name[0] = '.';
2856
			dp->d_name[1] = '\0';
2858
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
2857
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
2858
			/*
2859
			/*
2859
			 * Just make these offset cookie 0.
2860
			 * Just make these offset cookie 0.
2860
			 */
2861
			 */
2861
			tl = (u_int32_t *)&dp->d_name[4];
2862
			tl = (u_int32_t *)&dp->d_name[8];
2862
			*tl++ = 0;
2863
			*tl++ = 0;
2863
			*tl = 0;
2864
			*tl = 0;
2864
			blksiz += dp->d_reclen;
2865
			blksiz += dp->d_reclen;
Lines 2866-2883 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2866
			uiop->uio_offset += dp->d_reclen;
2867
			uiop->uio_offset += dp->d_reclen;
2867
			uio_iov_base_add(uiop, dp->d_reclen);
2868
			uio_iov_base_add(uiop, dp->d_reclen);
2868
			uio_iov_len_add(uiop, -(dp->d_reclen));
2869
			uio_iov_len_add(uiop, -(dp->d_reclen));
2869
			dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
2870
			dp = (struct dirent *)uio_iov_base(uiop);
2871
			dp->d_off = 0;
2870
			dp->d_type = DT_DIR;
2872
			dp->d_type = DT_DIR;
2871
			dp->d_fileno = dotdotfileid;
2873
			dp->d_fileno = dotdotfileid;
2872
			dp->d_namlen = 2;
2874
			dp->d_namlen = 2;
2875
			*((uint64_t *)dp->d_name) = 0;
2873
			dp->d_name[0] = '.';
2876
			dp->d_name[0] = '.';
2874
			dp->d_name[1] = '.';
2877
			dp->d_name[1] = '.';
2875
			dp->d_name[2] = '\0';
2878
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
2876
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
2877
			/*
2879
			/*
2878
			 * Just make these offset cookie 0.
2880
			 * Just make these offset cookie 0.
2879
			 */
2881
			 */
2880
			tl = (u_int32_t *)&dp->d_name[4];
2882
			tl = (u_int32_t *)&dp->d_name[8];
2881
			*tl++ = 0;
2883
			*tl++ = 0;
2882
			*tl = 0;
2884
			*tl = 0;
2883
			blksiz += dp->d_reclen;
2885
			blksiz += dp->d_reclen;
Lines 2974-2984 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2974
				error = EBADRPC;
2976
				error = EBADRPC;
2975
				goto nfsmout;
2977
				goto nfsmout;
2976
			}
2978
			}
2977
			tlen = NFSM_RNDUP(len);
2979
			tlen = roundup2(len, 8);
2978
			if (tlen == len)
2980
			if (tlen == len)
2979
				tlen += 4;  /* To ensure null termination */
2981
				tlen += 8;  /* To ensure null termination. */
2980
			left = DIRBLKSIZ - blksiz;
2982
			left = DIRBLKSIZ - blksiz;
2981
			if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > left) {
2983
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER > left) {
2982
				dp->d_reclen += left;
2984
				dp->d_reclen += left;
2983
				uio_iov_base_add(uiop, left);
2985
				uio_iov_base_add(uiop, left);
2984
				uio_iov_len_add(uiop, -(left));
2986
				uio_iov_len_add(uiop, -(left));
Lines 2986-2997 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
2986
				uiop->uio_offset += left;
2988
				uiop->uio_offset += left;
2987
				blksiz = 0;
2989
				blksiz = 0;
2988
			}
2990
			}
2989
			if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop))
2991
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER >
2992
			    uio_uio_resid(uiop))
2990
				bigenough = 0;
2993
				bigenough = 0;
2991
			if (bigenough) {
2994
			if (bigenough) {
2992
				dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
2995
				dp = (struct dirent *)uio_iov_base(uiop);
2996
				dp->d_off = 0;
2993
				dp->d_namlen = len;
2997
				dp->d_namlen = len;
2994
				dp->d_reclen = tlen + DIRHDSIZ + NFSX_HYPER;
2998
				dp->d_reclen = _GENERIC_DIRLEN(len) +
2999
				    NFSX_HYPER;
2995
				dp->d_type = DT_UNKNOWN;
3000
				dp->d_type = DT_UNKNOWN;
2996
				blksiz += dp->d_reclen;
3001
				blksiz += dp->d_reclen;
2997
				if (blksiz == DIRBLKSIZ)
3002
				if (blksiz == DIRBLKSIZ)
Lines 3003-3009 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3003
				error = nfsm_mbufuio(nd, uiop, len);
3008
				error = nfsm_mbufuio(nd, uiop, len);
3004
				if (error)
3009
				if (error)
3005
					goto nfsmout;
3010
					goto nfsmout;
3006
				cp = CAST_DOWN(caddr_t, uio_iov_base(uiop));
3011
				cp = uio_iov_base(uiop);
3007
				tlen -= len;
3012
				tlen -= len;
3008
				*cp = '\0';	/* null terminate */
3013
				*cp = '\0';	/* null terminate */
3009
				cp += tlen;	/* points to cookie storage */
3014
				cp += tlen;	/* points to cookie storage */
Lines 3118-3125 nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3118
	/*
3123
	/*
3119
	 * Add extra empty records to any remaining DIRBLKSIZ chunks.
3124
	 * Add extra empty records to any remaining DIRBLKSIZ chunks.
3120
	 */
3125
	 */
3121
	while (uio_uio_resid(uiop) > 0 && ((size_t)(uio_uio_resid(uiop))) != tresid) {
3126
	while (uio_uio_resid(uiop) > 0 && uio_uio_resid(uiop) != tresid) {
3122
		dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
3127
		dp = (struct dirent *)uio_iov_base(uiop);
3123
		dp->d_type = DT_UNKNOWN;
3128
		dp->d_type = DT_UNKNOWN;
3124
		dp->d_fileno = 0;
3129
		dp->d_fileno = 0;
3125
		dp->d_namlen = 0;
3130
		dp->d_namlen = 0;
Lines 3276-3291 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3276
			    return (error);
3281
			    return (error);
3277
			nd->nd_mrep = NULL;
3282
			nd->nd_mrep = NULL;
3278
			dp = (struct dirent *)uio_iov_base(uiop);
3283
			dp = (struct dirent *)uio_iov_base(uiop);
3284
			dp->d_off = 0;
3279
			dp->d_type = DT_DIR;
3285
			dp->d_type = DT_DIR;
3280
			dp->d_fileno = dotfileid;
3286
			dp->d_fileno = dotfileid;
3281
			dp->d_namlen = 1;
3287
			dp->d_namlen = 1;
3288
			*((uint64_t *)dp->d_name) = 0;	/* Zero pad it. */
3282
			dp->d_name[0] = '.';
3289
			dp->d_name[0] = '.';
3283
			dp->d_name[1] = '\0';
3290
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
3284
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
3285
			/*
3291
			/*
3286
			 * Just make these offset cookie 0.
3292
			 * Just make these offset cookie 0.
3287
			 */
3293
			 */
3288
			tl = (u_int32_t *)&dp->d_name[4];
3294
			tl = (u_int32_t *)&dp->d_name[8];
3289
			*tl++ = 0;
3295
			*tl++ = 0;
3290
			*tl = 0;
3296
			*tl = 0;
3291
			blksiz += dp->d_reclen;
3297
			blksiz += dp->d_reclen;
Lines 3294-3310 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3294
			uio_iov_base_add(uiop, dp->d_reclen);
3300
			uio_iov_base_add(uiop, dp->d_reclen);
3295
			uio_iov_len_add(uiop, -(dp->d_reclen));
3301
			uio_iov_len_add(uiop, -(dp->d_reclen));
3296
			dp = (struct dirent *)uio_iov_base(uiop);
3302
			dp = (struct dirent *)uio_iov_base(uiop);
3303
			dp->d_off = 0;
3297
			dp->d_type = DT_DIR;
3304
			dp->d_type = DT_DIR;
3298
			dp->d_fileno = dotdotfileid;
3305
			dp->d_fileno = dotdotfileid;
3299
			dp->d_namlen = 2;
3306
			dp->d_namlen = 2;
3307
			*((uint64_t *)dp->d_name) = 0;
3300
			dp->d_name[0] = '.';
3308
			dp->d_name[0] = '.';
3301
			dp->d_name[1] = '.';
3309
			dp->d_name[1] = '.';
3302
			dp->d_name[2] = '\0';
3310
			dp->d_reclen = _GENERIC_DIRSIZ(dp) + NFSX_HYPER;
3303
			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
3304
			/*
3311
			/*
3305
			 * Just make these offset cookie 0.
3312
			 * Just make these offset cookie 0.
3306
			 */
3313
			 */
3307
			tl = (u_int32_t *)&dp->d_name[4];
3314
			tl = (u_int32_t *)&dp->d_name[8];
3308
			*tl++ = 0;
3315
			*tl++ = 0;
3309
			*tl = 0;
3316
			*tl = 0;
3310
			blksiz += dp->d_reclen;
3317
			blksiz += dp->d_reclen;
Lines 3382-3392 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3382
				error = EBADRPC;
3389
				error = EBADRPC;
3383
				goto nfsmout;
3390
				goto nfsmout;
3384
			}
3391
			}
3385
			tlen = NFSM_RNDUP(len);
3392
			tlen = roundup2(len, 8);
3386
			if (tlen == len)
3393
			if (tlen == len)
3387
				tlen += 4;  /* To ensure null termination */
3394
				tlen += 8;  /* To ensure null termination. */
3388
			left = DIRBLKSIZ - blksiz;
3395
			left = DIRBLKSIZ - blksiz;
3389
			if ((tlen + DIRHDSIZ + NFSX_HYPER) > left) {
3396
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER > left) {
3390
				dp->d_reclen += left;
3397
				dp->d_reclen += left;
3391
				uio_iov_base_add(uiop, left);
3398
				uio_iov_base_add(uiop, left);
3392
				uio_iov_len_add(uiop, -(left));
3399
				uio_iov_len_add(uiop, -(left));
Lines 3394-3405 nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, Link Here
3394
				uiop->uio_offset += left;
3401
				uiop->uio_offset += left;
3395
				blksiz = 0;
3402
				blksiz = 0;
3396
			}
3403
			}
3397
			if ((tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop))
3404
			if (_GENERIC_DIRLEN(len) + NFSX_HYPER >
3405
			    uio_uio_resid(uiop))
3398
				bigenough = 0;
3406
				bigenough = 0;
3399
			if (bigenough) {
3407
			if (bigenough) {
3400
				dp = (struct dirent *)uio_iov_base(uiop);
3408
				dp = (struct dirent *)uio_iov_base(uiop);
3409
				dp->d_off = 0;
3401
				dp->d_namlen = len;
3410
				dp->d_namlen = len;
3402
				dp->d_reclen = tlen + DIRHDSIZ + NFSX_HYPER;
3411
				dp->d_reclen = _GENERIC_DIRLEN(len) +
3412
				    NFSX_HYPER;
3403
				dp->d_type = DT_UNKNOWN;
3413
				dp->d_type = DT_UNKNOWN;
3404
				blksiz += dp->d_reclen;
3414
				blksiz += dp->d_reclen;
3405
				if (blksiz == DIRBLKSIZ)
3415
				if (blksiz == DIRBLKSIZ)
(-)b/sys/fs/nfsclient/nfs_clvnops.c (-2 lines)
Lines 205-212 static int nfs_renameit(struct vnode *sdvp, struct vnode *svp, Link Here
205
/*
205
/*
206
 * Global variables
206
 * Global variables
207
 */
207
 */
208
#define	DIRHDSIZ	(sizeof (struct dirent) - (MAXNAMLEN + 1))
209
210
SYSCTL_DECL(_vfs_nfs);
208
SYSCTL_DECL(_vfs_nfs);
211
209
212
static int	nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
210
static int	nfsaccess_cache_timeout = NFS_MAXATTRTIMO;
(-)b/sys/fs/nfsserver/nfs_nfsdport.c (-11 / +28 lines)
Lines 2018-2034 again: Link Here
2018
	}
2018
	}
2019
2019
2020
	/*
2020
	/*
2021
	 * For now ZFS requires VOP_LOOKUP as a workaround.  Until ino_t is changed
2021
	 * Check to see if entries in this directory can be safely acquired
2022
	 * to 64 bit type a ZFS filesystem with over 1 billion files in it
2022
	 * via VFS_VGET() or if a switch to VOP_LOOKUP() is required.
2023
	 * will suffer from 64bit -> 32bit truncation.
2023
	 * ZFS snapshot directories need VOP_LOOKUP(), so that any
2024
	 * automount of the snapshot directory that is required will
2025
	 * be done.
2026
	 * This needs to be done here for NFSv4, since NFSv4 never does
2027
	 * a VFS_VGET() for "." or "..".
2024
	 */
2028
	 */
2025
	if (is_zfs == 1)
2029
	if (is_zfs == 1) {
2026
		usevget = 0;
2030
		r = VFS_VGET(mp, at.na_fileid, LK_SHARED, &nvp);
2027
2031
		if (r == EOPNOTSUPP) {
2028
	cn.cn_nameiop = LOOKUP;
2032
			usevget = 0;
2029
	cn.cn_lkflags = LK_SHARED | LK_RETRY;
2033
			cn.cn_nameiop = LOOKUP;
2030
	cn.cn_cred = nd->nd_cred;
2034
			cn.cn_lkflags = LK_SHARED | LK_RETRY;
2031
	cn.cn_thread = p;
2035
			cn.cn_cred = nd->nd_cred;
2036
			cn.cn_thread = p;
2037
		} else if (r == 0)
2038
			vput(nvp);
2039
	}
2032
2040
2033
	/*
2041
	/*
2034
	 * Save this position, in case there is an error before one entry
2042
	 * Save this position, in case there is an error before one entry
Lines 2097-2103 again: Link Here
2097
					else
2105
					else
2098
						r = EOPNOTSUPP;
2106
						r = EOPNOTSUPP;
2099
					if (r == EOPNOTSUPP) {
2107
					if (r == EOPNOTSUPP) {
2100
						usevget = 0;
2108
						if (usevget) {
2109
							usevget = 0;
2110
							cn.cn_nameiop = LOOKUP;
2111
							cn.cn_lkflags =
2112
							    LK_SHARED |
2113
							    LK_RETRY;
2114
							cn.cn_cred =
2115
							    nd->nd_cred;
2116
							cn.cn_thread = p;
2117
						}
2101
						cn.cn_nameptr = dp->d_name;
2118
						cn.cn_nameptr = dp->d_name;
2102
						cn.cn_namelen = nlen;
2119
						cn.cn_namelen = nlen;
2103
						cn.cn_flags = ISLASTCN |
2120
						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 / +36 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 1350-1367 kern_fstat(struct thread *td, int fd, struct stat *sbp) Link Here
1350
	return (error);
1367
	return (error);
1351
}
1368
}
1352
1369
1370
#if defined(COMPAT_FREEBSD11)
1353
/*
1371
/*
1354
 * Return status information about a file descriptor.
1372
 * Return status information about a file descriptor.
1355
 */
1373
 */
1356
#ifndef _SYS_SYSPROTO_H_
1374
#ifndef _SYS_SYSPROTO_H_
1357
struct nfstat_args {
1375
struct freebsd11_nfstat_args {
1358
	int	fd;
1376
	int	fd;
1359
	struct	nstat *sb;
1377
	struct	nstat *sb;
1360
};
1378
};
1361
#endif
1379
#endif
1362
/* ARGSUSED */
1380
/* ARGSUSED */
1363
int
1381
int
1364
sys_nfstat(struct thread *td, struct nfstat_args *uap)
1382
freebsd11_nfstat(struct thread *td, struct freebsd11_nfstat_args *uap)
1365
{
1383
{
1366
	struct nstat nub;
1384
	struct nstat nub;
1367
	struct stat ub;
1385
	struct stat ub;
Lines 1369-1379 sys_nfstat(struct thread *td, struct nfstat_args *uap) Link Here
1369
1387
1370
	error = kern_fstat(td, uap->fd, &ub);
1388
	error = kern_fstat(td, uap->fd, &ub);
1371
	if (error == 0) {
1389
	if (error == 0) {
1372
		cvtnstat(&ub, &nub);
1390
		freebsd11_cvtnstat(&ub, &nub);
1373
		error = copyout(&nub, uap->sb, sizeof(nub));
1391
		error = copyout(&nub, uap->sb, sizeof(nub));
1374
	}
1392
	}
1375
	return (error);
1393
	return (error);
1376
}
1394
}
1395
#endif /* COMPAT_FREEBSD11 */
1377
1396
1378
/*
1397
/*
1379
 * Return pathconf information about a file descriptor.
1398
 * 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 |
3609
	    KF_FLAG_APPEND | KF_FLAG_ASYNC | KF_FLAG_FSYNC | KF_FLAG_NONBLOCK |
3591
	    KF_FLAG_DIRECT | KF_FLAG_HASLOCK);
3610
	    KF_FLAG_DIRECT | KF_FLAG_HASLOCK);
3592
	okif->kf_offset = kif->kf_offset;
3611
	okif->kf_offset = kif->kf_offset;
3593
	okif->kf_vnode_type = kif->kf_vnode_type;
3612
	if (kif->kf_type == KF_TYPE_VNODE)
3594
	okif->kf_sock_domain = kif->kf_sock_domain;
3613
		okif->kf_vnode_type = kif->kf_un.kf_file.kf_file_type;
3595
	okif->kf_sock_type = kif->kf_sock_type;
3614
	else
3596
	okif->kf_sock_protocol = kif->kf_sock_protocol;
3615
		okif->kf_vnode_type = KF_VTYPE_VNON;
3597
	strlcpy(okif->kf_path, kif->kf_path, sizeof(okif->kf_path));
3616
	strlcpy(okif->kf_path, kif->kf_path, sizeof(okif->kf_path));
3598
	okif->kf_sa_local = kif->kf_sa_local;
3617
	if (kif->kf_type == KF_TYPE_SOCKET) {
3599
	okif->kf_sa_peer = kif->kf_sa_peer;
3618
		okif->kf_sock_domain = kif->kf_un.kf_sock.kf_sock_domain0;
3619
		okif->kf_sock_type = kif->kf_un.kf_sock.kf_sock_type0;
3620
		okif->kf_sock_protocol = kif->kf_un.kf_sock.kf_sock_protocol0;
3621
		okif->kf_sa_local = kif->kf_un.kf_sock.kf_sa_local;
3622
		okif->kf_sa_peer = kif->kf_un.kf_sock.kf_sa_peer;
3623
	} else {
3624
		okif->kf_sa_local.ss_family = AF_UNSPEC;
3625
		okif->kf_sa_peer.ss_family = AF_UNSPEC;
3626
	}
3600
}
3627
}
3601
3628
3602
static int
3629
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 / +387 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));
2266
	return (error);
2267
}
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));
2117
	return (error);
2301
	return (error);
2118
}
2302
}
2119
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 2177-2219 kern_statat(struct thread *td, int flag, int fd, char *path, Link Here
2177
	return (0);
2381
	return (0);
2178
}
2382
}
2179
2383
2180
/*
2384
#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
/*
2385
/*
2208
 * Implementation of the NetBSD [l]stat() functions.
2386
 * Implementation of the NetBSD [l]stat() functions.
2209
 */
2387
 */
2210
void
2388
void
2211
cvtnstat(sb, nsb)
2389
freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb)
2212
	struct stat *sb;
2213
	struct nstat *nsb;
2214
{
2390
{
2215
2391
2216
	bzero(nsb, sizeof *nsb);
2392
	bzero(nsb, sizeof(*nsb));
2217
	nsb->st_dev = sb->st_dev;
2393
	nsb->st_dev = sb->st_dev;
2218
	nsb->st_ino = sb->st_ino;
2394
	nsb->st_ino = sb->st_ino;
2219
	nsb->st_mode = sb->st_mode;
2395
	nsb->st_mode = sb->st_mode;
Lines 2233-2247 cvtnstat(sb, nsb) Link Here
2233
}
2409
}
2234
2410
2235
#ifndef _SYS_SYSPROTO_H_
2411
#ifndef _SYS_SYSPROTO_H_
2236
struct nstat_args {
2412
struct freebsd11_nstat_args {
2237
	char	*path;
2413
	char	*path;
2238
	struct nstat *ub;
2414
	struct nstat *ub;
2239
};
2415
};
2240
#endif
2416
#endif
2241
int
2417
int
2242
sys_nstat(td, uap)
2418
freebsd11_nstat(td, uap)
2243
	struct thread *td;
2419
	struct thread *td;
2244
	register struct nstat_args /* {
2420
	register struct freebsd11_nstat_args /* {
2245
		char *path;
2421
		char *path;
2246
		struct nstat *ub;
2422
		struct nstat *ub;
2247
	} */ *uap;
2423
	} */ *uap;
Lines 2254-2260 sys_nstat(td, uap) Link Here
2254
	    &sb, NULL);
2430
	    &sb, NULL);
2255
	if (error != 0)
2431
	if (error != 0)
2256
		return (error);
2432
		return (error);
2257
	cvtnstat(&sb, &nsb);
2433
	freebsd11_cvtnstat(&sb, &nsb);
2258
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2434
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2259
}
2435
}
2260
2436
Lines 2262-2276 sys_nstat(td, uap) Link Here
2262
 * NetBSD lstat.  Get file status; this version does not follow links.
2438
 * NetBSD lstat.  Get file status; this version does not follow links.
2263
 */
2439
 */
2264
#ifndef _SYS_SYSPROTO_H_
2440
#ifndef _SYS_SYSPROTO_H_
2265
struct lstat_args {
2441
struct freebsd11_nlstat_args {
2266
	char	*path;
2442
	char	*path;
2267
	struct stat *ub;
2443
	struct stat *ub;
2268
};
2444
};
2269
#endif
2445
#endif
2270
int
2446
int
2271
sys_nlstat(td, uap)
2447
freebsd11_nlstat(td, uap)
2272
	struct thread *td;
2448
	struct thread *td;
2273
	register struct nlstat_args /* {
2449
	register struct freebsd11_nlstat_args /* {
2274
		char *path;
2450
		char *path;
2275
		struct nstat *ub;
2451
		struct nstat *ub;
2276
	} */ *uap;
2452
	} */ *uap;
Lines 2283-2291 sys_nlstat(td, uap) Link Here
2283
	    UIO_USERSPACE, &sb, NULL);
2459
	    UIO_USERSPACE, &sb, NULL);
2284
	if (error != 0)
2460
	if (error != 0)
2285
		return (error);
2461
		return (error);
2286
	cvtnstat(&sb, &nsb);
2462
	freebsd11_cvtnstat(&sb, &nsb);
2287
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2463
	return (copyout(&nsb, uap->ub, sizeof (nsb)));
2288
}
2464
}
2465
#endif /* COMPAT_FREEBSD11 */
2289
2466
2290
/*
2467
/*
2291
 * Get configurable pathname variables.
2468
 * Get configurable pathname variables.
Lines 3751-3757 out: Link Here
3751
	return (error);
3928
	return (error);
3752
}
3929
}
3753
3930
3931
#if defined(COMPAT_43) || defined(COMPAT_FREEBSD11)
3932
int
3933
freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int count,
3934
    long *basep, void (*func)(struct freebsd11_dirent *))
3935
{
3936
	struct freebsd11_dirent dstdp;
3937
	struct dirent *dp, *edp;
3938
	char *dirbuf;
3939
	off_t base;
3940
	ssize_t resid, ucount;
3941
	int error;
3942
3943
	/* XXX arbitrary sanity limit on `count'. */
3944
	count = min(count, 64 * 1024);
3945
3946
	dirbuf = malloc(count, M_TEMP, M_WAITOK);
3947
3948
	error = kern_getdirentries(td, fd, dirbuf, count, &base, &resid,
3949
	    UIO_SYSSPACE);
3950
	if (error != 0)
3951
		goto done;
3952
	if (basep != NULL)
3953
		*basep = base;
3954
3955
	ucount = 0;
3956
	for (dp = (struct dirent *)dirbuf,
3957
	    edp = (struct dirent *)&dirbuf[count - resid];
3958
	    ucount < count && dp < edp; ) {
3959
		if (dp->d_reclen == 0)
3960
			break;
3961
		MPASS(dp->d_reclen >= _GENERIC_DIRLEN(0));
3962
		if (dp->d_namlen > sizeof(dstdp.d_name) - 1)
3963
			continue;
3964
		dstdp.d_type = dp->d_type;
3965
		dstdp.d_namlen = dp->d_namlen;
3966
		dstdp.d_fileno = dp->d_fileno;		/* truncate */
3967
		dstdp.d_reclen = sizeof(dstdp) - sizeof(dstdp.d_name) +
3968
		    ((dp->d_namlen + 1 + 3) &~ 3);
3969
		bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);
3970
		bzero(dstdp.d_name + dstdp.d_namlen,
3971
		    dstdp.d_reclen - offsetof(struct freebsd11_dirent, d_name) -
3972
		    dstdp.d_namlen);
3973
		MPASS(dstdp.d_reclen <= dp->d_reclen);
3974
		MPASS(ucount + dstdp.d_reclen <= count);
3975
		if (func != NULL)
3976
			func(&dstdp);
3977
		error = copyout(&dstdp, ubuf + ucount, dstdp.d_reclen);
3978
		if (error != 0)
3979
			break;
3980
		dp = (struct dirent *)((char *)dp + dp->d_reclen);
3981
		ucount += dstdp.d_reclen;
3982
	}
3983
3984
done:
3985
	free(dirbuf, M_TEMP);
3986
	if (error == 0)
3987
		td->td_retval[0] = ucount;
3988
	return (error);
3989
}
3990
#endif /* COMPAT */
3991
3754
#ifdef COMPAT_43
3992
#ifdef COMPAT_43
3993
static void
3994
ogetdirentries_cvt(struct freebsd11_dirent *dp)
3995
{
3996
#if (BYTE_ORDER == LITTLE_ENDIAN)
3997
	/*
3998
	 * The expected low byte of dp->d_namlen is our dp->d_type.
3999
	 * The high MBZ byte of dp->d_namlen is our dp->d_namlen.
4000
	 */
4001
	dp->d_type = dp->d_namlen;
4002
	dp->d_namlen = 0;
4003
#else
4004
	/*
4005
	 * The dp->d_type is the high byte of the expected dp->d_namlen,
4006
	 * so must be zero'ed.
4007
	 */
4008
	dp->d_type = 0;
4009
#endif
4010
}
4011
3755
/*
4012
/*
3756
 * Read a block of directory entries in a filesystem independent format.
4013
 * Read a block of directory entries in a filesystem independent format.
3757
 */
4014
 */
Lines 3779-3916 int Link Here
3779
kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
4036
kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
3780
    long *ploff)
4037
    long *ploff)
3781
{
4038
{
3782
	struct vnode *vp;
4039
	long base;
3783
	struct file *fp;
4040
	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
4041
3793
	/* XXX arbitrary sanity limit on `count'. */
4042
	/* XXX arbitrary sanity limit on `count'. */
3794
	if (uap->count > 64 * 1024)
4043
	if (uap->count > 64 * 1024)
3795
		return (EINVAL);
4044
		return (EINVAL);
3796
	error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
4045
3797
	if (error != 0)
4046
	error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
3798
		return (error);
4047
	    &base, ogetdirentries_cvt);
3799
	if ((fp->f_flag & FREAD) == 0) {
4048
3800
		fdrop(fp, td);
4049
	if (error == 0 && uap->basep != NULL)
3801
		return (EBADF);
4050
		error = copyout(&base, uap->basep, sizeof(long));
3802
	}
4051
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);
4052
	return (error);
3906
}
4053
}
3907
#endif /* COMPAT_43 */
4054
#endif /* COMPAT_43 */
3908
4055
3909
/*
4056
#if defined(COMPAT_FREEBSD11)
3910
 * Read a block of directory entries in a filesystem independent format.
3911
 */
3912
#ifndef _SYS_SYSPROTO_H_
4057
#ifndef _SYS_SYSPROTO_H_
3913
struct getdirentries_args {
4058
struct freebsd11_getdirentries_args {
3914
	int	fd;
4059
	int	fd;
3915
	char	*buf;
4060
	char	*buf;
3916
	u_int	count;
4061
	u_int	count;
Lines 3918-3954 struct getdirentries_args { Link Here
3918
};
4063
};
3919
#endif
4064
#endif
3920
int
4065
int
3921
sys_getdirentries(td, uap)
4066
freebsd11_getdirentries(struct thread *td,
3922
	struct thread *td;
4067
    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
{
4068
{
3930
	long base;
4069
	long base;
3931
	int error;
4070
	int error;
3932
4071
4072
	error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
4073
	    &base, NULL);
4074
4075
	if (error == 0 && uap->basep != NULL)
4076
		error = copyout(&base, uap->basep, sizeof(long));
4077
	return (error);
4078
}
4079
4080
int
4081
freebsd11_getdents(struct thread *td, struct freebsd11_getdents_args *uap)
4082
{
4083
	struct freebsd11_getdirentries_args ap;
4084
4085
	ap.fd = uap->fd;
4086
	ap.buf = uap->buf;
4087
	ap.count = uap->count;
4088
	ap.basep = NULL;
4089
	return (freebsd11_getdirentries(td, &ap));
4090
}
4091
#endif /* COMPAT_FREEBSD11 */
4092
4093
/*
4094
 * Read a block of directory entries in a filesystem independent format.
4095
 */
4096
int
4097
sys_getdirentries(struct thread *td, struct getdirentries_args *uap)
4098
{
4099
	off_t base;
4100
	int error;
4101
3933
	error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
4102
	error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
3934
	    NULL, UIO_USERSPACE);
4103
	    NULL, UIO_USERSPACE);
3935
	if (error != 0)
4104
	if (error != 0)
3936
		return (error);
4105
		return (error);
3937
	if (uap->basep != NULL)
4106
	if (uap->basep != NULL)
3938
		error = copyout(&base, uap->basep, sizeof(long));
4107
		error = copyout(&base, uap->basep, sizeof(off_t));
3939
	return (error);
4108
	return (error);
3940
}
4109
}
3941
4110
3942
int
4111
int
3943
kern_getdirentries(struct thread *td, int fd, char *buf, u_int count,
4112
kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
3944
    long *basep, ssize_t *residp, enum uio_seg bufseg)
4113
    off_t *basep, ssize_t *residp, enum uio_seg bufseg)
3945
{
4114
{
3946
	struct vnode *vp;
4115
	struct vnode *vp;
3947
	struct file *fp;
4116
	struct file *fp;
3948
	struct uio auio;
4117
	struct uio auio;
3949
	struct iovec aiov;
4118
	struct iovec aiov;
3950
	cap_rights_t rights;
4119
	cap_rights_t rights;
3951
	long loff;
4120
	off_t loff;
3952
	int error, eofflag;
4121
	int error, eofflag;
3953
	off_t foffset;
4122
	off_t foffset;
3954
4123
Lines 4015-4045 fail: Link Here
4015
	return (error);
4184
	return (error);
4016
}
4185
}
4017
4186
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
/*
4187
/*
4044
 * Set the mode mask for creation of filesystem nodes.
4188
 * Set the mode mask for creation of filesystem nodes.
4045
 */
4189
 */
(-)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 a 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 / +36 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
struct stat {
155
	dev_t     st_dev;		/* inode's device */
156
	ino_t	  st_ino;		/* inode's number */
157
	nlink_t	  st_nlink;		/* number of hard links */
158
	mode_t	  st_mode;		/* inode protection mode */
159
	__int16_t st_padding0;
160
	uid_t	  st_uid;		/* user ID of the file's owner */
161
	gid_t	  st_gid;		/* group ID of the file's group */
162
	__int32_t st_padding1;
163
	dev_t     st_rdev;		/* device type */
164
	struct	timespec st_atim;	/* time of last access */
165
	struct	timespec st_mtim;	/* time of last data modification */
166
	struct	timespec st_ctim;	/* time of last file status change */
167
	struct	timespec st_birthtim;	/* time of file creation */
168
	off_t	  st_size;		/* file size, in bytes */
169
	blkcnt_t st_blocks;		/* blocks allocated for file */
170
	blksize_t st_blksize;		/* optimal blocksize for I/O */
171
	fflags_t  st_flags;		/* user defined flags for file */
172
	__uint64_t st_gen;		/* file generation number */
173
	__uint64_t st_spare[10];
174
};
151
175
152
#ifdef _KERNEL
176
#ifdef _KERNEL
153
struct nstat {
177
struct nstat {
154
	__dev_t   st_dev;		/* inode's device */
178
	__uint32_t st_dev;		/* inode's device */
155
	ino_t	  st_ino;		/* inode's number */
179
	__uint32_t st_ino;		/* inode's number */
156
	__uint32_t st_mode;		/* inode protection mode */
180
	__uint32_t st_mode;		/* inode protection mode */
157
	__uint32_t st_nlink;		/* number of hard links */
181
	__uint32_t st_nlink;		/* number of hard links */
158
	uid_t	  st_uid;		/* user ID of the file's owner */
182
	uid_t	  st_uid;		/* user ID of the file's owner */
159
	gid_t	  st_gid;		/* group ID of the file's group */
183
	gid_t	  st_gid;		/* group ID of the file's group */
160
	__dev_t   st_rdev;		/* device type */
184
	__uint32_t st_rdev;		/* device type */
161
	struct	timespec st_atim;	/* time of last access */
185
	struct	timespec st_atim;	/* time of last access */
162
	struct	timespec st_mtim;	/* time of last data modification */
186
	struct	timespec st_mtim;	/* time of last data modification */
163
	struct	timespec st_ctim;	/* time of last file status change */
187
	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 */
192
	__uint32_t st_gen;		/* file generation number */
169
	struct timespec st_birthtim;	/* time of file creation */
193
	struct timespec st_birthtim;	/* time of file creation */
170
	/*
194
	/*
171
	 * See above about the following padding.
195
	 * See comment in the definition of struct freebsd11_stat
196
	 * above about the following padding.
172
	 */
197
	 */
173
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
198
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
174
	unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec));
199
	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 290-293 int kern_socketpair(struct thread *td, int domain, int type, int protocol, Link Here
290
#define	KSA_OSIGSET	0x0001	/* uses osigact_t */
290
#define	KSA_OSIGSET	0x0001	/* uses osigact_t */
291
#define	KSA_FREEBSD4	0x0002	/* uses ucontext4 */
291
#define	KSA_FREEBSD4	0x0002	/* uses ucontext4 */
292
292
293
struct freebsd11_dirent;
294
295
int	freebsd11_kern_getdirentries(struct thread *td, int fd, char *ubuf, u_int
296
	    count, long *basep, void (*func)(struct freebsd11_dirent *));
297
293
#endif /* !_SYS_SYSCALLSUBR_H_ */
298
#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 584-589 struct file; Link Here
584
struct mount;
585
struct mount;
585
struct nameidata;
586
struct nameidata;
586
struct ostat;
587
struct ostat;
588
struct freebsd11_stat;
587
struct thread;
589
struct thread;
588
struct proc;
590
struct proc;
589
struct stat;
591
struct stat;
Lines 612-618 void cache_purge_negative(struct vnode *vp); Link Here
612
void	cache_purgevfs(struct mount *mp, bool force);
614
void	cache_purgevfs(struct mount *mp, bool force);
613
int	change_dir(struct vnode *vp, struct thread *td);
615
int	change_dir(struct vnode *vp, struct thread *td);
614
void	cvtstat(struct stat *st, struct ostat *ost);
616
void	cvtstat(struct stat *st, struct ostat *ost);
615
void	cvtnstat(struct stat *sb, struct nstat *nsb);
617
void	freebsd11_cvtnstat(struct stat *sb, struct nstat *nsb);
618
void	freebsd11_cvtstat(struct stat *st, struct freebsd11_stat *ost);
616
int	getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
619
int	getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
617
	    struct vnode **vpp);
620
	    struct vnode **vpp);
618
void	getnewvnode_reserve(u_int count);
621
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 (+98 lines)
Added Link Here
1
This note explains how to perform useful testing of the ino64 branch,
2
beyond usual checks.
3
4
1. Overview.
5
The ino64 branch extends the basic system types ino_t, dev_t from
6
32bit to 64bit, and nlink_t from 16bit to 64bit.  The struct dirent is
7
modified, besides expected layout change due to ino_t, also get d_off
8
members.  Since we are taking the ABI breakage, struct statfs
9
f_mntfromname[] and f_mntonname[] arrays length MNAMELEN is increased
10
from 88 to 1024, which should allow longer mount path names.
11
12
The work is done to mitigate the ABI breakage, by providing
13
compatibility utilizing symbol version, ingenious use of the existing
14
padding in structures, and by employing other tricks.  Unfortunately,
15
not everything can be fixed, especially oustide the base system.  For
16
instance, third-party APIs which pass struct stat around are broken in
17
backward and forward-incompatible way.
18
19
2. Motivation.
20
21
The main risk of the ino64 change is the uncontrolled ABI breakage.
22
Due to expansion of the basic types dev_t, ino_t and struct dirent,
23
the impact is not limited to one part of the system, but affects:
24
- kernel/userspace interface (syscalls ABI, mostly stat(2), kinfo
25
  and more)
26
- libc interface (mostly related to the readdir(3), FTS(3))
27
- collateral damage in other libraries that happens to use changed types
28
  in the interfaces.  See, for instance, libprocstat, for which compat
29
  was provided using symbol versioning, and libutil, which shlib version
30
  was bumped.
31
32
3. Quirks.
33
34
We handled kinfo sysctl MIBs, but other MIBs which report structures
35
depended on the changed type, are not handled in general.  It was
36
considered that the breakage is either in the management interfaces,
37
where we usually allow ABI slip, or is not important.
38
39
Struct xvnode changed layout, no compat shims are provided.
40
41
For struct xtty, dev_t tty device member was reduced to uint32_t.  It
42
was decided that keeping ABI compat in this case is more useful than
43
reporting 64bit dev_t, for the sake of pstat.
44
45
4. Testing procedure.
46
47
4.1 New kernel, old world.
48
Build and install pristine HEAD world, apply patch and only build and
49
install updated kernel. The system must work same as with the pristine
50
kernel.
51
52
4.2 New kernel, new world, old third-party applications.
53
Build and install patched kernel and world.  Applications compiled on the
54
pristine HEAD (e.g. installed by pkg from the regular portmgr builds) must
55
work without a regression.
56
57
4.3 32bit compat.
58
Same as 4.1 and 4.2, but for 32bit (i386) binaries on the amd64 host.
59
Note that big-endian host, like powerpc, might expose additional
60
bugs in the 32bit compat with the patch, but the testing is too cumbersome
61
to arrange.
62
63
4.4 Targeted tests.
64
Useful programs to check items 4.1, 4.2 and 4.3 are versions of the
65
following programs, taken from the pristine system:
66
67
  stat(8). Use it on regular file, file in /dev, socket, pipe and so
68
  on. For both native and 32bit compat, stat(8) must print reasonable
69
  information.
70
71
  procstat(1). Use it with the -f option to examine processes files.
72
  kinfo(9) data must be returned in the format acceptable for older
73
  apps.
74
75
  Use pristine find(1) binary with many arbitrary options on a system with
76
  installed patched world, in particular, libc. Find examines FTS(3),
77
  and compat shims in libc are non-trivial.
78
79
4.5 NFS server and client test.
80
Check that the NFS server in the patched kernel operates correctly and without
81
performance regressions.  Same for client.
82
NFS should be checked for all four combination of patched/unpatched
83
kernel server/client, because the filehandle format includes inode number.
84
85
4.6 Other filesystems
86
Generally, filesystems should see no change in the system behaviour,
87
since patch goal is to provide space to grow in the ABI.  In
88
particular, local filesystem layout must stay same.  Of course, it is
89
possible that some reliance on the exact sizes of the changed types
90
was left unnoticed during the patch review, in which case e.g. on-disk
91
format would be broken.  We do not expect this to slip in, but it is
92
possible and should be watched for.
93
94
4.7 Test accounting
95
The process accounting, as documented in acct(5), changed format of
96
the records due to dev_t increase.  Verify that the programs like
97
sa(8) and accton(8) correctly work with both old and new accounting
98
records.
(-)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