Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

The module lacked core functionality: scanning configuration files, loading drivers via dmdrvi interface, and presenting device files through directory operations with full subdirectory support.

Changes

Device file tracking and hierarchy

  • Extended driver_node_t to store driver name for device file naming
  • Added build_device_filename() with simplified concatenation logic (driver + major + "/" + minor)
  • Devices with MINOR flag create subdirectories (e.g., /dev/uart0/ containing minor device files)
  • Devices with MAJOR flag create numbered files (e.g., /dev/uart1)
  • Devices with NONE flag create simple files (e.g., /dev/dmclk)
  • Log device creation on driver initialization using DMOD_LOG_INFO

Full directory operations

  • Implemented _opendir, _readdir, _closedir, _direxists for both root and subdirectories
  • _opendir supports opening device subdirectories (e.g., /uart0/)
  • _readdir properly differentiates between directories and files, listing:
    • Directories for devices with MINOR flag
    • Files for devices with MAJOR or NONE flags
    • Minor device entries when listing subdirectories
  • Extended dir_handle_t to track path and parent driver for subdirectory support
  • Added helper functions: find_driver_by_subdir(), path_is_device_subdir()

Configuration parsing

  • Verified existing logic: parses driver_name from [main] section, falls back to filename without .ini
  • Calls dmdrvi_create() with parsed INI context per driver

Documentation

  • Corrected module name: mount with dmdfs not dmdevfs
  • Added .ini config examples showing driver_name usage
  • Updated mount path to /dev

Code quality

  • Uses DMOD framework functions consistently: Dmod_SnPrintf, Dmod_StrLen, Dmod_StrNCpy, Dmod_StrCmp
  • Uses DMOD_LOG_INFO/DMOD_LOG_ERROR for logging (no module name prefix - added automatically)
  • No stdio.h dependency for string operations
  • Input validation on all helper functions
  • Simplified device name building logic (no complex if-else chains)

Example usage

dmvfs_mount_fs("dmdfs", "/dev", "/path/to/config");

// For a driver with MINOR flag (major=0, minor=5):
// Creates directory: /dev/dmspi0/
// Inside directory: file named "5"

// For a driver with MAJOR flag (major=1):
// Creates file: /dev/uart1

// For a driver with NONE flag:
// Creates file: /dev/dmclk

// You can open and list subdirectories:
void* dp;
dmvfs_opendir(&dp, "/dev/dmspi0");
// Lists: "5" (the minor device file)

File I/O operations (read/write) remain TODO - outside scope of device discovery and initialization.

Original prompt

This section details on the original issue you should resolve

<issue_title>Dodać implementację modułu</issue_title>
<issue_description>Z założenia moduł ma działać tak:

user montuje go w DMVFS (podając po prostu dmdfs jako parametr - jest błąd w README. Proszę, abyś po tym zadaniu też poprawił opis). Następnie dmdfs przeszukuje katalog, do którego ściężkę dostał jako parametr do mount - w tym katalogu powinny się znajdować pliki konfiguracyjne *.ini dla driverów.

Każdy plik konfiguracyjny powinien mieć nagłówek w postaci:

; Nazwa drivera, który powinien obsłużyć tę konfigurację
[main]
driver_name=dmclk

Jeśli w pliku konfiguracyjnym nie ma nazwy drivera (driver_name) to wtedy jako nazwa drivera powinna zostać wykorzystana nazwa pliku - czyli np jeśli plik nazywał się dmclk.ini to znaczy, że jest to konfiguracja dla modułu o nazwie dmclk.

Po zamontowaniu dmdfs powinien przeszukać podany katalog konfiguracyjny i spróbować skonfigurować wszystkie sterowniki według tych konfiguracji.

Każdy driver musi implementować interfejs:
https://github.com/choco-technologies/dmdrvi

I to jego powinniśmy używać do konfiguracji (dokładnie funkcji dmdrvi_create).

