xref: /openbmc/qemu/bsd-user/freebsd/os-stat.c (revision 86547e57)
1 /*
2  *  FreeBSD stat related conversion routines
3  *
4  *  Copyright (c) 2013 Stacey D. Son
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 #include "qemu/osdep.h"
20 
21 #include "qemu.h"
22 
23 /*
24  * stat conversion
25  */
26 abi_long h2t_freebsd11_stat(abi_ulong target_addr,
27         struct freebsd11_stat *host_st)
28 {
29     struct target_freebsd11_stat *target_st;
30 
31     if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
32         return -TARGET_EFAULT;
33     }
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);
57 
58     return 0;
59 }
60 
61 abi_long h2t_freebsd11_nstat(abi_ulong target_addr,
62         struct freebsd11_stat *host_st)
63 {
64     struct target_freebsd11_nstat *target_st;
65 
66     if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) {
67         return -TARGET_EFAULT;
68     }
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);
91 
92     return 0;
93 }
94 
95