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

Method TarVolume

Kernel/src/fs/tar.cpp:118–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116 }
117
118 TarVolume::TarVolume(uintptr_t base, size_t size, char* name){
119 blocks = (tar_header_t*)base;
120 blockCount = size / 512;
121
122 int entryCount = 0;
123 for(uint64_t i = 0; i < blockCount; i++, nodeCount++){ // Get file count
124 tar_header_t header = blocks[i];
125
126 if(!strchr(header.ustar.name, '/') || (header.ustar.type == TAR_TYPE_DIRECTORY && strchr(header.ustar.name, '/') == header.ustar.name + strlen(header.ustar.name) - 1)) entryCount++;
127
128 i += GetBlockCount(header.ustar.size);
129 }
130
131 nodes = new TarNode[nodeCount];
132
133 TarNode* volumeNode = &nodes[0];
134 volumeNode->header = nullptr;
135 volumeNode->flags = FS_NODE_DIRECTORY | FS_NODE_MOUNTPOINT;
136 volumeNode->inode = 0;
137 volumeNode->size = size;
138 volumeNode->vol = this;
139 volumeNode->parent = 0;
140
141 mountPoint = volumeNode;
142 strcpy(mountPointDirent.name, name);
143 mountPointDirent.flags = DT_DIR;
144 mountPointDirent.node = volumeNode;
145
146 volumeNode->children = (ino_t*)kmalloc(sizeof(ino_t) * entryCount);
147 volumeNode->entryCount = entryCount;
148 int e = 0;
149 for(unsigned i = 0; i < blockCount; e++){
150 tar_header_t header = blocks[i];
151
152 if(!strlen(header.ustar.name)) break;
153
154 if(header.ustar.type == TAR_TYPE_DIRECTORY){
155 volumeNode->children[e] = nextNode; // Directory will take next available node so add it to children
156 i = ReadDirectory(i, 0);
157 continue;
158 } else if(header.ustar.type == TAR_TYPE_FILE) {
159 ino_t inode = nextNode++;
160 TarNode* node = &nodes[inode];
161 MakeNode(&blocks[i], node, inode, 0);
162 volumeNode->children[e] = inode;
163 }
164
165 i += GetBlockCount(header.ustar.size);
166 i++;
167 }
168 volumeNode->entryCount = e;
169 }
170
171 ssize_t TarVolume::Read(TarNode* node, size_t offset, size_t size, uint8_t *buffer){
172 TarNode* tarNode = &nodes[node->inode];

Callers

nothing calls this directly

Calls 5

strchrFunction · 0.85
strlenFunction · 0.85
GetBlockCountFunction · 0.85
strcpyFunction · 0.85
kmallocFunction · 0.85

Tested by

no test coverage detected