1 /* Convert between the kernel's `struct stat' format, and libc's.
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
21 #include <kernel_stat.h>
22 #include <kernel-features.h>
24 #ifdef STAT_IS_KERNEL_STAT
34 #ifdef XSTAT_IS_XSTAT64
36 __xstat_conv (int vers
, struct kernel_stat
*kbuf
, void *ubuf
)
40 case _STAT_VER_KERNEL
:
41 /* Nothing to do. The struct is in the form the kernel expects.
42 We should have short-circuted before we got here, but for
44 *(struct kernel_stat
*) ubuf
= *kbuf
;
49 struct stat
*buf
= ubuf
;
51 /* Convert to current kernel version of `struct stat'. */
52 buf
->st_dev
= kbuf
->st_dev
;
53 #ifdef _HAVE_STAT___PAD1
56 buf
->st_ino
= kbuf
->st_ino
;
57 buf
->st_mode
= kbuf
->st_mode
;
58 buf
->st_nlink
= kbuf
->st_nlink
;
59 buf
->st_uid
= kbuf
->st_uid
;
60 buf
->st_gid
= kbuf
->st_gid
;
61 buf
->st_rdev
= kbuf
->st_rdev
;
62 #ifdef _HAVE_STAT___PAD2
65 buf
->st_size
= kbuf
->st_size
;
66 buf
->st_blksize
= kbuf
->st_blksize
;
67 buf
->st_blocks
= kbuf
->st_blocks
;
68 #ifdef _HAVE_STAT_NSEC
69 buf
->st_atim
.tv_sec
= kbuf
->st_atim
.tv_sec
;
70 buf
->st_atim
.tv_nsec
= kbuf
->st_atim
.tv_nsec
;
71 buf
->st_mtim
.tv_sec
= kbuf
->st_mtim
.tv_sec
;
72 buf
->st_mtim
.tv_nsec
= kbuf
->st_mtim
.tv_nsec
;
73 buf
->st_ctim
.tv_sec
= kbuf
->st_ctim
.tv_sec
;
74 buf
->st_ctim
.tv_nsec
= kbuf
->st_ctim
.tv_nsec
;
76 buf
->st_atime
= kbuf
->st_atime
;
77 buf
->st_mtime
= kbuf
->st_mtime
;
78 buf
->st_ctime
= kbuf
->st_ctime
;
80 #ifdef _HAVE_STAT___UNUSED1
81 buf
->__glibc_reserved1
= 0;
83 #ifdef _HAVE_STAT___UNUSED2
84 buf
->__glibc_reserved2
= 0;
86 #ifdef _HAVE_STAT___UNUSED3
87 buf
->__glibc_reserved3
= 0;
89 #ifdef _HAVE_STAT___UNUSED4
90 buf
->__glibc_reserved4
= 0;
92 #ifdef _HAVE_STAT___UNUSED5
93 buf
->__glibc_reserved5
= 0;
99 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL
);
107 __xstat64_conv (int vers
, struct kernel_stat
*kbuf
, void *ubuf
)
109 #ifdef XSTAT_IS_XSTAT64
110 return __xstat_conv (vers
, kbuf
, ubuf
);
114 case _STAT_VER_LINUX
:
116 struct stat64
*buf
= ubuf
;
118 /* Convert to current kernel version of `struct stat64'. */
119 buf
->st_dev
= kbuf
->st_dev
;
120 #ifdef _HAVE_STAT64___PAD1
123 buf
->st_ino
= kbuf
->st_ino
;
124 #ifdef _HAVE_STAT64___ST_INO
125 buf
->__st_ino
= kbuf
->st_ino
;
127 buf
->st_mode
= kbuf
->st_mode
;
128 buf
->st_nlink
= kbuf
->st_nlink
;
129 buf
->st_uid
= kbuf
->st_uid
;
130 buf
->st_gid
= kbuf
->st_gid
;
131 buf
->st_rdev
= kbuf
->st_rdev
;
132 #ifdef _HAVE_STAT64___PAD2
135 buf
->st_size
= kbuf
->st_size
;
136 buf
->st_blksize
= kbuf
->st_blksize
;
137 buf
->st_blocks
= kbuf
->st_blocks
;
138 #ifdef _HAVE_STAT64_NSEC
139 buf
->st_atim
.tv_sec
= kbuf
->st_atim
.tv_sec
;
140 buf
->st_atim
.tv_nsec
= kbuf
->st_atim
.tv_nsec
;
141 buf
->st_mtim
.tv_sec
= kbuf
->st_mtim
.tv_sec
;
142 buf
->st_mtim
.tv_nsec
= kbuf
->st_mtim
.tv_nsec
;
143 buf
->st_ctim
.tv_sec
= kbuf
->st_ctim
.tv_sec
;
144 buf
->st_ctim
.tv_nsec
= kbuf
->st_ctim
.tv_nsec
;
146 buf
->st_atime
= kbuf
->st_atime
;
147 buf
->st_mtime
= kbuf
->st_mtime
;
148 buf
->st_ctime
= kbuf
->st_ctime
;
150 #ifdef _HAVE_STAT64___UNUSED1
151 buf
->__glibc_reserved1
= 0;
153 #ifdef _HAVE_STAT64___UNUSED2
154 buf
->__glibc_reserved2
= 0;
156 #ifdef _HAVE_STAT64___UNUSED3
157 buf
->__glibc_reserved3
= 0;
159 #ifdef _HAVE_STAT64___UNUSED4
160 buf
->__glibc_reserved4
= 0;
162 #ifdef _HAVE_STAT64___UNUSED5
163 buf
->__glibc_reserved5
= 0;
168 /* If struct stat64 is different from struct stat then
169 _STAT_VER_KERNEL does not make sense. */
170 case _STAT_VER_KERNEL
:
172 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL
);
180 __xstat32_conv (int vers
, struct stat64
*kbuf
, struct stat
*buf
)
184 case _STAT_VER_LINUX
:
186 /* Convert current kernel version of `struct stat64' to
188 buf
->st_dev
= kbuf
->st_dev
;
189 #ifdef _HAVE_STAT___PAD1
192 #ifdef _HAVE_STAT64___ST_INO
193 # ifndef __ASSUME_ST_INO_64_BIT
194 if (kbuf
->st_ino
== 0)
195 buf
->st_ino
= kbuf
->__st_ino
;
199 buf
->st_ino
= kbuf
->st_ino
;
200 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
201 && buf
->st_ino
!= kbuf
->st_ino
)
202 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW
);
205 buf
->st_ino
= kbuf
->st_ino
;
206 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
207 && buf
->st_ino
!= kbuf
->st_ino
)
208 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW
);
210 buf
->st_mode
= kbuf
->st_mode
;
211 buf
->st_nlink
= kbuf
->st_nlink
;
212 buf
->st_uid
= kbuf
->st_uid
;
213 buf
->st_gid
= kbuf
->st_gid
;
214 buf
->st_rdev
= kbuf
->st_rdev
;
215 #ifdef _HAVE_STAT___PAD2
218 buf
->st_size
= kbuf
->st_size
;
219 /* Check for overflow. */
220 if (sizeof (buf
->st_size
) != sizeof (kbuf
->st_size
)
221 && buf
->st_size
!= kbuf
->st_size
)
222 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW
);
223 buf
->st_blksize
= kbuf
->st_blksize
;
224 buf
->st_blocks
= kbuf
->st_blocks
;
225 /* Check for overflow. */
226 if (sizeof (buf
->st_blocks
) != sizeof (kbuf
->st_blocks
)
227 && buf
->st_blocks
!= kbuf
->st_blocks
)
228 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW
);
229 #ifdef _HAVE_STAT_NSEC
230 buf
->st_atim
.tv_sec
= kbuf
->st_atim
.tv_sec
;
231 buf
->st_atim
.tv_nsec
= kbuf
->st_atim
.tv_nsec
;
232 buf
->st_mtim
.tv_sec
= kbuf
->st_mtim
.tv_sec
;
233 buf
->st_mtim
.tv_nsec
= kbuf
->st_mtim
.tv_nsec
;
234 buf
->st_ctim
.tv_sec
= kbuf
->st_ctim
.tv_sec
;
235 buf
->st_ctim
.tv_nsec
= kbuf
->st_ctim
.tv_nsec
;
237 buf
->st_atime
= kbuf
->st_atime
;
238 buf
->st_mtime
= kbuf
->st_mtime
;
239 buf
->st_ctime
= kbuf
->st_ctime
;
242 #ifdef _HAVE_STAT___UNUSED1
243 buf
->__glibc_reserved1
= 0;
245 #ifdef _HAVE_STAT___UNUSED2
246 buf
->__glibc_reserved2
= 0;
248 #ifdef _HAVE_STAT___UNUSED3
249 buf
->__glibc_reserved3
= 0;
251 #ifdef _HAVE_STAT___UNUSED4
252 buf
->__glibc_reserved4
= 0;
254 #ifdef _HAVE_STAT___UNUSED5
255 buf
->__glibc_reserved5
= 0;
260 /* If struct stat64 is different from struct stat then
261 _STAT_VER_KERNEL does not make sense. */
262 case _STAT_VER_KERNEL
:
264 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL
);