devsd.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. /*
  2. * Storage Device.
  3. */
  4. #include "u.h"
  5. #include "../port/lib.h"
  6. #include "mem.h"
  7. #include "dat.h"
  8. #include "fns.h"
  9. #include "io.h"
  10. #include "ureg.h"
  11. #include "../port/error.h"
  12. #include "../port/sd.h"
  13. extern Dev sddevtab;
  14. extern SDifc* sdifc[];
  15. typedef struct {
  16. SDev* dt_dev;
  17. int dt_nunits; /* num units in dev */
  18. } dev_t;
  19. static dev_t* devs; /* all devices */
  20. static QLock devslock; /* insertion and removal of devices */
  21. static int ndevs; /* total number of devices in the system */
  22. enum {
  23. Rawcmd,
  24. Rawdata,
  25. Rawstatus,
  26. };
  27. enum {
  28. Qtopdir = 1, /* top level directory */
  29. Qtopbase,
  30. Qtopctl = Qtopbase,
  31. Qtopstat,
  32. Qunitdir, /* directory per unit */
  33. Qunitbase,
  34. Qctl = Qunitbase,
  35. Qraw,
  36. Qpart,
  37. TypeLOG = 4,
  38. NType = (1<<TypeLOG),
  39. TypeMASK = (NType-1),
  40. TypeSHIFT = 0,
  41. PartLOG = 8,
  42. NPart = (1<<PartLOG),
  43. PartMASK = (NPart-1),
  44. PartSHIFT = TypeLOG,
  45. UnitLOG = 8,
  46. NUnit = (1<<UnitLOG),
  47. UnitMASK = (NUnit-1),
  48. UnitSHIFT = (PartLOG+TypeLOG),
  49. DevLOG = 8,
  50. NDev = (1 << DevLOG),
  51. DevMASK = (NDev-1),
  52. DevSHIFT = (UnitLOG+PartLOG+TypeLOG),
  53. Ncmd = 20,
  54. };
  55. #define TYPE(q) ((((ulong)(q).path)>>TypeSHIFT) & TypeMASK)
  56. #define PART(q) ((((ulong)(q).path)>>PartSHIFT) & PartMASK)
  57. #define UNIT(q) ((((ulong)(q).path)>>UnitSHIFT) & UnitMASK)
  58. #define DEV(q) ((((ulong)(q).path)>>DevSHIFT) & DevMASK)
  59. #define QID(d,u, p, t) (((d)<<DevSHIFT)|((u)<<UnitSHIFT)|\
  60. ((p)<<PartSHIFT)|((t)<<TypeSHIFT))
  61. static void
  62. sdaddpart(SDunit* unit, char* name, ulong start, ulong end)
  63. {
  64. SDpart *pp;
  65. int i, partno;
  66. /*
  67. * Check name not already used
  68. * and look for a free slot.
  69. */
  70. if(unit->part != nil){
  71. partno = -1;
  72. for(i = 0; i < unit->npart; i++){
  73. pp = &unit->part[i];
  74. if(!pp->valid){
  75. if(partno == -1)
  76. partno = i;
  77. break;
  78. }
  79. if(strcmp(name, pp->name) == 0){
  80. if(pp->start == start && pp->end == end)
  81. return;
  82. error(Ebadctl);
  83. }
  84. }
  85. }
  86. else{
  87. if((unit->part = malloc(sizeof(SDpart)*SDnpart)) == nil)
  88. error(Enomem);
  89. unit->npart = SDnpart;
  90. partno = 0;
  91. }
  92. /*
  93. * If no free slot found then increase the
  94. * array size (can't get here with unit->part == nil).
  95. */
  96. if(partno == -1){
  97. if(unit->npart >= NPart)
  98. error(Enomem);
  99. if((pp = malloc(sizeof(SDpart)*(unit->npart+SDnpart))) == nil)
  100. error(Enomem);
  101. memmove(pp, unit->part, sizeof(SDpart)*unit->npart);
  102. free(unit->part);
  103. unit->part = pp;
  104. partno = unit->npart;
  105. unit->npart += SDnpart;
  106. }
  107. /*
  108. * Check size and extent are valid.
  109. */
  110. if(start > end || end > unit->sectors)
  111. error(Eio);
  112. pp = &unit->part[partno];
  113. pp->start = start;
  114. pp->end = end;
  115. kstrdup(&pp->name, name);
  116. kstrdup(&pp->user, eve);
  117. pp->perm = 0640;
  118. pp->valid = 1;
  119. }
  120. static void
  121. sddelpart(SDunit* unit, char* name)
  122. {
  123. int i;
  124. SDpart *pp;
  125. /*
  126. * Look for the partition to delete.
  127. * Can't delete if someone still has it open.
  128. */
  129. pp = unit->part;
  130. for(i = 0; i < unit->npart; i++){
  131. if(strcmp(name, pp->name) == 0)
  132. break;
  133. pp++;
  134. }
  135. if(i >= unit->npart)
  136. error(Ebadctl);
  137. if(strcmp(up->user, pp->user) && !iseve())
  138. error(Eperm);
  139. pp->valid = 0;
  140. pp->vers++;
  141. }
  142. static int
  143. sdinitpart(SDunit* unit)
  144. {
  145. int i, nf;
  146. ulong start, end;
  147. char *f[4], *p, *q, buf[10];
  148. unit->vers++;
  149. unit->sectors = unit->secsize = 0;
  150. if(unit->part){
  151. for(i = 0; i < unit->npart; i++){
  152. unit->part[i].valid = 0;
  153. unit->part[i].vers++;
  154. }
  155. }
  156. if(unit->inquiry[0] & 0xC0)
  157. return 0;
  158. switch(unit->inquiry[0] & 0x1F){
  159. case 0x00: /* DA */
  160. case 0x04: /* WORM */
  161. case 0x05: /* CD-ROM */
  162. case 0x07: /* MO */
  163. break;
  164. default:
  165. return 0;
  166. }
  167. if(unit->dev->ifc->online)
  168. unit->dev->ifc->online(unit);
  169. if(unit->sectors){
  170. sdaddpart(unit, "data", 0, unit->sectors);
  171. /*
  172. * Use partitions passed from boot program,
  173. * e.g.
  174. * sdC0part=dos 63 123123/plan9 123123 456456
  175. * This happens before /boot sets hostname so the
  176. * partitions will have the null-string for user.
  177. * The gen functions patch it up.
  178. */
  179. snprint(buf, sizeof buf, "%spart", unit->name);
  180. for(p = getconf(buf); p != nil; p = q){
  181. if(q = strchr(p, '/'))
  182. *q++ = '\0';
  183. nf = tokenize(p, f, nelem(f));
  184. if(nf < 3)
  185. continue;
  186. start = strtoul(f[1], 0, 0);
  187. end = strtoul(f[2], 0, 0);
  188. if(!waserror()){
  189. sdaddpart(unit, f[0], start, end);
  190. poperror();
  191. }
  192. }
  193. }
  194. return 1;
  195. }
  196. static SDev*
  197. sdgetdev(int idno)
  198. {
  199. SDev *sdev;
  200. int i;
  201. qlock(&devslock);
  202. for(i = 0; i != ndevs; i++)
  203. if (devs[i].dt_dev->idno == idno)
  204. break;
  205. if(i == ndevs)
  206. sdev = nil;
  207. else{
  208. sdev = devs[i].dt_dev;
  209. incref(&sdev->r);
  210. }
  211. qunlock(&devslock);
  212. return sdev;
  213. }
  214. static SDunit*
  215. sdgetunit(SDev* sdev, int subno)
  216. {
  217. SDunit *unit;
  218. char buf[32];
  219. /*
  220. * Associate a unit with a given device and sub-unit
  221. * number on that device.
  222. * The device will be probed if it has not already been
  223. * successfully accessed.
  224. */
  225. qlock(&sdev->unitlock);
  226. if(subno > sdev->nunit){
  227. qunlock(&sdev->unitlock);
  228. return nil;
  229. }
  230. unit = sdev->unit[subno];
  231. if(unit == nil){
  232. /*
  233. * Probe the unit only once. This decision
  234. * may be a little severe and reviewed later.
  235. */
  236. if(sdev->unitflg[subno]){
  237. qunlock(&sdev->unitlock);
  238. return nil;
  239. }
  240. if((unit = malloc(sizeof(SDunit))) == nil){
  241. qunlock(&sdev->unitlock);
  242. return nil;
  243. }
  244. sdev->unitflg[subno] = 1;
  245. if(sdev->enabled == 0 && sdev->ifc->enable)
  246. sdev->ifc->enable(sdev);
  247. sdev->enabled = 1;
  248. snprint(buf, sizeof(buf), "%s%d", sdev->name, subno);
  249. kstrdup(&unit->name, buf);
  250. kstrdup(&unit->user, eve);
  251. unit->perm = 0555;
  252. unit->subno = subno;
  253. unit->dev = sdev;
  254. /*
  255. * No need to lock anything here as this is only
  256. * called before the unit is made available in the
  257. * sdunit[] array.
  258. */
  259. if(unit->dev->ifc->verify(unit) == 0){
  260. qunlock(&sdev->unitlock);
  261. free(unit);
  262. return nil;
  263. }
  264. sdev->unit[subno] = unit;
  265. }
  266. qunlock(&sdev->unitlock);
  267. return unit;
  268. }
  269. static void
  270. sdreset(void)
  271. {
  272. int i;
  273. SDev *sdev, *tail, *sdlist;
  274. /*
  275. * Probe all configured controllers and make a list
  276. * of devices found, accumulating a possible maximum number
  277. * of units attached and marking each device with an index
  278. * into the linear top-level directory array of units.
  279. */
  280. tail = sdlist = nil;
  281. for(i = 0; sdifc[i] != nil; i++){
  282. if(sdifc[i]->pnp == nil || (sdev = sdifc[i]->pnp()) == nil)
  283. continue;
  284. if(sdlist != nil)
  285. tail->next = sdev;
  286. else
  287. sdlist = sdev;
  288. for(tail = sdev; tail->next != nil; tail = tail->next){
  289. tail->unit = (SDunit**)malloc(tail->nunit * sizeof(SDunit*));
  290. tail->unitflg = (int*)malloc(tail->nunit * sizeof(int));
  291. assert(tail->unit && tail->unitflg);
  292. ndevs++;
  293. }
  294. tail->unit = (SDunit**)malloc(tail->nunit * sizeof(SDunit*));
  295. tail->unitflg = (int*)malloc(tail->nunit * sizeof(int));
  296. ndevs++;
  297. }
  298. /*
  299. * Legacy and option code goes here. This will be hard...
  300. */
  301. /*
  302. * The maximum number of possible units is known, allocate
  303. * placeholders for their datastructures; the units will be
  304. * probed and structures allocated when attached.
  305. * Allocate controller names for the different types.
  306. */
  307. if(ndevs == 0)
  308. return;
  309. for(i = 0; sdifc[i] != nil; i++){
  310. /*
  311. * BUG: no check is made here or later when a
  312. * unit is attached that the id and name are set.
  313. */
  314. if(sdifc[i]->id)
  315. sdifc[i]->id(sdlist);
  316. }
  317. /*
  318. * The IDs have been set, unlink the sdlist and copy the spec to
  319. * the devtab.
  320. */
  321. devs = (dev_t*)malloc(ndevs * sizeof(dev_t));
  322. memset(devs, 0, ndevs * sizeof(dev_t));
  323. i = 0;
  324. while(sdlist != nil){
  325. devs[i].dt_dev = sdlist;
  326. devs[i].dt_nunits = sdlist->nunit;
  327. sdlist = sdlist->next;
  328. devs[i].dt_dev->next = nil;
  329. i++;
  330. }
  331. }
  332. static int
  333. sd2gen(Chan* c, int i, Dir* dp)
  334. {
  335. Qid q;
  336. vlong l;
  337. SDpart *pp;
  338. SDperm *perm;
  339. SDunit *unit;
  340. SDev *sdev;
  341. int rv;
  342. sdev = sdgetdev(DEV(c->qid));
  343. assert(sdev);
  344. unit = sdev->unit[UNIT(c->qid)];
  345. rv = -1;
  346. switch(i){
  347. case Qctl:
  348. mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qctl),
  349. unit->vers, QTFILE);
  350. perm = &unit->ctlperm;
  351. if(emptystr(perm->user)){
  352. kstrdup(&perm->user, eve);
  353. perm->perm = 0640;
  354. }
  355. devdir(c, q, "ctl", 0, perm->user, perm->perm, dp);
  356. rv = 1;
  357. break;
  358. case Qraw:
  359. mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qraw),
  360. unit->vers, QTFILE);
  361. perm = &unit->rawperm;
  362. if(emptystr(perm->user)){
  363. kstrdup(&perm->user, eve);
  364. perm->perm = DMEXCL|0600;
  365. }
  366. devdir(c, q, "raw", 0, perm->user, perm->perm, dp);
  367. rv = 1;
  368. break;
  369. case Qpart:
  370. pp = &unit->part[PART(c->qid)];
  371. l = (pp->end - pp->start) * (vlong)unit->secsize;
  372. mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), PART(c->qid), Qpart),
  373. unit->vers+pp->vers, QTFILE);
  374. if(emptystr(pp->user))
  375. kstrdup(&pp->user, eve);
  376. devdir(c, q, pp->name, l, pp->user, pp->perm, dp);
  377. rv = 1;
  378. break;
  379. }
  380. decref(&sdev->r);
  381. return rv;
  382. }
  383. static int
  384. sd1gen(Chan* c, int i, Dir* dp)
  385. {
  386. Qid q;
  387. switch(i){
  388. case Qtopctl:
  389. mkqid(&q, QID(0, 0, 0, Qtopctl), 0, QTFILE);
  390. devdir(c, q, "sdctl", 0, eve, 0640, dp);
  391. return 1;
  392. case Qtopstat:
  393. mkqid(&q, QID(0, 0, 0, Qtopstat), 0, QTFILE);
  394. devdir(c, q, "sdstat", 0, eve, 0640, dp);
  395. return 1;
  396. }
  397. return -1;
  398. }
  399. static int
  400. sdgen(Chan* c, char*, Dirtab*, int, int s, Dir* dp)
  401. {
  402. Qid q;
  403. vlong l;
  404. int i, r;
  405. SDpart *pp;
  406. SDunit *unit;
  407. SDev *sdev;
  408. switch(TYPE(c->qid)){
  409. case Qtopdir:
  410. if(s == DEVDOTDOT){
  411. mkqid(&q, QID(0, s, 0, Qtopdir), 0, QTDIR);
  412. sprint(up->genbuf, "#%C", sddevtab.dc);
  413. devdir(c, q, up->genbuf, 0, eve, 0555, dp);
  414. return 1;
  415. }
  416. if(s == 0 || s == 1)
  417. return sd1gen(c, s + Qtopbase, dp);
  418. s -= 2;
  419. qlock(&devslock);
  420. for(i = 0; i != ndevs; i++){
  421. if (s < devs[i].dt_nunits)
  422. break;
  423. s -= devs[i].dt_nunits;
  424. }
  425. if(i == ndevs){
  426. /* Run of the end of the list */
  427. qunlock(&devslock);
  428. return -1;
  429. }
  430. if ((sdev = devs[i].dt_dev) == nil){
  431. qunlock(&devslock);
  432. return 0;
  433. }
  434. incref(&sdev->r);
  435. qunlock(&devslock);
  436. if((unit = sdev->unit[s]) == nil)
  437. if((unit = sdgetunit(sdev, s)) == nil){
  438. decref(&sdev->r);
  439. return 0;
  440. }
  441. mkqid(&q, QID(sdev->idno, s, 0, Qunitdir), 0, QTDIR);
  442. if(emptystr(unit->user))
  443. kstrdup(&unit->user, eve);
  444. devdir(c, q, unit->name, 0, unit->user, unit->perm, dp);
  445. decref(&sdev->r);
  446. return 1;
  447. case Qunitdir:
  448. if(s == DEVDOTDOT){
  449. mkqid(&q, QID(0, s, 0, Qtopdir), 0, QTDIR);
  450. sprint(up->genbuf, "#%C", sddevtab.dc);
  451. devdir(c, q, up->genbuf, 0, eve, 0555, dp);
  452. return 1;
  453. }
  454. if((sdev = sdgetdev(DEV(c->qid))) == nil){
  455. devdir(c, q, "unavailable", 0, eve, 0, dp);
  456. return 1;
  457. }
  458. unit = sdev->unit[UNIT(c->qid)];
  459. qlock(&unit->ctl);
  460. /*
  461. * Check for media change.
  462. * If one has already been detected, sectors will be zero.
  463. * If there is one waiting to be detected, online
  464. * will return > 1.
  465. * Online is a bit of a large hammer but does the job.
  466. */
  467. if(unit->sectors == 0
  468. || (unit->dev->ifc->online && unit->dev->ifc->online(unit) > 1))
  469. sdinitpart(unit);
  470. i = s+Qunitbase;
  471. if(i < Qpart){
  472. r = sd2gen(c, i, dp);
  473. qunlock(&unit->ctl);
  474. decref(&sdev->r);
  475. return r;
  476. }
  477. i -= Qpart;
  478. if(unit->part == nil || i >= unit->npart){
  479. qunlock(&unit->ctl);
  480. decref(&sdev->r);
  481. break;
  482. }
  483. pp = &unit->part[i];
  484. if(!pp->valid){
  485. qunlock(&unit->ctl);
  486. decref(&sdev->r);
  487. return 0;
  488. }
  489. l = (pp->end - pp->start) * (vlong)unit->secsize;
  490. mkqid(&q, QID(DEV(c->qid), UNIT(c->qid), i, Qpart),
  491. unit->vers+pp->vers, QTFILE);
  492. if(emptystr(pp->user))
  493. kstrdup(&pp->user, eve);
  494. devdir(c, q, pp->name, l, pp->user, pp->perm, dp);
  495. qunlock(&unit->ctl);
  496. decref(&sdev->r);
  497. return 1;
  498. case Qraw:
  499. case Qctl:
  500. case Qpart:
  501. if((sdev = sdgetdev(DEV(c->qid))) == nil){
  502. devdir(c, q, "unavailable", 0, eve, 0, dp);
  503. return 1;
  504. }
  505. unit = sdev->unit[UNIT(c->qid)];
  506. qlock(&unit->ctl);
  507. r = sd2gen(c, TYPE(c->qid), dp);
  508. qunlock(&unit->ctl);
  509. decref(&sdev->r);
  510. return r;
  511. case Qtopctl:
  512. case Qtopstat:
  513. return sd1gen(c, TYPE(c->qid), dp);
  514. default:
  515. break;
  516. }
  517. return -1;
  518. }
  519. static Chan*
  520. sdattach(char* spec)
  521. {
  522. Chan *c;
  523. char *p;
  524. SDev *sdev;
  525. int idno, subno, i;
  526. if(ndevs == 0 || *spec == '\0'){
  527. c = devattach(sddevtab.dc, spec);
  528. mkqid(&c->qid, QID(0, 0, 0, Qtopdir), 0, QTDIR);
  529. return c;
  530. }
  531. if(spec[0] != 's' || spec[1] != 'd')
  532. error(Ebadspec);
  533. idno = spec[2];
  534. subno = strtol(&spec[3], &p, 0);
  535. if(p == &spec[3])
  536. error(Ebadspec);
  537. qlock(&devslock);
  538. for (sdev = nil, i = 0; i != ndevs; i++)
  539. if ((sdev = devs[i].dt_dev) != nil && sdev->idno == idno)
  540. break;
  541. if(i == ndevs || subno >= sdev->nunit || sdgetunit(sdev, subno) == nil){
  542. qunlock(&devslock);
  543. error(Enonexist);
  544. }
  545. incref(&sdev->r);
  546. qunlock(&devslock);
  547. c = devattach(sddevtab.dc, spec);
  548. mkqid(&c->qid, QID(sdev->idno, subno, 0, Qunitdir), 0, QTDIR);
  549. c->dev = (sdev->idno << UnitLOG) + subno;
  550. decref(&sdev->r);
  551. return c;
  552. }
  553. static Walkqid*
  554. sdwalk(Chan* c, Chan* nc, char** name, int nname)
  555. {
  556. return devwalk(c, nc, name, nname, nil, 0, sdgen);
  557. }
  558. static int
  559. sdstat(Chan* c, uchar* db, int n)
  560. {
  561. return devstat(c, db, n, nil, 0, sdgen);
  562. }
  563. static Chan*
  564. sdopen(Chan* c, int omode)
  565. {
  566. SDpart *pp;
  567. SDunit *unit;
  568. SDev *sdev;
  569. uchar tp;
  570. c = devopen(c, omode, 0, 0, sdgen);
  571. if((tp = TYPE(c->qid)) != Qctl && tp != Qraw && tp != Qpart)
  572. return c;
  573. sdev = sdgetdev(DEV(c->qid));
  574. if(sdev == nil)
  575. error(Enonexist);
  576. unit = sdev->unit[UNIT(c->qid)];
  577. switch(TYPE(c->qid)){
  578. case Qctl:
  579. c->qid.vers = unit->vers;
  580. break;
  581. case Qraw:
  582. c->qid.vers = unit->vers;
  583. if(tas(&unit->rawinuse) != 0){
  584. c->flag &= ~COPEN;
  585. error(Einuse);
  586. }
  587. unit->state = Rawcmd;
  588. break;
  589. case Qpart:
  590. qlock(&unit->ctl);
  591. if(waserror()){
  592. qunlock(&unit->ctl);
  593. c->flag &= ~COPEN;
  594. nexterror();
  595. }
  596. pp = &unit->part[PART(c->qid)];
  597. c->qid.vers = unit->vers+pp->vers;
  598. qunlock(&unit->ctl);
  599. poperror();
  600. break;
  601. }
  602. decref(&sdev->r);
  603. return c;
  604. }
  605. static void
  606. sdclose(Chan* c)
  607. {
  608. SDunit *unit;
  609. SDev *sdev;
  610. if(c->qid.type & QTDIR)
  611. return;
  612. if(!(c->flag & COPEN))
  613. return;
  614. switch(TYPE(c->qid)){
  615. default:
  616. break;
  617. case Qraw:
  618. sdev = sdgetdev(DEV(c->qid));
  619. if (sdev) {
  620. unit = sdev->unit[UNIT(c->qid)];
  621. unit->rawinuse = 0;
  622. decref(&sdev->r);
  623. }
  624. break;
  625. }
  626. }
  627. static long
  628. sdbio(Chan* c, int write, char* a, long len, vlong off)
  629. {
  630. int nchange;
  631. long l;
  632. uchar *b;
  633. SDpart *pp;
  634. SDunit *unit;
  635. SDev *sdev;
  636. ulong bno, max, nb, offset;
  637. sdev = sdgetdev(DEV(c->qid));
  638. if(sdev == nil)
  639. error(Enonexist);
  640. unit = sdev->unit[UNIT(c->qid)];
  641. if(unit == nil)
  642. error(Enonexist);
  643. nchange = 0;
  644. qlock(&unit->ctl);
  645. while(waserror()){
  646. /* notification of media change; go around again */
  647. if(strcmp(up->errstr, Eio) == 0 && unit->sectors == 0 && nchange++ == 0){
  648. sdinitpart(unit);
  649. continue;
  650. }
  651. /* other errors; give up */
  652. qunlock(&unit->ctl);
  653. decref(&sdev->r);
  654. nexterror();
  655. }
  656. pp = &unit->part[PART(c->qid)];
  657. if(unit->vers+pp->vers != c->qid.vers)
  658. error(Eio);
  659. /*
  660. * Check the request is within bounds.
  661. * Removeable drives are locked throughout the I/O
  662. * in case the media changes unexpectedly.
  663. * Non-removeable drives are not locked during the I/O
  664. * to allow the hardware to optimise if it can; this is
  665. * a little fast and loose.
  666. * It's assumed that non-removeable media parameters
  667. * (sectors, secsize) can't change once the drive has
  668. * been brought online.
  669. */
  670. bno = (off/unit->secsize) + pp->start;
  671. nb = ((off+len+unit->secsize-1)/unit->secsize) + pp->start - bno;
  672. max = SDmaxio/unit->secsize;
  673. if(nb > max)
  674. nb = max;
  675. if(bno+nb > pp->end)
  676. nb = pp->end - bno;
  677. if(bno >= pp->end || nb == 0){
  678. if(write)
  679. error(Eio);
  680. qunlock(&unit->ctl);
  681. decref(&sdev->r);
  682. poperror();
  683. return 0;
  684. }
  685. if(!(unit->inquiry[1] & 0x80)){
  686. qunlock(&unit->ctl);
  687. poperror();
  688. }
  689. b = sdmalloc(nb*unit->secsize);
  690. if(b == nil)
  691. error(Enomem);
  692. if(waserror()){
  693. sdfree(b);
  694. if(!(unit->inquiry[1] & 0x80))
  695. decref(&sdev->r); /* gadverdamme! */
  696. nexterror();
  697. }
  698. offset = off%unit->secsize;
  699. if(offset+len > nb*unit->secsize)
  700. len = nb*unit->secsize - offset;
  701. if(write){
  702. if(offset || (len%unit->secsize)){
  703. l = unit->dev->ifc->bio(unit, 0, 0, b, nb, bno);
  704. if(l < 0)
  705. error(Eio);
  706. if(l < (nb*unit->secsize)){
  707. nb = l/unit->secsize;
  708. l = nb*unit->secsize - offset;
  709. if(len > l)
  710. len = l;
  711. }
  712. }
  713. memmove(b+offset, a, len);
  714. l = unit->dev->ifc->bio(unit, 0, 1, b, nb, bno);
  715. if(l < 0)
  716. error(Eio);
  717. if(l < offset)
  718. len = 0;
  719. else if(len > l - offset)
  720. len = l - offset;
  721. }
  722. else{
  723. l = unit->dev->ifc->bio(unit, 0, 0, b, nb, bno);
  724. if(l < 0)
  725. error(Eio);
  726. if(l < offset)
  727. len = 0;
  728. else if(len > l - offset)
  729. len = l - offset;
  730. memmove(a, b+offset, len);
  731. }
  732. sdfree(b);
  733. poperror();
  734. if(unit->inquiry[1] & 0x80){
  735. qunlock(&unit->ctl);
  736. poperror();
  737. }
  738. decref(&sdev->r);
  739. return len;
  740. }
  741. static long
  742. sdrio(SDreq* r, void* a, long n)
  743. {
  744. void *data;
  745. if(n >= SDmaxio || n < 0)
  746. error(Etoobig);
  747. data = nil;
  748. if(n){
  749. if((data = sdmalloc(n)) == nil)
  750. error(Enomem);
  751. if(r->write)
  752. memmove(data, a, n);
  753. }
  754. r->data = data;
  755. r->dlen = n;
  756. if(waserror()){
  757. if(data != nil){
  758. sdfree(data);
  759. r->data = nil;
  760. }
  761. nexterror();
  762. }
  763. if(r->unit->dev->ifc->rio(r) != SDok)
  764. error(Eio);
  765. if(!r->write && r->rlen > 0)
  766. memmove(a, data, r->rlen);
  767. if(data != nil){
  768. sdfree(data);
  769. r->data = nil;
  770. }
  771. poperror();
  772. return r->rlen;
  773. }
  774. static long
  775. sdread(Chan *c, void *a, long n, vlong off)
  776. {
  777. char *p, *e, *buf;
  778. SDpart *pp;
  779. SDunit *unit;
  780. SDev *sdev;
  781. ulong offset;
  782. int i, l, status;
  783. offset = off;
  784. switch(TYPE(c->qid)){
  785. default:
  786. error(Eperm);
  787. case Qtopstat:
  788. p = buf = malloc(READSTR);
  789. assert(p);
  790. e = p + READSTR;
  791. qlock(&devslock);
  792. for(i = 0; i != ndevs; i++){
  793. SDev *sdev = devs[i].dt_dev;
  794. if(sdev->ifc->stat)
  795. p = sdev->ifc->stat(sdev, p, e);
  796. else
  797. p = seprint(e, "%s; no statistics available\n", sdev->name);
  798. }
  799. qunlock(&devslock);
  800. n = readstr(off, a, n, buf);
  801. free(buf);
  802. return n;
  803. case Qtopdir:
  804. case Qunitdir:
  805. return devdirread(c, a, n, 0, 0, sdgen);
  806. case Qctl:
  807. sdev = sdgetdev(DEV(c->qid));
  808. if (sdev == nil)
  809. error(Enonexist);
  810. unit = sdev->unit[UNIT(c->qid)];
  811. p = malloc(READSTR);
  812. l = snprint(p, READSTR, "inquiry %.48s\n",
  813. (char*)unit->inquiry+8);
  814. qlock(&unit->ctl);
  815. /*
  816. * If there's a device specific routine it must
  817. * provide all information pertaining to night geometry
  818. * and the garscadden trains.
  819. */
  820. if(unit->dev->ifc->rctl)
  821. l += unit->dev->ifc->rctl(unit, p+l, READSTR-l);
  822. if(unit->sectors == 0)
  823. sdinitpart(unit);
  824. if(unit->sectors){
  825. if(unit->dev->ifc->rctl == nil)
  826. l += snprint(p+l, READSTR-l,
  827. "geometry %ld %ld\n",
  828. unit->sectors, unit->secsize);
  829. pp = unit->part;
  830. for(i = 0; i < unit->npart; i++){
  831. if(pp->valid)
  832. l += snprint(p+l, READSTR-l,
  833. "part %s %lud %lud\n",
  834. pp->name, pp->start, pp->end);
  835. pp++;
  836. }
  837. }
  838. qunlock(&unit->ctl);
  839. decref(&sdev->r);
  840. l = readstr(offset, a, n, p);
  841. free(p);
  842. return l;
  843. case Qraw:
  844. sdev = sdgetdev(DEV(c->qid));
  845. if (sdev == nil)
  846. error(Enonexist);
  847. unit = sdev->unit[UNIT(c->qid)];
  848. qlock(&unit->raw);
  849. if(waserror()){
  850. qunlock(&unit->raw);
  851. decref(&sdev->r);
  852. nexterror();
  853. }
  854. if(unit->state == Rawdata){
  855. unit->state = Rawstatus;
  856. i = sdrio(unit->req, a, n);
  857. }
  858. else if(unit->state == Rawstatus){
  859. status = unit->req->status;
  860. unit->state = Rawcmd;
  861. free(unit->req);
  862. unit->req = nil;
  863. i = readnum(0, a, n, status, NUMSIZE);
  864. } else
  865. i = 0;
  866. qunlock(&unit->raw);
  867. decref(&sdev->r);
  868. poperror();
  869. return i;
  870. case Qpart:
  871. return sdbio(c, 0, a, n, off);
  872. }
  873. return 0;
  874. }
  875. typedef struct {
  876. int o_on;
  877. char* o_spec;
  878. DevConf o_cf;
  879. } confdata_t;
  880. static void
  881. parse_switch(confdata_t* cd, char* option)
  882. {
  883. if(!strcmp("on", option))
  884. cd->o_on = 1;
  885. else if(!strcmp("off", option))
  886. cd->o_on = 0;
  887. else
  888. error(Ebadarg);
  889. }
  890. static void
  891. parse_spec(confdata_t* cd, char* option)
  892. {
  893. if(strlen(option) > 1)
  894. error(Ebadarg);
  895. cd->o_spec = option;
  896. }
  897. static port_t*
  898. getnewport(DevConf* dc)
  899. {
  900. port_t *p;
  901. p = (port_t *)malloc((dc->nports + 1) * sizeof(port_t));
  902. if(dc->nports > 0){
  903. memmove(p, dc->ports, dc->nports * sizeof(port_t));
  904. free(dc->ports);
  905. }
  906. dc->ports = p;
  907. p = &dc->ports[dc->nports++];
  908. p->size = -1;
  909. p->port = (ulong)-1;
  910. return p;
  911. }
  912. static void
  913. parse_port(confdata_t* cd, char* option)
  914. {
  915. char *e;
  916. port_t *p;
  917. if(cd->o_cf.nports == 0 || cd->o_cf.ports[cd->o_cf.nports-1].port != (ulong)-1)
  918. p = getnewport(&cd->o_cf);
  919. else
  920. p = &cd->o_cf.ports[cd->o_cf.nports-1];
  921. p->port = strtol(option, &e, 0);
  922. if(e == nil || *e != '\0')
  923. error(Ebadarg);
  924. }
  925. static void
  926. parse_size(confdata_t* cd, char* option)
  927. {
  928. char *e;
  929. port_t *p;
  930. if(cd->o_cf.nports == 0 || cd->o_cf.ports[cd->o_cf.nports-1].size != -1)
  931. p = getnewport(&cd->o_cf);
  932. else
  933. p = &cd->o_cf.ports[cd->o_cf.nports-1];
  934. p->size = (int)strtol(option, &e, 0);
  935. if(e == nil || *e != '\0')
  936. error(Ebadarg);
  937. }
  938. static void
  939. parse_irq(confdata_t* cd, char* option)
  940. {
  941. char *e;
  942. cd->o_cf.intnum = strtoul(option, &e, 0);
  943. if(e == nil || *e != '\0')
  944. error(Ebadarg);
  945. }
  946. static void
  947. parse_type(confdata_t* cd, char* option)
  948. {
  949. cd->o_cf.type = option;
  950. }
  951. static struct {
  952. char *option;
  953. void (*parse)(confdata_t*, char*);
  954. } options[] = {
  955. { "switch", parse_switch, },
  956. { "spec", parse_spec, },
  957. { "port", parse_port, },
  958. { "size", parse_size, },
  959. { "irq", parse_irq, },
  960. { "type", parse_type, },
  961. };
  962. static long
  963. sdwrite(Chan* c, void* a, long n, vlong off)
  964. {
  965. Cmdbuf *cb;
  966. SDreq *req;
  967. SDunit *unit;
  968. SDev *sdev;
  969. ulong end, start;
  970. switch(TYPE(c->qid)){
  971. default:
  972. error(Eperm);
  973. case Qtopctl: {
  974. confdata_t cd;
  975. char buf[256], *field[Ncmd];
  976. int nf, i, j;
  977. memset(&cd, 0, sizeof(confdata_t));
  978. if(n > sizeof(buf)-1) n = sizeof(buf)-1;
  979. memmove(buf, a, n);
  980. buf[n] = '\0';
  981. cd.o_on = -1;
  982. cd.o_spec = '\0';
  983. memset(&cd.o_cf, 0, sizeof(DevConf));
  984. nf = tokenize(buf, field, Ncmd);
  985. for(i = 0; i < nf; i++){
  986. char *opt = field[i++];
  987. if(i >= nf)
  988. error(Ebadarg);
  989. for(j = 0; j != nelem(options); j++)
  990. if(!strcmp(opt, options[j].option))
  991. break;
  992. if(j == nelem(options))
  993. error(Ebadarg);
  994. options[j].parse(&cd, field[i]);
  995. }
  996. if(cd.o_on < 0)
  997. error(Ebadarg);
  998. if(cd.o_on){
  999. if(cd.o_spec == '\0' || cd.o_cf.nports == 0 ||
  1000. cd.o_cf.intnum == 0 || cd.o_cf.type == nil)
  1001. error(Ebadarg);
  1002. }
  1003. else{
  1004. if(cd.o_spec == '\0')
  1005. error(Ebadarg);
  1006. }
  1007. if(sddevtab.config == nil)
  1008. error("No configuration function");
  1009. sddevtab.config(cd.o_on, cd.o_spec, &cd.o_cf);
  1010. break;
  1011. }
  1012. case Qctl:
  1013. cb = parsecmd(a, n);
  1014. sdev = sdgetdev(DEV(c->qid));
  1015. if (sdev == nil)
  1016. error(Enonexist);
  1017. unit = sdev->unit[UNIT(c->qid)];
  1018. qlock(&unit->ctl);
  1019. if(waserror()){
  1020. qunlock(&unit->ctl);
  1021. decref(&sdev->r);
  1022. free(cb);
  1023. nexterror();
  1024. }
  1025. if(unit->vers != c->qid.vers)
  1026. error(Eio);
  1027. if(cb->nf < 1)
  1028. error(Ebadctl);
  1029. if(strcmp(cb->f[0], "part") == 0){
  1030. if(cb->nf != 4)
  1031. error(Ebadctl);
  1032. if(unit->sectors == 0 && !sdinitpart(unit))
  1033. error(Eio);
  1034. start = strtoul(cb->f[2], 0, 0);
  1035. end = strtoul(cb->f[3], 0, 0);
  1036. sdaddpart(unit, cb->f[1], start, end);
  1037. }
  1038. else if(strcmp(cb->f[0], "delpart") == 0){
  1039. if(cb->nf != 2 || unit->part == nil)
  1040. error(Ebadctl);
  1041. sddelpart(unit, cb->f[1]);
  1042. }
  1043. else if(unit->dev->ifc->wctl)
  1044. unit->dev->ifc->wctl(unit, cb);
  1045. else
  1046. error(Ebadctl);
  1047. qunlock(&unit->ctl);
  1048. decref(&sdev->r);
  1049. poperror();
  1050. free(cb);
  1051. break;
  1052. case Qraw:
  1053. sdev = sdgetdev(DEV(c->qid));
  1054. if(sdev == nil)
  1055. error(Enonexist);
  1056. unit = sdev->unit[UNIT(c->qid)];
  1057. qlock(&unit->raw);
  1058. if(waserror()){
  1059. qunlock(&unit->raw);
  1060. decref(&sdev->r);
  1061. nexterror();
  1062. }
  1063. switch(unit->state){
  1064. case Rawcmd:
  1065. if(n < 6 || n > sizeof(req->cmd))
  1066. error(Ebadarg);
  1067. if((req = malloc(sizeof(SDreq))) == nil)
  1068. error(Enomem);
  1069. req->unit = unit;
  1070. memmove(req->cmd, a, n);
  1071. req->clen = n;
  1072. req->flags = SDnosense;
  1073. req->status = ~0;
  1074. unit->req = req;
  1075. unit->state = Rawdata;
  1076. break;
  1077. case Rawstatus:
  1078. unit->state = Rawcmd;
  1079. free(unit->req);
  1080. unit->req = nil;
  1081. error(Ebadusefd);
  1082. case Rawdata:
  1083. if(unit->state != Rawdata)
  1084. error(Ebadusefd);
  1085. unit->state = Rawstatus;
  1086. unit->req->write = 1;
  1087. n = sdrio(unit->req, a, n);
  1088. }
  1089. qunlock(&unit->raw);
  1090. decref(&sdev->r);
  1091. poperror();
  1092. break;
  1093. case Qpart:
  1094. return sdbio(c, 1, a, n, off);
  1095. }
  1096. return n;
  1097. }
  1098. static int
  1099. sdwstat(Chan* c, uchar* dp, int n)
  1100. {
  1101. Dir *d;
  1102. SDpart *pp;
  1103. SDperm *perm;
  1104. SDunit *unit;
  1105. SDev *sdev;
  1106. if(c->qid.type & QTDIR)
  1107. error(Eperm);
  1108. sdev = sdgetdev(DEV(c->qid));
  1109. if (sdev == nil)
  1110. error(Enonexist);
  1111. unit = sdev->unit[UNIT(c->qid)];
  1112. qlock(&unit->ctl);
  1113. d = nil;
  1114. if(waserror()){
  1115. free(d);
  1116. qunlock(&unit->ctl);
  1117. decref(&sdev->r);
  1118. nexterror();
  1119. }
  1120. switch(TYPE(c->qid)){
  1121. default:
  1122. error(Eperm);
  1123. case Qctl:
  1124. perm = &unit->ctlperm;
  1125. break;
  1126. case Qraw:
  1127. perm = &unit->rawperm;
  1128. break;
  1129. case Qpart:
  1130. pp = &unit->part[PART(c->qid)];
  1131. if(unit->vers+pp->vers != c->qid.vers)
  1132. error(Enonexist);
  1133. perm = &pp->SDperm;
  1134. break;
  1135. }
  1136. if(strcmp(up->user, perm->user) && !iseve())
  1137. error(Eperm);
  1138. d = smalloc(sizeof(Dir)+n);
  1139. n = convM2D(dp, n, &d[0], (char*)&d[1]);
  1140. if(n == 0)
  1141. error(Eshortstat);
  1142. if(!emptystr(d[0].uid))
  1143. kstrdup(&perm->user, d[0].uid);
  1144. if(d[0].mode != ~0UL)
  1145. perm->perm = (perm->perm & ~0777) | (d[0].mode & 0777);
  1146. free(d);
  1147. qunlock(&unit->ctl);
  1148. decref(&sdev->r);
  1149. poperror();
  1150. return n;
  1151. }
  1152. static char
  1153. getspec(char base)
  1154. {
  1155. while(1){
  1156. int i;
  1157. SDev *sdev;
  1158. for(i = 0; i != ndevs; i++)
  1159. if((sdev = devs[i].dt_dev) != nil && (char)sdev->idno == base)
  1160. break;
  1161. if(i == ndevs)
  1162. return base;
  1163. base++;
  1164. }
  1165. return '\0';
  1166. }
  1167. static int
  1168. configure(char* spec, DevConf* cf)
  1169. {
  1170. ISAConf isa;
  1171. dev_t *_devs;
  1172. SDev *tail, *sdev, *(*probe)(DevConf*);
  1173. char *p, name[32];
  1174. int i, added_devs;
  1175. if((p = strchr(cf->type, '/')) != nil)
  1176. *p++ = '\0';
  1177. for(i = 0; sdifc[i] != nil; i++)
  1178. if(!strcmp(sdifc[i]->name, cf->type))
  1179. break;
  1180. if(sdifc[i] == nil)
  1181. error("type not found");
  1182. if((probe = sdifc[i]->probe) == nil)
  1183. error("No probe function");
  1184. if(p){
  1185. /* Try to find the card on the ISA bus. This code really belongs
  1186. in sdata and I'll move it later. Really! */
  1187. memset(&isa, 0, sizeof(isa));
  1188. isa.port = cf->ports[0].port;
  1189. isa.irq = cf->intnum;
  1190. if(pcmspecial(p, &isa) < 0)
  1191. error("Cannot find controller");
  1192. }
  1193. qlock(&devslock);
  1194. if(waserror()){
  1195. qunlock(&devslock);
  1196. nexterror();
  1197. }
  1198. for(i = 0; i != ndevs; i++)
  1199. if((sdev = devs[i].dt_dev) != nil && sdev->idno == *spec)
  1200. break;
  1201. if(i != ndevs)
  1202. error(Eexist);
  1203. if((sdev = (*probe)(cf)) == nil)
  1204. error("Cannot probe controller");
  1205. poperror();
  1206. added_devs = 0;
  1207. tail = sdev;
  1208. while(tail){
  1209. added_devs++;
  1210. tail = tail->next;
  1211. }
  1212. _devs = (dev_t*)malloc((ndevs + added_devs) * sizeof(dev_t));
  1213. memmove(_devs, devs, ndevs * sizeof(dev_t));
  1214. free(devs);
  1215. devs = _devs;
  1216. while(sdev){
  1217. /* Assign `spec' to the device */
  1218. *spec = getspec(*spec);
  1219. snprint(name, sizeof(name), "sd%c", *spec);
  1220. kstrdup(&sdev->name, name);
  1221. sdev->idno = *spec;
  1222. sdev->unit = (SDunit **)malloc(sdev->nunit * sizeof(SDunit*));
  1223. sdev->unitflg = (int *)malloc(sdev->nunit * sizeof(int));
  1224. assert(sdev->unit && sdev->unitflg);
  1225. devs[ndevs].dt_dev = sdev;
  1226. devs[ndevs].dt_nunits = sdev->nunit;
  1227. sdev = sdev->next;
  1228. devs[ndevs].dt_dev->next = nil;
  1229. ndevs++;
  1230. }
  1231. qunlock(&devslock);
  1232. return 0;
  1233. }
  1234. static int
  1235. unconfigure(char* spec)
  1236. {
  1237. int i;
  1238. SDev *sdev;
  1239. qlock(&devslock);
  1240. if(waserror()){
  1241. qunlock(&devslock);
  1242. nexterror();
  1243. }
  1244. sdev = nil;
  1245. for(i = 0; i != ndevs; i++)
  1246. if((sdev = devs[i].dt_dev) != nil && sdev->idno == *spec)
  1247. break;
  1248. if(i == ndevs)
  1249. error(Enonexist);
  1250. if(sdev->r.ref)
  1251. error(Einuse);
  1252. /* make sure no interrupts arrive anymore before removing resources */
  1253. if(sdev->enabled && sdev->ifc->disable)
  1254. sdev->ifc->disable(sdev);
  1255. /* we're alone and the device tab is locked; make the device unavailable */
  1256. memmove(&devs[i], &devs[ndevs - 1], sizeof(dev_t));
  1257. memset(&devs[ndevs - 1], 0, sizeof(dev_t));
  1258. ndevs--;
  1259. qunlock(&devslock);
  1260. poperror();
  1261. for(i = 0; i != sdev->nunit; i++)
  1262. if(sdev->unit[i]){
  1263. SDunit *unit = sdev->unit[i];
  1264. free(unit->name);
  1265. free(unit->user);
  1266. free(unit);
  1267. }
  1268. if(sdev->ifc->clear)
  1269. sdev->ifc->clear(sdev);
  1270. return 0;
  1271. }
  1272. static int
  1273. sdconfig(int on, char* spec, DevConf* cf)
  1274. {
  1275. if(on)
  1276. return configure(spec, cf);
  1277. return unconfigure(spec);
  1278. }
  1279. Dev sddevtab = {
  1280. 'S',
  1281. "sd",
  1282. sdreset,
  1283. devinit,
  1284. devshutdown,
  1285. sdattach,
  1286. sdwalk,
  1287. sdstat,
  1288. sdopen,
  1289. devcreate,
  1290. sdclose,
  1291. sdread,
  1292. devbread,
  1293. sdwrite,
  1294. devbwrite,
  1295. devremove,
  1296. sdwstat,
  1297. devpower,
  1298. sdconfig,
  1299. };