]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/sparc/sparc64/xstatconv.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc64 / xstatconv.c
CommitLineData
49783c67 1/* Convert between the kernel's `struct stat' format, and libc's.
d4697bc9 2 Copyright (C) 1991-2014 Free Software Foundation, Inc.
49783c67
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 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
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
49783c67
UD
18
19#include <assert.h>
20#include <errno.h>
21#include <sys/stat.h>
22#include <kernel_stat.h>
23#include <string.h>
24#include <kernel-features.h>
25
26int
27__xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
28{
29 switch (vers)
30 {
31 case _STAT_VER_KERNEL:
32 /* Nothing to do. The struct is in the form the kernel expects.
33 We should have short-circuted before we got here, but for
34 completeness... */
35 *(struct kernel_stat *) ubuf = *kbuf;
36 break;
37
38 case _STAT_VER_LINUX:
39 {
40 struct stat *buf = ubuf;
41
42 /* Convert to current kernel version of `struct stat'. */
43 buf->st_dev = kbuf->st_dev;
44 buf->__pad1 = 0;
45 buf->st_ino = kbuf->st_ino;
46 buf->st_mode = kbuf->st_mode;
47 buf->st_nlink = kbuf->st_nlink;
48 buf->st_uid = kbuf->st_uid;
49 buf->st_gid = kbuf->st_gid;
50 buf->st_rdev = kbuf->st_rdev;
51 buf->__pad2 = 0;
52 buf->st_size = kbuf->st_size;
53 buf->st_blksize = kbuf->st_blksize;
54 buf->st_blocks = kbuf->st_blocks;
55 buf->st_atim.tv_sec = kbuf->st_atime_sec;
56 buf->st_atim.tv_nsec = 0;
57 buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
58 buf->st_mtim.tv_nsec = 0;
59 buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
60 buf->st_ctim.tv_nsec = 0;
d1d9eaf4
OB
61 buf->__glibc_reserved4 = 0;
62 buf->__glibc_reserved5 = 0;
49783c67
UD
63 }
64 break;
65
66 default:
67 __set_errno (EINVAL);
68 return -1;
69 }
70
71 return 0;
72}
73
74int
75__xstat32_conv (int vers, struct stat64 *sbuf, struct stat *buf)
76{
77 struct kernel_stat64 *kbuf;
78
79 /* *stat64 syscalls on sparc64 really fill in struct kernel_stat64,
80 rather than struct stat64. But it is the same size as
81 struct kernel_stat64, so use this hack so that we can reuse
82 i386 {,f,l}xstat{,at}.c routines. */
83 __asm ("" : "=r" (kbuf) : "0" (sbuf));
84 assert (sizeof (struct stat) == sizeof (struct stat64));
85 assert (sizeof (struct stat64) >= sizeof (struct kernel_stat64));
86
87 switch (vers)
88 {
89 case _STAT_VER_LINUX:
90 {
91 /* Convert current kernel version of `struct stat64' to
92 `struct stat'. */
93 buf->st_dev = kbuf->st_dev;
94 buf->__pad1 = 0;
95 buf->st_ino = kbuf->st_ino;
96 buf->st_mode = kbuf->st_mode;
97 buf->st_nlink = kbuf->st_nlink;
98 buf->st_uid = kbuf->st_uid;
99 buf->st_gid = kbuf->st_gid;
100 buf->st_rdev = kbuf->st_rdev;
101 buf->__pad2 = 0;
102 buf->st_size = kbuf->st_size;
103 buf->st_blksize = kbuf->st_blksize;
104 buf->st_blocks = kbuf->st_blocks;
105 buf->st_atim.tv_sec = kbuf->st_atime_sec;
106 buf->st_atim.tv_nsec = kbuf->st_atime_nsec;
107 buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
108 buf->st_mtim.tv_nsec = kbuf->st_mtime_nsec;
109 buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
110 buf->st_ctim.tv_nsec = kbuf->st_ctime_nsec;
d1d9eaf4
OB
111 buf->__glibc_reserved4 = 0;
112 buf->__glibc_reserved5 = 0;
49783c67
UD
113 }
114 break;
115
116 /* If struct stat64 is different from struct stat then
117 _STAT_VER_KERNEL does not make sense. */
118 case _STAT_VER_KERNEL:
119 default:
120 __set_errno (EINVAL);
121 return -1;
122 }
123
124 return 0;
125}