-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.h
More file actions
73 lines (65 loc) · 2.03 KB
/
Directory.h
File metadata and controls
73 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** @file Directory.h
*
* Directory structure
*
* @author Copyright Aniesh Chawla, Sept 2015
**/
#ifndef DIRECTORY_H
#define DIRECTORY_H
#include <map>
#include "includes.h"
#include "FAT.h"
#include "FileName.h"
#include "FCB.h"
struct ltname
{
bool operator()(FileName name1, FileName name2) const
{
return name1.compare(name2) < 0;
}
};
typedef std::map<FileName, FCB, ltname> DirectoryMap;
/** Directory helper object.
*
* Stores directory information obtained from disk. The root directory is
* assumed to be located right after the FAT on disk. A search starts at
* the root directory and recursively moves down a path. The directory
* object is used to obtain and set file FCBs, list directory content,
* create directory entries, erase directory entries, and more.
**/
class Directory
{
private:
/// A reference to the FAT of a Disk
FAT& fat;
/// The directory map from file names to FCBs
DirectoryMap dir;
/// The start block of the directory on Disk
int start_block;
/// Indicates that the directory has changed and need to be flushed
bool updated;
public:
/// Create a new directory helper object from the root directory of the FAT.
Directory(FAT& fat);
~Directory();
/// Checks if the directory is empty.
bool empty();
/// Change the current directory by searching down the path.
int chdir(const char *path);
/// Create a new directory in the current directory.
int mkdir(const FileName& name);
/// Check if a file or directory exists in the current directory.
bool exists(const FileName& name) const;
/// Erase a file or directory from the current directory.
int erase(const FileName& name);
/// Get the FCB of a file in the current directory.
const FCB *get_fcb(const FileName& name) const;
/// Set the FCB for a file in the current directory.
void set_fcb(const FileName& name, const FCB& fcb);
/// List the current directory.
void list();
private:
int retrieve(int block_num);
int flush();
};
#endif