xref: /freebsd-14-stable/lib/libc/sys/compat-ino64.h (revision f9afcbff02a230af85e646ef3ae166ae61b04ca1)
1 /*-
2  * Copyright (c) 2017 M. Warner Losh <imp@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 /*
27  * Forward compatibility shim to convert old stat buffer to
28  * new so we can call the old system call, but return data in
29  * the new system call's format.
30  */
31 #define _WANT_FREEBSD11_STATFS
32 #include <sys/fcntl.h>
33 #include <sys/mount.h>
34 
35 #define _WANT_FREEBSD11_STAT
36 #include <sys/stat.h>
37 
38 #include <string.h>
39 
40 #define INO64_FIRST 1200031
41 
42 static __inline void
__stat11_to_stat(const struct freebsd11_stat * sb11,struct stat * sb)43 __stat11_to_stat(const struct freebsd11_stat *sb11, struct stat *sb)
44 {
45 
46 	sb->st_dev = sb11->st_dev;
47 	sb->st_ino = sb11->st_ino;
48 	sb->st_nlink = sb11->st_nlink;
49 	sb->st_mode = sb11->st_mode;
50 	sb->st_uid = sb11->st_uid;
51 	sb->st_gid = sb11->st_gid;
52 	sb->st_rdev = sb11->st_rdev;
53 	sb->st_atim = sb11->st_atim;
54 	sb->st_mtim = sb11->st_mtim;
55 	sb->st_ctim = sb11->st_ctim;
56 #ifdef __STAT_TIME_T_EXT
57 	sb->st_atim_ext = 0;
58 	sb->st_mtim_ext = 0;
59 	sb->st_ctim_ext = 0;
60 	sb->st_btim_ext = 0;
61 #endif
62 	sb->st_birthtim = sb11->st_birthtim;
63 	sb->st_size = sb11->st_size;
64 	sb->st_blocks = sb11->st_blocks;
65 	sb->st_blksize = sb11->st_blksize;
66 	sb->st_flags = sb11->st_flags;
67 	sb->st_gen = sb11->st_gen;
68 	sb->st_bsdflags = 0;
69 	sb->st_padding1 = 0;
70 	memset(sb->st_spare, 0, sizeof(sb->st_spare));
71 }
72 
73 static __inline void
__statfs11_to_statfs(const struct freebsd11_statfs * sf11,struct statfs * sf)74 __statfs11_to_statfs(const struct freebsd11_statfs *sf11, struct statfs *sf)
75 {
76 
77 	sf->f_version = STATFS_VERSION;
78 	sf->f_type = sf11->f_type;
79 	sf->f_flags = sf11->f_flags;
80 	sf->f_bsize = sf11->f_bsize;
81 	sf->f_iosize = sf11->f_iosize;
82 	sf->f_blocks = sf11->f_blocks;
83 	sf->f_bfree = sf11->f_bfree;
84 	sf->f_bavail = sf11->f_bavail;
85 	sf->f_files = sf11->f_files;
86 	sf->f_ffree = sf11->f_ffree;
87 	sf->f_syncwrites = sf11->f_syncwrites;
88 	sf->f_asyncwrites = sf11->f_asyncwrites;
89 	sf->f_syncreads = sf11->f_syncreads;
90 	sf->f_asyncreads = sf11->f_asyncreads;
91 	sf->f_namemax = sf11->f_namemax;
92 	sf->f_owner = sf11->f_owner;
93 	sf->f_fsid = sf11->f_fsid;
94 	memset(sf->f_spare, 0, sizeof(sf->f_spare));
95 	memset(sf->f_charspare, 0, sizeof(sf->f_charspare));
96 	strlcpy(sf->f_fstypename, sf11->f_fstypename, sizeof(sf->f_fstypename));
97 	strlcpy(sf->f_mntfromname, sf11->f_mntfromname, sizeof(sf->f_mntfromname));
98 	strlcpy(sf->f_mntonname, sf11->f_mntonname, sizeof(sf->f_mntonname));
99 }
100