1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Dmitry Yemanov |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2006 Dmitry Yemanov <dimitr@users.sf.net> |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | */ |
22 | |
23 | #ifndef CLASSES_FILE_H |
24 | #define CLASSES_FILE_H |
25 | |
26 | #include "../common/classes/array.h" |
27 | |
28 | #if !defined(SOLARIS) && !defined(AIX) |
29 | typedef FB_UINT64 offset_t; |
30 | #endif |
31 | |
32 | namespace Firebird { |
33 | |
34 | class File |
35 | { |
36 | public: |
37 | virtual ~File() {} |
38 | |
39 | virtual size_t read(offset_t, void*, size_t) = 0; |
40 | virtual size_t write(offset_t, const void*, size_t) = 0; |
41 | |
42 | virtual void unlink() = 0; |
43 | |
44 | virtual offset_t getSize() const = 0; |
45 | }; |
46 | |
47 | class ZeroBuffer |
48 | { |
49 | static const size_t DEFAULT_SIZE = 1024 * 256; |
50 | static const size_t SYS_PAGE_SIZE = 1024 * 4; |
51 | |
52 | public: |
53 | explicit ZeroBuffer(MemoryPool& p, size_t size = DEFAULT_SIZE) |
54 | : buffer(p) |
55 | { |
56 | bufSize = size; |
57 | bufAligned = buffer.getBuffer(bufSize + SYS_PAGE_SIZE); |
58 | bufAligned = (char*) FB_ALIGN((U_IPTR) bufAligned, SYS_PAGE_SIZE); |
59 | memset(bufAligned, 0, size); |
60 | } |
61 | |
62 | const char* getBuffer() const { return bufAligned; } |
63 | size_t getSize() const { return bufSize; } |
64 | |
65 | private: |
66 | Firebird::Array<char> buffer; |
67 | char* bufAligned; |
68 | size_t bufSize; |
69 | }; |
70 | |
71 | } // namespace |
72 | |
73 | #endif // CLASSES_FILE_H |
74 | |