summaryrefslogtreecommitdiff
path: root/lib/filesystem.h
blob: 0c44236a02c52be588a843c3e41a36559eb98a3a (plain)
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
#pragma once

#include "special_members.hpp"
#include <cstddef>
#include <sys/types.h>

namespace filesystem {
	class [[nodiscard]] memmap final {
	public:
		memmap(size_t length, int prot, int flags, int fd, off_t offset);
		~memmap();
		NO_MOVE(memmap);
		NO_COPY(memmap);

		template<typename T>
		T *
		get()
		{
			return static_cast<T *>(addr);
		}

		void msync(int flags) const;

	private:
		void * addr;
		size_t length;
	};

	class [[nodiscard]] fh final {
	public:
		fh(const char * path, int flags, int mode);
		~fh();
		NO_MOVE(fh);
		NO_COPY(fh);

		void truncate(size_t size);
		memmap mmap(size_t length, size_t offset, int prot, int flags);

	private:
		int h;
	};
}