le_atomFile.h
Go to the documentation of this file.
11 * This API only supports regular files. Attempts to use this API on sockets, devices, etc. results17 * operation is performed or the operation fails. Any unclean reboot or power-cut should not lead to18 * corruption or inconsistency of the file. Also when a process is performing an atomic write on a22 * Use @c le_atomFile_Open() to open a file for atomic access. This API uses @ref c_flock_cooperative32 * Writing on the file descriptors obtained by this API same as writing to regular file descriptor.33 * That means, any write to a file descriptor using this API doesn't ensure that data is transferred150 * The functions @c le_atomFile_OpenStream() and @c le_atomFile_CreateStream() can be used to obtain151 * a file stream for atomic operation. @c le_atomFile_CloseStream() is used to commit all changes152 * to disk and close the stream. @c le_atomFile_CancelStream() is used to discard all changes and154 * le_atomFile_Close() and le_atomFile_Cancel() except that works on file streams rather than file160 * le_atomFile_CreateStream() and le_atomFile_Delete() always block if there is an incompatible lock162 * le_atomFile_TryOpenStream(), le_atomFile_TryCreateStream() and le_atomFile_TryDelete() are their194 * closing APIs (i.e. le_atomFile_Close(), le_atomFile_CloseStream() etc.). This is illustrated in249 //--------------------------------------------------------------------------------------------------263 //--------------------------------------------------------------------------------------------------268 * Parameter accessMode specifies the lock to be applied on the file (read lock will be applied for282 //--------------------------------------------------------------------------------------------------290 //--------------------------------------------------------------------------------------------------294 * If the file does not exist it will be created with the file permissions specified in the argument295 * permissions (modified by the process's umask). Refer to the POSIX function open(2) for details301 * Parameter accessMode specifies the lock to be applied on the file (read lock will be applied for304 * This is a blocking call. It will block until it can create and open the target file with specified315 //--------------------------------------------------------------------------------------------------326 //--------------------------------------------------------------------------------------------------328 * Same as @c le_atomFile_Open() except that it is non-blocking function and it will fail and return340 //--------------------------------------------------------------------------------------------------348 //--------------------------------------------------------------------------------------------------362 //--------------------------------------------------------------------------------------------------372 //--------------------------------------------------------------------------------------------------376 //--------------------------------------------------------------------------------------------------383 //--------------------------------------------------------------------------------------------------385 * Commits all changes and closes the file descriptor. No need to close the file descriptor again if386 * this function returns error (i.e. file descriptor is closed in both success and error scenario).392 //--------------------------------------------------------------------------------------------------399 //--------------------------------------------------------------------------------------------------404 * Parameter accessMode specifies the lock to be applied on the file (read lock will be applied for422 //--------------------------------------------------------------------------------------------------432 //--------------------------------------------------------------------------------------------------436 * If the file does not exist it will be created with the file permissions specified in the argument437 * permissions (modified by the process's umask). Refer to the POSIX function open(2) for details443 * Parameter accessMode specifies the lock to be applied on the file (read lock will be applied for450 * - LE_DUPLICATE if the file already exists and LE_FLOCK_FAIL_IF_EXIST is specified in createMode.461 //--------------------------------------------------------------------------------------------------474 //--------------------------------------------------------------------------------------------------476 * Same as @c le_atomFile_OpenStream() except that it is non-blocking function and it will fail and492 //--------------------------------------------------------------------------------------------------501 //--------------------------------------------------------------------------------------------------503 * Same as @c le_atomFile_CreateStream() except that it is non-blocking function and it will fail507 * - LE_DUPLICATE if the file already exists and LE_FLOCK_FAIL_IF_EXIST is specified in createMode.519 //--------------------------------------------------------------------------------------------------530 //--------------------------------------------------------------------------------------------------534 //--------------------------------------------------------------------------------------------------541 //--------------------------------------------------------------------------------------------------543 * Commits all changes and closes the file stream. No need to close the file stream again if this550 //--------------------------------------------------------------------------------------------------557 //--------------------------------------------------------------------------------------------------559 * Atomically deletes a file. This function also ensures safe deletion of file (i.e. if any other560 * process/thread is using the file by acquiring file lock, it won't delete the file unless lock is568 //--------------------------------------------------------------------------------------------------575 //--------------------------------------------------------------------------------------------------586 //--------------------------------------------------------------------------------------------------LE_API_FILESYSTEM LE_FULL_API void le_atomFile_CancelStream(FILE *fileStreamPtr)LE_API_FILESYSTEM le_result_t le_atomFile_Close(int fd)LE_API_FILESYSTEM LE_FULL_API le_result_t le_atomFile_TryDelete(const char *pathNamePtr)LE_API_FILESYSTEM LE_FULL_API int le_atomFile_TryOpen(const char *pathNamePtr, le_flock_AccessMode_t accessMode)LE_API_FILESYSTEM LE_FULL_API int le_atomFile_TryCreate(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_flock_CreateMode_t createMode, mode_t permissions)LE_API_FILESYSTEM void le_atomFile_Cancel(int fd)LE_API_FILESYSTEM LE_FULL_API FILE * le_atomFile_TryOpenStream(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_result_t *resultPtr)LE_API_FILESYSTEM LE_FULL_API FILE * le_atomFile_OpenStream(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_result_t *resultPtr)#define LE_API_FILESYSTEMAPI requires filesystem support.Definition: le_apiFeatures.h:47LE_API_FILESYSTEM LE_FULL_API FILE * le_atomFile_CreateStream(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_flock_CreateMode_t createMode, mode_t permissions, le_result_t *resultPtr)LE_API_FILESYSTEM LE_FULL_API le_result_t le_atomFile_CloseStream(FILE *fileStreamPtr)LE_API_FILESYSTEM le_result_t le_atomFile_Delete(const char *pathNamePtr)LE_API_FILESYSTEM int le_atomFile_Open(const char *pathNamePtr, le_flock_AccessMode_t accessMode)LE_API_FILESYSTEM int le_atomFile_Create(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_flock_CreateMode_t createMode, mode_t permissions)LE_API_FILESYSTEM LE_FULL_API FILE * le_atomFile_TryCreateStream(const char *pathNamePtr, le_flock_AccessMode_t accessMode, le_flock_CreateMode_t createMode, mode_t permissions, le_result_t *resultPtr)