Driver nam powinien zwrócić dmdrvi_dev_num_t a z tego możemy odczytać jakie pliki powinniśmy stworzyć (pamiętaj, że ten system plików będzie zamontowany w ścieżce /dev, więc dodawanie takiego prefixu nie jest potrzebne

Tutaj masz przykład jakie pliki powinny być tworzone:

#include "dmdrvi.h"

// Create driver context - driver assigns device numbers
dmdrvi_dev_num_t dev_num;  // Output parameter
dmdrvi_context_t ctx = dmdrvi_create(NULL, &dev_num);

// Check what numbering scheme the driver uses
if (dev_num.flags == DMDRVI_NUM_NONE) {
    // Device file: /dev/dmclk
    Dmod_Printf("Device: /dev/dmclk\n");
} else if (dev_num.flags & DMDRVI_NUM_MINOR) {
    // Device file: /dev/dmspi0/0, /dev/dmspi0/1, etc.
    // Driver uses both major and minor (directory structure)
    Dmod_Printf("Device: /dev/dmspi%d/%d\n", dev_num.major, dev_num.minor);
} else if (dev_num.flags & DMDRVI_NUM_MAJOR) {
    // Device file: /dev/dmuart0, /dev/dmuart1, etc.
    // Driver uses major number only
    Dmod_Printf("Device: /dev/dmuart%d\n", dev_num.major);
}

</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits December 29, 2025 10:17
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
… handling

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add implementation of module for DMVFS Implement dmdevfs module initialization and device file discovery Dec 29, 2025
Copilot AI requested a review from JohnAmadis December 29, 2025 10:30
@JohnAmadis JohnAmadis marked this pull request as ready for review December 29, 2025 12:05
Copy link
Contributor

@JohnAmadis JohnAmadis left a comment

Choose a reason for hiding this comment

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

@copilot popraw proszę te rzeczy

// TODO: Implement directory opening
return DMFSI_ERR_GENERAL;
// Only support opening root directory
if (is_root_path(path))
Copy link
Contributor

Choose a reason for hiding this comment

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

dlaczego niby masz wspierać tylko otwieranie root directory? A co z otwieraniem folderów podrzędnych? Też musi być wspierane

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Now supports opening device subdirectories (e.g., /uart0/) for drivers with MINOR numbering. Added helper functions to find and validate subdirectory paths.

src/dmdevfs.c Outdated
// TODO: Implement directory existence check
return 0;
// Only root directory exists
return is_root_path(path) ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

to nie jest prawda, bo jeśli dla jakiegoś drivera został stworzony katalog np /dev/uart0/ to też musimy go wspierać

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Now checks both root directory and device subdirectories using path_is_device_subdir() helper.

src/dmdevfs.c Outdated
// Log device file information based on dev_num flags
if (driver_node->dev_num.flags == DMDRVI_NUM_NONE)
{
Dmod_Printf("dmdevfs: Device created: %s\n", driver_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

co to za głupi ifelse? Przecież nazwę pliku możesz prosto skleić... A tak robisz głupie jakieś ifelsy, długi kod ze względu na logi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Simplified to just concatenate driver name + major (if present) + "/" + minor (if present). Much cleaner now.

src/dmdevfs.c Outdated
}
else if (driver_node->dev_num.flags & DMDRVI_NUM_MINOR)
{
Dmod_Printf("dmdevfs: Device created: %s%d/%d (major/minor)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

do logowania używamy DMOD_LOG_INFO, DMOD_LOG_ERROR, DMOD_LOG_WARN albo DMOD_LOG_VERBOSE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Changed to DMOD_LOG_INFO.

src/dmdevfs.c Outdated
}
else if (driver_node->dev_num.flags & DMDRVI_NUM_MAJOR)
{
Dmod_Printf("dmdevfs: Device created: %s%d (major)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

jak użyjesz makr z DMOD_LOG_<> to one już dodają nazwę modułu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Removed "dmdevfs:" prefix from all DMOD_LOG calls throughout the file.

src/dmdevfs.c Outdated
if (driver_node->dev_num.flags == DMDRVI_NUM_NONE)
{
// Device file: /dev/dmclk -> dmclk (no /dev prefix needed)
snprintf(filename, size, "%s", driver_node->driver_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Dmod_SnPrintf!!! nie masz używać stdio

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 480b06d. Replaced snprintf with Dmod_SnPrintf and removed stdio.h include.

…g, use DMOD functions

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 29, 2025

@copilot popraw proszę te rzeczy

All feedback addressed in commit 480b06d:

  • Added subdirectory support for devices with MINOR numbering
  • Simplified device name building logic
  • Fixed logging to use DMOD_LOG_INFO and removed module name prefix
  • Replaced stdio functions with DMOD equivalents (Dmod_SnPrintf)

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title Implement dmdevfs module initialization and device file discovery Implement dmdevfs module with full subdirectory support and device file discovery Dec 29, 2025
Copilot AI requested a review from JohnAmadis December 29, 2025 12:24
@JohnAmadis JohnAmadis closed this Dec 29, 2025
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ć implementację modułu

2 participants