WORD save_icn(VOID) { LONG daddr, maddr; WORD ret; save_fat(FALSE); rast_op(3,&hold_area, &hold_mfdb, &hold_area, &save_mfdb); if(gl_isicon) rast_op(3, &hold_area, &hld2_mfdb, &hold_area, &sav2_mfdb); daddr = GET_SPEC(ad_pbx, DATAWIND); if (gl_isicon) { /* write data and mask */ maddr = GET_SPEC(ad_pbx, MASKWIND); ret = writ_icon(LLGET(BI_PDATA(daddr)), gl_wimage, gl_himage, gl_datasize, TRUE) ; if (ret ) return( writ_icon(LLGET(BI_PDATA(maddr)), gl_wimage, gl_himage, gl_datasize, FALSE) ); else return( ret ); } else /* write data only */ return( writ_icon(LLGET(BI_PDATA(daddr)), gl_wimage, gl_himage, gl_datasize, TRUE) ); }
void format(uint16_t sector_sz, uint16_t cluster_sz, uint16_t disk_sz) { cluster_sz_bytes = cluster_sz * sector_sz; extended_mbr = (uint8_t *)malloc(cluster_sz_bytes); bzero(extended_mbr, cluster_sz_bytes); mbr = (mbr_t *) (&extended_mbr[0]); mbr->sector_sz = sector_sz; mbr->cluster_sz = cluster_sz; mbr->disk_sz = disk_sz; mbr->fat_start = 1; double fat_length = disk_sz * sizeof(uint16_t) / ((double) cluster_sz * sector_sz); fat_length = ceil(fat_length); mbr->fat_len = fat_length; mbr->data_start = fat_length + 1; strcpy(mbr->disk_name, "no name"); printf("fat start=%d len=%d\n", mbr->fat_start, mbr->fat_len); //save the mbr to disk write_full((uint8_t *) &extended_mbr[0], cluster_sz_bytes, file); // allocate the fat fat = (uint16_t *) malloc(mbr->fat_len * cluster_sz_bytes); alloc_entries = disk_sz; total_entries = mbr->fat_len * cluster_sz_bytes / sizeof(uint16_t); printf("fat alloc=%d total=%d\n", alloc_entries, total_entries); for (int i = 0; i < alloc_entries; i++) { fat[i] = FAT_FREE; } for (int i = alloc_entries + 1; i < total_entries; i++) { fat[i] = FAT_UNALLOC; } fat_size = mbr->fat_len * cluster_sz_bytes; // fat_size = total_entries * sizeof(uint16_t); save_fat(); }