
On Tue, Sep 08, 2015 at 09:27:27AM +0100, Joao Martins wrote:
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index dc83083..fd952a3 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c static int +libxlDiskPathMatches(const char *virtpath, const char *devtype, + int *index_r, int max_index, + int *partition_r, int max_partition) +{ + const char *p; + char *ep; + int tl, c; + long pl; + + tl = strlen(devtype); + if (memcmp(virtpath, devtype, tl)) + return 0;
Nit-pick, we prefer use of STREQLEN / STRNEQLEN instead of memcmp, whenever comparing strings.
+ + /* We decode the drive letter as if it were in base 52 + * with digits a-zA-Z, more or less */ + *index_r = -1; + p = virtpath + tl; + for (;;) { + c = *p++; + if (c >= 'a' && c <= 'z') { + c -= 'a'; + } else { + --p; + break; + } + (*index_r)++; + (*index_r) *= 26; + (*index_r) += c; + + if (*index_r > max_index) + return 0; + } + + if (!*p) { + *partition_r = 0; + return 1; + } + + if (*p == '0') + return 0; /* leading zeroes not permitted in partition number */ + + if (virStrToLong_l(p, &ep, 10, &pl) < 0) + return 0; + + if (pl > max_partition || *ep) + return 0; + + *partition_r = pl; + return 1; +}
IIUC, the virDiskNameToIndex() method could do the disk part of this, but doesn't provide the partition info. I think it would be desirable to extend that common method to provide partition info too, as it is conceptually useful elsewhere. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|