1bf31ee39SPawel Dziepak /* 2bf31ee39SPawel Dziepak * Copyright 2012 Haiku, Inc. All rights reserved. 3bf31ee39SPawel Dziepak * Distributed under the terms of the MIT License. 4bf31ee39SPawel Dziepak * 5bf31ee39SPawel Dziepak * Authors: 6bf31ee39SPawel Dziepak * Paweł Dziepak, pdziepak@quarnos.org 7bf31ee39SPawel Dziepak */ 8bf31ee39SPawel Dziepak #ifndef INODE_H 9bf31ee39SPawel Dziepak #define INODE_H 10bf31ee39SPawel Dziepak 11bf31ee39SPawel Dziepak 127efb4c9bSPawel Dziepak #include "MetadataCache.h" 130dbff361SPawel Dziepak #include "NFS4Inode.h" 14eeabdab1SPawel Dziepak #include "OpenState.h" 15bf31ee39SPawel Dziepak 16bf31ee39SPawel Dziepak 1752aaad17SPawel Dziepak class Delegation; 1852aaad17SPawel Dziepak 190dbff361SPawel Dziepak class Inode : public NFS4Inode { 20bf31ee39SPawel Dziepak public: 2100a8558cSPawel Dziepak static status_t CreateInode(FileSystem* fs, const FileInfo& fi, 220792abe0SPawel Dziepak Inode** inode); 2387c6b832SPawel Dziepak ~Inode(); 24bf31ee39SPawel Dziepak 25bf31ee39SPawel Dziepak inline ino_t ID() const; 26d38e98d8SPawel Dziepak inline mode_t Type() const; 2796b7b14aSPawel Dziepak inline const char* Name() const; 2800a8558cSPawel Dziepak inline FileSystem* GetFileSystem() const; 29bf31ee39SPawel Dziepak 3052aaad17SPawel Dziepak inline void SetOpenState(OpenState* state); 3152aaad17SPawel Dziepak 320bc98afdSPawel Dziepak inline void* FileCache(); 3313a90e37SPawel Dziepak status_t RevalidateFileCache(); 3413a90e37SPawel Dziepak 35e743e243SPawel Dziepak inline uint64 MaxFileSize(); 36e743e243SPawel Dziepak 37*4a153753SPawel Dziepak void SetDelegation(Delegation* delegation); 38*4a153753SPawel Dziepak void RecallDelegation(bool truncate = false); 39*4a153753SPawel Dziepak 400dbff361SPawel Dziepak status_t LookUp(const char* name, ino_t* id); 410dbff361SPawel Dziepak 420dbff361SPawel Dziepak status_t Access(int mode); 4375fe7b90SPawel Dziepak 4436577ed5SPawel Dziepak status_t Commit(); 4536577ed5SPawel Dziepak 460dbff361SPawel Dziepak status_t CreateObject(const char* name, const char* path, 470dbff361SPawel Dziepak int mode, FileType type); 48f5baf2efSPawel Dziepak 49f5baf2efSPawel Dziepak status_t CreateLink(const char* name, const char* path, 50f5baf2efSPawel Dziepak int mode); 51f5baf2efSPawel Dziepak 52c0de7acaSPawel Dziepak status_t Link(Inode* dir, const char* name); 53cf511f24SPawel Dziepak status_t Remove(const char* name, FileType type); 541ec6b0c1SPawel Dziepak static status_t Rename(Inode* from, Inode* to, 551ec6b0c1SPawel Dziepak const char* fromName, const char* toName); 56abba2fddSPawel Dziepak 57212de720SPawel Dziepak status_t Stat(struct stat* st); 58abba2fddSPawel Dziepak status_t WriteStat(const struct stat* st, uint32 mask); 597bfa4fe8SPawel Dziepak 6020bd3ee1SPawel Dziepak status_t Create(const char* name, int mode, int perms, 6120bd3ee1SPawel Dziepak OpenFileCookie* cookie, ino_t* id); 622a292557SPawel Dziepak status_t Open(int mode, OpenFileCookie* cookie); 6360a8140dSPawel Dziepak status_t Close(OpenFileCookie* cookie); 642f2e57d0SPawel Dziepak status_t Read(OpenFileCookie* cookie, off_t pos, 65e743e243SPawel Dziepak void* buffer, size_t* length); 66e36a5442SPawel Dziepak status_t Write(OpenFileCookie* cookie, off_t pos, 6786d2cab3SPawel Dziepak const void* buffer, size_t *_length); 682a292557SPawel Dziepak 69e743e243SPawel Dziepak status_t ReadDirect(OpenFileCookie* cookie, off_t pos, 70e743e243SPawel Dziepak void* buffer, size_t* length, bool* eof); 71e743e243SPawel Dziepak status_t WriteDirect(OpenFileCookie* cookie, off_t pos, 72e743e243SPawel Dziepak const void* buffer, size_t *_length); 73e743e243SPawel Dziepak 7469adfb6dSPawel Dziepak status_t CreateDir(const char* name, int mode); 75be4c74eaSPawel Dziepak status_t OpenDir(OpenDirCookie* cookie); 764b48348fSPawel Dziepak status_t ReadDir(void* buffer, uint32 size, 77be4c74eaSPawel Dziepak uint32* count, OpenDirCookie* cookie); 78212de720SPawel Dziepak 797d0b8c97SPawel Dziepak status_t TestLock(OpenFileCookie* cookie, 807d0b8c97SPawel Dziepak struct flock* lock); 817d0b8c97SPawel Dziepak status_t AcquireLock(OpenFileCookie* cookie, 827d0b8c97SPawel Dziepak const struct flock* lock, bool wait); 837d0b8c97SPawel Dziepak status_t ReleaseLock(OpenFileCookie* cookie, 847d0b8c97SPawel Dziepak const struct flock* lock); 857d0b8c97SPawel Dziepak status_t ReleaseAllLocks(OpenFileCookie* cookie); 867d0b8c97SPawel Dziepak 872f03ff09SPawel Dziepak protected: 880792abe0SPawel Dziepak Inode(); 890792abe0SPawel Dziepak 90eeabdab1SPawel Dziepak status_t CreateState(const char* name, int mode, 91eeabdab1SPawel Dziepak int perms, OpenState* state); 92eeabdab1SPawel Dziepak 930dbff361SPawel Dziepak status_t ReadDirUp(struct dirent* de, uint32 pos, 94ed517d6cSPawel Dziepak uint32 size); 950dbff361SPawel Dziepak status_t FillDirEntry(struct dirent* de, ino_t id, 960dbff361SPawel Dziepak const char* name, uint32 pos, uint32 size); 970dbff361SPawel Dziepak status_t GetDirSnapshot(DirectoryCacheSnapshot** 9809dbdd36SPawel Dziepak _snapshot, OpenDirCookie* cookie, 9909dbdd36SPawel Dziepak uint64* _change); 1004b48348fSPawel Dziepak 1010dbff361SPawel Dziepak status_t ChildAdded(const char* name, uint64 fileID, 102df6a5eaeSPawel Dziepak const FileHandle& fileHandle); 103df6a5eaeSPawel Dziepak 1047efb4c9bSPawel Dziepak status_t GetStat(struct stat* st); 10589f05134SPawel Dziepak 1060dbff361SPawel Dziepak static inline status_t CheckLockType(short ltype, uint32 mode); 1070dbff361SPawel Dziepak 1080dbff361SPawel Dziepak static inline ino_t FileIdToInoT(uint64 fileid); 1090dbff361SPawel Dziepak 11052aaad17SPawel Dziepak private: 1110dbff361SPawel Dziepak uint32 fType; 1124b48348fSPawel Dziepak 1137efb4c9bSPawel Dziepak MetadataCache fMetaCache; 11475fe7b90SPawel Dziepak DirectoryCache* fCache; 11513a90e37SPawel Dziepak 11652aaad17SPawel Dziepak rw_lock fDelegationLock; 11752aaad17SPawel Dziepak Delegation* fDelegation; 11852aaad17SPawel Dziepak 11913a90e37SPawel Dziepak uint64 fChange; 1200bc98afdSPawel Dziepak void* fFileCache; 12113a90e37SPawel Dziepak mutex fFileCacheLock; 122e743e243SPawel Dziepak uint64 fMaxFileSize; 123d4a75b9cSPawel Dziepak 12452aaad17SPawel Dziepak OpenState* fOpenState; 125eeabdab1SPawel Dziepak mutex fStateLock; 126eeabdab1SPawel Dziepak 127d4a75b9cSPawel Dziepak bool fWriteDirty; 128bf31ee39SPawel Dziepak }; 129bf31ee39SPawel Dziepak 130bf31ee39SPawel Dziepak 131bf31ee39SPawel Dziepak inline ino_t 1320dbff361SPawel Dziepak Inode::FileIdToInoT(uint64 fileid) 1334b48348fSPawel Dziepak { 1344b48348fSPawel Dziepak if (sizeof(ino_t) >= sizeof(uint64)) 1354b48348fSPawel Dziepak return fileid; 1364b48348fSPawel Dziepak else 1374b48348fSPawel Dziepak return (ino_t)fileid ^ (fileid >> 1384b48348fSPawel Dziepak (sizeof(uint64) - sizeof(ino_t)) * 8); 1394b48348fSPawel Dziepak } 1404b48348fSPawel Dziepak 1414b48348fSPawel Dziepak 1424b48348fSPawel Dziepak inline ino_t 143bf31ee39SPawel Dziepak Inode::ID() const 144bf31ee39SPawel Dziepak { 1450dbff361SPawel Dziepak return FileIdToInoT(fInfo.fFileId); 146bf31ee39SPawel Dziepak } 147bf31ee39SPawel Dziepak 148bf31ee39SPawel Dziepak 149d38e98d8SPawel Dziepak inline mode_t 150d38e98d8SPawel Dziepak Inode::Type() const 151d38e98d8SPawel Dziepak { 152d38e98d8SPawel Dziepak return sNFSFileTypeToHaiku[fType]; 153d38e98d8SPawel Dziepak } 154d38e98d8SPawel Dziepak 155d38e98d8SPawel Dziepak 15696b7b14aSPawel Dziepak inline const char* 15796b7b14aSPawel Dziepak Inode::Name() const 15896b7b14aSPawel Dziepak { 159a28e8732SPawel Dziepak return fInfo.fName; 16096b7b14aSPawel Dziepak } 16196b7b14aSPawel Dziepak 16296b7b14aSPawel Dziepak 16300a8558cSPawel Dziepak inline FileSystem* 16400a8558cSPawel Dziepak Inode::GetFileSystem() const 165be4c74eaSPawel Dziepak { 16600a8558cSPawel Dziepak return fFileSystem; 167be4c74eaSPawel Dziepak } 168be4c74eaSPawel Dziepak 169be4c74eaSPawel Dziepak 1700bc98afdSPawel Dziepak inline void* 1710bc98afdSPawel Dziepak Inode::FileCache() 1720bc98afdSPawel Dziepak { 1730bc98afdSPawel Dziepak return fFileCache; 1740bc98afdSPawel Dziepak } 1750bc98afdSPawel Dziepak 1760bc98afdSPawel Dziepak 17752aaad17SPawel Dziepak inline void 17852aaad17SPawel Dziepak Inode::SetOpenState(OpenState* state) 17952aaad17SPawel Dziepak { 18052aaad17SPawel Dziepak MutexLocker _(fStateLock); 18152aaad17SPawel Dziepak fOpenState = state; 18252aaad17SPawel Dziepak } 18352aaad17SPawel Dziepak 18452aaad17SPawel Dziepak 185e743e243SPawel Dziepak inline uint64 186e743e243SPawel Dziepak Inode::MaxFileSize() 187e743e243SPawel Dziepak { 188e743e243SPawel Dziepak return fMaxFileSize; 189e743e243SPawel Dziepak } 190e743e243SPawel Dziepak 191e743e243SPawel Dziepak 192bf31ee39SPawel Dziepak #endif // INODE_H 193bf31ee39SPawel Dziepak 194