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 EXTENT_SIZE 16 15 #define BLOCKNO_FROM_ADDRESS(n, volume) \ 16 (n >> (volume->BlockLog() + volume->DirBlockLog())) 17 #define BLOCKOFFSET_FROM_ADDRESS(n, inode) (n & (inode->DirBlockSize() - 1)) 18 #define HEADER_MAGIC 0x58443244 19 #define LEAF_STARTOFFSET(n) 1UL << (35 - n) 20 21 enum ContentType { DATA, LEAF }; 22 23 24 // xfs_da_blkinfo_t 25 struct BlockInfo { 26 uint32 forw; 27 uint32 back; 28 uint16 magic; 29 uint16 pad; 30 }; 31 32 33 //xfs_dir2_leaf_hdr_t 34 struct ExtentLeafHeader { 35 BlockInfo info; 36 uint16 count; 37 uint16 stale; 38 }; 39 40 41 // xfs_dir2_leaf_tail_t 42 struct ExtentLeafTail { 43 uint32 bestcount; 44 // # of best free entries 45 }; 46 47 48 class LeafDirectory { 49 public: 50 LeafDirectory(Inode* inode); 51 ~LeafDirectory(); 52 status_t Init(); 53 bool IsLeafType(); 54 void FillMapEntry(int num, ExtentMapEntry* map); 55 status_t FillBuffer(int type, char* buffer, 56 int howManyBlocksFurthur); 57 void SearchAndFillDataMap(int blockNo); 58 ExtentLeafEntry* FirstLeaf(); 59 xfs_ino_t GetIno(); 60 uint32 GetOffsetFromAddress(uint32 address); 61 int EntrySize(int len) const; 62 status_t GetNext(char* name, size_t* length, 63 xfs_ino_t* ino); 64 status_t Lookup(const char* name, size_t length, 65 xfs_ino_t* id); 66 private: 67 Inode* fInode; 68 ExtentMapEntry* fDataMap; 69 ExtentMapEntry* fLeafMap; 70 uint32 fOffset; 71 char* fDataBuffer; 72 // This isn't inode data. It holds the directory block. 73 char* fLeafBuffer; 74 uint32 fCurBlockNumber; 75 }; 76 77 78 #endif 79