samedi 21 mars 2015

Function explanation in this part of the c code? a little confusion

so this is the structure of the code that parse out a floppy disk, the outoutput should be like this:



flop: structure
number of FAT: 2
number of sectors used by FAT: 9
number of sectors per cluster: 1
number of ROOT Entries: 224
number of bytes per sector: 512
---Sector #--- ---Sector Types---
0 BOOT
01 -- 09 FAT1
10 -- 18 FAT2
19 -- 32 ROOT DIRECTORY


The numbers should be numbers should be extracted from the disk rather than hard coded.


Here is the part of the code:



void structure(int l) {
printf(" number of FAT: %d\n", disk.NUMBER_OF_FATS);
printf(" number of sectors used by FAT: %d\n", disk.SECTORS_PER_FAT);
printf(" number of sectors per cluster: %d\n", disk.SECTORS_PER_CLUSTER);
printf(" number of ROOT Entries: %d\n", disk.MAX_ROOT_DIRS);
printf(" number of bytes per sector %d\n", disk.BYTES_PER_SECTOR);
if (l) {
printf(" ---Sector #--- ---Sector Types---\n");
printf(" 0 BOOT\n");

for(int i = 0; i < disk.NUMBER_OF_FATS; i++)
printf(" %02d -- %02d FAT%d\n", (disk.SECTORS_PER_FAT * i) + 1, disk.SECTORS_PER_FAT * (i + 1), i);

printf(" %02d -- %02d ROOT DIRECTORY\n", disk.SECTORS_PER_FAT * disk.NUMBER_OF_FATS, (disk.MAX_ROOT_DIRS / 16) + (disk.SECTORS_PER_FAT * disk.NUMBER_OF_FATS));
}
}


My questions are 1. What are int l stand for? is it just a variable in if function? 2. Also can you some just give me a brief explation of the for(int i = 0; i < disk.NUMBER_OF_FATS; i++) part of the function? does it mean that if I is smaller than number of fats it will go into FAT1, then rest go to fat2?


Please feel free to comment or explain the code, thank you!


Aucun commentaire:

Enregistrer un commentaire