KDK_GET_HARD_FWREV(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

💖 KDK_GET_HARD_FWREV(3) 💖

okay so bestie, welcome to the Library Functions Manual page for kdk_get_hard_fwrev, living its best life in section 3 of the manual. this is the glow-up edition, but every single fact is untouched, i promise. 🫶


✨ NAME ✨

kdk_get_hard_fwrev — 获取硬盘固态版本


✨ SYNOPSIS ✨

#include <libkydiskinfo.h>

extern char* kdk_get_hard_fwrev(const char *diskname);

Link with -lkydiskinfo.


🌸 Detailed Description 🌸

so here's the tea ☕ — you hand this function a diskname, and it goes and finds the firmware version for that drive. the diskname can be an absolute path like /dev/sda, or it can be one of the elements that come back in the value returned by the kdk_get_hard_disk() function. either way, you get the hard drive's firmware version info. iconic behavior honestly. 💅


🎀 RETURN VALUE 🎀

  • On success — you get back the hard drive firmware version. and listen, this returned string is yours to clean up: it needs to be released by free. don't leave it hanging, that's not main character energy. 🧚
  • On error — you get NULL. that's it, that's the whole vibe. 😭

🦋 EXAMPLES 🦋

here's a whole little program showing the whole friend group working together, no cap:

#include "libkydiskinfo.h"
#include <stdio.h>
#include <stdlib.h>

static void display_disk_info(kdk_diskinfo *di)
{
    printf("---------------%s------------------0, di->name);
    printf("Disk Sectors:%llu0, di->sectors_num);
    printf("Disk Sector Size:%u0, di->sector_size);
    printf("Disk Size:%f MiB0, di->total_size_MiB);
    printf("Disk Model:%s0, di->model ? di->model : "None");
    printf("Disk Serial:%s0, di->serial ? di->serial : "None");
    printf("Disk Partition Number:%u0, di->partition_nums);
    printf("Disk Type:%d0, di->disk_type);
    printf("Disk fwrev:%s0, di->fwrev);
}

static void display_disk_list(char **disklist)
{
    int count = 0;
    while (disklist[count])
    {
        printf("No. %d %s0, count + 1, disklist[count]);
        count ++;
    }
}

int main()
{
    char **disklist = kdk_get_disklist();
    // display_disk_list(disklist);
    for (int i = 0; disklist[i]; i++)
    {
        kdk_diskinfo *sdainfo = kdk_get_diskinfo(disklist[i]);
        if (!sdainfo)
        {
            printf("[%s]Get disk info error.0, disklist[i]);
            continue;
        }

        display_disk_info(sdainfo);

        kdk_free_diskinfo(sdainfo);
    }
    kdk_free_disklist(disklist);

    char **di = kdk_get_hard_disk();
    size_t num = 0;
    while (di[num])
    {
        printf("No. %ld %s0, num + 1, di[num]);
        char *res = kdk_get_hard_disk_size(di[num]);
        printf("容量 = %s0, res);
        free(res);

        res = kdk_get_hard_fwrev(di[num]);
        printf("固态版本 = %s0, res);
        free(res);

        res = kdk_get_hard_vendor(di[num]);
        printf("厂商 = %s0, res);
        free(res);

        res = kdk_get_hard_type(di[num]);
        printf("类型 = %s0, res);
        free(res);

        res = kdk_get_hard_model(di[num]);
        printf("型号 = %s0, res);
        free(res);

        res =kdk_get_hard_serial(di[num]);
        printf("序列号 = %s0, res);
        free(res);

        num ++;
    }
    kdk_free_disklist(di);

    return 0;
}

see how kdk_get_hard_fwrev shows up in there and then immediately gets a free(res) right after? yeah. that's the whole point. 🍓


🌈 CONFORMING TO 🌈

These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: kdk_get_hard_disk(), kdk_free_disklist(), kdk_get_hard_disk_size(), kdk_get_hard_type(), kdk_get_hard_model(), kdk_get_hard_serial(), and kdk_get_hard_vendor().

ngl "withdrawn POSIX.1e draft" is giving ancient scrolls energy but ok, we respect the lore. 👑

👑 SEE ALSO 👑

go read those too bestie, they're all part of the same squad fr fr. 💜


and that's a wrap!! this page came straight out of the Linux Programmer's Manual, dated Thu Aug 10 2023. slay, stay hydrated, and always free() your strings. periodt. 💅✨🎀

📦 where this page comes from