Ticket #12788: 0001-Fix-ticket-12788.patch

File 0001-Fix-ticket-12788.patch, 1.8 KB (added by hyche, 7 years ago)

update code for newer version of btrfs

  • src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp

    From 82593b2a52c4b7cdcf9e2e06b25c67fc5ea14584 Mon Sep 17 00:00:00 2001
    From: Hy Che <cvghy116@gmail.com>
    Date: Tue, 14 Mar 2017 00:08:48 +0700
    Subject: [PATCH] Fix ticket 12788: Found item has data offset higher than
     block size. Move the stream to get the data. If the data is not fit the
     block, fetch it directly from the device
    
    ---
     src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp | 18 +++++++++++++++---
     1 file changed, 15 insertions(+), 3 deletions(-)
    
    diff --git a/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp
    index 0f1bf01..b4d2dd6 100644
    a b BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,  
    168168            stream->entries[i].Offset(), stream->entries[i].Size());
    169169        if (_value != NULL) {
    170170            *_value = malloc(stream->entries[i].Size());
    171             memcpy(*_value, ((uint8 *)&stream->entries[0]
    172                 + stream->entries[i].Offset()),
    173                 stream->entries[i].Size());
     171            uint32 totalOffset = stream->entries[i].Offset() + sizeof(btrfs_header);
    174172            key.SetOffset(stream->entries[i].key.Offset());
     173
     174            if ((fVolume->BlockSize() - totalOffset % fVolume->BlockSize())
     175                >= stream->entries[i].Size()) {
     176                //If there is enough space for *_value
     177                stream = (btrfs_stream*)cached.SetTo(physical
     178                    + totalOffset / fVolume->BlockSize());
     179                memcpy(*_value, ((uint8 *)&stream->header
     180                    + totalOffset % fVolume->BlockSize()),
     181                    stream->entries[i].Size());
     182            } else {
     183                read_pos(fVolume->Device(), physical
     184                    * fVolume->BlockSize() + totalOffset,
     185                    *_value, stream->entries[i].Size());
     186            }
    175187            if (_size != NULL)
    176188                *_size = stream->entries[i].Size();
    177189        }