xref: /haiku/src/add-ons/kernel/file_systems/ramfs/DataContainer.h (revision 2141d2fe3a5df2f55f3590f67660573b50d1d1d3)
1 /*
2  * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2019-2024, Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT license.
5  */
6 #ifndef DATA_CONTAINER_H
7 #define DATA_CONTAINER_H
8 
9 
10 #include <OS.h>
11 
12 
13 struct vm_page;
14 class VMCache;
15 class AllocationInfo;
16 class Volume;
17 
18 
19 class DataContainer {
20 public:
21 	DataContainer(Volume *volume);
22 	virtual ~DataContainer();
23 
24 	status_t InitCheck() const;
25 
26 	Volume *GetVolume() const	{ return fVolume; }
27 
28 	status_t Resize(off_t newSize);
29 	off_t GetSize() const { return fSize; }
30 
31 	VMCache* GetCache(struct vnode* vnode);
32 
33 	virtual status_t ReadAt(off_t offset, void *buffer, size_t size,
34 							size_t *bytesRead);
35 	virtual status_t WriteAt(off_t offset, const void *buffer, size_t size,
36 							 size_t *bytesWritten);
37 
38 	// debugging
39 	void GetAllocationInfo(AllocationInfo &info);
40 
41 private:
42 	inline bool _RequiresCacheMode(size_t size);
43 	inline bool _IsCacheMode() const;
44 	status_t _SwitchToCacheMode();
45 	status_t _DoCacheIO(const off_t offset, uint8* buffer, ssize_t length,
46 		size_t* bytesProcessed, bool isWrite);
47 
48 	inline int32 _CountBlocks() const;
49 
50 private:
51 	Volume				*fVolume;
52 	off_t				fSize;
53 	VMCache*			fCache;
54 
55 	uint8*				fSmallBuffer;
56 	off_t				fSmallBufferSize;
57 };
58 
59 
60 #endif	// DATA_CONTAINER_H
61