main() { char buf[512], bbuf[512]; int i; /* for (i = 0; i < 512;) { buf[i++] = 'M'; buf[i++] = 'I'; buf[i++] = 'N'; buf[i++] = 'O'; } /**/ /* physical operation on unit 0 */ /* Lrwabs(9, buf, 1, 0x10000, 2); Lrwabs(8, bbuf, 1, 0x10000, 3); /**/ /* logical operation on D: */ /* i = 1; while (i == 1) { Mediach(3); Getbpb(3); Rwabs(1, buf, 1, 0x700, 3); } /**/ /* Lrwabs(0, bbuf, 1, 0x10000, 3); /**/ Rwabs(8, bbuf, 1, 0, 2); Rwabs(9, bbuf, 1, 0, 2); Pterm(0); }
/** * Callback function */ int hxc_media_read(unsigned long sector, unsigned char *buffer) { _direct_access_status_sector * dass; dass= (_direct_access_status_sector *)buffer; gui_more_busy(); if (_isEmulator) { Rwabs(0, buffer, 1, sector, 0); } else { do { if((sector-_last_setlbabase)>=8) { _setlbabase(sector); } if(!readsector(0,buffer,0)) { error("Read error"); } _last_setlbabase=L_INDIAN(dass->lba_base); /* gui_printf(0,0,0,"BA: %08X %08X" ,L_INDIAN(dass->lba_base),sector);*/ } while((sector-L_INDIAN(dass->lba_base))>=8); if(!readsector((sector-_last_setlbabase)+1,buffer,0)) { //gui_printf(0, 0, 0, "fsector=%d", (sector-_last_setlbabase)+1)); fatal("Read error"); } } gui_less_busy(); return 1; }
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); }
/** * Callback function */ int hxc_media_write(unsigned long sector, unsigned char *buffer) { gui_more_busy(); if (_isEmulator) { Rwabs(1, buffer, 1, sector, 0); } else { if((sector-_last_setlbabase)>=8) { _last_setlbabase=sector; _setlbabase(sector); } if(!writesector((sector-_last_setlbabase)+1,buffer)) { fatal("Write sector error"); } } gui_less_busy(); return 1; }
int Run_through_dir(DIR *entry, int nbr_of_entries, drive_struct *str, int *seq_in, int *ch_sum_in, int *is_v_in, char *my_path_end, char *long_path_end) { /* run through the dir copy files as it goes */ /* my_dir_end points to end of current path */ int expected_seq=*seq_in; /* 0 means tos name slot */ int last_check_sum=*ch_sum_in; int is_vfat_slot=*is_v_in; for(;nbr_of_entries>0;nbr_of_entries--,entry++,expected_seq--) { VDIR *vfat_slot=entry; /* is this an extended slot?? */ if((vfat_slot->attr==0xf)&& (!vfat_slot->reserved)&& (!vfat_slot->first_cluster[0])&& (!vfat_slot->first_cluster[1])) { /* if last bumb expected seq and checksum */ if (vfat_slot->id&0x40) { expected_seq=vfat_slot->id&0x3f; if (expected_seq<(LONG_FILE_LENGTH/13)) long_file_name[expected_seq*13]=0; /* always terminate filename */ last_check_sum=vfat_slot->alias_checksum; is_vfat_slot=TRUE; } /* check if checksum and sequence are correct */ if (((vfat_slot->id&0x3f)==expected_seq)&& (vfat_slot->alias_checksum==last_check_sum)&& (expected_seq<(LONG_FILE_LENGTH/13))) { /* slot ok! copy filename */ /* use the sequence number to index into the file name */ char *name=long_file_name+(expected_seq-1)*13; /* so a simple conversion from unicode */ /* will work on all ASCII characters */ *name++=vfat_slot->name0_4[0]; *name++=vfat_slot->name0_4[2]; *name++=vfat_slot->name0_4[4]; *name++=vfat_slot->name0_4[6]; *name++=vfat_slot->name0_4[8]; *name++=vfat_slot->name5_10[0]; *name++=vfat_slot->name5_10[2]; *name++=vfat_slot->name5_10[4]; *name++=vfat_slot->name5_10[6]; *name++=vfat_slot->name5_10[8]; *name++=vfat_slot->name5_10[10]; *name++=vfat_slot->name11_12[0]; *name++=vfat_slot->name11_12[2]; /* that's it! 13 characters.. */ } else { /* vfat corrupt */ is_vfat_slot=FALSE; } } else { /* should it be the "tos" slot?? */ if (expected_seq!=0) is_vfat_slot=FALSE; /* check if valid "tos" slot */ /* DEBUG print! */ if (is_vfat_slot) printf("file name found: %s\n",long_file_name); /* if valid copy file or create dir and descend */ if((entry->attr!=0xf)&& (entry->first_cluster[0]| entry->first_cluster[1])&& (is_vfat_slot)) { long cluster=(entry->first_cluster[1]<<8)|entry->first_cluster[0]; unsigned char sum; int i; char *ptr=entry->name; char *curr_tos_end=my_path_end; /* calc filename checksum */ sum=i=0; for(;i<8;) { unsigned char ch=entry->name[i]; sum=((((sum&1)<<7)|((sum&0xfe)>>1))+ch); if ((ch!=0)&&(ch!=' ')) { *curr_tos_end++=ch; } i++; } *curr_tos_end++='.'; i=0; for(;i<3;) { unsigned char ch=entry->name[8+i]; sum=((((sum&1)<<7)|((sum&0xfe)>>1))+ch); if ((ch!=0)&&(ch!=' ')) { *curr_tos_end++=ch; } i++; } if (*(curr_tos_end-1)=='.') { curr_tos_end--; } *curr_tos_end=0; if ((cluster>=2)&&(cluster<=0xfef)&&(last_check_sum==sum)) { char *l_p; strcpy(long_path_end,long_file_name); printf("VFAT file path: %s\n",long_path); printf("tos file path: %s\n",tos_path); /* file is ok */ if (entry->attr&0x10) { int seq=-1; int cs=0; int flag=FALSE; int cluster_size=str->bpb->clsiz; char *cluster_buff=malloc(str->bpb->recsiz*str->bpb->clsiz); unsigned long cluster; if (!cluster_buff) return(FALSE); *curr_tos_end++='\\'; l_p=long_path_end+strlen(long_path_end); /* directory.. create and descend! */ printf("descending!\n"); /* create dir on target */ Dcreate(long_path); /* descend */ *l_p++='\\'; *l_p=0; cluster=(entry->first_cluster[1]<<8)|entry->first_cluster[0]; do { Rwabs(0,cluster_buff,cluster_size, cluster_size*(cluster-2)+str->bpb->datrec, str->drive); Run_through_dir(cluster_buff,str->bpb->recsiz* cluster_size/sizeof(DIR),str,&seq, &cs,&flag,curr_tos_end,l_p); cluster=Next_cluster(str,cluster); } while(cluster); free(cluster_buff); printf("ascending\n"); /* return */ } else { /* normal file.. copy! */ printf("normal file!\n"); /* make dos name */ if (!Copy_file(tos_path,long_path,entry->attr)) { return(FALSE); } } } } /* if not ignore */ } }