forked from ratspeak/rsCardputer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDStore.h
More file actions
52 lines (41 loc) · 1.76 KB
/
Copy pathSDStore.h
File metadata and controls
52 lines (41 loc) · 1.76 KB
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
#pragma once
#include <Arduino.h>
#include <SD.h>
#include <SPI.h>
class SDStore {
public:
bool begin(SPIClass* spi, int csPin);
void end();
// Atomic write: .tmp -> verify -> .bak -> rename
bool writeAtomic(const char* path, const uint8_t* data, size_t len);
bool writeString(const char* path, const String& data);
// Simple direct write (no rename dance — for small config files)
bool writeDirect(const char* path, const uint8_t* data, size_t len);
String readString(const char* path);
// Resets a file's on-disk mtime/atime to a fixed, non-informative value
// (unix epoch) — FAT timestamps a file with real wall-clock time at
// write, which for per-message files means "when this message arrived"
// is readable straight off the card, no decryption required. See
// WriteQueue::processJob(), the only caller.
bool scrubTimestamp(const char* path);
bool ensureDir(const char* path);
bool exists(const char* path);
bool remove(const char* path);
File openDir(const char* path);
bool removeDir(const char* path);
bool rename(const char* from, const char* to);
bool rename(const String& f, const String& t) { return rename(f.c_str(), t.c_str()); }
bool readFile(const char* path, uint8_t* buffer, size_t maxLen, size_t& bytesRead);
bool isReady() const { return _ready; }
uint64_t totalBytes() const;
uint64_t usedBytes() const;
// Creates the legacy /ratcom/ directory tree (does NOT reformat FAT)
bool formatForStandalone();
// Recursively delete the legacy /ratcom/* data and recreate clean dirs
bool wipeStandalone();
// Check if SD has data from a previous install
bool hasExistingData();
private:
void wipeDir(const char* path);
bool _ready = false;
};