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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/**
* SPDX-License-Identifier: Apache-2.0
*
* @file example.c
* @brief example for librefop
*/
#include "librefop.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
//int mkdir(const char *pathname, mode_t mode);
const char filedir[] = "/tmp/refop-test/";
const char filename[] = "refop-example.bin";
int main(int argc, char *argv[])
{
refop_handle_t handle;
refop_error_t ret = REFOP_SUCCESS;
uint8_t *pbuf = NULL;
int64_t sz = 128 * 1024;
int64_t szr = 0;
// Data directry need to make self.
mkdir(filedir, 0777);
// Create handle
ret = refop_create_redundancy_handle(&handle, filedir, filename);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to create refop handle: return %d\n", (int) ret);
return -1;
}
// Example data create
pbuf = (uint8_t *) malloc(sz);
if (pbuf == NULL) {
fprintf(stderr, "Malloc fail\n");
return -1;
}
memset(pbuf, 0xff, sz);
// Set data
ret = refop_set_redundancy_data(handle, pbuf, sz);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to set data: return %d\n", (int) ret);
return -1;
}
// Set data
ret = refop_set_redundancy_data(handle, pbuf, sz);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to set data: return %d\n", (int) ret);
return -1;
}
// Set data
ret = refop_set_redundancy_data(handle, pbuf, sz);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to set data: return %d\n", (int) ret);
return -1;
}
// Get data
ret = refop_get_redundancy_data(handle, pbuf, sz, &szr);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to get data: return %d\n", (int) ret);
return -1;
}
ret = refop_remove_redundancy_data(handle);
if (ret != REFOP_SUCCESS) {
fprintf(stderr, "Fail to remove data: return %d\n", (int) ret);
return -1;
}
// Release handle
(void) refop_release_redundancy_handle(handle);
return 0;
}
|