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 struct ufs2_inode { 16 u_int16_t fileMode; 17 int16_t linkCount; 18 int32_t userId; 19 int32_t groupId; 20 int32_t inodeBlockSize; 21 int64_t size; 22 int64_t byteHeld; 23 int64_t accessTime; 24 int64_t modifiedTime; 25 int64_t changeTime; 26 int64_t createTime; 27 /* time in nano seconds */ 28 int32_t nsModifiedTime; 29 int32_t nsAccessTime; 30 int32_t nsChangeTime; 31 int32_t nsCreateTime; 32 int32_t generationNumber; 33 int32_t kernelFlags; 34 int32_t statusFlags; 35 int32_t extendedAttSize; /* Extended attribute size */ 36 /* 2 Direct extended attribute block pointers */ 37 int64_t extendedBklPtr1; 38 int64_t extendedBklPtr2; 39 /* 12 direct block pointers */ 40 int64_t directBlkPtr1; 41 int64_t directBlkPtr2; 42 int64_t directBlkPtr3; 43 int64_t directBlkPtr4; 44 int64_t directBlkPtr5; 45 int64_t directBlkPtr6; 46 int64_t directBlkPtr7; 47 int64_t directBlkPtr8; 48 int64_t directBlkPtr9; 49 int64_t directBlkPtr10; 50 int64_t directBlkPtr11; 51 int64_t directBlkPtr12; 52 int64_t indirectBlkPtr; /* 1 Indirect block pointer */ 53 int64_t doubleIndriectBlkPtr; // 1 Double Indirect block pointer 54 int64_t tripleIndriectBlkPtr; // 1 Triple Indirect block pointer 55 /* Unused but need to figure out what are they */ 56 int64_t unused1; 57 int64_t unused2; 58 int64_t unused3; 59 60 }; 61 62 class Inode { 63 public: 64 Inode(Volume* volume, ino_t id); 65 Inode(Volume* volume, ino_t id, 66 const ufs2_inode& item); 67 ~Inode(); 68 69 status_t InitCheck(); 70 71 ino_t ID() const { return fID; } 72 // 73 rw_lock* Lock() { return& fLock; } 74 // 75 // status_t UpdateNodeFromDisk(); 76 77 bool IsDirectory() const 78 { return S_ISDIR(Mode()); } 79 bool IsFile() const 80 { return S_ISREG(Mode()); } 81 bool IsSymLink() const 82 { return S_ISLNK(Mode()); } 83 // status_t CheckPermissions(int accessMode) const; 84 85 mode_t Mode() const { return fNode.fileMode; } 86 off_t Size() const { return fNode.size; } 87 uid_t UserID() const { return fNode.userId; } 88 gid_t GroupID() const { return fNode.groupId; } 89 /*void GetChangeTime(struct timespec& timespec) const 90 { fNode.GetChangeTime(timespec); } 91 void GetModificationTime(struct timespec& timespec) const 92 { fNode.GetModificationTime(timespec); } 93 void GetCreationTime(struct timespec& timespec) const 94 { fNode.GetCreationTime(timespec); } 95 void GetAccessTime(struct timespec& timespec) const 96 { fNode.GetCreationTime(timespec); }*/ 97 98 Volume* GetVolume() const { return fVolume; } 99 100 // status_t FindBlock(off_t logical, off_t& physical, 101 // off_t* _length = NULL); 102 // status_t ReadAt(off_t pos, uint8* buffer, size_t* length); 103 // status_t FillGapWithZeros(off_t start, off_t end); 104 105 void* FileCache() const { return fCache; } 106 void* Map() const { return fMap; } 107 108 // status_t FindParent(ino_t* id); 109 //static Inode* Create(Transaction& transaction, ino_t id, Inode* parent, int32 mode, uint64 size = 0, uint64 flags = 0); 110 private: 111 Inode(Volume* volume); 112 Inode(const Inode&); 113 Inode& operator=(const Inode&); 114 115 // uint64 _NumBlocks(); 116 private: 117 118 rw_lock fLock; 119 ::Volume* fVolume; 120 ino_t fID; 121 void* fCache; 122 void* fMap; 123 status_t fInitStatus; 124 ufs2_inode fNode; 125 }; 126 127 #endif // INODE_H 128