1 /* 2 * Copyright 2002-2012, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2012, Andreas Henriksson, sausageboy@gmail.com 4 * This file may be used under the terms of the MIT License. 5 */ 6 #ifndef CHECK_VISITOR_H 7 #define CHECK_VISITOR_H 8 9 10 #include "system_dependencies.h" 11 12 13 #include "bfs_control.h" 14 #include "FileSystemVisitor.h" 15 16 17 class BlockAllocator; 18 class BPlusTree; 19 struct check_index; 20 21 typedef Stack<check_index*> IndexStack; 22 23 24 class CheckVisitor : public FileSystemVisitor { 25 public: 26 CheckVisitor(Volume* volume); 27 virtual ~CheckVisitor(); 28 29 check_control& Control() { return control; } 30 IndexStack& Indices() { return indices; } 31 uint32 Pass() { return control.pass; } 32 33 status_t StartBitmapPass(); 34 status_t WriteBackCheckBitmap(); 35 status_t StartIndexPass(); 36 status_t StopChecking(); 37 38 virtual status_t VisitDirectoryEntry(Inode* inode, 39 Inode* parent, const char* treeName); 40 virtual status_t VisitInode(Inode* inode, const char* treeName); 41 42 virtual status_t OpenInodeFailed(status_t reason, ino_t id, 43 Inode* parent, char* treeName, 44 TreeIterator* iterator); 45 virtual status_t OpenBPlusTreeFailed(Inode* inode); 46 virtual status_t TreeIterationFailed(status_t reason, 47 Inode* parent); 48 49 private: 50 status_t _RemoveInvalidNode(Inode* parent, 51 BPlusTree* tree, Inode* inode, 52 const char* name); 53 54 bool _ControlValid(); 55 bool _CheckBitmapIsUsedAt(off_t block) const; 56 void _SetCheckBitmapAt(off_t block); 57 status_t _CheckInodeBlocks(Inode* inode, 58 const char* name); 59 status_t _CheckAllocated(block_run run, 60 const char* type); 61 62 size_t _BitmapSize() const; 63 64 status_t _PrepareIndices(); 65 void _FreeIndices(); 66 status_t _AddInodeToIndex(Inode* inode); 67 68 private: 69 check_control control; 70 IndexStack indices; 71 72 uint32* fCheckBitmap; 73 }; 74 75 76 #endif // CHECK_VISITOR_H 77