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