From 5c50d02c2e6369e551eb67638c7e0b36366f1cca Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 15 Oct 2018 02:39:55 +0200 Subject: [PATCH] Fix bug where allocating a new inode forgot that inodes are 1-based. --- VirtualFileSystem/Ext2FileSystem.cpp | 6 +++--- VirtualFileSystem/small.fs | Bin 2048000 -> 2048000 bytes VirtualFileSystem/test.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index bd93233db6..91295037c6 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -390,7 +390,7 @@ bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, std::functio if (entry->inode != 0) { memcpy(namebuf, entry->name, entry->name_len); namebuf[entry->name_len] = 0; -#ifndef EXT2_DEBUG +#ifdef EXT2_DEBUG printf("inode: %u, name_len: %u, rec_len: %u, file_type: %u, name: %s\n", entry->inode, entry->name_len, entry->rec_len, entry->file_type, namebuf); #endif if (!callback({ namebuf, { id(), entry->inode }, entry->file_type })) @@ -598,7 +598,7 @@ void Ext2FileSystem::traverseInodeBitmap(unsigned groupIndex, F callback) const for (unsigned i = 0; i < blockCount; ++i) { auto block = readBlock(bgd.bg_inode_bitmap + i); ASSERT(block); - bool shouldContinue = callback(i * (blockSize() / 8), Bitmap::wrap(block.pointer(), inodesInGroup)); + bool shouldContinue = callback(i * (blockSize() / 8) + 1, Bitmap::wrap(block.pointer(), inodesInGroup)); if (!shouldContinue) break; } @@ -793,7 +793,7 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S e2inode->i_mtime = timestamp; e2inode->i_dtime = 0; e2inode->i_gid = 0; - e2inode->i_links_count = 2; + e2inode->i_links_count = 1; e2inode->i_blocks = 0; e2inode->i_flags = 0; success = writeExt2Inode(inode, *e2inode); diff --git a/VirtualFileSystem/small.fs b/VirtualFileSystem/small.fs index 340576dbaf8f7ca94bc6e92c35a78bb49a2c00db..0f980f396da3620890fcaf7badf277a7fcd42fd7 100644 GIT binary patch delta 206 zcmX|%s}ccW0EPeG{_MKn@3$cfn*>o*MPmevWJXYgo!JpiArZWR%ayv))vm2Fni0MX~`nxF)IpaCk-4+cOJw7?)30>fYgjDj&R f4ko}Pm;%#a2F!vvFb@{MB3J^;UU-x%d{@x zJtvmy?QZ{+3*|sif*DW&RWJ+YKn>JE1I&X3un3mGGFSmk&;o6+3f90n=ztBd3AVsC M*a5p>@4^203ycp)Q2+n{ diff --git a/VirtualFileSystem/test.cpp b/VirtualFileSystem/test.cpp index 1697afe6e3..4c704d991f 100644 --- a/VirtualFileSystem/test.cpp +++ b/VirtualFileSystem/test.cpp @@ -38,8 +38,10 @@ int main(int c, char** v) return 1; } - //auto newFile = vfs.create("/empty"); - //printf("vfs.create: %p\n", newFile.ptr()); +#if 1 + auto newFile = vfs.create("/empty"); + printf("vfs.create: %p\n", newFile.ptr()); +#endif //return 0; if (!strcmp(v[0], "./vcat")) {