Skip to content

feature: Initial Windows compilation and command support using MinGW#3111

Draft
bgoing-micron-oss wants to merge 51 commits intolinux-nvme:masterfrom
Micron-TPG-OSS:windows-initial-review
Draft

feature: Initial Windows compilation and command support using MinGW#3111
bgoing-micron-oss wants to merge 51 commits intolinux-nvme:masterfrom
Micron-TPG-OSS:windows-initial-review

Conversation

@bgoing-micron-oss
Copy link

This is the initial proof-of-concept review for porting nvme-cli to Windows
using mingw-w64. This compiles on both Linux and Windows, and
demonstrates the proposed structure for cross-platform support and for
Windows IOCTL support. Initial testing of identify and get log page
have been successful.

  • Compiles on both Linux and Windows using the same Meson commands.
  • Support targets Windows 11 / Server 2022 and later.
  • Uses GCC, headers, and libraries that are part of mingw-w64 to simplify
    cross-platform support.
  • See WINDOWS-PORT-README.md for discussion of design decisions and strategy.
  • See ENVIRONMENT.md for Windows build system requirements.

Co-Developed-by: Broc Going bgoing@micron.com
Co-Developed-by: Brandon Capener bcapener@micron.com
Co-Developed-by: Brandon Busacker bbusacker@micron.com

jimmunn and others added 30 commits January 8, 2026 13:55
* feat: Windows cross-platform support for libnvme

Added libnvme build support for Windows.

- Added platform-specific include files for Linux/Windows.
- Added BUILD.md with detailed build instructions for Linux and Windows
- Added ENVIRONMENT.md with environment setup guide for both platforms
- Fix format string warnings in nbft.c (use %u instead of %zd for MinGW compatibility)
- Add forward declarations in windows-stubs.c to fix struct warnings
- Skipping generate-accessors for now.  Needs to be ported for Windows.
- Note: leaving asprintf warning in generate-accessors.c since it is present in the master branch as well.

Co-authored-by: Broc Going <bgoing@micron.com>
Co-authored-by: bbusacker <bbusacker@localhost.localdomain>
Co-authored-by: Brandon Capener <bcapener@micron.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* add tests kdoc and uuid

* Update libnvme/scripts/kernel-doc-check.ps1 no perl found error message

Co-authored-by: Broc Going <bgoing@micron.com>

---------

Co-authored-by: Broc Going <bgoing@micron.com>
* Merge origin/master into mingw

* add guards around the incoming upstream MIN macro
…inux-nvme#38)

* Merge origin/master into mingw

* Initial plan

* Fix circular dependency in platform_linux.h by removing cleanup.h include

Co-authored-by: bbusacker_micron <199673931+bbusacker_micron@users.noreply.github.com>

* use the code base standard for initializing variables

---------

Co-authored-by: Brandon Capener <bcapener@micron.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bbusacker_micron <199673931+bbusacker_micron@users.noreply.github.com>
* docs: Add comprehensive TODO.md for Windows port status

- Document all excluded plugins with priority ratings
- Detail critical missing device I/O functionality
- List implementable stubs (global context, dry-run, host NQN)
- Clarify fabrics string converters not needed (require Linux kernel)
- Add implementation phases and effort estimates
- Minor cleanup: nvme-rpmb.c whitespace

* feat: Add Windows support for nvme-cli

Enable compilation and linking of nvme-cli on Windows using MinGW-W64.
The build succeeds and produces a functional nvme.exe with help system
and 19 vendor plugins. Device I/O operations are stubbed (see TODO.md).

Core Changes:
- Expanded Windows POSIX compatibility layer in platform/windows.h/.c
  * dirent emulation (opendir/readdir/closedir)
  * POSIX functions: getline, strsep, reallocarray, gmtime_r
  * Signal handling: sigaction, sigemptyset
  * Memory mapping stubs: mmap, munmap, madvise
  * DLL loading: dlopen/dlsym/dlclose wrappers
  * mkdir wrapper, readlink stub, open_memstream stub
  * Fabrics/RPMB command stubs (commands registered but unsupported)

- Add platform/types.h stub that defines Windows equivalents to linux/types.h.

