1*ace5b9b5Schristos /* $NetBSD: compat_getfh.c,v 1.7 2024/01/20 14:52:46 christos Exp $ */
2688ce05cSmartin
3688ce05cSmartin /*-
4b4cb63a6Smartin * Copyright (c) 2006 The NetBSD Foundation, Inc.
5688ce05cSmartin * All rights reserved.
6688ce05cSmartin *
7688ce05cSmartin * This code is derived from software contributed to The NetBSD Foundation
8688ce05cSmartin * by Martin Husemann <martin@NetBSD.org>.
9688ce05cSmartin *
10688ce05cSmartin * Redistribution and use in source and binary forms, with or without
11688ce05cSmartin * modification, are permitted provided that the following conditions
12688ce05cSmartin * are met:
13688ce05cSmartin * 1. Redistributions of source code must retain the above copyright
14688ce05cSmartin * notice, this list of conditions and the following disclaimer.
15688ce05cSmartin * 2. Redistributions in binary form must reproduce the above copyright
16688ce05cSmartin * notice, this list of conditions and the following disclaimer in the
17688ce05cSmartin * documentation and/or other materials provided with the distribution.
18688ce05cSmartin *
19688ce05cSmartin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20688ce05cSmartin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21688ce05cSmartin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22688ce05cSmartin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23688ce05cSmartin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24688ce05cSmartin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25688ce05cSmartin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26688ce05cSmartin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27688ce05cSmartin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28688ce05cSmartin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29688ce05cSmartin * POSSIBILITY OF SUCH DAMAGE.
30688ce05cSmartin */
31688ce05cSmartin
32688ce05cSmartin
33688ce05cSmartin #include <sys/cdefs.h>
34688ce05cSmartin #if defined(LIBC_SCCS) && !defined(lint)
35*ace5b9b5Schristos __RCSID("$NetBSD: compat_getfh.c,v 1.7 2024/01/20 14:52:46 christos Exp $");
36688ce05cSmartin #endif /* LIBC_SCCS and not lint */
37688ce05cSmartin
38688ce05cSmartin #define __LIBC12_SOURCE__
39688ce05cSmartin
40688ce05cSmartin #include <sys/types.h>
41688ce05cSmartin #include <sys/mount.h>
42*ace5b9b5Schristos #include <compat/sys/mount.h>
43b4cb63a6Smartin #include <compat/include/fstypes.h>
44688ce05cSmartin
456e8d813fSyamt #include <errno.h>
466e8d813fSyamt
47688ce05cSmartin __warn_references(getfh,
48688ce05cSmartin "warning: reference to compatibility getfh(); include <sys/mount.h> to generate correct reference")
49688ce05cSmartin
50688ce05cSmartin
51688ce05cSmartin /*
52688ce05cSmartin * Convert old getfh() call to new calling convention
53688ce05cSmartin */
54688ce05cSmartin int
getfh(const char * path,struct compat_30_fhandle * fhp)55688ce05cSmartin getfh(const char *path, struct compat_30_fhandle *fhp)
56688ce05cSmartin {
57688ce05cSmartin size_t fh_size = sizeof(*fhp);
586e8d813fSyamt int ret;
59688ce05cSmartin
606e8d813fSyamt ret = __getfh30(path, (void*)fhp, &fh_size);
616e8d813fSyamt if (ret != 0) {
626e8d813fSyamt return ret;
636e8d813fSyamt }
646e8d813fSyamt if (fh_size != FHANDLE30_SIZE) {
656e8d813fSyamt errno = EINVAL;
666e8d813fSyamt return -1;
676e8d813fSyamt }
686e8d813fSyamt return 0;
69688ce05cSmartin }
70