KDK_GET_HARD_SERIAL(3)
💖 KDK_GET_HARD_SERIAL(3) 💖
okay bestie, welcome to the KDK_GET_HARD_SERIAL page, straight out of the Library Functions Manual 💅 this is the one that goes and asks your disk "hey girl, what's your serial number?" and no cap, it delivers.
✨ NAME ✨
kdk_get_hard_serial — 获取硬盘序列号 🌸 (yes, that's "get the hard drive serial number", she's bilingual and iconic)
🦋 SYNOPSIS 🦋
#include <libkydiskinfo.h>
extern char* kdk_get_hard_serial(const char *diskname);
Link with -lkydiskinfo. 🔗 do not forget this part, fr fr, the linker will be SO dramatic about it if you do.
👑 DETAILED DESCRIPTION 👑
So here's the tea ☕: you hand her a disk name — diskname — and she gets you the hard drive serial number info.
That diskname can be an absolute path situation like /dev/sda, or it can be one of the elements that the kdk_get_hard_disk() function hands back to you in its value. Either way, she knows what to do. main character energy, honestly. 💅
🎀 RETURN VALUE 🎀
- On success — she returns the serial number of the hard drive 🥳 and lowkey important: the returned string needs to be released by
free. Do NOT ghost thatfree, bestie, that's a memory leak and we don't do those here. 😭 - On error — she returns
NULL. 💀 vibe check failed, handle it.
🌈 EXAMPLES 🌈
here's the whole glow-up, copy-paste style, every line exactly as it lives:
#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 she grabs res =kdk_get_hard_serial(di[num]); and then prints it as 序列号 = %s0 and then free(res);? that's the whole circle of life, periodt. 🫶
💜 CONFORMING TO 💜
These functions are as per the withdrawn POSIX.1e draft specification. 📜 (withdrawn, bestie, we're honoring the ancestors.)
The following functions are Linux extensions: kdk_get_hard_disk(), kdk_free_disklist(), kdk_get_hard_disk_size(), kdk_get_hard_fwrev(), kdk_get_hard_type(), kdk_get_hard_model(), and kdk_get_hard_vendor(). 🐧
⭐ SEE ALSO ⭐
go read her friends, they're all slaying in their own lanes:
kdk_free_disklist(3)kdk_get_hard_disk_size(3)kdk_get_hard_fwrev(3)kdk_get_hard_type(3)kdk_get_hard_model(3)kdk_get_hard_vendor(3)kdk_get_hard_disk(3)
and that's the whole page, bestie 💖 this one lives in the Linux Programmer's Manual, version dated Thu Aug 10 2023 — so if you're reading her, you're reading the real one. mwah, go free your strings. 💅✨🎀
📦 where this page comes from
- arch rolling: libkysdk-system 3.0.1.4-1 · LGPL-3.0-or-later AND LGPL-2.1-only OR LGPL-3.0-only AND LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LGPL-3.0-only WITH Qt-LGPL-exception-1.1 AND MIT
- ubuntu resolute: libkysdk-system-dev 3.0.1.2-0ubuntu1 · LGPL-3.0-only
- ubuntu stonking: libkysdk-system-dev 3.0.1.3-0ubuntu1 · LGPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms