Skip to content

Commit

Permalink
fs: Clarify description of fs_open when no access bits given
Browse files Browse the repository at this point in the history
Add warning that file opened without R/W flags will have no read/write
access.
Remove suggestion for using fs_open to check if file exists.
Clarify -ENOENT return reason.

Fixes #64030

Signed-off-by: Dominik Ermel <[email protected]>
  • Loading branch information
de-nordic authored and dleach02 committed Feb 7, 2024
1 parent c612327 commit 07c1e49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions include/zephyr/fs/fs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
* Copyright (c) 2020-2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -252,6 +252,8 @@ static inline void fs_dir_t_init(struct fs_dir_t *zdp)
* @brief Open or create file
*
* Opens or possibly creates a file and associates a stream with it.
* Successfully opened file, when no longer in use, should be closed
* with fs_close().
*
* @details
* @p flags can be 0 or a binary combination of one or more of the following
Expand All @@ -262,8 +264,8 @@ static inline void fs_dir_t_init(struct fs_dir_t *zdp)
* - @c FS_O_CREATE create file if it does not exist
* - @c FS_O_APPEND move to end of file before each write
*
* If @p flags are set to 0 the function will attempt to open an existing file
* with no read/write access; this may be used to e.g. check if the file exists.
* @warning If @p flags are set to 0 the function will open file, if it exists
* and is accessible, but you will have no read/write access to it.
*
* @param zfp Pointer to a file object
* @param file_name The name of a file to open
Expand All @@ -275,7 +277,7 @@ static inline void fs_dir_t_init(struct fs_dir_t *zdp)
* @retval -EROFS when opening read-only file for write, or attempting to
* create a file on a system that has been mounted with the
* FS_MOUNT_FLAG_READ_ONLY flag;
* @retval -ENOENT when the file path is not possible (bad mount point);
* @retval -ENOENT when the file does not exist at the path;
* @retval -ENOTSUP when not implemented by underlying file system driver;
* @retval <0 an other negative errno code, depending on a file system back-end.
*/
Expand Down
2 changes: 1 addition & 1 deletion subsys/fs/fs.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 Intel Corporation.
* Copyright (c) 2020 Peter Bigot Consulting, LLC
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2020-2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down

0 comments on commit 07c1e49

Please sign in to comment.