- Extend libnvme/src/nvme/windows-stubs.c with 120+ stub functions
  * Keyring/TLS functions (nvme_read_key, nvme_insert_tls_key_*, etc.)
  * Fabrics string converters (nvmf_trtype_str, nvmf_sectype_str, etc.)
  * Tree/topology functions (nvme_scan_topology, nvme_create_root, etc.)
  * Device operations (nvme_open, nvme_close)
  * Host NQN generation (nvmf_hostnqn_generate*)
  * NBFT, global context, path properties

Build System Changes:
- Update meson.build to exclude fabrics.c and nvme-rpmb.c on Windows
- Add windows-stubs.c to Windows-specific sources
- Add Windows library dependencies (ws2_32, wsock32, kernel32, iphlpapi)
- Conditional link args (-ldl on Linux only)

- Update plugins/meson.build:
  * 19 cross-platform plugins enabled (including micron)
  * 10 Linux-only plugins excluded (huawei, ibm, netapp, sandisk,
    scaleflux, wdc, ymtc, zns, lm)

Code Modifications:
- Changed #include of linux/includes.h to platform/includes.h accross the project.
- Add min/max macro guards in common.h to prevent Windows conflicts

Known Limitations:
- All device I/O operations are stubbed (ioctl returns -ENOSYS)
- Cannot open NVMe devices or enumerate devices
- fabrics and rpmb commands print 'not supported on Windows'
- See TODO.md for detailed implementation roadmap

* Fix Windows compilation warnings

- plugins/intel/intel-nvme.c: Use uintptr_t for pointer-to-int casts for 64-bit compatibility
- plugins/micron/micron-nvme.c: Guard min macro definition to avoid redefinition warnings
- plugins/micron/micron-nvme.c: Replace %T with %H:%M:%S in strftime for Windows compatibility
- nvme-print-stdout.c: Fix array-bounds warnings with proper union-based type conversion

* Consolidate Windows platform headers

Reorganizes Windows compatibility layer for cleaner separation between
OS-level abstractions (libnvme) and application-specific code (nvme-cli).

OS-level abstractions (libnvme platform layer):
- Created libnvme/src/nvme/platform/platform_windows.h
  * Windows-specific includes (winsock2.h, windows.h, dirent.h)
  * POSIX compatibility: getline, strsep, reallocarray, readlink,
    open_memstream, fnmatch
  * Signal handling: sigaction, sigemptyset
  * Error codes: ENAVAIL, EREMOTEIO, EDQUOT, ENOTBLK, etc.
  * ioctl constants: BLKBSZSET, BLKRRPART
  * Mode_t typedef and mkdir wrapper macro

- Created libnvme/src/nvme/platform/platform_windows.c
  * POSIX function implementations for Windows compatibility
  * Added exports to libnvme.map for DLL symbol visibility

Application-level stubs (nvme-cli layer):

- Created windows-stubs.c
  * Application-specific stubs: fabrics_discovery, fabrics_connect,
    fabrics_disconnect, fabrics_config, fabrics_dim, rpmb_cmd_option

Combined platform-specific support for both nvme-cli and libnvme and restructured and renamed some of the platform-specific files.

