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 zcmZo@sBLJd-C)2Xl>X>&Gy{VYL-2b>21W)3hV)09omjkd*yA4^j*fqHc=Kd~ubj-W zj}C9{w))C4$&5vWfq{Xc_90j@8bqf&Ivl-Ok>kGnW&@53aN?!Fqz%*A7*lf#N-8%p zCNno}Y1_iswuPx}3v=5RmbNXdZClvdwy?Kt;b_~!*|vqNZ3}nX7M`{(ylq?f+P3hw zZ4qeOBG|S?sBMdI+ZK_wEuw8(#M-uqw{4MV+alSvMXGI!blVo0wk@*Dw#fAW0GUQr AeE21W)3hJaI>omjkd*u|zEiWZxCX!B%)ubj;J z9fvk|TYY8OY`}3r9)%DPoU~y&8$)VtK}qFC#$@KEEp1yE+qN*ZZDDTP!qT>dwQUPq z+ZOh=EgWrIINP>xwQb>U+rrbfg|}@BU)vV`wk-l}TLjy-2(@hyZrdW#wnemUi&)zh c@wP1zZCfPUwn(*Yk#5@})3!x+*%rAT0E`bvQ2+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")) {