in src/identify_disks.c [146:212]
void enumerate_namespaces_for_controller(struct nvme_controller *ctrl, struct context *ctx,
json_object *namespaces_array)
{
struct dirent **namelist;
int n = scandir(ctrl->sys_path, &namelist, is_nvme_namespace, versionsort);
if (n < 0)
{
fprintf(stderr, "failed scandir for %s: %m\n", ctrl->sys_path);
return;
}
DEBUG_PRINTF("found %d namespace(s) for controller=%s:\n", n, ctrl->name);
for (int i = 0; i < n; i++)
{
char namespace_path[MAX_PATH];
snprintf(namespace_path, sizeof(namespace_path), "/dev/%s", namelist[i]->d_name);
char *vs = nvme_identify_namespace_vs_for_namespace_device(namespace_path);
char *id = NULL;
json_object *namespace_obj = json_object_new_object();
json_object_object_add(namespace_obj, "path", json_object_new_string(namespace_path));
json_object_object_add(namespace_obj, "model", json_object_new_string(ctrl->model));
json_object_array_add(namespaces_array, namespace_obj);
if (vs != NULL)
{
if (vs[0] == 0)
{
id = identify_namespace_without_vs(ctrl->sys_path, namespace_path);
}
else
{
id = strdup(vs);
}
if (ctx->output_format == PLAIN)
{
printf("%s: %s\n", namespace_path, id);
}
}
if (id != NULL)
{
json_object_object_add(namespace_obj, "properties", parse_vs_string(id));
free(id);
}
else
{
json_object_object_add(namespace_obj, "properties", json_object_new_object());
}
if (vs != NULL)
{
json_object_object_add(namespace_obj, "vs", json_object_new_string(vs));
free(vs);
}
else
{
json_object_object_add(namespace_obj, "vs", NULL);
}
free(namelist[i]);
}
free(namelist);
}