BTRFS: Implement Dereference() in Inode that remove the "name" and unlink it with...
[haiku.git] / src / add-ons / kernel / file_systems / btrfs / Inode.h
blob933a61eb3ded6ab78adb065b74a4f4945145904a
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"
12 #include "Journal.h"
13 #include "BTree.h"
16 //#define TRACE_BTRFS
17 #ifdef TRACE_BTRFS
18 # define TRACEI(x...) dprintf("\33[34mbtrfs:\33[0m " x)
19 #else
20 # define TRACEI(x...) ;
21 #endif
24 class Inode {
25 public:
26 Inode(Volume* volume, ino_t id);
27 Inode(Volume* volume, ino_t id,
28 const btrfs_inode& item);
29 ~Inode();
31 status_t InitCheck();
33 ino_t ID() const { return fID; }
35 rw_lock* Lock() { return& fLock; }
37 status_t UpdateNodeFromDisk();
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;
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); }
60 Volume* GetVolume() const { return fVolume; }
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);
67 void* FileCache() const { return fCache; }
68 void* Map() const { return fMap; }
70 status_t FindParent(ino_t* id);
71 uint64 FindNextIndex(BTree::Path* path) const;
72 static Inode* Create(Transaction& transaction, ino_t id,
73 Inode* parent, int32 mode, uint64 size = 0,
74 uint64 flags = 0);
75 status_t Insert(Transaction& transaction, BTree::Path* path);
76 status_t Remove(Transaction& transaction, BTree::Path* path);
77 status_t MakeReference(Transaction& transaction, BTree::Path* path,
78 Inode* parent, const char* name, int32 mode);
79 status_t Dereference(Transaction& transaction, BTree::Path* path,
80 ino_t parentID, const char* name);
81 private:
82 Inode(Volume* volume);
83 Inode(const Inode&);
84 Inode& operator=(const Inode&);
85 // no implementation
87 uint64 _NumBlocks();
88 private:
90 rw_lock fLock;
91 ::Volume* fVolume;
92 ino_t fID;
93 void* fCache;
94 void* fMap;
95 status_t fInitStatus;
96 btrfs_inode fNode;
100 // The Vnode class provides a convenience layer upon get_vnode(), so that
101 // you don't have to call put_vnode() anymore, which may make code more
102 // readable in some cases
104 class Vnode {
105 public:
106 Vnode(Volume* volume, ino_t id)
108 fInode(NULL)
110 SetTo(volume, id);
113 Vnode()
115 fStatus(B_NO_INIT),
116 fInode(NULL)
120 ~Vnode()
122 Unset();
125 status_t InitCheck()
127 return fStatus;
130 void Unset()
132 if (fInode != NULL) {
133 put_vnode(fInode->GetVolume()->FSVolume(), fInode->ID());
134 fInode = NULL;
135 fStatus = B_NO_INIT;
139 status_t SetTo(Volume* volume, ino_t id)
141 Unset();
143 return fStatus = get_vnode(volume->FSVolume(), id, (void**)&fInode);
146 status_t Get(Inode** _inode)
148 *_inode = fInode;
149 return fStatus;
152 void Keep()
154 TRACEI("Vnode::Keep()\n");
155 fInode = NULL;
158 private:
159 status_t fStatus;
160 Inode* fInode;
164 #endif // INODE_H