- Moved nvme/platform/*.* into platform/*.* and removed platform_ from file names.
- Moved Windows-specific linux/types.h into platform/types.h and fixed it to support linux.  Updated references to linux/types.h to use platform/types.h.

* Fixed warnings on Windows.

* PATH_MAX is used for some buffers in micron-nvme.c where it is assumed to be larger than 1024.  On Windows it is 260.  On Linux it is typically 4096.  Using 4096.

- Fixed possible underflow error during size comparison.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Broc Going <bgoing@micron.com>
Co-authored-by: Brandon Capener <bcapener@micron.com>
Co-authored-by: Brandon Busacker <bbusacker@micron.com>
Add workflow to auto-merge master into mingw
Use personal access token (PAT) so workflow can push the merge.
Remove --strict from call to checkpatch.pl to match upstream behavior.
github-actions bot and others added 21 commits February 10, 2026 19:15
…OCTLs (linux-nvme#50)

* Broke methods with Linux ioctl calls into linux-specific implementation file and added stubs for Windows implementations.

* Added admin command stubs for supported commands.

* Initial implementation of nvme_submit_admin_identify.

Compiles. Untested.

* Removed ioctl stub function from platform_windows.h

Any ioctl calls need to be handled by Windows-specific code.  Current libnvme ioctl calls have been moved into ioctl-linux.c/ioctl-windows.c, so the ioctl stub in platform_windows.h is no longer needed.

* Added initial implementation of nvme_submit_admin_vendor_unique (passthrough)

* Pulled command initialization out of loop and additional cleanup.

* Added Get Log Page implementation.

* Updates for format_cmd direct ioctl calls.

- Calling nvme_ns_rescan instead of direct NVME_IOCTL_RESCAN ioctl call.
- Restored ioctl stub in platform/windows.h as temporary workaround for direct BLKBSZSET and BLKRRPART ioctl calls.
- Updated TODO.md entry for ioctl stub to note what will be needed to get rid of the stub.

* Implemented get features command.

* Implemented Set Features command.

* Removed unsupported SubValue5 setting.

* Implemented FW Download.  Several TODO comments left that require verification.

* Added FW commit implementation.

* Fixed security receive check and method name.

* Added security send/receive implementations.

* Implement self test and sanitize using storage protocol command pass-through.

* Format NVM implemented as much as possible based on documentation.

* Cleanup and fixes.

* Removing unrelated changes to ioctl usage in nvme.c.  Saving for a separate PR.

* REmoving unneccesary .gitignore change.

* Fixed checkpatch errors and explicitly added windows includes.

* Fixed identify CSI check.

* Checking SCSI command status after IOCTL_SCSI_PASS_THROUGH

* Handling data direction of storage protocol passthrough commands and added some more error checking.

* Fixed opening brace formatting reported by checkpatch.

* Fixing checkpatch formatting warnings where feasible.

* More minor checkpatch fixes.

* Removed HANDLE casts and switched to using hdl->fd directly.

A recent change that was merged in updated the type of nvme_transport_handle::fd on Windows builds to be HANDLE, so casting the value and storing it in a new variable was no longer necessary.

* Update ioctl-linux.c to align with upstream changes.

Co-authored-by: Brandon Capener <bcapener@micron.com>

* Moving linux implementations back into main ioctl.c.

To make merges from upstream easier for now, leaving linux-specific implementations where they are, but inside of #ifndef _WIN32 blocks.  Eventually we will probably pull these out again.

---------

Co-authored-by: Brandon Capener <bcapener@micron.com>
…x-nvme#55)

After further research and experimentation, it looks like BufferSize
and Offset need to be byte counts.  Alignment refers to the buffer
alignment in memory.
Experimentation shows that 4K alignment is required.
Evaluation of the code shows that this buffer alignment is already
handled by the code creating the firmware buffer.
* Manually merged master into mingw and resolved conflicts.
* Fixed build issues on Windows caused by merged changes.
The signature changed in the latest tree.h changes.
Updated to match.
- Merge remote-tracking branch 'origin/master' into mingw.
- Updated nvme_dump_config windows stub to match new signature.
Includes  manually resolved conflicts.
Add support for nvme_open, nvme_close, nvme_alloc_huge, nvme_free_huge.
tested command: `nvme id-ctrl PhysicalDrive0`
I added `windows.c` for implementations of functions from linux.h

Add new free functions that must match the allocation function
* `posix_memalign` uses new `platform_aligned_free` function. used in
both nvme-cli and libnvme.
* `nvme_alloc` uses new `nvme_free` function. used in nvme-cli
* `__nvme_alloc` uses new `__nvme_free` function. used in libnvme

---------

Co-authored-by: Broc Going <bgoing@micron.com>
* Cleaned up formatting in includes.h and linux.h.
* Standardized positioning of platform/includes.h includes and removed
comments.
* Updated more files to use platform/includes.h and removed _WIN32
checks.
* Removed platform-agnostic includes from platform/includes.h. They were
still being included explicitly where needed, and it didn't make sense
to have them included in the platform-specific includes file as well.
The build instructions are already documented in README.md,
and Windows builds now follow the same pattern.

Removed ENVIRONMENT.md references to MSVC.
This file will likely not be needed for the final merge,
but it provides good documentation for now.
It would be good to figure out how best to add it to README.md.
…s. (linux-nvme#58)

Added a document intended to provide an overview of direction
we've gone with the Windows port, and some background behind some of the
things we've done in the code. This document can be removed before the
actual PR into the upstream project.
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.

5 participants