int diskutil_sectors(const char *path, const int part, long long *first, long long *last)
{
    int p = 0;
    int ret = EUCA_ERROR;
    char *ss = NULL;
    char *end = NULL;
    char *comma = NULL;
    char *output = NULL;
    char *section = NULL;
    boolean found = FALSE;

    if (path && first && last) {
        *first = 0L;
        *last = 0L;

        if ((output = pruntf(TRUE, "%s %s", helpers_path[FILECMD], path)) == NULL) {
            LOGERROR("failed to extract partition information for '%s'\n", path);
        } else {
            // parse the output, such as:
            // NAME: x86 boot sector;
            // partition 1: ID=0x83, starthead 1, startsector 63, 32769 sectors;
            // partition 2: ID=0x83, starthead 2, startsector 32832, 32769 sectors;
            // partition 3: ID=0x82, starthead 2, startsector 65601, 81 sectors
            found = FALSE;
            section = strtok(output, ";");  // split by semicolon
            for (p = 0; section != NULL; p++) {
                section = strtok(NULL, ";");
                if (section && (p == part)) {
                    found = TRUE;
                    break;
                }
            }

            if (found) {
                if ((ss = strstr(section, "startsector")) != NULL) {
                    ss += strlen("startsector ");
                    if ((comma = strstr(ss, ", ")) != NULL) {
                        *comma = '\0';
                        comma += strlen(", ");
                        if ((end = strstr(comma, " sectors")) != NULL) {
                            *end = '\0';
                            *first = atoll(ss);
                            *last = *first + atoll(comma) - 1L;
                        }
                    }
                }
            }

            EUCA_FREE(output);
        }

        if (*last > 0)
            ret = EUCA_OK;

        return (ret);
    }

    LOGERROR("failed to extract partition information for '%s'\n", SP(path));
    return (EUCA_INVALID_ERROR);
}
int diskutil_sectors(const char *path, const int part, long long *first, long long *last)
{
    int p = 0;
    int ret = EUCA_ERROR;
    char *ss = NULL;
    char *end = NULL;
    char *comma = NULL;
    char *output = NULL;
    char *section = NULL;
    boolean found = FALSE;

    if (path && first && last) {
        *first = 0L;
        *last = 0L;

        if ((output = pruntf(TRUE, "%s %s", helpers_path[FILECMD], path)) == NULL) {
            LOGERROR("failed to extract partition information for '%s'\n", path);
        } else {
             
             
             
             
             
            found = FALSE;
            section = strtok(output, ";");   
            for (p = 0; section != NULL; p++) {
                section = strtok(NULL, ";");
                if (section && (p == part)) {
                    found = TRUE;
                    break;
                }
            }

            if (found) {
                if ((ss = strstr(section, "startsector")) != NULL) {
                    ss += strlen("startsector ");
                    if ((comma = strstr(ss, ", ")) != NULL) {
                        *comma = '\0';
                        comma += strlen(", ");
                        if ((end = strstr(comma, " sectors")) != NULL) {
                            *end = '\0';
                            *first = atoll(ss);
                            *last = *first + atoll(comma) - 1L;
                        }
                    }
                }
            }

            EUCA_FREE(output);
        }

        if (*last > 0)
            ret = EUCA_OK;

        return (ret);
    }

    LOGERROR("failed to extract partition information for '%s'\n", SP(path));
    return (EUCA_INVALID_ERROR);
}