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 12212de720SPawel Dziepak #include <sys/stat.h> 13212de720SPawel Dziepak 14bf31ee39SPawel Dziepak #include <SupportDefs.h> 15bf31ee39SPawel Dziepak 16be4c74eaSPawel Dziepak #include "Cookie.h" 17bf31ee39SPawel Dziepak #include "Filesystem.h" 18bf31ee39SPawel Dziepak #include "NFS4Defs.h" 194b48348fSPawel Dziepak #include "ReplyInterpreter.h" 20bf31ee39SPawel Dziepak 21bf31ee39SPawel Dziepak 22bf31ee39SPawel Dziepak class Inode { 23bf31ee39SPawel Dziepak public: 240792abe0SPawel Dziepak static status_t CreateInode(Filesystem* fs, const FileInfo& fi, 250792abe0SPawel Dziepak Inode** inode); 2687c6b832SPawel Dziepak ~Inode(); 27bf31ee39SPawel Dziepak 28bf31ee39SPawel Dziepak inline ino_t ID() const; 29d38e98d8SPawel Dziepak inline mode_t Type() const; 3096b7b14aSPawel Dziepak inline const char* Name() const; 31be4c74eaSPawel Dziepak inline Filesystem* FileSystem() const; 32bf31ee39SPawel Dziepak 337bfa4fe8SPawel Dziepak status_t LookUp(const char* name, ino_t* id); 34f5baf2efSPawel Dziepak 35f5baf2efSPawel Dziepak status_t CreateLink(const char* name, const char* path, 36f5baf2efSPawel Dziepak int mode); 37f2da914dSPawel Dziepak status_t ReadLink(void* buffer, size_t* length); 38f5baf2efSPawel Dziepak 39c0de7acaSPawel Dziepak status_t Link(Inode* dir, const char* name); 40cf511f24SPawel Dziepak status_t Remove(const char* name, FileType type); 411ec6b0c1SPawel Dziepak static status_t Rename(Inode* from, Inode* to, 421ec6b0c1SPawel Dziepak const char* fromName, const char* toName); 43abba2fddSPawel Dziepak 44631d9e98SPawel Dziepak status_t Access(int mode); 45212de720SPawel Dziepak status_t Stat(struct stat* st); 46abba2fddSPawel Dziepak status_t WriteStat(const struct stat* st, uint32 mask); 477bfa4fe8SPawel Dziepak 4820bd3ee1SPawel Dziepak status_t Create(const char* name, int mode, int perms, 4920bd3ee1SPawel Dziepak OpenFileCookie* cookie, ino_t* id); 502a292557SPawel Dziepak status_t Open(int mode, OpenFileCookie* cookie); 5160a8140dSPawel Dziepak status_t Close(OpenFileCookie* cookie); 522f2e57d0SPawel Dziepak status_t Read(OpenFileCookie* cookie, off_t pos, 532f2e57d0SPawel Dziepak void* buffer, size_t* length); 54e36a5442SPawel Dziepak status_t Write(OpenFileCookie* cookie, off_t pos, 5586d2cab3SPawel Dziepak const void* buffer, size_t *_length); 562a292557SPawel Dziepak 5769adfb6dSPawel Dziepak status_t CreateDir(const char* name, int mode); 58be4c74eaSPawel Dziepak status_t OpenDir(OpenDirCookie* cookie); 594b48348fSPawel Dziepak status_t ReadDir(void* buffer, uint32 size, 60be4c74eaSPawel Dziepak uint32* count, OpenDirCookie* cookie); 61212de720SPawel Dziepak 627d0b8c97SPawel Dziepak status_t TestLock(OpenFileCookie* cookie, 637d0b8c97SPawel Dziepak struct flock* lock); 647d0b8c97SPawel Dziepak status_t AcquireLock(OpenFileCookie* cookie, 657d0b8c97SPawel Dziepak const struct flock* lock, bool wait); 667d0b8c97SPawel Dziepak status_t ReleaseLock(OpenFileCookie* cookie, 677d0b8c97SPawel Dziepak const struct flock* lock); 687d0b8c97SPawel Dziepak status_t ReleaseAllLocks(OpenFileCookie* cookie); 697d0b8c97SPawel Dziepak 707d0b8c97SPawel Dziepak 712f03ff09SPawel Dziepak protected: 720792abe0SPawel Dziepak Inode(); 730792abe0SPawel Dziepak 7407f2e2d2SPawel Dziepak bool _HandleErrors(uint32 nfs4Error, 7507f2e2d2SPawel Dziepak RPC::Server* serv, 7607f2e2d2SPawel Dziepak OpenFileCookie* cookie = NULL); 77c702f887SPawel Dziepak status_t _LookUpFilehandle(); 78c702f887SPawel Dziepak 790f4dcd8bSPawel Dziepak status_t _ConfirmOpen(const Filehandle& fh, 800f4dcd8bSPawel Dziepak OpenFileCookie* cookie); 812a73e4c5SPawel Dziepak 824b48348fSPawel Dziepak status_t _ReadDirOnce(DirEntry** dirents, uint32* count, 83be4c74eaSPawel Dziepak OpenDirCookie* cookie, bool* eof); 844b48348fSPawel Dziepak status_t _FillDirEntry(struct dirent* de, ino_t id, 854b48348fSPawel Dziepak const char* name, uint32 pos, uint32 size); 86ed517d6cSPawel Dziepak status_t _ReadDirUp(struct dirent* de, uint32 pos, 87ed517d6cSPawel Dziepak uint32 size); 884b48348fSPawel Dziepak 8989f05134SPawel Dziepak static inline status_t _CheckLockType(short ltype, uint32 mode); 9089f05134SPawel Dziepak 914b48348fSPawel Dziepak static inline ino_t _FileIdToInoT(uint64 fileid); 924b48348fSPawel Dziepak 93d38e98d8SPawel Dziepak uint32 fType; 94bf31ee39SPawel Dziepak 95*a28e8732SPawel Dziepak FileInfo fInfo; 96bf31ee39SPawel Dziepak Filesystem* fFilesystem; 97bf31ee39SPawel Dziepak }; 98bf31ee39SPawel Dziepak 99bf31ee39SPawel Dziepak 100bf31ee39SPawel Dziepak inline ino_t 1014b48348fSPawel Dziepak Inode::_FileIdToInoT(uint64 fileid) 1024b48348fSPawel Dziepak { 1034b48348fSPawel Dziepak if (sizeof(ino_t) >= sizeof(uint64)) 1044b48348fSPawel Dziepak return fileid; 1054b48348fSPawel Dziepak else 1064b48348fSPawel Dziepak return (ino_t)fileid ^ (fileid >> 1074b48348fSPawel Dziepak (sizeof(uint64) - sizeof(ino_t)) * 8); 1084b48348fSPawel Dziepak } 1094b48348fSPawel Dziepak 1104b48348fSPawel Dziepak 1114b48348fSPawel Dziepak inline ino_t 112bf31ee39SPawel Dziepak Inode::ID() const 113bf31ee39SPawel Dziepak { 114*a28e8732SPawel Dziepak return _FileIdToInoT(fInfo.fFileId); 115bf31ee39SPawel Dziepak } 116bf31ee39SPawel Dziepak 117bf31ee39SPawel Dziepak 118d38e98d8SPawel Dziepak inline mode_t 119d38e98d8SPawel Dziepak Inode::Type() const 120d38e98d8SPawel Dziepak { 121d38e98d8SPawel Dziepak return sNFSFileTypeToHaiku[fType]; 122d38e98d8SPawel Dziepak } 123d38e98d8SPawel Dziepak 124d38e98d8SPawel Dziepak 12596b7b14aSPawel Dziepak inline const char* 12696b7b14aSPawel Dziepak Inode::Name() const 12796b7b14aSPawel Dziepak { 128*a28e8732SPawel Dziepak return fInfo.fName; 12996b7b14aSPawel Dziepak } 13096b7b14aSPawel Dziepak 13196b7b14aSPawel Dziepak 132be4c74eaSPawel Dziepak inline Filesystem* 133be4c74eaSPawel Dziepak Inode::FileSystem() const 134be4c74eaSPawel Dziepak { 135be4c74eaSPawel Dziepak return fFilesystem; 136be4c74eaSPawel Dziepak } 137be4c74eaSPawel Dziepak 138be4c74eaSPawel Dziepak 139bf31ee39SPawel Dziepak #endif // INODE_H 140bf31ee39SPawel Dziepak 141