From b36996509c59c3e7048316d5bef1e730b2aace12 Mon Sep 17 00:00:00 2001
From: hy che <cvghy116@gmail.com>
Date: Thu, 30 Mar 2017 08:53:16 +0000
Subject: [PATCH] stream is re-defined which misplaces size of item data.
---
.../kernel/file_systems/btrfs/BPlusTree.cpp | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp
index b4d2dd6..1e28a5b 100644
a
|
b
|
BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
|
116 | 116 | } |
117 | 117 | TRACE("Find() getting index %" B_PRIu32 " at %" B_PRId64 "\n", i - 1, |
118 | 118 | stream->index[i - 1].BlockNum()); |
119 | | |
| 119 | |
120 | 120 | if (fVolume->FindBlock(stream->index[i - 1].BlockNum(), physical) |
121 | 121 | != B_OK) { |
122 | 122 | ERROR("Find() unmapped block %" B_PRId64 "\n", |
… |
… |
BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
|
132 | 132 | for (i = 0; i < stream->header.ItemCount(); i++) { |
133 | 133 | int32 comp = _CompareKeys(key, stream->entries[i].key); |
134 | 134 | TRACE("Find() dump %" B_PRIu32 " %" B_PRIu32 " offset %" B_PRId64 |
135 | | " comp %" B_PRId32 "\n", stream->entries[i].Offset(), |
| 135 | " comp %" B_PRId32 "\n", stream->entries[i].Offset(), |
136 | 136 | stream->entries[i].Size(), stream->entries[i].key.Offset(), comp); |
137 | 137 | } |
138 | 138 | #endif |
139 | 139 | |
140 | 140 | for (i = 0; i < stream->header.ItemCount(); i++) { |
141 | 141 | int32 comp = _CompareKeys(key, stream->entries[i].key); |
142 | | TRACE("Find() found %" B_PRIu32 " %" B_PRIu32 " oid %" B_PRId64 |
| 142 | TRACE("Find() found %" B_PRIu32 " %" B_PRIu32 " oid %" B_PRId64 |
143 | 143 | " type %d offset %" B_PRId64 " comp %" B_PRId32 "\n", |
144 | 144 | stream->entries[i].Offset(), stream->entries[i].Size(), |
145 | 145 | stream->entries[i].key.ObjectID(), stream->entries[i].key.Type(), |
… |
… |
BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
|
162 | 162 | return B_ENTRY_NOT_FOUND; |
163 | 163 | } |
164 | 164 | |
165 | | if (i < stream->header.ItemCount() |
| 165 | if (i < stream->header.ItemCount() |
166 | 166 | && stream->entries[i].key.Type() == key.Type()) { |
167 | 167 | TRACE("Find() found %" B_PRIu32 " %" B_PRIu32 "\n", |
168 | 168 | stream->entries[i].Offset(), stream->entries[i].Size()); |
| 169 | |
169 | 170 | if (_value != NULL) { |
170 | 171 | *_value = malloc(stream->entries[i].Size()); |
171 | 172 | uint32 totalOffset = stream->entries[i].Offset() + sizeof(btrfs_header); |
172 | | key.SetOffset(stream->entries[i].key.Offset()); |
| 173 | |
173 | 174 | |
174 | 175 | if ((fVolume->BlockSize() - totalOffset % fVolume->BlockSize()) |
175 | 176 | >= stream->entries[i].Size()) { |
176 | 177 | //If there is enough space for *_value |
177 | | stream = (btrfs_stream*)cached.SetTo(physical |
178 | | + totalOffset / fVolume->BlockSize()); |
179 | | memcpy(*_value, ((uint8 *)&stream->header |
| 178 | memcpy(*_value, ((uint8 *)cached.SetTo(physical |
| 179 | + totalOffset / fVolume->BlockSize()) |
180 | 180 | + totalOffset % fVolume->BlockSize()), |
181 | 181 | stream->entries[i].Size()); |
182 | 182 | } else { |
… |
… |
BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
|
184 | 184 | * fVolume->BlockSize() + totalOffset, |
185 | 185 | *_value, stream->entries[i].Size()); |
186 | 186 | } |
| 187 | |
| 188 | key.SetOffset(stream->entries[i].key.Offset()); |
187 | 189 | if (_size != NULL) |
188 | 190 | *_size = stream->entries[i].Size(); |
189 | | } |
| 191 | } |
190 | 192 | return B_OK; |
191 | 193 | } |
192 | | |
| 194 | |
193 | 195 | |
194 | 196 | TRACE("Find() not found %" B_PRId64 " %" B_PRId64 "\n", key.Offset(), |
195 | 197 | key.ObjectID()); |