1 | /* Convert between the kernel's `struct stat' format, and libc's. |
---|---|
2 | Copyright (C) 1997-2022 Free Software Foundation, Inc. |
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 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. |
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 | Lesser General Public License for more details. |
14 | |
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 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <string.h> |
21 | #include <sys/stat.h> |
22 | #include <kernel_stat.h> |
23 | #include <xstatconv.h> |
24 | #include <sys/syscall.h> |
25 | |
26 | int |
27 | __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf) |
28 | { |
29 | switch (vers) |
30 | { |
31 | case _STAT_VER_KERNEL: |
32 | *(struct kernel_stat *) ubuf = *kbuf; |
33 | break; |
34 | |
35 | case _STAT_VER_GLIBC2: |
36 | { |
37 | struct glibc2_stat *buf = ubuf; |
38 | |
39 | buf->st_dev = kbuf->st_dev; |
40 | buf->st_ino = kbuf->st_ino; |
41 | buf->st_mode = kbuf->st_mode; |
42 | buf->st_nlink = kbuf->st_nlink; |
43 | buf->st_uid = kbuf->st_uid; |
44 | buf->st_gid = kbuf->st_gid; |
45 | buf->st_rdev = kbuf->st_rdev; |
46 | buf->st_size = kbuf->st_size; |
47 | buf->st_atime_sec = kbuf->st_atime_sec; |
48 | buf->st_mtime_sec = kbuf->st_mtime_sec; |
49 | buf->st_ctime_sec = kbuf->st_ctime_sec; |
50 | buf->st_blksize = kbuf->st_blksize; |
51 | buf->st_blocks = kbuf->st_blocks; |
52 | buf->st_flags = kbuf->st_flags; |
53 | buf->st_gen = kbuf->st_gen; |
54 | } |
55 | break; |
56 | |
57 | case _STAT_VER_GLIBC2_1: |
58 | { |
59 | struct glibc21_stat *buf = ubuf; |
60 | |
61 | buf->st_dev = kbuf->st_dev; |
62 | buf->st_ino = kbuf->st_ino; |
63 | buf->st_mode = kbuf->st_mode; |
64 | buf->st_nlink = kbuf->st_nlink; |
65 | buf->st_uid = kbuf->st_uid; |
66 | buf->st_gid = kbuf->st_gid; |
67 | buf->st_rdev = kbuf->st_rdev; |
68 | buf->st_size = kbuf->st_size; |
69 | buf->st_atime_sec = kbuf->st_atime_sec; |
70 | buf->st_mtime_sec = kbuf->st_mtime_sec; |
71 | buf->st_ctime_sec = kbuf->st_ctime_sec; |
72 | buf->st_blocks = kbuf->st_blocks; |
73 | buf->st_blksize = kbuf->st_blksize; |
74 | buf->st_flags = kbuf->st_flags; |
75 | buf->st_gen = kbuf->st_gen; |
76 | buf->__pad3 = 0; |
77 | buf->__glibc_reserved[0] = 0; |
78 | buf->__glibc_reserved[1] = 0; |
79 | buf->__glibc_reserved[2] = 0; |
80 | buf->__glibc_reserved[3] = 0; |
81 | } |
82 | break; |
83 | |
84 | case _STAT_VER_GLIBC2_3_4: |
85 | { |
86 | struct stat64 *buf = ubuf; |
87 | |
88 | buf->st_dev = kbuf->st_dev; |
89 | buf->st_ino = kbuf->st_ino; |
90 | buf->st_rdev = kbuf->st_rdev; |
91 | buf->st_size = kbuf->st_size; |
92 | buf->st_blocks = kbuf->st_blocks; |
93 | |
94 | buf->st_mode = kbuf->st_mode; |
95 | buf->st_uid = kbuf->st_uid; |
96 | buf->st_gid = kbuf->st_gid; |
97 | buf->st_blksize = kbuf->st_blksize; |
98 | buf->st_nlink = kbuf->st_nlink; |
99 | buf->__pad0 = 0; |
100 | |
101 | buf->st_atim.tv_sec = kbuf->st_atime_sec; |
102 | buf->st_atim.tv_nsec = 0; |
103 | buf->st_mtim.tv_sec = kbuf->st_mtime_sec; |
104 | buf->st_mtim.tv_nsec = 0; |
105 | buf->st_ctim.tv_sec = kbuf->st_ctime_sec; |
106 | buf->st_ctim.tv_nsec = 0; |
107 | |
108 | buf->__glibc_reserved[0] = 0; |
109 | buf->__glibc_reserved[1] = 0; |
110 | buf->__glibc_reserved[2] = 0; |
111 | } |
112 | break; |
113 | |
114 | default: |
115 | __set_errno (EINVAL); |
116 | return -1; |
117 | } |
118 | |
119 | return 0; |
120 | } |
121 |