static int wrap_fs_mountfs(struct _reent *r, const char *pathname) { if (fs) { r->_errno = EBUSY; return -1; } lfile = malloc(sizeof(*lfile)); if (if_initInterface(lfile,"mci0:")) { free(lfile); r->_errno = EACCES; return -1; } ioman = malloc(sizeof(*ioman)); disc = malloc(sizeof(*disc)); part = malloc(sizeof(*part)); ioman_init(ioman,lfile,0); disc_initDisc(disc,ioman); memClr(disc->partitions,sizeof(PartitionField)*4); disc->partitions[0].type=0x0B; disc->partitions[0].LBA_begin=0; disc->partitions[0].numSectors=lfile->sectorCount; part_initPartition(part,disc); fs = malloc(sizeof(*fs)); if( (fs_initFs(fs,part)) != 0) { printf("Unable to init the filesystem\n"); return(-1); } return 0; }
/* **************************************************************************** * esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename) * This function will take a full directory path, and strip off all leading * dirs and characters, leaving you with the MS-DOS notation of the actual filename. * Return value: 1 on success, 0 on not being able to produca a filename */ esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename) { eint8 ffnamec[11],*next,nn=0; memClr(ffnamec,11); memClr(fatfilename,11); next = filename; if(*filename=='/')next++; while((next=file_normalToFatName(next,ffnamec))){ memCpy(ffnamec,fatfilename,11); nn++; } if(nn)return(1); return(0); }
void ioman_reset(IOManager *ioman) { euint16 nb,ni; memClr(ioman->sector,sizeof(euint32)*ioman->numbuf); memClr(ioman->status,sizeof(euint8) *ioman->numbuf); memClr(ioman->usage ,sizeof(euint8) *ioman->numbuf); memClr(ioman->itptr ,sizeof(euint8) *ioman->numbuf); for(nb=0;nb<ioman->numbuf;nb++){ for(ni=0;ni<ioman->numit;ni++){ ioman->stack[nb][ni].sector=0; ioman->stack[nb][ni].status=0; ioman->stack[nb][ni].usage =0; } } }
void ioman_reset(IOManager *ioman) { unsigned short nb,ni; memClr(ioman->sector,sizeof(unsigned long)*ioman->numbuf); memClr(ioman->status,sizeof(unsigned char) *ioman->numbuf); memClr(ioman->usage ,sizeof(unsigned char) *ioman->numbuf); memClr(ioman->itptr ,sizeof(unsigned char) *ioman->numbuf); ioman_setError(ioman,IOMAN_NOERROR); for(nb=0;nb<ioman->numbuf;nb++){ for(ni=0;ni<ioman->numit;ni++){ ioman->stack[nb][ni].sector=0; ioman->stack[nb][ni].status=0; ioman->stack[nb][ni].usage =0; } } }
esint8 ls_openDir(DirList *dlist,FileSystem *fs,eint8* dirname) { FileLocation loc; euint32 fc; dlist->fs=fs; if(fs_findFile(dlist->fs,dirname,&loc,&fc)!=2) { return(-1); } fs_initClusterChain(dlist->fs,&(dlist->Cache),fc); memClr(&(dlist->currentEntry),sizeof(dlist->currentEntry)); dlist->rEntry=0; dlist->cEntry=0xFFFF; return(0); }
/* **************************************************************************** * esint8 file_fclose(File *file) * Description: This function closes a file, by clearing the object. * Return value: 0 on success. */ esint8 file_fclose(File *file) { if(fs_hasTimeSupport()){ file->DirEntry.AccessDate = time_getDate(); if(file_getAttr(file,FILE_STATUS_WRITE)){ file->DirEntry.FileSize = file->FileSize; file->DirEntry.WriteDate = file->DirEntry.AccessDate; file->DirEntry.WriteTime = time_getTime(); } dir_updateDirectoryEntry(file->fs,&(file->DirEntry),&(file->Location)); }else{ if(file_getAttr(file,FILE_STATUS_WRITE)){ dir_setFileSize(file->fs,&(file->Location),file->FileSize); } } memClr(file,sizeof(*file)); file_setAttr(file,FILE_STATUS_OPEN,0); file_setAttr(file,FILE_STATUS_WRITE,0); return(0); }
signed short mkfs_makevfat(Partition *part) { unsigned long c,cc,ret; unsigned long ns,fs,ds,dc; unsigned char buf[512]; ns=part->disc->partitions[part->activePartition].numSectors; if( ns < 66581 ) { DBG((TXT("This is not possible due to insufficient sectors. Sorry\n"))); return(MKFS_ERR_TOOLITTLESECTORS); } ret=0; for(c=1<<6; c>=1; c>>=1) { /* First guess */ ds = ns - 32; fs = ((ds/c)+127)/128; /* ds was guess too large, so fs is too large now too. */ for(cc=0; cc<2; cc++) { /* Round 2, error round */ ds = ns - 32 - 2*fs; fs = ((ds/c)+127)/128; /* Since fs was too large, ds became too small. So the fs for this small ds is too small as well. */ /* Round 3, correction round */ ds = ns - 32 - 2*fs; fs = ((ds/c)+127)/128; /* The fs was too small, so ds was too large. The calculated fs should be slightly too large. */ } /* Round 4, finalise */ ds = ns - 32 - 2*fs; dc = ds / c; if(ret<(fs*128-dc)/128)ret=(fs*128-dc)/128; /* Check if with current setting we have a valid fat ? */ if(dc >= 65525 + 16) { break; } } /* Generate BPB */ memClr(buf,512); /* Boot code */ *(buf+0)=0xE9; *(buf+1)=0x00; *(buf+2)=0x00; /* RESET */ /* OEM name */ memCpy("DSCOSMSH",buf+3,8); /* Bytes/Sector */ *((unsigned short*)(buf+11)) = 512; /* Sectors/Cluster */ *(buf+13) = c; /* Reserved Sectors */ *((unsigned short*)(buf+14)) = 32; /* Number of FAT Tables */ *(buf+16) = 2; /* RootEntryCount */ *((unsigned short*)(buf+17)) = 0; /* Total Sector Count __16 */ *((unsigned short*)(buf+19)) = 0; /* Media (crap) */ *(buf+21) = 0xF8; /* FAT size 16 */ *((unsigned short*)(buf+22)) = 0; /* Total Sector Count __32 */ *((unsigned long*)(buf+32)) = ns; /* Fat Size 32 */ *((unsigned long*)(buf+36)) = fs; /* First Cluster Root Dir */ *((unsigned long*)(buf+44)) = 2; /* VolumeID */ *((unsigned long*)(buf+67)) = 0x13371337; /* Volume Label */ memCpy("DISCOSMASH!",buf+71,11); /* Filesystemtype */ memCpy("FAT32 ",buf+82,8); /* Magic */ *(buf+510) = 0x55; *(buf+511) = 0xAA; part_writeBuf(part,0,buf); memClr(buf,512); for(c=32; c<(32+2*fs); c++) { part_writeBuf(part,c,buf); } *(((unsigned long*)buf) )=0x0FFFFFF8; *(((unsigned long*)buf)+1)=0x0FFFFFFF; *(((unsigned long*)buf)+2)=0x0FFFFFF8; part_writeBuf(part,32,buf); part_writeBuf(part,32+fs,buf); return(0); }