Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: Clarify description of fs_open when no access bits given #64146

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

de-nordic
Copy link
Collaborator

Added note warnign that fs_open should not be used for checking whether file exists or not and fs_stat should be used instead.

Fixes #64030

@de-nordic de-nordic requested a review from nashif as a code owner October 19, 2023 16:55
@de-nordic
Copy link
Collaborator Author

FYI @clamattia

include/zephyr/fs/fs.h Outdated Show resolved Hide resolved
kartben
kartben previously approved these changes Nov 9, 2023
@de-nordic
Copy link
Collaborator Author

@kartben you have convinced me, with the "makeshift and error-prone", to take your change... partially, as I have removed the suggested usage to check for file existence.

@de-nordic de-nordic requested a review from kartben November 9, 2023 11:45
@kartben
Copy link
Collaborator

kartben commented Nov 9, 2023

@kartben you have convinced me, with the "makeshift and error-prone", to take your change... partially, as I have removed the suggested usage to check for file existence.

:)
I'm confused by your latest force-push -- it seems it's back to a previous state?

Copy link
Collaborator

@Laczen Laczen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making it clear from the start:

 * If @p flags are set to 0 the function will attempt to open file with
 * no read/write access. This should not be used to check if a file
 * exists as this will generate a log error when the file is not found
 * and requires the file to be closed when it is present. Instead use
 * fs_stat to check if a file exists.

@de-nordic
Copy link
Collaborator Author

de-nordic commented Nov 9, 2023

@kartben you have convinced me, with the "makeshift and error-prone", to take your change... partially, as I have removed the suggested usage to check for file existence.

:) I'm confused by your latest force-push -- it seems it's back to a previous state?

No, I have taken the warning part but removed suggestion for using fs_open to check if file exists at all.

Edit: Yeah, wrong branch pushed.... eh. Monday every day.

kartben
kartben previously approved these changes Nov 9, 2023
@de-nordic
Copy link
Collaborator Author

What about making it clear from the start:

 * If @p flags are set to 0 the function will attempt to open file with
 * no read/write access. This should not be used to check if a file
 * exists as this will generate a log error when the file is not found
 * and requires the file to be closed when it is present. Instead use
 * fs_stat to check if a file exists.

I, unfortunately, find this usage to be a hack. I know that this works but if the usage would be intended we would have to silence the error for that specific case. Additionally, if the file exists you have to actually close it afterwards, which is another possibility for mistake and leaving open handlers.
fs_open should be used for opening files.

We still need to fix some test cases that provide no flags, when checking whether they can open a file.

* 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 attempt to open file with
* no read/write access.
Copy link
Collaborator

@Laczen Laczen Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this have a @warning ? It seems to be an allowed usage pattern but why does it have a warning,

Copy link
Collaborator Author

@de-nordic de-nordic Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you will open file but will not be able to read/write to it.
Maybe. Because backends may interpret some of open flags differently, for example create may imply write on one backend, but not on an another.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I have with the @warning is that (without some extra information) the user does not know what is warned against.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, seems that the info no lack of read/write access is enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but when adding the @warning it should warn against something. Either remove the warning or add something like: When issued on a existing file the file needs to be closed afterwards. When issued on a non-existing file an error message will be generated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to mention error message, because any subsystem called by driver may actually render error messages, or not depending on Kconfig, so it is pointless to provide such message here.

kartben
kartben previously approved these changes Nov 21, 2023
include/zephyr/fs/fs.h Outdated Show resolved Hide resolved
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jan 21, 2024
@clamattia
Copy link
Contributor

@de-nordic What is the state on this? Was it decided, that it is not needed?
Thanks and have a good day.

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 zephyrproject-rtos#64030

Signed-off-by: Dominik Ermel <[email protected]>
@de-nordic
Copy link
Collaborator Author

@kartben I have taken in your Nit.

@github-actions github-actions bot removed the Stale label Jan 23, 2024
@de-nordic
Copy link
Collaborator Author

@kartben I have taken in your Nit.

Can you take a look again?

@kartben kartben added this to the v3.6.0 milestone Feb 6, 2024
@kartben
Copy link
Collaborator

kartben commented Feb 6, 2024

This should go into 3.6 as it is a documentation improvement.
Thanks @de-nordic! and sorry that I dropped the ball.

@de-nordic
Copy link
Collaborator Author

This should go into 3.6 as it is a documentation improvement. Thanks @de-nordic! and sorry that I dropped the ball.

Thanks! No problem.

@dleach02 dleach02 merged commit 07c1e49 into zephyrproject-rtos:main Feb 7, 2024
21 checks passed
@de-nordic de-nordic deleted the fix-for-64030 branch March 4, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

fs_open error log
7 participants