I have to write a virtualdisk file handling system as part of a university project using C(I am running windows), I'm running into a problem when I am writing to the FAT table where I try to create a FAT chain containing a reference to FAT block 10(0A 00) and it is instead writing 0D 0A 00.
The disk is comprised of 1024 blocks of size 1024, the first block is used for arbitrary information, the second and third blocks are for the FAT and the fourth block is for the root directory, the remaining blocks are for farther data.
The FAT table is defined as:
fatentry_t FAT[MAXBLOCKS];
Fatentry_t is defined as:
typedef short fatentry_t;
And I access it using:
typedef union block{
datablock_t data;
dirblock_t dir;
fatblock_t fat;
}diskblock_t;
I am copying the FAT to the disk using:
void copyFAT(){
diskblock_t block = getEmptyDiskBlock();
int pos = 0;
for(pos = 0; pos < 512; pos++){
block.fat[pos] = FAT[pos];
}
writeblock(&block, 1);
for(pos = 512; pos < 1024; pos++){
block.fat[pos-512] = FAT[pos];
}
writeblock(&block, 2);
writedisk("src\\virtualdiskD3_D1");
}
When making a FAT chain, if there is any reference to 0A I will get a 0D, for example:
00 00 02 00 00 00 00 00 05 00 06 00 07 00 08 00
09 00 0D 0A 00 0B 00 0C 00 0D 00 0E 00 0F 00 10
00 ...
When I am expecting:
00 00 02 00 00 00 00 00 05 00 06 00 07 00 08 00
09 00 0A 00 0B 00 0C 00 0D 00 0E 00 0F 00 10 00
11 ...
Has anyone got any idea what is causing this?
My current thought is that it is windows, however I have no idea how to fix this in eclipse.
Thanks in advance.
EDIT:
void writedisk(const char *filename){
printf("writedisk> virtualdisk[0] = %s\n", virtualDisk[0].data);
FILE *dest = fopen( filename, "w" );
if(fwrite(virtualDisk, sizeof(virtualDisk), 1, dest) < 0){
fprintf(stderr, "write virtual disk to disk failed\n");
}
fclose(dest);
}
void writeblock(diskblock_t * block, int block_address){
memmove(virtualDisk[block_address].data, block->data, BLOCKSIZE);
}
EDIT2:
Thanks to all who commented and answered this, I did not write the writedisk function and as such did not notice this, the guide who will be marking will be using linux which I don't believe he well need it to be in binary mode as linux only uses 0A rather than 0D0A, but for me this will make developing on windows much easier.