summaryrefslogtreecommitdiff
path: root/Source/Kernel/FileSystems/RamFS/RamFS.class.h
blob: 042baa92b77de580d7ee82f2d950bd390f03df4d (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
49
50
#ifndef DEF_RAMFS_CLASS_H
#define DEF_RAMFS_CLASS_H

#include <VFS/FileSystem.proto.h>

struct initrd_header {
	unsigned int magic;
	unsigned int files;
};

struct initrd_file_header {
	unsigned int name_length;
	unsigned int file_length;
};

#define INITRD_MAGIC 0x1337BEEF

class RamFS : public FileSystem {
	private:
	virtual ~RamFS();
	RamFS(const RamFS& other);
	RamFS();
	bool unmount();

	u32int m_maxSize;
	u32int m_usedSize;

	public:
	static RamFS* mount(u32int maxSize, DirectoryNode* mountpoint);	//Creates an empty RAM file system
	static RamFS* mount(u8int* ptr, u32int maxSize, DirectoryNode* mountpoint, bool writable = true);	//Creates a RAM file system from data loaded in memory. format to be defined

	bool setName(FSNode* node, String name);
	bool setPermissions(FSNode* node, u32int permissions);
	bool setUid(FSNode* node, u32int uid);
	bool setGid(FSNode* node, u32int gid);
	bool setParent(FSNode* node, FSNode* parent);

	String getDevDescription() { return "ramfs"; }

	u32int read(FileNode* file, u64int position, u32int max_length, u8int *data);
	bool write(FileNode* file, u64int position, u32int length, u8int *data);
	bool truncate(FileNode* file);

	bool loadContents(DirectoryNode* dir);
	FileNode* createFile(DirectoryNode* parent, String name);
	DirectoryNode* createDirectory(DirectoryNode* parent, String name);
	bool remove(DirectoryNode* parent, FSNode* node);
};

#endif