1 /* $NetBSD: irix_stat.c,v 1.23 2008/03/21 21:54:58 ad Exp $ */
4 * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_stat.c,v 1.23 2008/03/21 21:54:58 ad Exp $");
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/signal.h>
38 #include <sys/param.h>
39 #include <sys/filedesc.h>
41 #include <sys/mount.h>
42 #include <sys/namei.h>
43 #include <sys/stdint.h>
45 #include <sys/systm.h>
46 #include <sys/syscallargs.h>
47 #include <sys/vfs_syscalls.h>
49 #include <compat/common/compat_util.h>
51 #include <compat/svr4/svr4_types.h>
53 #include <compat/irix/irix_types.h>
54 #include <compat/irix/irix_signal.h>
55 #include <compat/irix/irix_syscall.h>
56 #include <compat/irix/irix_syscallargs.h>
58 static void bsd_to_irix_stat(struct stat
*, struct irix_stat
*);
59 static void bsd_to_irix_stat64(struct stat
*, struct irix_stat64
*);
62 bsd_to_irix_stat(struct stat
*bsp
, struct irix_stat
*isp
)
64 memset(isp
, 0, sizeof(*isp
));
65 isp
->ist_dev
= (irix_dev_t
)bsd_to_svr4_dev_t(bsp
->st_dev
);
66 isp
->ist_ino
= bsp
->st_ino
;
67 isp
->ist_mode
= bsp
->st_mode
; /* XXX translate it */
68 isp
->ist_nlink
= bsp
->st_nlink
;
69 isp
->ist_uid
= bsp
->st_uid
;
70 isp
->ist_gid
= bsp
->st_gid
;
71 if ((bsp
->st_mode
& S_IFMT
) == S_IFBLK
||
72 (bsp
->st_mode
& S_IFMT
) == S_IFCHR
)
73 isp
->ist_rdev
= (irix_dev_t
)bsd_to_svr4_dev_t(bsp
->st_rdev
);
76 isp
->ist_size
= bsp
->st_size
;
77 isp
->ist_atim
.tv_sec
= bsp
->st_atimespec
.tv_sec
;
78 isp
->ist_atim
.tv_nsec
= bsp
->st_atimespec
.tv_nsec
;
79 isp
->ist_mtim
.tv_sec
= bsp
->st_mtimespec
.tv_sec
;
80 isp
->ist_mtim
.tv_nsec
= bsp
->st_mtimespec
.tv_nsec
;
81 isp
->ist_ctim
.tv_sec
= bsp
->st_ctimespec
.tv_sec
;
82 isp
->ist_ctim
.tv_nsec
= bsp
->st_ctimespec
.tv_nsec
;
83 isp
->ist_size
= bsp
->st_size
;
84 isp
->ist_blocks
= bsp
->st_blocks
;
85 isp
->ist_blksize
= bsp
->st_blksize
;
86 strlcpy(isp
->ist_fstype
, "unknown", sizeof(isp
->ist_fstype
));
92 bsd_to_irix_stat64(struct stat
*bsp
, struct irix_stat64
*isp
)
94 memset(isp
, 0, sizeof(*isp
));
95 isp
->ist_dev
= (irix_dev_t
)bsd_to_svr4_dev_t(bsp
->st_dev
);
96 isp
->ist_ino
= bsp
->st_ino
;
97 isp
->ist_mode
= bsp
->st_mode
; /* XXX translate it */
98 isp
->ist_nlink
= bsp
->st_nlink
;
99 isp
->ist_uid
= bsp
->st_uid
;
100 isp
->ist_gid
= bsp
->st_gid
;
101 if ((bsp
->st_mode
& S_IFMT
) == S_IFBLK
||
102 (bsp
->st_mode
& S_IFMT
) == S_IFCHR
)
103 isp
->ist_rdev
= (irix_dev_t
)bsd_to_svr4_dev_t(bsp
->st_rdev
);
106 isp
->ist_size
= bsp
->st_size
;
107 isp
->ist_atim
.tv_sec
= bsp
->st_atimespec
.tv_sec
;
108 isp
->ist_atim
.tv_nsec
= bsp
->st_atimespec
.tv_nsec
;
109 isp
->ist_mtim
.tv_sec
= bsp
->st_mtimespec
.tv_sec
;
110 isp
->ist_mtim
.tv_nsec
= bsp
->st_mtimespec
.tv_nsec
;
111 isp
->ist_ctim
.tv_sec
= bsp
->st_ctimespec
.tv_sec
;
112 isp
->ist_ctim
.tv_nsec
= bsp
->st_ctimespec
.tv_nsec
;
113 isp
->ist_size
= bsp
->st_size
;
114 isp
->ist_blocks
= bsp
->st_blocks
;
115 isp
->ist_blksize
= bsp
->st_blksize
;
116 strlcpy(isp
->ist_fstype
, "unknown", sizeof(isp
->ist_fstype
));
122 convert_irix_stat(struct stat
*st
, void *buf
, int stat_version
)
124 switch (stat_version
) {
125 case IRIX__STAT_VER
: {
126 struct irix_stat ist
;
128 bsd_to_irix_stat(st
, &ist
);
129 return copyout(&ist
, buf
, sizeof (ist
));
131 case IRIX__STAT64_VER
: {
132 struct irix_stat64 ist
;
134 bsd_to_irix_stat64(st
, &ist
);
135 return copyout(&ist
, buf
, sizeof (ist
));
137 case IRIX__R3_STAT_VER
:
139 printf("Warning: unimplemented irix_sys_?stat() version %d\n",
146 irix_sys_xstat(struct lwp
*l
, const struct irix_sys_xstat_args
*uap
, register_t
*retval
)
149 syscallarg(const int) version;
150 syscallarg(const char *) path;
151 syscallarg(struct stat *) buf;
156 error
= do_sys_stat(SCARG(uap
, path
), FOLLOW
, &st
);
160 return convert_irix_stat(&st
, SCARG(uap
, buf
), SCARG(uap
, version
));
164 irix_sys_lxstat(struct lwp
*l
, const struct irix_sys_lxstat_args
*uap
, register_t
*retval
)
167 syscallarg(const int) version;
168 syscallarg(const char *) path;
169 syscallarg(struct stat *) buf;
174 error
= do_sys_stat(SCARG(uap
, path
), NOFOLLOW
, &st
);
177 return convert_irix_stat(&st
, SCARG(uap
, buf
), SCARG(uap
, version
));
181 irix_sys_fxstat(struct lwp
*l
, const struct irix_sys_fxstat_args
*uap
, register_t
*retval
)
184 syscallarg(const int) version;
185 syscallarg(const int) fd;
186 syscallarg(struct stat *) buf;
191 error
= do_sys_fstat(SCARG(uap
, fd
), &st
);
194 return convert_irix_stat(&st
, SCARG(uap
, buf
), SCARG(uap
, version
));