KDK_GET_DISKINFO(3)
🦋 NAME 🦋
okay so hi bestie, welcome to the <libkydiskinfo.h> cinematic universe 💖 this little page right here is kdk_get_diskinfo, and it comes to you from the Library Functions Manual (that's section 3, iykyk). What does she do? 获取指定磁盘的磁盘信息 — yeah she's bilingual and she's serving, she gets the disk info for the disk you point at. Periodt. 👑
✨ SYNOPSIS ✨
#include <libkydiskinfo.h>
extern kdk_diskinfo *kdk_get_diskinfo(const char *diskname);
Link with -lkydiskinfo.
🎀 Detailed Description 🎀
So here's the vibe: you hand her a disk name — diskname — and she goes and gets you the disk info for that disk. 🫶
What counts as a disk name? Anything like an absolute path, for example /dev/sda, or an element from the value that the kdk_get_disklist() function returns. Either way, you're covered. Slay. 💅
💅 RETURN VALUE 💅
kdk_diskinfo is a structure that stores disk information, and here it is in all her glory, not one field changed, no cap:
typedef struct _kdk_diskinfo{
char *name; // 绝对路径
char *vendor; // 制造商
char *model; // 型号
char *serial; // 序列号
kdk_disk_type disk_type; // 磁盘类型,固态 or 机械 or 混合
kdk_disk_interface_type inter_type; // 接口类型
unsigned int rpm; // 转速,注意固态是没有转速概念的
unsigned long long sectors_num; // 扇区数量
unsigned int sector_size; // 每个扇区的字节数
float total_size_MiB; // 磁盘容量,MiB为单位
unsigned int partition_nums; // 该磁盘/分区下的子分区数量
char *uuid; // UUID
short mounted; // 是否已挂载
char *mount_path; // 挂载路径
kdk_disk_format format; // 格式化类型
kdk_disk_partition_type part_type; // 分区类型
char *fwrev; //固件版本信息
}kdk_diskinfo;
and if you want the tour, field by field, here's the tea ☕ (the comments are doing the heavy lifting, I'm just narrating):
name— 绝对路径, the absolute path bestie 🌸vendor— 制造商, the manufacturermodel— 型号, the modelserial— 序列号, the serial numberdisk_type— 磁盘类型, 固态 or 机械 or 混合 (that's akdk_disk_type)inter_type— 接口类型, the interface type (akdk_disk_interface_type)rpm— 转速, rotational speed — and read this twice, 注意固态是没有转速概念的, SSDs do not have a concept of rotational speed, so don't come for her about that 🫠sectors_num— 扇区数量, the number of sectors (anunsigned long long, she's big like that)sector_size— 每个扇区的字节数, the number of bytes in each sectortotal_size_MiB— 磁盘容量, MiB为单位, the disk capacity measured in MiBpartition_nums— 该磁盘/分区下的子分区数量, how many sub-partitions live under this disk/partitionuuid— UUID, it's giving exactly what it saysmounted— 是否已挂载, whether it's already mounted or notmount_path— 挂载路径, the mount pathformat— 格式化类型, the format type (akdk_disk_format)part_type— 分区类型, the partition type (akdk_disk_partition_type)fwrev— 固件版本信息, firmware revision info
🌈 EXAMPLES 🌈
Here's the whole example, copied character for character, we do not touch a single glyph, mwah 💋:
#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;
}
💀 CONFORMING TO 💀
These functions are as per the withdrawn POSIX.1e draft specification — yeah, withdrawn, she's a legacy icon, we still love her. 🕯️
The following functions are Linux extensions: kdk_get_disklist(), kdk_get_hard_disk(), and kdk_get_hard_disk_size(). Those ones are Linux-only, bestie, don't go looking for them in the POSIX draft, she's gone.
👑 SEE ALSO 👑
kdk_get_disklist(3)kdk_free_disklist(3)kdk_free_diskinfo(3)
and that's the whole page 🎀 she's from the Linux Programmer's Manual and dated Thu Aug 10 2023, so go forth, call her, free your structs, and stay iconic 💖✨🦋 no cap.
📦 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