215 lines
7.1 KiB
C
215 lines
7.1 KiB
C
#ifndef SDBlockData_h
|
|
#define SDBlockData_h
|
|
|
|
/*
|
|
|
|
Misc notes:
|
|
|
|
* Structure of all blocks:
|
|
* Block type
|
|
* Free form set of fields
|
|
* Free block to be used
|
|
* Status field - re-writable
|
|
* CRC32 - TODO, consider leaving status out of the CRC
|
|
(although only for time, as the block has to be in memory to change the status)
|
|
|
|
Sizes:
|
|
* 32 Bit blocks allows for up to 2000 GB of Storage
|
|
* Where as 32 Bit bytes (when moving an address) allows only 4GB
|
|
|
|
TODO:
|
|
|
|
* Status based searcher - like that being considered for Queues
|
|
* Find me next with Status X or bitmap or < or >
|
|
* But.... keep where we were up to to, so we don't have to serarh/load all them blocks again
|
|
* Consider this only for memory for now.
|
|
|
|
Notes on WII5
|
|
|
|
|
|
One Run = 40960 records. 15 Per Sector
|
|
2730 data packets
|
|
|
|
Total packets = 62500000
|
|
/ runs = 22893
|
|
|
|
4 per hour, 24 hours per day
|
|
238 days
|
|
|
|
2 Cards - actually = 476
|
|
|
|
So make it 150 days
|
|
14400 records
|
|
|
|
Data Size = 14400 * 2730 = 39312000 = 62%
|
|
|
|
Therefore Metadata minimum 14400, up to 20000
|
|
|
|
Queue - could have up to 8 messages per metadata, so 20000*8 = 160000
|
|
|
|
Number Start End Size Type File system Flags
|
|
1 2048s 1251327s 1249280s primary fat32 lba
|
|
|
|
|
|
sudo dd if=/dev/mmcblk2 of=block_fat1.img bs=512 count=1251328
|
|
|
|
|
|
*/
|
|
|
|
#define SDBLOCK_SECTOR_SIZE 512
|
|
|
|
// XXX Add super block information
|
|
// Bytes:
|
|
// 1 = Fixed = SDBlock, always 10101111
|
|
// 2 = Version of SDBlock, 00000001
|
|
// 3 = Block type & Bersion 1, 2, 3,4 + 1
|
|
#define SDBLOCK_TYPE_SDBLOCK 101
|
|
#define SDBLOCK_TYPE_SDBLOCK_VERSION 1
|
|
#define SDBLOCK_TYPE_ALLOCATION 1
|
|
#define SDBLOCK_TYPE_ALLOCATION_VERSION 1
|
|
#define SDBLOCK_TYPE_ALLOCATION_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_ALLOCATION << 8) | SDBLOCK_TYPE_ALLOCATION_VERSION)
|
|
#define SDBLOCK_TYPE_METADATA 2
|
|
#define SDBLOCK_TYPE_METADATA_VERSION 1
|
|
#define SDBLOCK_TYPE_METADATA_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_METADATA << 8) | SDBLOCK_TYPE_METADATA_VERSION)
|
|
#define SDBLOCK_TYPE_LOGLINES 3
|
|
#define SDBLOCK_TYPE_LOGLINES_VERSION 1
|
|
#define SDBLOCK_TYPE_LOGLINES_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_LOGLINES << 8) | SDBLOCK_TYPE_LOGLINES_VERSION)
|
|
#define SDBLOCK_TYPE_SINGLE 4
|
|
#define SDBLOCK_TYPE_SINGLE_VERSION 1
|
|
#define SDBLOCK_TYPE_SINGLE_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_SINGLE << 8) | SDBLOCK_TYPE_SINGLE_VERSION)
|
|
#define SDBLOCK_TYPE_BLOCK 5
|
|
#define SDBLOCK_TYPE_BLOCK_VERSION 1
|
|
#define SDBLOCK_TYPE_BLOCK_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_BLOCK << 8) | SDBLOCK_TYPE_BLOCK_VERSION)
|
|
#define SDBLOCK_TYPE_QUEUE 5
|
|
#define SDBLOCK_TYPE_QUEUE_VERSION 1
|
|
#define SDBLOCK_TYPE_QUEUE_FULL ((SDBLOCK_TYPE_SDBLOCK << 24) | (SDBLOCK_TYPE_SDBLOCK_VERSION << 16) | (SDBLOCK_TYPE_QUEUE << 8) | SDBLOCK_TYPE_QUEUE_VERSION)
|
|
|
|
|
|
// Special - Block Offset ! Where does this start
|
|
#define SDBLOCK_OFFSET (uint32_t)1300000 // Absolute position start of allocation table
|
|
#define SDBLOCK_MAX (uint32_t)62500000
|
|
#define SDBLOCK_ALLOCATION_MAX (uint32_t)2 // How many we can have
|
|
#define SDBLOCK_METADATA_MAX (uint32_t)20000 // How many we can have
|
|
#define SDBLOCK_SINGLE_MAX (uint32_t)20000 // How many we can have
|
|
#define SDBLOCK_LOGLINES_MAX (uint32_t)10000 // How many we can have
|
|
#define SDBLOCK_QUEUE_MAX (uint32_t)300000 // How many we can have
|
|
#define SDBLOCK_DATA_MAX (uint32_t)45000000 // How many we can have
|
|
|
|
#define SDBLOCK_ACTUAL_ALLOCATION (uint32_t)SDBLOCK_OFFSET
|
|
#define SDBLOCK_ACTUAL_METADATA (uint32_t)(SDBLOCK_OFFSET + SDBLOCK_ALLOCATION_MAX)
|
|
#define SDBLOCK_ACTUAL_SINGLE (uint32_t)(SDBLOCK_OFFSET + SDBLOCK_ALLOCATION_MAX + SDBLOCK_METADATA_MAX)
|
|
#define SDBLOCK_ACTUAL_LOGLINES (uint32_t)(SDBLOCK_OFFSET + SDBLOCK_ALLOCATION_MAX + SDBLOCK_METADATA_MAX + SDBLOCK_SINGLE_MAX)
|
|
#define SDBLOCK_ACTUAL_QUEUE (uint32_t)(SDBLOCK_OFFSET + SDBLOCK_ALLOCATION_MAX + SDBLOCK_METADATA_MAX + SDBLOCK_SINGLE_MAX + SDBLOCK_LOGLINES_MAX)
|
|
#define SDBLOCK_ACTUAL_DATA (uint32_t)(SDBLOCK_OFFSET + SDBLOCK_ALLOCATION_MAX + SDBLOCK_METADATA_MAX + SDBLOCK_SINGLE_MAX + SDBLOCK_LOGLINES_MAX + SDBLOCK_QUEUE_MAX)
|
|
|
|
// ALLOCATION Block
|
|
#define SDBLOCK_ALLOCATION_DATA_SIZE 460
|
|
typedef struct {
|
|
// 12
|
|
uint32_t blockType;
|
|
uint32_t deviceId; // Device and Record
|
|
uint32_t recordId; // In this case, it will be the last actually used one
|
|
uint32_t cardId; // In this case, it will be the last actually used one
|
|
|
|
// 16
|
|
time_t currentTime; // Last updated?
|
|
|
|
// 16
|
|
uint32_t metadataBlockNext; // And of course where is the Metadata
|
|
uint32_t singleBlockNext; // And of course where is the Metadata
|
|
uint32_t loglinesBlockNext; // And of course where is the Metadata
|
|
uint32_t dataBlockNext; // Next, becasue first record is 0, so initilaly we write there
|
|
|
|
uint32_t queueBlockNext; // Next, becasue first record is 0, so initilaly we write there
|
|
uint32_t queueHighDone; // What queue high have we done, read from here
|
|
uint32_t queueLowDone; // What queue low have we done, read from here
|
|
|
|
uint8_t data[SDBLOCK_ALLOCATION_DATA_SIZE]; // Calcu;ate
|
|
|
|
uint32_t crc;
|
|
} SDBlock_Allocation;
|
|
|
|
// METADATA Block
|
|
#define SDBLOCK_METADATA_DATA_SIZE 476
|
|
typedef struct {
|
|
// 12
|
|
uint32_t blockType;
|
|
uint32_t deviceId; // Device and Record
|
|
uint32_t recordId; // OR recordCount
|
|
|
|
// 8
|
|
uint32_t dataBlockStart; // DATA: Where does it start
|
|
uint32_t dataBlocks; // DATA: Number of blocks, 0 being none at all
|
|
|
|
// Keep these variables outside of this structure - see wii5Metadata
|
|
char data[SDBLOCK_METADATA_DATA_SIZE];
|
|
|
|
// 8
|
|
uint32_t resultsBlockStart; // RESULTS: Where does it start
|
|
uint32_t resultsBlocks; // RESULTS: Number of blocks, 0 being none at all
|
|
|
|
// 8
|
|
uint32_t status; // WII5 example - 0=NoResults, 1=Results, 4=Results+Sent, 5=
|
|
/*
|
|
|
|
uint8_t
|
|
. ?
|
|
. ?
|
|
. > 0 = Number of attempts sending - 1111 = Success
|
|
. > 0 = Data saved
|
|
*/
|
|
|
|
uint32_t crc;
|
|
} SDBlock_Metadata;
|
|
|
|
#define SDBLOCK_LOG_DATA_SIZE 42
|
|
#define SDBLOCK_LOG_DATA_LINES 10
|
|
|
|
// LogLine
|
|
typedef struct {
|
|
time_t logTime;
|
|
// NOTE: Most of these integers, normally 1 byte, are set to 4 bytes for packing.
|
|
uint32_t logLevel;
|
|
char data[SDBLOCK_LOG_DATA_SIZE];
|
|
} SDBlock_LogLine;
|
|
|
|
// LOG Block
|
|
typedef struct {
|
|
uint32_t blockType;
|
|
uint32_t recordId; // OR recordCount
|
|
|
|
SDBlock_LogLine lines[SDBLOCK_LOG_DATA_LINES];
|
|
|
|
uint32_t crc;
|
|
} SDBlock_LogLines;
|
|
|
|
#define SDBLOCK_QUEUE_DATAIN_SIZE 400
|
|
#define SDBLOCK_QUEUE_DATAOUT_SIZE 92
|
|
// Queue
|
|
typedef struct {
|
|
uint32_t blockType; // 4
|
|
// deviceId, recordId ?
|
|
|
|
time_t currentTime;
|
|
uint32_t priority;
|
|
char dataIn[SDBLOCK_QUEUE_DATAIN_SIZE];
|
|
char dataOut[SDBLOCK_QUEUE_DATAOUT_SIZE];
|
|
uint32_t status;
|
|
uint32_t crc;
|
|
} SDBlock_Queue;
|
|
|
|
// BLOCK - Let us make them all the same !
|
|
#define SDBLOCK_BLOCK_DATA_SIZE 496
|
|
typedef struct {
|
|
uint32_t blockType; // 4
|
|
// Note: deviceId etc can all be taken from Metadata.
|
|
uint32_t recordId; // Important to group these together.
|
|
|
|
uint8_t data[SDBLOCK_BLOCK_DATA_SIZE]; // All the data in the middle
|
|
|
|
uint32_t status;
|
|
uint32_t crc;
|
|
} SDBlock_Block;
|
|
|
|
#endif
|