Write a program to take the name of a file in the root directory and extract its contents to your local disk. Hint: • Sector number to byte offset • Sector number to next sector number (using the FAT) • readCluster(clusterNumber) -> bytes array • readSector(sectorNumber). -> bytes array readFromSector(sectorNumber, bytes) -> bytes array • • read MBR -> boot_t ⚫ getRootDirEntries() -> dir_entry_t[] • findRootDirEntry(string filename, dir_entry_t entries[]) -> dir_entry_t // This has to do a search with a loop H EXE EXE .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 EDIT.COM EGA.CP_ EGA2.CP_ EGA3.CP_ EMM386.EX EXPAND.EXE FDISK.EXE FORMAT.COM IO.SYS ISO.CP_ KEYB.COM KEYBOARD.SYS EXE TXT KEYBRD2.SY_ MEM.EX MSCDEX.EXE MSDOS.SYS NETWORKS.TXT NLSFUNC.EXE PACKING.LST QBASIC.EXE README.TXT REPLACE.EX RESTORE.EX SCANDISK.EXE SCANDISK.INI SETUP.EXE SETUP.MSG SYS.COM XCOPY.EX_ typedef struct { int8_t int8_t uint16_t uint8_t uint16_t uint8_t uint16_t uint16_t jump_to_bootstrap [3]; oem_id [8]; bytes_per_sector; sectors_per_cluster; reserved sectors; fat_copies; root_dir_entries; total_sectors; media_descriptor_type; sectors_per_fat; uint8_t uint16_t uint16_t sectors_per_track; uint16_t heads; uint32_t hidden_sectors; uint32_t total_sectors2; uint8_t drive_index; uint8_t _stuff; uint8_t signature; uint32_t id; int8_t label [11]; int8_t type [8]; uint8_t _more_stuff [448]; uint16_t sig; } __attribute _ ((packed)) boot_t; typedef struct int8_t int8_t int8_t int8_t uint16_t uint16_t uint16_t uint32_t filename [8]; extension [3]; attributes; _reserved [10]; update_time; update_date; starting_cluster; file_size; } _ attribute _ ((packed)) dir_entry_t;
Write a program to take the name of a file in the root directory and extract its contents to your local disk. Hint: • Sector number to byte offset • Sector number to next sector number (using the FAT) • readCluster(clusterNumber) -> bytes array • readSector(sectorNumber). -> bytes array readFromSector(sectorNumber, bytes) -> bytes array • • read MBR -> boot_t ⚫ getRootDirEntries() -> dir_entry_t[] • findRootDirEntry(string filename, dir_entry_t entries[]) -> dir_entry_t // This has to do a search with a loop H EXE EXE .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 EDIT.COM EGA.CP_ EGA2.CP_ EGA3.CP_ EMM386.EX EXPAND.EXE FDISK.EXE FORMAT.COM IO.SYS ISO.CP_ KEYB.COM KEYBOARD.SYS EXE TXT KEYBRD2.SY_ MEM.EX MSCDEX.EXE MSDOS.SYS NETWORKS.TXT NLSFUNC.EXE PACKING.LST QBASIC.EXE README.TXT REPLACE.EX RESTORE.EX SCANDISK.EXE SCANDISK.INI SETUP.EXE SETUP.MSG SYS.COM XCOPY.EX_ typedef struct { int8_t int8_t uint16_t uint8_t uint16_t uint8_t uint16_t uint16_t jump_to_bootstrap [3]; oem_id [8]; bytes_per_sector; sectors_per_cluster; reserved sectors; fat_copies; root_dir_entries; total_sectors; media_descriptor_type; sectors_per_fat; uint8_t uint16_t uint16_t sectors_per_track; uint16_t heads; uint32_t hidden_sectors; uint32_t total_sectors2; uint8_t drive_index; uint8_t _stuff; uint8_t signature; uint32_t id; int8_t label [11]; int8_t type [8]; uint8_t _more_stuff [448]; uint16_t sig; } __attribute _ ((packed)) boot_t; typedef struct int8_t int8_t int8_t int8_t uint16_t uint16_t uint16_t uint32_t filename [8]; extension [3]; attributes; _reserved [10]; update_time; update_date; starting_cluster; file_size; } _ attribute _ ((packed)) dir_entry_t;
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
please help, i use mac terminal so pls also include how to compile and run. I need this code to work for any file in the directory given by the disk image i think. So id like the code to work with any disk img etc. The code solutions i have gotten from bartleby compile but does not find the file even though i entered it right after compiling. please help. ifpossible can you aslo maybe send a screenshot of it running on your end and working with a file in a directory of disk img?
"Desktop % ./extract_file disk_image.img CONFIG.SYS output_file.ext
File not found in root directory"
![Write a program to take the name of a file in the root directory and extract its contents to your
local disk.
Hint:
• Sector number to byte offset
• Sector number to next sector number (using the FAT)
•
readCluster(clusterNumber) -> bytes array
• readSector(sectorNumber). -> bytes array
readFromSector(sectorNumber, bytes) -> bytes array
•
•
read MBR -> boot_t
⚫ getRootDirEntries() -> dir_entry_t[]
•
findRootDirEntry(string filename, dir_entry_t entries[]) -> dir_entry_t // This has to do a
search with a loop
H
EXE
EXE
.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
EDIT.COM
EGA.CP_
EGA2.CP_
EGA3.CP_
EMM386.EX
EXPAND.EXE
FDISK.EXE
FORMAT.COM
IO.SYS
ISO.CP_
KEYB.COM
KEYBOARD.SYS
EXE
TXT
KEYBRD2.SY_
MEM.EX
MSCDEX.EXE
MSDOS.SYS
NETWORKS.TXT
NLSFUNC.EXE
PACKING.LST
QBASIC.EXE
README.TXT
REPLACE.EX
RESTORE.EX
SCANDISK.EXE
SCANDISK.INI
SETUP.EXE
SETUP.MSG
SYS.COM
XCOPY.EX_](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4217e83c-b4b2-47da-9d7a-2d6031448fca%2Fd9481f5b-8985-46e3-b13e-0ab67bc5bf2e%2Fjnl6upn_processed.png&w=3840&q=75)
Transcribed Image Text:Write a program to take the name of a file in the root directory and extract its contents to your
local disk.
Hint:
• Sector number to byte offset
• Sector number to next sector number (using the FAT)
•
readCluster(clusterNumber) -> bytes array
• readSector(sectorNumber). -> bytes array
readFromSector(sectorNumber, bytes) -> bytes array
•
•
read MBR -> boot_t
⚫ getRootDirEntries() -> dir_entry_t[]
•
findRootDirEntry(string filename, dir_entry_t entries[]) -> dir_entry_t // This has to do a
search with a loop
H
EXE
EXE
.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
EDIT.COM
EGA.CP_
EGA2.CP_
EGA3.CP_
EMM386.EX
EXPAND.EXE
FDISK.EXE
FORMAT.COM
IO.SYS
ISO.CP_
KEYB.COM
KEYBOARD.SYS
EXE
TXT
KEYBRD2.SY_
MEM.EX
MSCDEX.EXE
MSDOS.SYS
NETWORKS.TXT
NLSFUNC.EXE
PACKING.LST
QBASIC.EXE
README.TXT
REPLACE.EX
RESTORE.EX
SCANDISK.EXE
SCANDISK.INI
SETUP.EXE
SETUP.MSG
SYS.COM
XCOPY.EX_
![typedef struct
{
int8_t
int8_t
uint16_t
uint8_t
uint16_t
uint8_t
uint16_t
uint16_t
jump_to_bootstrap [3];
oem_id [8];
bytes_per_sector;
sectors_per_cluster;
reserved sectors;
fat_copies;
root_dir_entries;
total_sectors;
media_descriptor_type;
sectors_per_fat;
uint8_t
uint16_t
uint16_t
sectors_per_track;
uint16_t
heads;
uint32_t
hidden_sectors;
uint32_t
total_sectors2;
uint8_t
drive_index;
uint8_t
_stuff;
uint8_t
signature;
uint32_t
id;
int8_t
label [11];
int8_t
type [8];
uint8_t
_more_stuff [448];
uint16_t
sig;
} __attribute _ ((packed)) boot_t;
typedef struct
int8_t
int8_t
int8_t
int8_t
uint16_t
uint16_t
uint16_t
uint32_t
filename [8];
extension [3];
attributes;
_reserved [10];
update_time;
update_date;
starting_cluster;
file_size;
} _ attribute _ ((packed)) dir_entry_t;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4217e83c-b4b2-47da-9d7a-2d6031448fca%2Fd9481f5b-8985-46e3-b13e-0ab67bc5bf2e%2Feqauojoh_processed.png&w=3840&q=75)
Transcribed Image Text:typedef struct
{
int8_t
int8_t
uint16_t
uint8_t
uint16_t
uint8_t
uint16_t
uint16_t
jump_to_bootstrap [3];
oem_id [8];
bytes_per_sector;
sectors_per_cluster;
reserved sectors;
fat_copies;
root_dir_entries;
total_sectors;
media_descriptor_type;
sectors_per_fat;
uint8_t
uint16_t
uint16_t
sectors_per_track;
uint16_t
heads;
uint32_t
hidden_sectors;
uint32_t
total_sectors2;
uint8_t
drive_index;
uint8_t
_stuff;
uint8_t
signature;
uint32_t
id;
int8_t
label [11];
int8_t
type [8];
uint8_t
_more_stuff [448];
uint16_t
sig;
} __attribute _ ((packed)) boot_t;
typedef struct
int8_t
int8_t
int8_t
int8_t
uint16_t
uint16_t
uint16_t
uint32_t
filename [8];
extension [3];
attributes;
_reserved [10];
update_time;
update_date;
starting_cluster;
file_size;
} _ attribute _ ((packed)) dir_entry_t;
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