MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / DevFS

Class DevFS

Kernel/src/device.cpp:62–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 List<Device*> devices;
61
62 class DevFS : public FsNode{
63 private:
64 fs::FsVolume vol;
65
66 public:
67 DevFS(const char* name){
68 flags = FS_NODE_DIRECTORY;
69
70 vol.mountPoint = this;
71 vol.mountPointDirent = DirectoryEntry(this, name);
72
73 fs::RegisterVolume(&vol);
74 }
75
76 int ReadDir(DirectoryEntry* dirPtr, uint32_t index) final {
77 if(index >= devices.get_length() + 2){
78 return 0;
79 }
80
81 if(index == 0){
82 strcpy(dirPtr->name, ".");
83 dirPtr->flags = FS_NODE_DIRECTORY;
84
85 return 1;
86 } else if(index == 1){
87 strcpy(dirPtr->name, "..");
88 dirPtr->flags = FS_NODE_DIRECTORY;
89
90 return 1;
91 } else {
92 strcpy(dirPtr->name, devices[index - 2]->GetName());
93
94 return 1;
95 }
96 }
97
98 FsNode* FindDir(char* name) final {
99 if(!strcmp(name, ".")){
100 return this;
101 } else if(!strcmp(name, "..")){
102 return fs::GetRoot();
103 }
104
105 for(auto& dev : devices){
106 if(!strcmp(dev->GetName(), name)){
107 return dev;
108 }
109 }
110
111 return nullptr; // No such device found
112 }
113 };
114
115 DevFS devfs = DevFS("dev");
116

Callers 1

device.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected