sd.h 2.3 KB

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