Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printDataStats(const char* name)
- {
- FILE* file = openFile(name, "rb");
- int freeBlocks = freeBlocksCount(file);
- int busyBlocks = BLOCKS_NUMBER - freeBlocks;
- fclose(file);
- int freeSpace = freeBlocks*BLOCK_SIZE;
- int allSpace = BLOCK_SIZE*BLOCKS_NUMBER;
- int busySpace = allSpace-freeSpace;
- cout << "Free Blocks: " << freeBlocks << "/" << BLOCKS_NUMBER << "\n";
- cout << "Occupied Blocks: " << busyBlocks << "/" << BLOCKS_NUMBER << "\n";
- cout << "Results in: \n";
- cout << ((double)freeSpace/(double)allSpace)*100.0 << "% of free space\n";
- cout << ((double)busySpace/(double)allSpace)*100.0 << "% of occupied space\n";
- cout << freeSpace << "/" << allSpace << " bytes are free\n";
- cout << busySpace << "/" << allSpace << " bytes are occupied\n";
- /* Can comment if not working first time */
- int i;
- uint16_t temp;
- unsigned long int tempPos;
- file = openFile(name, "rb");
- int unusedBytes = 0;
- while(true)
- {
- tempPos = ftell(file);
- fread((void*) &temp, sizeof(temp), 1, file);
- if(feof(file))
- break;
- //printf("%#08lx\t", tempPos);
- int bytescount = 0;
- if((temp & 32768) == 0)
- {
- bool go = true;
- char c = 'a';
- while(c != '\0' && go)
- {
- fread((void*) &c, sizeof(c), 1, file);
- bytescount++;
- if(bytescount == BLOCK_SIZE)
- {
- //cout << "Break by BLOCK_SIZE\n";
- go = false;
- }
- }
- unusedBytes += BLOCK_SIZE-bytescount;
- }
- fseek(file, -bytescount+BLOCK_SIZE, SEEK_CUR);
- }
- fclose(file);
- cout << unusedBytes << "/" << allSpace << " lost by fragmentation\n";
- cout << (double)unusedBytes/(double)allSpace*100.0 << "% of disk space lost by fragmentation\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement