summaryrefslogtreecommitdiff
path: root/Source/Kernel/VFS/File.class.h
blob: 460036c1fee3bb12accf72ebddf1c793b0db876f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef DEF_FILE_CLASS_H
#define DEF_FILE_CLASS_H

#include <VFS/FileNode.class.h>
#include <Library/ByteArray.class.h>

enum {
	FM_READ = 0,		//Open for read, put cursor at beginning
	FM_TRUNCATE = 1,	//Open for write, truncating file before
	FM_APPEND = 2,		//Open for write, put cursor at end
	FM_REPLACE = 3		//Open for write, put cursor at beginning
};

enum {
	SM_FORWARD = 0,		//Seek from actual position
	SM_BACKWARD = 1,	//Seek from actual position, backward
	SM_BEGINNING = 2,	//Seek from start of file
	SM_END = 3,			//Seek from end of file
};

class File {
	private:
	FileNode* m_file;
	bool m_valid;		//Is a file opened and valid ?
	bool m_writable;	//Is file opened for write ?
	u64int m_position;

	public:
	File();
	File(String filename, u8int mode = FM_READ, FSNode* start = 0);
	~File();

	bool open(String filename, u8int mode = FM_READ, FSNode* start = 0);
	void close(bool unregisterFD = true);	//unregisterFD = whether or not we must unregister the file descriptor from process

	u32int read(u32int max_length, u8int *data);
	bool write(u32int length, u8int *data);
	u32int read(ByteArray &data);	//Fills ByteArray at its current length or shrinks it if necessary
	bool write(ByteArray &data);

	bool seek(u64int count, u8int mode);
	u64int position() { return m_position; }
	u64int length() { return m_file->getLength(); }

	bool valid() { return m_valid; }
};

#endif