ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/src/iot-baidu-ota/baidu_ota_unpack/ota/inc/fs.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | |
| TMBOY | 47:9e361da97763 | 2 | |
| TMBOY | 47:9e361da97763 | 3 | #ifndef _MBED_FS_H_ |
| TMBOY | 47:9e361da97763 | 4 | #define _MBED_FS_H_ |
| TMBOY | 47:9e361da97763 | 5 | |
| TMBOY | 47:9e361da97763 | 6 | /* sl_FsOpen options */ |
| TMBOY | 47:9e361da97763 | 7 | /* Open for Read */ |
| TMBOY | 47:9e361da97763 | 8 | #define FS_MODE_OPEN_READ 0 |
| TMBOY | 47:9e361da97763 | 9 | /* Open for Write (in case file exist) */ |
| TMBOY | 47:9e361da97763 | 10 | #define FS_MODE_OPEN_WRITE 1 |
| TMBOY | 47:9e361da97763 | 11 | |
| TMBOY | 47:9e361da97763 | 12 | |
| TMBOY | 47:9e361da97763 | 13 | /*****************************************************************************/ |
| TMBOY | 47:9e361da97763 | 14 | /* Function prototypes */ |
| TMBOY | 47:9e361da97763 | 15 | /*****************************************************************************/ |
| TMBOY | 47:9e361da97763 | 16 | |
| TMBOY | 47:9e361da97763 | 17 | /*! |
| TMBOY | 47:9e361da97763 | 18 | \brief open file for read or write from/to storage device |
| TMBOY | 47:9e361da97763 | 19 | |
| TMBOY | 47:9e361da97763 | 20 | \param[in] pFileName File Name buffer pointer |
| TMBOY | 47:9e361da97763 | 21 | \param[in] AccessModeAndMaxSize Options: As described below |
| TMBOY | 47:9e361da97763 | 22 | \param[in] pToken Reserved for future use. Use NULL for this field |
| TMBOY | 47:9e361da97763 | 23 | \param[out] pFileHandle Pointing on the file and used for read and write commands to the file |
| TMBOY | 47:9e361da97763 | 24 | |
| TMBOY | 47:9e361da97763 | 25 | AccessModeAndMaxSize possible input \n |
| TMBOY | 47:9e361da97763 | 26 | FS_MODE_OPEN_READ - Read a file \n |
| TMBOY | 47:9e361da97763 | 27 | FS_MODE_OPEN_WRITE - Open for write for an existing file \n |
| TMBOY | 47:9e361da97763 | 28 | FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) - Open for creating a new file. Max file size is defined in bytes. \n |
| TMBOY | 47:9e361da97763 | 29 | For optimal FS size, use max size in 4K-512 bytes steps (e.g. 3584,7680,117760) \n |
| TMBOY | 47:9e361da97763 | 30 | Several access modes bits can be combined together from SlFileOpenFlags_e enum |
| TMBOY | 47:9e361da97763 | 31 | |
| TMBOY | 47:9e361da97763 | 32 | \return On success, zero is returned. On error, an error code is returned |
| TMBOY | 47:9e361da97763 | 33 | |
| TMBOY | 47:9e361da97763 | 34 | \sa sl_FsRead sl_FsWrite sl_FsClose |
| TMBOY | 47:9e361da97763 | 35 | \note belongs to \ref basic_api |
| TMBOY | 47:9e361da97763 | 36 | \warning |
| TMBOY | 47:9e361da97763 | 37 | \par Example: |
| TMBOY | 47:9e361da97763 | 38 | \code |
| TMBOY | 47:9e361da97763 | 39 | char* DeviceFileName = "MyFile.txt"; |
| TMBOY | 47:9e361da97763 | 40 | unsigned long MaxSize = 63 * 1024; //62.5K is max file size |
| TMBOY | 47:9e361da97763 | 41 | long DeviceFileHandle = -1; |
| TMBOY | 47:9e361da97763 | 42 | long RetVal; //negative retval is an error |
| TMBOY | 47:9e361da97763 | 43 | unsigned long Offset = 0; |
| TMBOY | 47:9e361da97763 | 44 | unsigned char InputBuffer[100]; |
| TMBOY | 47:9e361da97763 | 45 | |
| TMBOY | 47:9e361da97763 | 46 | // Create a file and write data. The file in this example is secured, without signature and with a fail safe commit |
| TMBOY | 47:9e361da97763 | 47 | RetVal = sl_FsOpen((unsigned char *)DeviceFileName, |
| TMBOY | 47:9e361da97763 | 48 | FS_MODE_OPEN_CREATE(MaxSize , _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ), |
| TMBOY | 47:9e361da97763 | 49 | NULL, &DeviceFileHandle); |
| TMBOY | 47:9e361da97763 | 50 | |
| TMBOY | 47:9e361da97763 | 51 | Offset = 0; |
| TMBOY | 47:9e361da97763 | 52 | //Preferred in secure file that the Offset and the length will be aligned to 16 bytes. |
| TMBOY | 47:9e361da97763 | 53 | RetVal = sl_FsWrite( DeviceFileHandle, Offset, (unsigned char *)"HelloWorld", strlen("HelloWorld")); |
| TMBOY | 47:9e361da97763 | 54 | |
| TMBOY | 47:9e361da97763 | 55 | RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); |
| TMBOY | 47:9e361da97763 | 56 | |
| TMBOY | 47:9e361da97763 | 57 | // open the same file for read, using the Token we got from the creation procedure above |
| TMBOY | 47:9e361da97763 | 58 | RetVal = sl_FsOpen((unsigned char *)DeviceFileName, |
| TMBOY | 47:9e361da97763 | 59 | FS_MODE_OPEN_READ, |
| TMBOY | 47:9e361da97763 | 60 | NULL, &DeviceFileHandle); |
| TMBOY | 47:9e361da97763 | 61 | |
| TMBOY | 47:9e361da97763 | 62 | Offset = 0; |
| TMBOY | 47:9e361da97763 | 63 | RetVal = sl_FsRead( DeviceFileHandle, Offset, (unsigned char *)InputBuffer, strlen("HelloWorld")); |
| TMBOY | 47:9e361da97763 | 64 | |
| TMBOY | 47:9e361da97763 | 65 | RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); |
| TMBOY | 47:9e361da97763 | 66 | |
| TMBOY | 47:9e361da97763 | 67 | \endcode |
| TMBOY | 47:9e361da97763 | 68 | */ |
| TMBOY | 47:9e361da97763 | 69 | int32_t sl_FsOpen(const uint8_t *pFileName,const uint32_t AccessModeAndMaxSize,uint32_t *pToken,int32_t *pFileHandle); |
| TMBOY | 47:9e361da97763 | 70 | |
| TMBOY | 47:9e361da97763 | 71 | /*! |
| TMBOY | 47:9e361da97763 | 72 | \brief close file in storage device |
| TMBOY | 47:9e361da97763 | 73 | |
| TMBOY | 47:9e361da97763 | 74 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
| TMBOY | 47:9e361da97763 | 75 | \param[in] pCeritificateFileName Reserved for future use. Use NULL. |
| TMBOY | 47:9e361da97763 | 76 | \param[in] pSignature Reserved for future use. Use NULL. |
| TMBOY | 47:9e361da97763 | 77 | \param[in] SignatureLen Reserved for future use. Use 0. |
| TMBOY | 47:9e361da97763 | 78 | |
| TMBOY | 47:9e361da97763 | 79 | |
| TMBOY | 47:9e361da97763 | 80 | \return On success, zero is returned. On error, an error code is returned |
| TMBOY | 47:9e361da97763 | 81 | |
| TMBOY | 47:9e361da97763 | 82 | \sa sl_FsRead sl_FsWrite sl_FsOpen |
| TMBOY | 47:9e361da97763 | 83 | \note Call the fs_Close with signature = 'A' signature len = 1 for activating an abort action |
| TMBOY | 47:9e361da97763 | 84 | \warning |
| TMBOY | 47:9e361da97763 | 85 | \par Example: |
| TMBOY | 47:9e361da97763 | 86 | \code |
| TMBOY | 47:9e361da97763 | 87 | sl_FsClose(FileHandle,0,0,0); |
| TMBOY | 47:9e361da97763 | 88 | \endcode |
| TMBOY | 47:9e361da97763 | 89 | */ |
| TMBOY | 47:9e361da97763 | 90 | int16_t sl_FsClose(const int32_t FileHdl,const uint8_t* pCeritificateFileName,const uint8_t* pSignature,const uint32_t SignatureLen); |
| TMBOY | 47:9e361da97763 | 91 | |
| TMBOY | 47:9e361da97763 | 92 | /*! |
| TMBOY | 47:9e361da97763 | 93 | \brief Read block of data from a file in storage device |
| TMBOY | 47:9e361da97763 | 94 | |
| TMBOY | 47:9e361da97763 | 95 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
| TMBOY | 47:9e361da97763 | 96 | \param[in] Offset Offset to specific read block |
| TMBOY | 47:9e361da97763 | 97 | \param[out] pData Pointer for the received data |
| TMBOY | 47:9e361da97763 | 98 | \param[in] Len Length of the received data |
| TMBOY | 47:9e361da97763 | 99 | |
| TMBOY | 47:9e361da97763 | 100 | \return On success, returns the number of read bytes. On error, negative number is returned |
| TMBOY | 47:9e361da97763 | 101 | |
| TMBOY | 47:9e361da97763 | 102 | \sa sl_FsClose sl_FsWrite sl_FsOpen |
| TMBOY | 47:9e361da97763 | 103 | \note belongs to \ref basic_api |
| TMBOY | 47:9e361da97763 | 104 | \warning |
| TMBOY | 47:9e361da97763 | 105 | \par Example: |
| TMBOY | 47:9e361da97763 | 106 | \code |
| TMBOY | 47:9e361da97763 | 107 | Status = sl_FsRead(FileHandle, 0, &readBuff[0], readSize); |
| TMBOY | 47:9e361da97763 | 108 | \endcode |
| TMBOY | 47:9e361da97763 | 109 | */ |
| TMBOY | 47:9e361da97763 | 110 | int32_t sl_FsRead(const int32_t FileHdl, uint32_t Offset , uint8_t* pData, uint32_t Len); |
| TMBOY | 47:9e361da97763 | 111 | |
| TMBOY | 47:9e361da97763 | 112 | /*! |
| TMBOY | 47:9e361da97763 | 113 | \brief write block of data to a file in storage device |
| TMBOY | 47:9e361da97763 | 114 | |
| TMBOY | 47:9e361da97763 | 115 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
| TMBOY | 47:9e361da97763 | 116 | \param[in] Offset Offset to specific block to be written |
| TMBOY | 47:9e361da97763 | 117 | \param[in] pData Pointer the transmitted data to the storage device |
| TMBOY | 47:9e361da97763 | 118 | \param[in] Len Length of the transmitted data |
| TMBOY | 47:9e361da97763 | 119 | |
| TMBOY | 47:9e361da97763 | 120 | \return On success, returns the number of written bytes. On error, an error code is returned |
| TMBOY | 47:9e361da97763 | 121 | |
| TMBOY | 47:9e361da97763 | 122 | \sa |
| TMBOY | 47:9e361da97763 | 123 | \note belongs to \ref basic_api |
| TMBOY | 47:9e361da97763 | 124 | \warning |
| TMBOY | 47:9e361da97763 | 125 | \par Example: |
| TMBOY | 47:9e361da97763 | 126 | \code |
| TMBOY | 47:9e361da97763 | 127 | Status = sl_FsWrite(FileHandle, 0, &buff[0], readSize); |
| TMBOY | 47:9e361da97763 | 128 | \endcode |
| TMBOY | 47:9e361da97763 | 129 | */ |
| TMBOY | 47:9e361da97763 | 130 | int32_t sl_FsWrite(const int32_t FileHdl, uint32_t Offset, uint8_t* pData, uint32_t Len); |
| TMBOY | 47:9e361da97763 | 131 | |
| TMBOY | 47:9e361da97763 | 132 | /*! |
| TMBOY | 47:9e361da97763 | 133 | \brief get info on a file |
| TMBOY | 47:9e361da97763 | 134 | |
| TMBOY | 47:9e361da97763 | 135 | \param[in] pFileName File name |
| TMBOY | 47:9e361da97763 | 136 | \param[in] Token Reserved for future use. Use 0 |
| TMBOY | 47:9e361da97763 | 137 | \param[out] pFsFileInfo Returns the File's Information: flags,file size, allocated size and Tokens |
| TMBOY | 47:9e361da97763 | 138 | |
| TMBOY | 47:9e361da97763 | 139 | \return On success, zero is returned. On error, an error code is returned |
| TMBOY | 47:9e361da97763 | 140 | |
| TMBOY | 47:9e361da97763 | 141 | \sa sl_FsOpen |
| TMBOY | 47:9e361da97763 | 142 | \note belongs to \ref basic_api |
| TMBOY | 47:9e361da97763 | 143 | \warning |
| TMBOY | 47:9e361da97763 | 144 | \par Example: |
| TMBOY | 47:9e361da97763 | 145 | \code |
| TMBOY | 47:9e361da97763 | 146 | Status = sl_FsGetInfo("FileName.html",0,&FsFileInfo); |
| TMBOY | 47:9e361da97763 | 147 | \endcode |
| TMBOY | 47:9e361da97763 | 148 | */ |
| TMBOY | 47:9e361da97763 | 149 | |
| TMBOY | 47:9e361da97763 | 150 | |
| TMBOY | 47:9e361da97763 | 151 | |
| TMBOY | 47:9e361da97763 | 152 | #endif /* __FS_H__ */ |
| TMBOY | 47:9e361da97763 | 153 |
