Skip to content

meterfs: Start file id's from 1#152

Merged
anglov merged 1 commit intomasterfrom
anglov/meterfs_id1
Aug 19, 2025
Merged

meterfs: Start file id's from 1#152
anglov merged 1 commit intomasterfrom
anglov/meterfs_id1

Conversation

@anglov
Copy link
Member

@anglov anglov commented Jul 29, 2025

Common usage of meterfs involves using static fd table in zeroed bss. This causes that programmer error (eg. invalid initialisation) can lead to weird and hard to identify errors, that someone writes to firstly created file, instead of proper one.

Starting id from 1 can help to avoid that kind of issues.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @anglov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a change in the meterfs file system to ensure that all file IDs are 1-based instead of 0-based. The primary motivation is to mitigate hard-to-identify errors that can arise when using static file descriptor tables initialized to zero, by making the first valid file ID non-zero. This change affects how file IDs are generated and validated within the system.

Highlights

  • File ID Shifting: Modified the meterfs_rbTreeFill and meterfs_allocateFile functions in meterfs.c to ensure that all file IDs are assigned starting from 1 instead of 0. This is achieved by adding + 1 to the calculated file ID during both initial tree population and new file allocation.
  • Zero ID Assertion: Added an assert(id != 0); check at the beginning of the node_add function in meterfs/node.c. This explicitly prevents the use of file ID 0, reinforcing the new 1-based indexing scheme and helping to catch potential programming errors early.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the file ID allocation to start from 1 instead of 0. This is a good defensive measure to prevent bugs arising from uninitialized file descriptors, which might default to 0. The implementation correctly adjusts ID generation and adds an assertion to enforce that file ID 0 is invalid. My review includes a suggestion to improve a comment's clarity and ensure consistent casting style, enhancing code maintainability.

@github-actions
Copy link

github-actions bot commented Jul 29, 2025

Unit Test Results

8 201 tests  ±0   7 677 ✅ ±0   40m 59s ⏱️ -1s
  479 suites ±0     524 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 19dd2d5. ± Comparison against base commit e368661.

♻️ This comment has been updated with latest results.

@anglov anglov requested review from agkaminski and nalajcie July 31, 2025 17:06
@anglov anglov marked this pull request as ready for review July 31, 2025 17:06
Common usage of meterfs involves using static fd table in zeroed bss.
This causes that programmer error (eg. invalid initialisation) can lead
to weird and hard to identify errors, that someone writes to firstly
created file, instead of proper one.

Starting id from 1 can help to avoid that kind of issues.
@anglov anglov force-pushed the anglov/meterfs_id1 branch from b701d8f to 19dd2d5 Compare August 18, 2025 15:00
@anglov anglov merged commit 7c0791e into master Aug 19, 2025
38 checks passed
@anglov anglov deleted the anglov/meterfs_id1 branch August 19, 2025 12:06
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