fs_port.h File Reference

File system abstraction layer. More...

#include "fs_port_config.h"
#include "os_port.h"
#include "date_time.h"
#include "error.h"

Go to the source code of this file.

Data Structures

struct  FsDirEntry
 Directory entry. More...
 

Macros

#define FS_MAX_FILES   8
 
#define FS_MAX_DIRS   8
 
#define FS_MAX_NAME_LEN   127
 

Typedefs

typedef void FsFile
 File handle. More...
 
typedef void FsDir
 Directory handle. More...
 

Enumerations

enum  FsFileAttributes {
  FS_FILE_ATTR_READ_ONLY = 0x01, FS_FILE_ATTR_HIDDEN = 0x02, FS_FILE_ATTR_SYSTEM = 0x04, FS_FILE_ATTR_VOLUME_NAME = 0x08,
  FS_FILE_ATTR_DIRECTORY = 0x10, FS_FILE_ATTR_ARCHIVE = 0x20
}
 File attributes. More...
 
enum  FsFileMode { FS_FILE_MODE_READ = 1, FS_FILE_MODE_WRITE = 2, FS_FILE_MODE_CREATE = 4, FS_FILE_MODE_TRUNC = 8 }
 File access mode. More...
 
enum  FsSeekOrigin { FS_SEEK_SET = 0, FS_SEEK_CUR = 1, FS_SEEK_END = 2 }
 File seek origin. More...
 

Functions

error_t fsInit (void)
 File system initialization. More...
 
bool_t fsFileExists (const char_t *path)
 Check whether a file exists. More...
 
error_t fsGetFileSize (const char_t *path, uint32_t *size)
 Retrieve the size of the specified file. More...
 
error_t fsRenameFile (const char_t *oldPath, const char_t *newPath)
 Rename the specified file. More...
 
error_t fsDeleteFile (const char_t *path)
 Delete a file. More...
 
FsFilefsOpenFile (const char_t *path, uint_t mode)
 Open the specified file for reading or writing. More...
 
error_t fsSeekFile (FsFile *file, int_t offset, uint_t origin)
 Move to specified position in file. More...
 
error_t fsWriteFile (FsFile *file, void *data, size_t length)
 Write data to the specified file. More...
 
error_t fsReadFile (FsFile *file, void *data, size_t size, size_t *length)
 Read data from the specified file. More...
 
void fsCloseFile (FsFile *file)
 Close a file. More...
 
bool_t fsDirExists (const char_t *path)
 Check whether a directory exists. More...
 
error_t fsCreateDir (const char_t *path)
 Create a directory. More...
 
error_t fsRemoveDir (const char_t *path)
 Remove a directory. More...
 
FsDirfsOpenDir (const char_t *path)
 Open a directory stream. More...
 
error_t fsReadDir (FsDir *dir, FsDirEntry *dirEntry)
 Read an entry from the specified directory stream. More...
 
void fsCloseDir (FsDir *dir)
 Close a directory stream. More...
 

Detailed Description

File system abstraction layer.

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file fs_port.h.

Macro Definition Documentation

◆ FS_MAX_DIRS

#define FS_MAX_DIRS   8

Definition at line 45 of file fs_port.h.

◆ FS_MAX_FILES

#define FS_MAX_FILES   8

Definition at line 38 of file fs_port.h.

◆ FS_MAX_NAME_LEN

#define FS_MAX_NAME_LEN   127

Definition at line 52 of file fs_port.h.

Typedef Documentation

◆ FsDir

typedef void FsDir

Directory handle.

Definition at line 127 of file fs_port.h.

◆ FsFile

typedef void FsFile

File handle.

Definition at line 120 of file fs_port.h.

Enumeration Type Documentation

◆ FsFileAttributes

File attributes.

Enumerator
FS_FILE_ATTR_READ_ONLY 
FS_FILE_ATTR_HIDDEN 
FS_FILE_ATTR_SYSTEM 
FS_FILE_ATTR_VOLUME_NAME 
FS_FILE_ATTR_DIRECTORY 
FS_FILE_ATTR_ARCHIVE 

Definition at line 67 of file fs_port.h.

◆ FsFileMode

enum FsFileMode

File access mode.

Enumerator
FS_FILE_MODE_READ 
FS_FILE_MODE_WRITE 
FS_FILE_MODE_CREATE 
FS_FILE_MODE_TRUNC 

Definition at line 82 of file fs_port.h.

◆ FsSeekOrigin

File seek origin.

Enumerator
FS_SEEK_SET 
FS_SEEK_CUR 
FS_SEEK_END 

Definition at line 95 of file fs_port.h.

Function Documentation

◆ fsCloseDir()

void fsCloseDir ( FsDir dir)

