1 /* Convert between the kernel's `struct stat' format, and libc's.
2 Copyright (C) 1991, 1995, 1996, 1997, 2000 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
24 xstat_conv (int vers
, struct kernel_stat
*kbuf
, void *ubuf
)
28 case _STAT_VER_KERNEL
:
29 /* Nothing to do. The struct is in the form the kernel expects.
30 We should have short-circuted before we got here, but for
32 *(struct kernel_stat
*) ubuf
= *kbuf
;
37 struct stat
*buf
= ubuf
;
39 /* Convert to current kernel version of `struct stat'. */
40 buf
->st_dev
= kbuf
->st_dev
;
41 #ifdef _HAVE_STAT___PAD1
44 buf
->st_ino
= kbuf
->st_ino
;
45 buf
->st_mode
= kbuf
->st_mode
;
46 buf
->st_nlink
= kbuf
->st_nlink
;
47 buf
->st_uid
= kbuf
->st_uid
;
48 buf
->st_gid
= kbuf
->st_gid
;
49 buf
->st_rdev
= kbuf
->st_rdev
;
50 #ifdef _HAVE_STAT___PAD2
53 buf
->st_size
= kbuf
->st_size
;
54 buf
->st_blksize
= kbuf
->st_blksize
;
55 buf
->st_blocks
= kbuf
->st_blocks
;
56 buf
->st_atime
= kbuf
->st_atime
;
57 #ifdef _HAVE_STAT___UNUSED1
60 buf
->st_mtime
= kbuf
->st_mtime
;
61 #ifdef _HAVE_STAT___UNUSED2
64 buf
->st_ctime
= kbuf
->st_ctime
;
65 #ifdef _HAVE_STAT___UNUSED3
68 #ifdef _HAVE_STAT___UNUSED4
71 #ifdef _HAVE_STAT___UNUSED5
86 xstat64_conv (int vers
, struct kernel_stat
*kbuf
, void *ubuf
)
88 #ifdef XSTAT_IS_XSTAT64
89 return xstat_conv (vers
, kbuf
, ubuf
);
95 struct stat64
*buf
= ubuf
;
97 /* Convert to current kernel version of `struct stat64'. */
98 buf
->st_dev
= kbuf
->st_dev
;
99 #ifdef _HAVE_STAT64___PAD1
102 buf
->st_ino
= kbuf
->st_ino
;
103 #ifdef _HAVE_STAT64___ST_INO
104 buf
->__st_ino
= kbuf
->st_ino
;
106 buf
->st_mode
= kbuf
->st_mode
;
107 buf
->st_nlink
= kbuf
->st_nlink
;
108 buf
->st_uid
= kbuf
->st_uid
;
109 buf
->st_gid
= kbuf
->st_gid
;
110 buf
->st_rdev
= kbuf
->st_rdev
;
111 #ifdef _HAVE_STAT64___PAD2
114 buf
->st_size
= kbuf
->st_size
;
115 buf
->st_blksize
= kbuf
->st_blksize
;
116 buf
->st_blocks
= kbuf
->st_blocks
;
117 buf
->st_atime
= kbuf
->st_atime
;
118 #ifdef _HAVE_STAT64___UNUSED1
121 buf
->st_mtime
= kbuf
->st_mtime
;
122 #ifdef _HAVE_STAT64___UNUSED2
125 buf
->st_ctime
= kbuf
->st_ctime
;
126 #ifdef _HAVE_STAT64___UNUSED3
129 #ifdef _HAVE_STAT64___UNUSED4
132 #ifdef _HAVE_STAT64___UNUSED5
138 /* If struct stat64 is different from struct stat then
139 _STAT_VER_KERNEL does not make sense. */
140 case _STAT_VER_KERNEL
:
142 __set_errno (EINVAL
);
151 xstat32_conv (int vers
, struct stat64
*kbuf
, struct stat
*buf
)
155 case _STAT_VER_LINUX
:
157 /* Convert current kernel version of `struct stat64' to
159 buf
->st_dev
= kbuf
->st_dev
;
160 #ifdef _HAVE_STAT___PAD1
163 #ifdef _HAVE_STAT64___ST_INO
164 # if __ASSUME_ST_INO_64_BIT == 0
165 if (kbuf
->st_ino
== 0)
166 buf
->st_ino
= kbuf
->__st_ino
;
170 buf
->st_ino
= kbuf
->st_ino
;
171 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
172 && buf
->st_ino
!= kbuf
->st_ino
)
174 __set_errno (EOVERFLOW
);
179 buf
->st_ino
= kbuf
->st_ino
;
180 if (sizeof (buf
->st_ino
) != sizeof (kbuf
->st_ino
)
181 && buf
->st_ino
!= kbuf
->st_ino
)
183 __set_errno (EOVERFLOW
);
187 buf
->st_mode
= kbuf
->st_mode
;
188 buf
->st_nlink
= kbuf
->st_nlink
;
189 buf
->st_uid
= kbuf
->st_uid
;
190 buf
->st_gid
= kbuf
->st_gid
;
191 buf
->st_rdev
= kbuf
->st_rdev
;
192 #ifdef _HAVE_STAT___PAD2
195 buf
->st_size
= kbuf
->st_size
;
196 /* Check for overflow. */
197 if (sizeof (buf
->st_size
) != sizeof (kbuf
->st_size
)
198 && buf
->st_size
!= kbuf
->st_size
)
200 __set_errno (EOVERFLOW
);
203 buf
->st_blksize
= kbuf
->st_blksize
;
204 buf
->st_blocks
= kbuf
->st_blocks
;
205 /* Check for overflow. */
206 if (sizeof (buf
->st_blocks
) != sizeof (kbuf
->st_blocks
)
207 && buf
->st_blocks
!= kbuf
->st_blocks
)
209 __set_errno (EOVERFLOW
);
212 buf
->st_atime
= kbuf
->st_atime
;
213 #ifdef _HAVE_STAT___UNUSED1
216 buf
->st_mtime
= kbuf
->st_mtime
;
217 #ifdef _HAVE_STAT___UNUSED2
220 buf
->st_ctime
= kbuf
->st_ctime
;
221 #ifdef _HAVE_STAT___UNUSED3
224 #ifdef _HAVE_STAT___UNUSED4
227 #ifdef _HAVE_STAT___UNUSED5
233 /* If struct stat64 is different from struct stat then
234 _STAT_VER_KERNEL does not make sense. */
235 case _STAT_VER_KERNEL
:
237 __set_errno (EINVAL
);