styxaux.b 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. implement Styxaux;
  2. include "sys.m";
  3. sys: Sys;
  4. include "styx.m";
  5. include "styxaux.m";
  6. Tmsg : import Styx;
  7. init()
  8. {
  9. }
  10. msize(m: ref Tmsg): int
  11. {
  12. pick fc := m {
  13. Version => return fc.msize;
  14. }
  15. error("bad styx msize", m);
  16. return 0;
  17. }
  18. version(m: ref Tmsg): string
  19. {
  20. pick fc := m {
  21. Version => return fc.version;
  22. }
  23. error("bad styx version", m);
  24. return nil;
  25. }
  26. fid(m: ref Tmsg): int
  27. {
  28. pick fc := m {
  29. Readerror => return 0;
  30. Version => return 0;
  31. Flush => return 0;
  32. Walk => return fc.fid;
  33. Open => return fc.fid;
  34. Create => return fc.fid;
  35. Read => return fc.fid;
  36. Write => return fc.fid;
  37. Clunk => return fc.fid;
  38. Remove => return fc.fid;
  39. Stat => return fc.fid;
  40. Wstat => return fc.fid;
  41. Attach => return fc.fid;
  42. }
  43. error("bad styx fid", m);
  44. return 0;
  45. }
  46. uname(m: ref Tmsg): string
  47. {
  48. pick fc := m {
  49. Attach => return fc.uname;
  50. }
  51. error("bad styx uname", m);
  52. return nil;
  53. }
  54. aname(m: ref Tmsg): string
  55. {
  56. pick fc := m {
  57. Attach => return fc.aname;
  58. }
  59. error("bad styx aname", m);
  60. return nil;
  61. }
  62. newfid(m: ref Tmsg): int
  63. {
  64. pick fc := m {
  65. Walk => return fc.newfid;
  66. }
  67. error("bad styx newfd", m);
  68. return 0;
  69. }
  70. name(m: ref Tmsg): string
  71. {
  72. pick fc := m {
  73. Create => return fc.name;
  74. }
  75. error("bad styx name", m);
  76. return nil;
  77. }
  78. names(m: ref Tmsg): array of string
  79. {
  80. pick fc := m {
  81. Walk => return fc.names;
  82. }
  83. error("bad styx names", m);
  84. return nil;
  85. }
  86. mode(m: ref Tmsg): int
  87. {
  88. pick fc := m {
  89. Open => return fc.mode;
  90. }
  91. error("bad styx mode", m);
  92. return 0;
  93. }
  94. setmode(m: ref Tmsg, mode: int)
  95. {
  96. pick fc := m {
  97. Open => fc.mode = mode;
  98. * => error("bad styx setmode", m);
  99. }
  100. }
  101. offset(m: ref Tmsg): big
  102. {
  103. pick fc := m {
  104. Read => return fc.offset;
  105. Write => return fc.offset;
  106. }
  107. error("bad styx offset", m);
  108. return big 0;
  109. }
  110. count(m: ref Tmsg): int
  111. {
  112. pick fc := m {
  113. Read => return fc.count;
  114. Write => return len fc.data;
  115. }
  116. error("bad styx count", m);
  117. return 0;
  118. }
  119. setcount(m: ref Tmsg, count: int)
  120. {
  121. pick fc := m {
  122. Read => fc.count = count;
  123. * => error("bad styx setcount", m);
  124. }
  125. }
  126. oldtag(m: ref Tmsg): int
  127. {
  128. pick fc := m {
  129. Flush => return fc.oldtag;
  130. }
  131. error("bad styx oldtag", m);
  132. return 0;
  133. }
  134. data(m: ref Tmsg): array of byte
  135. {
  136. pick fc := m {
  137. Write => return fc.data;
  138. }
  139. error("bad styx data", m);
  140. return nil;
  141. }
  142. setdata(m: ref Tmsg, data: array of byte)
  143. {
  144. pick fc := m {
  145. Write => fc.data = data;
  146. * => error("bad styx setdata", m);
  147. }
  148. }
  149. error(s: string, m: ref Tmsg)
  150. {
  151. if(sys == nil)
  152. sys = load Sys Sys->PATH;
  153. sys->fprint(sys->fildes(2), "%s %d\n", s, tagof m);
  154. }