BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / add-ons / kernel / file_systems / btrfs / Inode.h
blob003baf43224d7b93933c0fbd39b99bb6ac9422e2
1 /*
2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
4 * This file may be used under the terms of the MIT License.
5 */
6 #ifndef INODE_H
7 #define INODE_H
10 #include "btrfs.h"
11 #include "Volume.h"
14 //#define TRACE_BTRFS
15 #ifdef TRACE_BTRFS
16 # define TRACEI(x...) dprintf("\33[34mbtrfs:\33[0m " x)
17 #else
18 # define TRACEI(x...) ;
19 #endif
22 class Inode {
23 public:
24 Inode(Volume* volume, ino_t id);
25 ~Inode();
27 status_t InitCheck();
29 ino_t ID() const { return fID; }
31 rw_lock* Lock() { return& fLock; }
33 status_t UpdateNodeFromDisk();
35 bool IsDirectory() const
36 { return S_ISDIR(Mode()); }
37 bool IsFile() const
38 { return S_ISREG(Mode()); }
39 bool IsSymLink() const
40 { return S_ISLNK(Mode()); }
41 status_t CheckPermissions(int accessMode) const;
43 mode_t Mode() const { return fNode.Mode(); }
44 off_t Size() const { return fNode.Size(); }
45 uid_t UserID() const { return fNode.UserID(); }
46 gid_t GroupID() const { return fNode.GroupID(); }
47 void GetChangeTime(struct timespec& timespec) const
48 { fNode.GetChangeTime(timespec); }
49 void GetModificationTime(struct timespec& timespec) const
50 { fNode.GetModificationTime(timespec); }
51 void GetCreationTime(struct timespec& timespec) const
52 { fNode.GetCreationTime(timespec); }
53 void GetAccessTime(struct timespec& timespec) const
54 { fNode.GetCreationTime(timespec); }
56 Volume* GetVolume() const { return fVolume; }
58 status_t FindBlock(off_t logical, off_t& physical,
59 off_t* _length = NULL);
60 status_t ReadAt(off_t pos, uint8* buffer, size_t* length);
61 status_t FillGapWithZeros(off_t start, off_t end);
63 void* FileCache() const { return fCache; }
64 void* Map() const { return fMap; }
66 status_t FindParent(ino_t* id);
67 private:
68 Inode(Volume* volume);
69 Inode(const Inode&);
70 Inode& operator=(const Inode&);
71 // no implementation
73 uint64 _NumBlocks();
75 rw_lock fLock;
76 ::Volume* fVolume;
77 ino_t fID;
78 void* fCache;
79 void* fMap;
80 status_t fInitStatus;
81 btrfs_inode fNode;
85 // The Vnode class provides a convenience layer upon get_vnode(), so that
86 // you don't have to call put_vnode() anymore, which may make code more
87 // readable in some cases
89 class Vnode {
90 public:
91 Vnode(Volume* volume, ino_t id)
93 fInode(NULL)
95 SetTo(volume, id);
98 Vnode()
100 fStatus(B_NO_INIT),
101 fInode(NULL)
105 ~Vnode()
107 Unset();
110 status_t InitCheck()
112 return fStatus;
115 void Unset()
117 if (fInode != NULL) {
118 put_vnode(fInode->GetVolume()->FSVolume(), fInode->ID());
119 fInode = NULL;
120 fStatus = B_NO_INIT;
124 status_t SetTo(Volume* volume, ino_t id)
126 Unset();
128 return fStatus = get_vnode(volume->FSVolume(), id, (void**)&fInode);
131 status_t Get(Inode** _inode)
133 *_inode = fInode;
134 return fStatus;
137 void Keep()
139 TRACEI("Vnode::Keep()\n");
140 fInode = NULL;
143 private:
144 status_t fStatus;
145 Inode* fInode;
149 #endif // INODE_H