int diskutil_loop_check(const char *path, const char *lodev)
{
    int ret = EUCA_OK;
    char *output = NULL;
    char *oparen = NULL;
    char *cparen = NULL;

    if (path && lodev) {
        output = pruntf(TRUE, "%s %s %s", helpers_path[ROOTWRAP], helpers_path[LOSETUP], lodev);
        if (output == NULL)
            return (EUCA_ERROR);

        // output is expected to look like: /dev/loop4: [0801]:5509589 (/var/lib/eucalyptus/volumes/v*)
        oparen = strchr(output, '(');
        cparen = strchr(output, ')');
        if ((oparen == NULL) || (cparen == NULL)) {
            // no parenthesis => unexpected `losetup` output
            ret = EUCA_ERROR;
        } else if ((cparen - oparen) < 3) {
            // strange paren arrangement => unexpected
            ret = EUCA_ERROR;
        } else {
            // extract just the path, possibly truncated, from inside the parens
            oparen++;
            cparen--;
            if (*cparen == '*') {
                // handle truncated paths, identified with an asterisk
                cparen--;
            }
            // truncate ')' or '*)'
            *cparen = '\0';

            // see if path is in the blobstore
            if (strstr(path, oparen) == NULL) {
                ret = EUCA_ERROR;
            }
        }

        EUCA_FREE(output);
        return (ret);
    }

    LOGWARN("bad params: path=%s, lodev=%s\n", SP(path), SP(lodev));
    return (EUCA_INVALID_ERROR);
}
int diskutil_loop_check(const char *path, const char *lodev)
{
    int ret = EUCA_OK;
    char *output = NULL;
    char *oparen = NULL;
    char *cparen = NULL;

    if (path && lodev) {
        output = pruntf(TRUE, "%s %s %s", helpers_path[ROOTWRAP], helpers_path[LOSETUP], lodev);
        if (output == NULL)
            return (EUCA_ERROR);

         
        oparen = strchr(output, '(');
        cparen = strchr(output, ')');
        if ((oparen == NULL) || (cparen == NULL)) {
             
            ret = EUCA_ERROR;
        } else if ((cparen - oparen) < 3) {
             
            ret = EUCA_ERROR;
        } else {
             
            oparen++;
            cparen--;
            if (*cparen == '*') {
                 
                cparen--;
            }
             
            *cparen = '\0';

             
            if (strstr(path, oparen) == NULL) {
                ret = EUCA_ERROR;
            }
        }

        EUCA_FREE(output);
        return (ret);
    }

    LOGWARN("bad params: path=%s, lodev=%s\n", SP(path), SP(lodev));
    return (EUCA_INVALID_ERROR);
}