xref: /haiku/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 
66 	Inode*				fDirectory;
67 	Volume*				fVolume;
68 	uint32				fBlockSize;
69 	HTreeEntryIterator*	fParent;
70 	bool				fIndexing;
71 
72 	uint32				fNumBlocks;
73 	uint32				fLogicalBlock;
74 	fsblock_t			fPhysicalBlock;
75 	uint32				fDisplacement;
76 	uint32				fPreviousDisplacement;
77 
78 	off_t				fStartPhysicalBlock;
79 	uint32				fStartLogicalBlock;
80 	uint32				fStartDisplacement;
81 
82 	status_t			fInitStatus;
83 };
84 
85 #endif	// DIRECTORY_ITERATOR_H
86 
87