aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fileop.h
blob: d005fd535cf6d0a0826f9b5aa9f9c277d8a840da (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
43
44
45
46
47
48
49
50
51
52
53
/**
 * SPDX-License-Identifier: Apache-2.0
 *
 * @file	fileop.h
 * @brief	The file operation functions
 */
#ifndef REFOP_FILEOP_H
#define REFOP_FILEOP_H
//-----------------------------------------------------------------------------
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <linux/limits.h>

//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
//-----------------------------------------------------------------------------
struct __attribute__((packed)) s_refop_file_header_v1 {
	uint32_t magic;       /*  4 *//**< Magic code */
	uint32_t version;     /*  8 *//**< Data format version */
	uint32_t version_inv; /* 12 *//**< Data format version (inversion value) */
	uint16_t crc16;       /* 14 *//**< Data block crc */
	uint16_t crc16_inv;   /* 16 *//**< Data block crc (inversion value) */
	uint64_t size;        /* 24 *//**< Data block size */
	uint64_t size_inv;    /* 32 *//**< Data block size (inversion value) */
};

#define REFOP_FILE_HEADER_MAGIC	((uint32_t)0x96962323)
#define REFOP_FILE_HEADER_VERSION_V1	((uint32_t)0x00000001)

typedef struct s_refop_file_header_v1 s_refop_file_header;

struct refop_halndle {
	char latestfile[PATH_MAX];
	char backupfile1[PATH_MAX];
	char newfile[PATH_MAX];
	char basedir[PATH_MAX];
};

//-----------------------------------------------------------------------------
int refop_new_file_write(refop_handle_t handle, uint8_t *data, int64_t bufsize);
int refop_file_rotation(refop_handle_t handle);

int refop_file_pickup(refop_handle_t handle, uint8_t *data, int64_t bufsize, int64_t *readsize);

//-----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
//-----------------------------------------------------------------------------
#endif //#ifndef REFOP_FILEOP_H