]>
Commit | Line | Data |
---|---|---|
abbde1b0 | 1 | /* Convert between the kernel's `struct stat' format, and libc's. |
e739de11 | 2 | Copyright (C) 1991,1995,1996,1997,1998,2000 Free Software Foundation, Inc. |
abbde1b0 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
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 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include <string.h> | |
21 | ||
22 | ||
23 | static inline int | |
24 | xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf) | |
25 | { | |
26 | switch (vers) | |
27 | { | |
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; | |
34 | ||
35 | case _STAT_VER_LINUX: | |
36 | { | |
37 | struct stat *buf = ubuf; | |
38 | ||
39 | /* Convert to current kernel version of `struct stat'. */ | |
40 | buf->st_dev = kbuf->st_dev; | |
e739de11 | 41 | buf->st_pad1[0] = 0; buf->st_pad1[1] = 0; buf->st_pad1[2] = 0; |
abbde1b0 UD |
42 | buf->st_ino = kbuf->st_ino; |
43 | buf->st_mode = kbuf->st_mode; | |
44 | buf->st_nlink = kbuf->st_nlink; | |
45 | buf->st_uid = kbuf->st_uid; | |
46 | buf->st_gid = kbuf->st_gid; | |
47 | buf->st_rdev = kbuf->st_rdev; | |
48 | buf->st_pad2[0] = 0; buf->st_pad2[1] = 0; | |
49 | buf->st_pad3 = 0; | |
50 | buf->st_size = kbuf->st_size; | |
51 | buf->st_blksize = kbuf->st_blksize; | |
52 | buf->st_blocks = kbuf->st_blocks; | |
e739de11 | 53 | |
abbde1b0 UD |
54 | buf->st_atime = kbuf->st_atime; buf->__reserved0 = 0; |
55 | buf->st_mtime = kbuf->st_mtime; buf->__reserved1 = 0; | |
56 | buf->st_ctime = kbuf->st_ctime; buf->__reserved2 = 0; | |
e739de11 AJ |
57 | |
58 | buf->st_pad5[0] = 0; buf->st_pad5[1] = 0; | |
59 | buf->st_pad5[2] = 0; buf->st_pad5[3] = 0; | |
60 | buf->st_pad5[4] = 0; buf->st_pad5[5] = 0; | |
61 | buf->st_pad5[6] = 0; buf->st_pad5[7] = 0; | |
abbde1b0 UD |
62 | } |
63 | break; | |
64 | ||
65 | default: | |
66 | __set_errno (EINVAL); | |
67 | return -1; | |
68 | } | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | static inline int | |
74 | xstat64_conv (int vers, struct kernel_stat *kbuf, void *ubuf) | |
75 | { | |
76 | #ifdef XSTAT_IS_XSTAT64 | |
77 | return xstat_conv (vers, kbuf, ubuf); | |
78 | #else | |
79 | switch (vers) | |
80 | { | |
81 | case _STAT_VER_LINUX: | |
82 | { | |
83 | struct stat64 *buf = ubuf; | |
84 | ||
85 | buf->st_dev = kbuf->st_dev; | |
e739de11 | 86 | buf->st_pad1[0] = 0; buf->st_pad1[1] = 0; buf->st_pad1[2] = 0; |
abbde1b0 UD |
87 | buf->st_ino = kbuf->st_ino; |
88 | buf->st_mode = kbuf->st_mode; | |
89 | buf->st_nlink = kbuf->st_nlink; | |
90 | buf->st_uid = kbuf->st_uid; | |
91 | buf->st_gid = kbuf->st_gid; | |
92 | buf->st_rdev = kbuf->st_rdev; | |
e739de11 | 93 | buf->st_pad2[0] = 0; buf->st_pad2[1] = 0; buf->st_pad2[2] = 0; |
abbde1b0 UD |
94 | buf->st_pad3 = 0; |
95 | buf->st_size = kbuf->st_size; | |
96 | buf->st_blksize = kbuf->st_blksize; | |
97 | buf->st_blocks = kbuf->st_blocks; | |
98 | ||
99 | buf->st_atime = kbuf->st_atime; buf->__reserved0 = 0; | |
100 | buf->st_mtime = kbuf->st_mtime; buf->__reserved1 = 0; | |
101 | buf->st_ctime = kbuf->st_ctime; buf->__reserved2 = 0; | |
102 | ||
103 | buf->st_pad4[0] = 0; buf->st_pad4[1] = 0; | |
104 | buf->st_pad4[2] = 0; buf->st_pad4[3] = 0; | |
105 | buf->st_pad4[4] = 0; buf->st_pad4[5] = 0; | |
106 | buf->st_pad4[6] = 0; buf->st_pad4[7] = 0; | |
107 | } | |
108 | break; | |
109 | ||
110 | /* If struct stat64 is different from struct stat then | |
111 | _STAT_VER_KERNEL does not make sense. */ | |
112 | case _STAT_VER_KERNEL: | |
113 | default: | |
114 | __set_errno (EINVAL); | |
115 | return -1; | |
116 | } | |
117 | ||
118 | return 0; | |
119 | #endif | |
120 | } |