Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_system_defines.h « fs « pastilda « emb - github.com/thirdpin/pastilda.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b5028646dcfe25e38bd26a35d372832d044a7ce5 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * This file is part of the pastilda project.
 * hosted at http://github.com/thirdpin/pastilda
 *
 * Copyright (C) 2016  Third Pin LLC
 *
 * Written by:
 *  Anastasiia Lazareva <a.lazareva@thirdpin.ru>
 *	Dmitrii Lisin <mrlisdim@ya.ru>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef FILE_SYSTEM_DEFINES_H
#define FILE_SYSTEM_DEFINES_H

#include <fs/drv/SST25.h>
#include <string.h>
#include "spi_ext.h"

typedef enum
{
	READ,
	WRITE
}MemoryCommand;

struct UsbMemoryControlParams {
	const int block_count;
	int (*read_block_func)(uint32_t lba, uint8_t *copy_to);
	int (*write_block_func)(uint32_t lba, const uint8_t *copy_from);
};

struct FatMemoryControlParams {
	int (*access_memory_func)(MemoryCommand cmd, uint32_t sector, uint32_t count, void *buf);
};

constexpr uint16_t FAKE_SECTOR_COUNT                       = 2048;//(MEMORY_SIZE / FAKE_SECTOR_SIZE);

constexpr uint8_t JUMP_BOOT_SIZE 							= 3;
constexpr uint8_t JUMP_BOOT_VALUE[JUMP_BOOT_SIZE] 			= {0xEB, 0xFF, 0x90};
constexpr uint8_t OEM_NAME_SIZE 							= 8;
constexpr uint8_t OEM_NAME_VALUE[OEM_NAME_SIZE] 			= {'M','S','W','I','N','4','.','1'};
constexpr uint16_t BYTES_PER_SECTOR 						= 512;
constexpr uint8_t SECTORS_PER_CLUSTER 						= 8;
constexpr uint16_t RESERVED_SECTORS  						= 1;
constexpr uint8_t FAT_COUNT   								= 2;
constexpr uint16_t ROOT_ENTRY_COUNT 						= 512;
constexpr uint16_t TOTAL_SECTORS_COUNT_FAT16 				= 2048;//16384;
constexpr uint8_t REMOVABLE_MEDIA 							= 0xF8;
constexpr uint16_t SECTORS_PER_FAT 							= 1;
constexpr uint16_t SECTORS_PER_TRACK 						= 0;
constexpr uint16_t NUMBER_OF_HEADS 							= 0;
constexpr uint32_t HIDDEN_SECTORS_COUNT 					= 0;
constexpr uint32_t TOTAL_SECTORS_COUNT_FAT32 				= 0;
constexpr uint8_t DRIVE_NUMBER 								= 0x80;
constexpr uint8_t BOOT_SIGNATURE 							= 0x29;
constexpr uint32_t VOL_SERIAL_NUMBER 						= 0xC4B1CDCF;
constexpr uint8_t VOLUME_LABLE_SIZE 						= 11;
constexpr uint8_t VOLUME_LABLE_VALUE[VOLUME_LABLE_SIZE]   	= {'N','O',' ','N','A','M','E',' ',' ',' ',' '};
constexpr uint8_t FS_TYPE_SIZE                              = 8;
constexpr uint8_t FS_TYPE_VALUE[FS_TYPE_SIZE] 				= {'F','A','T',' ','1','2',' ',' '};
constexpr uint16_t SIGNATURE               					= 0xAA55;

constexpr uint8_t BPB_OFFSET 								= 0;
constexpr uint16_t PARTITION_OFFSET 						= 446;
constexpr uint16_t SIGNATURE_OFFSET 						= 510;

constexpr uint8_t MBR_SECTOR 								= 0;
constexpr uint8_t MBR_SECTORS_COUNT 						= 1;

constexpr uint8_t FAT1_SECTOR 								= 1;
constexpr uint8_t FAT_SECTORS_COUNT 						= 1;
constexpr uint16_t BYTES_PER_FAT 							= (FAT_SECTORS_COUNT * BYTES_PER_SECTOR);
constexpr uint8_t FAT2_SECTOR 								= (FAT1_SECTOR + FAT_SECTORS_COUNT);
constexpr uint8_t FAT_HEADER_SIZE 							= 4;
constexpr uint8_t FAT_HEADER[FAT_HEADER_SIZE] 				= {0xF8, 0xFF, 0xFF, 0xFF};

constexpr uint8_t ROOT_SECTOR 								= (FAT2_SECTOR + FAT_SECTORS_COUNT);
constexpr uint8_t ROOT_SECTORS_COUNT 						= 32;
constexpr uint16_t BYTES_PER_ROOT 							= (ROOT_SECTORS_COUNT * BYTES_PER_SECTOR);

constexpr uint8_t  NUMBER_OF_CHARS      					= 30;
constexpr uint8_t  NUMBER_OF_FILES      					= 50;

#pragma pack (push, 1)
typedef struct {
	uint8_t  jump_boot[JUMP_BOOT_SIZE];
	uint8_t  oem_name[OEM_NAME_SIZE];
	uint16_t bytes_per_sector;
	uint8_t  sectors_per_cluster;
	uint16_t reserved_sectors_count;
	uint8_t  num_fats;
	uint16_t root_entry_count;
	uint16_t total_sectors_fat16;
	uint8_t  media;
	uint16_t fat16_size;
	uint16_t sector_per_track;
	uint16_t number_of_heads;
	uint32_t count_of_hidden_sectors;
	uint32_t total_sectors_fat32;
}Bpb_base;

typedef struct {
	Bpb_base bpb_base;
	uint8_t  drive_number;
	uint8_t  reserved_1;
	uint8_t  boot_signature;
	uint32_t volume_serial_number;
	uint8_t  volume_label[VOLUME_LABLE_SIZE];
	uint8_t  filesystem_type[FS_TYPE_SIZE];
}Bpb_fat12_16;

typedef struct {
	uint8_t bootable;
	uint8_t first_head;
	uint8_t first_sector;
	uint8_t first_cylinder;
	uint8_t type;
	uint8_t last_head;
	uint8_t last_sector;
	uint8_t last_cylinder;
	uint32_t first_lba;
	uint32_t sector_count;
}Partition;
#pragma pack (pop)

typedef enum {
	FAT12            = 0x01,
	FAT16_UNDER_32MB = 0x04,
	FAT16            = 0x06,
	FAT32            = 0x0B,
	FAT32_LBA        = 0x0C
}PartitionType;

typedef enum {
	PARTITION_ACTIVE   = 0x80,
	PARTITION_INACTIVE = 0x00
}Bootable;

typedef enum {
	FAT_READY,
	FAT_ERROR
}FatState;

typedef enum : uint8_t {
	OK    = 0,
	ERROR = 1
}Result;

#endif