Ticket #13513: 0001-Code-refactoring.patch
File 0001-Code-refactoring.patch, 66.4 KB (added by , 7 years ago) |
---|
-
src/add-ons/kernel/file_systems/btrfs/Attribute.cpp
From 7203f00d12fe31b54d407d3738781e9148fdbdff Mon Sep 17 00:00:00 2001 From: hyche <cvghy116@gmail.com> Date: Thu, 18 May 2017 19:52:06 +0700 Subject: [PATCH] Code refactoring: * Fixed style violation * System header files should be the first to be included * Insert fs_shell headers if compiled with FS_SHELL --- .../kernel/file_systems/btrfs/Attribute.cpp | 25 ++-- src/add-ons/kernel/file_systems/btrfs/Attribute.h | 54 +++++---- .../file_systems/btrfs/AttributeIterator.cpp | 11 +- .../kernel/file_systems/btrfs/AttributeIterator.h | 26 ++-- .../kernel/file_systems/btrfs/BPlusTree.cpp | 32 ++--- src/add-ons/kernel/file_systems/btrfs/BPlusTree.h | 117 +++++++++--------- src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp | 72 +++++------ src/add-ons/kernel/file_systems/btrfs/CRCTable.h | 3 +- .../kernel/file_systems/btrfs/CachedBlock.h | 39 +++--- src/add-ons/kernel/file_systems/btrfs/Chunk.cpp | 9 +- src/add-ons/kernel/file_systems/btrfs/Chunk.h | 31 +++-- .../file_systems/btrfs/DirectoryIterator.cpp | 16 +-- .../kernel/file_systems/btrfs/DirectoryIterator.h | 24 ++-- src/add-ons/kernel/file_systems/btrfs/Inode.cpp | 18 ++- src/add-ons/kernel/file_systems/btrfs/Inode.h | 133 ++++++++++----------- src/add-ons/kernel/file_systems/btrfs/Utility.h | 17 +-- src/add-ons/kernel/file_systems/btrfs/Volume.cpp | 91 ++++++-------- src/add-ons/kernel/file_systems/btrfs/Volume.h | 104 +++++++++------- src/add-ons/kernel/file_systems/btrfs/btrfs.h | 98 ++++++++------- .../kernel/file_systems/btrfs/crc_table.cpp | 73 +++++------ .../kernel/file_systems/btrfs/kernel_interface.cpp | 56 +++++---- 21 files changed, 540 insertions(+), 509 deletions(-) diff --git a/src/add-ons/kernel/file_systems/btrfs/Attribute.cpp b/src/add-ons/kernel/file_systems/btrfs/Attribute.cpp index d6be6d3..4bc78f4 100644
a b 8 8 //! connection between pure inode and kernel_interface attributes 9 9 10 10 11 #include "Attribute.h"12 13 11 #include <new> 14 #include <stdio.h>15 #include <stdlib.h>16 12 13 #include "Attribute.h" 17 14 #include "BPlusTree.h" 18 15 #include "CRCTable.h" 19 16 #include "Utility.h" … … Attribute::Stat(struct stat& stat) 92 89 TRACE("Stat\n"); 93 90 94 91 size_t nameLength = strlen(fName); 95 btrfs_dir_entry *entries;92 btrfs_dir_entry* entries; 96 93 size_t length; 97 94 status_t status = _Lookup(fName, nameLength, &entries, &length); 98 95 if (status < B_OK) 99 96 return status; 100 97 101 btrfs_dir_entry *entry;98 btrfs_dir_entry* entry; 102 99 status = _FindEntry(entries, length, fName, nameLength, &entry); 103 100 if (status != B_OK) { 104 101 free(entries); … … Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length) 120 117 return ERANGE; 121 118 122 119 size_t nameLength = strlen(fName); 123 btrfs_dir_entry *entries;120 btrfs_dir_entry* entries; 124 121 size_t length; 125 122 status_t status = _Lookup(fName, nameLength, &entries, &length); 126 123 if (status < B_OK) 127 124 return status; 128 125 129 btrfs_dir_entry *entry;126 btrfs_dir_entry* entry; 130 127 status = _FindEntry(entries, length, fName, nameLength, &entry); 131 128 if (status != B_OK) { 132 129 free(entries); … … Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length) 149 146 150 147 status_t 151 148 Attribute::_Lookup(const char* name, size_t nameLength, 152 btrfs_dir_entry **_entries, size_t *_length)149 btrfs_dir_entry** _entries, size_t* _length) 153 150 { 154 151 uint32 hash = calculate_crc((uint32)~1, (uint8*)name, nameLength); 155 152 struct btrfs_key key; … … Attribute::_Lookup(const char* name, size_t nameLength, 157 154 key.SetObjectID(fInode->ID()); 158 155 key.SetOffset(hash); 159 156 160 btrfs_dir_entry *entries;157 btrfs_dir_entry* entries; 161 158 size_t length; 162 159 status_t status = fInode->GetVolume()->FSTree()->FindExact(key, 163 160 (void**)&entries, &length); … … Attribute::_Lookup(const char* name, size_t nameLength, 180 177 181 178 182 179 status_t 183 Attribute::_FindEntry(btrfs_dir_entry *entries, size_t length,184 const char* name, size_t nameLength, btrfs_dir_entry **_entry)180 Attribute::_FindEntry(btrfs_dir_entry* entries, size_t length, 181 const char* name, size_t nameLength, btrfs_dir_entry** _entry) 185 182 { 186 btrfs_dir_entry *entry = entries;183 btrfs_dir_entry* entry = entries; 187 184 uint16 current = 0; 188 185 while (current < length) { 189 186 current += entry->Length(); 190 187 break; 191 188 // TODO there could be several entries with the same name hash 192 entry = (btrfs_dir_entry 189 entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length()); 193 190 } 194 191 195 192 *_entry = entry; -
src/add-ons/kernel/file_systems/btrfs/Attribute.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/Attribute.h b/src/add-ons/kernel/file_systems/btrfs/Attribute.h index 892b71e..ad9acfe9 100644
a b 7 7 #define ATTRIBUTE_H 8 8 9 9 10 #ifndef FS_SHELL 11 # include <stdio.h> 12 # include <stdlib.h> 13 #else 14 # include "fssh_api_wrapper.h" 15 #endif 16 10 17 #include "CachedBlock.h" 11 18 #include "Inode.h" 12 19 … … struct attr_cookie { 21 28 22 29 class Attribute { 23 30 public: 24 Attribute(Inode* inode); 25 Attribute(Inode* inode, attr_cookie* cookie); 26 ~Attribute(); 27 28 status_t CheckAccess(const char* name, int openMode); 29 30 status_t Create(const char* name, type_code type, 31 int openMode, attr_cookie** _cookie); 32 status_t Open(const char* name, int openMode, 33 attr_cookie** _cookie); 34 35 status_t Stat(struct stat& stat); 31 Attribute(Inode* inode); 32 Attribute(Inode* inode, attr_cookie* cookie); 33 ~Attribute(); 34 35 status_t CheckAccess(const char* name, int openMode); 36 status_t Create(const char* name, type_code type, 37 int openMode, attr_cookie** _cookie); 38 status_t Open(const char* name, int openMode, 39 attr_cookie** _cookie); 40 status_t Stat(struct stat& stat); 41 status_t Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length); 36 42 37 status_t Read(attr_cookie* cookie, off_t pos,38 uint8* buffer, size_t* _length);39 43 private: 40 status_t_Lookup(const char* name, size_t nameLength,41 btrfs_dir_entry **entries = NULL,42 size_t *length = NULL);43 status_t _FindEntry(btrfs_dir_entry *entries,44 45 46 btrfs_dir_entry **_entry);47 48 ::Volume*fVolume;49 Inode*fInode;50 const char*fName;44 status_t _Lookup(const char* name, size_t nameLength, 45 btrfs_dir_entry** entries = NULL, 46 size_t* length = NULL); 47 status_t _FindEntry(btrfs_dir_entry* entries, 48 size_t length, const char* name, 49 size_t nameLength, 50 btrfs_dir_entry** _entry); 51 52 ::Volume* fVolume; 53 Inode* fInode; 54 const char* fName; 51 55 }; 52 56 53 57 #endif // ATTRIBUTE_H -
src/add-ons/kernel/file_systems/btrfs/AttributeIterator.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/AttributeIterator.cpp b/src/add-ons/kernel/file_systems/btrfs/AttributeIterator.cpp index b668ca5..c90907d 100644
a b 4 4 */ 5 5 6 6 7 #include "AttributeIterator.h"8 9 7 #include <new> 10 #include <stdlib.h> 11 8 #include "AttributeIterator.h" 12 9 13 10 //#define TRACE_BTRFS 14 11 #ifdef TRACE_BTRFS … … status_t 50 47 AttributeIterator::GetNext(char* name, size_t* _nameLength) 51 48 { 52 49 btrfs_key key; 53 btrfs_dir_entry *entries;50 btrfs_dir_entry* entries; 54 51 size_t entries_length; 55 52 status_t status = fIterator->GetPreviousEntry(key, (void**)&entries, 56 53 &entries_length); 57 54 if (status != B_OK) 58 55 return status; 59 56 60 btrfs_dir_entry *entry = entries;57 btrfs_dir_entry* entry = entries; 61 58 uint16 current = 0; 62 59 while (current < entries_length) { 63 60 current += entry->Length(); 64 61 break; 65 62 // TODO there could be several entries with the same name hash 66 entry = (btrfs_dir_entry 63 entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length()); 67 64 } 68 65 69 66 TRACE("DirectoryIterator::GetNext() entries_length %ld name_length %d\n", -
src/add-ons/kernel/file_systems/btrfs/AttributeIterator.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/AttributeIterator.h b/src/add-ons/kernel/file_systems/btrfs/AttributeIterator.h index d1f60c5..ffd7a9a 100644
a b 2 2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de. 3 3 * This file may be used under the terms of the MIT License. 4 4 */ 5 5 6 #ifndef ATTRIBUTEITERATOR_H 6 7 #define ATTRIBUTEITERATOR_H 7 8 8 9 10 #ifndef FS_SHELL 11 # include <stdlib.h> 12 #else 13 # include "fssh_api_wrapper.h" 14 #endif 15 9 16 #include "BPlusTree.h" 10 17 #include "Inode.h" 11 18 12 13 19 class AttributeIterator { 14 20 public: 15 AttributeIterator(Inode* inode); 16 ~AttributeIterator(); 21 AttributeIterator(Inode* inode); 22 ~AttributeIterator(); 23 24 status_t InitCheck(); 25 status_t GetNext(char* name, size_t* _nameLength); 26 status_t Rewind(); 17 27 18 status_t InitCheck();19 28 20 status_t GetNext(char* name, size_t* _nameLength);21 status_t Rewind();22 29 private: 23 uint64fOffset;24 Inode*fInode;25 TreeIterator*fIterator;30 uint64 fOffset; 31 Inode* fInode; 32 TreeIterator* fIterator; 26 33 }; 27 34 28 29 35 #endif // ATTRIBUTEITERATOR_H -
src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp index 1e28a5b..1a99fac 100644
a b 9 9 10 10 11 11 #include "BPlusTree.h" 12 13 12 #include "CachedBlock.h" 14 13 15 #include <stdlib.h>16 #include <string.h>17 #include <util/AutoLock.h>18 19 20 14 //#define TRACE_BTRFS 21 15 #ifdef TRACE_BTRFS 22 16 # define TRACE(x...) dprintf("\33[34mbtrfs:\33[0m " x) … … 26 20 # define ERROR(x...) dprintf("\33[34mbtrfs:\33[0m " x) 27 21 28 22 29 BPlusTree::BPlusTree(Volume* volume, struct btrfs_stream *stream)23 BPlusTree::BPlusTree(Volume* volume, struct btrfs_stream* stream) 30 24 : 31 25 fStream(stream), 32 26 fRootBlock(0), … … BPlusTree::~BPlusTree() 62 56 63 57 64 58 int32 65 BPlusTree::_CompareKeys(struct btrfs_key &key1, struct btrfs_key &key2)59 BPlusTree::_CompareKeys(struct btrfs_key& key1, struct btrfs_key& key2) 66 60 { 67 61 if (key1.ObjectID() > key2.ObjectID()) 68 62 return 1; … … BPlusTree::_CompareKeys(struct btrfs_key &key1, struct btrfs_key &key2) 86 80 It can also return other errors to indicate that something went wrong. 87 81 */ 88 82 status_t 89 BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,83 BPlusTree::_Find(struct btrfs_key& key, void** _value, size_t* _size, 90 84 bplustree_traversing type) 91 85 { 92 86 TRACE("Find() objectid %" B_PRId64 " type %d offset %" B_PRId64 " \n", 93 87 key.ObjectID(), key.Type(), key.Offset()); 94 btrfs_stream *stream = fStream;88 btrfs_stream* stream = fStream; 95 89 CachedBlock cached(fVolume); 96 90 fsblock_t physical; 97 91 if (stream == NULL) { … … BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size, 99 93 ERROR("Find() unmapped block %" B_PRId64 "\n", fRootBlock); 100 94 return B_ERROR; 101 95 } 102 stream = (btrfs_stream 96 stream = (btrfs_stream*)cached.SetTo(physical); 103 97 } 104 98 105 99 while (stream->header.Level() != 0) { … … BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size, 123 117 stream->index[i - 1].BlockNum()); 124 118 return B_ERROR; 125 119 } 126 stream = (btrfs_stream 120 stream = (btrfs_stream*)cached.SetTo(physical); 127 121 } 128 122 129 123 uint32 i; … … BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size, 175 169 if ((fVolume->BlockSize() - totalOffset % fVolume->BlockSize()) 176 170 >= stream->entries[i].Size()) { 177 171 //If there is enough space for *_value 178 memcpy(*_value, ((uint8 172 memcpy(*_value, ((uint8*)cached.SetTo(physical 179 173 + totalOffset / fVolume->BlockSize()) 180 174 + totalOffset % fVolume->BlockSize()), 181 175 stream->entries[i].Size()); … … BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size, 201 195 202 196 203 197 status_t 204 BPlusTree::FindNext(struct btrfs_key &key, void** _value, size_t* _size)198 BPlusTree::FindNext(struct btrfs_key& key, void** _value, size_t* _size) 205 199 { 206 200 return _Find(key, _value, _size, BPLUSTREE_FORWARD); 207 201 } 208 202 209 203 210 204 status_t 211 BPlusTree::FindPrevious(struct btrfs_key &key, void** _value, size_t* _size)205 BPlusTree::FindPrevious(struct btrfs_key& key, void** _value, size_t* _size) 212 206 { 213 207 return _Find(key, _value, _size, BPLUSTREE_BACKWARD); 214 208 } 215 209 216 210 217 211 status_t 218 BPlusTree::FindExact(struct btrfs_key &key, void** _value, size_t* _size)212 BPlusTree::FindExact(struct btrfs_key& key, void** _value, size_t* _size) 219 213 { 220 214 return _Find(key, _value, _size, BPLUSTREE_EXACT); 221 215 } … … BPlusTree::_RemoveIterator(TreeIterator* iterator) 240 234 // #pragma mark - 241 235 242 236 243 TreeIterator::TreeIterator(BPlusTree* tree, struct btrfs_key &key)237 TreeIterator::TreeIterator(BPlusTree* tree, struct btrfs_key& key) 244 238 : 245 239 fTree(tree), 246 240 fCurrentKey(key) … … TreeIterator::~TreeIterator() 260 254 /*! Iterates through the tree in the specified direction. 261 255 */ 262 256 status_t 263 TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key &key,257 TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key& key, 264 258 void** value, size_t* size) 265 259 { 266 260 if (fTree == NULL) … … TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key &key, 281 275 /*! just sets the current key in the iterator. 282 276 */ 283 277 status_t 284 TreeIterator::Find(struct btrfs_key &key)278 TreeIterator::Find(struct btrfs_key& key) 285 279 { 286 280 if (fTree == NULL) 287 281 return B_INTERRUPTED; -
src/add-ons/kernel/file_systems/btrfs/BPlusTree.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/BPlusTree.h b/src/add-ons/kernel/file_systems/btrfs/BPlusTree.h index fb051a0..0767492 100644
a b 7 7 #define B_PLUS_TREE_H 8 8 9 9 10 #include "btrfs.h" 11 12 #include <util/SinglyLinkedList.h> 10 #ifndef FS_SHELL 11 # include <stdlib.h> 12 # include <string.h> 13 # include <util/AutoLock.h> 14 # include <util/SinglyLinkedList.h> 15 #else 16 # include "fssh_api_wrapper.h" 17 #endif 13 18 19 #include "btrfs.h" 14 20 #include "Volume.h" 15 21 16 22 17 #define BPLUSTREE_NULL 18 #define BPLUSTREE_FREE 23 #define BPLUSTREE_NULL -1LL 24 #define BPLUSTREE_FREE -2LL 19 25 20 26 21 27 enum bplustree_traversing { … … struct node_and_key { 43 49 44 50 class BPlusTree { 45 51 public: 46 BPlusTree(Volume* volume, 47 struct btrfs_stream *stream); 48 BPlusTree(Volume* volume, 49 fsblock_t rootBlock); 50 ~BPlusTree(); 51 status_t FindExact(struct btrfs_key &key, void** value, 52 size_t* size = NULL); 53 status_t FindNext(struct btrfs_key &key, void** value, 54 size_t* size = NULL); 55 status_t FindPrevious(struct btrfs_key &key, void** value, 56 size_t* size = NULL); 52 BPlusTree(Volume* volume, struct btrfs_stream* stream); 53 BPlusTree(Volume* volume, fsblock_t rootBlock); 54 ~BPlusTree(); 55 56 status_t FindExact(struct btrfs_key& key, void** value, 57 size_t* size = NULL); 58 status_t FindNext(struct btrfs_key& key, void** value, 59 size_t* size = NULL); 60 status_t FindPrevious(struct btrfs_key& key, void** value, 61 size_t* size = NULL); 57 62 58 63 private: 59 BPlusTree(const BPlusTree& other); 60 BPlusTree& operator=(const BPlusTree& other); 61 // no implementation 62 63 int32 _CompareKeys(struct btrfs_key &key1, 64 struct btrfs_key &key2); 65 status_t _Find(struct btrfs_key &key, void** value, 66 size_t* size, bplustree_traversing type); 67 void _AddIterator(TreeIterator* iterator); 68 void _RemoveIterator(TreeIterator* iterator); 64 BPlusTree(const BPlusTree& other); 65 BPlusTree& operator=(const BPlusTree& other); 66 // no implementation 67 68 int32 _CompareKeys(struct btrfs_key& key1, 69 struct btrfs_key& key2); 70 status_t _Find(struct btrfs_key& key, void** value, 71 size_t* size, bplustree_traversing type); 72 void _AddIterator(TreeIterator* iterator); 73 void _RemoveIterator(TreeIterator* iterator); 74 75 69 76 private: 70 77 friend class TreeIterator; 71 78 72 73 fsblock_tfRootBlock;74 Volume*fVolume;75 mutexfIteratorLock;76 79 struct btrfs_stream* fStream; 80 fsblock_t fRootBlock; 81 Volume* fVolume; 82 mutex fIteratorLock; 83 SinglyLinkedList<TreeIterator> fIterators; 77 84 }; 78 85 79 86 80 87 class TreeIterator : public SinglyLinkedListLinkImpl<TreeIterator> { 81 88 public: 82 TreeIterator(BPlusTree* tree, struct btrfs_key &key); 83 ~TreeIterator(); 84 85 status_t Traverse(bplustree_traversing direction, 86 struct btrfs_key &key, void** value, 87 size_t *size = NULL); 88 status_t Find(struct btrfs_key &key); 89 90 status_t Rewind(); 91 status_t GetNextEntry(struct btrfs_key &key, void** value, 92 size_t *size = NULL); 93 status_t GetPreviousEntry(struct btrfs_key &key, void** value, 94 size_t *size = NULL); 95 96 BPlusTree* Tree() const { return fTree; } 89 TreeIterator(BPlusTree* tree, struct btrfs_key& key); 90 ~TreeIterator(); 91 92 status_t Traverse(bplustree_traversing direction, 93 struct btrfs_key& key, void** value, 94 size_t* size = NULL); 95 status_t Find(struct btrfs_key& key); 96 status_t Rewind(); 97 status_t GetNextEntry(struct btrfs_key& key, void** value, 98 size_t* size = NULL); 99 status_t GetPreviousEntry(struct btrfs_key& key, void** value, 100 size_t* size = NULL); 101 BPlusTree* Tree() const { return fTree; } 97 102 98 103 private: 99 104 friend class BPlusTree; 100 105 101 102 voidStop();106 // called by BPlusTree 107 void Stop(); 103 108 104 109 private: 105 BPlusTree*fTree;106 110 BPlusTree* fTree; 111 struct btrfs_key fCurrentKey; 107 112 }; 108 113 109 114 … … TreeIterator::Rewind() 117 122 return B_OK; 118 123 } 119 124 125 120 126 inline status_t 121 TreeIterator::GetNextEntry(struct btrfs_key &key, void** value, size_t *size)127 TreeIterator::GetNextEntry(struct btrfs_key& key, void** value, size_t* size) 122 128 { 123 129 return Traverse(BPLUSTREE_FORWARD, key, value, size); 124 130 } 125 131 132 126 133 inline status_t 127 TreeIterator::GetPreviousEntry(struct btrfs_key &key, void** value, 128 size_t *size) 134 TreeIterator::GetPreviousEntry(struct btrfs_key& key, void** value, size_t* size) 129 135 { 130 136 return Traverse(BPLUSTREE_BACKWARD, key, value, size); 131 137 } 132 138 133 139 134 135 140 #endif // B_PLUS_TREE_H -
src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp b/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp index 75f35e5..e53afaf 100644
a b 7 7 */ 8 8 9 9 10 #include <SupportDefs.h> 10 #ifndef FS_SHELL 11 # include <SupportDefs.h> 12 #else 13 # include "fssh_api_wrapper.h" 14 #endif 11 15 12 16 13 17 //! CRC 03667067501 table, as generated by crc_table.cpp 14 18 static uint32 kCrcTable[256] = { 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 19 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, 20 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, 21 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384, 22 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b, 23 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35, 24 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa, 25 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a, 26 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595, 27 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957, 28 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198, 29 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38, 30 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7, 31 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789, 32 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46, 33 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6, 34 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829, 35 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93, 36 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c, 37 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc, 38 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033, 39 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d, 40 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982, 41 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622, 42 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed, 43 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f, 44 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0, 45 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540, 46 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f, 47 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1, 48 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e, 49 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e, 50 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351 47 51 }; 48 52 49 53 … … static uint32 kCrcTable[256] = { 58 62 \return The crc checksum, or 0 if an error occurred. 59 63 */ 60 64 uint32 61 calculate_crc(uint32 crc, uint8 *data, uint16 length)65 calculate_crc(uint32 crc, uint8* data, uint16 length) 62 66 { 63 67 if (data) { 64 68 for ( ; length > 0; length--, data++) -
src/add-ons/kernel/file_systems/btrfs/CRCTable.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/CRCTable.h b/src/add-ons/kernel/file_systems/btrfs/CRCTable.h index 965251a..b6c1192 100644
a b 6 6 * Jérôme Duval 7 7 */ 8 8 9 uint32 calculate_crc(uint32 crc, uint8 *data, uint16 length); 10 9 uint32 calculate_crc(uint32 crc, uint8* data, uint16 length); -
src/add-ons/kernel/file_systems/btrfs/CachedBlock.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/CachedBlock.h b/src/add-ons/kernel/file_systems/btrfs/CachedBlock.h index 09fec08..b4910b3 100644
a b 7 7 8 8 //! interface for the block cache 9 9 10 #include <fs_cache.h> 10 11 #ifndef FS_SHELL 12 # include <fs_cache.h> 13 #else 14 # include "fssh_api_wrapper.h" 15 #endif 11 16 12 17 #include "Volume.h" 13 18 14 19 15 20 class CachedBlock { 16 21 public: 17 18 19 22 CachedBlock(Volume* volume); 23 CachedBlock(Volume* volume, off_t block); 24 ~CachedBlock(); 20 25 21 voidKeep();22 voidUnset();26 void Keep(); 27 void Unset(); 23 28 24 29 const uint8* SetTo(off_t block); 25 30 26 27 off_tBlockNumber() const { return fBlockNumber; }31 const uint8* Block() const { return fBlock; } 32 off_t BlockNumber() const { return fBlockNumber; } 28 33 29 34 private: 30 CachedBlock(const CachedBlock&);31 CachedBlock &operator=(const CachedBlock&);32 33 35 CachedBlock(const CachedBlock&); 36 CachedBlock& operator=(const CachedBlock&); 37 // no implementation 38 34 39 protected: 35 Volume*fVolume;36 off_tfBlockNumber;37 uint8*fBlock;40 Volume* fVolume; 41 off_t fBlockNumber; 42 uint8* fBlock; 38 43 }; 39 44 40 45 … … CachedBlock::SetTo(off_t block) 91 96 { 92 97 Unset(); 93 98 fBlockNumber = block; 94 return fBlock = (uint8 99 return fBlock = (uint8*)block_cache_get(fVolume->BlockCache(), block); 95 100 } 96 101 97 102 #endif // CACHED_BLOCK_H -
src/add-ons/kernel/file_systems/btrfs/Chunk.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/Chunk.cpp b/src/add-ons/kernel/file_systems/btrfs/Chunk.cpp index ee08cbd..43e8180 100644
a b 3 3 * This file may be used under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 * 6 * Jérôme Duval 7 7 */ 8 8 9 9 10 10 #include "Chunk.h" 11 11 12 #include <stdlib.h>13 #include <string.h>14 15 12 16 13 //#define TRACE_BTRFS 17 14 #ifdef TRACE_BTRFS … … Chunk::Chunk(struct btrfs_chunk* chunk, fsblock_t offset) 43 40 "sector_size %" B_PRIu32 "\n", chunk->Length(), chunk->Owner(), 44 41 chunk->StripeLength(), chunk->Type(), chunk->StripeCount(), 45 42 chunk->SubStripes(), chunk->SectorSize()); 46 for (int32 i = 0; i < chunk->StripeCount(); i++) {43 for (int32 i = 0; i < chunk->StripeCount(); i++) { 47 44 TRACE("chunk.stripe[%" B_PRId32 "].physical %" B_PRId64 " deviceid %" 48 45 B_PRId64 "\n", i, chunk->stripes[i].Offset(), 49 46 chunk->stripes[i].DeviceID()); … … Chunk::Size() const 66 63 67 64 68 65 status_t 69 Chunk::FindBlock(off_t logical, off_t &physical)66 Chunk::FindBlock(off_t logical, off_t& physical) 70 67 { 71 68 if (fChunk == NULL) 72 69 return B_NO_INIT; -
src/add-ons/kernel/file_systems/btrfs/Chunk.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/Chunk.h b/src/add-ons/kernel/file_systems/btrfs/Chunk.h index b751e72..0665658 100644
a b 5 5 * Authors: 6 6 * Jérôme Duval 7 7 */ 8 8 9 #ifndef CHUNK_H 9 10 #define CHUNK_H 10 11 11 12 13 #ifndef FS_SHELL 14 # include <stdlib.h> 15 # include <string.h> 16 #else 17 # include "fssh_api_wrapper.h" 18 #endif 19 12 20 #include "btrfs.h" 13 21 14 22 15 23 class Chunk { 16 24 public: 17 18 19 20 uint32Size() const;21 status_t FindBlock(off_t logical, off_t &physical);22 fsblock_tOffset() const { return fChunkOffset; }23 fsblock_tEnd() const24 25 Chunk(struct btrfs_chunk* chunk, 26 fsblock_t offset); 27 ~Chunk(); 28 uint32 Size() const; 29 status_t FindBlock(off_t logical, off_t& physical); 30 fsblock_t Offset() const { return fChunkOffset; } 31 fsblock_t End() const 32 { return fChunkOffset + fChunk->Length(); } 25 33 private: 26 27 fsblock_tfChunkOffset;28 status_tfInitStatus;34 struct btrfs_chunk* fChunk; 35 fsblock_t fChunkOffset; 36 status_t fInitStatus; 29 37 }; 30 38 39 31 40 #endif // CHUNK_H -
src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.cpp b/src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.cpp index 01eb988..ded0351 100644
a b 5 5 6 6 7 7 #include "DirectoryIterator.h" 8 9 #include <new>10 #include <stdlib.h>11 12 8 #include "CRCTable.h" 13 9 14 10 … … DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id) 73 69 } 74 70 75 71 btrfs_key key; 76 btrfs_dir_entry *entries;72 btrfs_dir_entry* entries; 77 73 size_t entries_length; 78 74 status_t status = fIterator->GetNextEntry(key, (void**)&entries, 79 75 &entries_length); 80 76 if (status != B_OK) 81 77 return status; 82 78 83 btrfs_dir_entry *entry = entries;79 btrfs_dir_entry* entry = entries; 84 80 uint16 current = 0; 85 81 while (current < entries_length) { 86 82 current += entry->Length(); 87 83 break; 88 84 // TODO there could be several entries with the same name hash 89 entry = (btrfs_dir_entry 85 entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length()); 90 86 } 91 87 92 88 size_t length = entry->NameLength(); … … DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id) 127 123 key.SetObjectID(fInode->ID()); 128 124 key.SetOffset(hash); 129 125 130 btrfs_dir_entry *entries;126 btrfs_dir_entry* entries; 131 127 size_t length; 132 128 status_t status = fInode->GetVolume()->FSTree()->FindExact(key, 133 129 (void**)&entries, &length); … … DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id) 137 133 return status; 138 134 } 139 135 140 btrfs_dir_entry *entry = entries;136 btrfs_dir_entry* entry = entries; 141 137 uint16 current = 0; 142 138 while (current < length) { 143 139 current += entry->Length(); 144 140 break; 145 141 // TODO there could be several entries with the same name hash 146 entry = (btrfs_dir_entry 142 entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length()); 147 143 } 148 144 149 145 TRACE("DirectoryIterator::Lookup() entries_length %ld name_length %d\n", -
src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.h b/src/add-ons/kernel/file_systems/btrfs/DirectoryIterator.h index 069c9a0..4d9c5ba 100644
a b 6 6 #define DIRECTORYITERATOR_H 7 7 8 8 9 #ifndef FS_SHELL 10 # include <new> 11 # include <stdlib.h> 12 #else 13 # include "fssh_api_wrapper.h" 14 #endif 9 15 #include "BPlusTree.h" 10 16 #include "Inode.h" 11 17 12 18 13 19 class DirectoryIterator { 14 20 public: 15 16 21 DirectoryIterator(Inode* inode); 22 ~DirectoryIterator(); 17 23 18 status_tInitCheck();24 status_t InitCheck(); 19 25 20 status_tGetNext(char* name, size_t* _nameLength, ino_t* _id);21 status_tLookup(const char* name, size_t nameLength, ino_t* _id);22 status_tRewind();26 status_t GetNext(char* name, size_t* _nameLength, ino_t* _id); 27 status_t Lookup(const char* name, size_t nameLength, ino_t* _id); 28 status_t Rewind(); 23 29 private: 24 uint64fOffset;25 Inode*fInode;26 TreeIterator*fIterator;30 uint64 fOffset; 31 Inode* fInode; 32 TreeIterator* fIterator; 27 33 }; 28 34 29 35 -
src/add-ons/kernel/file_systems/btrfs/Inode.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/Inode.cpp b/src/add-ons/kernel/file_systems/btrfs/Inode.cpp index 742f6d5..a38dace 100644
a b 5 5 * This file may be used under the terms of the MIT License. 6 6 */ 7 7 8 9 #include "Inode.h"10 11 #include <string.h>12 #include <stdlib.h>13 8 #include <zlib.h> 14 9 10 #include "Inode.h" 15 11 #include "BPlusTree.h" 16 12 #include "CachedBlock.h" 17 13 #include "Utility.h" … … Inode::UpdateNodeFromDisk() 84 80 search_key.SetObjectID(fID); 85 81 search_key.SetOffset(0); 86 82 87 struct btrfs_inode *node;83 struct btrfs_inode* node; 88 84 if (fVolume->FSTree()->FindExact(search_key, (void**)&node) != B_OK) { 89 85 ERROR("Inode::UpdateNodeFromDisk(): Couldn't find inode %" 90 86 B_PRIdINO "\n", fID); … … Inode::CheckPermissions(int accessMode) const 110 106 111 107 112 108 status_t 113 Inode::FindBlock(off_t pos, off_t& physical, off_t *_length)109 Inode::FindBlock(off_t pos, off_t& physical, off_t* _length) 114 110 { 115 111 struct btrfs_key search_key; 116 112 search_key.SetType(BTRFS_KEY_TYPE_EXTENT_DATA); 117 113 search_key.SetObjectID(fID); 118 114 search_key.SetOffset(pos + 1); 119 115 120 btrfs_extent_data *extent_data;116 btrfs_extent_data* extent_data; 121 117 status_t status = fVolume->FSTree()->FindPrevious(search_key, 122 118 (void**)&extent_data); 123 119 if (status != B_OK) { … … Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length) 173 169 search_key.SetOffset(pos + 1); 174 170 175 171 size_t item_size; 176 btrfs_extent_data *extent_data;172 btrfs_extent_data* extent_data; 177 173 status_t status = fVolume->FSTree()->FindPrevious(search_key, 178 174 (void**)&extent_data, &item_size); 179 175 if (status != B_OK) { … … Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length) 291 287 292 288 293 289 status_t 294 Inode::FindParent(ino_t *id)290 Inode::FindParent(ino_t* id) 295 291 { 296 292 struct btrfs_key search_key; 297 293 search_key.SetType(BTRFS_KEY_TYPE_INODE_REF); 298 294 search_key.SetObjectID(fID); 299 295 search_key.SetOffset(-1); 300 296 301 void *node_ref;297 void* node_ref; 302 298 if (fVolume->FSTree()->FindPrevious(search_key, &node_ref) != B_OK) { 303 299 ERROR("Inode::FindParent(): Couldn't find inode for %" B_PRIdINO "\n", 304 300 fID); -
src/add-ons/kernel/file_systems/btrfs/Inode.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/Inode.h b/src/add-ons/kernel/file_systems/btrfs/Inode.h index b6fa157..b10da99 100644
a b 7 7 #define INODE_H 8 8 9 9 10 #include <fs_cache.h> 11 #include <lock.h> 12 #include <string.h> 10 #ifndef FS_SHELL 11 # include <stdlib.h> 12 # include <fs_cache.h> 13 # include <lock.h> 14 # include <string.h> 15 #else 16 # include "fssh_api_wrapper.h" 17 #endif 13 18 14 19 #include "btrfs.h" 15 20 #include "Volume.h" … … 25 30 26 31 class Inode { 27 32 public: 28 Inode(Volume* volume, ino_t id); 29 ~Inode(); 30 31 status_t InitCheck(); 32 33 ino_t ID() const { return fID; } 34 35 rw_lock* Lock() { return &fLock; } 36 37 status_t UpdateNodeFromDisk(); 38 39 bool IsDirectory() const 40 { return S_ISDIR(Mode()); } 41 bool IsFile() const 42 { return S_ISREG(Mode()); } 43 bool IsSymLink() const 44 { return S_ISLNK(Mode()); } 45 status_t CheckPermissions(int accessMode) const; 46 47 mode_t Mode() const { return fNode.Mode(); } 48 off_t Size() const { return fNode.Size(); } 49 uid_t UserID() const { return fNode.UserID(); } 50 gid_t GroupID() const { return fNode.GroupID(); } 51 void GetChangeTime(struct timespec ×pec) const 52 { fNode.GetChangeTime(timespec); } 53 void GetModificationTime(struct timespec ×pec) const 54 { fNode.GetModificationTime(timespec); } 55 void GetCreationTime(struct timespec ×pec) const 56 { fNode.GetCreationTime(timespec); } 57 void GetAccessTime(struct timespec ×pec) const 58 { fNode.GetCreationTime(timespec); } 59 60 Volume* GetVolume() const { return fVolume; } 61 62 status_t FindBlock(off_t logical, off_t& physical, 63 off_t *_length = NULL); 64 status_t ReadAt(off_t pos, uint8 *buffer, size_t *length); 65 status_t FillGapWithZeros(off_t start, off_t end); 66 67 void* FileCache() const { return fCache; } 68 void* Map() const { return fMap; } 69 70 status_t FindParent(ino_t *id); 33 Inode(Volume* volume, ino_t id); 34 ~Inode(); 35 36 status_t InitCheck(); 37 ino_t ID() const { return fID; } 38 rw_lock* Lock() { return& fLock; } 39 status_t UpdateNodeFromDisk(); 40 41 bool IsDirectory() const 42 { return S_ISDIR(Mode()); } 43 bool IsFile() const 44 { return S_ISREG(Mode()); } 45 bool IsSymLink() const 46 { return S_ISLNK(Mode()); } 47 status_t CheckPermissions(int accessMode) const; 48 mode_t Mode() const { return fNode.Mode(); } 49 off_t Size() const { return fNode.Size(); } 50 uid_t UserID() const { return fNode.UserID(); } 51 gid_t GroupID() const { return fNode.GroupID(); } 52 void GetChangeTime(struct timespec& timespec) const 53 { fNode.GetChangeTime(timespec); } 54 void GetModificationTime(struct timespec& timespec) const 55 { fNode.GetModificationTime(timespec); } 56 void GetCreationTime(struct timespec& timespec) const 57 { fNode.GetCreationTime(timespec); } 58 void GetAccessTime(struct timespec& timespec) const 59 { fNode.GetCreationTime(timespec); } 60 Volume* GetVolume() const { return fVolume; } 61 status_t FindBlock(off_t logical, off_t& physical, 62 off_t* _length = NULL); 63 status_t ReadAt(off_t pos, uint8* buffer, size_t* length); 64 status_t FillGapWithZeros(off_t start, off_t end); 65 void* FileCache() const { return fCache; } 66 void* Map() const { return fMap; } 67 status_t FindParent(ino_t* id); 71 68 private: 72 Inode(Volume* volume); 73 Inode(const Inode&); 74 Inode &operator=(const Inode&); 75 // no implementation 76 77 uint64 _NumBlocks(); 78 79 rw_lock fLock; 80 ::Volume* fVolume; 81 ino_t fID; 82 void* fCache; 83 void* fMap; 84 status_t fInitStatus; 85 struct btrfs_inode fNode; 69 Inode(Volume* volume); 70 Inode(const Inode&); 71 Inode& operator=(const Inode&); 72 // no implementation 73 74 uint64 _NumBlocks(); 75 rw_lock fLock; 76 ::Volume* fVolume; 77 ino_t fID; 78 void* fCache; 79 void* fMap; 80 status_t fInitStatus; 81 struct btrfs_inode fNode; 86 82 }; 87 83 88 84 … … public: 98 94 { 99 95 SetTo(volume, id); 100 96 } 101 97 102 98 Vnode() 103 99 : 104 100 fStatus(B_NO_INIT), 105 101 fInode(NULL) 106 102 { 107 103 } 108 104 109 105 ~Vnode() 110 106 { 111 107 Unset(); 112 108 } 113 109 114 110 status_t InitCheck() 115 111 { 116 112 return fStatus; 117 113 } 118 114 119 115 void Unset() 120 116 { 121 117 if (fInode != NULL) { … … public: 124 120 fStatus = B_NO_INIT; 125 121 } 126 122 } 127 123 128 124 status_t SetTo(Volume* volume, ino_t id) 129 125 { 130 126 Unset(); 131 132 127 return fStatus = get_vnode(volume->FSVolume(), id, (void**)&fInode); 133 128 } 134 129 135 130 status_t Get(Inode** _inode) 136 131 { 137 132 *_inode = fInode; 138 133 return fStatus; 139 134 } 140 135 141 136 void Keep() 142 137 { 143 138 TRACEI("Vnode::Keep()\n"); … … public: 146 141 147 142 private: 148 143 status_t fStatus; 149 Inode* 144 Inode* fInode; 150 145 }; 151 146 152 147 #endif // INODE_H -
src/add-ons/kernel/file_systems/btrfs/Utility.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/Utility.h b/src/add-ons/kernel/file_systems/btrfs/Utility.h index 07a252e..9ad930d 100644
a b 10 10 11 11 12 12 enum inode_type { 13 S_DIRECTORY 14 S_FILE 15 S_SYMLINK 16 17 S_INDEX_TYPES = 18 | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX19 | S_FLOAT_INDEX | S_DOUBLE_INDEX),20 13 S_DIRECTORY = S_IFDIR, 14 S_FILE = S_IFREG, 15 S_SYMLINK = S_IFLNK, 16 17 S_INDEX_TYPES = (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX 18 | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX 19 | S_FLOAT_INDEX | S_DOUBLE_INDEX), 20 21 21 S_EXTENDED_TYPES = (S_ATTR_DIR | S_ATTR | S_INDEX_DIR) 22 22 }; 23 23 … … open_mode_to_access(int openMode) 38 38 return R_OK | W_OK; 39 39 } 40 40 41 41 42 #endif // UTILITY_H -
src/add-ons/kernel/file_systems/btrfs/Volume.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp index 5b99447..4dc7ddc 100644
a b 9 9 10 10 11 11 #include "Volume.h" 12 13 #include <errno.h>14 #include <new>15 #include <stdio.h>16 #include <stdlib.h>17 #include <string.h>18 19 #include <fs_cache.h>20 #include <fs_volume.h>21 22 #include <util/AutoLock.h>23 24 12 #include "BPlusTree.h" 25 13 #include "CachedBlock.h" 26 14 #include "Chunk.h" … … 38 26 39 27 class DeviceOpener { 40 28 public: 41 42 43 29 DeviceOpener(int fd, int mode); 30 DeviceOpener(const char* device, int mode); 31 ~DeviceOpener(); 44 32 45 intOpen(const char* device, int mode);46 intOpen(int fd, int mode);47 void*InitCache(off_t numBlocks, uint32 blockSize);48 voidRemoveCache(bool allowWrites);33 int Open(const char* device, int mode); 34 int Open(int fd, int mode); 35 void* InitCache(off_t numBlocks, uint32 blockSize); 36 void RemoveCache(bool allowWrites); 49 37 50 voidKeep();38 void Keep(); 51 39 52 int Device() const { return fDevice; } 53 int Mode() const { return fMode; } 54 bool IsReadOnly() const 55 { return _IsReadOnly(fMode); } 40 int Device() const { return fDevice; } 41 int Mode() const { return fMode; } 42 bool IsReadOnly() const { return _IsReadOnly(fMode); } 56 43 57 status_tGetSize(off_t* _size, uint32* _blockSize = NULL);44 status_t GetSize(off_t* _size, uint32* _blockSize = NULL); 58 45 59 private: 60 static bool _IsReadOnly(int mode) 61 { return (mode & O_RWMASK) == O_RDONLY;} 62 static bool _IsReadWrite(int mode) 63 { return (mode & O_RWMASK) == O_RDWR;} 46 private: 47 static bool _IsReadOnly(int mode) { return (mode & O_RWMASK) == O_RDONLY;} 48 static bool _IsReadWrite(int mode) { return (mode & O_RWMASK) == O_RDWR;} 64 49 65 intfDevice;66 intfMode;67 void*fBlockCache;50 int fDevice; 51 int fMode; 52 void* fBlockCache; 68 53 }; 69 54 70 55 … … void* 142 127 DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize) 143 128 { 144 129 return fBlockCache = block_cache_create(fDevice, numBlocks, blockSize, 145 IsReadOnly());130 IsReadOnly()); 146 131 } 147 132 148 133 … … DeviceOpener::GetSize(off_t* _size, uint32* _blockSize) 187 172 188 173 if (_size) { 189 174 *_size = 1ULL * geometry.head_count * geometry.cylinder_count 190 * geometry.sectors_per_track * geometry.bytes_per_sector;175 * geometry.sectors_per_track * geometry.bytes_per_sector; 191 176 } 192 177 if (_blockSize) 193 178 *_blockSize = geometry.bytes_per_sector; … … btrfs_super_block::IsValid() 205 190 // TODO: check some more values! 206 191 if (strncmp(magic, BTRFS_SUPER_BLOCK_MAGIC, sizeof(magic)) != 0) 207 192 return false; 208 193 209 194 return true; 210 195 } 211 196 … … Volume::Volume(fs_volume* volume) 219 204 fFlags(0), 220 205 fChunk(NULL), 221 206 fChunkTree(NULL) 222 {207 { 223 208 mutex_init(&fLock, "btrfs volume"); 224 209 } 225 210 … … Volume::Name() const 249 234 250 235 status_t 251 236 Volume::Mount(const char* deviceName, uint32 flags) 252 {237 { 253 238 flags |= B_MOUNT_READ_ONLY; 254 255 239 // we only support read-only for now 240 256 241 if ((flags & B_MOUNT_READ_ONLY) != 0) { 257 242 TRACE("Volume::Mount(): Read only\n"); 258 243 } else { … … Volume::Mount(const char* deviceName, uint32 flags) 276 261 ERROR("Volume::Mount(): Identify() failed\n"); 277 262 return status; 278 263 } 279 264 280 265 fBlockSize = fSuperBlock.BlockSize(); 281 266 TRACE("block size %" B_PRIu32 "\n", fBlockSize); 282 267 … … Volume::Mount(const char* deviceName, uint32 flags) 290 275 if (key->Type() != BTRFS_KEY_TYPE_CHUNK_ITEM) { 291 276 break; 292 277 } 293 278 294 279 struct btrfs_chunk* chunk = (struct btrfs_chunk*)(key + 1); 295 280 fChunk = new(std::nothrow) Chunk(chunk, key->Offset()); 296 281 if (fChunk == NULL) … … Volume::Mount(const char* deviceName, uint32 flags) 310 295 FindBlock(fSuperBlock.LogRoot(), physical); 311 296 TRACE("Volume::Mount() log_root: %" B_PRIu64 " (physical %" B_PRIu64 ")\n", 312 297 fSuperBlock.LogRoot(), physical); 313 298 314 299 // check if the device size is large enough to hold the file system 315 300 off_t diskSize; 316 301 status = opener.GetSize(&diskSize); … … Volume::Mount(const char* deviceName, uint32 flags) 323 308 fBlockSize); 324 309 if (fBlockCache == NULL) 325 310 return B_ERROR; 326 311 327 312 TRACE("Volume::Mount(): Initialized block cache: %p\n", fBlockCache); 328 313 329 314 fChunkTree = new(std::nothrow) BPlusTree(this, fSuperBlock.ChunkRoot()); … … Volume::Mount(const char* deviceName, uint32 flags) 348 333 search_key.SetOffset(0); 349 334 search_key.SetType(BTRFS_KEY_TYPE_ROOT_ITEM); 350 335 search_key.SetObjectID(BTRFS_OBJECT_ID_EXTENT_TREE); 351 struct btrfs_root *root;336 struct btrfs_root* root; 352 337 if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) { 353 338 ERROR("Volume::Mount(): Couldn't find extent root\n"); 354 339 return B_ERROR; … … Volume::Mount(const char* deviceName, uint32 flags) 359 344 free(root); 360 345 if (fExtentTree == NULL) 361 346 return B_NO_MEMORY; 362 347 363 348 search_key.SetOffset(0); 364 349 search_key.SetObjectID(BTRFS_OBJECT_ID_FS_TREE); 365 350 if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) { … … Volume::Mount(const char* deviceName, uint32 flags) 371 356 free(root); 372 357 if (fFSTree == NULL) 373 358 return B_NO_MEMORY; 374 359 375 360 search_key.SetOffset(0); 376 361 search_key.SetObjectID(BTRFS_OBJECT_ID_DEV_TREE); 377 362 if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) { … … Volume::Mount(const char* deviceName, uint32 flags) 397 382 free(root); 398 383 if (fChecksumTree == NULL) 399 384 return B_NO_MEMORY; 400 385 401 386 // ready 402 387 status = get_vnode(fFSVolume, BTRFS_OBJECT_ID_CHUNK_TREE, 403 388 (void**)&fRootNode); … … Volume::Mount(const char* deviceName, uint32 flags) 426 411 } 427 412 428 413 double size = double((10 * diskSize + divisor - 1) / divisor); 429 414 // %g in the kernel does not support precision... 430 415 431 416 snprintf(fName, sizeof(fName), "%g %cB Btrfs Volume", 432 417 size / 10, unit); … … Volume::LoadSuperBlock() 478 463 479 464 480 465 status_t 481 Volume::FindBlock(off_t logical, fsblock_t &physicalBlock)466 Volume::FindBlock(off_t logical, fsblock_t& physicalBlock) 482 467 { 483 468 off_t physical; 484 469 status_t status = FindBlock(logical, physical); … … Volume::FindBlock(off_t logical, fsblock_t &physicalBlock) 490 475 491 476 492 477 status_t 493 Volume::FindBlock(off_t logical, off_t &physical)478 Volume::FindBlock(off_t logical, off_t& physical) 494 479 { 495 480 if (fChunkTree == NULL 496 481 || (logical >= (off_t)fChunk->Offset() … … Volume::FindBlock(off_t logical, off_t &physical) 503 488 search_key.SetOffset(logical); 504 489 search_key.SetType(BTRFS_KEY_TYPE_CHUNK_ITEM); 505 490 search_key.SetObjectID(BTRFS_OBJECT_ID_CHUNK_TREE); 506 struct btrfs_chunk *chunk;491 struct btrfs_chunk* chunk; 507 492 size_t chunk_length; 508 493 status_t status = fChunkTree->FindPrevious(search_key, (void**)&chunk, 509 494 &chunk_length); … … Volume::FindBlock(off_t logical, off_t &physical) 514 499 free(chunk); 515 500 status = _chunk.FindBlock(logical, physical); 516 501 if (status != B_OK) 517 502 return status; 518 503 TRACE("Volume::FindBlock(): logical: %" B_PRIdOFF ", physical: %" B_PRIdOFF 519 504 "\n", logical, physical); 520 505 return B_OK; -
src/add-ons/kernel/file_systems/btrfs/Volume.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.h b/src/add-ons/kernel/file_systems/btrfs/Volume.h index a832fd2..ae991b7 100644
a b 7 7 #define VOLUME_H 8 8 9 9 10 #include <lock.h> 10 #ifndef FS_SHELL 11 # include <lock.h> 12 # include <errno.h> 13 # include <new> 14 # include <stdio.h> 15 # include <stdlib.h> 16 # include <string.h> 17 # include <fs_cache.h> 18 # include <fs_volume.h> 19 # include <util/AutoLock.h> 20 #else 21 # include "fssh_api_wrapper.h" 22 #endif 11 23 12 24 #include "btrfs.h" 13 25 14 26 15 27 enum volume_flags { 16 VOLUME_READ_ONLY 28 VOLUME_READ_ONLY = 0x0001 17 29 }; 18 30 31 19 32 class BPlusTree; 20 33 class Chunk; 21 34 class Inode; … … class Inode; 23 36 24 37 class Volume { 25 38 public: 26 Volume(fs_volume* volume); 27 ~Volume(); 28 29 status_t Mount(const char* device, uint32 flags); 30 status_t Unmount(); 39 Volume(fs_volume* volume); 40 ~Volume(); 31 41 32 bool IsValidSuperBlock(); 33 bool IsReadOnly() const 34 { return (fFlags & VOLUME_READ_ONLY) != 0; } 42 status_t Mount(const char* device, uint32 flags); 43 status_t Unmount(); 35 44 36 Inode* RootNode() const { return fRootNode; } 37 int Device() const { return fDevice; } 45 bool IsValidSuperBlock(); 46 bool IsReadOnly() const 47 { return (fFlags & VOLUME_READ_ONLY) != 0; } 38 48 39 dev_t ID() const 40 { return fFSVolume ? fFSVolume->id : -1; } 41 fs_volume* FSVolume() const { return fFSVolume; } 42 const char* Name() const; 43 BPlusTree* FSTree() const { return fFSTree; } 44 BPlusTree* RootTree() const { return fRootTree; } 49 Inode* RootNode() const { return fRootNode; } 50 int Device() const { return fDevice; } 45 51 46 uint32 BlockSize() const { return fBlockSize; }47 btrfs_super_block& SuperBlock() { return fSuperBlock; }52 dev_t ID() const 53 { return fFSVolume ? fFSVolume->id : -1; } 48 54 49 status_t LoadSuperBlock(); 55 fs_volume* FSVolume() const { return fFSVolume; } 56 const char* Name() const; 57 BPlusTree* FSTree() const { return fFSTree; } 58 BPlusTree* RootTree() const { return fRootTree; } 59 uint32 BlockSize() const { return fBlockSize; } 60 btrfs_super_block& SuperBlock() { return fSuperBlock; } 61 status_t LoadSuperBlock(); 50 62 51 52 void*BlockCache() { return fBlockCache; }63 // cache access 64 void* BlockCache() { return fBlockCache; } 53 65 54 static status_t Identify(int fd, btrfs_super_block* superBlock); 55 56 status_t FindBlock(off_t logical, fsblock_t &physical); 57 status_t FindBlock(off_t logical, off_t &physical); 66 static status_t Identify(int fd, btrfs_super_block* superBlock); 67 status_t FindBlock(off_t logical, fsblock_t& physical); 68 status_t FindBlock(off_t logical, off_t& physical); 58 69 59 70 private: 60 mutexfLock;61 fs_volume*fFSVolume;62 intfDevice;63 64 charfName[32];65 66 uint32fFlags;67 uint32fBlockSize;68 69 void*fBlockCache;70 Inode*fRootNode;71 72 Chunk*fChunk;73 BPlusTree*fChunkTree;74 BPlusTree*fRootTree;75 BPlusTree*fDevTree;76 BPlusTree*fExtentTree;77 BPlusTree*fFSTree;78 BPlusTree*fChecksumTree;71 mutex fLock; 72 fs_volume* fFSVolume; 73 int fDevice; 74 btrfs_super_block fSuperBlock; 75 char fName[32]; 76 77 uint32 fFlags; 78 uint32 fBlockSize; 79 80 void* fBlockCache; 81 Inode* fRootNode; 82 83 Chunk* fChunk; 84 BPlusTree* fChunkTree; 85 BPlusTree* fRootTree; 86 BPlusTree* fDevTree; 87 BPlusTree* fExtentTree; 88 BPlusTree* fFSTree; 89 BPlusTree* fChecksumTree; 79 90 }; 80 91 92 81 93 #endif // VOLUME_H 82 94 -
src/add-ons/kernel/file_systems/btrfs/btrfs.h
diff --git a/src/add-ons/kernel/file_systems/btrfs/btrfs.h b/src/add-ons/kernel/file_systems/btrfs/btrfs.h index c3e6ad5..6d1a040 100644
a b 6 6 #define BTRFS_H 7 7 8 8 9 #include <sys/stat.h> 9 #ifndef FS_SHELL 10 # include <sys/stat.h> 11 # include <ByteOrder.h> 12 # include <fs_interface.h> 13 # include <KernelExport.h> 14 #else 15 # include "fssh_api_wrapper.h" 16 #endif 10 17 11 #include <ByteOrder.h>12 #include <fs_interface.h>13 #include <KernelExport.h>14 18 15 16 typedef uint64 fileblock_t; // file block number 17 typedef uint64 fsblock_t; // filesystem block number 19 typedef uint64 fileblock_t; // file block number 20 typedef uint64 fsblock_t; // filesystem block number 18 21 19 22 20 23 #define BTRFS_SUPER_BLOCK_OFFSET 0x10000 … … struct btrfs_key { 23 26 uint64 object_id; 24 27 uint8 type; 25 28 uint64 offset; 26 27 29 uint64 ObjectID() const { return B_LENDIAN_TO_HOST_INT64(object_id); } 28 30 uint8 Type() const { return type; } 29 31 uint64 Offset() const { return B_LENDIAN_TO_HOST_INT64(offset); } … … struct btrfs_key { 32 34 void SetOffset(uint64 off) { offset = B_HOST_TO_LENDIAN_INT64(off); } 33 35 } _PACKED; 34 36 37 35 38 struct btrfs_timespec { 36 39 uint64 seconds; 37 40 uint32 nanoseconds; 38 41 } _PACKED; 39 42 43 40 44 struct btrfs_header { 41 45 uint8 checksum[32]; 42 46 uint8 fsid[16]; … … struct btrfs_header { 50 54 uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); } 51 55 uint64 Flags() const { return B_LENDIAN_TO_HOST_INT64(flags); } 52 56 uint64 Generation() const { 53 return B_LENDIAN_TO_HOST_INT64(generation); }57 return B_LENDIAN_TO_HOST_INT64(generation); } 54 58 uint64 Owner() const { 55 return B_LENDIAN_TO_HOST_INT64(owner); }59 return B_LENDIAN_TO_HOST_INT64(owner); } 56 60 uint32 ItemCount() const { 57 return B_LENDIAN_TO_HOST_INT32(item_count); }61 return B_LENDIAN_TO_HOST_INT32(item_count); } 58 62 uint8 Level() const { return level; } 59 63 } _PACKED; 60 64 65 61 66 struct btrfs_index { 62 67 btrfs_key key; 63 68 uint64 blocknum; 64 69 uint64 generation; 65 70 uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); } 66 71 uint64 Generation() const { 67 return B_LENDIAN_TO_HOST_INT64(generation); }72 return B_LENDIAN_TO_HOST_INT64(generation); } 68 73 } _PACKED; 69 74 75 70 76 struct btrfs_entry { 71 77 btrfs_key key; 72 78 uint32 offset; 73 79 uint32 size; 74 80 uint32 Offset() const { 75 return B_LENDIAN_TO_HOST_INT32(offset); }81 return B_LENDIAN_TO_HOST_INT32(offset); } 76 82 uint32 Size() const { 77 return B_LENDIAN_TO_HOST_INT32(size); }83 return B_LENDIAN_TO_HOST_INT32(size); } 78 84 } _PACKED; 79 85 86 80 87 struct btrfs_stream { 81 88 btrfs_header header; 82 89 union { … … struct btrfs_stream { 85 92 }; 86 93 } _PACKED; 87 94 95 88 96 struct btrfs_stripe { 89 97 uint64 device_id; 90 98 uint64 offset; … … struct btrfs_stripe { 93 101 uint64 Offset() const { return B_LENDIAN_TO_HOST_INT64(offset); } 94 102 } _PACKED; 95 103 104 96 105 struct btrfs_chunk { 97 106 uint64 length; 98 107 uint64 owner; … … struct btrfs_chunk { 107 116 uint64 Length() const { return B_LENDIAN_TO_HOST_INT64(length); } 108 117 uint64 Owner() const { return B_LENDIAN_TO_HOST_INT64(owner); } 109 118 uint64 StripeLength() const 110 { return B_LENDIAN_TO_HOST_INT64(stripe_length); }119 { return B_LENDIAN_TO_HOST_INT64(stripe_length); } 111 120 uint64 Type() const { return B_LENDIAN_TO_HOST_INT64(type); } 112 121 uint32 IOAlign() const { return B_LENDIAN_TO_HOST_INT32(io_align); } 113 122 uint32 IOWidth() const { return B_LENDIAN_TO_HOST_INT32(io_width); } 114 123 uint32 SectorSize() const 115 { return B_LENDIAN_TO_HOST_INT32(sector_size); }124 { return B_LENDIAN_TO_HOST_INT32(sector_size); } 116 125 uint16 StripeCount() const 117 { return B_LENDIAN_TO_HOST_INT16(stripe_count); }126 { return B_LENDIAN_TO_HOST_INT16(stripe_count); } 118 127 uint16 SubStripes() const 119 { return B_LENDIAN_TO_HOST_INT16(sub_stripes); }128 { return B_LENDIAN_TO_HOST_INT16(sub_stripes); } 120 129 } _PACKED; 121 130 131 122 132 struct btrfs_device { 123 133 uint64 id; 124 134 uint64 total_size; … … struct btrfs_super_block { 171 181 uint8 system_chunk_array[2048]; 172 182 173 183 bool IsValid(); 174 // implemented in Volume.cpp184 // implemented in Volume.cpp 175 185 uint64 TotalSize() const { return B_LENDIAN_TO_HOST_INT64(total_size); } 176 186 uint32 BlockSize() const { return B_LENDIAN_TO_HOST_INT32(sector_size); } 177 187 uint64 RootDirObjectID() const { 178 return B_LENDIAN_TO_HOST_INT64(root_dir_object_id); }188 return B_LENDIAN_TO_HOST_INT64(root_dir_object_id); } 179 189 uint64 Generation() const { 180 return B_LENDIAN_TO_HOST_INT64(generation); }190 return B_LENDIAN_TO_HOST_INT64(generation); } 181 191 uint64 Root() const { 182 return B_LENDIAN_TO_HOST_INT64(root); }192 return B_LENDIAN_TO_HOST_INT64(root); } 183 193 uint64 ChunkRoot() const { 184 return B_LENDIAN_TO_HOST_INT64(chunk_root); }194 return B_LENDIAN_TO_HOST_INT64(chunk_root); } 185 195 uint64 LogRoot() const { 186 return B_LENDIAN_TO_HOST_INT64(log_root); }196 return B_LENDIAN_TO_HOST_INT64(log_root); } 187 197 uint8 ChunkRootLevel() const { return chunk_root_level; } 188 198 } _PACKED; 189 199 200 190 201 struct btrfs_inode { 191 202 uint64 generation; 192 203 uint64 transaction_id; … … struct btrfs_inode { 212 223 uint32 Mode() const { return B_LENDIAN_TO_HOST_INT32(mode); } 213 224 uint64 Flags() const { return B_LENDIAN_TO_HOST_INT64(flags); } 214 225 uint64 Sequence() const { return B_LENDIAN_TO_HOST_INT64(sequence); } 215 static void _DecodeTime(struct timespec ×pec,216 const struct btrfs_timespec &time)226 static void _DecodeTime(struct timespec& timespec, 227 const struct btrfs_timespec& time) 217 228 { 218 229 timespec.tv_sec = B_LENDIAN_TO_HOST_INT64(time.seconds); 219 230 timespec.tv_nsec = B_LENDIAN_TO_HOST_INT32(time.nanoseconds); 220 231 } 221 void GetAccessTime(struct timespec ×pec) const222 { _DecodeTime(timespec, access_time); }223 void GetChangeTime(struct timespec ×pec) const224 { _DecodeTime(timespec, change_time); }225 void GetModificationTime(struct timespec ×pec) const226 { _DecodeTime(timespec, modification_time); }227 void GetCreationTime(struct timespec ×pec) const228 { _DecodeTime(timespec, creation_time); }232 void GetAccessTime(struct timespec& timespec) const 233 { _DecodeTime(timespec, access_time); } 234 void GetChangeTime(struct timespec& timespec) const 235 { _DecodeTime(timespec, change_time); } 236 void GetModificationTime(struct timespec& timespec) const 237 { _DecodeTime(timespec, modification_time); } 238 void GetCreationTime(struct timespec& timespec) const 239 { _DecodeTime(timespec, creation_time); } 229 240 } _PACKED; 230 241 242 231 243 struct btrfs_root { 232 244 btrfs_inode inode; 233 245 uint64 generation; … … struct btrfs_root { 242 254 uint8 drop_level; 243 255 uint8 level; 244 256 uint64 Generation() const { 245 return B_LENDIAN_TO_HOST_INT64(generation); }257 return B_LENDIAN_TO_HOST_INT64(generation); } 246 258 uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); } 247 259 } _PACKED; 248 260 261 249 262 struct btrfs_dir_entry { 250 263 btrfs_key location; 251 264 uint64 transaction_id; … … struct btrfs_dir_entry { 256 269 uint16 NameLength() const { return B_LENDIAN_TO_HOST_INT16(name_length); } 257 270 ino_t InodeID() const { return location.ObjectID(); } 258 271 uint16 Length() const 259 { return sizeof(*this) + NameLength() + DataLength(); }272 { return sizeof(*this) + NameLength() + DataLength(); } 260 273 } _PACKED; 261 274 275 262 276 struct btrfs_extent_data { 263 277 uint64 generation; 264 278 uint64 memory_size; … … struct btrfs_extent_data { 276 290 uint8 inline_data[0]; 277 291 }; 278 292 uint64 Generation() const { 279 return B_LENDIAN_TO_HOST_INT64(generation); }293 return B_LENDIAN_TO_HOST_INT64(generation); } 280 294 uint64 MemoryBytes() const { 281 return B_LENDIAN_TO_HOST_INT64(memory_size); }295 return B_LENDIAN_TO_HOST_INT64(memory_size); } 282 296 uint8 Compression() const { return compression; } 283 297 uint8 Type() const { return type; } 284 298 uint64 DiskOffset() const { 285 return B_LENDIAN_TO_HOST_INT64(disk_offset); }299 return B_LENDIAN_TO_HOST_INT64(disk_offset); } 286 300 uint64 DiskSize() const { 287 return B_LENDIAN_TO_HOST_INT64(disk_size); }301 return B_LENDIAN_TO_HOST_INT64(disk_size); } 288 302 uint64 ExtentOffset() const { 289 return B_LENDIAN_TO_HOST_INT64(extent_offset); }303 return B_LENDIAN_TO_HOST_INT64(extent_offset); } 290 304 uint64 Size() const { 291 return B_LENDIAN_TO_HOST_INT64(size); }305 return B_LENDIAN_TO_HOST_INT64(size); } 292 306 } _PACKED; 293 307 294 308 -
src/add-ons/kernel/file_systems/btrfs/crc_table.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/crc_table.cpp b/src/add-ons/kernel/file_systems/btrfs/crc_table.cpp index b5de8bd..cab9ddf 100644
a b 7 7 8 8 /*! \file crc_table.cpp 9 9 10 Standalone program to generate the CRC table used for calculating 11 UDF tag id CRC values. 12 13 This code based off of crc code in UDF-2.50 specs, as permitted. 14 See UDF-2.50 6.5 for more information. 10 Standalone program to generate the CRC table used for calculating 11 UDF tag id CRC values. 15 12 16 Reflected version by Jéme Duval 13 This code based off of crc code in UDF-2.50 specs, as permitted. 14 See UDF-2.50 6.5 for more information. 15 16 Reflected version by Jéme Duval 17 17 */ 18 18 19 #include <stdio.h> 20 #include <sys/types.h> 19 20 #ifndef FS_SHELL 21 # include <stdio.h> 22 # include <sys/types.h> 23 #else 24 # include "fssh_api_wrapper.h" 25 #endif 21 26 22 27 typedef unsigned int uint32 ; 23 28 … … reflect32 (uint32 b) 36 41 37 42 38 43 int 39 main(int argc, char *argv[]) {40 44 main(int argc, char* argv[]) { 45 uint32 crc, poly; 41 46 42 43 44 45 47 if (argc != 2) { 48 fprintf(stderr, "USAGE: crc_table <octal polynomial=3667067501 for btrfs>\n"); 49 return 0; 50 } 46 51 47 48 49 50 51 52 if (n%8 == 0)53 54 55 56 57 58 59 60 52 sscanf(argv[1], "%lo", &poly); 53 54 printf("//! CRC 0%o table, as generated by crc_table.cpp\n", poly); 55 printf("static uint32 crc_table[256] = { \n"); 56 for (int n = 0; n < 256; n++) { 57 if (n % 8 == 0) 58 printf(" "); 59 crc = reflect32(n); 60 for (int i = 0; i < 8; i++) { 61 if (crc & 0x80000000) 62 crc = (crc << 1) ^ poly; 63 else 64 crc <<= 1; 65 } 61 66 crc = reflect32(crc); 62 63 if (n%8 == 7)64 65 66 67 67 printf("0x%08x%s ", crc, (n != 255 ? "," : "")); 68 if (n % 8 == 7) 69 printf("\n"); 70 } 71 printf("};\n"); 72 return 0; 68 73 } -
src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp
diff --git a/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp index 3ab3765..93c5f76 100644
a b 5 5 */ 6 6 7 7 8 #include <dirent.h> 9 #include <util/kernel_cpp.h> 10 #include <string.h> 11 12 #include <AutoDeleter.h> 13 #include <fs_cache.h> 14 #include <fs_info.h> 15 #include <io_requests.h> 16 #include <NodeMonitor.h> 17 #include <util/AutoLock.h> 8 #ifndef FS_SHELL 9 # include <dirent.h> 10 # include <util/kernel_cpp.h> 11 # include <string.h> 12 # include <AutoDeleter.h> 13 # include <fs_cache.h> 14 # include <fs_info.h> 15 # include <io_requests.h> 16 # include <NodeMonitor.h> 17 # include <util/AutoLock.h> 18 #else 19 # include "fssh_api_wrapper.h" 20 # include "fssh_auto_deleter.h" 21 #endif 18 22 19 23 #include "Attribute.h" 20 24 #include "AttributeIterator.h" … … iterative_io_finished_hook(void* cookie, io_request* request, status_t status, 68 72 69 73 70 74 static float 71 btrfs_identify_partition(int fd, partition_data *partition, void **_cookie)75 btrfs_identify_partition(int fd, partition_data* partition, void** _cookie) 72 76 { 73 77 btrfs_super_block superBlock; 74 78 status_t status = Volume::Identify(fd, &superBlock); 75 79 if (status != B_OK) 76 80 return -1; 77 81 78 identify_cookie *cookie = new identify_cookie;82 identify_cookie* cookie = new identify_cookie; 79 83 memcpy(&cookie->super_block, &superBlock, sizeof(btrfs_super_block)); 80 84 81 85 *_cookie = cookie; … … btrfs_identify_partition(int fd, partition_data *partition, void **_cookie) 84 88 85 89 86 90 static status_t 87 btrfs_scan_partition(int fd, partition_data *partition, void *_cookie)91 btrfs_scan_partition(int fd, partition_data* partition, void* _cookie) 88 92 { 89 identify_cookie *cookie = (identify_cookie*)_cookie;93 identify_cookie* cookie = (identify_cookie*)_cookie; 90 94 91 95 partition->status = B_PARTITION_VALID; 92 96 partition->flags |= B_PARTITION_FILE_SYSTEM; … … btrfs_mount(fs_volume* _volume, const char* device, uint32 flags, 138 142 139 143 140 144 static status_t 141 btrfs_unmount(fs_volume *_volume)145 btrfs_unmount(fs_volume* _volume) 142 146 { 143 Volume* volume = (Volume 147 Volume* volume = (Volume*)_volume->private_volume; 144 148 145 149 status_t status = volume->Unmount(); 146 150 delete volume; … … btrfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos, 452 456 453 457 454 458 static status_t 455 btrfs_close(fs_volume *_volume, fs_vnode *_node, void *_cookie)459 btrfs_close(fs_volume* _volume, fs_vnode* _node, void* _cookie) 456 460 { 457 461 return B_OK; 458 462 } … … btrfs_access(fs_volume* _volume, fs_vnode* _node, int accessMode) 482 486 483 487 484 488 static status_t 485 btrfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer,486 size_t *_bufferSize)489 btrfs_read_link(fs_volume* _volume, fs_vnode* _node, char* buffer, 490 size_t* _bufferSize) 487 491 { 488 492 Inode* inode = (Inode*)_node->private_node; 489 493 return inode->ReadAt(0, (uint8*)buffer, _bufferSize); … … btrfs_open_dir(fs_volume* /*_volume*/, fs_vnode* _node, void** _cookie) 516 520 517 521 518 522 static status_t 519 btrfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie,520 struct dirent *dirent, size_t bufferSize, uint32 *_num)523 btrfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie, 524 struct dirent* dirent, size_t bufferSize, uint32* _num) 521 525 { 522 526 DirectoryIterator* iterator = (DirectoryIterator*)_cookie; 523 527 Volume* volume = (Volume*)_volume->private_volume; … … btrfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie, 560 564 561 565 562 566 static status_t 563 btrfs_rewind_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void *_cookie)567 btrfs_rewind_dir(fs_volume* /*_volume*/, fs_vnode* /*node*/, void* _cookie) 564 568 { 565 569 DirectoryIterator* iterator = (DirectoryIterator*)_cookie; 566 570 … … btrfs_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void * /*_cookie*/ 576 580 577 581 578 582 static status_t 579 btrfs_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)583 btrfs_free_dir_cookie(fs_volume* _volume, fs_vnode* _node, void* _cookie) 580 584 { 581 585 delete (DirectoryIterator*)_cookie; 582 586 return B_OK; … … btrfs_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) 584 588 585 589 586 590 static status_t 587 btrfs_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie)591 btrfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie) 588 592 { 589 593 Inode* inode = (Inode*)_node->private_node; 590 594 TRACE("%s()\n", __FUNCTION__); … … static file_system_module_info sBtrfsFileSystem = { 859 863 }; 860 864 861 865 862 module_info *modules[] = {863 (module_info 866 module_info* modules[] = { 867 (module_info*)&sBtrfsFileSystem, 864 868 NULL, 865 869 };