int amigados_writeFile(FSMNG * fsmng,int filehandle,unsigned char * buffer,int size) { int byteswrite; byteswrite = 0; if(filehandle<128) { if((long)fsmng->handletable[filehandle-1]!=-1) { if(amigados_getFreeSpace(fsmng) >= size) { byteswrite = adfWriteFile((struct File*)fsmng->handletable[filehandle-1], size, buffer); } return byteswrite; } } return HXCFE_ACCESSERROR; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; struct File *file; unsigned char buf[600]; long n; FILE *out; long len; struct List *list; adfEnvInitDefault(); /* create and mount one device */ hd = adfCreateDumpDevice("newdev", 80, 11, 2); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE ); vol = adfMount(hd, 0, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); /* the directory */ list = adfGetDirEnt(vol,vol->curDirPtr); while(list) { printEntry(list->content); adfFreeEntry(list->content); list = list->next; } freeList(list); /* write one file */ file = adfOpenFile(vol, "moon_gif","w"); if (!file) return 1; out = fopen("Check/MOON.GIF","rb"); if (!out) return 1; len = 600; n = fread(buf,sizeof(unsigned char),len,out); while(!feof(out)) { adfWriteFile(file, n, buf); n = fread(buf,sizeof(unsigned char),len,out); } if (n>0) adfWriteFile(file, n, buf); fclose(out); adfCloseFile(file); /* the directory */ list = adfGetDirEnt(vol,vol->curDirPtr); while(list) { printEntry(list->content); adfFreeEntry(list->content); list = list->next; } freeList(list); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }
int ScanFile(HXCFLOPPYEMULATOR* floppycontext,struct Volume * adfvolume,char * folder,char * file) { long hfindfile; filefoundinfo FindFileData; int bbool; int byte_written; FILE * ftemp; unsigned char tempbuffer[512]; struct File* adffile; unsigned char * fullpath;//,*fileimg; int size,filesize; RETCODE rc; hfindfile=find_first_file(folder,file, &FindFileData); if(hfindfile!=-1) { bbool=TRUE; while(hfindfile!=-1 && bbool) { if(FindFileData.isdirectory) { if(strcmp(".",FindFileData.filename)!=0 && strcmp("..",FindFileData.filename)!=0) { if(adfCountFreeBlocks(adfvolume)>4) { floppycontext->hxc_printf(MSG_INFO_1,"Adding directory %s",FindFileData.filename); rc=adfCreateDir(adfvolume,adfvolume->curDirPtr,FindFileData.filename); if(rc==RC_OK) { floppycontext->hxc_printf(MSG_INFO_1,"entering directory %s",FindFileData.filename); rc=adfChangeDir(adfvolume, FindFileData.filename); if(rc==RC_OK) { fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); if(ScanFile(floppycontext,adfvolume,fullpath,file)) { adfParentDir(adfvolume); free(fullpath); return 1; } floppycontext->hxc_printf(MSG_INFO_1,"Leaving directory %s",FindFileData.filename); free(fullpath); adfParentDir( adfvolume); } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot enter to the directory %s !",FindFileData.filename); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot Add the directory %s !",FindFileData.filename); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot Add a directory ! : no more free block!!!"); return 1; } } } else { if(adfCountFreeBlocks(adfvolume)>4) { floppycontext->hxc_printf(MSG_INFO_1,"Adding file %s, %dB",FindFileData.filename,FindFileData.size); adffile = adfOpenFile(adfvolume, FindFileData.filename, "w"); if(adffile) { if(FindFileData.size) { fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); ftemp=fopen(fullpath,"rb"); if(ftemp) { fseek(ftemp,0,SEEK_END); filesize=ftell(ftemp); fseek(ftemp,0,SEEK_SET); do { if(filesize>=512) { size=512; } else { size=filesize; } fread(&tempbuffer,size,1,ftemp); byte_written=adfWriteFile(adffile, size, tempbuffer); if((byte_written!=size) || (adfCountFreeBlocks(adfvolume)<2) ) { floppycontext->hxc_printf(MSG_ERROR,"Error while writting the file %s. No more free block ?",FindFileData.filename); adfCloseFile(adffile); fclose(ftemp); free(fullpath); return 1; } filesize=filesize-512; }while( (filesize>0) && (byte_written==size)); /*fileimg=(unsigned char*)malloc(filesize); memset(fileimg,0,filesize); fread(fileimg,filesize,1,ftemp); adfWriteFile(adffile, filesize, fileimg); free(fileimg);*/ adfCloseFile(adffile); fclose(ftemp); free(fullpath); } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot open %s !!!",fullpath); free(fullpath); return 1; } } } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot create %s, %dB!!!",FindFileData.filename,FindFileData.size); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot add a file : no more free block"); return 1; } } bbool=find_next_file(hfindfile,folder,file,&FindFileData); } } else printf("Error FindFirstFile\n"); find_close(hfindfile); return 0; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; struct File *fic; unsigned char buf[1]; struct List *list, *cell; struct GenBlock *block; BOOL true = TRUE; adfEnvInitDefault(); adfChgEnvProp(PR_USEDIRC,&true); /* display or not the physical / logical blocks and W or R */ adfChgEnvProp(PR_USE_RWACCESS,&true); /* create and mount one device */ hd = adfCreateDumpDevice("newdev", 80, 2, 11); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } adfDeviceInfo(hd); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } fic = adfOpenFile(vol, "file_1a","w"); if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } adfWriteFile(fic,1,buf); adfCloseFile(fic); puts("\ncreate file_1a"); adfVolumeInfo(vol); adfCreateDir(vol,vol->curDirPtr,"dir_5u"); puts("\ncreate dir_5u"); adfVolumeInfo(vol); cell = list = adfGetDirEnt(vol, vol->curDirPtr); while(cell) { printEntry(cell->content); cell = cell->next; } adfFreeDirList(list); puts("\nremove file_1a"); adfRemoveEntry(vol,vol->curDirPtr,"file_1a"); adfVolumeInfo(vol); adfRemoveEntry(vol,vol->curDirPtr,"dir_5u"); puts("\nremove dir_5u"); adfVolumeInfo(vol); cell = list = adfGetDelEnt(vol); while(cell) { block =(struct GenBlock*) cell->content; printf("%s %d %d %ld\n",block->name,block->type,block->secType, block->sect); cell = cell->next; } adfFreeDelList(list); adfUndelEntry(vol,vol->curDirPtr,883); // file_1a puts("\nundel file_1a"); adfVolumeInfo(vol); adfUndelEntry(vol,vol->curDirPtr,885); // dir_5u puts("\nundel dir_5u"); adfVolumeInfo(vol); cell = list = adfGetDirEnt(vol, vol->curDirPtr); while(cell) { printEntry(cell->content); cell = cell->next; } adfFreeDirList(list); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; struct File *file; unsigned char buf[600]; long n; FILE *in; long len; struct List *list; adfEnvInitDefault(); // adfSetEnvFct(0,0,MyVer,0); /* mount existing device : FFS */ hd = adfMountDev( "testffs.bak",FALSE ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); list = adfGetDirEnt(vol, vol->curDirPtr); while(list) { printEntry(list->content); adfFreeEntry(list->content); list = list->next; } freeList(list); // adfCreateDir(vol,vol->curDirPtr,"dir_1a"); adfCreateDir(vol,vol->curDirPtr,"dir_1b"); file = adfOpenFile(vol, "newfile","w"); adfCloseFile(file); file = adfOpenFile(vol, "moon_gif","w"); if (!file) return 1; in = fopen("Check/MOON.GIF","rb"); if (!in) return 1; len = 600; n = fread(buf,sizeof(unsigned char),len,in); while(!feof(in)) { adfWriteFile(file, n, buf); n = fread(buf,sizeof(unsigned char),len,in); } if (n>0) adfWriteFile(file, n, buf); // adfFlushFile(file); adfCloseFile(file); fclose(in); adfRemoveEntry(vol,vol->curDirPtr, "dir_1b"); list = adfGetDirEnt(vol, vol->curDirPtr); while(list) { printEntry(list->content); adfFreeEntry(list->content); list = list->next; } freeList(list); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; struct File *file; unsigned char buf[600]; long n; FILE *out; long len; struct List *list; adfEnvInitDefault(); // adfSetEnvFct(0,0,MyVer,0); /* mount existing device : FFS */ hd = adfMountDev( "hd.adf",FALSE ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } adfDeviceInfo(hd); vol = adfMount(hd, 1, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); /* write one file */ file = adfOpenFile(vol, "moon_gif","w"); if (!file) return 1; out = fopen("Check/MOON.GIF","rb"); if (!out) return 1; len = 600; n = fread(buf,sizeof(unsigned char),len,out); while(!feof(out)) { adfWriteFile(file, n, buf); n = fread(buf,sizeof(unsigned char),len,out); } if (n>0) adfWriteFile(file, n, buf); fclose(out); adfCloseFile(file); /* the directory */ /* list = adfGetDirEnt(vol,vol->curDirPtr); while(list) { printEntry(list->content); adfFreeEntry(list->content); list = list->next; } freeList(list); */ /* re read this file */ file = adfOpenFile(vol, "moon_gif","r"); if (!file) return 1; out = fopen("moon__gif","wb"); if (!out) return 1; len = 300; n = adfReadFile(file, len, buf); while(!adfEndOfFile(file)) { fwrite(buf,sizeof(unsigned char),n,out); n = adfReadFile(file, len, buf); } if (n>0) fwrite(buf,sizeof(unsigned char),n,out); fclose(out); adfCloseFile(file); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }