DF-2217 / nvme_getlog.c
#include <fcntl.h> #include <sys/ioctl.h> #include <stdio.h> #include <string.h> #include <stdint.h> #include "nvme_ioctl.h" int main(int argc, char **argv) { int fd, i; nvme_getlog_ioctl_t ioc; if (argc < 3) { fprintf(stderr, "usage: %s /dev/nvmeN <lid>\n", argv[0]); return 1; } fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open"); return 1; } memset(&ioc, 0, sizeof(ioc)); ioc.lid = (uint8_t)strtoul(argv[2], NULL, 0); ioc.ret_size = 4096; if (ioctl(fd, NVMEIOCGETLOG, &ioc) != 0) { perror("ioctl"); return 1; } printf("status=0x%04x lid=0x%02x ret_size=%u\n", ioc.status, ioc.lid, ioc.ret_size); for (i = 0; i < (int)ioc.ret_size; i++) { printf("%02x", ((unsigned char *)&ioc.info)[i]); if ((i + 1) % 32 == 0) printf("\n"); } printf("\n"); close(fd); return 0; } |