bool initialize_nvme_controller()

in src/identify_disks.c [261:288]


bool initialize_nvme_controller(struct nvme_controller *ctrl, const char *name)
{
    char model_path[sizeof(ctrl->sys_path) + sizeof("/model")];

    snprintf(ctrl->name, sizeof(ctrl->name), "%s", name);
    snprintf(ctrl->dev_path, sizeof(ctrl->dev_path), "/dev/%s", ctrl->name);
    snprintf(ctrl->sys_path, sizeof(ctrl->sys_path), "%s/%s", SYS_CLASS_NVME_PATH, ctrl->name);
    snprintf(model_path, sizeof(model_path), "%s/model", ctrl->sys_path);

    FILE *file = fopen(model_path, "r");
    if (file == NULL)
    {
        DEBUG_PRINTF("failed to open %s: %m\n", model_path);
        return false;
    }

    char *result = fgets(ctrl->model, sizeof(ctrl->model), file);
    if (result == NULL)
    {
        DEBUG_PRINTF("failed to read model name from %s: %m\n", model_path);
        fclose(file);
        return false;
    }

    fclose(file);
    trim_trailing_whitespace(ctrl->model);
    return true;
}