aoeata.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <ip.h>
  4. #include "dat.h"
  5. #include "protos.h"
  6. typedef struct{
  7. uchar aflag;
  8. uchar feat;
  9. uchar sectors;
  10. uchar cmd;
  11. uchar lba[6];
  12. }Hdr;
  13. enum{
  14. Hsize = 10,
  15. };
  16. enum{
  17. Oaflag,
  18. Ocmd,
  19. Ofeat,
  20. Osectors,
  21. Olba,
  22. Ostat,
  23. Oerr,
  24. };
  25. static Field p_fields[] =
  26. {
  27. {"aflag", Fnum, Oaflag, "aflag", },
  28. {"cmd", Fnum, Ocmd, "command register", },
  29. {"feat", Fnum, Ofeat, "features", },
  30. {"sectors", Fnum, Osectors, "number of sectors", },
  31. {"lba", Fnum, Olba, "lba", },
  32. {"stat", Fnum, Ostat, "status", },
  33. {"err", Fnum, Oerr, "error", },
  34. {0}
  35. };
  36. static void
  37. p_compile(Filter *f)
  38. {
  39. if(f->op == '='){
  40. compile_cmp(aoeata.name, f, p_fields);
  41. return;
  42. }
  43. sysfatal("unknown aoeata field: %s", f->s);
  44. }
  45. uvlong
  46. llba(uchar *c)
  47. {
  48. uvlong l;
  49. l = c[0];
  50. l |= c[1]<<8;
  51. l |= c[2]<<16;
  52. l |= c[3]<<24;
  53. l |= (uvlong)c[4]<<32;
  54. l |= (uvlong)c[5]<<40;
  55. return l;
  56. }
  57. static int
  58. p_filter(Filter *f, Msg *m)
  59. {
  60. Hdr *h;
  61. if(m->pe - m->ps < Hsize)
  62. return 0;
  63. h = (Hdr*)m->ps;
  64. m->ps += Hsize;
  65. switch(f->subop){
  66. case Oaflag:
  67. return h->aflag == f->ulv;
  68. case Ocmd:
  69. return h->cmd == f->ulv;
  70. case Ofeat:
  71. return h->feat == f->ulv;
  72. case Osectors:
  73. return h->sectors == f->ulv;
  74. case Olba:
  75. return llba(h->lba) == f->vlv;
  76. /* this is wrong, but we don't have access to the direction here */
  77. case Ostat:
  78. return h->cmd == f->ulv;
  79. case Oerr:
  80. return h->feat == f->ulv;
  81. }
  82. return 0;
  83. }
  84. static int
  85. p_seprint(Msg *m)
  86. {
  87. Hdr *h;
  88. if(m->pe - m->ps < Hsize)
  89. return 0;
  90. h = (Hdr*)m->ps;
  91. m->ps += Hsize;
  92. /* no next protocol */
  93. m->pr = nil;
  94. m->p = seprint(m->p, m->e, "aflag=%ux errfeat=%ux sectors=%ux cmdstat=%ux lba=%lld",
  95. h->aflag, h->feat, h->sectors, h->cmd, llba(h->lba));
  96. return 0;
  97. }
  98. Proto aoeata =
  99. {
  100. "aoeata",
  101. p_compile,
  102. p_filter,
  103. p_seprint,
  104. nil,
  105. nil,
  106. p_fields,
  107. defaultframer,
  108. };