Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me solve this question The ds 3 ls utility prints the names for all of the files and directories in a disk image.
Please help me solve this question
The dsls utility prints the names for all of the files and directories in a disk image. This utility takes a single command line argument: the name of the disk image file to use. This program will start at the root of the file system, print the contents of that directory in full, and then traverse to each directory contained within. This process repeats in a depthfirst fasion until all file and directory names have been printed.
When printing the contents of a directory, first, print the word Directory followed by a space and then the full path for the directory you're printing, and ending it with a newline. Second, print each of the entries in that directory. Sorted each entry using std::strcmp and print them in that order. Each entry will include the inode number, a tab, the name of the entry, and finishing it off with a newline. Third, print a empty line consisting of only a newline to finish printing the contents of the directory.
Make sure that your solution does not print the contents of and subdirectories as this action would lead to an infinitely loop.
After printing a directory, traverse into each subdirectory and repeat the process recursively in a depthfirst fashion.
LocalFileSystem.cpp
#include
#include
#include
#include
#include
#include "LocalFileSystem.h
#include "ufs.h
using namespace std;
LocalFileSystem::LocalFileSystemDisk disk
thisdisk disk;
void LocalFileSystem::readDataBitmapsupert super unsigned char dataBitmap
for int i ; i superdatabitmaplen; i
diskreadBlocksuperdatabitmapaddr i dataBitmap i UFSBLOCKSIZE;
void LocalFileSystem::readInodeBitmapsupert super unsigned char inodeBitmap
for int i ; i superinodebitmaplen; i
diskreadBlocksuperinodebitmapaddr i inodeBitmap i UFSBLOCKSIZE;
void LocalFileSystem::readSuperBlocksupert super
unsigned char bufferUFSBLOCKSIZE;
diskreadBlock buffer;
memcpysuper buffer, sizeofsupert;
void LocalFileSystem::readInodeRegionsupert super inodet inodes
int numBlocks superinoderegionlen;
for int i ; i numBlocks; i
int blockIndex superinoderegionaddr i;
char bufferUFSBLOCKSIZE;
diskreadBlockblockIndex buffer;
memcpyinodes i UFSBLOCKSIZE sizeofinodet buffer, UFSBLOCKSIZE;
int LocalFileSystem::readint inodeNumber, void buffer int size
if size return EINVALIDSIZE;
inodet inode;
if statinodeNumber &inode return EINVALIDINODE;
if inodetype UFSREGULARFILE return EINVALIDTYPE;
int bytesRead ;
int remainingSize minsize inode.size;
int blockIndex ;
while remainingSize && blockIndex DIRECTPTRS
if inodedirectblockIndex staticcast
break;
int blockSize minremainingSize UFSBLOCKSIZE;
diskreadBlockinodedirectblockIndex staticcastbuffer bytesRead;
bytesRead blockSize;
remainingSize blockSize;
blockIndex;
return bytesRead;
int LocalFileSystem::lookupint parentInodeNumber, string name
return ;
int LocalFileSystem::statint inodeNumber, inodet inode
supert super;
readSuperBlock&super;
if inodeNumber inodeNumber super.numinodes
return EINVALIDINODE;
inodet inodessupernuminodes;
readInodeRegion&super, inodes;
if inodesinodeNumbertype Assuming represents an invalid inode
return ENOTALLOCATED;
inode inodesinodeNumber;
return ;
int LocalFileSystem::createint parentInodeNumber, int type, string name
return ;
int LocalFileSystem::writeint inodeNumber, const void buffer int size
return ;
int LocalFileSystem::unlinkint parentInodeNumber, string name
return ;
dslscpp
#include
#include
#include
#include
#include
#include "Disk.h
#include "LocalFileSystem.h
#include "ufs.h
using namespace std;
int mainint argc, char argv
if argc
cout "Usage: argv diskImageFile" endl;
return ;
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