Skip to content

examples/userfs: use designated initializers for struct dirent#3554

Open
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:userfs-dirent-designated-init
Open

examples/userfs: use designated initializers for struct dirent#3554
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:userfs-dirent-designated-init

Conversation

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Summary

The userfs example initialized each g_rootdir[] entry's
struct dirent member positionally as { DTYPE_FILE, "FileN" }, which
assumes d_type is the first field of struct dirent.

apache/nuttx PR #19179 ("fs: widen ino_t to uint32_t and add d_ino to
struct dirent") adds the POSIX d_ino member as the first field of
struct dirent. With that change the positional initializer assigns the
file-name string to d_type (a uint8_t), producing
-Wint-conversion warnings and an
error: initializer element is not computable at load time, which broke
the CI build.

This change converts the three initializers to designated initializers
(.d_type / .d_name) so the table is robust against the field order of
struct dirent.

Impact

  • examples/userfs only. No functional change; the same d_type/d_name
    values are assigned. d_ino is left zero-initialized, which is fine for
    this in-memory test filesystem.

Testing

  • checkpatch.sh -f examples/userfs/userfs_main.c → all checks pass.
  • A standalone host program reproducing the table against a d_ino-first
    struct dirent compiles cleanly with -Wall -Wextra -Werror and assigns
    d_type=DTYPE_FILE, d_name="File1" as expected.

Related

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the examples/userfs in-memory directory table to use designated initializers for struct dirent so it remains correct even if the field order changes (e.g., with the addition of d_ino).

Changes:

  • Converted g_rootdir[] struct dirent initializers from positional to designated (.d_type, .d_name) for File1File3.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/userfs/userfs_main.c
Comment thread examples/userfs/userfs_main.c
Comment thread examples/userfs/userfs_main.c
The g_rootdir[] table initialized each entry's struct dirent member
positionally as { DTYPE_FILE, "FileN" }, which assumes d_type is the
first field.  This breaks when struct dirent gains the POSIX d_ino field
as its first member (see apache/nuttx: "fs/dirent: add d_ino member to
struct dirent"): the file-name string would be assigned to d_type,
producing -Wint-conversion warnings and an "initializer element is not
computable at load time" error.

Use designated initializers (.d_type / .d_name) so the table is robust
against the field order of struct dirent.

Also fix a 'Initiallly' typo in a nearby comment flagged by codespell.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 force-pushed the userfs-dirent-designated-init branch from 0977fec to e71f819 Compare June 20, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants