]>
git.proxmox.com Git - mirror_qemu.git/blob - bsd-user/freebsd/os-stat.c
2 * FreeBSD stat related conversion routines
4 * Copyright (c) 2013 Stacey D. Son
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
26 abi_long
h2t_freebsd11_stat(abi_ulong target_addr
,
27 struct freebsd11_stat
*host_st
)
29 struct target_freebsd11_stat
*target_st
;
31 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0)) {
32 return -TARGET_EFAULT
;
34 memset(target_st
, 0, sizeof(*target_st
));
35 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
36 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
37 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
38 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
39 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
40 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
41 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
42 __put_user(host_st
->st_atim
.tv_sec
, &target_st
->st_atim
.tv_sec
);
43 __put_user(host_st
->st_atim
.tv_nsec
, &target_st
->st_atim
.tv_nsec
);
44 __put_user(host_st
->st_mtim
.tv_sec
, &target_st
->st_mtim
.tv_sec
);
45 __put_user(host_st
->st_mtim
.tv_nsec
, &target_st
->st_mtim
.tv_nsec
);
46 __put_user(host_st
->st_ctim
.tv_sec
, &target_st
->st_ctim
.tv_sec
);
47 __put_user(host_st
->st_ctim
.tv_nsec
, &target_st
->st_ctim
.tv_nsec
);
48 __put_user(host_st
->st_size
, &target_st
->st_size
);
49 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
50 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
51 __put_user(host_st
->st_flags
, &target_st
->st_flags
);
52 __put_user(host_st
->st_gen
, &target_st
->st_gen
);
53 /* st_lspare not used */
54 __put_user(host_st
->st_birthtim
.tv_sec
, &target_st
->st_birthtim
.tv_sec
);
55 __put_user(host_st
->st_birthtim
.tv_nsec
, &target_st
->st_birthtim
.tv_nsec
);
56 unlock_user_struct(target_st
, target_addr
, 1);
61 abi_long
h2t_freebsd11_nstat(abi_ulong target_addr
,
62 struct freebsd11_stat
*host_st
)
64 struct target_freebsd11_nstat
*target_st
;
66 if (!lock_user_struct(VERIFY_WRITE
, target_st
, target_addr
, 0)) {
67 return -TARGET_EFAULT
;
69 memset(target_st
, 0, sizeof(*target_st
));
70 __put_user(host_st
->st_dev
, &target_st
->st_dev
);
71 __put_user(host_st
->st_ino
, &target_st
->st_ino
);
72 __put_user(host_st
->st_mode
, &target_st
->st_mode
);
73 __put_user(host_st
->st_nlink
, &target_st
->st_nlink
);
74 __put_user(host_st
->st_uid
, &target_st
->st_uid
);
75 __put_user(host_st
->st_gid
, &target_st
->st_gid
);
76 __put_user(host_st
->st_rdev
, &target_st
->st_rdev
);
77 __put_user(host_st
->st_atim
.tv_sec
, &target_st
->st_atim
.tv_sec
);
78 __put_user(host_st
->st_atim
.tv_nsec
, &target_st
->st_atim
.tv_nsec
);
79 __put_user(host_st
->st_mtim
.tv_sec
, &target_st
->st_mtim
.tv_sec
);
80 __put_user(host_st
->st_mtim
.tv_nsec
, &target_st
->st_mtim
.tv_nsec
);
81 __put_user(host_st
->st_ctim
.tv_sec
, &target_st
->st_ctim
.tv_sec
);
82 __put_user(host_st
->st_ctim
.tv_nsec
, &target_st
->st_ctim
.tv_nsec
);
83 __put_user(host_st
->st_size
, &target_st
->st_size
);
84 __put_user(host_st
->st_blocks
, &target_st
->st_blocks
);
85 __put_user(host_st
->st_blksize
, &target_st
->st_blksize
);
86 __put_user(host_st
->st_flags
, &target_st
->st_flags
);
87 __put_user(host_st
->st_gen
, &target_st
->st_gen
);
88 __put_user(host_st
->st_birthtim
.tv_sec
, &target_st
->st_birthtim
.tv_sec
);
89 __put_user(host_st
->st_birthtim
.tv_nsec
, &target_st
->st_birthtim
.tv_nsec
);
90 unlock_user_struct(target_st
, target_addr
, 1);
96 * file handle conversion
98 abi_long
t2h_freebsd_fhandle(fhandle_t
*host_fh
, abi_ulong target_addr
)
100 target_freebsd_fhandle_t
*target_fh
;
102 if (!lock_user_struct(VERIFY_READ
, target_fh
, target_addr
, 1)) {
103 return -TARGET_EFAULT
;
105 __get_user(host_fh
->fh_fsid
.val
[0], &target_fh
->fh_fsid
.val
[0]);
106 __get_user(host_fh
->fh_fsid
.val
[1], &target_fh
->fh_fsid
.val
[0]);
107 __get_user(host_fh
->fh_fid
.fid_len
, &target_fh
->fh_fid
.fid_len
);
108 /* u_short fid_data0; */
109 memcpy(host_fh
->fh_fid
.fid_data
, target_fh
->fh_fid
.fid_data
,
111 unlock_user_struct(target_fh
, target_addr
, 0);
115 abi_long
h2t_freebsd_fhandle(abi_ulong target_addr
, fhandle_t
*host_fh
)
117 target_freebsd_fhandle_t
*target_fh
;
119 if (!lock_user_struct(VERIFY_WRITE
, target_fh
, target_addr
, 0)) {
120 return -TARGET_EFAULT
;
122 __put_user(host_fh
->fh_fsid
.val
[0], &target_fh
->fh_fsid
.val
[0]);
123 __put_user(host_fh
->fh_fsid
.val
[1], &target_fh
->fh_fsid
.val
[0]);
124 __put_user(host_fh
->fh_fid
.fid_len
, &target_fh
->fh_fid
.fid_len
);
125 /* u_short fid_data0; */
126 memcpy(target_fh
->fh_fid
.fid_data
, host_fh
->fh_fid
.fid_data
,
128 unlock_user_struct(target_fh
, target_addr
, 1);
135 abi_long
h2t_freebsd11_statfs(abi_ulong target_addr
,
136 struct freebsd11_statfs
*host_statfs
)
138 struct target_freebsd11_statfs
*target_statfs
;
140 if (!lock_user_struct(VERIFY_WRITE
, target_statfs
, target_addr
, 0)) {
141 return -TARGET_EFAULT
;
143 __put_user(host_statfs
->f_version
, &target_statfs
->f_version
);
144 __put_user(host_statfs
->f_type
, &target_statfs
->f_type
);
145 __put_user(host_statfs
->f_flags
, &target_statfs
->f_flags
);
146 __put_user(host_statfs
->f_bsize
, &target_statfs
->f_bsize
);
147 __put_user(host_statfs
->f_iosize
, &target_statfs
->f_iosize
);
148 __put_user(host_statfs
->f_blocks
, &target_statfs
->f_blocks
);
149 __put_user(host_statfs
->f_bfree
, &target_statfs
->f_bfree
);
150 __put_user(host_statfs
->f_bavail
, &target_statfs
->f_bavail
);
151 __put_user(host_statfs
->f_files
, &target_statfs
->f_files
);
152 __put_user(host_statfs
->f_ffree
, &target_statfs
->f_ffree
);
153 __put_user(host_statfs
->f_syncwrites
, &target_statfs
->f_syncwrites
);
154 __put_user(host_statfs
->f_asyncwrites
, &target_statfs
->f_asyncwrites
);
155 __put_user(host_statfs
->f_syncreads
, &target_statfs
->f_syncreads
);
156 __put_user(host_statfs
->f_asyncreads
, &target_statfs
->f_asyncreads
);
157 /* uint64_t f_spare[10]; */
158 __put_user(host_statfs
->f_namemax
, &target_statfs
->f_namemax
);
159 __put_user(host_statfs
->f_owner
, &target_statfs
->f_owner
);
160 __put_user(host_statfs
->f_fsid
.val
[0], &target_statfs
->f_fsid
.val
[0]);
161 __put_user(host_statfs
->f_fsid
.val
[1], &target_statfs
->f_fsid
.val
[1]);
162 /* char f_charspace[80]; */
163 strncpy(target_statfs
->f_fstypename
, host_statfs
->f_fstypename
,
164 sizeof(target_statfs
->f_fstypename
));
165 strncpy(target_statfs
->f_mntfromname
, host_statfs
->f_mntfromname
,
166 sizeof(target_statfs
->f_mntfromname
));
167 strncpy(target_statfs
->f_mntonname
, host_statfs
->f_mntonname
,
168 sizeof(target_statfs
->f_mntonname
));
169 unlock_user_struct(target_statfs
, target_addr
, 1);