1/*
2** Copyright 2003, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the MIT License.
4*/
5#ifndef DIRECTORY_H
6#define DIRECTORY_H
7
8
9#include "fatfs.h"
10#include "Stream.h"
11
12#include <boot/vfs.h>
13
14
15namespace FATFS {
16
17struct dir_entry;
18class Volume;
19
20class Directory : public ::Directory {
21	public:
22		Directory();
23		Directory(Volume &volume, off_t dirEntryOffset, uint32 cluster,
24			const char *name);
25		virtual ~Directory();
26
27		status_t InitCheck();
28
29		off_t DirEntryOffset() const	{ return fDirEntryOffset; }
30
31		virtual status_t Open(void **_cookie, int mode);
32		virtual status_t Close(void *cookie);
33
34		virtual Node* LookupDontTraverse(const char* name);
35
36		virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize);
37		virtual status_t GetNextNode(void *cookie, Node **_node);
38		virtual status_t Rewind(void *cookie);
39		virtual bool IsEmpty();
40
41		virtual status_t GetName(char *name, size_t size) const;
42		virtual ino_t Inode() const;
43
44		virtual status_t CreateFile(const char *name, mode_t permissions,
45			Node **_node);
46
47		static status_t UpdateDirEntry(Volume& volume, off_t dirEntryOffset,
48			uint32 firstCluster, uint32 size);
49
50	private:
51		status_t GetNextEntry(void *cookie,
52				uint8 mask = FAT_VOLUME, uint8 match = 0);
53		status_t _AddEntry(dir_entry& entry, off_t& _entryOffset);
54		off_t _GetStreamSize();
55
56		Volume			&fVolume;
57		Stream			fStream;
58		off_t			fDirEntryOffset;
59
60		typedef ::Directory _inherited;
61};
62
63}	// namespace FATFS
64
65#endif	/* DIRECTORY_H */
66