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

Deprecate OS_open and OS_creat #556

Closed
jphickey opened this issue Aug 12, 2020 · 12 comments · Fixed by #617 or #621
Closed

Deprecate OS_open and OS_creat #556

jphickey opened this issue Aug 12, 2020 · 12 comments · Fixed by #617 or #621
Assignees
Milestone

Comments

@jphickey
Copy link
Contributor

Is your feature request related to a problem? Please describe.
For historical/backward compatibility reasons, the API of these two functions doesn't follow the typical flow. Rather than providing a uint32 ID output buffer as the first argument with a separate int32 return code, they return the OSAL ID cast as an int32 on success. For these functions, the caller is expected to check if the result is negative, and if so, consider it an error code. Whereas if it is non-negative, the caller is expected to cast it back to a uint32 type and interpret it as an OSAL ID.

Describe the solution you'd like
These should be like all other OSAL APIs and pass back the ID separately from the return/error status.

Describe alternatives you've considered
Leave as is. But these two functions present a challenge when making a distinct type for OSAL IDs .

Additional context
In the current implementation,. these are just compatibility wrappers anyway. They both call OS_OpenCreate() internally, which provides both open (existing file) and creat (new file) based on the flags it was passed. The OS_OpenCreate function does follow the correct pattern so one option would be to just expose this to the public API.

The other option is to create a new version of OS_open and OS_creat which follow the correct pattern. But in order to provide a transition they would have to use different names.

Requester Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey
Copy link
Contributor Author

One other possible compromise is to keep these as-is returning int32, but provide another function to decode the return value into a status and ID of the correct type (e.g. uint32) rather than relying on the user to cast it themselves and do it properly.

This has been a source of confusion in the past, see #498.

@jphickey jphickey added CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) question labels Aug 12, 2020
@jphickey
Copy link
Contributor Author

Would like to get some feedback on this idea in the next CCB.

@skliper
Copy link
Contributor

skliper commented Aug 12, 2020

I'm in favor of the suggested approach (deprecate, expose OS_OpenCreate).

@skliper
Copy link
Contributor

skliper commented Aug 12, 2020

@acudmore @ejtimmon ping, deprecation proposal

@skliper
Copy link
Contributor

skliper commented Aug 12, 2020

CCB 2020-08-12: No objections, but solicited responses/review.

@jphickey
Copy link
Contributor Author

Also @CDKnightNASA - you might have some thoughts here as well?

Summary of questions are:

  1. Does the inconsistency/confusion around this API warrant making a breaking change to try to fix it and make it like the others?

If (1) is yes, then:

  1. Should we keep a separate open & creat routine or combine them into a single API, using flags to differentiate whether a file should be created or not? Or should we keep it 1:1 and offer a direct replacement for OS_open and OS_creat, to make it easier for apps to update?

If (1) is no, then:

  1. Is it worth providing a new API to help users check/decode the int32 value returned from these existing API calls? This would be backward compatible at least, as it doesn't change/remove any existing function, while alleviating the need for applications to directly cast/convert between OSAL IDs and other integer data types, which is the fundamental concern here.

@jwilmot
Copy link

jwilmot commented Aug 12, 2020

No objections to just using OS_OpenCreate as this follows the normal API structure found in many file systems where the create option flag is passed in. Hopefully the change only impacts a limited number of applications.

@jphickey
Copy link
Contributor Author

Worth noting, in case anyone is unconvinced about the benefits of being type-strict, I found a mistake/bug in the unit tests here, that's probably been lurking for quite some time, where it fails to handle this return code properly:

fd1 = OS_open(newfilename1,OS_READ_ONLY,0644);
UtAssert_True(status >= OS_SUCCESS, "status after open 1 = %d",(int)status);

This type of goof-up becomes very apparent/obvious when using a distinct type, and can actually trigger a compiler error if desired.

@ejtimmon
Copy link

@acudmore @ejtimmon ping, deprecation proposal

This will impact several apps, but I'm not opposed.

@skliper skliper modified the milestones: 6.0.0, 5.2.0 Aug 13, 2020
@astrogeco astrogeco added CCB-20200812 and removed CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) labels Aug 14, 2020
@skliper skliper modified the milestones: 5.2.0, 6.0.0 Sep 1, 2020
@skliper
Copy link
Contributor

skliper commented Sep 21, 2020

@jphickey - did you start implementing this change, or want me to take it?

@jphickey
Copy link
Contributor Author

A previously merged PR has already exposed the OS_OpenCreate() API in the public header as discussed, so the next step was to replace current CFE references to OS_open/OS_creat.

I hadn't started on that apart yet because I needed to get nasa/cFE#868 in first, but now that is settled there shouldn't be any issue in replacing these refs now. I can submit a CFE ticket for that. If someone else is available and wants to take it on that would be fine, otherwise I'm happy to do it.

@jphickey
Copy link
Contributor Author

See nasa/cFE#893 for the CFE work to be done.

jphickey added a commit to jphickey/osal that referenced this issue Oct 2, 2020
These functions are replaced by OS_OpenCreate, which
implements both functions via flags, and follows the
correct OSAL API patterns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants