1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef VOLUME_H
6 #define VOLUME_H
7
8
9 #include <fs_info.h>
10 #include <fs_interface.h>
11 #include <fs_volume.h>
12
13 #include <lock.h>
14
15
16 class BlockAllocator;
17 class Directory;
18 class File;
19 class Node;
20 class SymLink;
21 class Transaction;
22
23
24 class Volume {
25 public:
26 Volume(uint32 flags);
27 ~Volume();
28
29 status_t Init(const char* device);
30 status_t Init(int fd, uint64 totalBlocks);
31
32 status_t Mount(fs_volume* fsVolume);
33 void Unmount();
34
35 status_t Initialize(const char* name);
36
37 void GetInfo(fs_info& info);
38
39 status_t NewNode(Node* node);
40 status_t PublishNode(Node* node, uint32 flags);
41 status_t GetNode(uint64 blockIndex, Node*& _node);
42 status_t PutNode(Node* node);
43 status_t RemoveNode(Node* node);
44 status_t UnremoveNode(Node* node);
45
46 status_t ReadNode(uint64 blockIndex, Node*& _node);
47
48 status_t CreateDirectory(mode_t mode,
49 Transaction& transaction,
50 Directory*& _directory);
51 status_t CreateFile(mode_t mode,
52 Transaction& transaction, File*& _file);
53 status_t CreateSymLink(mode_t mode,
54 Transaction& transaction,
55 SymLink*& _symLink);
56 status_t DeleteNode(Node* node);
57
58 status_t SetName(const char* name);
59
60 inline void TransactionStarted();
61 inline void TransactionFinished();
62
ID()63 inline dev_t ID() const { return fFSVolume->id; }
FD()64 inline int FD() const { return fFD; }
65 inline bool IsReadOnly() const;
TotalBlocks()66 inline uint64 TotalBlocks() const { return fTotalBlocks; }
BlockCache()67 inline void* BlockCache() const { return fBlockCache; }
Name()68 inline const char* Name() const { return fName; }
GetBlockAllocator()69 inline BlockAllocator* GetBlockAllocator() const
70 { return fBlockAllocator; }
RootDirectory()71 inline Directory* RootDirectory() const
72 { return fRootDirectory; }
73
74 private:
75 status_t _Init(uint64 totalBlocks);
76
77 status_t _CreateNode(Node* node,
78 Transaction& transaction);
79 status_t _DeleteDirectoryEntries(Directory* directory);
80
81 private:
82 fs_volume* fFSVolume;
83 int fFD;
84 uint32 fFlags;
85 void* fBlockCache;
86 uint64 fTotalBlocks;
87 char* fName;
88 BlockAllocator* fBlockAllocator;
89 Directory* fRootDirectory;
90 mutex fLock;
91 mutex fTransactionLock;
92 };
93
94
95 void
TransactionStarted()96 Volume::TransactionStarted()
97 {
98 mutex_lock(&fTransactionLock);
99 }
100
101
102 void
TransactionFinished()103 Volume::TransactionFinished()
104 {
105 mutex_unlock(&fTransactionLock);
106 }
107
108
109 bool
IsReadOnly()110 Volume::IsReadOnly() const
111 {
112 return (fFlags & B_FS_IS_READONLY) != 0;
113 }
114
115
116 #endif // VOLUME_H
117