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