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 /* 96 * file handle conversion 97 */ 98 abi_long t2h_freebsd_fhandle(fhandle_t *host_fh, abi_ulong target_addr) 99 { 100 target_freebsd_fhandle_t *target_fh; 101 102 if (!lock_user_struct(VERIFY_READ, target_fh, target_addr, 1)) { 103 return -TARGET_EFAULT; 104 } 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, 110 TARGET_MAXFIDSZ); 111 unlock_user_struct(target_fh, target_addr, 0); 112 return 0; 113 } 114 115 abi_long h2t_freebsd_fhandle(abi_ulong target_addr, fhandle_t *host_fh) 116 { 117 target_freebsd_fhandle_t *target_fh; 118 119 if (!lock_user_struct(VERIFY_WRITE, target_fh, target_addr, 0)) { 120 return -TARGET_EFAULT; 121 } 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, 127 TARGET_MAXFIDSZ); 128 unlock_user_struct(target_fh, target_addr, 1); 129 return 0; 130 } 131 132 /* 133 * file system stat 134 */ 135 abi_long h2t_freebsd11_statfs(abi_ulong target_addr, 136 struct freebsd11_statfs *host_statfs) 137 { 138 struct target_freebsd11_statfs *target_statfs; 139 140 if (!lock_user_struct(VERIFY_WRITE, target_statfs, target_addr, 0)) { 141 return -TARGET_EFAULT; 142 } 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); 170 return 0; 171 } 172 173 /* 174 * fcntl cmd conversion 175 */ 176 abi_long target_to_host_fcntl_cmd(int cmd) 177 { 178 return cmd; 179 } 180 181