/* * ckdrv - check the drive, see if it needs to be logged in. * * Arguments: * d - has this drive been accessed, or had a media change * * * returns: * ERR if getbpb() failed * ENSMEM if log() failed * EINTRN if no room in dirtbl * drive nbr if success. */ long ckdrv(int d) { int curdir; LONG mask; BPB *b; KDEBUG(("ckdrv(%i)\n",d)); mask = 1L << d; if (!(mask & drvsel)) { /* drive has not been selected yet */ b = (BPB *) Getbpb(d); if (!b) return (mask&drvrem) ? EPTHNF : EDRIVE; if ((long)b < 0) return (long)b; if (log_media(b,d)) return ENSMEM; drvsel |= mask; } else if (mask & drvrem) /* handle removable media */ { if (Mediach(d)) { errdrv = d; rwerr = E_CHNG; /* signal media change */ errcode = rwerr; longjmp(errbuf,1); } } /* * ensure that current process has a valid default directory * on this drive */ curdir = run->p_curdir[d]; if (curdir >= NCURDIR) /* validate */ curdir = 0; /* if invalid, say none */ if (!curdir /* no current dir for this drive */ || !dirtbl[curdir].dnd) /* or current dir is invalid */ { curdir = incr_curdir_usage(drvtbl[d]->m_dtl); /* add root DND */ if (curdir < 0) return ENSMEM; run->p_curdir[d] = curdir; /* link to process */ } return d; }
long ckdrv(int d) { int i; LONG mask; BPB *b; #if DBGFSDRIVE kprintf("ckdrv(%i)\n", d); #endif mask = 1L << d; if (!(mask & drvsel)) { /* drive has not been selected yet */ b = (BPB *) Getbpb(d); if ( !(long)b ) /* M01.01.1007.01 */ return(ERR); if ( (long)b < 0 ) /* M01.01.0915.02 */ /* M01.01.1007.01 */ return( (long)b ); if (log_media(b,d)) return (ENSMEM); drvsel |= mask; } if ((!run->p_curdir[d]) || (!dirtbl[(int)(run->p_curdir[d])])) { /* need to allocate current dir on this drv */ for (i = 1; i < NCURDIR; i++) /* find unused slot */ if (!diruse[i]) break; if (i == NCURDIR) /* no slot available */ return( EINTRN ) ; /* M01.01.20 */ diruse[i]++; /* mark as used */ dirtbl[i] = drvtbl[d]->m_dtl; /* link to DND */ run->p_curdir[d] = i; /* link to process */ } return(d); }
int Init_drive(int drive,drive_struct *str) { /* read BPB,FAT and init drive struct */ str->drive=drive; if ((!(str->bpb=Getbpb(drive)))||(str->bpb->bflags&1)) /* cannot currently handle FAT16 */ { return(FALSE); } if (!(str->fat=(char *) malloc(str->bpb->recsiz*str->bpb->fsiz))) { return(FALSE); } /* now read FAT */ if (Rwabs(0,str->fat,str->bpb->fsiz,str->bpb->fatrec-str->bpb->fsiz, drive)) { /* hmm error */ free(str->fat); return(FALSE); } /* now alloc root dir */ if (!(str->root_dir=(char *) malloc(str->bpb->recsiz*str->bpb->rdlen))) { free(str->fat); return(FALSE); } if (Rwabs(0,str->root_dir,str->bpb->rdlen,str->bpb->fatrec+str->bpb->fsiz, drive)) { /* hmm error */ free(str->root_dir); free(str->fat); return(FALSE); } return(TRUE); }