1*fda5f877Schristos /* $NetBSD: compat___stat30.c,v 1.4 2013/10/04 21:07:37 christos Exp $ */
2461a86f9Schristos
3461a86f9Schristos /*
4461a86f9Schristos * Copyright (c) 1997 Frank van der Linden
5461a86f9Schristos * All rights reserved.
6461a86f9Schristos *
7461a86f9Schristos * Redistribution and use in source and binary forms, with or without
8461a86f9Schristos * modification, are permitted provided that the following conditions
9461a86f9Schristos * are met:
10461a86f9Schristos * 1. Redistributions of source code must retain the above copyright
11461a86f9Schristos * notice, this list of conditions and the following disclaimer.
12461a86f9Schristos * 2. Redistributions in binary form must reproduce the above copyright
13461a86f9Schristos * notice, this list of conditions and the following disclaimer in the
14461a86f9Schristos * documentation and/or other materials provided with the distribution.
15461a86f9Schristos * 3. All advertising materials mentioning features or use of this software
16461a86f9Schristos * must display the following acknowledgement:
17461a86f9Schristos * This product includes software developed for the NetBSD Project
18461a86f9Schristos * by Frank van der Linden
19461a86f9Schristos * 4. The name of the author may not be used to endorse or promote products
20461a86f9Schristos * derived from this software without specific prior written permission
21461a86f9Schristos *
22461a86f9Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23461a86f9Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24461a86f9Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25461a86f9Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26461a86f9Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27461a86f9Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28461a86f9Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29461a86f9Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30461a86f9Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31461a86f9Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32461a86f9Schristos */
33461a86f9Schristos
34461a86f9Schristos #include <sys/cdefs.h>
35461a86f9Schristos #if defined(LIBC_SCCS) && !defined(lint)
36*fda5f877Schristos __RCSID("$NetBSD: compat___stat30.c,v 1.4 2013/10/04 21:07:37 christos Exp $");
37461a86f9Schristos #endif /* LIBC_SCCS and not lint */
38461a86f9Schristos
39461a86f9Schristos #define __LIBC12_SOURCE__
40461a86f9Schristos
41461a86f9Schristos #include <sys/types.h>
42461a86f9Schristos #include <sys/param.h>
43461a86f9Schristos #include <sys/stat.h>
44461a86f9Schristos #include <sys/mount.h>
45461a86f9Schristos #include <compat/sys/time.h>
46461a86f9Schristos #include <compat/sys/stat.h>
47461a86f9Schristos #include <compat/sys/mount.h>
48461a86f9Schristos
49461a86f9Schristos __warn_references(__stat30,
50461a86f9Schristos "warning: reference to compatibility __stat30(); include <sys/stat.h> to generate correct reference")
51461a86f9Schristos
52461a86f9Schristos __warn_references(__fstat30,
53461a86f9Schristos "warning: reference to compatibility __fstat30(); include <sys/stat.h> to generate correct reference")
54461a86f9Schristos
55461a86f9Schristos __warn_references(__lstat30,
56461a86f9Schristos "warning: reference to compatibility __lstat30(); include <sys/stat.h> to generate correct reference")
57461a86f9Schristos
58461a86f9Schristos __warn_references(__fhstat40,
59461a86f9Schristos "warning: reference to compatibility __fhstat40(); include <sys/mount.h> to generate correct reference")
60461a86f9Schristos
61461a86f9Schristos
62*fda5f877Schristos __strong_alias(__stat30, __compat___stat30)
63*fda5f877Schristos __strong_alias(__fstat30, __compat___fstat30)
64*fda5f877Schristos __strong_alias(__lstat30, __compat___lstat30)
65*fda5f877Schristos __strong_alias(__fhstat40, __compat___fhstat40)
66ca2d95d1Schristos
67461a86f9Schristos /*
68461a86f9Schristos * Convert from a new to an old stat structure.
69461a86f9Schristos */
70461a86f9Schristos
71461a86f9Schristos static void cvtstat(struct stat30 *, const struct stat *);
72461a86f9Schristos
73461a86f9Schristos static void
cvtstat(struct stat30 * ost,const struct stat * st)74461a86f9Schristos cvtstat(struct stat30 *ost, const struct stat *st)
75461a86f9Schristos {
76461a86f9Schristos
77461a86f9Schristos ost->st_dev = (uint32_t)st->st_dev;
78461a86f9Schristos ost->st_ino = st->st_ino;
79461a86f9Schristos ost->st_mode = st->st_mode;
80461a86f9Schristos ost->st_nlink = st->st_nlink;
81461a86f9Schristos ost->st_uid = st->st_uid;
82461a86f9Schristos ost->st_gid = st->st_gid;
83461a86f9Schristos ost->st_rdev = (uint32_t)st->st_rdev;
84461a86f9Schristos timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
85461a86f9Schristos timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
86461a86f9Schristos timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
87461a86f9Schristos timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
88461a86f9Schristos ost->st_size = st->st_size;
89461a86f9Schristos ost->st_blocks = st->st_blocks;
90461a86f9Schristos ost->st_blksize = st->st_blksize;
91461a86f9Schristos ost->st_flags = st->st_flags;
92461a86f9Schristos ost->st_gen = st->st_gen;
93461a86f9Schristos }
94461a86f9Schristos
95461a86f9Schristos int
__compat___stat30(const char * file,struct stat30 * ost)96*fda5f877Schristos __compat___stat30(const char *file, struct stat30 *ost)
97461a86f9Schristos {
98461a86f9Schristos struct stat nst;
99461a86f9Schristos int ret;
100461a86f9Schristos
101461a86f9Schristos if ((ret = __stat50(file, &nst)) == -1)
102461a86f9Schristos return ret;
103461a86f9Schristos cvtstat(ost, &nst);
104461a86f9Schristos return ret;
105461a86f9Schristos }
106461a86f9Schristos
107461a86f9Schristos int
__compat___fstat30(int f,struct stat30 * ost)108*fda5f877Schristos __compat___fstat30(int f, struct stat30 *ost)
109461a86f9Schristos {
110461a86f9Schristos struct stat nst;
111461a86f9Schristos int ret;
112461a86f9Schristos
113461a86f9Schristos if ((ret = __fstat50(f, &nst)) == -1)
114461a86f9Schristos return ret;
115461a86f9Schristos cvtstat(ost, &nst);
116461a86f9Schristos return ret;
117461a86f9Schristos }
118461a86f9Schristos
119461a86f9Schristos int
__compat___lstat30(const char * file,struct stat30 * ost)120*fda5f877Schristos __compat___lstat30(const char *file, struct stat30 *ost)
121461a86f9Schristos {
122461a86f9Schristos struct stat nst;
123461a86f9Schristos int ret;
124461a86f9Schristos
125461a86f9Schristos if ((ret = __lstat50(file, &nst)) == -1)
126461a86f9Schristos return ret;
127461a86f9Schristos cvtstat(ost, &nst);
128461a86f9Schristos return ret;
129461a86f9Schristos }
130461a86f9Schristos
131461a86f9Schristos int
__compat___fhstat40(const void * fh,size_t fh_size,struct stat30 * ost)132*fda5f877Schristos __compat___fhstat40(const void *fh, size_t fh_size, struct stat30 *ost)
133461a86f9Schristos {
134461a86f9Schristos struct stat nst;
135461a86f9Schristos int ret;
136461a86f9Schristos
137461a86f9Schristos if ((ret = __fhstat50(fh, fh_size, &nst)) == -1)
138461a86f9Schristos return ret;
139461a86f9Schristos cvtstat(ost, &nst);
140461a86f9Schristos return ret;
141461a86f9Schristos }
142