here is the code:
after i have read all information on the boot sector to buffer,Code:/* ===== SharedDisk.h ===== */ #ifndef __SHAREDISK__ #define __SHAREDISK__ typedef struct { unsigned short Jump; char Manufacturer[ 9 ]; unsigned short BytesPerSector; unsigned char SectorsPerCluster; unsigned short ReservedSectors; unsigned char FATs; unsigned short RootDirectoryEntries; unsigned short LogicalSectors; unsigned char MediaDescriptorByte; unsigned short SectorsPerFAT; unsigned short SectorsPerTrack; unsigned short Surfaces; unsigned short HiddenSectors; } Disk; #endif /* ===== FDisk.c ===== */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <ctype.h> #include <string.h> #include "SharedDisk.h" #include "FDisk.h" int DiskOpen( Disk *theDisk ) { int fd; int len; char buffer[SIZE]; // ===== Initialize theDisk ===== // memset( theDisk, '\0', sizeof( Disk ) ); // ===== Open the file ===== // fd = open ( "disk.img", O_RDONLY ); // ===== Read boot sector information in the file to array buffer ===== // len = read ( fd, buffer, 512 ); // ===== Check if it reads file sucessful ===== // if ( len == -1 ) { printf( "Unable to read file.\n" ); } ===== i have problem from here it is not correct ===== ===== i do not know how to put each inforamtion to each member of the struct Disk. ===== // ===== Copy the information to each member of the Disk ===== // memcpy( theDisk->Jump, &buffer[ 0 ], 3 ); memcpy( theDisk->Manufacturer, &buffer[ 3 ], 8 ); memcpy( theDisk->BytesPerSector, &buffer[ 11 ], 2 ); memcpy( theDisk->SectorsPerCluster, &buffer[ 13 ], 1 ); memcpy( theDisk->ReservedSectors, &buffer[ 14 ], 2 ); memcpy( theDisk->FATs, &buffer[ 16 ], 1 ); memcpy( theDisk->RootDirectoryEntries, &buffer[ 17 ], 2 ); memcpy( theDisk->LogicalSectors, &buffer[ 19 ], 2 ); memcpy( theDisk->MediaDescriptorByte, &buffer[ 21 ], 1 ); memcpy( theDisk->SectorsPerFAT, &buffer[ 22 ], 2 ); memcpy( theDisk->SectorsPerTrack, &buffer[ 24 ], 2 ); memcpy( theDisk->Surfaces, &buffer[ 26 ], 2 ); memcpy( theDisk->HiddenSectors, &buffer[ 28 ], 2 ); return fd; }
how do i put each information to each member of the struct Disk?
i have heard that i have to deal with offset bytes to get each information like shifting byte left.
i do not know how.
can some one tell me how?
if u need more information, please tell me.
i will provide more information.
thx a lot



LinkBack URL
About LinkBacks


