sd.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Storage Device.
  3. */
  4. typedef struct SDev SDev;
  5. typedef struct SDifc SDifc;
  6. typedef struct SDpart SDpart;
  7. typedef struct SDperm SDperm;
  8. typedef struct SDreq SDreq;
  9. typedef struct SDunit SDunit;
  10. typedef struct SDwp SDwp;
  11. typedef struct SDcache SDcache;
  12. enum {
  13. SDcachesize = 20,
  14. };
  15. struct SDperm {
  16. char* name;
  17. char* user;
  18. ulong perm;
  19. };
  20. struct SDpart {
  21. ulong start;
  22. ulong end;
  23. SDperm;
  24. int valid;
  25. ulong vers;
  26. };
  27. struct SDcache {
  28. ulong age;
  29. ulong bn;
  30. uchar *data;
  31. };
  32. struct SDwp {
  33. QLock;
  34. ulong age;
  35. ulong start;
  36. ulong end;
  37. SDcache cache[SDcachesize];
  38. };
  39. struct SDunit {
  40. SDev* dev;
  41. int subno;
  42. uchar inquiry[256]; /* format follows SCSI spec */
  43. SDperm;
  44. Rendez rendez;
  45. QLock ctl;
  46. ulong sectors;
  47. ulong secsize;
  48. SDpart* part; /* nil or array of size npart */
  49. int npart;
  50. ulong vers;
  51. SDperm ctlperm;
  52. QLock raw; /* raw read or write in progress */
  53. ulong rawinuse; /* really just a test-and-set */
  54. int state;
  55. SDreq* req;
  56. SDperm rawperm;
  57. int wpunit; /* whole unit is write protected */
  58. SDwp *wp; /* block level write prtection */
  59. };
  60. /*
  61. * Each controller is represented by a SDev.
  62. * Each controller is responsible for allocating its unit structures.
  63. * Each controller has at least one unit.
  64. */
  65. struct SDev {
  66. Ref r; /* Number of callers using device */
  67. SDifc* ifc; /* pnp/legacy */
  68. void* ctlr;
  69. int idno;
  70. char* name;
  71. SDev* next;
  72. QLock; /* enable/disable */
  73. int enabled;
  74. int nunit; /* Number of units */
  75. QLock unitlock; /* `Loading' of units */
  76. int* unitflg; /* Unit flags */
  77. SDunit**unit;
  78. };
  79. struct SDifc {
  80. char* name;
  81. SDev* (*pnp)(void);
  82. SDev* (*legacy)(int, int);
  83. SDev* (*id)(SDev*);
  84. int (*enable)(SDev*);
  85. int (*disable)(SDev*);
  86. int (*verify)(SDunit*);
  87. int (*online)(SDunit*);
  88. int (*rio)(SDreq*);
  89. int (*rctl)(SDunit*, char*, int);
  90. int (*wctl)(SDunit*, Cmdbuf*);
  91. long (*bio)(SDunit*, int, int, void*, long, long);
  92. SDev* (*probe)(DevConf*);
  93. void (*clear)(SDev*);
  94. char* (*stat)(SDev*, char*, char*);
  95. };
  96. struct SDreq {
  97. SDunit* unit;
  98. int lun;
  99. int write;
  100. uchar cmd[16];
  101. int clen;
  102. void* data;
  103. int dlen;
  104. int flags;
  105. int status;
  106. long rlen;
  107. uchar sense[256];
  108. };
  109. enum {
  110. SDnosense = 0x00000001,
  111. SDvalidsense = 0x00010000,
  112. };
  113. enum {
  114. SDretry = -5, /* internal to controllers */
  115. SDmalloc = -4,
  116. SDeio = -3,
  117. SDtimeout = -2,
  118. SDnostatus = -1,
  119. SDok = 0,
  120. SDcheck = 0x02, /* check condition */
  121. SDbusy = 0x08, /* busy */
  122. SDmaxio = 2048*1024,
  123. SDnpart = 16,
  124. };
  125. #define sdmalloc(n) malloc(n)
  126. #define sdfree(p) free(p)
  127. /* sdscsi.c */
  128. extern int scsiverify(SDunit*);
  129. extern int scsionline(SDunit*);
  130. extern long scsibio(SDunit*, int, int, void*, long, long);
  131. extern SDev* scsiid(SDev*, SDifc*);