VSF Documented
vsf_fatfs.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_FATFS_H__
19#define __VSF_FATFS_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "../../vsf_fs_cfg.h"
24
25#if VSF_USE_FS == ENABLED && (VSF_FS_USE_FATFS == ENABLED || VSF_FS_USE_EXFATFS == ENABLED)
26
27#include "../malfs/vsf_malfs.h"
28
29#if defined(__VSF_FATFS_CLASS_IMPLEMENT)
30# undef __VSF_FATFS_CLASS_IMPLEMENT
31# define __VSF_CLASS_IMPLEMENT__
32#endif
33
34#include "utilities/ooc_class.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*============================ MACROS ========================================*/
41
42#define implement_fatfs_info(__block_size, __cache_num) \
43 implement(__vk_fatfs_info_t) \
44 __implement_malfs_cache(__block_size, __cache_num)
45
46#define init_fatfs_info_ex(__info, __block_size, __cache_num, __fatinfo) \
47 do { \
48 __fatinfo->block_size = __block_size; \
49 __fatinfo->cache.number = __cache_num; \
50 __fatinfo->cache.nodes = __info->__cache_nodes; \
51 } while (0)
52
53#define init_fatfs_info(__info, __block_size, __cache_num) \
54 .block_size = __block_size, \
55 .cache = { \
56 .number = __cache_num, \
57 .nodes = __info.__cache_nodes, \
58 },
59
60/*============================ MACROFIED FUNCTIONS ===========================*/
61/*============================ TYPES =========================================*/
62
65
66#if VSF_FS_USE_EXFATFS == ENABLED
68#else
70#endif
71
72typedef enum vk_fat_type_t {
79
80typedef enum vk_fat_file_attr_t {
85
88 char *filename;
92
93 // private
98
99 union {
100 struct {
103#if VSF_FS_USE_EXFATFS == ENABLED
104 struct {
110#endif
112 };
114
115typedef struct vk_fatfs_file_pos_t {
120
122 public_member(
123 implement(__vk_malfs_file_t)
124 )
125
126 private_member(
127 uint32_t first_cluster;
129 struct {
130 vk_fat_sector_type_t sector0;
131 vk_fat_sector_type_t sector1;
132 uint8_t entry_num;
133 uint8_t entry_offset_in_sector0;
134
135 // vital sector/entry_offset is the entry containing first_cluster/size
136 // for fat, should be the last entry
137 // for exfat, should be the stream entry
138 uint8_t vital_sector;
139 uint8_t vital_entry_offset;
140#if VSF_FS_USE_EXFATFS == ENABLED
141 // root 0/entry_offset is the entry for Critical Primary Directory Entries of exfat
142 uint8_t root_entry_offset;
143#endif
144 } dentry;
146};
147
148// memory layout:
149// |-----------------------|
150// | __vk_fatfs_info_t: |<-|
151// | |-------------------| | |
152// | | ... | | |
153// | |-------------------| | |
154// | ||__vk_malfs_info_t|| | |
155// | ||-----------------|| | |
156// | || total_cb ||-|--- if __vk_fatfs_info_t is dynamically allocated,
157// | ||-----------------|| | total_cb in __vk_malfs_info_t points to the __vk_fatfs_info_t.
158// |-----------------------| so in __vk_malfs_unmount, can free total_cb
159// | vk_malfs_cache_t[num] |
160// |-----------------------|
161// | cache_buffer[num] |
162// |-----------------------|
164 private_member(
165 vk_fatfs_file_t root;
167#if VSF_FS_USE_EXFATFS == ENABLED
168 char fat_volume_name[24];
169#else
170 char fat_volume_name[12];
171#endif
172
173 // fat parameters, will not change after mount
174#if VSF_FS_USE_EXFATFS == ENABLED
175 uint32_t bitmap_sector;
176 uint32_t bitmap_size;
177#endif
178 uint32_t root_sector;
179 uint32_t root_size;
180 uint32_t fat_sector;
181 uint32_t fat_size;
182 uint32_t data_sector;
183 uint32_t cluster_num;
184 uint8_t sector_size_bits;
185 uint8_t cluster_size_bits;
186 uint8_t fat_num;
187 )
188
189 // vk_malfs_info_t must be the last in vk_fatfs_info_t
190 public_member(
191 implement(__vk_malfs_info_t)
192 )
193};
194
195/*============================ GLOBAL VARIABLES ==============================*/
196
197extern const vk_fs_op_t vk_fatfs_op;
198
199/*============================ PROTOTYPES ====================================*/
200
201extern bool vk_fatfs_is_lfn(char *name);
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif // VSF_USE_FS && VSF_FS_USE_FATFS
209#endif // __VSF_FATFS_H__
Definition vsf_fatfs.h:163
Definition vsf_malfs.h:83
Definition vsf_malfs.h:98
Definition vsf_fatfs.h:121
Definition vsf_fs.h:92
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
short int16_t
Definition stdint.h:6
unsigned long long uint64_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_fatfs.h:86
char * filename
Definition vsf_fatfs.h:88
struct vk_fatfs_dentry_parser_t::@14::@17 exfat
uint8_t lfn
Definition vsf_fatfs.h:101
bool is_unicode
Definition vsf_fatfs.h:94
uint32_t zero_before_first_call
Definition vsf_fatfs.h:111
int16_t vital_entry_num
Definition vsf_fatfs.h:91
uint16_t node_parsed_num
Definition vsf_fatfs.h:90
int16_t entry_num
Definition vsf_fatfs.h:89
struct vk_fatfs_dentry_parser_t::@14::@16 fat
uint8_t namelen
Definition vsf_fatfs.h:105
uint8_t entry_num
Definition vsf_fatfs.h:107
uint8_t attr
Definition vsf_fatfs.h:95
uint64_t size
Definition vsf_fatfs.h:97
uint8_t * entry
Definition vsf_fatfs.h:87
uint32_t first_cluster
Definition vsf_fatfs.h:96
int16_t root_entry_num
Definition vsf_fatfs.h:108
uint8_t namepos
Definition vsf_fatfs.h:106
Definition vsf_fatfs.h:115
uint32_t sector_offset_in_cluster
Definition vsf_fatfs.h:117
uint32_t cluster
Definition vsf_fatfs.h:116
uint32_t offset_in_sector
Definition vsf_fatfs.h:118
vk_av_control_type_t type
Definition vsf_audio.h:170
bool vk_fatfs_parse_dentry_fat(vk_fatfs_dentry_parser_t *parser)
Definition vsf_fatfs.c:609
bool vk_fatfs_is_lfn(char *name)
Definition vsf_fatfs.c:320
vk_fat_type_t
Definition vsf_fatfs.h:72
@ VSF_FAT_32
Definition vsf_fatfs.h:76
@ VSF_FAT_12
Definition vsf_fatfs.h:74
@ VSF_FAT_EX
Definition vsf_fatfs.h:77
@ VSF_FAT_NONE
Definition vsf_fatfs.h:73
@ VSF_FAT_16
Definition vsf_fatfs.h:75
uint64_t vk_fat_sector_type_t
Definition vsf_fatfs.h:67
const vk_fs_op_t vk_fatfs_op
vk_fat_file_attr_t
Definition vsf_fatfs.h:80
@ VSF_FAT_FILE_ATTR_SYSTEM
Definition vsf_fatfs.h:82
@ VSF_FAT_FILE_ATTR_ARCHIVE
Definition vsf_fatfs.h:83
@ VSF_FAT_FILE_ATTR_VOLUMID
Definition vsf_fatfs.h:81
@ VSF_FILE_ATTR_EXT
Definition vsf_fs_cfg.h:108