sd.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. QLock ctl;
  45. ulong sectors;
  46. ulong secsize;
  47. SDpart* part; /* nil or array of size npart */
  48. int npart;
  49. ulong vers;
  50. SDperm ctlperm;
  51. QLock raw; /* raw read or write in progress */
  52. ulong rawinuse; /* really just a test-and-set */
  53. int state;
  54. SDreq* req;
  55. SDperm rawperm;
  56. int wpunit; /* whole unit is write protected */
  57. SDwp *wp; /* block level write prtection */
  58. };
  59. /*
  60. * Each controller is represented by a SDev.
  61. * Each controller is responsible for allocating its unit structures.
  62. * Each controller has at least one unit.
  63. */
  64. struct SDev {
  65. Ref r; /* Number of callers using device */
  66. SDifc* ifc; /* pnp/legacy */
  67. void* ctlr;
  68. int idno;
  69. char* name;
  70. SDev* next;
  71. QLock; /* enable/disable */
  72. int enabled;
  73. int nunit; /* Number of units */
  74. QLock unitlock; /* `Loading' of units */
  75. int* unitflg; /* Unit flags */
  76. SDunit**unit;
  77. };
  78. struct SDifc {
  79. char* name;
  80. SDev* (*pnp)(void);
  81. SDev* (*legacy)(int, int);
  82. SDev* (*id)(SDev*);
  83. int (*enable)(SDev*);
  84. int (*disable)(SDev*);
  85. int (*verify)(SDunit*);
  86. int (*online)(SDunit*);
  87. int (*rio)(SDreq*);
  88. int (*rctl)(SDunit*, char*, int);
  89. int (*wctl)(SDunit*, Cmdbuf*);
  90. long (*bio)(SDunit*, int, int, void*, long, long);
  91. SDev* (*probe)(DevConf*);
  92. void (*clear)(SDev*);
  93. char* (*stat)(SDev*, char*, char*);
  94. };
  95. struct SDreq {
  96. SDunit* unit;
  97. int lun;
  98. int write;
  99. uchar cmd[16];
  100. int clen;
  101. void* data;
  102. int dlen;
  103. int flags;
  104. int status;
  105. long rlen;
  106. uchar sense[256];
  107. };
  108. enum {
  109. SDnosense = 0x00000001,
  110. SDvalidsense = 0x00010000,
  111. };
  112. enum {
  113. SDretry = -5, /* internal to controllers */
  114. SDmalloc = -4,
  115. SDeio = -3,
  116. SDtimeout = -2,
  117. SDnostatus = -1,
  118. SDok = 0,
  119. SDcheck = 0x02, /* check condition */
  120. SDbusy = 0x08, /* busy */
  121. SDmaxio = 2048*1024,
  122. SDnpart = 16,
  123. };
  124. #define sdmalloc(n) malloc(n)
  125. #define sdfree(p) free(p)
  126. /* sdscsi.c */
  127. extern int scsiverify(SDunit*);
  128. extern int scsionline(SDunit*);
  129. extern long scsibio(SDunit*, int, int, void*, long, long);
  130. extern SDev* scsiid(SDev*, SDifc*);