-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryItem.cpp
More file actions
84 lines (69 loc) · 2.03 KB
/
DirectoryItem.cpp
File metadata and controls
84 lines (69 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
74
75
76
77
78
79
80
81
82
83
84
#include "DirectoryItem.hpp"
#include <cstring>
using std::strncpy;
using std::strcmp;
DirectoryItem::DirectoryItem(int32_t inodeId, const char* itemName)
: inode(inodeId), next(nullptr) {
strncpy(this->itemName, itemName, 11);
this->itemName[11] = '\0'; // Ensure null termination
}
DirectoryItem::DirectoryItem(const DirectoryItem& other)
: inode(other.inode), next(other.next) {
strcpy(this->itemName, other.itemName);
}
DirectoryItem& DirectoryItem::operator=(const DirectoryItem& other) {
if (this != &other) {
inode = other.inode;
strcpy(this->itemName, other.itemName);
next = other.next;
}
return *this;
}
DirectoryItem::~DirectoryItem() {
// No dynamic memory to delete
}
int32_t DirectoryItem::getInode() const {
return inode;
}
void DirectoryItem::setInode(int32_t inodeId) {
inode = inodeId;
}
const char* DirectoryItem::getItemName() const {
return itemName;
}
void DirectoryItem::setItemName(const char* itemName) {
strncpy(this->itemName, itemName, 11);
this->itemName[11] = '\0';
}
DirectoryItem* DirectoryItem::getNext() const {
return next;
}
DirectoryItem*& DirectoryItem::getNextRef() {
return next;
}
void DirectoryItem::setNext(DirectoryItem* nextItem) {
next = nextItem;
}
DirectoryItem* createDirectoryItem(int32_t inodeId, const char* name) {
return new DirectoryItem(inodeId, name);
}
DirectoryItem* findItem(DirectoryItem* firstItem, const char* name) {
DirectoryItem* currentItem = firstItem;
while (currentItem != nullptr) {
if (strcmp(name, currentItem->getItemName()) == 0) {
return currentItem;
}
currentItem = currentItem->getNext();
}
return nullptr;
}
DirectoryItem* findItemByInodeId(DirectoryItem* firstItem, int32_t inodeId) {
DirectoryItem* currentItem = firstItem;
while (currentItem != nullptr) {
if (inodeId == currentItem->getInode()) {
return currentItem;
}
currentItem = currentItem->getNext();
}
return nullptr;
}