1 /* 2 * Copyright 2020 Suhel Mehta, mehtasuhel@gmail.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #ifndef DIRECTORYITERATOR_H 8 #define DIRECTORYITERATOR_H 9 10 11 #include "ufs2.h" 12 13 14 class Inode; 15 16 #define MAXNAMELEN 255 17 18 struct dir { 19 u_int32_t next_ino; 20 u_int16_t reclen; 21 u_int8_t type; 22 u_int8_t namlen; 23 char name[MAXNAMELEN + 1]; 24 }; 25 26 struct dir_info { 27 u_int32_t dot_ino; 28 int16_t dot_reclen; 29 u_int8_t dot_type; 30 u_int8_t dot_namelen; 31 char dot_name[4]; 32 u_int32_t dotdot_ino; 33 int16_t dotdot_reclen; 34 u_int8_t dotdot_type; 35 u_int8_t dotdot_namelen; 36 char dotdot_name[4]; 37 }; 38 39 class DirectoryIterator { 40 public: 41 DirectoryIterator(Inode* inode); 42 ~DirectoryIterator(); 43 44 status_t InitCheck(); 45 status_t Rewind(); 46 status_t Lookup(const char* name, ino_t* id); 47 status_t GetNext(char* name, size_t* _nameLength, 48 ino_t* _id); 49 status_t _GetNext(const char* name, size_t* _nameLength, 50 ino_t* _id, int64_t* offset); 51 dir* DirectContent() { return direct; } 52 dir_info* DirectInfo() { return direct_info; } 53 54 private: 55 int fCountDir; 56 int64 fOffset; 57 cluster_t fCluster; 58 Inode* fInode; 59 dir* direct; 60 dir_info* direct_info; 61 62 }; 63 64 65 #endif // DIRECTORYITERATOR_H 66