1 /* 2 * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef _LEAFDIRECTORY_H_ 6 #define _LEAFDIRECTORY_H_ 7 8 9 #include "Extent.h" 10 #include "Inode.h" 11 #include "system_dependencies.h" 12 13 14 #define DATA_HEADER_MAGIC 0x58443244 15 16 17 enum ContentType { DATA, LEAF }; 18 19 20 //xfs_dir2_leaf_hdr_t 21 struct ExtentLeafHeader { 22 BlockInfo info; 23 uint16 count; 24 uint16 stale; 25 }; 26 27 28 // xfs_dir2_leaf_tail_t 29 struct ExtentLeafTail { 30 uint32 bestcount; 31 // # of best free entries 32 }; 33 34 35 class LeafDirectory { 36 public: 37 LeafDirectory(Inode* inode); 38 ~LeafDirectory(); 39 status_t Init(); 40 bool IsLeafType(); 41 void FillMapEntry(int num, ExtentMapEntry* map); 42 status_t FillBuffer(int type, char* buffer, 43 int howManyBlocksFurthur); 44 void SearchAndFillDataMap(uint64 blockNo); 45 ExtentLeafEntry* FirstLeaf(); 46 xfs_ino_t GetIno(); 47 uint32 GetOffsetFromAddress(uint32 address); 48 int EntrySize(int len) const; 49 status_t GetNext(char* name, size_t* length, 50 xfs_ino_t* ino); 51 status_t Lookup(const char* name, size_t length, 52 xfs_ino_t* id); 53 private: 54 Inode* fInode; 55 ExtentMapEntry* fDataMap; 56 ExtentMapEntry* fLeafMap; 57 uint32 fOffset; 58 char* fDataBuffer; 59 // This isn't inode data. It holds the directory block. 60 char* fLeafBuffer; 61 uint32 fCurBlockNumber; 62 }; 63 64 65 #endif 66