1 #ifndef INODE_H 2 #define INODE_H 3 /* Inode - emulation for the B+Tree torture test 4 ** 5 ** Initial version by Axel Dörfler, axeld@pinc-software.de 6 ** This file may be used under the terms of the OpenBeOS License. 7 */ 8 9 10 #include <SupportDefs.h> 11 #include <File.h> 12 13 #include "bfs.h" 14 #include "Utility.h" 15 16 17 #define ASSERT_READ_LOCKED_INODE(inode) inode->AssertReadLocked() 18 #define ASSERT_WRITE_LOCKED_INODE(inode) inode->AssertWriteLocked() 19 20 21 class Volume; 22 class Transaction; 23 24 25 class Inode { 26 public: 27 Inode(const char* name, int32 mode = S_STR_INDEX | S_ALLOW_DUPS); 28 ~Inode(); 29 30 rw_lock& Lock() { return fLock; } 31 32 status_t FindBlockRun(off_t pos, block_run& run, off_t& offset); 33 status_t Append(Transaction&, off_t bytes); 34 status_t SetFileSize(Transaction&, off_t bytes); 35 36 Volume* GetVolume() const { return fVolume; } 37 off_t ID() const { return 0; } 38 int32 Mode() const { return fMode; } 39 const char* Name() const { return "whatever"; } 40 block_run BlockRun() const { return block_run::Run(0, 0, 0); } 41 block_run Parent() const { return block_run::Run(0, 0, 0); } 42 off_t BlockNumber() const { return 0; } 43 bfs_inode* Node() { return (bfs_inode*)1; } 44 45 off_t Size() const { return fSize; } 46 bool IsContainer() const { return true; } 47 bool IsDirectory() const { return true; } 48 bool IsIndex() const { return is_index(Mode()); } 49 50 void AssertReadLocked() { ASSERT_READ_LOCKED_RW_LOCK(&fLock); } 51 void AssertWriteLocked() { ASSERT_WRITE_LOCKED_RW_LOCK(&fLock); } 52 53 private: 54 friend void dump_inode(Inode& inode); 55 56 Volume* fVolume; 57 BFile fFile; 58 off_t fSize; 59 rw_lock fLock; 60 int32 fMode; 61 62 // for dump_inode() only: 63 off_t fOldSize; 64 off_t fOldLastModified; 65 off_t fBlockNumber; 66 void* fTree; 67 void* fAttributes; 68 }; 69 70 71 class InodeReadLocker { 72 public: 73 InodeReadLocker(Inode* inode) 74 : 75 fLock(&inode->Lock()) 76 { 77 rw_lock_read_lock(fLock); 78 } 79 80 ~InodeReadLocker() 81 { 82 if (fLock != NULL) 83 rw_lock_read_unlock(fLock); 84 } 85 86 void Unlock() 87 { 88 if (fLock != NULL) { 89 rw_lock_read_unlock(fLock); 90 fLock = NULL; 91 } 92 } 93 94 private: 95 rw_lock* fLock; 96 }; 97 98 #endif /* INODE_H */ 99