master
c 251 lines 10.4 KB
Raw
1 /*
2 * FreeBSD stat related conversion routines
3 *
4 * Copyright (c) 2013 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #include "qemu/osdep.h"
9
10 #include "qemu.h"
11
12 /*
13 * stat conversion
14 */
15 abi_long h2t_freebsd11_stat(abi_ulong target_addr,
16 struct freebsd11_stat *host_st)
17 {
18 struct target_freebsd11_stat *target_st;
19
20 if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
21 return -TARGET_EFAULT;
22 }
23 memset(target_st, 0, sizeof(*target_st));
24 __put_user(host_st->st_dev, &target_st->st_dev);
25 __put_user(host_st->st_ino, &target_st->st_ino);
26 __put_user(host_st->st_mode, &target_st->st_mode);
27 __put_user(host_st->st_nlink, &target_st->st_nlink);
28 __put_user(host_st->st_uid, &target_st->st_uid);
29 __put_user(host_st->st_gid, &target_st->st_gid);
30 __put_user(host_st->st_rdev, &target_st->st_rdev);
31 __put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
32 __put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
33 __put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
34 __put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
35 __put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
36 __put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
37 __put_user(host_st->st_size, &target_st->st_size);
38 __put_user(host_st->st_blocks, &target_st->st_blocks);
39 __put_user(host_st->st_blksize, &target_st->st_blksize);
40 __put_user(host_st->st_flags, &target_st->st_flags);
41 __put_user(host_st->st_gen, &target_st->st_gen);
42 /* st_lspare not used */
43 __put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
44 __put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
45 unlock_user_struct(target_st, target_addr, 1);
46
47 return 0;
48 }
49
50 abi_long h2t_freebsd_stat(abi_ulong target_addr,
51 struct stat *host_st)
52 {
53 struct target_stat *target_st;
54
55 if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
56 return -TARGET_EFAULT;
57 }
58 memset(target_st, 0, sizeof(*target_st));
59 __put_user(host_st->st_dev, &target_st->st_dev);
60 __put_user(host_st->st_ino, &target_st->st_ino);
61 __put_user(host_st->st_nlink, &target_st->st_nlink);
62 __put_user(host_st->st_mode, &target_st->st_mode);
63 __put_user(host_st->st_uid, &target_st->st_uid);
64 __put_user(host_st->st_gid, &target_st->st_gid);
65 __put_user(host_st->st_rdev, &target_st->st_rdev);
66 __put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
67 __put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
68 #ifdef TARGET_HAS_STAT_TIME_T_EXT
69 /* __put_user(host_st->st_mtim_ext, &target_st->st_mtim_ext); XXX */
70 #endif
71 __put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
72 __put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
73 #ifdef TARGET_HAS_STAT_TIME_T_EXT
74 /* __put_user(host_st->st_ctim_ext, &target_st->st_ctim_ext); XXX */
75 #endif
76 __put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
77 __put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
78 #ifdef TARGET_HAS_STAT_TIME_T_EXT
79 /* __put_user(host_st->st_birthtim_ext, &target_st->st_birthtim_ext); XXX */
80 #endif
81 __put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
82 __put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
83
84 __put_user(host_st->st_size, &target_st->st_size);
85 __put_user(host_st->st_blocks, &target_st->st_blocks);
86 __put_user(host_st->st_blksize, &target_st->st_blksize);
87 __put_user(host_st->st_flags, &target_st->st_flags);
88 __put_user(host_st->st_gen, &target_st->st_gen);
89 unlock_user_struct(target_st, target_addr, 1);
90
91 return 0;
92 }
93
94 abi_long h2t_freebsd11_nstat(abi_ulong target_addr,
95 struct freebsd11_stat *host_st)
96 {
97 struct target_freebsd11_nstat *target_st;
98
99 if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
100 return -TARGET_EFAULT;
101 }
102 memset(target_st, 0, sizeof(*target_st));
103 __put_user(host_st->st_dev, &target_st->st_dev);
104 __put_user(host_st->st_ino, &target_st->st_ino);
105 __put_user(host_st->st_mode, &target_st->st_mode);
106 __put_user(host_st->st_nlink, &target_st->st_nlink);
107 __put_user(host_st->st_uid, &target_st->st_uid);
108 __put_user(host_st->st_gid, &target_st->st_gid);
109 __put_user(host_st->st_rdev, &target_st->st_rdev);
110 __put_user(host_st->st_atim.tv_sec, &target_st->st_atim.tv_sec);
111 __put_user(host_st->st_atim.tv_nsec, &target_st->st_atim.tv_nsec);
112 __put_user(host_st->st_mtim.tv_sec, &target_st->st_mtim.tv_sec);
113 __put_user(host_st->st_mtim.tv_nsec, &target_st->st_mtim.tv_nsec);
114 __put_user(host_st->st_ctim.tv_sec, &target_st->st_ctim.tv_sec);
115 __put_user(host_st->st_ctim.tv_nsec, &target_st->st_ctim.tv_nsec);
116 __put_user(host_st->st_size, &target_st->st_size);
117 __put_user(host_st->st_blocks, &target_st->st_blocks);
118 __put_user(host_st->st_blksize, &target_st->st_blksize);
119 __put_user(host_st->st_flags, &target_st->st_flags);
120 __put_user(host_st->st_gen, &target_st->st_gen);
121 __put_user(host_st->st_birthtim.tv_sec, &target_st->st_birthtim.tv_sec);
122 __put_user(host_st->st_birthtim.tv_nsec, &target_st->st_birthtim.tv_nsec);
123 unlock_user_struct(target_st, target_addr, 1);
124
125 return 0;
126 }
127
128 /*
129 * file handle conversion
130 */
131 abi_long t2h_freebsd_fhandle(fhandle_t *host_fh, abi_ulong target_addr)
132 {
133 target_freebsd_fhandle_t *target_fh;
134
135 if (!lock_user_struct(VERIFY_READ, target_fh, target_addr, 1)) {
136 return -TARGET_EFAULT;
137 }
138 __get_user(host_fh->fh_fsid.val[0], &target_fh->fh_fsid.val[0]);
139 __get_user(host_fh->fh_fsid.val[1], &target_fh->fh_fsid.val[0]);
140 __get_user(host_fh->fh_fid.fid_len, &target_fh->fh_fid.fid_len);
141 /* u_short fid_data0; */
142 memcpy(host_fh->fh_fid.fid_data, target_fh->fh_fid.fid_data,
143 TARGET_MAXFIDSZ);
144 unlock_user_struct(target_fh, target_addr, 0);
145 return 0;
146 }
147
148 abi_long h2t_freebsd_fhandle(abi_ulong target_addr, fhandle_t *host_fh)
149 {
150 target_freebsd_fhandle_t *target_fh;
151
152 if (!lock_user_struct(VERIFY_WRITE, target_fh, target_addr, 0)) {
153 return -TARGET_EFAULT;
154 }
155 __put_user(host_fh->fh_fsid.val[0], &target_fh->fh_fsid.val[0]);
156 __put_user(host_fh->fh_fsid.val[1], &target_fh->fh_fsid.val[0]);
157 __put_user(host_fh->fh_fid.fid_len, &target_fh->fh_fid.fid_len);
158 /* u_short fid_data0; */
159 memcpy(target_fh->fh_fid.fid_data, host_fh->fh_fid.fid_data,
160 TARGET_MAXFIDSZ);
161 unlock_user_struct(target_fh, target_addr, 1);
162 return 0;
163 }
164
165 /*
166 * file system stat
167 */
168 abi_long h2t_freebsd11_statfs(abi_ulong target_addr,
169 struct freebsd11_statfs *host_statfs)
170 {
171 struct target_freebsd11_statfs *target_statfs;
172
173 if (!lock_user_struct(VERIFY_WRITE, target_statfs, target_addr, 0)) {
174 return -TARGET_EFAULT;
175 }
176 __put_user(host_statfs->f_version, &target_statfs->f_version);
177 __put_user(host_statfs->f_type, &target_statfs->f_type);
178 __put_user(host_statfs->f_flags, &target_statfs->f_flags);
179 __put_user(host_statfs->f_bsize, &target_statfs->f_bsize);
180 __put_user(host_statfs->f_iosize, &target_statfs->f_iosize);
181 __put_user(host_statfs->f_blocks, &target_statfs->f_blocks);
182 __put_user(host_statfs->f_bfree, &target_statfs->f_bfree);
183 __put_user(host_statfs->f_bavail, &target_statfs->f_bavail);
184 __put_user(host_statfs->f_files, &target_statfs->f_files);
185 __put_user(host_statfs->f_ffree, &target_statfs->f_ffree);
186 __put_user(host_statfs->f_syncwrites, &target_statfs->f_syncwrites);
187 __put_user(host_statfs->f_asyncwrites, &target_statfs->f_asyncwrites);
188 __put_user(host_statfs->f_syncreads, &target_statfs->f_syncreads);
189 __put_user(host_statfs->f_asyncreads, &target_statfs->f_asyncreads);
190 /* uint64_t f_spare[10]; */
191 __put_user(host_statfs->f_namemax, &target_statfs->f_namemax);
192 __put_user(host_statfs->f_owner, &target_statfs->f_owner);
193 __put_user(host_statfs->f_fsid.val[0], &target_statfs->f_fsid.val[0]);
194 __put_user(host_statfs->f_fsid.val[1], &target_statfs->f_fsid.val[1]);
195 /* char f_charspace[80]; */
196 strncpy(target_statfs->f_fstypename, host_statfs->f_fstypename,
197 sizeof(target_statfs->f_fstypename));
198 strncpy(target_statfs->f_mntfromname, host_statfs->f_mntfromname,
199 sizeof(target_statfs->f_mntfromname));
200 strncpy(target_statfs->f_mntonname, host_statfs->f_mntonname,
201 sizeof(target_statfs->f_mntonname));
202 unlock_user_struct(target_statfs, target_addr, 1);
203 return 0;
204 }
205
206 abi_long h2t_freebsd_statfs(abi_ulong target_addr,
207 struct statfs *host_statfs)
208 {
209 struct target_statfs *target_statfs;
210
211 if (!lock_user_struct(VERIFY_WRITE, target_statfs, target_addr, 0)) {
212 return -TARGET_EFAULT;
213 }
214 __put_user(host_statfs->f_version, &target_statfs->f_version);
215 __put_user(host_statfs->f_type, &target_statfs->f_type);
216 __put_user(host_statfs->f_flags, &target_statfs->f_flags);
217 __put_user(host_statfs->f_bsize, &target_statfs->f_bsize);
218 __put_user(host_statfs->f_iosize, &target_statfs->f_iosize);
219 __put_user(host_statfs->f_blocks, &target_statfs->f_blocks);
220 __put_user(host_statfs->f_bfree, &target_statfs->f_bfree);
221 __put_user(host_statfs->f_bavail, &target_statfs->f_bavail);
222 __put_user(host_statfs->f_files, &target_statfs->f_files);
223 __put_user(host_statfs->f_ffree, &target_statfs->f_ffree);
224 __put_user(host_statfs->f_syncwrites, &target_statfs->f_syncwrites);
225 __put_user(host_statfs->f_asyncwrites, &target_statfs->f_asyncwrites);
226 __put_user(host_statfs->f_syncreads, &target_statfs->f_syncreads);
227 __put_user(host_statfs->f_asyncreads, &target_statfs->f_asyncreads);
228 /* uint64_t f_spare[10]; */
229 __put_user(host_statfs->f_namemax, &target_statfs->f_namemax);
230 __put_user(host_statfs->f_owner, &target_statfs->f_owner);
231 __put_user(host_statfs->f_fsid.val[0], &target_statfs->f_fsid.val[0]);
232 __put_user(host_statfs->f_fsid.val[1], &target_statfs->f_fsid.val[1]);
233 /* char f_charspace[80]; */
234 strncpy(target_statfs->f_fstypename, host_statfs->f_fstypename,
235 sizeof(target_statfs->f_fstypename));
236 strncpy(target_statfs->f_mntfromname, host_statfs->f_mntfromname,
237 sizeof(target_statfs->f_mntfromname));
238 strncpy(target_statfs->f_mntonname, host_statfs->f_mntonname,
239 sizeof(target_statfs->f_mntonname));
240 unlock_user_struct(target_statfs, target_addr, 1);
241 return 0;
242 }
243
244 /*
245 * fcntl cmd conversion
246 */
247 abi_long target_to_host_fcntl_cmd(int cmd)
248 {
249 return cmd;
250 }
251