Close a directory stream.

Parameters
[in]dirHandle that identifies the directory to be closed

Definition at line 818 of file fs_port_fatfs.c.

◆ fsCloseFile()

void fsCloseFile ( FsFile file)

Close a file.

Parameters
[in]fileHandle that identifies the file to be closed

Definition at line 522 of file fs_port_fatfs.c.

◆ fsCreateDir()

error_t fsCreateDir ( const char_t path)

Create a directory.

Parameters
[in]pathNULL-terminated string specifying the directory path
Returns
Error code

Definition at line 603 of file fs_port_fatfs.c.

◆ fsDeleteFile()

error_t fsDeleteFile ( const char_t path)

Delete a file.

Parameters
[in]pathNULL-terminated string specifying the filename
Returns
Error code

Definition at line 275 of file fs_port_fatfs.c.

◆ fsDirExists()

bool_t fsDirExists ( const char_t path)

Check whether a directory exists.

Parameters
[in]pathNULL-terminated string specifying the directory path
Returns
The function returns TRUE if the directory exists. Otherwise FALSE is returned

Definition at line 552 of file fs_port_fatfs.c.

◆ fsFileExists()

bool_t fsFileExists ( const char_t path)

Check whether a file exists.

Parameters
[in]pathNULL-terminated string specifying the filename
Returns
The function returns TRUE if the file exists. Otherwise FALSE is returned

Definition at line 138 of file fs_port_fatfs.c.

◆ fsGetFileSize()

error_t fsGetFileSize ( const char_t path,
uint32_t *  size 
)

Retrieve the size of the specified file.

Parameters
[in]pathNULL-terminated string specifying the filename
[out]sizeSize of the file in bytes
Returns
Error code

Definition at line 186 of file fs_port_fatfs.c.

◆ fsInit()

error_t fsInit ( void  )

File system initialization.

Returns
Error code

Definition at line 96 of file fs_port_fatfs.c.

◆ fsOpenDir()

FsDir* fsOpenDir ( const char_t path)

Open a directory stream.

Parameters
[in]pathNULL-terminated string specifying the directory path
Returns
Directory handle

Definition at line 679 of file fs_port_fatfs.c.

◆ fsOpenFile()

FsFile* fsOpenFile ( const char_t path,
uint_t  mode 
)

Open the specified file for reading or writing.

Parameters
[in]pathNULL-terminated string specifying the filename
[in]modeType of access permitted (FS_FILE_MODE_READ, FS_FILE_MODE_WRITE or FS_FILE_MODE_CREATE)
Returns
File handle

Definition at line 315 of file fs_port_fatfs.c.

◆ fsReadDir()

error_t fsReadDir ( FsDir dir,
FsDirEntry dirEntry 
)

Read an entry from the specified directory stream.

Parameters
[in]dirHandle that identifies the directory
[out]dirEntryPointer to a directory entry
Returns
Error code

Definition at line 730 of file fs_port_fatfs.c.

◆ fsReadFile()

error_t fsReadFile ( FsFile file,
void *  data,
size_t  size,
size_t *  length 
)

Read data from the specified file.

Parameters
[in]fileHandle that identifies the file to be read
[in]dataPointer to the buffer where to copy the data
[in]sizeSize of the buffer, in bytes
[out]lengthNumber of data bytes that have been read
Returns
Error code

Definition at line 475 of file fs_port_fatfs.c.

◆ fsRemoveDir()

error_t fsRemoveDir ( const char_t path)

Remove a directory.

Parameters
[in]pathNULL-terminated string specifying the directory path
Returns
Error code

Definition at line 641 of file fs_port_fatfs.c.

◆ fsRenameFile()

error_t fsRenameFile ( const char_t oldPath,
const char_t newPath 
)

Rename the specified file.

Parameters
[in]oldPathNULL-terminated string specifying the pathname of the file to be renamed
[in]newPathNULL-terminated string specifying the new filename
Returns
Error code

Definition at line 237 of file fs_port_fatfs.c.

◆ fsSeekFile()

error_t fsSeekFile ( FsFile file,
int_t  offset,
uint_t  origin 
)

Move to specified position in file.

Parameters
[in]fileHandle that identifies the file
[in]offsetNumber of bytes to move from origin
[in]originPosition used as reference for the offset (FS_SEEK_SET, FS_SEEK_CUR or FS_SEEK_END)
Returns
Error code

Definition at line 382 of file fs_port_fatfs.c.

◆ fsWriteFile()

error_t fsWriteFile ( FsFile file,
void *  data,
size_t  length 
)

Write data to the specified file.

Parameters
[in]fileHandle that identifies the file to be written
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
Returns
Error code

Definition at line 429 of file fs_port_fatfs.c.