Linux c 开发-31 获取磁盘序列号

lsblk -n --nodeps -o name,serial /dev/mmcblk0
cat /sys/class/block/mmcblk0boot1/device/device/serial

static int get_chip_id(char *buf, size_t size)
{
	char *path = "/sys/class/block/mmcblk0boot1/device/device/serial";
	FILE *fd;
	char data[128];
	char *key, *value, *end;
	int len = -1;

	fd = fopen(path, "r");
	if (fd == NULL)
	{
		printf(" ERROR !!!! cannot open %s\n", path);
		return -1;
	}
	while (fgets(data, sizeof(data), fd)) {
		len = snprintf(buf, size, "%s", data);
		printf("disk serial   buf=%s len=%d\n", buf, len);
		break;
	}
	fclose(fd);
	return 0;
}
posted @ 2022-11-24 18:32  zhaogaojian  阅读(467)  评论(0编辑  收藏  举报