Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc64 / xstatconv.c
blob1fb207be1f7cde9ec4129ae92709f4fd85159475
1 /* Convert between the kernel's `struct stat' format, and libc's.
2 Copyright (C) 1991, 1995, 1996, 1997, 2000, 2002, 2003, 2006
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <assert.h>
21 #include <errno.h>
22 #include <sys/stat.h>
23 #include <kernel_stat.h>
24 #include <string.h>
25 #include <kernel-features.h>
27 int
28 __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
30 switch (vers)
32 case _STAT_VER_KERNEL:
33 /* Nothing to do. The struct is in the form the kernel expects.
34 We should have short-circuted before we got here, but for
35 completeness... */
36 *(struct kernel_stat *) ubuf = *kbuf;
37 break;
39 case _STAT_VER_LINUX:
41 struct stat *buf = ubuf;
43 /* Convert to current kernel version of `struct stat'. */
44 buf->st_dev = kbuf->st_dev;
45 buf->__pad1 = 0;
46 buf->st_ino = kbuf->st_ino;
47 buf->st_mode = kbuf->st_mode;
48 buf->st_nlink = kbuf->st_nlink;
49 buf->st_uid = kbuf->st_uid;
50 buf->st_gid = kbuf->st_gid;
51 buf->st_rdev = kbuf->st_rdev;
52 buf->__pad2 = 0;
53 buf->st_size = kbuf->st_size;
54 buf->st_blksize = kbuf->st_blksize;
55 buf->st_blocks = kbuf->st_blocks;
56 buf->st_atim.tv_sec = kbuf->st_atime_sec;
57 buf->st_atim.tv_nsec = 0;
58 buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
59 buf->st_mtim.tv_nsec = 0;
60 buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
61 buf->st_ctim.tv_nsec = 0;
62 buf->__unused4 = 0;
63 buf->__unused5 = 0;
65 break;
67 default:
68 __set_errno (EINVAL);
69 return -1;
72 return 0;
75 int
76 __xstat32_conv (int vers, struct stat64 *sbuf, struct stat *buf)
78 struct kernel_stat64 *kbuf;
80 /* *stat64 syscalls on sparc64 really fill in struct kernel_stat64,
81 rather than struct stat64. But it is the same size as
82 struct kernel_stat64, so use this hack so that we can reuse
83 i386 {,f,l}xstat{,at}.c routines. */
84 __asm ("" : "=r" (kbuf) : "0" (sbuf));
85 assert (sizeof (struct stat) == sizeof (struct stat64));
86 assert (sizeof (struct stat64) >= sizeof (struct kernel_stat64));
88 switch (vers)
90 case _STAT_VER_LINUX:
92 /* Convert current kernel version of `struct stat64' to
93 `struct stat'. */
94 buf->st_dev = kbuf->st_dev;
95 buf->__pad1 = 0;
96 buf->st_ino = kbuf->st_ino;
97 buf->st_mode = kbuf->st_mode;
98 buf->st_nlink = kbuf->st_nlink;
99 buf->st_uid = kbuf->st_uid;
100 buf->st_gid = kbuf->st_gid;
101 buf->st_rdev = kbuf->st_rdev;
102 buf->__pad2 = 0;
103 buf->st_size = kbuf->st_size;
104 buf->st_blksize = kbuf->st_blksize;
105 buf->st_blocks = kbuf->st_blocks;
106 buf->st_atim.tv_sec = kbuf->st_atime_sec;
107 buf->st_atim.tv_nsec = kbuf->st_atime_nsec;
108 buf->st_mtim.tv_sec = kbuf->st_mtime_sec;
109 buf->st_mtim.tv_nsec = kbuf->st_mtime_nsec;
110 buf->st_ctim.tv_sec = kbuf->st_ctime_sec;
111 buf->st_ctim.tv_nsec = kbuf->st_ctime_nsec;
112 buf->__unused4 = 0;
113 buf->__unused5 = 0;
115 break;
117 /* If struct stat64 is different from struct stat then
118 _STAT_VER_KERNEL does not make sense. */
119 case _STAT_VER_KERNEL:
120 default:
121 __set_errno (EINVAL);
122 return -1;
125 return 0;