From 30294b6d051423db6d27e568111b93a010cc5210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 20 Apr 2022 17:13:37 +0200 Subject: [PATCH] ext2: use st_blocks from the disk inode structure * this lets cp from coreutils use lseek to find the data chunks in a sparse file. * fix endian conversion macro used for num_blocks_high Change-Id: I221d6316002b1c491ae987aeef3f25e8721b5ab9 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5218 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- src/add-ons/kernel/file_systems/ext2/Inode.cpp | 6 +++--- src/add-ons/kernel/file_systems/ext2/Inode.h | 2 +- src/add-ons/kernel/file_systems/ext2/ext2.h | 4 ++-- src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ext2/Inode.cpp b/src/add-ons/kernel/file_systems/ext2/Inode.cpp index fe00fd12aa..2c4777142d 100644 --- a/src/add-ons/kernel/file_systems/ext2/Inode.cpp +++ b/src/add-ons/kernel/file_systems/ext2/Inode.cpp @@ -857,7 +857,7 @@ Inode::_EnlargeDataStream(Transaction& transaction, off_t size) fNode.SetSize(size); TRACE("Inode::_EnlargeDataStream(): Setting allocated block count to %" B_PRIdOFF "\n", end); - return _SetNumBlocks(_NumBlocks() + end * (fVolume->BlockSize() / 512)); + return _SetNumBlocks(NumBlocks() + end * (fVolume->BlockSize() / 512)); } @@ -895,12 +895,12 @@ Inode::_ShrinkDataStream(Transaction& transaction, off_t size) } fNode.SetSize(size); - return _SetNumBlocks(_NumBlocks() - end * (fVolume->BlockSize() / 512)); + return _SetNumBlocks(NumBlocks() - end * (fVolume->BlockSize() / 512)); } uint64 -Inode::_NumBlocks() +Inode::NumBlocks() { if (fVolume->HugeFiles()) { if (fNode.Flags() & EXT2_INODE_HUGE_FILE) diff --git a/src/add-ons/kernel/file_systems/ext2/Inode.h b/src/add-ons/kernel/file_systems/ext2/Inode.h index c8dcbf257e..0a40efceea 100644 --- a/src/add-ons/kernel/file_systems/ext2/Inode.h +++ b/src/add-ons/kernel/file_systems/ext2/Inode.h @@ -59,6 +59,7 @@ public: int32 Flags() const { return fNode.Flags(); } off_t Size() const { return fNode.Size(); } + uint64 NumBlocks(); void GetChangeTime(struct timespec *timespec) const { fNode.GetChangeTime(timespec, fHasExtraAttributes); } void GetModificationTime(struct timespec *timespec) const @@ -142,7 +143,6 @@ private: status_t _ShrinkDataStream(Transaction& transaction, off_t size); - uint64 _NumBlocks(); status_t _SetNumBlocks(uint64 numBlocks); uint32 _InodeChecksum(ext2_inode* inode); diff --git a/src/add-ons/kernel/file_systems/ext2/ext2.h b/src/add-ons/kernel/file_systems/ext2/ext2.h index a13bb3bca5..3b4e4f0a06 100644 --- a/src/add-ons/kernel/file_systems/ext2/ext2.h +++ b/src/add-ons/kernel/file_systems/ext2/ext2.h @@ -490,7 +490,7 @@ struct ext2_inode { uint16 NumLinks() const { return B_LENDIAN_TO_HOST_INT16(num_links); } uint32 NumBlocks() const { return B_LENDIAN_TO_HOST_INT32(num_blocks); } uint64 NumBlocks64() const { return B_LENDIAN_TO_HOST_INT32(num_blocks) - | ((uint64)B_LENDIAN_TO_HOST_INT32(num_blocks_high) << 32); } + | ((uint64)B_LENDIAN_TO_HOST_INT16(num_blocks_high) << 32); } static void _DecodeTime(struct timespec *timespec, uint32 time, uint32 time_extra, bool extra) @@ -631,7 +631,7 @@ struct ext2_inode { void SetNumBlocks64(uint64 numBlocks) { num_blocks = B_HOST_TO_LENDIAN_INT32(numBlocks & 0xffffffff); - num_blocks_high = B_HOST_TO_LENDIAN_INT32(numBlocks >> 32); + num_blocks_high = B_HOST_TO_LENDIAN_INT16(numBlocks >> 32); } void SetNextOrphan(ino_t id) diff --git a/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp index 7b18382afa..7ebe231207 100644 --- a/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp @@ -587,7 +587,7 @@ ext2_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat* stat) inode->GetCreationTime(&stat->st_crtim); stat->st_size = inode->Size(); - stat->st_blocks = (inode->Size() + 511) / 512; + stat->st_blocks = inode->NumBlocks(); return B_OK; }