monstruct.c 5.0 KB

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