
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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;
}

Transcribed Image Text:>
< > 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
}](https://content.bartleby.com/qna-images/question/4217e83c-b4b2-47da-9d7a-2d6031448fca/537af5e2-e845-4257-b00f-2f6928b29d91/y31kz9c_thumbnail.jpeg)
Transcribed Image Text: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
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- pls help NOTE! it must be in ARM assembly languagearrow_forwardCan you do 1 and 2 please? (C++ language) 1- Please implement the Word Counting program that is shown in the pictures attached. 2- Also in the same program count the number of words longer than 3 letters.arrow_forwardPYTHON cannot use numpy, opencv, array, readline( ), or enumerate. can only use open, read, write, and close methods for files. please utilize split and append functionsarrow_forward
- MASM x86 classarrow_forwardPlz use c programming to solve this question. Plz don't use a library other than # include < stdio. h > and # include math . h and # define n 100arrow_forward1-Write a JAVA program that reads an array from input file and invokes twodifferent methods Sort and Max ,that sorts the elements of the array and findsthe Max element and writes out the resulted array in to output file . Usetwo interfaces for methods and throw Exception Handling for Out Of Boundindex for the arrayarrow_forward
- Please answer in C++arrow_forwardC# also I have a error that states cannot open assembly 'debugone4.exe' no such file or directoryarrow_forwardPlease design the mapper and reducer for the below WordCount problem. WordCount problem: Given an input text file, count the frequency of each word in the file. Please design the input and output pairs for the Mapper and Reducer, use below table for reference. Input Output We get the "WordCount.jar" file by using the above table. It only contains Mapper and Reducer. There is no Combiner and no Partitioner in this program. Please illustrate how the WordCount.jar program works on the below dataset. This text file only contains one line. Dataset: the sound sounds sound. it is the right right, right? Suppose we run the WordCount.jar program on this file. Suppose that the space symbol, and "?" are all used for separating the words. The outputs of the Mapper are Mapper The outputs of the reducer are Reducer Answer: Are the results sorted alphabetically? When was it sorted? 2 27 20 35arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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