Remove *xattr syscalls.
[glibc.git] / sysdeps / unix / sysv / linux / xstatconv.c
blob78399b0d01aa75f585e36b39a0f1be5b8ef6ce9d
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
18 02111-1307 USA. */
20 #include <string.h>
23 static inline int
24 xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
26 switch (vers)
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
31 completeness... */
32 *(struct kernel_stat *) ubuf = *kbuf;
33 break;
35 case _STAT_VER_LINUX:
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
42 buf->__pad1 = 0;
43 #endif
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
51 buf->__pad2 = 0;
52 #endif
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
58 buf->__unused1 = 0;
59 #endif
60 buf->st_mtime = kbuf->st_mtime;
61 #ifdef _HAVE_STAT___UNUSED2
62 buf->__unused2 = 0;
63 #endif
64 buf->st_ctime = kbuf->st_ctime;
65 #ifdef _HAVE_STAT___UNUSED3
66 buf->__unused3 = 0;
67 #endif
68 #ifdef _HAVE_STAT___UNUSED4
69 buf->__unused4 = 0;
70 #endif
71 #ifdef _HAVE_STAT___UNUSED5
72 buf->__unused5 = 0;
73 #endif
75 break;
77 default:
78 __set_errno (EINVAL);
79 return -1;
82 return 0;
85 static inline int
86 xstat64_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
88 #ifdef XSTAT_IS_XSTAT64
89 return xstat_conv (vers, kbuf, ubuf);
90 #else
91 switch (vers)
93 case _STAT_VER_LINUX:
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
100 buf->__pad1 = 0;
101 #endif
102 buf->st_ino = kbuf->st_ino;
103 #ifdef _HAVE_STAT64___ST_INO
104 buf->__st_ino = kbuf->st_ino;
105 #endif
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
112 buf->__pad2 = 0;
113 #endif
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
119 buf->__unused1 = 0;
120 #endif
121 buf->st_mtime = kbuf->st_mtime;
122 #ifdef _HAVE_STAT64___UNUSED2
123 buf->__unused2 = 0;
124 #endif
125 buf->st_ctime = kbuf->st_ctime;
126 #ifdef _HAVE_STAT64___UNUSED3
127 buf->__unused3 = 0;
128 #endif
129 #ifdef _HAVE_STAT64___UNUSED4
130 buf->__unused4 = 0;
131 #endif
132 #ifdef _HAVE_STAT64___UNUSED5
133 buf->__unused5 = 0;
134 #endif
136 break;
138 /* If struct stat64 is different from struct stat then
139 _STAT_VER_KERNEL does not make sense. */
140 case _STAT_VER_KERNEL:
141 default:
142 __set_errno (EINVAL);
143 return -1;
146 return 0;
147 #endif
150 static inline int
151 xstat32_conv (int vers, struct stat64 *kbuf, struct stat *buf)
153 switch (vers)
155 case _STAT_VER_LINUX:
157 /* Convert current kernel version of `struct stat64' to
158 `struct stat'. */
159 buf->st_dev = kbuf->st_dev;
160 #ifdef _HAVE_STAT___PAD1
161 buf->__pad1 = 0;
162 #endif
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;
167 else
168 # endif
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);
175 return -1;
178 #else
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);
184 return -1;
186 #endif
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
193 buf->__pad2 = 0;
194 #endif
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);
201 return -1;
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);
210 return -1;
212 buf->st_atime = kbuf->st_atime;
213 #ifdef _HAVE_STAT___UNUSED1
214 buf->__unused1 = 0;
215 #endif
216 buf->st_mtime = kbuf->st_mtime;
217 #ifdef _HAVE_STAT___UNUSED2
218 buf->__unused2 = 0;
219 #endif
220 buf->st_ctime = kbuf->st_ctime;
221 #ifdef _HAVE_STAT___UNUSED3
222 buf->__unused3 = 0;
223 #endif
224 #ifdef _HAVE_STAT___UNUSED4
225 buf->__unused4 = 0;
226 #endif
227 #ifdef _HAVE_STAT___UNUSED5
228 buf->__unused5 = 0;
229 #endif
231 break;
233 /* If struct stat64 is different from struct stat then
234 _STAT_VER_KERNEL does not make sense. */
235 case _STAT_VER_KERNEL:
236 default:
237 __set_errno (EINVAL);
238 return -1;
241 return 0;