1 /* 2 * Copyright 2020 Suhel Mehta, mehtasuhel@gmail.com 3 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de. 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 7 #ifndef INODE_H 8 #define INODE_H 9 10 #include "ufs2.h" 11 #include "Volume.h" 12 13 #define UFS2_ROOT ((ino_t)2) 14 15 16 struct timeval32 17 { 18 int tv_sec, tv_usec; 19 }; 20 21 22 struct ufs2_inode { 23 u_int16_t fileMode; 24 int16_t linkCount; 25 int32_t userId; 26 int32_t groupId; 27 int32_t inodeBlockSize; 28 int64_t size; 29 int64_t byteHeld; 30 struct timeval32 accessTime; 31 struct timeval32 modifiedTime; 32 struct timeval32 changeTime; 33 struct timeval32 createTime; 34 /* time in nano seconds */ 35 int32_t nsModifiedTime; 36 int32_t nsAccessTime; 37 int32_t nsChangeTime; 38 int32_t nsCreateTime; 39 int32_t generationNumber; 40 int32_t kernelFlags; 41 int32_t statusFlags; 42 int32_t extendedAttSize; /* Extended attribute size */ 43 /* 2 Direct extended attribute block pointers */ 44 int64_t extendedBklPtr1; 45 int64_t extendedBklPtr2; 46 /* 12 direct block pointers */ 47 int64_t directBlkPtr1; 48 int64_t directBlkPtr2; 49 int64_t directBlkPtr3; 50 int64_t directBlkPtr4; 51 int64_t directBlkPtr5; 52 int64_t directBlkPtr6; 53 int64_t directBlkPtr7; 54 int64_t directBlkPtr8; 55 int64_t directBlkPtr9; 56 int64_t directBlkPtr10; 57 int64_t directBlkPtr11; 58 int64_t directBlkPtr12; 59 int64_t indirectBlkPtr; /* 1 Indirect block pointer */ 60 int64_t doubleIndriectBlkPtr; // 1 Double Indirect block pointer 61 int64_t tripleIndriectBlkPtr; // 1 Triple Indirect block pointer 62 /* Unused but need to figure out what are they */ 63 int64_t unused1; 64 int64_t unused2; 65 int64_t unused3; 66 67 68 static void _DecodeTime(struct timespec& timespec, timeval32 time) 69 { 70 timespec.tv_sec = time.tv_sec; 71 timespec.tv_nsec = time.tv_usec * 1000; 72 } 73 void GetAccessTime(struct timespec& timespec) const 74 { _DecodeTime(timespec, accessTime); } 75 void GetChangeTime(struct timespec& timespec) const 76 { _DecodeTime(timespec, changeTime); } 77 void GetModificationTime(struct timespec& timespec) const 78 { _DecodeTime(timespec, modifiedTime); } 79 void GetCreationTime(struct timespec& timespec) const 80 { _DecodeTime(timespec, createTime); } 81 }; 82 83 class Inode { 84 public: 85 Inode(Volume* volume, ino_t id); 86 Inode(Volume* volume, ino_t id, 87 const ufs2_inode& item); 88 ~Inode(); 89 90 status_t InitCheck(); 91 92 ino_t ID() const { return fID; } 93 // 94 rw_lock* Lock() { return& fLock; } 95 // 96 // status_t UpdateNodeFromDisk(); 97 98 bool IsDirectory() const 99 { return S_ISDIR(Mode()); } 100 bool IsFile() const 101 { return S_ISREG(Mode()); } 102 bool IsSymLink() const 103 { return S_ISLNK(Mode()); } 104 // status_t CheckPermissions(int accessMode) const; 105 106 mode_t Mode() const { return fNode.fileMode; } 107 off_t Size() const { return fNode.size; } 108 uid_t UserID() const { return fNode.userId; } 109 gid_t GroupID() const { return fNode.groupId; } 110 void GetChangeTime(struct timespec& timespec) const 111 { fNode.GetChangeTime(timespec); } 112 void GetModificationTime(struct timespec& timespec) const 113 { fNode.GetModificationTime(timespec); } 114 void GetCreationTime(struct timespec& timespec) const 115 { fNode.GetCreationTime(timespec); } 116 void GetAccessTime(struct timespec& timespec) const 117 { fNode.GetAccessTime(timespec); } 118 119 Volume* GetVolume() const { return fVolume; } 120 121 int64_t GetBlockPointer() { return fNode.directBlkPtr1; } 122 ino_t Parent(); 123 124 // status_t FindBlock(off_t logical, off_t& physical, 125 // off_t* _length = NULL); 126 // status_t ReadAt(off_t pos, uint8* buffer, size_t* length); 127 // status_t FillGapWithZeros(off_t start, off_t end); 128 129 void* FileCache() const { return fCache; } 130 void* Map() const { return fMap; } 131 132 // status_t FindParent(ino_t* id); 133 //static Inode* Create(Transaction& transaction, ino_t id, Inode* parent, int32 mode, uint64 size = 0, uint64 flags = 0); 134 private: 135 Inode(Volume* volume); 136 Inode(const Inode&); 137 Inode& operator=(const Inode&); 138 139 // uint64 _NumBlocks(); 140 private: 141 142 rw_lock fLock; 143 ::Volume* fVolume; 144 ino_t fID; 145 void* fCache; 146 void* fMap; 147 status_t fInitStatus; 148 ufs2_inode fNode; 149 }; 150 151 #endif // INODE_H 152