tac0S
Template Affectional Command Operating System
filehdr.h
Go to the documentation of this file.
1 
13 #include "copyright.h"
14 
15 #ifndef FILEHDR_H
16 #define FILEHDR_H
17 
18 #include "disk.h"
19 #include "bitmap.h"
20 
21 #define NumDirect ((SectorSize - 2 * sizeof(int)) / sizeof(int))
22 #define MaxFileSize (NumDirect * SectorSize)
23 
25 enum File_type {
26  f, // file type
27  d // directory type
28 };
29 
44 
45 class FileHeader {
46 public:
47  bool Allocate(BitMap *bitMap, int fileSize);// Initialize a file header,
48  // including allocating space
49  // on disk for the file data
50  void Deallocate(BitMap *bitMap); // De-allocate this file's
51  // data blocks
52 
53  void FetchFrom(int sectorNumber); // Initialize file header from disk
54  void WriteBack(int sectorNumber); // Write modifications to file header
55  // back to disk
56 
57  int ByteToSector(int offset); // Convert a byte offset into the file
58  // to the disk sector containing
59  // the byte
60 
61  int FileLength(); // Return the length of the file in bytes
62 
63  void Print(); // Print the contents of the file.
64 
65  File_type type;
66 
67  void test();
68 
69  int get_sector(int id_sector);
70 
71  void set_sector(int id_sector, int sector);
72 
73 private:
74  int numBytes; // Number of bytes in the file
75  int numSectors; // Number of data sectors in the file
76  int dataSectors[NumDirect]; // Disk sector numbers for each data block in the file
77 
78 };
79 
80 #endif // FILEHDR_H
void FetchFrom(int sectorNumber)
FileHeader::FetchFrom Fetch contents of file header from disk.
Definition: filehdr.cc:74
File_type
enum that define if the FileHeader define a file or a directory
Definition: filehdr.h:25
void Print()
FileHeader::Print Print the contents of the file header, and the contents of all the data blocks poin...
Definition: filehdr.cc:119
The following class defines a "bitmap" – an array of bits, each of which can be independently set...
Definition: bitmap.h:36
int FileLength()
FileHeader::FileLength.
Definition: filehdr.cc:110
int ByteToSector(int offset)
FileHeader::ByteToSector.
Definition: filehdr.cc:100
Data structures defining a bitmap.
bool Allocate(BitMap *bitMap, int fileSize)
FileHeader::Allocate Initialize a fresh file header for a newly created file. Allocate data blocks fo...
Definition: filehdr.cc:42
void WriteBack(int sectorNumber)
FileHeader::WriteBack Write the modified contents of the file header back to disk.
Definition: filehdr.cc:85
void Deallocate(BitMap *bitMap)
FileHeader::Deallocate De-allocate all the space allocated for data blocks for this file...
Definition: filehdr.cc:60
The following class defines the Nachos "file header" (in UNIX terms, the "i-node"), describing where on disk to find all of the data in the file. The file header is organized as a simple table of pointers to data blocks.
Definition: filehdr.h:45
Data structures to emulate a physical disk