Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
PAL Services Public Functions
[PAL_GROUP_FS]
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 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 the SD partition indentified by the `partitionID` parameter. | |
bool | pal_fsIsPrivatePartition (pal_fsStorageID_t dataID) |
This function will return if the partition used by pal only or not. | |
void | pal_fsCleanup (void) |
This function will clean all file system resources. |
Function Documentation
void pal_fsCleanup | ( | void | ) |
This function will clean all file system resources.
Definition at line 31 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 (MUST exist).
- Returns:
- PAL_SUCCESS upon successful operation.
PAL_FILE_SYSTEM_ERROR - see error code descriptionpalError_t
.
- Note:
- Both folders must not be open. If the folders do not exist, the function fails.
Definition at line 177 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 97 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 - see error code descriptionpalError_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 79 of file pal_fileSystem.c.
palStatus_t pal_fsFormat | ( | pal_fsStorageID_t | dataID ) |
This function formats the SD partition indentified by the `partitionID` parameter.
- Parameters:
-
[in] partitionID The ID of the partition to be formatted. (**Note:** The actual partition values mapped to the IDs is determined by the porting layer.)
- Returns:
- PAL_SUCCESS upon successful operation.
PAL_FILE_SYSTEM_ERROR - see error code descriptionpalError_t
.
PAL_ERR_INVALID_ARGUMENT - an invalid `partitionID`.
Definition at line 243 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 - see error code descriptionpalError_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 109 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 - see error code descriptionpalError_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 134 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 - see error code descriptionpalError_t
.
Definition at line 145 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 - see error codepalError_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 121 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 pre-allocated buffer with size PAL_MAX_FOLDER_DEPTH_CHAR
+ 1 chars.
- Returns:
- PAL_SUCCESS upon successful operation.
PAL_FILE_SYSTEM_ERROR - see error code descriptionpalError_t
.
- Note:
- The plus 1 is for the '\0' terminator at the end of the buffer.
Definition at line 216 of file pal_fileSystem.c.
bool pal_fsIsPrivatePartition | ( | pal_fsStorageID_t | dataID ) |
This function will return if the partition used by pal only or not.
- Parameters:
-
[in] dataID - the ID of the data to be cleared (Note: the actual partition values mapped the IDs will be determined by the porting layer)
- Returns:
- true - if partition is used only by pal.
false - if partition is used by other component then pal.
Definition at line 269 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 - see error code descriptionpalError_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 52 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 - see error code descriptionpalError_t
.
- Note:
- The deleted directory must be empty and closed and the folder path shall 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 69 of file pal_fileSystem.c.
palStatus_t pal_fsRmFiles | ( | const char * | pathName ) |
This function deletes all files and folders in a 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 - see error code descriptionpalError_t
.
- Note:
- The folder must not be open and the folder path must end with "/".
Definition at line 166 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 - see error code descriptionpalError_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 189 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 descriptionpalError_t
.
- Note:
- The file must not be open.
Definition at line 154 of file pal_fileSystem.c.
Generated on Tue Jul 12 2022 19:12:18 by 1.7.2