首页 > 系统相关 >Linux c 开发-31 获取磁盘序列号

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

时间:2022-11-24 18:49:25浏览次数:41  
标签:31 len char fd Linux device 序列号 data serial

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

标签:31,len,char,fd,Linux,device,序列号,data,serial
From: https://www.cnblogs.com/zhaogaojian/p/16922824.html

相关文章