1 /* Convert between the kernel's `struct stat' format, and libc's.
2 Copyright (C) 1991,1995-1997,2000,2002,2003 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <kernel_stat.h>
24 #ifdef STAT_IS_KERNEL_STAT
34 #if !defined __ASSUME_STAT64_SYSCALL || defined 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
83 #ifdef _HAVE_STAT___UNUSED2
86 #ifdef _HAVE_STAT___UNUSED3
89 #ifdef _HAVE_STAT___UNUSED4
92 #ifdef _HAVE_STAT___UNUSED5
108 __xstat64_conv (int vers
, struct kernel_stat
*kbuf
, void *ubuf
)
110 #ifdef XSTAT_IS_XSTAT64
111 return __xstat_conv (vers
, kbuf
, ubuf
);
115 case _STAT_VER_LINUX
:
117 struct stat64
*buf
= ubuf
;
119 /* Convert to current kernel version of `struct stat64'. */
120 buf
->st_dev
= kbuf
->st_dev
;
121 #ifdef _HAVE_STAT64___PAD1
124 buf
->st_ino
= kbuf
->st_ino
;
125 #ifdef _HAVE_STAT64___ST_INO
126 buf
->__st_ino
= kbuf
->st_ino
;
128 buf
->st_mode
= kbuf
->st_mode
;
129 buf
->st_nlink
= kbuf
->st_nlink
;
130 buf
->st_uid
= kbuf
->st_uid
;
131 buf
->st_gid
= kbuf
->st_gid
;
132 buf
->st_rdev
= kbuf
->st_rdev
;
133 #ifdef _HAVE_STAT64___PAD2
136 buf
->st_size
= kbuf
->st_size
;
137 buf
->st_blksize
= kbuf
->st_blksize
;
138 buf
->st_blocks
= kbuf
->st_blocks
;
139 #ifdef _HAVE_STAT64_NSEC
140 buf
->st_atim
.tv_sec
= kbuf
->st_atim
.tv_sec
;
141 buf
->st_atim
.tv_nsec
= kbuf
->st_atim
.tv_nsec
;
142 buf
->st_mtim
.tv_sec
= kbuf
->st_mtim
.tv_sec
;
143 buf
->st_mtim
.tv_nsec
= kbuf
->st_mtim
.tv_nsec
;
144 buf
->st_ctim
.tv_sec
= kbuf
->st_ctim
.tv_sec
;
145 buf
->st_ctim
.tv_nsec
= kbuf
->st_ctim
.tv_nsec
;
147 buf
->st_atime
= kbuf
->st_atime
;
148 buf
->st_mtime
= kbuf
->st_mtime
;
149 buf
->st_ctime
= kbuf
->st_ctime
;
151 #ifdef _HAVE_STAT64___UNUSED1
154 #ifdef _HAVE_STAT64___UNUSED2
157 #ifdef _HAVE_STAT64___UNUSED3
160 #ifdef _HAVE_STAT64___UNUSED4
163 #ifdef _HAVE_STAT64___UNUSED5
169 /* If struct stat64 is different from struct stat then
170 _STAT_VER_KERNEL does not make sense. */
171 case _STAT_VER_KERNEL
:
173 __set_errno (EINVAL
);
182 __xstat32_conv (int vers
, struct stat64
*kbuf
, struct stat
*buf
)
186 case _STAT_VER_LINUX
:
188 /* Convert current kernel version of `struct stat64' to
190 buf
->st_dev
= kbuf
->st_dev
;
191 #ifdef _HAVE_STAT___PAD1
194 #ifdef _HAVE_STAT64___ST_INO
195 # if __ASSUME_ST_INO_64_BIT == 0
196 if (kbuf
->st_ino
== 0)
197 buf
->st_ino
= kbuf
->__st_ino
;
201 buf
->st_ino
= kbuf
->st_ino
;
202 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
203 && buf
->st_ino
!= kbuf
->st_ino
)
205 __set_errno (EOVERFLOW
);
210 buf
->st_ino
= kbuf
->st_ino
;
211 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
212 && buf
->st_ino
!= kbuf
->st_ino
)
214 __set_errno (EOVERFLOW
);
218 buf
->st_mode
= kbuf
->st_mode
;
219 buf
->st_nlink
= kbuf
->st_nlink
;
220 buf
->st_uid
= kbuf
->st_uid
;
221 buf
->st_gid
= kbuf
->st_gid
;
222 buf
->st_rdev
= kbuf
->st_rdev
;
223 #ifdef _HAVE_STAT___PAD2
226 buf
->st_size
= kbuf
->st_size
;
227 /* Check for overflow. */
228 if (sizeof (buf
->st_size
) != sizeof (kbuf
->st_size
)
229 && buf
->st_size
!= kbuf
->st_size
)
231 __set_errno (EOVERFLOW
);
234 buf
->st_blksize
= kbuf
->st_blksize
;
235 buf
->st_blocks
= kbuf
->st_blocks
;
236 /* Check for overflow. */
237 if (sizeof (buf
->st_blocks
) != sizeof (kbuf
->st_blocks
)
238 && buf
->st_blocks
!= kbuf
->st_blocks
)
240 __set_errno (EOVERFLOW
);
243 #ifdef _HAVE_STAT_NSEC
244 buf
->st_atim
.tv_sec
= kbuf
->st_atim
.tv_sec
;
245 buf
->st_atim
.tv_nsec
= kbuf
->st_atim
.tv_nsec
;
246 buf
->st_mtim
.tv_sec
= kbuf
->st_mtim
.tv_sec
;
247 buf
->st_mtim
.tv_nsec
= kbuf
->st_mtim
.tv_nsec
;
248 buf
->st_ctim
.tv_sec
= kbuf
->st_ctim
.tv_sec
;
249 buf
->st_ctim
.tv_nsec
= kbuf
->st_ctim
.tv_nsec
;
251 buf
->st_atime
= kbuf
->st_atime
;
252 buf
->st_mtime
= kbuf
->st_mtime
;
253 buf
->st_ctime
= kbuf
->st_ctime
;
256 #ifdef _HAVE_STAT___UNUSED1
259 #ifdef _HAVE_STAT___UNUSED2
262 #ifdef _HAVE_STAT___UNUSED3
265 #ifdef _HAVE_STAT___UNUSED4
268 #ifdef _HAVE_STAT___UNUSED5
274 /* If struct stat64 is different from struct stat then
275 _STAT_VER_KERNEL does not make sense. */
276 case _STAT_VER_KERNEL
:
278 __set_errno (EINVAL
);