Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me solve this code The ds 3 cat utility prints the contents of a file to standard output. It takes the name of
please help me solve this code
The dscat utility prints the contents of a file to standard output. It takes the name of the disk image file and an inode number as the only arguments. It prints the contents of the file that is specified by the inode number.
For this utility, first print the string File blocks with a newline at the end and then print each of the disk block numbers for the file to standard out, one disk block number per line. After printing the file blocks, print an empty line with only a newline.
Next, print the string File data with a newline at the end and then print the full contents of the file to standard out. You do not need to differentiate between files and directories, for this utility everything is considered to be data and should be printed to standard out.
#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 ;
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