monstruct.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. Moving system structs between UNIX and EM
  3. */
  4. /* $Id$ */
  5. #include "sysidf.h"
  6. #include "v7ioctl.h"
  7. #include "global.h"
  8. #include "mem.h"
  9. #include "monstruct.h"
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #if __STDC__
  13. #include <time.h>
  14. #endif
  15. #include <sys/times.h>
  16. #ifdef WANT_SGTTY
  17. #include <sgtty.h>
  18. #endif
  19. #ifdef BSD_X /* from system.h */
  20. #include <sys/timeb.h>
  21. #endif /* BSD_X */
  22. #ifdef SYS_V /* from system.h */
  23. struct timeb { /* non-existing; we use an ad-hoc definition */
  24. long time;
  25. unsigned short millitm;
  26. short timezone, dstflag;
  27. }
  28. #endif /* SYS_V */
  29. /******** System to EM memory ********/
  30. PRIVATE mem_stfld(addr, offset, length, val)
  31. ptr addr;
  32. size offset, length;
  33. long val;
  34. {
  35. mem_stn(addr + offset, val, length);
  36. }
  37. int stat2mem(addr, statb)
  38. ptr addr;
  39. struct stat *statb;
  40. {
  41. if (memfault(addr, V7st_sz))
  42. return 0;
  43. mem_stfld(addr, V7st_dev, (long) statb->st_dev);
  44. mem_stfld(addr, V7st_ino, (long) statb->st_ino);
  45. mem_stfld(addr, V7st_mode, (long) statb->st_mode);
  46. mem_stfld(addr, V7st_nlink, (long) statb->st_nlink);
  47. mem_stfld(addr, V7st_uid, (long) statb->st_uid);
  48. mem_stfld(addr, V7st_gid, (long) statb->st_gid);
  49. mem_stfld(addr, V7st_rdev, (long) statb->st_rdev);
  50. mem_stfld(addr, V7st_size, (long) statb->st_size);
  51. mem_stfld(addr, V7st_atime, (long) statb->st_atime);
  52. mem_stfld(addr, V7st_mtime, (long) statb->st_mtime);
  53. mem_stfld(addr, V7st_ctime, (long) statb->st_ctime);
  54. return 1;
  55. }
  56. int timeb2mem(addr, timebb)
  57. ptr addr;
  58. struct timeb *timebb;
  59. {
  60. if (memfault(addr, V7tb_sz))
  61. return 0;
  62. mem_stfld(addr, V7tb_time, (long) timebb->time);
  63. mem_stfld(addr, V7tb_millitm, (long) timebb->millitm);
  64. mem_stfld(addr, V7tb_timezone, (long) timebb->timezone);
  65. mem_stfld(addr, V7tb_dstflag, (long) timebb->dstflag);
  66. return 1;
  67. }
  68. int tms2mem(addr, tmsb)
  69. ptr addr;
  70. struct tms *tmsb;
  71. {
  72. if (memfault(addr, V7tms_sz))
  73. return 0;
  74. mem_stfld(addr, V7tms_utime, (long) tmsb->tms_utime);
  75. mem_stfld(addr, V7tms_stime, (long) tmsb->tms_stime);
  76. mem_stfld(addr, V7tms_cutime, (long) tmsb->tms_cutime);
  77. mem_stfld(addr, V7tms_cstime, (long) tmsb->tms_cstime);
  78. return 1;
  79. }
  80. #ifdef WANT_SGTTY
  81. /* FIXME: see the related fixme in sysidf.h. --- dtrg */
  82. int sgttyb2mem(addr, sgttybb)
  83. ptr addr;
  84. struct sgttyb *sgttybb;
  85. {
  86. if (memfault(addr, V7sg_sz))
  87. return 0;
  88. mem_stfld(addr, V7sg_ispeed, (long) sgttybb->sg_ispeed);
  89. mem_stfld(addr, V7sg_ospeed, (long) sgttybb->sg_ospeed);
  90. mem_stfld(addr, V7sg_erase, (long) sgttybb->sg_erase);
  91. mem_stfld(addr, V7sg_kill, (long) sgttybb->sg_kill);
  92. mem_stfld(addr, V7sg_flags, (long) sgttybb->sg_flags);
  93. return 1;
  94. }
  95. #endif
  96. #ifdef BSD_X /* from system.h */
  97. int tchars2mem(addr, tcharsb)
  98. ptr addr;
  99. struct tchars *tcharsb;
  100. {
  101. if (memfault(addr, V7t_sz_tch))
  102. return 0;
  103. mem_stfld(addr, V7t_intrc, (long) tcharsb->t_intrc);
  104. mem_stfld(addr, V7t_quitc, (long) tcharsb->t_quitc);
  105. mem_stfld(addr, V7t_startc, (long) tcharsb->t_startc);
  106. mem_stfld(addr, V7t_stopc, (long) tcharsb->t_stopc);
  107. mem_stfld(addr, V7t_eofc, (long) tcharsb->t_eofc);
  108. mem_stfld(addr, V7t_brkc, (long) tcharsb->t_brkc);
  109. return 1;
  110. }
  111. #ifndef V7IOCTL
  112. int ltchars2mem(addr, ltcharsb)
  113. ptr addr;
  114. struct ltchars *ltcharsb;
  115. {
  116. if (memfault(addr, V7t_sz_ltch))
  117. return 0;
  118. mem_stfld(addr, V7t_suspc, (long) ltcharsb->t_suspc);
  119. mem_stfld(addr, V7t_dsuspc, (long) ltcharsb->t_dsuspc);
  120. mem_stfld(addr, V7t_rprntc, (long) ltcharsb->t_rprntc);
  121. mem_stfld(addr, V7t_flushc, (long) ltcharsb->t_flushc);
  122. mem_stfld(addr, V7t_werasc, (long) ltcharsb->t_werasc);
  123. mem_stfld(addr, V7t_lnextc, (long) ltcharsb->t_lnextc);
  124. return 1;
  125. }
  126. #endif /* V7IOCTL */
  127. #endif /* BSD_X */
  128. /******** EM memory to system ********/
  129. PRIVATE unsigned long mem_ldfld(addr, offset, length)
  130. ptr addr;
  131. size offset, length;
  132. {
  133. return mem_ldu(addr + offset, length);
  134. }
  135. #ifdef WANT_SGTTY
  136. /* FIXME: see the related fixme in sysidf.h. --- dtrg */
  137. int mem2sgtty(addr, sgttybb)
  138. ptr addr;
  139. struct sgttyb *sgttybb;
  140. {
  141. if (memfault(addr, V7sg_sz))
  142. return 0;
  143. sgttybb->sg_ispeed = (char) mem_ldfld(addr, V7sg_ispeed);
  144. sgttybb->sg_ospeed = (char) mem_ldfld(addr, V7sg_ospeed);
  145. sgttybb->sg_erase = (char) mem_ldfld(addr, V7sg_erase);
  146. sgttybb->sg_kill = (char) mem_ldfld(addr, V7sg_kill);
  147. sgttybb->sg_flags = (short) mem_ldfld(addr, V7sg_flags);
  148. return 1;
  149. }
  150. #endif
  151. #ifdef BSD_X /* from system.h */
  152. int mem2tchars(addr, tcharsb)
  153. ptr addr;
  154. struct tchars *tcharsb;
  155. {
  156. if (memfault(addr, V7t_sz_tch))
  157. return 0;
  158. tcharsb->t_intrc = (char) mem_ldfld(addr, V7t_intrc);
  159. tcharsb->t_quitc = (char) mem_ldfld(addr, V7t_quitc);
  160. tcharsb->t_startc = (char) mem_ldfld(addr, V7t_startc);
  161. tcharsb->t_stopc = (char) mem_ldfld(addr, V7t_stopc);
  162. tcharsb->t_eofc = (char) mem_ldfld(addr, V7t_eofc);
  163. tcharsb->t_brkc = (char) mem_ldfld(addr, V7t_brkc);
  164. return 1;
  165. }
  166. #ifndef V7IOCTL
  167. int mem2ltchars(addr, ltcharsb)
  168. ptr addr;
  169. struct ltchars *ltcharsb;
  170. {
  171. if (memfault(addr, V7t_sz_ltch))
  172. return 0;
  173. ltcharsb->t_suspc = (char) mem_ldfld(addr, V7t_suspc);
  174. ltcharsb->t_dsuspc = (char) mem_ldfld(addr, V7t_dsuspc);
  175. ltcharsb->t_rprntc = (char) mem_ldfld(addr, V7t_rprntc);
  176. ltcharsb->t_flushc = (char) mem_ldfld(addr, V7t_flushc);
  177. ltcharsb->t_werasc = (char) mem_ldfld(addr, V7t_werasc);
  178. ltcharsb->t_lnextc = (char) mem_ldfld(addr, V7t_lnextc);
  179. return 1;
  180. }
  181. #endif /* V7IOCTL */
  182. #endif /* BSD_X */