+static uint64_t vtoydm_get_part_secnum(const char *diskname, int part)
+{
+ int fd;
+ unsigned long long size = 0;
+ char diskpath[256] = {0};
+ char sizebuf[64] = {0};
+
+ diskname += 5; /* skip /dev/ */
+
+ if (strstr(diskname, "nvme") || strstr(diskname, "mmc") || strstr(diskname, "nbd"))
+ {
+ snprintf(diskpath, sizeof(diskpath) - 1, "/sys/class/block/%sp%d/size", diskname, part);
+ }
+ else
+ {
+ snprintf(diskpath, sizeof(diskpath) - 1, "/sys/class/block/%s%d/size", diskname, part);
+ }
+
+ if (access(diskpath, F_OK) >= 0)
+ {
+ debug("get part size from sysfs for %s %d\n", diskname, part);
+
+ fd = open(diskpath, O_RDONLY | O_BINARY);
+ if (fd >= 0)
+ {
+ read(fd, sizebuf, sizeof(sizebuf));
+ size = strtoull(sizebuf, NULL, 10);
+ close(fd);
+ return size;
+ }
+ }
+ else
+ {
+ debug("%s not exist \n", diskpath);
+ }
+
+ return size;
+}
+