| 150 | } |
| 151 | |
| 152 | uint32_t Ext2Volume::GetInodeBlock(uint32_t index, ext2_inode_t& ino){ |
| 153 | uint32_t blocksPerPointer = blocksize / sizeof(uint32_t); // Amount of blocks in a indirect block table |
| 154 | uint32_t singlyIndirectStart = EXT2_DIRECT_BLOCK_COUNT; |
| 155 | uint32_t doublyIndirectStart = singlyIndirectStart + blocksPerPointer; |
| 156 | uint32_t triplyIndirectStart = doublyIndirectStart + blocksPerPointer * blocksPerPointer; |
| 157 | |
| 158 | assert(index < triplyIndirectStart + blocksPerPointer * blocksPerPointer * blocksPerPointer); // Make sure that an invalid index was not passed |
| 159 | |
| 160 | if(index < EXT2_DIRECT_BLOCK_COUNT){ |
| 161 | // Index lies within the direct blocklist |
| 162 | return ino.blocks[index]; |
| 163 | } else if(index < doublyIndirectStart){ |
| 164 | // Index lies within the singly indirect blocklist |
| 165 | uint32_t buffer[blocksize / sizeof(uint32_t)]; |
| 166 | |
| 167 | if(int e = ReadBlockCached(ino.blocks[EXT2_SINGLY_INDIRECT_INDEX], buffer)){ |
| 168 | (void)e; |
| 169 | error = DiskReadError; |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | return buffer[index - singlyIndirectStart]; |
| 174 | } else if(index < triplyIndirectStart){ |
| 175 | // Index lies within the doubly indirect blocklist |
| 176 | uint32_t blockPointers[blocksize / sizeof(uint32_t)]; |
| 177 | uint32_t buffer[blocksize / sizeof(uint32_t)]; |
| 178 | |
| 179 | if(int e = ReadBlockCached(ino.blocks[EXT2_DOUBLY_INDIRECT_INDEX], blockPointers)){ |
| 180 | (void)e; |
| 181 | error = DiskReadError; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | uint32_t blockPointer = blockPointers[(index - doublyIndirectStart) / blocksPerPointer]; |
| 186 | |
| 187 | if(int e = ReadBlockCached(blockPointer, buffer)){ |
| 188 | (void)e; |
| 189 | error = DiskReadError; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | return buffer[(index - doublyIndirectStart) % blocksPerPointer]; |
| 194 | } else { |
| 195 | assert(!"Yet to support triply indirect"); |
| 196 | return 0; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | Vector<uint32_t> Ext2Volume::GetInodeBlocks(uint32_t index, uint32_t count, ext2_inode_t& ino){ |
| 201 | uint32_t blocksPerPointer = blocksize / sizeof(uint32_t); // Amount of blocks in a indirect block table |
nothing calls this directly
no outgoing calls
no test coverage detected