Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libnvme/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ headers = [
'nvme/endian.h',
'nvme/filters.h',
'nvme/ioctl.h',
'nvme/lib-compat.h',
'nvme/lib-types.h',
'nvme/lib.h',
'nvme/linux.h',
Expand Down
2 changes: 1 addition & 1 deletion libnvme/src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ __public int libnvme_update_block_size(struct libnvme_transport_handle *hdl,
int block_size)
{
int ret;
int fd = libnvme_transport_handle_get_fd(hdl);
libnvme_fd_t fd = libnvme_transport_handle_get_fd(hdl);

ret = ioctl(fd, BLKBSZSET, &block_size);
if (ret < 0)
Expand Down
27 changes: 27 additions & 0 deletions libnvme/src/nvme/lib-compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* This file is part of libnvme.
* Copyright (c) 2026 Micron Technology, Inc.
*
* Cross-platform compatibility definitions, types, and utilities.
*
* Authors: Brandon Capener <[email protected]>
*/
#pragma once

#if defined(_WIN32)

#define WIN32_LEAN_AND_MEAN /* keeps windows.h from including winsock */
#include <windows.h>

typedef HANDLE libnvme_fd_t;

Check failure on line 17 in libnvme/src/nvme/lib-compat.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: do not add new typedefs
#define LIBNVME_INVALID_FD INVALID_HANDLE_VALUE
#define LIBNVME_TEST_FD ((HANDLE)0xFD)

#else

typedef int libnvme_fd_t;

Check failure on line 23 in libnvme/src/nvme/lib-compat.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: do not add new typedefs
#define LIBNVME_INVALID_FD -1
#define LIBNVME_TEST_FD 0xFD

#endif
4 changes: 2 additions & 2 deletions libnvme/src/nvme/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@

if (!strncmp(name, "NVME_TEST_FD", 12)) {
hdl->type = LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT;
hdl->fd = 0xFD;
hdl->fd = LIBNVME_TEST_FD;

if (!strcmp(name, "NVME_TEST_FD64"))
hdl->ioctl_admin64 = true;
Expand Down Expand Up @@ -287,7 +287,7 @@
}
}

__public int libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl)
__public libnvme_fd_t libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl)

Check failure on line 290 in libnvme/src/nvme/lib.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 91 exceeds 80 columns
{
return hdl->fd;
}
Expand Down
6 changes: 4 additions & 2 deletions libnvme/src/nvme/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdbool.h>
#include <stdio.h>

#include <nvme/lib-compat.h>
#include <nvme/lib-types.h>

enum libnvme_log_level {
Expand Down Expand Up @@ -94,9 +95,10 @@
* If the device handle is for a ioctl based device,
* libnvme_transport_handle_get_fd will return a valid file descriptor.
*
* Return: File descriptor for an IOCTL based transport handle, otherwise -1.
* Return: File descriptor for an IOCTL based transport handle,
* otherwise LIBNVME_INVALID_FD.
*/
int libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl);
libnvme_fd_t libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl);

Check failure on line 101 in libnvme/src/nvme/lib.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 83 exceeds 80 columns

/**
* libnvme_transport_handle_get_name - Return name of the device
Expand Down
3 changes: 2 additions & 1 deletion libnvme/src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ccan/list/list.h>

#include "nvme/nvme-types.h"
#include "nvme/lib-compat.h"
#include "nvme/lib-types.h"

#include <nvme/tree.h>
Expand Down Expand Up @@ -156,7 +157,7 @@ struct libnvme_transport_handle {
__u32 timeout;

/* direct */
int fd;
libnvme_fd_t fd;
struct stat stat;
bool ioctl_admin64;
bool ioctl_io64;
Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/ana.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define PDU_SIZE NVME_LOG_PAGE_PDU_SIZE

static struct libnvme_transport_handle *test_hdl;
Expand Down Expand Up @@ -631,7 +630,7 @@ int main(void)
struct libnvme_global_ctx *ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl),
"opening test link failed");

Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define HEADER_LEN 20

