Line data Source code
1 : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : */
4 :
5 : #ifndef SOLIDSYSLOGFILEBLOCKDEVICEPRIVATE_H
6 : #define SOLIDSYSLOGFILEBLOCKDEVICEPRIVATE_H
7 :
8 : #include <stdint.h>
9 :
10 : #include <stdbool.h>
11 : #include <stddef.h>
12 :
13 : #include "SolidSyslogBlockDeviceDefinition.h"
14 : #include "SolidSyslogError.h"
15 : #include "SolidSyslogFileBlockDeviceErrors.h"
16 : #include "SolidSyslogPrival.h"
17 :
18 : struct SolidSyslogFile;
19 :
20 : /* OpenHandle caches the single SolidSyslogFile the device holds. The handle is
21 : * re-pointed only when the targeted blockIndex changes; same-block runs reuse
22 : * it. This is the structural enforcement of the S27.01 single-handle-per-path
23 : * invariant - by construction the device has exactly one underlying file. */
24 : struct OpenHandle
25 : {
26 : struct SolidSyslogFile* File;
27 : size_t BlockIndex;
28 : bool IsOpen;
29 : };
30 :
31 : struct SolidSyslogFileBlockDevice
32 : {
33 : struct SolidSyslogBlockDevice Base;
34 : struct OpenHandle Handle;
35 : const char* PathPrefix;
36 : size_t BlockSize;
37 : };
38 :
39 : void SolidSyslogFileBlockDevice_Initialise(
40 : struct SolidSyslogBlockDevice* base,
41 : struct SolidSyslogFile* file,
42 : const char* pathPrefix,
43 : size_t blockSize
44 : );
45 : void SolidSyslogFileBlockDevice_Cleanup(struct SolidSyslogBlockDevice* base);
46 :
47 5 : static inline void FileBlockDevice_Report(
48 : enum SolidSyslogSeverity severity,
49 : uint16_t category,
50 : enum SolidSyslogFileBlockDeviceErrors code
51 : )
52 : {
53 5 : SolidSyslog_Error(severity, &SolidSyslogFileBlockDeviceErrorSource, category, (int32_t) code);
54 5 : }
55 :
56 : #endif /* SOLIDSYSLOGFILEBLOCKDEVICEPRIVATE_H */
|