MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / Directory

Class Directory

lib/vfs/smaky6fs.cc:135–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134 friend class Directory;
135 class Directory
136 {
137 public:
138 /* drStartSector=0 reads the root directory; any other value reads
139 * the sub-directory stored in the first 3 sectors of a DR entry. */
140 Directory(Smaky6Filesystem* fs, unsigned drStartSector = 0)
141 {
142 auto bytes = fs->getLogicalSector(drStartSector, 3);
143 parseFrom(bytes, drStartSector);
144 }
145
146 std::shared_ptr<SmakyDirent> findFile(const std::string& filename)
147 {
148 for (auto& de : dirents)
149 if (de->filename == filename)
150 return de;
151
152 throw FileNotFoundException();
153 }
154
155 private:
156 void parseFrom(const Bytes& bytes, unsigned sectorBase)
157 {
158 for (int i = 0; i < 32; i++)
159 {
160 auto dbuf = bytes.slice(i * 0x18, 0x18);
161 /* 0x00 = empty slot; 0xFF = deleted entry */
162 if (dbuf[0] && dbuf[0] != 0xff)
163 {
164 auto de = std::make_shared<SmakyDirent>(dbuf);
165 /* Sub-directory entries use relative sector numbers;
166 * add the DR container's base sector to get absolute ones. */
167 de->startSector += sectorBase;
168 de->endSector += sectorBase;
169 dirents.push_back(de);
170 }
171 }
172 }
173
174 public:
175 std::vector<std::shared_ptr<SmakyDirent>> dirents;
176 };
177
178public:
179 Smaky6Filesystem(const Smaky6FsProto& config,

Callers 1

directoryAtMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected