Skip to content

Conversation

@kubiak-jpl
Copy link
Contributor

Related Issue(s) 4604
Has Unit Tests (y/n) N
Documentation Included (y/n) Y
Generative AI was used in this contribution (y/n) N

Change Description

Creates an OsCfg.fpp configuration file with a default file creation mode constant. Os/Posix/File is updated to use this constant when creating new files. This allows the F Prime developer to control permissions on files created with Os::File, at least globally for the deployment

Rationale

This is a fix that would have been useful for a previous F Prime project, where the default 600 permissions caused operational headaches when the files were created by root, but access by a normal user

Testing/Review Recommendations

A small bit of test code was added to the reference topology to create files with this interface. All defined FILE_MODE_ bits were tested in one form or another on a Debian 13 system. The code was also compiled under Darwin and files were created with the expected permissions.

diff --git a/Ref/Top/RefTopology.cpp b/Ref/Top/RefTopology.cpp
index 6d18f751d..389f120f3 100644
--- a/Ref/Top/RefTopology.cpp
+++ b/Ref/Top/RefTopology.cpp
@@ -53,6 +53,10 @@ void configureTopology() {
 
     // Command sequencer needs to allocate memory to hold contents of command sequences
     cmdSeq.allocateBuffer(0, mallocator, 5 * 1024);
+
+    Os::File test_file;
+    test_file.open("test_file.txt", Os::FileInterface::OPEN_CREATE);
+    test_file.close();
 }

No testing was done on other operating systems. In particular, I am not sure how the VxWorks, FreeRTOS or Zephr OS layers will behave if they use the Os/Posix abstraction for File.

Future Work

I would also like to change the default creation mode from 600 to 666. That is the default used by multiple unix tools (touch, vim). End users can drop permissions by changing the config constant or by using umask with their application.

AI Usage (see policy)

No AI assistance used.

}

mode_t PosixFile::map_open_create_mode(const U32 create_mode) {
mode_t out_mode = 0;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

out_mode uses the basic integral type unsigned int rather than a typedef with size and signedness.
break;
}
int descriptor = ::open(filepath, mode_flags, USER_FLAGS);
int descriptor = ::open(filepath, mode_flags, map_open_create_mode(Os::FILE_DEFAULT_CREATE_MODE));

Check notice

Code scanning / CodeQL

Use of basic integral type Note

descriptor uses the basic integral type int rather than a typedef with size and signedness.

// Some posix systems (e.g. Darwin) use the older S_IREAD and S_IWRITE flags
// while other systems (e.g. Linux) use the newer S_IRUSR and S_IWUSR flags.
#if defined(S_IREAD)

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Necessary to support Linux and MacOS (ie. BSD mode_t constants)

@thomas-bc
Copy link
Collaborator

Note: we should clearly mark the configuration as Posix-specific

module Os {

@ File open mode permission bits
@ Constant values are derived from standard
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CCB recommends that we namespace this further to make it clear it is meant to apply only to Posix. Other implementations may borrow from it if they want (e.g. VxWorks seems to have the same API?) but it should be clear that this isn't a universal config.

So something like such:

module Os {

  module Posix {
    [ ....]
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree that this should be further namespaced.

The intention is that the FILE_MODE_ bits can be used across different backends. I only implemented it in the Posix backend because that's the only one I'm familiar with. However, the constants could be referenced by other backends. The Posix::File::map_open_create_mode maps these FILE_MODE_ bits to mode_t bits for Posix, but a similar function could be defined for VxWorks or zephyr to map FILE_DEFAULT_CREATE_MODE to the specific permission bits for those platforms.

Copy link
Collaborator

@thomas-bc thomas-bc Jan 16, 2026

Choose a reason for hiding this comment

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

What we want to avoid is for users to believe that this option will unambiguously happen anywhere, when that's not the case.
VxWorks and Zephyr happen to have the option to have some compliance with Posix w.r.t. file management, so I'd say it's not wrong to namespace Os::Posix when Posix is precisely what Zephyr/VxWorks are trying to comply with? (I might be reaching at straws haha)
I have no strong opinion, let's discuss with the team.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that we agree that, as much as possible, OSALs should attempt to respect this config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we agree that, as much as possible, OSALs should attempt to respect this config

If that's the case then I think that namespacing it under Os::Posix would discourage other OSALs from using the interface, and make it look like this is only intended to be a Posix thing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very true!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a thought, but could using an HPP file instead of FPP solve some of these concerns (conditional compilation / includes or whatnot)? Also easier to just reuse the Posix constants rather than re-define them in FPP

@ File open mode permission bits
@ Constant values are derived from standard
@ Unix values, but should not be assumed
@ to match
Copy link
Collaborator

Choose a reason for hiding this comment

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

What should not be assumed to match? I'm not sure I follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants