Skip to content

Add dmdrvi v0.5 eof API support with file-size fallback#39

Merged
JohnAmadis merged 2 commits intomainfrom
copilot/add-eof-support-to-dmdevfs
Mar 11, 2026
Merged

Add dmdrvi v0.5 eof API support with file-size fallback#39
JohnAmadis merged 2 commits intomainfrom
copilot/add-eof-support-to-dmdevfs

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

_eof in dmdevfs always returned 0 (never at EOF), which required every driver to implement its own EOF tracking. With dmdrvi v0.5 introducing an optional eof API, dmdevfs should delegate to it when available and fall back to size-based calculation otherwise.

Changes

  • file_handle_t — added bytes_read field to accumulate total bytes read per handle
  • _fopen — initializes bytes_read = 0
  • _fread — increments handle->bytes_read after each read
  • _eof — new priority logic:
    1. If driver exposes dmod_dmdrvi_eof_sig → delegate to it (streaming drivers can return false permanently)
    2. Else if driver_stat returns a size → bytes_read >= size
    3. Else → return 0 (indeterminate)
dmod_dmdrvi_eof_t dmdrvi_eof = Dmod_GetDifFunction(handle->driver->driver, dmod_dmdrvi_eof_sig);
if(dmdrvi_eof != NULL)
    return dmdrvi_eof(handle->driver->driver_context, handle->driver_handle);

dmdrvi_stat_t stat = {0};
if(driver_stat(handle->driver, handle->path, &stat) == 0)
    return (handle->bytes_read >= (size_t)stat.size) ? 1 : 0;

return 0;

Default behavior flips from "never EOF" to "file-like EOF" — drivers that need streaming semantics must now opt in via the eof API.

Original prompt

This section details on the original issue you should resolve

<issue_title>Dodać wykorzystanie nowego API - eof</issue_title>
<issue_description>W wersji v0.5 w dmdrvi zostało dodane nowe API eof, które może być zaimplementowane przez drivery - trzeba dodać wsparcie dla tego w dmdevfs. Jeśli jakiś driver nie zaimplementował eof, to po prostu odczytujemy rozmiar pliku, liczbę odczytanych bajtów i na tej podstawie obliczamy czy już jest eof czy też nie. Czyli domyślne zachowanie powinno być inne niż jest teraz - domyślnie niech drivery będą zwykłymi plikami, a dopiero jeśli zaimplementują sobie eof, to wtedy mogą sobie zwracać zawsze false na eof - będzie to sensowniejsze, bo dzięki temu każdy driver nie będzie musiał implementować własnego eof z mierzeniem czy już jest koniec pliku czy też nie </issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

- Add bytes_read field to file_handle_t to track total bytes read
- Initialize bytes_read = 0 on file open (_fopen)
- Accumulate bytes_read after each _fread call
- Modify _eof to delegate to driver's eof API if implemented,
  otherwise fall back to comparing bytes_read against file size,
  and return 0 (not at EOF) if file size is unavailable

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for new eof API in dmdevfs Add dmdrvi v0.5 eof API support with file-size fallback Mar 11, 2026
@JohnAmadis JohnAmadis marked this pull request as ready for review March 11, 2026 08:58
@JohnAmadis JohnAmadis merged commit 2ba701f into main Mar 11, 2026
1 check passed
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.

Dodać wykorzystanie nowego API - eof

2 participants