xref: /haiku/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h (revision 9e54316c528c34ee76f4d0d21150ceadd031c4de)
1 /*
2  * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3  * This file may be used under the terms of the MIT License.
4  */
5 #ifndef DIRECTORY_ITERATOR_H
6 #define DIRECTORY_ITERATOR_H
7 
8 
9 #include "ext2.h"
10 
11 #include <SupportDefs.h>
12 
13 #include "Transaction.h"
14 
15 
16 class HTreeEntryIterator;
17 class Inode;
18 
19 class DirectoryIterator {
20 public:
21 						DirectoryIterator(Inode* inode, off_t start = 0,
22 							HTreeEntryIterator* parent = NULL);
23 						~DirectoryIterator();
24 
25 			status_t	InitCheck();
26 
27 
28 			status_t	Next();
29 			status_t	Get(char* name, size_t* _nameLength, ino_t* id);
30 			status_t	GetNext(char* name, size_t* _nameLength, ino_t* id);
31 
32 			status_t	Rewind();
33 			void		Restart();
34 
35 			status_t	AddEntry(Transaction& transaction, const char* name,
36 							size_t nameLength, ino_t id, uint8 type);
37 			status_t	FindEntry(const char* name, ino_t* id = NULL);
38 			status_t	RemoveEntry(Transaction& transaction);
39 
40 			status_t	ChangeEntry(Transaction& transaction, ino_t id,
41 							uint8 fileType);
42 
43 private:
44 						DirectoryIterator(const DirectoryIterator&);
45 						DirectoryIterator &operator=(const DirectoryIterator&);
46 							// no implementation
47 
48 
49 protected:
50 			status_t	_AllocateBestEntryInBlock(uint8 nameLength, uint16& pos,
51 							uint16& newLength);
52 			status_t	_AddEntry(Transaction& transaction, const char* name,
53 							uint8 nameLength, ino_t id, uint8 fileType,
54 							uint16 newLength, uint16 pos,
55 							bool hasPrevious = true);
56 			status_t	_SplitIndexedBlock(Transaction& transaction,
57 							const char* name, uint8 nameLength, ino_t id,
58 							uint8 type, uint32 newBlocksPos,
59 							bool firstSplit = false);
60 
61 			status_t	_NextBlock();
62 			off_t		_Offset() { return fLogicalBlock * fBlockSize
63 							+ fDisplacement; }
64 
65 			bool		_CheckDirEntry(const ext2_dir_entry* dirEntry,
66 							const uint8* buffer);
67 			status_t	_CheckBlock(const uint8* buffer);
68 			uint32		_MaxSize();
69 
70 #if 0
71 			ext2_dir_entry_tail* _DirEntryTail(uint8* block) const;
72 			uint32		_Checksum(uint8* block) const;
73 			void		_SetDirEntryChecksum(uint8* block);
74 #endif
75 			ext2_htree_tail* _HTreeEntryTail(uint8* block, uint16 offset) const;
76 			uint32		_HTreeRootChecksum(uint8* block, uint16 offset, uint16 count) const;
77 			void		_SetHTreeEntryChecksum(uint8* block, uint16 offset, uint16 count);
78 
79 
80 	Inode*				fDirectory;
81 	Volume*				fVolume;
82 	uint32				fBlockSize;
83 	HTreeEntryIterator*	fParent;
84 	bool				fIndexing;
85 
86 	uint32				fNumBlocks;
87 	uint32				fLogicalBlock;
88 	fsblock_t			fPhysicalBlock;
89 	uint32				fDisplacement;
90 	uint32				fPreviousDisplacement;
91 
92 	off_t				fStartPhysicalBlock;
93 	uint32				fStartLogicalBlock;
94 	uint32				fStartDisplacement;
95 
96 	status_t			fInitStatus;
97 };
98 
99 #endif	// DIRECTORY_ITERATOR_H
100 
101