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;
}
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