2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
4 * Copyright 2014 Haiku, Inc. All rights reserved.
6 * Distributed under the terms of the MIT License.
9 * Axel Dörfler, axeld@pinc-software.de
10 * Jérôme Duval, korli@users.berlios.de
11 * John Scipione, jscipione@gmail.com
20 #include <StorageDefs.h>
23 #include "SplayTree.h"
35 SplayTreeLink
<struct node
> nodeTreeLink
;
36 SplayTreeLink
<struct node
> inoTreeLink
;
40 struct NodeTreeDefinition
{
41 typedef struct node_key KeyType
;
42 typedef struct node NodeType
;
44 static KeyType
GetKey(const NodeType
* node
)
49 static SplayTreeLink
<NodeType
>* GetLink(NodeType
* node
)
51 return &node
->nodeTreeLink
;
54 static int Compare(KeyType key
, const NodeType
* node
)
56 if (key
.cluster
== node
->key
.cluster
) {
57 if (key
.offset
== node
->key
.offset
)
59 return key
.offset
< node
->key
.offset
? -1 : 1;
61 return key
.cluster
< node
->key
.cluster
? -1 : 1;
65 struct InoTreeDefinition
{
66 typedef ino_t KeyType
;
67 typedef struct node NodeType
;
69 static KeyType
GetKey(const NodeType
* node
)
74 static SplayTreeLink
<NodeType
>* GetLink(NodeType
* node
)
76 return &node
->inoTreeLink
;
79 static int Compare(KeyType key
, const NodeType
* node
)
82 return key
< node
->ino
? -1 : 1;
88 typedef SplayTree
<NodeTreeDefinition
> NodeTree
;
89 typedef SplayTree
<InoTreeDefinition
> InoTree
;
91 struct InodesInoTreeDefinition
;
92 typedef IteratableSplayTree
<InodesInoTreeDefinition
> InodesInoTree
;
93 struct InodesClusterTreeDefinition
;
94 typedef IteratableSplayTree
<InodesClusterTreeDefinition
> InodesClusterTree
;
98 VOLUME_READ_ONLY
= 0x0001
104 Volume(fs_volume
* volume
);
107 status_t
Mount(const char* device
, uint32 flags
);
110 bool IsValidSuperBlock();
111 bool IsReadOnly() const
112 { return (fFlags
& VOLUME_READ_ONLY
) != 0; }
114 Inode
* RootNode() const { return fRootNode
; }
115 int Device() const { return fDevice
; }
118 { return fFSVolume
? fFSVolume
->id
: -1; }
119 fs_volume
* FSVolume() const { return fFSVolume
; }
120 const char* Name() const;
121 void SetName(const char* name
)
122 { strlcpy(fName
, name
, sizeof(fName
)); }
124 uint32
BlockSize() const { return fBlockSize
; }
125 uint32
EntriesPerBlock() const
126 { return fEntriesPerBlock
; }
127 uint32
EntriesPerCluster()
128 { return fEntriesPerBlock
129 << SuperBlock().BlocksPerClusterShift(); }
130 size_t ClusterSize() { return fBlockSize
131 << SuperBlock().BlocksPerClusterShift(); }
132 exfat_super_block
& SuperBlock() { return fSuperBlock
; }
134 status_t
LoadSuperBlock();
137 void* BlockCache() { return fBlockCache
; }
139 static status_t
Identify(int fd
, exfat_super_block
* superBlock
);
141 status_t
ClusterToBlock(cluster_t cluster
,
143 Inode
* FindInode(ino_t id
);
144 Inode
* FindInode(cluster_t cluster
);
145 cluster_t
NextCluster(cluster_t cluster
);
146 ino_t
GetIno(cluster_t cluster
, uint32 offset
,
148 struct node_key
* GetNode(ino_t ino
, ino_t
&parent
);
150 ino_t
_NextID() { return fNextId
++; }
153 fs_volume
* fFSVolume
;
155 exfat_super_block fSuperBlock
;
156 char fName
[B_FILE_NAME_LENGTH
];
160 uint32 fEntriesPerBlock
;
165 InodesInoTree
* fInodesInoTree
;
166 InodesClusterTree
* fInodesClusterTree
;