Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Boot sector stores vital information about the file system. The boot sector is laid out in the following way, starting at the beginning of the
Boot sector stores vital information about the file system. The boot sector is laid out in the following way, starting at the beginning of the disk (logical sector 0, byte 0): All values are stored as unsigned little-endian numbers unless otherwise specified. Offset Ox00 Ox03 OxOB OxOD Ox Ox10 Ox11 Ox13 Ox15 Ox16 0x18 0x1A Ox10 Length Contents Display Format 3 Binary offset of boot loader hex 8 Volume Label (ASCII, null padded) ASCII 2 Bytes / sector decimal 1 Sectors / cluster decimal 2 Reserved sectors decimal 1 Number of FATs (generally 2) decimal 2 Number of Root Directory entries decimal Number of logical sectors decimal 1 Medium descriptor hex Sectors per FAT decimal 2 Sectors per track decimal 2 Number of heads decimal 2 Number of hidden sectors decimal Table 1: The Layout of FAT-12 Boot Sector 2 N N N N 3.1 Decoding the boot sector by hand Using the supplied program and the offsets in the tables above, find and decode the values for each of the following fields in the boot sector (remember that it starts at offset 0): Hex Decimal Bytes/ sector Sectors/cluster Root directory entries Sectors/FAT 3.2 Decoding the boot sector Create a program to read and then print information from the boot sector. The starting offset and size of each field can be found in Table 1. All of the information is (of course) stored as binary on disk. When you print the values, use the format specified in Table 1. Use printf to print out values correctly after converting any little endian data. Call your new program bsdump (see the C program template bsdump-template.c). Your program should take the name of the file to read, and then decode and print out all of the values in the boot sector (you may skip the jump instruction). bytedump.c- Notepad File Edit Format View Help \* bytedump.c This program reads a set number of bytes from a file and prints out the hex/ASCII values one byte at a time. Compile: gcc bytedump.c -o bytedump */ #include #include #include #include #include #include #define SIZE 32 /* size of the read buffer */ /* helper functions for printing out the buffer */ char printable(char c); void bytedump(char *buf, int offset); int main(int args, char *argv[]) { int floppy; /* file descriptor */ int offset; /* offset into the file */ unsigned char buf[SIZE]; /* read buffer */ /* check args */ if (argc #include #include #include #define SIZE 32 /* size of the read buffer */ //define PRINT_HEX // un-comment this to print the values in hex for debugging struct Boot Sector { unsigned char sName[9]; unsigned short iBytesSector; // The name of the volume // Bytes per Sector unsigned char iSectorsCluster; unsigned short iReservedSectors; unsigned char iNumberFATS; // Sectors per Cluster // Reserved sectors // Number of FATS unsigned short iRootEntries; unsigned short iLogicalSectors; unsigned char xMediumDescriptor; // Number of Root Directory entries // Number of logical sectors // Medium descriptor unsigned short iSectorsFAT; unsigned short iSectors Track; unsigned short iHeads; // Sectors per FAT // Sectors per Track // Number of heads unsigned short iHiddenSectors; // Number of hidden sectors }; unsigned short endianSwap(unsigned char one, unsigned char two); // Pre: Two initialized characters // Post: The characters are swapped (two, one) and returned as a short void decodeBootSector(struct BootSector * pBoots, unsigned char buffer[]); // Pre: An initialized BootSector struct and a pointer to an array of characters read from a BootSector // Post: The BootSector struct is filled out from the buffer data void printBootSector(struct BootSector * pBoots); // Pre: A filled BootSector struct // Post: The information about the boot sector prints to the console // entry point: int main(int args, char * argv[]) { int pBootSector 0; unsigned char buffer[SIZE]; struct BootSector sector; // Check for argument if (argc sName); printf(" Bytes/Sector: %i ", pBoots->iBytes Sector); printf(" Sectors/Cluster: %i ", pBoots->iSectorsCluster); printf(" Reserved Sectors: %i ", pBoots->iReservedSectors); printf(" Number of FATS: %i ", pBoots-> NumberFATS); printf(" Root Directory entries: %i ", pBoots->iRootEntries); printf(" Logical sectors: %i ", pBoots->iLogicalSectors); printf(" Medium descriptor: @x%04x ", pBoots->xMediumDescriptor); printf(" Sectors/FAT: %i ", pBoots->iSectorsFAT); printf(" Sectors/Track: %i ", pBoots->iSectorsTrack); printf(" Number of heads: %i ", pBoots->iHeads); printf("Number of Hidden Sectors: %i ", pBoots->iHiddenSectors); #else printf(" Name: pBoots->sName); printf(" Bytes/Sector: 0x%04x ", pBoots->iBytesSector); printf(" Sectors/Cluster: 0x%02x ", pBoots->iSectorsCluster); printf(" Reserved Sectors: @x%04x ", pBoots->iReservedSectors); printf(" Number of FATS: 0x%02x ", pBoots->iNumberFATs); printf("Root Directory entries: 0x%04x ", pBoots-> RootEntries); printf(" Logical sectors: 0x%04x ", pBoots->iLogicalSectors); printf(" Medium descriptor: @x%02x ", pBoots->xMediumDescriptor); printf(" Sectors/FAT: @x%04x ", pBoots->iSectorsFAT); printf(" Sectors/Track: @x%04x ", pBoots->iSectorsTrack); printf(" Number of heads: Ox%04x ", pBoots->iHeads); printf("Number of Hidden Sectors: 0x%04x ", pBoots->iHiddenSectors); #endif return; } %s ", Boot sector stores vital information about the file system. The boot sector is laid out in the following way, starting at the beginning of the disk (logical sector 0, byte 0): All values are stored as unsigned little-endian numbers unless otherwise specified. Offset Ox00 Ox03 OxOB OxOD Ox Ox10 Ox11 Ox13 Ox15 Ox16 0x18 0x1A Ox10 Length Contents Display Format 3 Binary offset of boot loader hex 8 Volume Label (ASCII, null padded) ASCII 2 Bytes / sector decimal 1 Sectors / cluster decimal 2 Reserved sectors decimal 1 Number of FATs (generally 2) decimal 2 Number of Root Directory entries decimal Number of logical sectors decimal 1 Medium descriptor hex Sectors per FAT decimal 2 Sectors per track decimal 2 Number of heads decimal 2 Number of hidden sectors decimal Table 1: The Layout of FAT-12 Boot Sector 2 N N N N 3.1 Decoding the boot sector by hand Using the supplied program and the offsets in the tables above, find and decode the values for each of the following fields in the boot sector (remember that it starts at offset 0): Hex Decimal Bytes/ sector Sectors/cluster Root directory entries Sectors/FAT 3.2 Decoding the boot sector Create a program to read and then print information from the boot sector. The starting offset and size of each field can be found in Table 1. All of the information is (of course) stored as binary on disk. When you print the values, use the format specified in Table 1. Use printf to print out values correctly after converting any little endian data. Call your new program bsdump (see the C program template bsdump-template.c). Your program should take the name of the file to read, and then decode and print out all of the values in the boot sector (you may skip the jump instruction). bytedump.c- Notepad File Edit Format View Help \* bytedump.c This program reads a set number of bytes from a file and prints out the hex/ASCII values one byte at a time. Compile: gcc bytedump.c -o bytedump */ #include #include #include #include #include #include #define SIZE 32 /* size of the read buffer */ /* helper functions for printing out the buffer */ char printable(char c); void bytedump(char *buf, int offset); int main(int args, char *argv[]) { int floppy; /* file descriptor */ int offset; /* offset into the file */ unsigned char buf[SIZE]; /* read buffer */ /* check args */ if (argc #include #include #include #define SIZE 32 /* size of the read buffer */ //define PRINT_HEX // un-comment this to print the values in hex for debugging struct Boot Sector { unsigned char sName[9]; unsigned short iBytesSector; // The name of the volume // Bytes per Sector unsigned char iSectorsCluster; unsigned short iReservedSectors; unsigned char iNumberFATS; // Sectors per Cluster // Reserved sectors // Number of FATS unsigned short iRootEntries; unsigned short iLogicalSectors; unsigned char xMediumDescriptor; // Number of Root Directory entries // Number of logical sectors // Medium descriptor unsigned short iSectorsFAT; unsigned short iSectors Track; unsigned short iHeads; // Sectors per FAT // Sectors per Track // Number of heads unsigned short iHiddenSectors; // Number of hidden sectors }; unsigned short endianSwap(unsigned char one, unsigned char two); // Pre: Two initialized characters // Post: The characters are swapped (two, one) and returned as a short void decodeBootSector(struct BootSector * pBoots, unsigned char buffer[]); // Pre: An initialized BootSector struct and a pointer to an array of characters read from a BootSector // Post: The BootSector struct is filled out from the buffer data void printBootSector(struct BootSector * pBoots); // Pre: A filled BootSector struct // Post: The information about the boot sector prints to the console // entry point: int main(int args, char * argv[]) { int pBootSector 0; unsigned char buffer[SIZE]; struct BootSector sector; // Check for argument if (argc sName); printf(" Bytes/Sector: %i ", pBoots->iBytes Sector); printf(" Sectors/Cluster: %i ", pBoots->iSectorsCluster); printf(" Reserved Sectors: %i ", pBoots->iReservedSectors); printf(" Number of FATS: %i ", pBoots-> NumberFATS); printf(" Root Directory entries: %i ", pBoots->iRootEntries); printf(" Logical sectors: %i ", pBoots->iLogicalSectors); printf(" Medium descriptor: @x%04x ", pBoots->xMediumDescriptor); printf(" Sectors/FAT: %i ", pBoots->iSectorsFAT); printf(" Sectors/Track: %i ", pBoots->iSectorsTrack); printf(" Number of heads: %i ", pBoots->iHeads); printf("Number of Hidden Sectors: %i ", pBoots->iHiddenSectors); #else printf(" Name: pBoots->sName); printf(" Bytes/Sector: 0x%04x ", pBoots->iBytesSector); printf(" Sectors/Cluster: 0x%02x ", pBoots->iSectorsCluster); printf(" Reserved Sectors: @x%04x ", pBoots->iReservedSectors); printf(" Number of FATS: 0x%02x ", pBoots->iNumberFATs); printf("Root Directory entries: 0x%04x ", pBoots-> RootEntries); printf(" Logical sectors: 0x%04x ", pBoots->iLogicalSectors); printf(" Medium descriptor: @x%02x ", pBoots->xMediumDescriptor); printf(" Sectors/FAT: @x%04x ", pBoots->iSectorsFAT); printf(" Sectors/Track: @x%04x ", pBoots->iSectorsTrack); printf(" Number of heads: Ox%04x ", pBoots->iHeads); printf("Number of Hidden Sectors: 0x%04x ", pBoots->iHiddenSectors); #endif return; } %s
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started