From 8326d934d357f96eed694d59e47200e09462d2bb Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 16 Apr 1995 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1995-04-16 --- port/devsd.c | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/port/devsd.c b/port/devsd.c index 07e5c6ac9b4baa9b620d21a9118ca76162c69f57..31b1a09f32ba6350e6994cc63d4968eb90e17c5d 100644 --- a/port/devsd.c +++ b/port/devsd.c @@ -184,11 +184,36 @@ sdinit(void) Chan* sdattach(char *spec) { - int i; + int i, nfound; + Disk *d; - for(i = 0; i < ndisk; i++) - sdrdpart(&disk[i]); - + /* + * If the drive wasn't ready when we tried to do a + * read-capacity earlier (in sdinit()), try again. + * It might be possible to be smarter here, and look at the + * response from a test-unit-ready which would show if the + * target was in the process of becoming ready. + */ + nfound = 0; + for(i = 0; i < ndisk; i++){ + d = &disk[i]; + if(waserror()){ + poperror(); + continue; + } + if(d->size == 0 || d->bsize == 0){ + if(scsicap(d->t, d->lun, &d->size, &d->bsize) != STok){ + d->size = d->bsize = 0; + continue; + } + } + sdrdpart(d); + nfound++; + poperror(); + } + + if(nfound == 0) + return 0; return devattach('w', spec); } @@ -284,20 +309,6 @@ sdrdpart(Disk *d) char *b, *line[Npart+2], *field[3]; static char MAGIC[] = "plan9 partitions"; - /* - * If the drive wasn't ready when we tried to do a - * read-capacity earlier (in sdinit()), try again. - * It might be possible to be smarter here, and look at the - * response from a test-unit-ready which would show if the - * target was in the process of becoming ready. - */ - if(d->size == 0 || d->bsize == 0){ - if(scsicap(d->t, d->lun, &d->size, &d->bsize) != STok){ - d->size = d->bsize = 0; - error(Eio); - } - } - b = scsialloc(d->bsize); if(b == 0) error(Enomem); @@ -363,6 +374,9 @@ sdio(Chan *c, int write, char *a, ulong len, ulong offset) d = &disk[DRIVE(c->qid)]; p = &d->table[PART(c->qid)]; + if(d->bsize == 0) + error(Eio); + if(write && (d->inquire[0] & 0x1F) == TypeCD) error(Eperm);