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

Method ReadDirectory

Kernel/src/fs/tar.cpp:85–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83 }
84
85 int TarVolume::ReadDirectory(int blockIndex, ino_t parent){
86 ino_t dirInode = nextNode++;
87 tar_header_t* dirHeader = &blocks[blockIndex];
88 TarNode* dirNode = &nodes[dirInode];
89 MakeNode(dirHeader, dirNode, dirInode, parent);
90 dirNode->entryCount = 0;
91
92 unsigned i = blockIndex + GetBlockCount(dirHeader->ustar.size) + 1; // Next block
93 while(i < blockCount){
94 if(strncmp(blocks[i].ustar.name, dirHeader->ustar.name, strlen(dirHeader->ustar.name)) || !strlen(blocks[i].ustar.name)){
95 break; // End of directory - header is not in directory
96 }
97 dirNode->entryCount++;
98 i += GetBlockCount(blocks[i].ustar.size) + 1;
99 }
100
101 dirNode->children = (ino_t*)kmalloc(sizeof(ino_t) * dirNode->entryCount);
102
103 i = blockIndex + GetBlockCount(dirHeader->ustar.size) + 1;
104 for(int e = 0; i < blockCount && e < dirNode->entryCount; e++){ // Iterate through directory
105 ino_t inode = nextNode++;
106 TarNode* n = &nodes[inode];
107 MakeNode(&blocks[i], n, inode, dirInode, dirHeader);
108 dirNode->children[e] = inode;
109
110 //Log::Info("[TAR] Found File: %s, ", blocks[i].ustar.name);
111
112 i += GetBlockCount(blocks[i].ustar.size) + 1;
113 }
114
115 return i;
116 }
117
118 TarVolume::TarVolume(uintptr_t base, size_t size, char* name){
119 blocks = (tar_header_t*)base;

Callers

nothing calls this directly

Calls 4

GetBlockCountFunction · 0.85
strncmpFunction · 0.85
strlenFunction · 0.85
kmallocFunction · 0.85

Tested by

no test coverage detected