Ticket #13513: 0001-Code-refactoring.patch

File 0001-Code-refactoring.patch, 66.4 KB (added by hyche, 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  
    88//! connection between pure inode and kernel_interface attributes
    99
    1010
    11 #include "Attribute.h"
    12 
    1311#include <new>
    14 #include <stdio.h>
    15 #include <stdlib.h>
    1612
     13#include "Attribute.h"
    1714#include "BPlusTree.h"
    1815#include "CRCTable.h"
    1916#include "Utility.h"
    Attribute::Stat(struct stat& stat)  
    9289    TRACE("Stat\n");
    9390
    9491    size_t nameLength = strlen(fName);
    95     btrfs_dir_entry *entries;
     92    btrfs_dir_entry* entries;
    9693    size_t length;
    9794    status_t status = _Lookup(fName, nameLength, &entries, &length);
    9895    if (status < B_OK)
    9996        return status;
    10097
    101     btrfs_dir_entry *entry;
     98    btrfs_dir_entry* entry;
    10299    status = _FindEntry(entries, length, fName, nameLength, &entry);
    103100    if (status != B_OK) {
    104101        free(entries);
    Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length)  
    120117        return ERANGE;
    121118
    122119    size_t nameLength = strlen(fName);
    123     btrfs_dir_entry *entries;
     120    btrfs_dir_entry* entries;
    124121    size_t length;
    125122    status_t status = _Lookup(fName, nameLength, &entries, &length);
    126123    if (status < B_OK)
    127124        return status;
    128125
    129     btrfs_dir_entry *entry;
     126    btrfs_dir_entry* entry;
    130127    status = _FindEntry(entries, length, fName, nameLength, &entry);
    131128    if (status != B_OK) {
    132129        free(entries);
    Attribute::Read(attr_cookie* cookie, off_t pos, uint8* buffer, size_t* _length)  
    149146
    150147status_t
    151148Attribute::_Lookup(const char* name, size_t nameLength,
    152     btrfs_dir_entry **_entries, size_t *_length)
     149    btrfs_dir_entry** _entries, size_t* _length)
    153150{
    154151    uint32 hash = calculate_crc((uint32)~1, (uint8*)name, nameLength);
    155152    struct btrfs_key key;
    Attribute::_Lookup(const char* name, size_t nameLength,  
    157154    key.SetObjectID(fInode->ID());
    158155    key.SetOffset(hash);
    159156
    160     btrfs_dir_entry *entries;
     157    btrfs_dir_entry* entries;
    161158    size_t length;
    162159    status_t status = fInode->GetVolume()->FSTree()->FindExact(key,
    163160        (void**)&entries, &length);
    Attribute::_Lookup(const char* name, size_t nameLength,  
    180177
    181178
    182179status_t
    183 Attribute::_FindEntry(btrfs_dir_entry *entries, size_t length,
    184     const char* name, size_t nameLength, btrfs_dir_entry **_entry)
     180Attribute::_FindEntry(btrfs_dir_entry* entries, size_t length,
     181    const char* name, size_t nameLength, btrfs_dir_entry** _entry)
    185182{
    186     btrfs_dir_entry *entry = entries;
     183    btrfs_dir_entry* entry = entries;
    187184    uint16 current = 0;
    188185    while (current < length) {
    189186        current += entry->Length();
    190187        break;
    191188        // TODO there could be several entries with the same name hash
    192         entry = (btrfs_dir_entry *)((uint8*)entry + entry->Length());
     189        entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length());
    193190    }
    194191   
    195192    *_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  
    77#define ATTRIBUTE_H
    88
    99
     10#ifndef FS_SHELL
     11#   include <stdio.h>
     12#   include <stdlib.h>
     13#else
     14#   include "fssh_api_wrapper.h"
     15#endif
     16
    1017#include "CachedBlock.h"
    1118#include "Inode.h"
    1219
    struct attr_cookie {  
    2128
    2229class Attribute {
    2330public:
    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);
    3642
    37             status_t            Read(attr_cookie* cookie, off_t pos,
    38                                     uint8* buffer, size_t* _length);
    3943private:
    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                                     size_t length, const char* name,
    45                                     size_t nameLength,
    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;
    5155};
    5256
    5357#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  
    44 */
    55
    66
    7 #include "AttributeIterator.h"
    8 
    97#include <new>
    10 #include <stdlib.h>
    11 
     8#include "AttributeIterator.h"
    129
    1310//#define TRACE_BTRFS
    1411#ifdef TRACE_BTRFS
    status_t  
    5047AttributeIterator::GetNext(char* name, size_t* _nameLength)
    5148{
    5249    btrfs_key key;
    53     btrfs_dir_entry *entries;
     50    btrfs_dir_entry* entries;
    5451    size_t entries_length;
    5552    status_t status = fIterator->GetPreviousEntry(key, (void**)&entries,
    5653        &entries_length);
    5754    if (status != B_OK)
    5855        return status;
    5956
    60     btrfs_dir_entry *entry = entries;
     57    btrfs_dir_entry* entry = entries;
    6158    uint16 current = 0;
    6259    while (current < entries_length) {
    6360        current += entry->Length();
    6461        break;
    6562        // TODO there could be several entries with the same name hash
    66         entry = (btrfs_dir_entry *)((uint8*)entry + entry->Length());
     63        entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length());
    6764    }
    6865
    6966    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  
    22 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
    33 * This file may be used under the terms of the MIT License.
    44 */
     5
    56#ifndef ATTRIBUTEITERATOR_H
    67#define ATTRIBUTEITERATOR_H
    78
    89
     10#ifndef FS_SHELL
     11#   include <stdlib.h>
     12#else
     13#   include "fssh_api_wrapper.h"
     14#endif
     15
    916#include "BPlusTree.h"
    1017#include "Inode.h"
    1118
    12 
    1319class AttributeIterator {
    1420public:
    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();
    1727
    18             status_t            InitCheck();
    1928
    20             status_t            GetNext(char* name, size_t* _nameLength);
    21             status_t            Rewind();
    2229private:
    23             uint64              fOffset;
    24             Inode*              fInode;
    25             TreeIterator*       fIterator;
     30    uint64  fOffset;
     31    Inode*  fInode;
     32    TreeIterator*   fIterator;
    2633};
    2734
    28 
    2935#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  
    99
    1010
    1111#include "BPlusTree.h"
    12 
    1312#include "CachedBlock.h"
    1413
    15 #include <stdlib.h>
    16 #include <string.h>
    17 #include <util/AutoLock.h>
    18 
    19 
    2014//#define TRACE_BTRFS
    2115#ifdef TRACE_BTRFS
    2216#   define TRACE(x...) dprintf("\33[34mbtrfs:\33[0m " x)
     
    2620#   define ERROR(x...) dprintf("\33[34mbtrfs:\33[0m " x)
    2721
    2822
    29 BPlusTree::BPlusTree(Volume* volume, struct btrfs_stream *stream)
     23BPlusTree::BPlusTree(Volume* volume, struct btrfs_stream* stream)
    3024    :
    3125    fStream(stream),
    3226    fRootBlock(0),
    BPlusTree::~BPlusTree()  
    6256
    6357
    6458int32
    65 BPlusTree::_CompareKeys(struct btrfs_key &key1, struct btrfs_key &key2)
     59BPlusTree::_CompareKeys(struct btrfs_key& key1, struct btrfs_key& key2)
    6660{
    6761    if (key1.ObjectID() > key2.ObjectID())
    6862        return 1;
    BPlusTree::_CompareKeys(struct btrfs_key &key1, struct btrfs_key &key2)  
    8680    It can also return other errors to indicate that something went wrong.
    8781*/
    8882status_t
    89 BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
     83BPlusTree::_Find(struct btrfs_key& key, void** _value, size_t* _size,
    9084    bplustree_traversing type)
    9185{
    9286    TRACE("Find() objectid %" B_PRId64 " type %d offset %" B_PRId64 " \n",
    9387        key.ObjectID(), key.Type(), key.Offset());
    94     btrfs_stream *stream = fStream;
     88    btrfs_stream* stream = fStream;
    9589    CachedBlock cached(fVolume);
    9690    fsblock_t physical;
    9791    if (stream == NULL) {
    BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,  
    9993            ERROR("Find() unmapped block %" B_PRId64 "\n", fRootBlock);
    10094            return B_ERROR;
    10195        }
    102         stream = (btrfs_stream *)cached.SetTo(physical);
     96        stream = (btrfs_stream*)cached.SetTo(physical);
    10397    }
    10498
    10599    while (stream->header.Level() != 0) {
    BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,  
    123117                stream->index[i - 1].BlockNum());
    124118            return B_ERROR;
    125119        }
    126         stream = (btrfs_stream *)cached.SetTo(physical);
     120        stream = (btrfs_stream*)cached.SetTo(physical);
    127121    }
    128122
    129123    uint32 i;
    BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,  
    175169            if ((fVolume->BlockSize() - totalOffset % fVolume->BlockSize())
    176170                >= stream->entries[i].Size()) {
    177171                //If there is enough space for *_value
    178                 memcpy(*_value, ((uint8 *)cached.SetTo(physical
     172                memcpy(*_value, ((uint8*)cached.SetTo(physical
    179173                    + totalOffset / fVolume->BlockSize())
    180174                    + totalOffset % fVolume->BlockSize()),
    181175                    stream->entries[i].Size());
    BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,  
    201195
    202196
    203197status_t
    204 BPlusTree::FindNext(struct btrfs_key &key, void** _value, size_t* _size)
     198BPlusTree::FindNext(struct btrfs_key& key, void** _value, size_t* _size)
    205199{
    206200    return _Find(key, _value, _size, BPLUSTREE_FORWARD);
    207201}
    208202
    209203
    210204status_t
    211 BPlusTree::FindPrevious(struct btrfs_key &key, void** _value, size_t* _size)
     205BPlusTree::FindPrevious(struct btrfs_key& key, void** _value, size_t* _size)
    212206{
    213207    return _Find(key, _value, _size, BPLUSTREE_BACKWARD);
    214208}
    215209
    216210
    217211status_t
    218 BPlusTree::FindExact(struct btrfs_key &key, void** _value, size_t* _size)
     212BPlusTree::FindExact(struct btrfs_key& key, void** _value, size_t* _size)
    219213{
    220214    return _Find(key, _value, _size, BPLUSTREE_EXACT);
    221215}
    BPlusTree::_RemoveIterator(TreeIterator* iterator)  
    240234//  #pragma mark -
    241235
    242236
    243 TreeIterator::TreeIterator(BPlusTree* tree, struct btrfs_key &key)
     237TreeIterator::TreeIterator(BPlusTree* tree, struct btrfs_key& key)
    244238    :
    245239    fTree(tree),
    246240    fCurrentKey(key)
    TreeIterator::~TreeIterator()  
    260254/*! Iterates through the tree in the specified direction.
    261255*/
    262256status_t
    263 TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key &key,
     257TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key& key,
    264258    void** value, size_t* size)
    265259{
    266260    if (fTree == NULL)
    TreeIterator::Traverse(bplustree_traversing direction, struct btrfs_key &key,  
    281275/*! just sets the current key in the iterator.
    282276*/
    283277status_t
    284 TreeIterator::Find(struct btrfs_key &key)
     278TreeIterator::Find(struct btrfs_key& key)
    285279{
    286280    if (fTree == NULL)
    287281        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  
    77#define B_PLUS_TREE_H
    88
    99
    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
    1318
     19#include "btrfs.h"
    1420#include "Volume.h"
    1521
    1622
    17 #define BPLUSTREE_NULL          -1LL
    18 #define BPLUSTREE_FREE          -2LL
     23#define BPLUSTREE_NULL -1LL
     24#define BPLUSTREE_FREE -2LL
    1925
    2026
    2127enum bplustree_traversing {
    struct node_and_key {  
    4349
    4450class BPlusTree {
    4551public:
    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);
    5762
    5863private:
    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
    6976private:
    70             friend class TreeIterator;
     77    friend class TreeIterator;
    7178
    72             struct btrfs_stream* fStream;
    73             fsblock_t           fRootBlock;
    74             Volume*             fVolume;
    75             mutex               fIteratorLock;
    76             SinglyLinkedList<TreeIterator> fIterators;
     79    struct btrfs_stream* fStream;
     80    fsblock_t   fRootBlock;
     81    Volume* fVolume;
     82    mutex   fIteratorLock;
     83    SinglyLinkedList<TreeIterator> fIterators;
    7784};
    7885
    7986
    8087class TreeIterator : public SinglyLinkedListLinkImpl<TreeIterator> {
    8188public:
    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; }
    97102
    98103private:
    99             friend class BPlusTree;
     104    friend class BPlusTree;
    100105
    101             // called by BPlusTree
    102             void                Stop();
     106    // called by BPlusTree
     107    void    Stop();
    103108
    104109private:
    105             BPlusTree*          fTree;
    106             struct btrfs_key    fCurrentKey;
     110    BPlusTree*  fTree;
     111    struct btrfs_key    fCurrentKey;
    107112};
    108113
    109114
    TreeIterator::Rewind()  
    117122    return B_OK;
    118123}
    119124
     125
    120126inline status_t
    121 TreeIterator::GetNextEntry(struct btrfs_key &key, void** value, size_t *size)
     127TreeIterator::GetNextEntry(struct btrfs_key& key, void** value, size_t* size)
    122128{
    123129    return Traverse(BPLUSTREE_FORWARD, key, value, size);
    124130}
    125131
     132
    126133inline status_t
    127 TreeIterator::GetPreviousEntry(struct btrfs_key &key, void** value,
    128     size_t *size)
     134TreeIterator::GetPreviousEntry(struct btrfs_key& key, void** value, size_t* size)
    129135{
    130136    return Traverse(BPLUSTREE_BACKWARD, key, value, size);
    131137}
    132138
    133139
    134 
    135140#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  
    77 */
    88
    99
    10 #include <SupportDefs.h>
     10#ifndef FS_SHELL
     11#   include <SupportDefs.h>
     12#else
     13#   include "fssh_api_wrapper.h"
     14#endif
    1115
    1216
    1317//! CRC 03667067501 table, as generated by crc_table.cpp
    1418static uint32 kCrcTable[256] = {
    15     0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb,
    16     0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24,
    17     0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384,
    18     0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b,
    19     0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35,
    20     0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa,
    21     0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a,
    22     0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595,
    23     0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957,
    24     0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198,
    25     0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38,
    26     0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7,
    27     0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789,
    28     0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46,
    29     0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6,
    30     0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829,
    31     0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93,
    32     0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c,
    33     0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc,
    34     0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033,
    35     0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d,
    36     0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982,
    37     0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622,
    38     0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed,
    39     0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f,
    40     0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0,
    41     0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540,
    42     0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f,
    43     0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1,
    44     0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e,
    45     0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e,
    46     0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351
     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
    4751};
    4852
    4953
    static uint32 kCrcTable[256] = {  
    5862    \return The crc checksum, or 0 if an error occurred.
    5963*/
    6064uint32
    61 calculate_crc(uint32 crc, uint8 *data, uint16 length)
     65calculate_crc(uint32 crc, uint8* data, uint16 length)
    6266{
    6367    if (data) {
    6468        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  
    66 *      Jérôme Duval
    77 */
    88
    9 uint32 calculate_crc(uint32 crc, uint8 *data, uint16 length);
    10 
     9uint32 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  
    77
    88//! interface for the block cache
    99
    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
    1116
    1217#include "Volume.h"
    1318
    1419
    1520class CachedBlock {
    1621public:
    17                             CachedBlock(Volume* volume);
    18                             CachedBlock(Volume* volume, off_t block);
    19                             ~CachedBlock();
     22    CachedBlock(Volume* volume);
     23    CachedBlock(Volume* volume, off_t block);
     24    ~CachedBlock();
    2025
    21             void            Keep();
    22             void            Unset();
     26    void    Keep();
     27    void    Unset();
    2328
    24             const uint8*    SetTo(off_t block);
     29    const uint8*    SetTo(off_t block);
    2530
    26             const uint8*    Block() const { return fBlock; }
    27             off_t           BlockNumber() const { return fBlockNumber; }
     31    const uint8*    Block() const { return fBlock; }
     32    off_t   BlockNumber() const { return fBlockNumber; }
    2833
    2934private:
    30                             CachedBlock(const CachedBlock &);
    31                             CachedBlock &operator=(const CachedBlock &);
    32                                 // no implementation
    33                        
     35    CachedBlock(const CachedBlock&);
     36    CachedBlock& operator=(const CachedBlock&);
     37    // no implementation
     38
    3439protected:
    35             Volume*         fVolume;
    36             off_t           fBlockNumber;
    37             uint8*          fBlock;
     40    Volume* fVolume;
     41    off_t   fBlockNumber;
     42    uint8*  fBlock;
    3843};
    3944
    4045
    CachedBlock::SetTo(off_t block)  
    9196{
    9297    Unset();
    9398    fBlockNumber = block;
    94     return fBlock = (uint8 *)block_cache_get(fVolume->BlockCache(), block);
     99    return fBlock = (uint8*)block_cache_get(fVolume->BlockCache(), block);
    95100}
    96101
    97102#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  
    33 * This file may be used under the terms of the MIT License.
    44 *
    55 * Authors:
    6  *      Jérôme Duval
     6 *  Jérôme Duval
    77 */
    88
    99
    1010#include "Chunk.h"
    1111
    12 #include <stdlib.h>
    13 #include <string.h>
    14 
    1512
    1613//#define TRACE_BTRFS
    1714#ifdef TRACE_BTRFS
    Chunk::Chunk(struct btrfs_chunk* chunk, fsblock_t offset)  
    4340        "sector_size %" B_PRIu32 "\n", chunk->Length(), chunk->Owner(),
    4441        chunk->StripeLength(), chunk->Type(), chunk->StripeCount(),
    4542        chunk->SubStripes(), chunk->SectorSize());
    46     for(int32 i = 0; i < chunk->StripeCount(); i++) {
     43    for (int32 i = 0; i < chunk->StripeCount(); i++) {
    4744        TRACE("chunk.stripe[%" B_PRId32 "].physical %" B_PRId64 " deviceid %"
    4845            B_PRId64 "\n", i, chunk->stripes[i].Offset(),
    4946            chunk->stripes[i].DeviceID());
    Chunk::Size() const  
    6663
    6764
    6865status_t
    69 Chunk::FindBlock(off_t logical, off_t &physical)
     66Chunk::FindBlock(off_t logical, off_t& physical)
    7067{
    7168    if (fChunk == NULL)
    7269        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  
    55 * Authors:
    66 *      Jérôme Duval
    77 */
     8
    89#ifndef CHUNK_H
    910#define CHUNK_H
    1011
    1112
     13#ifndef FS_SHELL
     14#   include <stdlib.h>
     15#   include <string.h>
     16#else
     17#   include "fssh_api_wrapper.h"
     18#endif
     19
    1220#include "btrfs.h"
    1321
    1422
    1523class Chunk {
    1624public:
    17                                 Chunk(struct btrfs_chunk* chunk,
    18                                     fsblock_t offset);
    19                                 ~Chunk();
    20             uint32              Size() const;
    21             status_t            FindBlock(off_t logical, off_t &physical);
    22             fsblock_t           Offset() const { return fChunkOffset; }
    23             fsblock_t           End() const
    24                                     { return fChunkOffset + fChunk->Length(); }
     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(); }
    2533private:
    26             struct btrfs_chunk* fChunk;
    27             fsblock_t           fChunkOffset;
    28             status_t            fInitStatus;
     34    struct btrfs_chunk* fChunk;
     35    fsblock_t   fChunkOffset;
     36    status_t    fInitStatus;
    2937};
    3038
     39
    3140#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  
    55
    66
    77#include "DirectoryIterator.h"
    8 
    9 #include <new>
    10 #include <stdlib.h>
    11 
    128#include "CRCTable.h"
    139
    1410
    DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id)  
    7369    }
    7470
    7571    btrfs_key key;
    76     btrfs_dir_entry *entries;
     72    btrfs_dir_entry* entries;
    7773    size_t entries_length;
    7874    status_t status = fIterator->GetNextEntry(key, (void**)&entries,
    7975        &entries_length);
    8076    if (status != B_OK)
    8177        return status;
    8278
    83     btrfs_dir_entry *entry = entries;
     79    btrfs_dir_entry* entry = entries;
    8480    uint16 current = 0;
    8581    while (current < entries_length) {
    8682        current += entry->Length();
    8783        break;
    8884        // TODO there could be several entries with the same name hash
    89         entry = (btrfs_dir_entry *)((uint8*)entry + entry->Length());
     85        entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length());
    9086    }
    9187
    9288    size_t length = entry->NameLength();
    DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id)  
    127123    key.SetObjectID(fInode->ID());
    128124    key.SetOffset(hash);
    129125
    130     btrfs_dir_entry *entries;
     126    btrfs_dir_entry* entries;
    131127    size_t length;
    132128    status_t status = fInode->GetVolume()->FSTree()->FindExact(key,
    133129        (void**)&entries, &length);
    DirectoryIterator::Lookup(const char* name, size_t nameLength, ino_t* _id)  
    137133        return status;
    138134    }
    139135
    140     btrfs_dir_entry *entry = entries;
     136    btrfs_dir_entry* entry = entries;
    141137    uint16 current = 0;
    142138    while (current < length) {
    143139        current += entry->Length();
    144140        break;
    145141        // TODO there could be several entries with the same name hash
    146         entry = (btrfs_dir_entry *)((uint8*)entry + entry->Length());
     142        entry = (btrfs_dir_entry*)((uint8*)entry + entry->Length());
    147143    }
    148144
    149145    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  
    66#define DIRECTORYITERATOR_H
    77
    88
     9#ifndef FS_SHELL
     10#   include <new>
     11#   include <stdlib.h>
     12#else
     13#   include "fssh_api_wrapper.h"
     14#endif
    915#include "BPlusTree.h"
    1016#include "Inode.h"
    1117
    1218
    1319class DirectoryIterator {
    1420public:
    15                                 DirectoryIterator(Inode* inode);
    16                                 ~DirectoryIterator();
     21    DirectoryIterator(Inode* inode);
     22    ~DirectoryIterator();
    1723
    18             status_t            InitCheck();
     24    status_t    InitCheck();
    1925
    20             status_t            GetNext(char* name, size_t* _nameLength, ino_t* _id);
    21             status_t            Lookup(const char* name, size_t nameLength, ino_t* _id);
    22             status_t            Rewind();
     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();
    2329private:
    24             uint64              fOffset;
    25             Inode*              fInode;
    26             TreeIterator*       fIterator;
     30    uint64  fOffset;
     31    Inode* fInode;
     32    TreeIterator*   fIterator;
    2733};
    2834
    2935
  • 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  
    55 * This file may be used under the terms of the MIT License.
    66 */
    77
    8 
    9 #include "Inode.h"
    10 
    11 #include <string.h>
    12 #include <stdlib.h>
    138#include <zlib.h>
    149
     10#include "Inode.h"
    1511#include "BPlusTree.h"
    1612#include "CachedBlock.h"
    1713#include "Utility.h"
    Inode::UpdateNodeFromDisk()  
    8480    search_key.SetObjectID(fID);
    8581    search_key.SetOffset(0);
    8682
    87     struct btrfs_inode *node;
     83    struct btrfs_inode* node;
    8884    if (fVolume->FSTree()->FindExact(search_key, (void**)&node) != B_OK) {
    8985        ERROR("Inode::UpdateNodeFromDisk(): Couldn't find inode %"
    9086            B_PRIdINO "\n", fID);
    Inode::CheckPermissions(int accessMode) const  
    110106
    111107
    112108status_t
    113 Inode::FindBlock(off_t pos, off_t& physical, off_t *_length)
     109Inode::FindBlock(off_t pos, off_t& physical, off_t* _length)
    114110{
    115111    struct btrfs_key search_key;
    116112    search_key.SetType(BTRFS_KEY_TYPE_EXTENT_DATA);
    117113    search_key.SetObjectID(fID);
    118114    search_key.SetOffset(pos + 1);
    119115
    120     btrfs_extent_data *extent_data;
     116    btrfs_extent_data* extent_data;
    121117    status_t status = fVolume->FSTree()->FindPrevious(search_key,
    122118        (void**)&extent_data);
    123119    if (status != B_OK) {
    Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)  
    173169    search_key.SetOffset(pos + 1);
    174170
    175171    size_t item_size;
    176     btrfs_extent_data *extent_data;
     172    btrfs_extent_data* extent_data;
    177173    status_t status = fVolume->FSTree()->FindPrevious(search_key,
    178174        (void**)&extent_data, &item_size);
    179175    if (status != B_OK) {
    Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length)  
    291287
    292288
    293289status_t
    294 Inode::FindParent(ino_t *id)
     290Inode::FindParent(ino_t* id)
    295291{
    296292    struct btrfs_key search_key;
    297293    search_key.SetType(BTRFS_KEY_TYPE_INODE_REF);
    298294    search_key.SetObjectID(fID);
    299295    search_key.SetOffset(-1);
    300296
    301     void *node_ref;
     297    void* node_ref;
    302298    if (fVolume->FSTree()->FindPrevious(search_key, &node_ref) != B_OK) {
    303299        ERROR("Inode::FindParent(): Couldn't find inode for %" B_PRIdINO "\n",
    304300            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  
    77#define INODE_H
    88
    99
    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
    1318
    1419#include "btrfs.h"
    1520#include "Volume.h"
     
    2530
    2631class Inode {
    2732public:
    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 &timespec) const
    52                             { fNode.GetChangeTime(timespec); }
    53             void        GetModificationTime(struct timespec &timespec) const
    54                             { fNode.GetModificationTime(timespec); }
    55             void        GetCreationTime(struct timespec &timespec) const
    56                             { fNode.GetCreationTime(timespec); }
    57             void        GetAccessTime(struct timespec &timespec) 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);
    7168private:
    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;
    8682};
    8783
    8884
    public:  
    9894    {
    9995        SetTo(volume, id);
    10096    }
    101 
     97   
    10298    Vnode()
    10399        :
    104100        fStatus(B_NO_INIT),
    105101        fInode(NULL)
    106102    {
    107103    }
    108 
     104   
    109105    ~Vnode()
    110106    {
    111107        Unset();
    112108    }
    113 
     109   
    114110    status_t InitCheck()
    115111    {
    116112        return fStatus;
    117113    }
    118 
     114   
    119115    void Unset()
    120116    {
    121117        if (fInode != NULL) {
    public:  
    124120            fStatus = B_NO_INIT;
    125121        }
    126122    }
    127 
     123   
    128124    status_t SetTo(Volume* volume, ino_t id)
    129125    {
    130126        Unset();
    131 
    132127        return fStatus = get_vnode(volume->FSVolume(), id, (void**)&fInode);
    133128    }
    134 
     129   
    135130    status_t Get(Inode** _inode)
    136131    {
    137132        *_inode = fInode;
    138133        return fStatus;
    139134    }
    140 
     135   
    141136    void Keep()
    142137    {
    143138        TRACEI("Vnode::Keep()\n");
    public:  
    146141
    147142private:
    148143    status_t    fStatus;
    149     Inode*      fInode;
     144    Inode*  fInode;
    150145};
    151146
    152147#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  
    1010
    1111
    1212enum inode_type {
    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 
     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   
    2121    S_EXTENDED_TYPES = (S_ATTR_DIR | S_ATTR | S_INDEX_DIR)
    2222};
    2323
    open_mode_to_access(int openMode)  
    3838    return R_OK | W_OK;
    3939}
    4040
     41
    4142#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  
    99
    1010
    1111#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 
    2412#include "BPlusTree.h"
    2513#include "CachedBlock.h"
    2614#include "Chunk.h"
     
    3826
    3927class DeviceOpener {
    4028public:
    41                                 DeviceOpener(int fd, int mode);
    42                                 DeviceOpener(const char* device, int mode);
    43                                 ~DeviceOpener();
     29    DeviceOpener(int fd, int mode);
     30    DeviceOpener(const char* device, int mode);
     31    ~DeviceOpener();
    4432
    45             int                 Open(const char* device, int mode);
    46             int                 Open(int fd, int mode);
    47             void*               InitCache(off_t numBlocks, uint32 blockSize);
    48             void                RemoveCache(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);
    4937
    50             void                Keep();
     38    void    Keep();
    5139
    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); }
    5643
    57             status_t            GetSize(off_t* _size, uint32* _blockSize = NULL);
     44    status_t    GetSize(off_t* _size, uint32* _blockSize = NULL);
    5845
    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;}
    6449
    65             int                 fDevice;
    66             int                 fMode;
    67             void*               fBlockCache;
     50    int fDevice;
     51    int fMode;
     52    void*   fBlockCache;
    6853};
    6954
    7055
    void*  
    142127DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize)
    143128{
    144129    return fBlockCache = block_cache_create(fDevice, numBlocks, blockSize,
    145         IsReadOnly());
     130            IsReadOnly());
    146131}
    147132
    148133
    DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)  
    187172
    188173    if (_size) {
    189174        *_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;
    191176    }
    192177    if (_blockSize)
    193178        *_blockSize = geometry.bytes_per_sector;
    btrfs_super_block::IsValid()  
    205190    // TODO: check some more values!
    206191    if (strncmp(magic, BTRFS_SUPER_BLOCK_MAGIC, sizeof(magic)) != 0)
    207192        return false;
    208    
     193
    209194    return true;
    210195}
    211196
    Volume::Volume(fs_volume* volume)  
    219204    fFlags(0),
    220205    fChunk(NULL),
    221206    fChunkTree(NULL)
    222 {
     207    {
    223208    mutex_init(&fLock, "btrfs volume");
    224209}
    225210
    Volume::Name() const  
    249234
    250235status_t
    251236Volume::Mount(const char* deviceName, uint32 flags)
    252 {
     237    {
    253238    flags |= B_MOUNT_READ_ONLY;
    254         // we only support read-only for now
    255    
     239    // we only support read-only for now
     240
    256241    if ((flags & B_MOUNT_READ_ONLY) != 0) {
    257242        TRACE("Volume::Mount(): Read only\n");
    258243    } else {
    Volume::Mount(const char* deviceName, uint32 flags)  
    276261        ERROR("Volume::Mount(): Identify() failed\n");
    277262        return status;
    278263    }
    279    
     264
    280265    fBlockSize = fSuperBlock.BlockSize();
    281266    TRACE("block size %" B_PRIu32 "\n", fBlockSize);
    282267
    Volume::Mount(const char* deviceName, uint32 flags)  
    290275        if (key->Type() != BTRFS_KEY_TYPE_CHUNK_ITEM) {
    291276            break;
    292277        }
    293        
     278
    294279        struct btrfs_chunk* chunk = (struct btrfs_chunk*)(key + 1);
    295280        fChunk = new(std::nothrow) Chunk(chunk, key->Offset());
    296281        if (fChunk == NULL)
    Volume::Mount(const char* deviceName, uint32 flags)  
    310295    FindBlock(fSuperBlock.LogRoot(), physical);
    311296    TRACE("Volume::Mount() log_root: %" B_PRIu64 " (physical %" B_PRIu64 ")\n",
    312297        fSuperBlock.LogRoot(), physical);
    313        
     298
    314299    // check if the device size is large enough to hold the file system
    315300    off_t diskSize;
    316301    status = opener.GetSize(&diskSize);
    Volume::Mount(const char* deviceName, uint32 flags)  
    323308        fBlockSize);
    324309    if (fBlockCache == NULL)
    325310        return B_ERROR;
    326    
     311
    327312    TRACE("Volume::Mount(): Initialized block cache: %p\n", fBlockCache);
    328313
    329314    fChunkTree = new(std::nothrow) BPlusTree(this, fSuperBlock.ChunkRoot());
    Volume::Mount(const char* deviceName, uint32 flags)  
    348333    search_key.SetOffset(0);
    349334    search_key.SetType(BTRFS_KEY_TYPE_ROOT_ITEM);
    350335    search_key.SetObjectID(BTRFS_OBJECT_ID_EXTENT_TREE);
    351     struct btrfs_root *root;
     336    struct btrfs_root* root;
    352337    if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) {
    353338        ERROR("Volume::Mount(): Couldn't find extent root\n");
    354339        return B_ERROR;
    Volume::Mount(const char* deviceName, uint32 flags)  
    359344    free(root);
    360345    if (fExtentTree == NULL)
    361346        return B_NO_MEMORY;
    362    
     347
    363348    search_key.SetOffset(0);
    364349    search_key.SetObjectID(BTRFS_OBJECT_ID_FS_TREE);
    365350    if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) {
    Volume::Mount(const char* deviceName, uint32 flags)  
    371356    free(root);
    372357    if (fFSTree == NULL)
    373358        return B_NO_MEMORY;
    374    
     359
    375360    search_key.SetOffset(0);
    376361    search_key.SetObjectID(BTRFS_OBJECT_ID_DEV_TREE);
    377362    if (fRootTree->FindNext(search_key, (void**)&root) != B_OK) {
    Volume::Mount(const char* deviceName, uint32 flags)  
    397382    free(root);
    398383    if (fChecksumTree == NULL)
    399384        return B_NO_MEMORY;
    400    
     385
    401386    // ready
    402387    status = get_vnode(fFSVolume, BTRFS_OBJECT_ID_CHUNK_TREE,
    403388        (void**)&fRootNode);
    Volume::Mount(const char* deviceName, uint32 flags)  
    426411        }
    427412
    428413        double size = double((10 * diskSize + divisor - 1) / divisor);
    429             // %g in the kernel does not support precision...
     414        // %g in the kernel does not support precision...
    430415
    431416        snprintf(fName, sizeof(fName), "%g %cB Btrfs Volume",
    432417            size / 10, unit);
    Volume::LoadSuperBlock()  
    478463
    479464
    480465status_t
    481 Volume::FindBlock(off_t logical, fsblock_t &physicalBlock)
     466Volume::FindBlock(off_t logical, fsblock_t& physicalBlock)
    482467{
    483468    off_t physical;
    484469    status_t status = FindBlock(logical, physical);
    Volume::FindBlock(off_t logical, fsblock_t &physicalBlock)  
    490475
    491476
    492477status_t
    493 Volume::FindBlock(off_t logical, off_t &physical)
     478Volume::FindBlock(off_t logical, off_t& physical)
    494479{
    495480    if (fChunkTree == NULL
    496481        || (logical >= (off_t)fChunk->Offset()
    Volume::FindBlock(off_t logical, off_t &physical)  
    503488    search_key.SetOffset(logical);
    504489    search_key.SetType(BTRFS_KEY_TYPE_CHUNK_ITEM);
    505490    search_key.SetObjectID(BTRFS_OBJECT_ID_CHUNK_TREE);
    506     struct btrfs_chunk *chunk;
     491    struct btrfs_chunk* chunk;
    507492    size_t chunk_length;
    508493    status_t status = fChunkTree->FindPrevious(search_key, (void**)&chunk,
    509494        &chunk_length);
    Volume::FindBlock(off_t logical, off_t &physical)  
    514499    free(chunk);
    515500    status = _chunk.FindBlock(logical, physical);
    516501    if (status != B_OK)
    517             return status;
     502        return status;
    518503    TRACE("Volume::FindBlock(): logical: %" B_PRIdOFF ", physical: %" B_PRIdOFF
    519504        "\n", logical, physical);
    520505    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  
    77#define VOLUME_H
    88
    99
    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
    1123
    1224#include "btrfs.h"
    1325
    1426
    1527enum volume_flags {
    16     VOLUME_READ_ONLY    = 0x0001
     28    VOLUME_READ_ONLY = 0x0001
    1729};
    1830
     31
    1932class BPlusTree;
    2033class Chunk;
    2134class Inode;
    class Inode;  
    2336
    2437class Volume {
    2538public:
    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();
    3141
    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();
    3544
    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; }
    3848
    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; }
    4551
    46             uint32              BlockSize() const { return fBlockSize; }
    47             btrfs_super_block&  SuperBlock() { return fSuperBlock; }
     52    dev_t   ID() const
     53                { return fFSVolume ? fFSVolume->id : -1; }
    4854
    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();
    5062
    51             // cache access
    52             void*               BlockCache() { return fBlockCache; }
     63    // cache access
     64    void*   BlockCache() { return fBlockCache; }
    5365
    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);
    5869
    5970private:
    60             mutex               fLock;
    61             fs_volume*          fFSVolume;
    62             int                 fDevice;
    63             btrfs_super_block   fSuperBlock;
    64             char                fName[32];
    65 
    66             uint32              fFlags;
    67             uint32              fBlockSize;
    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;
    7990};
    8091
     92
    8193#endif  // VOLUME_H
    8294
  • 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  
    66#define BTRFS_H
    77
    88
    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
    1017
    11 #include <ByteOrder.h>
    12 #include <fs_interface.h>
    13 #include <KernelExport.h>
    1418
    15 
    16 typedef uint64 fileblock_t;     // file block number
    17 typedef uint64 fsblock_t;       // filesystem block number
     19typedef uint64 fileblock_t; // file block number
     20typedef uint64 fsblock_t;   // filesystem block number
    1821
    1922
    2023#define BTRFS_SUPER_BLOCK_OFFSET    0x10000
    struct btrfs_key {  
    2326    uint64  object_id;
    2427    uint8   type;
    2528    uint64  offset;
    26    
    2729    uint64  ObjectID() const { return B_LENDIAN_TO_HOST_INT64(object_id); }
    2830    uint8   Type() const { return type; }
    2931    uint64  Offset() const { return B_LENDIAN_TO_HOST_INT64(offset); }
    struct btrfs_key {  
    3234    void SetOffset(uint64 off) { offset = B_HOST_TO_LENDIAN_INT64(off); }
    3335} _PACKED;
    3436
     37
    3538struct btrfs_timespec {
    3639    uint64  seconds;
    3740    uint32  nanoseconds;
    3841} _PACKED;
    3942
     43
    4044struct btrfs_header {
    4145    uint8   checksum[32];
    4246    uint8   fsid[16];
    struct btrfs_header {  
    5054    uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); }
    5155    uint64 Flags() const { return B_LENDIAN_TO_HOST_INT64(flags); }
    5256    uint64 Generation() const {
    53         return B_LENDIAN_TO_HOST_INT64(generation); }
     57            return B_LENDIAN_TO_HOST_INT64(generation); }
    5458    uint64 Owner() const {
    55         return B_LENDIAN_TO_HOST_INT64(owner); }
     59            return B_LENDIAN_TO_HOST_INT64(owner); }
    5660    uint32 ItemCount() const {
    57         return B_LENDIAN_TO_HOST_INT32(item_count); }
     61            return B_LENDIAN_TO_HOST_INT32(item_count); }
    5862    uint8 Level() const { return level; }
    5963} _PACKED;
    6064
     65
    6166struct btrfs_index {
    6267    btrfs_key key;
    6368    uint64  blocknum;
    6469    uint64  generation;
    6570    uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); }
    6671    uint64 Generation() const {
    67         return B_LENDIAN_TO_HOST_INT64(generation); }
     72            return B_LENDIAN_TO_HOST_INT64(generation); }
    6873} _PACKED;
    6974
     75
    7076struct btrfs_entry {
    7177    btrfs_key key;
    7278    uint32 offset;
    7379    uint32 size;
    7480    uint32 Offset() const {
    75         return B_LENDIAN_TO_HOST_INT32(offset); }
     81            return B_LENDIAN_TO_HOST_INT32(offset); }
    7682    uint32 Size() const {
    77         return B_LENDIAN_TO_HOST_INT32(size); }
     83            return B_LENDIAN_TO_HOST_INT32(size); }
    7884} _PACKED;
    7985
     86
    8087struct btrfs_stream {
    8188    btrfs_header header;
    8289    union {
    struct btrfs_stream {  
    8592    };
    8693} _PACKED;
    8794
     95
    8896struct btrfs_stripe {
    8997    uint64  device_id;
    9098    uint64  offset;
    struct btrfs_stripe {  
    93101    uint64  Offset() const { return B_LENDIAN_TO_HOST_INT64(offset); }
    94102} _PACKED;
    95103
     104
    96105struct btrfs_chunk {
    97106    uint64  length;
    98107    uint64  owner;
    struct btrfs_chunk {  
    107116    uint64 Length() const { return B_LENDIAN_TO_HOST_INT64(length); }
    108117    uint64 Owner() const { return B_LENDIAN_TO_HOST_INT64(owner); }
    109118    uint64 StripeLength() const
    110         { return B_LENDIAN_TO_HOST_INT64(stripe_length); }
     119            { return B_LENDIAN_TO_HOST_INT64(stripe_length); }
    111120    uint64 Type() const { return B_LENDIAN_TO_HOST_INT64(type); }
    112121    uint32 IOAlign() const { return B_LENDIAN_TO_HOST_INT32(io_align); }
    113122    uint32 IOWidth() const { return B_LENDIAN_TO_HOST_INT32(io_width); }
    114123    uint32 SectorSize() const
    115         { return B_LENDIAN_TO_HOST_INT32(sector_size); }
     124            { return B_LENDIAN_TO_HOST_INT32(sector_size); }
    116125    uint16 StripeCount() const
    117         { return B_LENDIAN_TO_HOST_INT16(stripe_count); }
     126            { return B_LENDIAN_TO_HOST_INT16(stripe_count); }
    118127    uint16 SubStripes() const
    119         { return B_LENDIAN_TO_HOST_INT16(sub_stripes); }
     128            { return B_LENDIAN_TO_HOST_INT16(sub_stripes); }
    120129} _PACKED;
    121130
     131
    122132struct btrfs_device {
    123133    uint64  id;
    124134    uint64  total_size;
    struct btrfs_super_block {  
    171181    uint8   system_chunk_array[2048];
    172182
    173183    bool IsValid();
    174         // implemented in Volume.cpp
     184            // implemented in Volume.cpp
    175185    uint64 TotalSize() const { return B_LENDIAN_TO_HOST_INT64(total_size); }
    176186    uint32 BlockSize() const { return B_LENDIAN_TO_HOST_INT32(sector_size); }
    177187    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); }
    179189    uint64 Generation() const {
    180         return B_LENDIAN_TO_HOST_INT64(generation); }
     190            return B_LENDIAN_TO_HOST_INT64(generation); }
    181191    uint64 Root() const {
    182         return B_LENDIAN_TO_HOST_INT64(root); }
     192            return B_LENDIAN_TO_HOST_INT64(root); }
    183193    uint64 ChunkRoot() const {
    184         return B_LENDIAN_TO_HOST_INT64(chunk_root); }
     194            return B_LENDIAN_TO_HOST_INT64(chunk_root); }
    185195    uint64 LogRoot() const {
    186         return B_LENDIAN_TO_HOST_INT64(log_root); }
     196            return B_LENDIAN_TO_HOST_INT64(log_root); }
    187197    uint8 ChunkRootLevel() const { return chunk_root_level; }
    188198} _PACKED;
    189199
     200
    190201struct btrfs_inode {
    191202    uint64  generation;
    192203    uint64  transaction_id;
    struct btrfs_inode {  
    212223    uint32 Mode() const { return B_LENDIAN_TO_HOST_INT32(mode); }
    213224    uint64 Flags() const { return B_LENDIAN_TO_HOST_INT64(flags); }
    214225    uint64 Sequence() const { return B_LENDIAN_TO_HOST_INT64(sequence); }
    215     static void _DecodeTime(struct timespec &timespec,
    216         const struct btrfs_timespec &time)
     226    static void _DecodeTime(struct timespec& timespec,
     227        const struct btrfs_timespec& time)
    217228    {
    218229        timespec.tv_sec = B_LENDIAN_TO_HOST_INT64(time.seconds);
    219230        timespec.tv_nsec = B_LENDIAN_TO_HOST_INT32(time.nanoseconds);
    220231    }
    221     void GetAccessTime(struct timespec &timespec) const
    222         { _DecodeTime(timespec, access_time); }
    223     void GetChangeTime(struct timespec &timespec) const
    224         { _DecodeTime(timespec, change_time); }
    225     void GetModificationTime(struct timespec &timespec) const
    226         { _DecodeTime(timespec, modification_time); }
    227     void GetCreationTime(struct timespec &timespec) const
    228         { _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); }
    229240} _PACKED;
    230241
     242
    231243struct btrfs_root {
    232244    btrfs_inode inode;
    233245    uint64  generation;
    struct btrfs_root {  
    242254    uint8   drop_level;
    243255    uint8   level;
    244256    uint64 Generation() const {
    245         return B_LENDIAN_TO_HOST_INT64(generation); }
     257            return B_LENDIAN_TO_HOST_INT64(generation); }
    246258    uint64 BlockNum() const { return B_LENDIAN_TO_HOST_INT64(blocknum); }
    247259} _PACKED;
    248260
     261
    249262struct btrfs_dir_entry {
    250263    btrfs_key location;
    251264    uint64  transaction_id;
    struct btrfs_dir_entry {  
    256269    uint16 NameLength() const { return B_LENDIAN_TO_HOST_INT16(name_length); }
    257270    ino_t InodeID() const { return location.ObjectID(); }
    258271    uint16 Length() const
    259         { return sizeof(*this) + NameLength() + DataLength(); }
     272            { return sizeof(*this) + NameLength() + DataLength(); }
    260273} _PACKED;
    261274
     275
    262276struct btrfs_extent_data {
    263277    uint64  generation;
    264278    uint64  memory_size;
    struct btrfs_extent_data {  
    276290        uint8 inline_data[0];
    277291    };
    278292    uint64 Generation() const {
    279         return B_LENDIAN_TO_HOST_INT64(generation); }
     293            return B_LENDIAN_TO_HOST_INT64(generation); }
    280294    uint64 MemoryBytes() const {
    281         return B_LENDIAN_TO_HOST_INT64(memory_size); }
     295            return B_LENDIAN_TO_HOST_INT64(memory_size); }
    282296    uint8 Compression() const { return compression; }
    283297    uint8 Type() const { return type; }
    284298    uint64 DiskOffset() const {
    285         return B_LENDIAN_TO_HOST_INT64(disk_offset); }
     299            return B_LENDIAN_TO_HOST_INT64(disk_offset); }
    286300    uint64 DiskSize() const {
    287         return B_LENDIAN_TO_HOST_INT64(disk_size); }
     301            return B_LENDIAN_TO_HOST_INT64(disk_size); }
    288302    uint64 ExtentOffset() const {
    289         return B_LENDIAN_TO_HOST_INT64(extent_offset); }
     303            return B_LENDIAN_TO_HOST_INT64(extent_offset); }
    290304    uint64 Size() const {
    291         return B_LENDIAN_TO_HOST_INT64(size); }
     305            return B_LENDIAN_TO_HOST_INT64(size); }
    292306} _PACKED;
    293307
    294308
  • 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  
    77
    88/*! \file crc_table.cpp
    99
    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.
    1512
    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
    1717*/
    1818
    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
    2126
    2227typedef unsigned int uint32 ;
    2328
    reflect32 (uint32 b)  
    3641
    3742
    3843int
    39 main(int argc, char *argv[]) {
    40         uint32 crc, poly;
     44main(int argc, char* argv[]) {
     45    uint32 crc, poly;
    4146
    42         if (argc != 2) {
    43                 fprintf(stderr, "USAGE: crc_table <octal polynomial=3667067501 for btrfs>\n");
    44                 return 0;
    45         }
     47    if (argc != 2) {
     48        fprintf(stderr, "USAGE: crc_table <octal polynomial=3667067501 for btrfs>\n");
     49        return 0;
     50    }
    4651
    47         sscanf(argv[1], "%lo", &poly);
    48       
    49         printf("//! CRC 0%o table, as generated by crc_table.cpp\n", poly);
    50         printf("static uint32 crc_table[256] = { \n");
    51         for (int n = 0; n < 256; n++) {
    52                 if (n%8 == 0)
    53                         printf("    ");
    54                 crc = reflect32(n);
    55                 for (int i = 0; i < 8; i++) {
    56                         if (crc & 0x80000000)
    57                                 crc = (crc << 1) ^ poly;
    58                         else
    59                                 crc <<= 1;
    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        }
    6166        crc = reflect32(crc);
    62                 printf("0x%08x%s ", crc, (n != 255 ? "," : ""));
    63                 if (n%8 == 7)
    64                         printf("\n");
    65         }
    66         printf("};\n");
    67         return 0;
     67        printf("0x%08x%s ", crc, (n != 255 ? "," : ""));
     68        if (n % 8 == 7)
     69            printf("\n");
     70    }
     71    printf("};\n");
     72    return 0;
    6873}
  • 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  
    55 */
    66
    77
    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
    1822
    1923#include "Attribute.h"
    2024#include "AttributeIterator.h"
    iterative_io_finished_hook(void* cookie, io_request* request, status_t status,  
    6872
    6973
    7074static float
    71 btrfs_identify_partition(int fd, partition_data *partition, void **_cookie)
     75btrfs_identify_partition(int fd, partition_data* partition, void** _cookie)
    7276{
    7377    btrfs_super_block superBlock;
    7478    status_t status = Volume::Identify(fd, &superBlock);
    7579    if (status != B_OK)
    7680        return -1;
    7781
    78     identify_cookie *cookie = new identify_cookie;
     82    identify_cookie* cookie = new identify_cookie;
    7983    memcpy(&cookie->super_block, &superBlock, sizeof(btrfs_super_block));
    8084
    8185    *_cookie = cookie;
    btrfs_identify_partition(int fd, partition_data *partition, void **_cookie)  
    8488
    8589
    8690static status_t
    87 btrfs_scan_partition(int fd, partition_data *partition, void *_cookie)
     91btrfs_scan_partition(int fd, partition_data* partition, void* _cookie)
    8892{
    89     identify_cookie *cookie = (identify_cookie *)_cookie;
     93    identify_cookie* cookie = (identify_cookie*)_cookie;
    9094
    9195    partition->status = B_PARTITION_VALID;
    9296    partition->flags |= B_PARTITION_FILE_SYSTEM;
    btrfs_mount(fs_volume* _volume, const char* device, uint32 flags,  
    138142
    139143
    140144static status_t
    141 btrfs_unmount(fs_volume *_volume)
     145btrfs_unmount(fs_volume* _volume)
    142146{
    143     Volume* volume = (Volume *)_volume->private_volume;
     147    Volume* volume = (Volume*)_volume->private_volume;
    144148
    145149    status_t status = volume->Unmount();
    146150    delete volume;
    btrfs_read(fs_volume* _volume, fs_vnode* _node, void* _cookie, off_t pos,  
    452456
    453457
    454458static status_t
    455 btrfs_close(fs_volume *_volume, fs_vnode *_node, void *_cookie)
     459btrfs_close(fs_volume* _volume, fs_vnode* _node, void* _cookie)
    456460{
    457461    return B_OK;
    458462}
    btrfs_access(fs_volume* _volume, fs_vnode* _node, int accessMode)  
    482486
    483487
    484488static status_t
    485 btrfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer,
    486     size_t *_bufferSize)
     489btrfs_read_link(fs_volume* _volume, fs_vnode* _node, char* buffer,
     490    size_t* _bufferSize)
    487491{
    488492    Inode* inode = (Inode*)_node->private_node;
    489493    return inode->ReadAt(0, (uint8*)buffer, _bufferSize);
    btrfs_open_dir(fs_volume* /*_volume*/, fs_vnode* _node, void** _cookie)  
    516520
    517521
    518522static status_t
    519 btrfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
    520     struct dirent *dirent, size_t bufferSize, uint32 *_num)
     523btrfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
     524    struct dirent* dirent, size_t bufferSize, uint32* _num)
    521525{
    522526    DirectoryIterator* iterator = (DirectoryIterator*)_cookie;
    523527    Volume* volume = (Volume*)_volume->private_volume;
    btrfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie,  
    560564
    561565
    562566static status_t
    563 btrfs_rewind_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void *_cookie)
     567btrfs_rewind_dir(fs_volume* /*_volume*/, fs_vnode* /*node*/, void* _cookie)
    564568{
    565569    DirectoryIterator* iterator = (DirectoryIterator*)_cookie;
    566570
    btrfs_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void * /*_cookie*/  
    576580
    577581
    578582static status_t
    579 btrfs_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)
     583btrfs_free_dir_cookie(fs_volume* _volume, fs_vnode* _node, void* _cookie)
    580584{
    581585    delete (DirectoryIterator*)_cookie;
    582586    return B_OK;
    btrfs_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)  
    584588
    585589
    586590static status_t
    587 btrfs_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie)
     591btrfs_open_attr_dir(fs_volume* _volume, fs_vnode* _node, void** _cookie)
    588592{
    589593    Inode* inode = (Inode*)_node->private_node;
    590594    TRACE("%s()\n", __FUNCTION__);
    static file_system_module_info sBtrfsFileSystem = {  
    859863};
    860864
    861865
    862 module_info *modules[] = {
    863     (module_info *)&sBtrfsFileSystem,
     866module_info* modules[] = {
     867    (module_info*)&sBtrfsFileSystem,
    864868    NULL,
    865869};