-
Notifications
You must be signed in to change notification settings - Fork 9
/
pack_littlefs.h
64 lines (53 loc) · 1.46 KB
/
pack_littlefs.h
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
#pragma once
#include <iostream>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <cstring>
#include <string>
#include <time.h>
#include <memory>
#include <cstdlib>
#include <stdio.h>
#if defined(_WIN32)
#include <io.h>
#endif
#include <dirent.h>
#include "lfs2.h"
#include "lfs2_rambd.h"
#define READ_SIZE 32
#define PROC_SIZE 32
#define LOOKAHEAD_SIZE 32
#define BLOCK_SIZE 4096
#define BLOCK_COUNT 512
/**
* @brief This class is used to pack/upack filesystem.
*
*/
class Pack_littlefs
{
public:
Pack_littlefs();
~Pack_littlefs();
int actionPack(std::string s_dirName, std::string s_imageName, int s_imageSize);
int actionUnpack(std::string s_imageName, std::string s_dirName,int s_imageSize);
private:
void lfsConfig(int s_imageSize);
bool fsMount(std::string s_imageName, int s_imageSize, bool format=false);
bool fsUnmount();
size_t getFileSize(FILE* fp);
bool dirExists(const char* path);
bool dirCreate(const char* path);
int parkFileToRamFS(char* path_src, const char* path_des);
bool parkFilesToRamFS(const char* dirSrc, const char* dirDes);
bool unparkFileFromRamFS(const char* path_src, lfs2_info *littlefsFile, const char* path_des);
bool unparkFilesFromRamFS(const char* dirSrc, std::string dirDes);
lfs2_t s_fs;
lfs2_config s_cfg;
lfs2_file_t f;
lfs2_rambd_config rambd_cfg;
lfs2_rambd_t bd;
protected:
};