-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpiecefat.h
99 lines (69 loc) · 1.53 KB
/
piecefat.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef __PIECEFAT_H_
#define __PIECEFAT_H_
#include <stdint.h>
#include <cstdio>
namespace n {
namespace piece {
class Device;
class Fs
{
uint32_t mblk_adr_;
static const int MAXDIR=96;
static const int MAXFAT=496;
static const uint16_t FAT_FREE=0xffff;
static const size_t FNAME_LEN=23;
struct Directory {
char name[FNAME_LEN+1];
unsigned char attr;
unsigned char resv;
uint16_t chain;
uint32_t size;
};
struct PffsMaster {
uint32_t ptr;
uint32_t resv;
char signature[24];
Directory directory[MAXDIR];
uint16_t fat_chain[MAXFAT];
} master_block_ __attribute__ ((packed)) ;
Device &dev_;
void load();
void update(); // 変更をむこーに反映させる
Directory *searchFile( const char *fname );
Directory *freeDir();
static const int SECTOR_SIZE=4096;
bool dirty_;
void removeFile( Directory *d );
inline int need_block( size_t filesize );
void makeChain( uint16_t *pchain, int blkcnt, int next );
public:
class File {
Fs &fs_;
uint16_t chain_top_;
uint16_t chain_now_;
int count_;
int size_;
uint32_t pffs_top_;
void nextSector();
public:
File( Fs &fat, const char *fname );
void download( std::FILE *out );
void upload( std::FILE *in );
void readSector( char buf[], size_t len );
void writeSector( const char buf[], size_t len );
};
Fs( Device &dev )
: dev_(dev), dirty_(false)
{
load();
}
~Fs();
void removeFile( const char *fname );
void dumpDir();
void createFile( const char *fname, size_t len );
size_t getFreeBlockCount( );
void format( );
};
}
}
#endif