Skip to content

Commit 5e509c1

Browse files
committed
Add NVMe support
insofar as udisks has it... storaged-project/udisks#386
1 parent 5300224 commit 5e509c1

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

src/info_manager.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ parse_blk_dev_path(
216216
do
217217
{
218218
if (1 == sscanf(slash, "/sd%[^0-9/]", blk_dev))
219-
continue;
219+
{
220+
strncpy(blk_dev, slash+1, MAX_BLK_DEV_LEN);
221+
}
222+
else if (2 == sscanf(slash, "/nvme%un%u", &dummy[0], &dummy[0]))
223+
{
224+
strncpy(blk_dev, slash+1, MAX_BLK_DEV_LEN);
225+
}
220226
else if (4 == sscanf(slash, "/%u:%u:%u:%u", &dummy[0], &dummy[1], &dummy[2], &dummy[3]))
221227
{
222228
tup->host = dummy[0];

src/output_fmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ get_field_blk_dev(
111111

112112
if (st)
113113
{
114-
if (-1 != (rc = asprintf(&f->string, "sd%s", scsi_target_get_blk_dev(st))))
114+
if (-1 != (rc = asprintf(&f->string, "%s", scsi_target_get_blk_dev(st))))
115115
f->sort_val = f->string;
116116
}
117117
else

src/sysfs_scan.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,57 @@ static bool usb_bus_dir_selector(const char* d_name, const void** next_sel, size
211211
return rc;
212212
}
213213

214+
static bool nvme_namespace_dir_selector(const char* d_name, const void** next_sel, size_t* n_next_sel)
215+
{
216+
unsigned int dummy;
217+
bool rc = (2 == sscanf(d_name, "nvme%un%u", &dummy, &dummy));
218+
219+
if (rc && next_sel && n_next_sel)
220+
{
221+
*next_sel = NULL;
222+
*n_next_sel = 0;
223+
}
224+
225+
return rc;
226+
}
227+
228+
static bool nvme_dev_dir_selector(const char* d_name, const void** next_sel, size_t* n_next_sel)
229+
{
230+
static const dir_selector_fn next_selectors[] = { nvme_namespace_dir_selector };
231+
unsigned int dummy;
232+
bool rc = (1 == sscanf(d_name, "nvme%u", &dummy));
233+
234+
if (rc && next_sel && n_next_sel)
235+
{
236+
*next_sel = next_selectors;
237+
*n_next_sel = ARRAY_SIZE(next_selectors);
238+
}
239+
240+
return rc;
241+
}
242+
243+
static bool nvme_bus_dir_selector(const char* d_name, const void** next_sel, size_t* n_next_sel)
244+
{
245+
static const dir_selector_fn next_selectors[] = { nvme_dev_dir_selector };
246+
bool rc = (0 == strcmp(d_name, "nvme"));
247+
248+
if (rc && next_sel && n_next_sel)
249+
{
250+
*next_sel = next_selectors;
251+
*n_next_sel = ARRAY_SIZE(next_selectors);
252+
}
253+
254+
return rc;
255+
}
256+
214257
static bool pci_dev_dir_selector(const char* d_name, const void** next_sel, size_t* n_next_sel)
215258
{
216259
static const dir_selector_fn next_selectors[] = {
217260
pci_dev_dir_selector
218261
, ata_dev_dir_selector
219262
, scsi_host_dir_selector
220263
, usb_bus_dir_selector
264+
, nvme_bus_dir_selector
221265
};
222266
unsigned int dummy;
223267
bool rc = (4 == sscanf(d_name, "%4x:%2x:%2x.%x", &dummy, &dummy, &dummy, &dummy));

src/udisks2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ udisks2_get_blk_dev_smart(
295295
char* udisks2_blk_dev_path;
296296
struct blk_dev_info* bdi = NULL;
297297

298-
if (-1 != asprintf(&udisks2_blk_dev_path, "%s/block_devices/sd%s", UDISKS_BASE_PATH, blk_dev))
298+
if (-1 != asprintf(&udisks2_blk_dev_path, "%s/block_devices/%s", UDISKS_BASE_PATH, blk_dev))
299299
{
300300
DBusMessage* req;
301301

0 commit comments

Comments
 (0)