-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemManager.cc
103 lines (86 loc) · 3.2 KB
/
FileSystemManager.cc
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* FileSystemManager.cc
*
* Created on: Oct 15, 2015
* Author: Prasanna Ponnada
*/
#include "FileSystemManager.h"
#include "KVStore.h"
#include "KVFSDirectory.h"
#include "KVFSFile.h"
FileSystemManager::FileSystemManager(KVStore* kvStore):kvstore(kvStore) {}
uint64_t
FileSystemManager::mountFileSystem(std::string& fsName, void*& fsHandle) {
uint64_t fsId = -1;
if (this->getKVStore()->open(fsName, &fsHandle) == true) {
fsId = CityHash64(fsName.c_str(), fsName.length());
return fsId;
}
return fsId;
}
bool
FileSystemManager::addDirectory(uint64_t fsId,
const std::string& parent_dir_name,
const std::string& dir_name,
KVFSMetaData metadata,
uint64_t dirHandle,
void* fsHandle) {
bool status = false;
std::string absolutePath = parent_dir_name + dir_name;
if (parent_dir_name == dir_name) {
KVFSObject* directory = new KVFSDirectory(fsId, parent_dir_name,
dir_name,
metadata, dirHandle);
if (directory->exists(this->getKVStore(), fsHandle)) {
std::cerr << "Directory: " << dir_name << " already exists" <<
std::endl;
return false;
}
status = directory->create(this->getKVStore(), fsHandle);
return status;
}
KVFSObject* parentDirectory = new KVFSDirectory(fsId, parent_dir_name,
parent_dir_name,
metadata, dirHandle);
if (!parentDirectory->exists(this->getKVStore(), fsHandle)) {
std::cerr << "Parent directory: " << parent_dir_name <<
" doesn't exist " << std::endl;
return false;
}
KVFSObject* directory = new KVFSDirectory(fsId, parent_dir_name, dir_name,
metadata, dirHandle);
if (directory->exists(this->getKVStore(), fsHandle)) {
std::cerr << "Directory: " << parent_dir_name + dir_name <<
" already exists " << std::endl;
return false;
} else
status = directory->create(this->getKVStore(), fsHandle);
return status;
}
bool
FileSystemManager::listDirectory(uint64_t fsId,
const std::string& parent_dir_name,
const std::string& dir_name,
KVFSMetaData metadata,
KVFSDirectoryEntry* entries,
uint64_t* entryCount,
void* fsHandle) {
*entryCount = 0;
entries->directoryEntries.clear();
std::string sub_dir_name = (parent_dir_name == dir_name) ?
parent_dir_name : dir_name;
KVFSDirectory* kvsFSDir = new KVFSDirectory(fsId, parent_dir_name,
sub_dir_name, metadata, -1);
if(!kvsFSDir->exists(this->getKVStore(), fsHandle)) {
return false;
}
kvsFSDir->listDirectory(entries, entryCount, this->getKVStore(), fsHandle);
return true;
}
bool
FileSystemManager::removeDirectory(uint64_t fsId,
const std::string& parent_dir_name,
const std::string& dir_name,
void* fsHandle) {
return true;
}