tac0S
Template Affectional Command Operating System
directory.h
Go to the documentation of this file.
1 
15 #include "copyright.h"
16 
17 #ifndef DIRECTORY_H
18 #define DIRECTORY_H
19 
20 #include "openfile.h"
21 
22 #define FileNameMaxLen 15 // for simplicity, we assume file names are <= 9 characters long
23 
30 
32 public:
33  bool inUse; // Is this directory entry in use?
34  int sector; // Location on disk to find the FileHeader for this file
35  char name[FileNameMaxLen + 1]; // Text name for file, with +1 for the trailing '\0'
36 };
37 
38 // The following class defines a UNIX-like "directory". Each entry in
39 // the directory describes a file, and where to find it on disk.
40 //
41 // The directory data structure can be stored in memory, or on disk.
42 // When it is on disk, it is stored as a regular Nachos file.
43 //
44 // The constructor initializes a directory structure in memory; the
45 // FetchFrom/WriteBack operations shuffle the directory information
46 // from/to disk.
47 
48 class Directory {
49 public:
50  Directory(int size); // Initialize an empty directory
51  // with space for "size" files
52  ~Directory(); // De-allocate the directory
53 
54  void FetchFrom(OpenFile *file); // Init directory contents from disk
55  void WriteBack(OpenFile *file); // Write modifications to
56  // directory contents back to disk
57 
58  int Find(const char *name); // Find the sector number of the FileHeader for file: "name"
59 
60  bool Add(const char *name, int newSector); // Add a file name into the directory
61 
62  bool Remove(const char *name); // Remove a file from the directory
63 
64  void List(); // Print the names of all the files in the directory
65  void Print(); // Verbose print of the contents of the directory -- all the file names and their contents.
66  bool isEmpty(); // check if the folder is empty
67 private:
68  int tableSize; // Number of directory entries
69  DirectoryEntry *table; // Table of pairs: <file name, file header location>
70 
71  int FindIndex(const char *name); // Find the index into the directory table corresponding to "name"
72 };
73 
74 #endif // DIRECTORY_H
Data structures for opening, closing, reading and writing.
Definition: list.h:46
Definition: openfile.h:77
void Print(char *name)
Print Print the contents of the Nachos file "name".
Definition: fstest.cc:79
The following class defines a "directory entry", representing a file in the directory. Each entry gives the name of the file, and where the file&#39;s header is to be found on disk.
Definition: directory.h:31
Definition: directory.h:48