Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PAL Services Public Functions
[File System Specification]
Functions | |
palStatus_t | pal_fsMkDir (const char *pathName) |
This function attempts to create a directory named pathName . | |
palStatus_t | pal_fsRmDir (const char *pathName) |
This function deletes a directory. | |
palStatus_t | pal_fsFopen (const char *pathName, pal_fsFileMode_t mode, palFileDescriptor_t *fd) |
This function opens the file whose name is specified in the parameter `pathName` and associates it with a stream that can be identified in future operations by the `fd` pointer returned. | |
palStatus_t | pal_fsFclose (palFileDescriptor_t *fd) |
This function closes an open file object. | |
palStatus_t | pal_fsFread (palFileDescriptor_t *fd, void *buffer, size_t numOfBytes, size_t *numberOfBytesRead) |
This function reads an array of bytes from the stream and stores it in the block of memory specified by `buffer`. The position indicator of the stream is advanced by the total amount of bytes read. | |
palStatus_t | pal_fsFwrite (palFileDescriptor_t *fd, const void *buffer, size_t numOfBytes, size_t *numberOfBytesWritten) |
This function starts to write data from buffer to the file at the position pointed by the read/write pointer. | |
palStatus_t | pal_fsFseek (palFileDescriptor_t *fd, int32_t offset, pal_fsOffset_t whence) |
This function moves the file read/write pointer without any read/write operation to the file. | |
palStatus_t | pal_fsFtell (palFileDescriptor_t *fd, int32_t *pos) |
This function gets the current read/write pointer of a file. | |
palStatus_t | pal_fsUnlink (const char *pathName) |
This function deletes a single file from the file system. | |
palStatus_t | pal_fsRmFiles (const char *pathName) |
This function deletes all files and folders in a specified folder from the file system. Flat remove only. | |
palStatus_t | pal_fsCpFolder (const char *pathNameSrc, char *pathNameDest) |
This function copies all files from the source folder to the destination folder. Flat copy only. | |
palStatus_t | pal_fsSetMountPoint (pal_fsStorageID_t dataID, const char *Path) |
This function sets the mount directory for the given storage ID (primary or secondary),. | |
palStatus_t | pal_fsGetMountPoint (pal_fsStorageID_t dataID, size_t length, char *Path) |
This function gets the mount directory for the given storage ID (primary or secondary), The function copies the path to the user pre allocated buffer. | |
palStatus_t | pal_fsFormat (pal_fsStorageID_t dataID) |
This function formats a given SD partition. | |
bool | pal_fsIsPrivatePartition (pal_fsStorageID_t dataID) |
This function will return whether a given partition is used only by PAL or not. | |
void | pal_fsCleanup (void) |
This function will perform clean up on all file system resources. |
Function Documentation
void pal_fsCleanup | ( | void | ) |
This function will perform clean up on all file system resources.
Definition at line 33 of file pal_fileSystem.c.
palStatus_t pal_fsCpFolder | ( | const char * | pathNameSrc, |
char * | pathNameDest | ||
) |
This function copies all files from the source folder to the destination folder. Flat copy only.
- Parameters:
-
[in] pathNameSrc A pointer to a null-terminated string that specifies the source folder. [in] pathNameDest A pointer to a null-terminated string that specifies the destination folder. The folder MUST already exist.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- Both folders must not be open. If the folders do not exist, the function fails.
Definition at line 179 of file pal_fileSystem.c.
palStatus_t pal_fsFclose | ( | palFileDescriptor_t * | fd ) |
This function closes an open file object.
- Parameters:
-
[in] fd A pointer to the open file object structure to be closed.
- Returns:
- PAL_SUCCESS upon successful operation.
PAL_FILE_SYSTEM_ERROR - see error codepalError_t
.
- Note:
- When the function has completed successfully, the file object is no longer valid and it can be discarded.
Definition at line 99 of file pal_fileSystem.c.
palStatus_t pal_fsFopen | ( | const char * | pathName, |
pal_fsFileMode_t | mode, | ||
palFileDescriptor_t * | fd | ||
) |
This function opens the file whose name is specified in the parameter `pathName` and associates it with a stream that can be identified in future operations by the `fd` pointer returned.
- Parameters:
-
[out] fd The file descriptor to the file entered in the `pathName`. [in] *pathName A pointer to the null-terminated string that specifies the file name to open or create. [in] mode A mode flag that specifies the type of access and open method for the file.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- The folder path shall end with "/".
Example
{.cpp} //Copy File from "File1" to "File2" palStatus_t ret; palFileDescriptor_t fd1 = NULL,fd2 = NULL ; // File Object 1 & 2 uint8 buffer[1024]; size_t bytes_read = 0, Bytes_wrote = 0; //Open first file with Read permission ret = PAL_ERR_FS_fopen(&fd1, "File1", PAL_ERR_FS_READWRITEEXCLUSIVE); if(ret) {//Error} //Create second file with Read/Write permissions ret = PAL_ERR_FS_fopen(&fd2, "File2", PAL_ERR_FS_READWRITEEXCLUSIVE); if(ret) {//Error} // Copy source to destination for (;;) { ret = PAL_ERR_FS_read(&fd1, buffer, sizeof(buffer), &bytes_read); // Read a chunk of source file if (ret || bytes_read == 0) break; // error or EOF ret = PAL_ERR_FS_write(&fd2, buffer, sizeof(buffer), &Bytes_wrote); // Write it to the destination file if (ret || Bytes_wrote < bytes_read) break; // error or disk full } PAL_ERR_FS_close(&fd1); PAL_ERR_FS_close(&fd2); }
Definition at line 81 of file pal_fileSystem.c.
palStatus_t pal_fsFormat | ( | pal_fsStorageID_t | dataID ) |
This function formats a given SD partition.
- Parameters:
-
[in] dataID The ID of the partition to be formatted.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- PAL_ERR_INVALID_ARGUMENT an invalid `partitionID`.
- Note:
- The actual partition values mapped to the IDs is determined by the porting layer.
Definition at line 245 of file pal_fileSystem.c.
palStatus_t pal_fsFread | ( | palFileDescriptor_t * | fd, |
void * | buffer, | ||
size_t | numOfBytes, | ||
size_t * | numberOfBytesRead | ||
) |
This function reads an array of bytes from the stream and stores it in the block of memory specified by `buffer`. The position indicator of the stream is advanced by the total amount of bytes read.
- Parameters:
-
[in] fd A pointer to the open file object structure. [in] buffer The buffer to store the read data. [in] numOfBytes The number of bytes to read. [out] numberOfBytesRead The number of bytes read.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- When the function has completed successfully, `numberOfBytesRead` should be checked to detect end of the file. If `numberOfBytesRead` is less than `numOfBytes`, the read/write pointer has reached the end of the file during the read operation or there is an error.
Definition at line 111 of file pal_fileSystem.c.
palStatus_t pal_fsFseek | ( | palFileDescriptor_t * | fd, |
int32_t | offset, | ||
pal_fsOffset_t | whence | ||
) |
This function moves the file read/write pointer without any read/write operation to the file.
- Parameters:
-
[in] fd A pointer to the open file object structure. [in] offset The byte offset from the top of the file to set the read/write pointer. [out] whence Where the offset is relative to.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- The `whence` options are:
- PAL_ERR_FS_SEEKSET - Relative to the start of the file.
- PAL_ERR_FS_SEEKCUR - The current position indicator.
- PAL_ERR_FS_SEEKEND - End-of-file.
Example
{.cpp} palStatus_t ret; palFileDescriptor_t fd1 = NULL; // File Object 1 uint8 buffer[1024]; size_t bytes_read = 0, Bytes_wrote = 0; //Open file with Read permission ret = PAL_ERR_FS_fopen(&fd1, "File1", PAL_ERR_FS_READ); if(ret) {//Error} ret = PAL_ERR_FS_fseek(&fd1, 500, PAL_ERR_FS_SEEKSET)
Definition at line 136 of file pal_fileSystem.c.
palStatus_t pal_fsFtell | ( | palFileDescriptor_t * | fd, |
int32_t * | pos | ||
) |
This function gets the current read/write pointer of a file.
- Parameters:
-
[in] fd A pointer to the open file object structure.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
Definition at line 147 of file pal_fileSystem.c.
palStatus_t pal_fsFwrite | ( | palFileDescriptor_t * | fd, |
const void * | buffer, | ||
size_t | numOfBytes, | ||
size_t * | numberOfBytesWritten | ||
) |
This function starts to write data from buffer
to the file at the position pointed by the read/write pointer.
- Parameters:
-
[in] fd A pointer to the open file object structure. [in] buffer A pointer to the data to be written. [in] numOfBytes The number of bytes to write. [out] numberOfBytesWritten The number of bytes written.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- The read/write pointer advances as number of bytes written. When the function has completed successfully,
- `numberOfBytesWritten` should be checked to detect the whether the disk is full. If `numberOfBytesWritten` is less than `numOfBytes`, the volume got full during the write operation.
Definition at line 123 of file pal_fileSystem.c.
palStatus_t pal_fsGetMountPoint | ( | pal_fsStorageID_t | dataID, |
size_t | length, | ||
char * | Path | ||
) |
This function gets the mount directory for the given storage ID (primary or secondary), The function copies the path to the user pre allocated buffer.
- Parameters:
-
[in] length The length of the buffer. [out] Path A pointer to a pre-allocated buffer with size PAL_MAX_FOLDER_DEPTH_CHAR
+ 1 chars. The plus 1 is to account for the '\0' terminator at the end of the buffer
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
Definition at line 218 of file pal_fileSystem.c.
bool pal_fsIsPrivatePartition | ( | pal_fsStorageID_t | dataID ) |
This function will return whether a given partition is used only by PAL or not.
- Parameters:
-
[in] dataID - the ID of the data to be cleared.
- Returns:
- true - if partition is used only by pal.
- false - if partition is used by other component then pal.
- Note:
- The actual partition values mapped the IDs will be determined by the porting layer.
Definition at line 271 of file pal_fileSystem.c.
palStatus_t pal_fsMkDir | ( | const char * | pathName ) |
This function attempts to create a directory named pathName
.
- Parameters:
-
[in] *pathName A pointer to the null-terminated string that specifies the directory name to create.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- To remove a directory, use
PAL_ERR_FS_rmdir
.
Example
{.cpp} palStatus_t ret; ret = PAL_ERR_FS_mkdir("Dir1"); if(!ret) { //Error }
Definition at line 54 of file pal_fileSystem.c.
palStatus_t pal_fsRmDir | ( | const char * | pathName ) |
This function deletes a directory.
- Parameters:
-
[in] *pathName A pointer to the null-terminated string that specifies the directory name to be deleted.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- The deleted directory must be both empty and closed and the folder path end with
/
.
Example
{.cpp} palStatus_t ret; ret = PAL_ERR_FS_mkdir("Dir1"); //Create folder name "Dir1" if(!ret) { //Error } ret = PAL_ERR_FS_rmdir("Dir1); //Remove directory from partition if(!ret) { //Error }
Definition at line 71 of file pal_fileSystem.c.
palStatus_t pal_fsRmFiles | ( | const char * | pathName ) |
This function deletes all files and folders in a specified folder from the file system. Flat remove only.
- Parameters:
-
[in] pathName A pointer to a null-terminated string that specifies the folder.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- The folder must not be open and the folder path must end with
/
.
Definition at line 168 of file pal_fileSystem.c.
palStatus_t pal_fsSetMountPoint | ( | pal_fsStorageID_t | dataID, |
const char * | Path | ||
) |
This function sets the mount directory for the given storage ID (primary or secondary),.
- Parameters:
-
[in] Path A pointer to a null-terminated string that specifies the root folder.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR For error code description, see
palError_t
.
- Note:
- If called with
NULL
, the ESFS root folder is set to default PAL_SOURCE_FOLDER. -
The folder path must end with
/
.
Definition at line 191 of file pal_fileSystem.c.
palStatus_t pal_fsUnlink | ( | const char * | pathName ) |
This function deletes a single file from the file system.
- Parameters:
-
[in] pathName A pointer to a null-terminated string that specifies the file to be removed.
- Returns:
- PAL_SUCCESS upon successful operation.
-
PAL_FILE_SYSTEM_ERROR - see error code description
palError_t
.
- Note:
- The file must not be open.
Definition at line 156 of file pal_fileSystem.c.
Generated on Mon Aug 29 2022 19:53:43 by
