1 /* 2 * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef __SHORT_DIR_H__ 6 #define __SHORT_DIR_H__ 7 8 9 #include "Directory.h" 10 #include "Inode.h" 11 12 13 /* 14 * offset into the literal area 15 * xfs_dir2_sf_off_t 16 */ 17 struct ShortFormOffset { 18 uint16 i; 19 } __attribute__((packed)); 20 21 //xfs_dir2_inou_t 22 union ShortFormInodeUnion { 23 uint64 i8; 24 uint32 i4; 25 } __attribute__((packed)); 26 27 28 // xfs_dir2_sf_hdr_t 29 struct ShortFormHeader { 30 uint8 count; 31 // number of entries 32 uint8 i8count; 33 // # of 64bit inode entries 34 ShortFormInodeUnion parent; 35 // absolute inode # of parent 36 } __attribute__((packed)); 37 38 39 //xfs_dir2_sf_entry_t 40 struct ShortFormEntry { 41 uint8 namelen; 42 // length of the name, in bytes 43 ShortFormOffset offset; 44 // offset tag, for directory iteration 45 uint8 name[]; 46 // name of directory entry 47 /* 48 * Following will be a single byte file type variable 49 * and inode number (64bits or 32 bits) 50 */ 51 } __attribute__((packed)); 52 53 54 class ShortDirectory : public DirectoryIterator { 55 public: 56 ShortDirectory(Inode* inode); 57 ~ShortDirectory(); 58 size_t HeaderSize(); 59 uint8 GetFileType(ShortFormEntry* entry); 60 ShortFormEntry* FirstEntry(); 61 xfs_ino_t GetIno(ShortFormInodeUnion* inum); 62 xfs_ino_t GetEntryIno(ShortFormEntry* entry); 63 size_t EntrySize(int namelen); 64 status_t GetNext(char* name, size_t* length, 65 xfs_ino_t* ino); 66 status_t Lookup(const char* name, size_t length, 67 xfs_ino_t* id); 68 private: 69 Inode* fInode; 70 ShortFormHeader* fHeader; 71 uint16 fLastEntryOffset; 72 // offset into the literal area 73 uint8 fTrack; 74 // Takes the values 0, 1 or 2 75 }; 76 77 #endif 78