static struct libnvme_transport_handle *test_hdl;
Expand Down Expand Up @@ -441,7 +440,7 @@ int main(void)
struct libnvme_global_ctx *ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl),
"opening test link failed");

Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define TEST_TIMEOUT 1234
#define TEST_NSID 0x89ABCDEF
#define TEST_CDW11 0x11111111
Expand Down Expand Up @@ -1625,7 +1624,7 @@ int main(void)
struct libnvme_global_ctx *ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl),
"opening test link failed");

Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define TEST_NSID 0x12345678
#define TEST_NVMSETID 0xABCD
#define TEST_UUID 123
Expand Down Expand Up @@ -647,7 +646,7 @@ int main(void)
struct libnvme_global_ctx * ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl),
"opening test link failed");

Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define TEST_NSID 0x12345678
#define TEST_NVMSETID 0xABCD
#define TEST_CSI NVME_CSI_KV
Expand Down Expand Up @@ -1105,7 +1104,7 @@ int main(void)
struct libnvme_global_ctx * ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl),
"opening test link failed");

Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define TEST_NSID 0x12345678
#define TEST_CSI NVME_CSI_KV
#define TEST_COPY_NR 0x12
Expand Down Expand Up @@ -1464,7 +1463,7 @@ int main(void)
struct libnvme_global_ctx *ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD64", &test_hdl),
"opening test link failed");

Expand Down
12 changes: 6 additions & 6 deletions libnvme/test/ioctl/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
size_t remaining_cmds;
};

static int mock_fd = -1;
static libnvme_fd_t mock_fd = LIBNVME_INVALID_FD;
static struct mock_cmds mock_admin_cmds = {.name = "admin"};
static struct mock_cmds mock_io_cmds = {.name = "IO"};

Expand All @@ -39,7 +39,7 @@
mock_cmds->remaining_cmds, mock_cmds->name);
}

void set_mock_fd(int fd)
void set_mock_fd(libnvme_fd_t fd)
{
mock_fd = fd;
}
Expand Down Expand Up @@ -122,11 +122,11 @@
})

#if defined(HAVE_GLIBC_IOCTL) && HAVE_GLIBC_IOCTL == 1
typedef int (*ioctl_func_t)(int, unsigned long, void *);
int ioctl(int fd, unsigned long request, ...)
typedef int (*ioctl_func_t)(libnvme_fd_t, unsigned long, void *);
int ioctl(libnvme_fd_t fd, unsigned long request, ...)

Check failure on line 126 in libnvme/test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: function definition argument 'void *' should also have an identifier name

Check failure on line 126 in libnvme/test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: function definition argument 'int' should also have an identifier name

Check failure on line 126 in libnvme/test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: function definition argument 'libnvme_fd_t' should also have an identifier name

Check failure on line 126 in libnvme/test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: function definition argument 'ioctl_func_t' should also have an identifier name

Check failure on line 126 in libnvme/test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: function definition argument 'int' should also have an identifier name
#else
typedef int (*ioctl_func_t)(int, int, void *);
int ioctl(int fd, int request, ...)
typedef int (*ioctl_func_t)(libnvme_fd_t, int, void *);
int ioctl(libnvme_fd_t fd, int request, ...)
#endif
{
ioctl_func_t real_ioctl = NULL;
Expand Down
2 changes: 1 addition & 1 deletion libnvme/test/ioctl/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct mock_cmd {
* set_mock_fd() - sets the expected file descriptor for NVMe passthru ioctls()
* @fd: file descriptor expected to be passed to ioctl()
*/
void set_mock_fd(int fd);
void set_mock_fd(libnvme_fd_t fd);

/**
* set_mock_admin_cmds() - mocks NVMe admin passthru ioctl() invocations
Expand Down
3 changes: 1 addition & 2 deletions libnvme/test/ioctl/zns.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "mock.h"
#include "util.h"

#define TEST_FD 0xFD
#define TEST_NSID 0x12345678
#define TEST_SLBA 0xffffffff12345678

Expand Down Expand Up @@ -165,7 +164,7 @@ int main(void)
struct libnvme_global_ctx *ctx =
libnvme_create_global_ctx(stdout, LIBNVME_DEFAULT_LOGLEVEL);

set_mock_fd(TEST_FD);
set_mock_fd(LIBNVME_TEST_FD);
check(!libnvme_open(ctx, "NVME_TEST_FD", &test_hdl),
"opening test link failed");

Expand Down
Loading