xref: /freebsd/lib/libc/gen/gen-compat.h (revision e194103bd35d9e08a5d271d814d6184ec159eadf)
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 #ifndef	_GEN_COMPAT_H_
28 #define	_GEN_COMPAT_H_
29 
30 #include <dirent.h>
31 
32 #define FREEBSD11_DIRSIZ(dp)						\
33 	(sizeof(struct freebsd11_dirent) - sizeof((dp)->d_name) +	\
34 	    (((dp)->d_namlen + 1 + 3) &~ 3))
35 
36 struct freebsd11_dirent;
37 struct freebsd11_stat;
38 struct freebsd11_statfs;
39 
40 struct freebsd11_dirent *freebsd11_readdir(DIR *);
41 int	freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
42 	    struct freebsd11_dirent **);
43 
44 int	freebsd11_getmntinfo(struct freebsd11_statfs **, int);
45 
46 char	*freebsd11_devname(__uint32_t dev, __mode_t type);
47 char	*freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf,
48 	    int len);
49 
50 /*
51  * We want freebsd11_fstat in C source to result in resolution to
52  * - fstat@FBSD_1.0 for libc.so (but we do not need the _definition_
53  *   of this fstat, it is provided by libsys.so which we want to use).
54  * - freebsd11_fstat for libc.a (since if we make it fstat@FBSD_1.0
55  *   for libc.a, then final linkage into static object ignores version
56  *   and would reference fstat, which is the current syscall, not the
57  *   compat syscall). libc.a provides the freebsd11_fstat implementation.
58  *   Note that freebsd11_fstat from libc.a is not used for anything, but
59  *   we make it correct nonetheless, just in case it would.
60  * This is arranged by COMPAT_SYSCALL, and libc can just use freebsd11_fstat.
61  */
62 #ifdef PIC
63 #define	COMPAT_SYSCALL(rtype, fun, args, sym, ver)			\
64     rtype fun args; __sym_compat(sym, fun, ver);
65 #else
66 #define	COMPAT_SYSCALL(rtype, fun, args, sym, ver)			\
67     rtype fun args;
68 #endif
69 
70 COMPAT_SYSCALL(int, freebsd11_stat, (const char *, struct freebsd11_stat *),
71     stat, FBSD_1.0);
72 COMPAT_SYSCALL(int, freebsd11_lstat, (const char *, struct freebsd11_stat *),
73     lstat, FBSD_1.0);
74 COMPAT_SYSCALL(int, freebsd11_fstat, (int, struct freebsd11_stat *),
75     fstat, FBSD_1.0);
76 COMPAT_SYSCALL(int, freebsd11_fstatat, (int, const char *,
77     struct freebsd11_stat *, int), fstatat, FBSD_1.1);
78 
79 COMPAT_SYSCALL(int, freebsd11_statfs, (const char *,
80     struct freebsd11_statfs *), statfs, FBSD_1.0);
81 COMPAT_SYSCALL(int, freebsd11_getfsstat, (struct freebsd11_statfs *, long,
82     int), getfsstat, FBSD_1.0);
83 
84 COMPAT_SYSCALL(int, freebsd14_setgroups, (int gidsize, const __gid_t *gidset),
85     setgroups, FBSD_1.0);
86 
87 #undef COMPAT_SYSCALL
88 
89 #endif /* _GEN_COMPAT_H_ */
90