xref: /minix3/lib/libc/compat/sys/compat___stat13.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: compat___stat13.c,v 1.6 2013/10/04 21:07:37 christos Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
42fe8fb19SBen Gras  * Copyright (c) 1997 Frank van der Linden
52fe8fb19SBen Gras  * All rights reserved.
62fe8fb19SBen Gras  *
72fe8fb19SBen Gras  * Redistribution and use in source and binary forms, with or without
82fe8fb19SBen Gras  * modification, are permitted provided that the following conditions
92fe8fb19SBen Gras  * are met:
102fe8fb19SBen Gras  * 1. Redistributions of source code must retain the above copyright
112fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer.
122fe8fb19SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
132fe8fb19SBen Gras  *    notice, this list of conditions and the following disclaimer in the
142fe8fb19SBen Gras  *    documentation and/or other materials provided with the distribution.
152fe8fb19SBen Gras  * 3. All advertising materials mentioning features or use of this software
162fe8fb19SBen Gras  *    must display the following acknowledgement:
172fe8fb19SBen Gras  *      This product includes software developed for the NetBSD Project
182fe8fb19SBen Gras  *      by Frank van der Linden
192fe8fb19SBen Gras  * 4. The name of the author may not be used to endorse or promote products
202fe8fb19SBen Gras  *    derived from this software without specific prior written permission
212fe8fb19SBen Gras  *
222fe8fb19SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
232fe8fb19SBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
242fe8fb19SBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
252fe8fb19SBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
262fe8fb19SBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
272fe8fb19SBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
282fe8fb19SBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
292fe8fb19SBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
302fe8fb19SBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
312fe8fb19SBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322fe8fb19SBen Gras  */
332fe8fb19SBen Gras 
342fe8fb19SBen Gras #include <sys/cdefs.h>
352fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
36*84d9c625SLionel Sambuc __RCSID("$NetBSD: compat___stat13.c,v 1.6 2013/10/04 21:07:37 christos Exp $");
372fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
382fe8fb19SBen Gras 
392fe8fb19SBen Gras #define __LIBC12_SOURCE__
402fe8fb19SBen Gras 
412fe8fb19SBen Gras #include <sys/types.h>
422fe8fb19SBen Gras #include <sys/param.h>
432fe8fb19SBen Gras #include <sys/stat.h>
442fe8fb19SBen Gras #include <sys/mount.h>
452fe8fb19SBen Gras #include <compat/sys/time.h>
462fe8fb19SBen Gras #include <compat/sys/stat.h>
472fe8fb19SBen Gras #include <compat/sys/mount.h>
482fe8fb19SBen Gras 
492fe8fb19SBen Gras __warn_references(__stat13,
502fe8fb19SBen Gras     "warning: reference to compatibility __stat13(); include <sys/stat.h> to generate correct reference")
512fe8fb19SBen Gras 
522fe8fb19SBen Gras __warn_references(__fstat13,
532fe8fb19SBen Gras     "warning: reference to compatibility __fstat13(); include <sys/stat.h> to generate correct reference")
542fe8fb19SBen Gras 
552fe8fb19SBen Gras __warn_references(__lstat13,
562fe8fb19SBen Gras     "warning: reference to compatibility __lstat13(); include <sys/stat.h> to generate correct reference")
572fe8fb19SBen Gras 
582fe8fb19SBen Gras __warn_references(fhstat,
592fe8fb19SBen Gras     "warning: reference to compatibility fhstat(); include <sys/mount.h> to generate correct reference")
602fe8fb19SBen Gras 
61*84d9c625SLionel Sambuc __strong_alias(__stat13, __compat___stat13)
62*84d9c625SLionel Sambuc __strong_alias(__fstat13, __compat___fstat13)
63*84d9c625SLionel Sambuc __strong_alias(__lstat13, __compat___lstat13)
64*84d9c625SLionel Sambuc __strong_alias(fhstat, __compat_fhstat)
652fe8fb19SBen Gras 
662fe8fb19SBen Gras /*
672fe8fb19SBen Gras  * Convert from a new to an old stat structure.
682fe8fb19SBen Gras  */
692fe8fb19SBen Gras 
702fe8fb19SBen Gras static void cvtstat(struct stat13 *, const struct stat *);
712fe8fb19SBen Gras 
722fe8fb19SBen Gras static void
cvtstat(struct stat13 * ost,const struct stat * st)732fe8fb19SBen Gras cvtstat(struct stat13 *ost, const struct stat *st)
742fe8fb19SBen Gras {
752fe8fb19SBen Gras 
762fe8fb19SBen Gras 	ost->st_dev = (uint32_t)st->st_dev;
772fe8fb19SBen Gras 	ost->st_ino = (uint32_t)st->st_ino;
782fe8fb19SBen Gras 	ost->st_mode = st->st_mode;
792fe8fb19SBen Gras 	ost->st_nlink = st->st_nlink;
802fe8fb19SBen Gras 	ost->st_uid = st->st_uid;
812fe8fb19SBen Gras 	ost->st_gid = st->st_gid;
822fe8fb19SBen Gras 	ost->st_rdev = (uint32_t)st->st_rdev;
832fe8fb19SBen Gras 	ost->st_atimespec.tv_sec = (int32_t)st->st_atimespec.tv_sec;
842fe8fb19SBen Gras 	ost->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
852fe8fb19SBen Gras 	ost->st_mtimespec.tv_sec = (int32_t)st->st_mtimespec.tv_sec;
862fe8fb19SBen Gras 	ost->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
872fe8fb19SBen Gras 	ost->st_ctimespec.tv_sec = (int32_t)st->st_ctimespec.tv_sec;
882fe8fb19SBen Gras 	ost->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
892fe8fb19SBen Gras 	ost->st_birthtimespec.tv_sec = (int32_t)st->st_birthtimespec.tv_sec;
902fe8fb19SBen Gras 	ost->st_birthtimespec.tv_nsec = st->st_birthtimespec.tv_nsec;
912fe8fb19SBen Gras 	ost->st_size = st->st_size;
922fe8fb19SBen Gras 	ost->st_blocks = st->st_blocks;
932fe8fb19SBen Gras 	ost->st_blksize = st->st_blksize;
942fe8fb19SBen Gras 	ost->st_flags = st->st_flags;
952fe8fb19SBen Gras 	ost->st_gen = st->st_gen;
962fe8fb19SBen Gras }
972fe8fb19SBen Gras 
982fe8fb19SBen Gras int
__compat___stat13(const char * file,struct stat13 * ost)99*84d9c625SLionel Sambuc __compat___stat13(const char *file, struct stat13 *ost)
1002fe8fb19SBen Gras {
1012fe8fb19SBen Gras 	struct stat nst;
1022fe8fb19SBen Gras 	int ret;
1032fe8fb19SBen Gras 
1042fe8fb19SBen Gras 	if ((ret = __stat50(file, &nst)) == -1)
1052fe8fb19SBen Gras 		return ret;
1062fe8fb19SBen Gras 	cvtstat(ost, &nst);
1072fe8fb19SBen Gras 	return ret;
1082fe8fb19SBen Gras }
1092fe8fb19SBen Gras 
1102fe8fb19SBen Gras int
__compat___fstat13(int f,struct stat13 * ost)111*84d9c625SLionel Sambuc __compat___fstat13(int f, struct stat13 *ost)
1122fe8fb19SBen Gras {
1132fe8fb19SBen Gras 	struct stat nst;
1142fe8fb19SBen Gras 	int ret;
1152fe8fb19SBen Gras 
1162fe8fb19SBen Gras 	if ((ret = __fstat50(f, &nst)) == -1)
1172fe8fb19SBen Gras 		return ret;
1182fe8fb19SBen Gras 	cvtstat(ost, &nst);
1192fe8fb19SBen Gras 	return ret;
1202fe8fb19SBen Gras }
1212fe8fb19SBen Gras 
1222fe8fb19SBen Gras int
__compat___lstat13(const char * file,struct stat13 * ost)123*84d9c625SLionel Sambuc __compat___lstat13(const char *file, struct stat13 *ost)
1242fe8fb19SBen Gras {
1252fe8fb19SBen Gras 	struct stat nst;
1262fe8fb19SBen Gras 	int ret;
1272fe8fb19SBen Gras 
1282fe8fb19SBen Gras 	if ((ret = __lstat50(file, &nst)) == -1)
1292fe8fb19SBen Gras 		return ret;
1302fe8fb19SBen Gras 	cvtstat(ost, &nst);
1312fe8fb19SBen Gras 	return ret;
1322fe8fb19SBen Gras }
1332fe8fb19SBen Gras 
1342fe8fb19SBen Gras int
__compat_fhstat(const struct compat_30_fhandle * fh,struct stat13 * ost)135*84d9c625SLionel Sambuc __compat_fhstat(const struct compat_30_fhandle *fh, struct stat13 *ost)
1362fe8fb19SBen Gras {
1372fe8fb19SBen Gras 	struct stat nst;
1382fe8fb19SBen Gras 	int ret;
1392fe8fb19SBen Gras 
1402fe8fb19SBen Gras 	if ((ret = __fhstat50((const void *)fh, /* FHANDLE_SIZE_COMPAT */28, &nst)) == -1)
1412fe8fb19SBen Gras 		return ret;
1422fe8fb19SBen Gras 	cvtstat(ost, &nst);
1432fe8fb19SBen Gras 	return ret;
1442fe8fb19SBen Gras }
145