fs_port.h
Go to the documentation of this file.
1 /**
2  * @file fs_port.h
3  * @brief File system abstraction layer
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * @author Oryx Embedded SARL (www.oryx-embedded.com)
24  * @version 1.9.0
25  **/
26 
27 #ifndef _FS_PORT_H
28 #define _FS_PORT_H
29 
30 //Dependencies
31 #include "fs_port_config.h"
32 #include "os_port.h"
33 #include "date_time.h"
34 #include "error.h"
35 
36 //Number of files that can be opened simultaneously
37 #ifndef FS_MAX_FILES
38  #define FS_MAX_FILES 8
39 #elif (FS_MAX_FILES < 1)
40  #error FS_MAX_FILES parameter is not valid
41 #endif
42 
43 //Number of directories that can be opened simultaneously
44 #ifndef FS_MAX_DIRS
45  #define FS_MAX_DIRS 8
46 #elif (FS_MAX_DIRS < 1)
47  #error FS_MAX_DIRS parameter is not valid
48 #endif
49 
50 //Maximum filename length
51 #ifndef FS_MAX_NAME_LEN
52  #define FS_MAX_NAME_LEN 127
53 #elif (FS_MAX_NAME_LEN < 11)
54  #error FS_MAX_NAME_LEN parameter is not valid
55 #endif
56 
57 //C++ guard
58 #ifdef __cplusplus
59  extern "C" {
60 #endif
61 
62 
63 /**
64  * @brief File attributes
65  **/
66 
67 typedef enum
68 {
76 
77 
78 /**
79  * @brief File access mode
80  **/
81 
82 typedef enum
83 {
88 } FsFileMode;
89 
90 
91 /**
92  * @brief File seek origin
93  **/
94 
95 typedef enum
96 {
100 } FsSeekOrigin;
101 
102 
103 /**
104  * @brief Directory entry
105  **/
106 
107 typedef struct
108 {
109  uint32_t attributes;
110  uint32_t size;
113 } FsDirEntry;
114 
115 
116 /**
117  * @brief File handle
118  **/
119 
120 typedef void FsFile;
121 
122 
123 /**
124  * @brief Directory handle
125  **/
126 
127 typedef void FsDir;
128 
129 
130 //File system abstraction layer
131 error_t fsInit(void);
132 
133 bool_t fsFileExists(const char_t *path);
134 error_t fsGetFileSize(const char_t *path, uint32_t *size);
135 error_t fsRenameFile(const char_t *oldPath, const char_t *newPath);
136 error_t fsDeleteFile(const char_t *path);
137 
138 FsFile *fsOpenFile(const char_t *path, uint_t mode);
139 error_t fsSeekFile(FsFile *file, int_t offset, uint_t origin);
140 error_t fsWriteFile(FsFile *file, void *data, size_t length);
141 error_t fsReadFile(FsFile *file, void *data, size_t size, size_t *length);
142 void fsCloseFile(FsFile *file);
143 
144 bool_t fsDirExists(const char_t *path);
145 error_t fsCreateDir(const char_t *path);
146 error_t fsRemoveDir(const char_t *path);
147 
148 FsDir *fsOpenDir(const char_t *path);
149 error_t fsReadDir(FsDir *dir, FsDirEntry *dirEntry);
150 void fsCloseDir(FsDir *dir);
151 
152 //C++ guard
153 #ifdef __cplusplus
154  }
155 #endif
156 
157 #endif
uint32_t size
Definition: fs_port.h:110
void FsDir
Directory handle.
Definition: fs_port.h:127
error_t fsDeleteFile(const char_t *path)
Delete a file.
char char_t
Definition: compiler_port.h:41
error_t fsSeekFile(FsFile *file, int_t offset, uint_t origin)
Move to specified position in file.
FsFile * fsOpenFile(const char_t *path, uint_t mode)
Open the specified file for reading or writing.
error_t fsWriteFile(FsFile *file, void *data, size_t length)
Write data to the specified file.
error_t fsInit(void)
File system initialization.
Definition: fs_port_fatfs.c:96
FsDir * fsOpenDir(const char_t *path)
Open a directory stream.
error_t fsRemoveDir(const char_t *path)
Remove a directory.
error_t fsGetFileSize(const char_t *path, uint32_t *size)
Retrieve the size of the specified file.
error_t fsReadFile(FsFile *file, void *data, size_t size, size_t *length)
Read data from the specified file.
Error codes description.
uint8_t file[128]
Definition: dhcp_common.h:210
DateTime modified
Definition: fs_port.h:111
bool_t fsDirExists(const char_t *path)
Check whether a directory exists.
signed int int_t
Definition: compiler_port.h:42
char_t name[]
Date and time management.
void fsCloseDir(FsDir *dir)
Close a directory stream.
RTOS abstraction layer.
error_t fsRenameFile(const char_t *oldPath, const char_t *newPath)
Rename the specified file.
Date and time representation.
Definition: date_time.h:44
FsFileAttributes
File attributes.
Definition: fs_port.h:67
#define FS_MAX_NAME_LEN
Definition: fs_port.h:52
error_t
Error codes.
Definition: error.h:40
void FsFile
File handle.
Definition: fs_port.h:120
unsigned int uint_t
Definition: compiler_port.h:43
error_t fsReadDir(FsDir *dir, FsDirEntry *dirEntry)
Read an entry from the specified directory stream.
uint8_t data[]
Definition: dtls_misc.h:167
bool_t fsFileExists(const char_t *path)
Check whether a file exists.
uint8_t mode
Definition: sntp_client.h:143
uint32_t attributes
Definition: fs_port.h:109
FsFileMode
File access mode.
Definition: fs_port.h:82
FsSeekOrigin
File seek origin.
Definition: fs_port.h:95
error_t fsCreateDir(const char_t *path)
Create a directory.
uint8_t length
Definition: dtls_misc.h:140
int bool_t
Definition: compiler_port.h:47
Directory entry.
Definition: fs_port.h:107
void fsCloseFile(FsFile *file)
Close a file.