X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fguestfsd.c;h=2e83b9fa96db06590b8f1f788343fb295a06273a;hb=b7e094fa14b306fe776b9b2695cf82fa32d4923f;hp=1d740545468640f3d4ec418778eef658d72a2aad;hpb=f7ef94f5158cc56d7b1fb391e5907abd87dc4c3f;p=libguestfs.git diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 1d74054..2e83b9f 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -685,3 +687,50 @@ shell_quote (char *out, int len, const char *in) return outlen; } + +/* Perform device name translation. Don't call this directly - + * use the IS_DEVICE macro. + * + * See guestfs(3) for the algorithm. + * + * We have to open the device and test for ENXIO, because + * the device nodes themselves will exist in the appliance. + */ +int +device_name_translation (char *device, const char *func) +{ + int fd; + + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + if (errno != ENXIO) { + error: + reply_with_perror ("%s: %s", func, device); + return -1; + } + + /* If the name begins with "/dev/sd" then try the alternatives. */ + if (strncmp (device, "/dev/sd", 7) != 0) + goto error; + + device[5] = 'h'; /* /dev/hd (old IDE driver) */ + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + device[5] = 'v'; /* /dev/vd (for virtio devices) */ + fd = open (device, O_RDONLY); + if (fd >= 0) { + close (fd); + return 0; + } + + device[5] = 's'; /* Restore original device name. */ + goto error; +}