> < > DISK1 » a Name Date Modified Size .fseventsd ATTRIB.EXE AUTOEXEC.BAT CHKDSK.EXE COMMAND.COM CONFIG.SYS COUNTRY.SYS COUNTRY.TX DEBUG.EXE DEFRAG.EXE DEFRAG.HL DOSSETUP.INI DRVSPACE.BIN Yesterday at 7:37 PM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM 37 1 5 13 EDIT.COM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM 2 1 7 6 413 EGA.CP_ May 31, 1994 at 6:22 AM 1 EGA2.CP May 31, 1994 at 6:22 AM 1 EGA3.CP_ May 31, 1994 at 6:22 AM 1 EMM386.EX May 31, 1994 at 6:22 AM 5 EXPAND.EXE FDISK.EXE FORMAT.COM May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 2 IO.SYS May 31, 1994 at 6:22 AM 4 < > > V3 + KEYB.COM ISO.CP_ May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 1 KEYBOARD.SYS May 31, 1994 at 6:22 AM 3 Name DISK1 disk1.img extract_file extract_file.c PACKING.LST QBASIC.EXE iCloud Drive > Desktop KEYBRD2.SY_ MEM.EX MSCDEX.EXE MSDOS.SYS NETWORKS.TXT May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 3 May 31, 1994 at 6:22 AM 1 NLSFUNC.EXE May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM V3 > May 31, 1994 at 6:22 AM DISK1 19 MacBook Pro 74 75 76 77 78 dir_entry_t✶ getRootDirEntries (FILE *disk, boot_t * 79 } 80 uint16_t rootDirSectors ((bootSector->root_di uint8_t *buffer = (uint8_t *)malloc(rootDirSect readSector (disk, bootSector->reserved_sectors + return (dir_entry_t *) buffer; dir_entry_t* find Root DirEntry(const char *filename, for (int i = 0; i < numEntries; i++) { if (strncmp(entries [i].filename, filename, return &entries [i]; 81 82 83 84 85 } 86 } 87 return NULL; 88 } 89 90 PROBLEMS void readCluster(FILE *disk. uint32 t clusterNumber. OUTPUT DEBUG CONSOLE TERMINAL PORTS End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reache^C }
> < > DISK1 » a Name Date Modified Size .fseventsd ATTRIB.EXE AUTOEXEC.BAT CHKDSK.EXE COMMAND.COM CONFIG.SYS COUNTRY.SYS COUNTRY.TX DEBUG.EXE DEFRAG.EXE DEFRAG.HL DOSSETUP.INI DRVSPACE.BIN Yesterday at 7:37 PM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM 37 1 5 13 EDIT.COM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM 2 1 7 6 413 EGA.CP_ May 31, 1994 at 6:22 AM 1 EGA2.CP May 31, 1994 at 6:22 AM 1 EGA3.CP_ May 31, 1994 at 6:22 AM 1 EMM386.EX May 31, 1994 at 6:22 AM 5 EXPAND.EXE FDISK.EXE FORMAT.COM May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 2 IO.SYS May 31, 1994 at 6:22 AM 4 < > > V3 + KEYB.COM ISO.CP_ May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 1 KEYBOARD.SYS May 31, 1994 at 6:22 AM 3 Name DISK1 disk1.img extract_file extract_file.c PACKING.LST QBASIC.EXE iCloud Drive > Desktop KEYBRD2.SY_ MEM.EX MSCDEX.EXE MSDOS.SYS NETWORKS.TXT May 31, 1994 at 6:22 AM 1 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 2 May 31, 1994 at 6:22 AM 3 May 31, 1994 at 6:22 AM 1 NLSFUNC.EXE May 31, 1994 at 6:22 AM May 31, 1994 at 6:22 AM V3 > May 31, 1994 at 6:22 AM DISK1 19 MacBook Pro 74 75 76 77 78 dir_entry_t✶ getRootDirEntries (FILE *disk, boot_t * 79 } 80 uint16_t rootDirSectors ((bootSector->root_di uint8_t *buffer = (uint8_t *)malloc(rootDirSect readSector (disk, bootSector->reserved_sectors + return (dir_entry_t *) buffer; dir_entry_t* find Root DirEntry(const char *filename, for (int i = 0; i < numEntries; i++) { if (strncmp(entries [i].filename, filename, return &entries [i]; 81 82 83 84 85 } 86 } 87 return NULL; 88 } 89 90 PROBLEMS void readCluster(FILE *disk. uint32 t clusterNumber. OUTPUT DEBUG CONSOLE TERMINAL PORTS End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reached unexpectedly. End of file reache^C }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
code is still giving me this error when i already asked on here and had it troubleshooted. Please help i need this program to work. Where I can extract any file in the disk img for example ./extract_file disk1.img CONFIG.SYS
#include
#include
#include
#include
#pragma pack(push, 1)
typedef struct {
int8_tjump_to_bootstrap[3];
int8_toem_id[8];
uint16_tbytes_per_sector;
uint8_tsectors_per_cluster;
uint16_treserved_sectors;
uint8_tfat_copies;
uint16_troot_dir_entries;
uint16_ttotal_sectors;
uint8_tmedia_descriptor_type;
uint16_tsectors_per_fat;
uint16_tsectors_per_track;
uint16_theads;
uint32_thidden_sectors;
uint32_ttotal_sectors2;
uint8_tdrive_index;
uint8_t_stuff;
uint8_tsignature;
uint32_tid;
int8_tlabel[11];
int8_ttype[8];
int8_t_more_stuff[448];
uint16_tsig;
} boot_t;
typedef struct {
int8_tfilename[8];
int8_textension[3];
int8_tattributes;
int8_t_reserved[10];
uint16_tupdate_time;
uint16_tupdate_date;
uint16_tstarting_cluster;
uint32_tfile_size;
} dir_entry_t;
#pragma pack(pop)
void readSector(FILE *disk, uint32_t sectorNumber, uint8_t *buffer, uint16_t bytesPerSector) {
if (disk==NULL) {
fprintf(stderr, "Invalid file pointer.\n");
return;
}
if (buffer==NULL) {
fprintf(stderr, "Invalid buffer pointer.\n");
return;
}
if (fseek(disk, sectorNumber*bytesPerSector, SEEK_SET) !=0) {
perror("Error seeking file");
return;
}
size_tbytesRead=fread(buffer, 1, bytesPerSector, disk);
if (bytesRead!=bytesPerSector) {
if (feof(disk)) {
fprintf(stderr, "End of file reached unexpectedly.\n");
} else if (ferror(disk)) {
perror("Error reading file");
}
return;
}
}
void readMBR(FILE *disk, boot_t *bootSector) {
uint8_tbuffer[512];
readSector(disk, 0, buffer, 512);
memcpy(bootSector, buffer, sizeof(boot_t));
}
dir_entry_t* getRootDirEntries(FILE *disk, boot_t *bootSector) {
uint16_trootDirSectors= ((bootSector->root_dir_entries*32) + (bootSector->bytes_per_sector-1)) /bootSector->bytes_per_sector;
uint8_t*buffer= (uint8_t*)malloc(rootDirSectors*bootSector->bytes_per_sector);
readSector(disk, bootSector->reserved_sectors+ (bootSector->fat_copies*bootSector->sectors_per_fat), buffer, rootDirSectors*bootSector->bytes_per_sector);
return (dir_entry_t*)buffer;
}
dir_entry_t* findRootDirEntry(const char *filename, dir_entry_t *entries, uint16_t numEntries) {
for (inti=0; ireserved_sectors+ (bootSector->fat_copies*bootSector->sectors_per_fat) + ((bootSector->root_dir_entries*32+bootSector->bytes_per_sector-1) /bootSector->bytes_per_sector);
uint32_tfirstSectorOfCluster= ((clusterNumber-2) *bootSector->sectors_per_cluster) +firstDataSector;
for (inti=0; isectors_per_cluster; i++) {
readSector(disk, firstSectorOfCluster+i, buffer+ (i*bootSector->bytes_per_sector), bootSector->bytes_per_sector);
}
}
void extractFile(FILE *disk, dir_entry_t *entry, boot_t *bootSector) {
uint8_t*buffer= (uint8_t*)malloc(entry->file_size);
uint32_tcluster=entry->starting_cluster;
uint32_tbytesRead=0;
while (bytesReadfile_size) {
readCluster(disk, cluster, buffer+bytesRead, bootSector);
bytesRead+=bootSector->bytes_per_sector*bootSector->sectors_per_cluster;
cluster++;
}
FILE*output=fopen("output_file", "wb");
fwrite(buffer, 1, entry->file_size, output);
fclose(output);
free(buffer);
}
int main(int argc, char *argv[]) {
if (argc!=3) {
fprintf(stderr, "Usage: %s \n", argv[0]);
return1;
}
constchar*diskImage=argv[1];
constchar*filename=argv[2];
FILE*disk=fopen(diskImage, "rb");
if (disk==NULL) {
perror("Error opening disk image");
return1;
}
boot_tbootSector;
readMBR(disk, &bootSector);
dir_entry_t*entries=getRootDirEntries(disk, &bootSector);
dir_entry_t*entry=findRootDirEntry(filename, entries, bootSector.root_dir_entries);
if (entry) {
extractFile(disk, entry, &bootSector);
printf("File extracted successfully.\n");
} else {
fprintf(stderr, "File not found in root directory.\n");
}
free(entries);
fclose(disk);
return0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education