2
0

os-stat.c 11 KB

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