hw4 test
This commit is contained in:
@@ -27,32 +27,38 @@
|
||||
#ifdef FILESYS_STUB // Temporarily implement calls to
|
||||
// Nachos file system as calls to UNIX!
|
||||
// See definitions listed under #else
|
||||
typedef int OpenFileId;
|
||||
|
||||
class OpenFile {
|
||||
public:
|
||||
OpenFile(int f) { file = f; currentOffset = 0; } // open the file
|
||||
~OpenFile() { Close(file); } // close the file
|
||||
|
||||
int ReadAt(char *into, int numBytes, int position) {
|
||||
Lseek(file, position, 0);
|
||||
return ReadPartial(file, into, numBytes);
|
||||
Lseek(file, position, 0);
|
||||
return ReadPartial(file, into, numBytes);
|
||||
}
|
||||
int WriteAt(char *from, int numBytes, int position) {
|
||||
Lseek(file, position, 0);
|
||||
WriteFile(file, from, numBytes);
|
||||
return numBytes;
|
||||
Lseek(file, position, 0);
|
||||
WriteFile(file, from, numBytes);
|
||||
return numBytes;
|
||||
}
|
||||
int Read(char *into, int numBytes) {
|
||||
int numRead = ReadAt(into, numBytes, currentOffset);
|
||||
currentOffset += numRead;
|
||||
return numRead;
|
||||
}
|
||||
int numRead = ReadAt(into, numBytes, currentOffset);
|
||||
currentOffset += numRead;
|
||||
return numRead;
|
||||
}
|
||||
int Write(char *from, int numBytes) {
|
||||
int numWritten = WriteAt(from, numBytes, currentOffset);
|
||||
currentOffset += numWritten;
|
||||
return numWritten;
|
||||
int numWritten = WriteAt(from, numBytes, currentOffset);
|
||||
currentOffset += numWritten;
|
||||
return numWritten;
|
||||
}
|
||||
|
||||
int Length() { Lseek(file, 0, 2); return Tell(file); }
|
||||
|
||||
OpenFileId GetFileDescriptor() {
|
||||
return file;
|
||||
}
|
||||
|
||||
private:
|
||||
int file;
|
||||
|
||||
Reference in New Issue
Block a user