]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/Lib/fat_io_lib/fat_filelib.h
update Russian and Bengali languages.json (#2167)
[Ventoy.git] / Plugson / src / Lib / fat_io_lib / fat_filelib.h
1 #ifndef __FAT_FILELIB_H__
2 #define __FAT_FILELIB_H__
3
4 #include "fat_opts.h"
5 #include "fat_access.h"
6 #include "fat_list.h"
7
8 //-----------------------------------------------------------------------------
9 // Defines
10 //-----------------------------------------------------------------------------
11 #ifndef SEEK_CUR
12 #define SEEK_CUR 1
13 #endif
14
15 #ifndef SEEK_END
16 #define SEEK_END 2
17 #endif
18
19 #ifndef SEEK_SET
20 #define SEEK_SET 0
21 #endif
22
23 #ifndef EOF
24 #define EOF (-1)
25 #endif
26
27 //-----------------------------------------------------------------------------
28 // Structures
29 //-----------------------------------------------------------------------------
30 struct sFL_FILE;
31
32 struct cluster_lookup
33 {
34 uint32 ClusterIdx;
35 uint32 CurrentCluster;
36 };
37
38 typedef struct sFL_FILE
39 {
40 uint32 parentcluster;
41 uint32 startcluster;
42 uint32 bytenum;
43 uint32 filelength;
44 int filelength_changed;
45 char path[FATFS_MAX_LONG_FILENAME];
46 char filename[FATFS_MAX_LONG_FILENAME];
47 uint8 shortfilename[11];
48
49 #ifdef FAT_CLUSTER_CACHE_ENTRIES
50 uint32 cluster_cache_idx[FAT_CLUSTER_CACHE_ENTRIES];
51 uint32 cluster_cache_data[FAT_CLUSTER_CACHE_ENTRIES];
52 #endif
53
54 // Cluster Lookup
55 struct cluster_lookup last_fat_lookup;
56
57 // Read/Write sector buffer
58 uint8 file_data_sector[FAT_SECTOR_SIZE];
59 uint32 file_data_address;
60 int file_data_dirty;
61
62 // File fopen flags
63 uint8 flags;
64 #define FILE_READ (1 << 0)
65 #define FILE_WRITE (1 << 1)
66 #define FILE_APPEND (1 << 2)
67 #define FILE_BINARY (1 << 3)
68 #define FILE_ERASE (1 << 4)
69 #define FILE_CREATE (1 << 5)
70
71 struct fat_node list_node;
72 } FL_FILE;
73
74 //-----------------------------------------------------------------------------
75 // Prototypes
76 //-----------------------------------------------------------------------------
77
78 // External
79 void fl_init(void);
80 void fl_attach_locks(void (*lock)(void), void (*unlock)(void));
81 int fl_attach_media(fn_diskio_read rd, fn_diskio_write wr);
82 void fl_shutdown(void);
83
84 // Standard API
85 void* fl_fopen(const char *path, const char *modifiers);
86 void fl_fclose(void *file);
87 int fl_fflush(void *file);
88 int fl_fgetc(void *file);
89 char * fl_fgets(char *s, int n, void *f);
90 int fl_fputc(int c, void *file);
91 int fl_fputs(const char * str, void *file);
92 int fl_fwrite(const void * data, int size, int count, void *file );
93 int fl_fread(void * data, int size, int count, void *file );
94 int fl_fseek(void *file , long offset , int origin );
95 int fl_fgetpos(void *file , uint32 * position);
96 long fl_ftell(void *f);
97 int fl_feof(void *f);
98 int fl_remove(const char * filename);
99
100 // Equivelant dirent.h
101 typedef struct fs_dir_list_status FL_DIR;
102 typedef struct fs_dir_ent fl_dirent;
103
104 FL_DIR* fl_opendir(const char* path, FL_DIR *dir);
105 int fl_readdir(FL_DIR *dirls, fl_dirent *entry);
106 int fl_closedir(FL_DIR* dir);
107
108 // Extensions
109 void fl_listdirectory(const char *path);
110 int fl_createdirectory(const char *path);
111 int fl_is_dir(const char *path);
112
113 int fl_format(uint32 volume_sectors, const char *name);
114
115 // Test hooks
116 #ifdef FATFS_INC_TEST_HOOKS
117 struct fatfs* fl_get_fs(void);
118 #endif
119
120 //-----------------------------------------------------------------------------
121 // Stdio file I/O names
122 //-----------------------------------------------------------------------------
123 #ifdef USE_FILELIB_STDIO_COMPAT_NAMES
124
125 #define FILE FL_FILE
126
127 #define fopen(a,b) fl_fopen(a, b)
128 #define fclose(a) fl_fclose(a)
129 #define fflush(a) fl_fflush(a)
130 #define fgetc(a) fl_fgetc(a)
131 #define fgets(a,b,c) fl_fgets(a, b, c)
132 #define fputc(a,b) fl_fputc(a, b)
133 #define fputs(a,b) fl_fputs(a, b)
134 #define fwrite(a,b,c,d) fl_fwrite(a, b, c, d)
135 #define fread(a,b,c,d) fl_fread(a, b, c, d)
136 #define fseek(a,b,c) fl_fseek(a, b, c)
137 #define fgetpos(a,b) fl_fgetpos(a, b)
138 #define ftell(a) fl_ftell(a)
139 #define feof(a) fl_feof(a)
140 #define remove(a) fl_remove(a)
141 #define mkdir(a) fl_createdirectory(a)
142 #define rmdir(a) 0
143
144 #endif
145
146 #endif