KDK_GET_HARD_DISK(3)

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

💖 KDK_GET_HARD_DISK 💖

okay bestie, so this one is from the Library Functions Manual section 3, and it's literally the glow-up you need if you wanna know every hard disk your system can touch. no cap. let's get into it 🦋


✨ NAME ✨

kdk_get_hard_disk — 获取系统接入所有硬盘 (yes she's bilingual, we stan a multilingual icon 👑)


🌸 SYNOPSIS 🌸

#include <libkydiskinfo.h>

extern char** kdk_get_hard_disk();

Link with -lkydiskinfo.

that's it, that's the whole vibe check. one include, one extern, one link flag. periodt. 💅


📖 DETAILED DESCRIPTION 📖

The kdk_get_hard_disk() function obtains the system access hard disk list information during the call process.

translation bestie: you call her, she goes and looks at what disks your system has access to right at that moment, and she hands you back the list. it's giving "let me check real quick" energy ✨


🎀 RETURN VALUE 🎀

The return value is a char** type, with each string representing the absolute path of a disk and ending with a NULL character.

After completion, kdk_free_disklist() function releases a list of disk information.

⚠️ okay this part matters: she gives you a char**, and the last entry is a NULL pointer — that's your little "the list stops here" signal, so you can loop on it. and when you're done being obsessed with the list, you have to hand it back to kdk_free_disklist() so she can release it. do not ghost her. 🙈

🔥 EXAMPLES 🔥

here's the whole thing, copy it, run it, live your truth 💜

#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;
}

the way this example does a whole round of kdk_get_disklist() first, frees it, and then comes back with kdk_get_hard_disk() for the main character moment?? two lists, two vibes, one main() ✨

notice she calls free(res) on every single one of those string results — yes bestie, those are yours to free. and kdk_free_disklist(di) at the end, always. no leaks, only slay. 💅


👑 CONFORMING TO 👑

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

💀 and yes, kdk_get_hard_disk_size() is listed twice in that Linux-extensions lineup. not a typo on my part, that's just what the page says. iconic behavior tbh, she said it twice because she meant it 🫶

🌈 SEE ALSO 🌈

go read the whole friend group, they all hang out together iykyk 💖


and that's the page bestie!! this one came from the Linux Programmer's Manual, dated Thu Aug 10 2023 — so if you're citing her, that's the source and the date, no cap. go forth and enumerate your disks, you gorgeous little sysadmin 🦋💖✨

📦 where this page comes from