Guys, I have a function that returns a bit from the exFAT heap to mark a new cluster. But for some reason there are errors when I create thousands of folders and files to test the system.
When I test the routine to start returning bits using the following, it works:
Basically, the function returns the first free bit it finds.
// test to see if the problem is in this routine!!!!!!!! static unsigned int test = 8; clear_cluster(stream, test); //return address of bit allocated return test++;
This is the function:
unsigned int dir_get_cluster_bit(FILEX * stream){ // base the pointer unsigned char * bitMap = stream->cache; /* Bit Map table, its a bit like the FAT table in FAT32 only it is in bits*/ unsigned int fat_table = data_to_cpu32(stream->exFAT_Boot_Sector->ClusterHeapOffset) + stream->partition_index; // read first sector dma_hardware_read(1, fat_table, 1, stream->cache, 0); unsigned int byte = 0, sector = 0; // scan sector for a free bit, i.e. one or more bits are Zero while(* bitMap == 0xff){ byte++, bitMap++; // stop arithmetic errors when byte is zero if(((byte % 512) == 0) && (byte != 0)){ // move to next sector sector++; byte = 0; // reset bitmap to start of sector bitMap = (unsigned char *)&bitMap[0]; // read next sector dma_hardware_read(1, fat_table + sector, 1, stream->cache, 0); } } // UnMap free bit location unsigned int bit = free_bit[* bitMap]; // write bit to target byte and update * bitMap |= (unsigned char)1 << bit; // write first FAT bit entry dma_hardware_write(1, fat_table + sector, 1, stream->cache, 0); unsigned int new_cluster = ((sector * 512) + (byte * 8) + bit + 2); clear_cluster(stream, new_cluster); // test to see if the problem is in this routine!!!!!!!! // static unsigned int test = 8; // clear_cluster(stream, test); //return address of bit allocated return new_cluster; }
So, when I find a free cluster bit, i.e. a zero int the byte, I mark it and return the address that the bit was found.