File System Component  Version 6.14.1
MDK Middleware for Devices with Flash File System
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
rl_fs.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  * MDK Middleware - Component ::File System
3  * Copyright (c) 2004-2020 Arm Limited (or its affiliates). All rights reserved.
4  *------------------------------------------------------------------------------
5  * Name: rl_fs.h
6  * Purpose: File System API
7  *----------------------------------------------------------------------------*/
8 
9 #ifndef __RL_FS_H
10 #define __RL_FS_H
11 
12 #include <stdint.h>
13 #include <stdbool.h>
14 
15 // ==== Enumeration, structures, defines ====
16 
18 #define FS_FAT_ATTR_READ_ONLY 0x01
19 #define FS_FAT_ATTR_HIDDEN 0x02
20 #define FS_FAT_ATTR_SYSTEM 0x04
21 #define FS_FAT_ATTR_VOLUME_ID 0x08
22 #define FS_FAT_ATTR_DIRECTORY 0x10
23 #define FS_FAT_ATTR_ARCHIVE 0x20
24 
25 #define FS_MEDIA_INSERTED 0x01
27 #define FS_MEDIA_PROTECTED 0x02
28 #define FS_MEDIA_INITIALIZED 0x04
29 #define FS_MEDIA_NOCHKMEDIA 0x80
30 
31 #define FS_CONTROL_MEDIA_INIT 0x00
33 #define FS_CONTROL_EMMC_SLEEP 0x01
34 #define FS_CONTROL_EMMC_AWAKE 0x02
35 
36 #define FS_DEVICE_SET_PASSWORD 0x01
38 #define FS_DEVICE_CLR_PASSWORD 0x02
39 #define FS_DEVICE_LOCK_UNLOCK 0x04
40 #define FS_DEVICE_ERASE 0x08
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
47 typedef enum {
48  fsOK = 0,
66 } fsStatus;
67 
69 typedef enum _fsType {
70  fsTypeNone = 0,
76 } fsType;
77 
79 typedef enum _fsDevCtrlCode {
88 
90 typedef struct _fsMediaInfo {
91  uint32_t block_cnt;
92  uint16_t read_blen;
93  uint16_t write_blen;
94 } fsMediaInfo;
95 
97 typedef struct _fsIOC_Cache {
98  uint8_t *buffer;
99  uint32_t size;
100 } fsIOC_Cache;
101 
103 typedef struct _fsCID_Register {
104  uint32_t PSN;
105  uint16_t OID;
106  uint8_t MID;
107  uint8_t PRV;
108  uint16_t MDT;
109  uint8_t PNM[6];
111 
112 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
113  #pragma clang diagnostic push
114  #pragma clang diagnostic ignored "-Wpadded"
115 #endif
116 
118 typedef struct {
119  uint8_t const *password;
120  uint8_t length;
121  uint8_t flags;
122 } fsLockUnlock;
123 
125 typedef struct {
126  uint32_t arg;
127  uint8_t *buf;
128  uint32_t buf_sz;
130 
132 typedef struct _fsTime {
133  uint8_t hr;
134  uint8_t min;
135  uint8_t sec;
136  uint8_t day;
137  uint8_t mon;
138  uint16_t year;
139 } fsTime;
140 
142 typedef struct _fsFileInfo {
143  char name[256];
144  uint32_t size;
145  uint16_t fileID;
146  uint8_t attrib;
148 } fsFileInfo;
149 
151 typedef struct _fsDriveInfo {
153  uint64_t capacity;
154 } fsDriveInfo;
155 
156 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
157  #pragma clang diagnostic pop
158 #endif
159 
160 // ==== System Routines ====
161 
170 extern fsStatus finit (const char *drive);
171 
179 extern fsStatus funinit (const char *drive);
180 
192 extern fsStatus fmount (const char *drive);
193 
200 extern fsStatus funmount (const char *drive);
201 
204 extern uint32_t fversion (void);
205 
206 // ==== File Maintenance Routines ====
207 
212 #ifdef MW_FILESYSTEM_FDELETE_LEGACY
213 extern fsStatus fdelete (const char *path);
214 #else
215 extern fsStatus fdelete (const char *path, const char *options);
216 #endif
217 
218 
228 extern fsStatus ffind (const char *pattern, fsFileInfo *info);
229 
234 extern fsStatus frename (const char *path, const char *newname);
235 
248 extern fsStatus fattrib (const char *path, const char *attr);
249 
250 
251 // ==== Directory Maintenance Routines ====
252 
258 extern fsStatus fpwd (const char *drive, char *buf, uint32_t len);
259 
263 extern fsStatus fchdir (const char *path);
264 
268 extern fsStatus fmkdir (const char *path);
269 
274 extern fsStatus frmdir (const char *path, const char *options);
275 
276 
277 // ==== Utility Routines ====
278 
282 extern fsStatus fchdrive (const char *drive);
283 
289 extern int64_t ffree (const char *drive);
290 
295 extern fsStatus fformat (const char *drive, const char *options);
296 
303 extern int32_t fanalyse (const char *drive);
304 
313 extern fsStatus fcheck (const char *drive);
314 
323 extern fsStatus fdefrag (const char *drive);
324 
333 extern fsStatus fmedia (const char *drive);
334 
343 extern fsStatus finfo (const char *drive, fsDriveInfo *info);
344 
358 extern fsStatus fvol (const char *drive, char *label, uint32_t *serial);
359 
360 
361 // ==== File Time Support Routines ====
362 
370 extern fsStatus ftime_set (const char *path, fsTime *create, fsTime *access, fsTime *write);
371 
379 extern fsStatus ftime_get (const char *path, fsTime *create, fsTime *access, fsTime *write);
380 
387 extern fsStatus fs_get_time (fsTime *time);
388 
389 
390 // ==== Media Support Routines ====
391 
396 extern int32_t fs_mc_read_cd (uint32_t drive_num);
397 
402 extern int32_t fs_mc_read_wp (uint32_t drive_num);
403 
411 extern int32_t fs_mc_spi_control_ss (uint32_t drive_num, uint32_t ss);
412 
417 extern fsLockUnlock *fs_mc_lock_unlock (uint32_t drive_num);
418 
419 
420 // ==== I/O Control Interface Routines ====
421 
427 extern int32_t fs_ioc_get_id (const char *drive);
428 
435 extern fsStatus fs_ioc_lock (int32_t drv_id);
436 
443 extern fsStatus fs_ioc_unlock (int32_t drv_id);
444 
453 extern fsStatus fs_ioc_get_cache (int32_t drv_id, fsIOC_Cache *cache_info);
454 
466 extern fsStatus fs_ioc_read_sector (int32_t drv_id, uint32_t sect, uint8_t *buf, uint32_t cnt);
467 
479 extern fsStatus fs_ioc_write_sector (int32_t drv_id, uint32_t sect, const uint8_t *buf, uint32_t cnt);
480 
490 extern fsStatus fs_ioc_read_info (int32_t drv_id, fsMediaInfo *info);
491 
497 extern fsStatus fs_ioc_device_ctrl (int32_t drv_id, fsDevCtrlCode code, void *p);
498 
499 #ifdef __cplusplus
500 }
501 #endif
502 
503 #endif /* __RL_FS_H */
fsStatus fdefrag(const char *drive)
Defragment Embedded Flash drive.
fsStatus fpwd(const char *drive, char *buf, uint32_t len)
Print working directory.
Media information.
Definition: rl_fs.h:90
fsStatus fmkdir(const char *path)
Create a directory.
fsStatus fs_ioc_write_sector(int32_t drv_id, uint32_t sect, const uint8_t *buf, uint32_t cnt)
Write sector to media.
File system type is unknown.
Definition: rl_fs.h:71
uint8_t * buf
Data buffer.
Definition: rl_fs.h:127
uint32_t size
Cache Buffer size in bytes.
Definition: rl_fs.h:99
Media error.
Definition: rl_fs.h:57
The directory is not empty.
Definition: rl_fs.h:62
fsStatus ftime_get(const char *path, fsTime *create, fsTime *access, fsTime *write)
Get file or directory timestamp.
uint16_t year
Year [1980..2107].
Definition: rl_fs.h:138
int32_t fs_mc_read_wp(uint32_t drive_num)
Callback function used to read Write Protect (WP) pin state when Memory Card is used in SPI mode...
fsStatus fmedia(const char *drive)
Check if media present on removable drive.
File system type is EFS.
Definition: rl_fs.h:75
uint8_t attrib
Attributes.
Definition: rl_fs.h:146
fsLockUnlock * fs_mc_lock_unlock(uint32_t drive_num)
Callback function used to retrieve password management information in order to manage locked memory c...
uint32_t buf_sz
Data buffer size in bytes.
Definition: rl_fs.h:128
File or directory already exists.
Definition: rl_fs.h:64
No file system (volume unformatted)
Definition: rl_fs.h:70
Too many open files.
Definition: rl_fs.h:63
File system type is FAT16.
Definition: rl_fs.h:73
uint16_t fileID
System Identification.
Definition: rl_fs.h:145
uint8_t flags
Operation definition bitmask.
Definition: rl_fs.h:121
uint32_t block_cnt
Total number of blocks on the volume.
Definition: rl_fs.h:91
Read/write error.
Definition: rl_fs.h:56
fsStatus fs_ioc_read_info(int32_t drv_id, fsMediaInfo *info)
Read media configuration info.
fsStatus ftime_set(const char *path, fsTime *create, fsTime *access, fsTime *write)
Set file or directory timestamp.
fsStatus fs_get_time(fsTime *time)
Callback function used to provide the current date and time to the File System.
File system type is FAT12.
Definition: rl_fs.h:72
int32_t fanalyse(const char *drive)
Analyse volume and check for file fragmentation.
uint64_t capacity
Drives capacity in bytes.
Definition: rl_fs.h:153
fsStatus finit(const char *drive)
Initialize File System and drive related driver.
fsStatus
File System return codes.
Definition: rl_fs.h:47
fsStatus fs_ioc_read_sector(int32_t drv_id, uint32_t sect, uint8_t *buf, uint32_t cnt)
Read sector from media.
fsStatus fs_ioc_device_ctrl(int32_t drv_id, fsDevCtrlCode code, void *p)
IOC device control access; control code is sent directly to device driver.
fsStatus finfo(const char *drive, fsDriveInfo *info)
Read drive information.
Control Media Device.
Definition: rl_fs.h:81
Unspecified error.
Definition: rl_fs.h:49
Check Media Status.
Definition: rl_fs.h:80
int32_t fs_mc_read_cd(uint32_t drive_num)
Callback function used to read Card Detect (CD) pin state when Memory Card is used in SPI mode...
fsStatus funinit(const char *drive)
Uninitialize File System.
uint32_t PSN
Product serial number.
Definition: rl_fs.h:104
uint8_t mon
Month [1..12].
Definition: rl_fs.h:137
Invalid parameter specified.
Definition: rl_fs.h:52
uint8_t MID
Manufacturer ID.
Definition: rl_fs.h:106
int32_t fs_ioc_get_id(const char *drive)
Check if valid drive is specified and return its ID.
fsStatus fchdrive(const char *drive)
Change current drive.
Operation succeeded.
Definition: rl_fs.h:48
Drive information.
Definition: rl_fs.h:151
uint8_t day
Day [1..31].
Definition: rl_fs.h:136
Drive is uninitialized.
Definition: rl_fs.h:55
Path is not a directory.
Definition: rl_fs.h:65
uint16_t MDT
Manufacturing date.
Definition: rl_fs.h:108
Manage device password protection.
Definition: rl_fs.h:85
File System Time structure.
Definition: rl_fs.h:132
File system type is FAT32.
Definition: rl_fs.h:74
fsStatus fs_ioc_lock(int32_t drv_id)
Lock drive and block media access to the upper layer.
Format Media at low level.
Definition: rl_fs.h:82
uint8_t hr
Hours [0..23].
Definition: rl_fs.h:133
fsType
File System Type.
Definition: rl_fs.h:69
Invalid path specified.
Definition: rl_fs.h:54
fsStatus frmdir(const char *path, const char *options)
Remove a directory.
uint8_t * buffer
Cache Buffer (4 byte aligned)
Definition: rl_fs.h:98
File information data.
Definition: rl_fs.h:142
fsStatus fvol(const char *drive, char *label, uint32_t *serial)
Read volume label and serial number.
fsStatus ffind(const char *pattern, fsFileInfo *info)
Find a file or directory matching search pattern.
Return device serial number.
Definition: rl_fs.h:83
uint8_t min
Minutes [0..59].
Definition: rl_fs.h:134
uint8_t length
Password length in bytes.
Definition: rl_fs.h:120
Access device health status (S.M.A.R.T)
Definition: rl_fs.h:86
fsStatus fformat(const char *drive, const char *options)
Format drive.
fsStatus fs_ioc_get_cache(int32_t drv_id, fsIOC_Cache *cache_info)
Return IOC cache buffer information.
Media lock/unlock information structure.
Definition: rl_fs.h:118
int64_t ffree(const char *drive)
Find free space on drive.
Health status access structure.
Definition: rl_fs.h:125
Nonexistent drive.
Definition: rl_fs.h:53
fsStatus fs_ioc_unlock(int32_t drv_id)
Unlock drive and allow media access to the upper layer.
fsStatus fchdir(const char *path)
Change working directory.
No free space available.
Definition: rl_fs.h:60
No media, or not initialized.
Definition: rl_fs.h:58
fsStatus fcheck(const char *drive)
Analyse volume and check for allocation errors.
uint32_t fversion(void)
Retrieve the File System component version.
Memory card CID register.
Definition: rl_fs.h:103
uint16_t read_blen
Read block length.
Definition: rl_fs.h:92
fsStatus fattrib(const char *path, const char *attr)
Change file attributes.
uint16_t write_blen
Write block length.
Definition: rl_fs.h:93
uint16_t OID
OEM/Application ID.
Definition: rl_fs.h:105
fsStatus fdelete(const char *path, const char *options)
Delete one or multiple files.
Read Memory Card CID Register.
Definition: rl_fs.h:84
uint8_t sec
Seconds [0..59].
Definition: rl_fs.h:135
uint8_t PRV
Product revision.
Definition: rl_fs.h:107
uint8_t const * password
Password data buffer.
Definition: rl_fs.h:119
uint32_t arg
Health status control argument.
Definition: rl_fs.h:126
fsTime time
Create/Modify Time.
Definition: rl_fs.h:147
fsStatus funmount(const char *drive)
Unmount drive.
Operation not supported.
Definition: rl_fs.h:50
IO Control Cache information.
Definition: rl_fs.h:97
fsStatus fmount(const char *drive)
Mount drive.
Resource access denied.
Definition: rl_fs.h:51
int32_t fs_mc_spi_control_ss(uint32_t drive_num, uint32_t ss)
Callback function used to control Slave Select signal when Memory Card is used in SPI mode...
fsDevCtrlCode
Driver DeviceCtrl parameter code.
Definition: rl_fs.h:79
fsType fs_type
Drives file system type.
Definition: rl_fs.h:152
File system is not formatted.
Definition: rl_fs.h:59
Requested file not found.
Definition: rl_fs.h:61
uint32_t size
File size in bytes.
Definition: rl_fs.h:144
fsStatus frename(const char *path, const char *newname)
Rename a file or directory with given path name to a new name.