BTRFS: Fix mismatched type of item size (should be uint32), and ObjectID of first subvolume when lookup directory (described in commit bd2dab1)

Signed-off-by: Augustin Cavalier <[email protected]>
This commit is contained in:
hyche
2017-12-10 10:56:09 -05:00
committed by Augustin Cavalier
parent 2ed88a489c
commit 16de9db54b
8 changed files with 32 additions and 31 deletions
@@ -88,7 +88,7 @@ Attribute::Stat(struct stat& stat)
size_t nameLength = strlen(fName);
btrfs_dir_entry* entries;
size_t length;
uint32 length;
status_t status = _Lookup(fName, nameLength, &entries, &length);
if (status < B_OK)
return status;
@@ -116,7 +116,7 @@ Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length)
size_t nameLength = strlen(fName);
btrfs_dir_entry* entries;
size_t length;
uint32 length;
status_t status = _Lookup(fName, nameLength, &entries, &length);
if (status < B_OK)
return status;
@@ -144,7 +144,7 @@ Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length)
status_t
Attribute::_Lookup(const char* name, size_t nameLength,
btrfs_dir_entry** _entries, size_t* _length)
btrfs_dir_entry** _entries, uint32* _length)
{
uint32 hash = calculate_crc((uint32)~1, (uint8*)name, nameLength);
struct btrfs_key key;
@@ -153,7 +153,7 @@ Attribute::_Lookup(const char* name, size_t nameLength,
key.SetOffset(hash);
btrfs_dir_entry* entries;
size_t length;
uint32 length;
status_t status = fInode->GetVolume()->FSTree()->FindExact(key,
(void**)&entries, &length);
if (status != B_OK) {
@@ -39,7 +39,7 @@ public:
private:
status_t _Lookup(const char* name, size_t nameLength,
btrfs_dir_entry** entries = NULL,
size_t* length = NULL);
uint32* length = NULL);
status_t _FindEntry(btrfs_dir_entry* entries,
size_t length, const char* name,
size_t nameLength,
@@ -48,7 +48,7 @@ AttributeIterator::GetNext(char* name, size_t* _nameLength)
{
btrfs_key key;
btrfs_dir_entry* entries;
size_t entries_length;
uint32 entries_length;
status_t status = fIterator->GetPreviousEntry(key, (void**)&entries,
&entries_length);
if (status != B_OK)
@@ -212,7 +212,7 @@ btrfs_key::Compare(const btrfs_key& key) const
It can also return other errors to indicate that something went wrong.
*/
status_t
BTree::_Find(btrfs_key& key, void** _value, size_t* _size,
BTree::_Find(btrfs_key& key, void** _value, uint32* _size,
bool read, btree_traversing type)
{
TRACE("Find() objectid %" B_PRId64 " type %d offset %" B_PRId64 " \n",
@@ -268,21 +268,21 @@ BTree::_Find(btrfs_key& key, void** _value, size_t* _size,
status_t
BTree::FindNext(btrfs_key& key, void** _value, size_t* _size, bool read)
BTree::FindNext(btrfs_key& key, void** _value, uint32* _size, bool read)
{
return _Find(key, _value, _size, read, BTREE_FORWARD);
}
status_t
BTree::FindPrevious(btrfs_key& key, void** _value, size_t* _size, bool read)
BTree::FindPrevious(btrfs_key& key, void** _value, uint32* _size, bool read)
{
return _Find(key, _value, _size, read, BTREE_BACKWARD);
}
status_t
BTree::FindExact(btrfs_key& key, void** _value, size_t* _size, bool read)
BTree::FindExact(btrfs_key& key, void** _value, uint32* _size, bool read)
{
return _Find(key, _value, _size, read, BTREE_EXACT);
}
@@ -345,7 +345,7 @@ TreeIterator::~TreeIterator()
*/
status_t
TreeIterator::Traverse(btree_traversing direction, btrfs_key& key,
void** value, size_t* size)
void** value, uint32* size)
{
if (fTree == NULL)
return B_INTERRUPTED;
+12 -12
View File
@@ -3,8 +3,8 @@
* Copyright 2001-2010, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License.
*/
#ifndef B_PLUS_TREE_H
#define B_PLUS_TREE_H
#ifndef B_TREE_H
#define B_TREE_H
#include "btrfs.h"
@@ -50,11 +50,11 @@ public:
fsblock_t rootBlock);
~BTree();
status_t FindExact(btrfs_key& key, void** value,
size_t* size = NULL, bool read = true);
uint32* size = NULL, bool read = true);
status_t FindNext(btrfs_key& key, void** value,
size_t* size = NULL, bool read = true);
uint32* size = NULL, bool read = true);
status_t FindPrevious(btrfs_key& key, void** value,
size_t* size = NULL, bool read = true);
uint32* size = NULL, bool read = true);
Volume* SystemVolume() const { return fVolume; }
@@ -67,7 +67,7 @@ private:
BTree& operator=(const BTree& other);
// no implementation
status_t _Find(btrfs_key& key, void** value, size_t* size,
status_t _Find(btrfs_key& key, void** value, uint32* size,
bool read, btree_traversing type);
void _AddIterator(TreeIterator* iterator);
void _RemoveIterator(TreeIterator* iterator);
@@ -153,14 +153,14 @@ public:
status_t Traverse(btree_traversing direction,
btrfs_key& key, void** value,
size_t* size = NULL);
uint32* size = NULL);
status_t Find(btrfs_key& key);
status_t Rewind();
status_t GetNextEntry(btrfs_key& key, void** value,
size_t* size = NULL);
uint32* size = NULL);
status_t GetPreviousEntry(btrfs_key& key, void** value,
size_t* size = NULL);
uint32* size = NULL);
BTree* Tree() const { return fTree; }
@@ -188,7 +188,7 @@ TreeIterator::Rewind()
inline status_t
TreeIterator::GetNextEntry(btrfs_key& key, void** value, size_t* size)
TreeIterator::GetNextEntry(btrfs_key& key, void** value, uint32* size)
{
return Traverse(BTREE_FORWARD, key, value, size);
}
@@ -196,10 +196,10 @@ TreeIterator::GetNextEntry(btrfs_key& key, void** value, size_t* size)
inline status_t
TreeIterator::GetPreviousEntry(btrfs_key& key, void** value,
size_t* size)
uint32* size)
{
return Traverse(BTREE_BACKWARD, key, value, size);
}
#endif // B_PLUS_TREE_H
#endif // B_TREE_H
@@ -33,7 +33,8 @@ DirectoryIterator::DirectoryIterator(Inode* inode)
DirectoryIterator::~DirectoryIterator()
{
delete fIterator;
if (fIterator != NULL)
delete fIterator;
}
@@ -61,7 +62,7 @@ DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id)
*_nameLength = 1;
strlcpy(name, ".", *_nameLength + 1);
fOffset = 2;
if (fInode->ID() == BTRFS_OBJECT_ID_CHUNK_TREE) {
if (fInode->ID() == BTRFS_FIRST_SUBVOLUME) {
*_id = fInode->ID();
return B_OK;
}
@@ -70,7 +71,7 @@ DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id)
btrfs_key key;
btrfs_dir_entry* entries;
size_t entries_length;
uint32 entries_length;
status_t status = fIterator->GetNextEntry(key, (void**)&entries,
&entries_length);
if (status != B_OK)
@@ -110,7 +111,7 @@ DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id)
{
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
if (strcmp(name, ".") == 0
|| fInode->ID() == BTRFS_OBJECT_ID_CHUNK_TREE) {
|| fInode->ID() == BTRFS_FIRST_SUBVOLUME) {
*_id = fInode->ID();
return B_OK;
}
@@ -124,7 +125,7 @@ DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id)
key.SetOffset(hash);
btrfs_dir_entry* entries;
size_t length;
uint32 length;
status_t status = fInode->GetVolume()->FSTree()->FindExact(key,
(void**)&entries, &length);
if (status != B_OK) {
@@ -167,7 +167,7 @@ Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
search_key.SetObjectID(fID);
search_key.SetOffset(pos + 1);
size_t item_size;
uint32 item_size;
btrfs_extent_data* extent_data;
status_t status = fVolume->FSTree()->FindPrevious(search_key,
(void**)&extent_data, &item_size);
@@ -222,7 +222,7 @@ Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)
int status;
ssize_t offset = 0;
size_t inline_size = item_size - 13;
uint32 inline_size = item_size - 13;
bool headerRead = false;
TRACE("Inode::ReadAt(%" B_PRIdINO ") diff %" B_PRIdOFF " size %"
@@ -486,7 +486,7 @@ Volume::FindBlock(off_t logical, off_t& physical)
search_key.SetType(BTRFS_KEY_TYPE_CHUNK_ITEM);
search_key.SetObjectID(BTRFS_OBJECT_ID_FIRST_CHUNK_TREE);
btrfs_chunk* chunk;
size_t chunk_length;
uint32 chunk_length;
status_t status = fChunkTree->FindPrevious(search_key, (void**)&chunk,
&chunk_length);
if (status != B_OK)