]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - vtoycli/fat_io_lib/include/fat_misc.h
Support TrueNAS Scale (Linux) distro. (#3069 #3137)
[Ventoy.git] / vtoycli / fat_io_lib / include / fat_misc.h
1 #ifndef __FAT_MISC_H__
2 #define __FAT_MISC_H__
3
4 #include "fat_defs.h"
5 #include "fat_opts.h"
6
7 //-----------------------------------------------------------------------------
8 // Defines
9 //-----------------------------------------------------------------------------
10 #define MAX_LONGFILENAME_ENTRIES 20
11 #define MAX_LFN_ENTRY_LENGTH 13
12
13 //-----------------------------------------------------------------------------
14 // Macros
15 //-----------------------------------------------------------------------------
16 #define GET_32BIT_WORD(buffer, location) ( ((uint32)buffer[location+3]<<24) + ((uint32)buffer[location+2]<<16) + ((uint32)buffer[location+1]<<8) + (uint32)buffer[location+0] )
17 #define GET_16BIT_WORD(buffer, location) ( ((uint16)buffer[location+1]<<8) + (uint16)buffer[location+0] )
18
19 #define SET_32BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \
20 buffer[location+1] = (uint8)((value>>8)&0xFF); \
21 buffer[location+2] = (uint8)((value>>16)&0xFF); \
22 buffer[location+3] = (uint8)((value>>24)&0xFF); }
23
24 #define SET_16BIT_WORD(buffer, location, value) { buffer[location+0] = (uint8)((value)&0xFF); \
25 buffer[location+1] = (uint8)((value>>8)&0xFF); }
26
27 //-----------------------------------------------------------------------------
28 // Structures
29 //-----------------------------------------------------------------------------
30 struct lfn_cache
31 {
32 #if FATFS_INC_LFN_SUPPORT
33 // Long File Name Structure (max 260 LFN length)
34 uint8 String[MAX_LONGFILENAME_ENTRIES][MAX_LFN_ENTRY_LENGTH];
35 uint8 Null;
36 #endif
37 uint8 no_of_strings;
38 };
39
40 //-----------------------------------------------------------------------------
41 // Prototypes
42 //-----------------------------------------------------------------------------
43 void fatfs_lfn_cache_init(struct lfn_cache *lfn, int wipeTable);
44 void fatfs_lfn_cache_entry(struct lfn_cache *lfn, uint8 *entryBuffer);
45 char* fatfs_lfn_cache_get(struct lfn_cache *lfn);
46 int fatfs_entry_lfn_text(struct fat_dir_entry *entry);
47 int fatfs_entry_lfn_invalid(struct fat_dir_entry *entry);
48 int fatfs_entry_lfn_exists(struct lfn_cache *lfn, struct fat_dir_entry *entry);
49 int fatfs_entry_sfn_only(struct fat_dir_entry *entry);
50 int fatfs_entry_is_dir(struct fat_dir_entry *entry);
51 int fatfs_entry_is_file(struct fat_dir_entry *entry);
52 int fatfs_lfn_entries_required(char *filename);
53 void fatfs_filename_to_lfn(char *filename, uint8 *buffer, int entry, uint8 sfnChk);
54 void fatfs_sfn_create_entry(char *shortfilename, uint32 size, uint32 startCluster, struct fat_dir_entry *entry, int dir);
55 int fatfs_lfn_create_sfn(char *sfn_output, char *filename);
56 int fatfs_lfn_generate_tail(char *sfn_output, char *sfn_input, uint32 tailNum);
57 void fatfs_convert_from_fat_time(uint16 fat_time, int *hours, int *minutes, int *seconds);
58 void fatfs_convert_from_fat_date(uint16 fat_date, int *day, int *month, int *year);
59 uint16 fatfs_convert_to_fat_time(int hours, int minutes, int seconds);
60 uint16 fatfs_convert_to_fat_date(int day, int month, int year);
61 void fatfs_print_sector(uint32 sector, uint8 *data);
62
63 #endif