mirror of
https://gitlab.com/c3d/db48x.git
synced 2024-09-29 05:36:58 +02:00
6399a1556a
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
154 lines
5.3 KiB
C
154 lines
5.3 KiB
C
/*
|
|
|
|
BSD 3-Clause License
|
|
|
|
Copyright (c) 2015-2022, SwissMicros
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
this list of conditions and the following disclaimer in the documentation
|
|
and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the copyright holder nor the names of its
|
|
contributors may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
The software and related material is released as “NOMAS” (NOt MAnufacturer Supported).
|
|
|
|
1. Info is released to assist customers using, exploring and extending the product
|
|
2. Do NOT contact the manufacturer with questions, seeking support, etc. regarding
|
|
NOMAS material as no support is implied or committed-to by the Manufacturer
|
|
3. The Manufacturer may reply and/or update materials if and when needed solely
|
|
at their discretion
|
|
|
|
*/
|
|
#ifndef __FF_IFC_H__
|
|
#define __FF_IFC_H__
|
|
|
|
|
|
|
|
/* These types MUST be 16-bit or 32-bit */
|
|
typedef int INT;
|
|
typedef unsigned int UINT;
|
|
|
|
/* This type MUST be 8-bit */
|
|
typedef unsigned char BYTE;
|
|
|
|
/* These types MUST be 16-bit */
|
|
typedef short SHORT;
|
|
typedef unsigned short WORD;
|
|
typedef unsigned short WCHAR;
|
|
|
|
/* These types MUST be 32-bit */
|
|
typedef long LONG;
|
|
typedef unsigned long DWORD;
|
|
|
|
/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
|
|
typedef unsigned long long QWORD;
|
|
|
|
typedef char TCHAR;
|
|
#define _T(x) x
|
|
#define _TEXT(x) x
|
|
|
|
typedef DWORD FSIZE_t;
|
|
|
|
typedef struct __FATFS FATFS;
|
|
|
|
|
|
typedef struct {
|
|
FATFS* fs;
|
|
WORD id;
|
|
BYTE attr;
|
|
BYTE stat;
|
|
DWORD sclust;
|
|
FSIZE_t objsize;
|
|
UINT lockid;
|
|
} _FDID;
|
|
|
|
typedef struct {
|
|
_FDID obj;
|
|
BYTE flag;
|
|
BYTE err;
|
|
FSIZE_t fptr;
|
|
DWORD clust;
|
|
DWORD sect;
|
|
DWORD dir_sect;
|
|
BYTE* dir_ptr;
|
|
DWORD* cltbl;
|
|
BYTE buf[512];
|
|
} FIL;
|
|
|
|
|
|
/* File access mode and open method flags (3rd argument of f_open) */
|
|
#define FA_READ 0x01
|
|
#define FA_WRITE 0x02
|
|
#define FA_OPEN_EXISTING 0x00
|
|
#define FA_CREATE_NEW 0x04
|
|
#define FA_CREATE_ALWAYS 0x08
|
|
#define FA_OPEN_ALWAYS 0x10
|
|
#define FA_OPEN_APPEND 0x30
|
|
|
|
|
|
|
|
/* File function return code (FRESULT) */
|
|
|
|
typedef enum {
|
|
FR_OK = 0, /* (0) Succeeded */
|
|
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
|
FR_INT_ERR, /* (2) Assertion failed */
|
|
FR_NOT_READY, /* (3) The physical drive cannot work */
|
|
FR_NO_FILE, /* (4) Could not find the file */
|
|
FR_NO_PATH, /* (5) Could not find the path */
|
|
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
|
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
|
FR_EXIST, /* (8) Access denied due to prohibited access */
|
|
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
|
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
|
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
|
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
|
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
|
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
|
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
|
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
|
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
|
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */
|
|
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
|
} FRESULT;
|
|
|
|
|
|
|
|
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
|
FRESULT f_close (FIL* fp); /* Close an open file object */
|
|
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
|
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
|
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
|
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
|
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
|
|
|
#define f_size(fp) ((fp)->obj.objsize)
|
|
#define f_tell(fp) ((fp)->fptr)
|
|
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
|
|
|
#ifndef EOF
|
|
#define EOF (-1)
|
|
#endif
|
|
|
|
#endif
|