xref: /minix3/lib/libc/compat/sys/compat___stat30.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: compat___stat30.c,v 1.4 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___stat30.c,v 1.4 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(__stat30,
502fe8fb19SBen Gras     "warning: reference to compatibility __stat30(); include <sys/stat.h> to generate correct reference")
512fe8fb19SBen Gras 
522fe8fb19SBen Gras __warn_references(__fstat30,
532fe8fb19SBen Gras     "warning: reference to compatibility __fstat30(); include <sys/stat.h> to generate correct reference")
542fe8fb19SBen Gras 
552fe8fb19SBen Gras __warn_references(__lstat30,
562fe8fb19SBen Gras     "warning: reference to compatibility __lstat30(); include <sys/stat.h> to generate correct reference")
572fe8fb19SBen Gras 
582fe8fb19SBen Gras __warn_references(__fhstat40,
592fe8fb19SBen Gras     "warning: reference to compatibility __fhstat40(); include <sys/mount.h> to generate correct reference")
602fe8fb19SBen Gras 
612fe8fb19SBen Gras 
62*84d9c625SLionel Sambuc __strong_alias(__stat30, __compat___stat30)
63*84d9c625SLionel Sambuc __strong_alias(__fstat30, __compat___fstat30)
64*84d9c625SLionel Sambuc __strong_alias(__lstat30, __compat___lstat30)
65*84d9c625SLionel Sambuc __strong_alias(__fhstat40, __compat___fhstat40)
66*84d9c625SLionel Sambuc 
672fe8fb19SBen Gras /*
682fe8fb19SBen Gras  * Convert from a new to an old stat structure.
692fe8fb19SBen Gras  */
702fe8fb19SBen Gras 
712fe8fb19SBen Gras static void cvtstat(struct stat30 *, const struct stat *);
722fe8fb19SBen Gras 
732fe8fb19SBen Gras static void
cvtstat(struct stat30 * ost,const struct stat * st)742fe8fb19SBen Gras cvtstat(struct stat30 *ost, const struct stat *st)
752fe8fb19SBen Gras {
762fe8fb19SBen Gras 
772fe8fb19SBen Gras 	ost->st_dev = (uint32_t)st->st_dev;
782fe8fb19SBen Gras 	ost->st_ino = st->st_ino;
792fe8fb19SBen Gras 	ost->st_mode = st->st_mode;
802fe8fb19SBen Gras 	ost->st_nlink = st->st_nlink;
812fe8fb19SBen Gras 	ost->st_uid = st->st_uid;
822fe8fb19SBen Gras 	ost->st_gid = st->st_gid;
832fe8fb19SBen Gras 	ost->st_rdev = (uint32_t)st->st_rdev;
842fe8fb19SBen Gras 	timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
852fe8fb19SBen Gras 	timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
862fe8fb19SBen Gras 	timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
872fe8fb19SBen Gras 	timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
882fe8fb19SBen Gras 	ost->st_size = st->st_size;
892fe8fb19SBen Gras 	ost->st_blocks = st->st_blocks;
902fe8fb19SBen Gras 	ost->st_blksize = st->st_blksize;
912fe8fb19SBen Gras 	ost->st_flags = st->st_flags;
922fe8fb19SBen Gras 	ost->st_gen = st->st_gen;
932fe8fb19SBen Gras }
942fe8fb19SBen Gras 
952fe8fb19SBen Gras int
__compat___stat30(const char * file,struct stat30 * ost)96*84d9c625SLionel Sambuc __compat___stat30(const char *file, struct stat30 *ost)
972fe8fb19SBen Gras {
982fe8fb19SBen Gras 	struct stat nst;
992fe8fb19SBen Gras 	int ret;
1002fe8fb19SBen Gras 
1012fe8fb19SBen Gras 	if ((ret = __stat50(file, &nst)) == -1)
1022fe8fb19SBen Gras 		return ret;
1032fe8fb19SBen Gras 	cvtstat(ost, &nst);
1042fe8fb19SBen Gras 	return ret;
1052fe8fb19SBen Gras }
1062fe8fb19SBen Gras 
1072fe8fb19SBen Gras int
__compat___fstat30(int f,struct stat30 * ost)108*84d9c625SLionel Sambuc __compat___fstat30(int f, struct stat30 *ost)
1092fe8fb19SBen Gras {
1102fe8fb19SBen Gras 	struct stat nst;
1112fe8fb19SBen Gras 	int ret;
1122fe8fb19SBen Gras 
1132fe8fb19SBen Gras 	if ((ret = __fstat50(f, &nst)) == -1)
1142fe8fb19SBen Gras 		return ret;
1152fe8fb19SBen Gras 	cvtstat(ost, &nst);
1162fe8fb19SBen Gras 	return ret;
1172fe8fb19SBen Gras }
1182fe8fb19SBen Gras 
1192fe8fb19SBen Gras int
__compat___lstat30(const char * file,struct stat30 * ost)120*84d9c625SLionel Sambuc __compat___lstat30(const char *file, struct stat30 *ost)
1212fe8fb19SBen Gras {
1222fe8fb19SBen Gras 	struct stat nst;
1232fe8fb19SBen Gras 	int ret;
1242fe8fb19SBen Gras 
1252fe8fb19SBen Gras 	if ((ret = __lstat50(file, &nst)) == -1)
1262fe8fb19SBen Gras 		return ret;
1272fe8fb19SBen Gras 	cvtstat(ost, &nst);
1282fe8fb19SBen Gras 	return ret;
1292fe8fb19SBen Gras }
1302fe8fb19SBen Gras 
1312fe8fb19SBen Gras int
__compat___fhstat40(const void * fh,size_t fh_size,struct stat30 * ost)132*84d9c625SLionel Sambuc __compat___fhstat40(const void *fh, size_t fh_size, struct stat30 *ost)
1332fe8fb19SBen Gras {
1342fe8fb19SBen Gras 	struct stat nst;
1352fe8fb19SBen Gras 	int ret;
1362fe8fb19SBen Gras 
1372fe8fb19SBen Gras 	if ((ret = __fhstat50(fh, fh_size, &nst)) == -1)
1382fe8fb19SBen Gras 		return ret;
1392fe8fb19SBen Gras 	cvtstat(ost, &nst);
1402fe8fb19SBen Gras 	return ret;
1412fe8fb19SBen Gras }
142