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