static int xen_host_pci_get_resource(XenHostPCIDevice *d)

{

    int i, rc, fd;

    char path[PATH_MAX];

    char buf[XEN_HOST_PCI_RESOURCE_BUFFER_SIZE];

    unsigned long long start, end, flags, size;

    char *endptr, *s;

    uint8_t type;



    rc = xen_host_pci_sysfs_path(d, "resource", path, sizeof (path));

    if (rc) {

        return rc;

    }

    fd = open(path, O_RDONLY);

    if (fd == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));

        return -errno;

    }



    do {

        rc = read(fd, &buf, sizeof (buf) - 1);

        if (rc < 0 && errno != EINTR) {

            rc = -errno;

            goto out;

        }

    } while (rc < 0);

    buf[rc] = 0;

    rc = 0;



    s = buf;

    for (i = 0; i < PCI_NUM_REGIONS; i++) {

        type = 0;



        start = strtoll(s, &endptr, 16);

        if (*endptr != ' ' || s == endptr) {

            break;

        }

        s = endptr + 1;

        end = strtoll(s, &endptr, 16);

        if (*endptr != ' ' || s == endptr) {

            break;

        }

        s = endptr + 1;

        flags = strtoll(s, &endptr, 16);

        if (*endptr != '\n' || s == endptr) {

            break;

        }

        s = endptr + 1;



        if (start) {

            size = end - start + 1;

        } else {

            size = 0;

        }



        if (flags & IORESOURCE_IO) {

            type |= XEN_HOST_PCI_REGION_TYPE_IO;

        }

        if (flags & IORESOURCE_MEM) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM;

        }

        if (flags & IORESOURCE_PREFETCH) {

            type |= XEN_HOST_PCI_REGION_TYPE_PREFETCH;

        }

        if (flags & IORESOURCE_MEM_64) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM_64;

        }



        if (i < PCI_ROM_SLOT) {

            d->io_regions[i].base_addr = start;

            d->io_regions[i].size = size;

            d->io_regions[i].type = type;

            d->io_regions[i].bus_flags = flags & IORESOURCE_BITS;

        } else {

            d->rom.base_addr = start;

            d->rom.size = size;

            d->rom.type = type;

            d->rom.bus_flags = flags & IORESOURCE_BITS;

        }

    }

    if (i != PCI_NUM_REGIONS) {

        /* Invalid format or input to short */

        rc = -ENODEV;

    }



out:

    close(fd);

    return rc;

}

static int xen_host_pci_get_resource(XenHostPCIDevice *d)

{

    int i, rc, fd;

    char path[PATH_MAX];

    char buf[XEN_HOST_PCI_RESOURCE_BUFFER_SIZE];

    unsigned long long start, end, flags, size;

    char *endptr, *s;

    uint8_t type;



    rc = xen_host_pci_sysfs_path(d, "resource", path, sizeof (path));

    if (rc) {

        return rc;

    }

    fd = open(path, O_RDONLY);

    if (fd == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %s: %s\n", path, strerror(errno));

        return -errno;

    }



    do {

        rc = read(fd, &buf, sizeof (buf) - 1);

        if (rc < 0 && errno != EINTR) {

            rc = -errno;

            goto out;

        }

    } while (rc < 0);

    buf[rc] = 0;

    rc = 0;



    s = buf;

    for (i = 0; i < PCI_NUM_REGIONS; i++) {

        type = 0;



        start = strtoll(s, &endptr, 16);

        if (*endptr != ' ' || s == endptr) {

            break;

        }

        s = endptr + 1;

        end = strtoll(s, &endptr, 16);

        if (*endptr != ' ' || s == endptr) {

            break;

        }

        s = endptr + 1;

        flags = strtoll(s, &endptr, 16);

        if (*endptr != '\n' || s == endptr) {

            break;

        }

        s = endptr + 1;



        if (start) {

            size = end - start + 1;

        } else {

            size = 0;

        }



        if (flags & IORESOURCE_IO) {

            type |= XEN_HOST_PCI_REGION_TYPE_IO;

        }

        if (flags & IORESOURCE_MEM) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM;

        }

        if (flags & IORESOURCE_PREFETCH) {

            type |= XEN_HOST_PCI_REGION_TYPE_PREFETCH;

        }

        if (flags & IORESOURCE_MEM_64) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM_64;

        }



        if (i < PCI_ROM_SLOT) {

            d->io_regions[i].base_addr = start;

            d->io_regions[i].size = size;

            d->io_regions[i].type = type;

            d->io_regions[i].bus_flags = flags & IORESOURCE_BITS;

        } else {

            d->rom.base_addr = start;

            d->rom.size = size;

            d->rom.type = type;

            d->rom.bus_flags = flags & IORESOURCE_BITS;

        }

    }

    if (i != PCI_NUM_REGIONS) {

        

        rc = -ENODEV;

    }



out:

    close(fd);

    return rc;

}

    rc = xen_host_pci_sysfs_path(d, "resource", path, sizeof (path));     if (rc) {         return rc;     if (rc) {         return rc;     if (rc) {         return rc;
static int FUNC_0(XenHostPCIDevice *VAR_0)

{

    int VAR_1, VAR_2, VAR_3;

    char VAR_4[PATH_MAX];

    char VAR_5[XEN_HOST_PCI_RESOURCE_BUFFER_SIZE];

    unsigned long long VAR_6, VAR_7, VAR_8, VAR_9;

    char *VAR_10, *VAR_11;

    uint8_t type;



    VAR_2 = xen_host_pci_sysfs_path(VAR_0, "resource", VAR_4, sizeof (VAR_4));

    if (VAR_2) {

        return VAR_2;

    }

    VAR_3 = open(VAR_4, O_RDONLY);

    if (VAR_3 == -1) {

        XEN_HOST_PCI_LOG("Error: Can't open %VAR_11: %VAR_11\n", VAR_4, strerror(errno));

        return -errno;

    }



    do {

        VAR_2 = read(VAR_3, &VAR_5, sizeof (VAR_5) - 1);

        if (VAR_2 < 0 && errno != EINTR) {

            VAR_2 = -errno;

            goto out;

        }

    } while (VAR_2 < 0);

    VAR_5[VAR_2] = 0;

    VAR_2 = 0;



    VAR_11 = VAR_5;

    for (VAR_1 = 0; VAR_1 < PCI_NUM_REGIONS; VAR_1++) {

        type = 0;



        VAR_6 = strtoll(VAR_11, &VAR_10, 16);

        if (*VAR_10 != ' ' || VAR_11 == VAR_10) {

            break;

        }

        VAR_11 = VAR_10 + 1;

        VAR_7 = strtoll(VAR_11, &VAR_10, 16);

        if (*VAR_10 != ' ' || VAR_11 == VAR_10) {

            break;

        }

        VAR_11 = VAR_10 + 1;

        VAR_8 = strtoll(VAR_11, &VAR_10, 16);

        if (*VAR_10 != '\n' || VAR_11 == VAR_10) {

            break;

        }

        VAR_11 = VAR_10 + 1;



        if (VAR_6) {

            VAR_9 = VAR_7 - VAR_6 + 1;

        } else {

            VAR_9 = 0;

        }



        if (VAR_8 & IORESOURCE_IO) {

            type |= XEN_HOST_PCI_REGION_TYPE_IO;

        }

        if (VAR_8 & IORESOURCE_MEM) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM;

        }

        if (VAR_8 & IORESOURCE_PREFETCH) {

            type |= XEN_HOST_PCI_REGION_TYPE_PREFETCH;

        }

        if (VAR_8 & IORESOURCE_MEM_64) {

            type |= XEN_HOST_PCI_REGION_TYPE_MEM_64;

        }



        if (VAR_1 < PCI_ROM_SLOT) {

            VAR_0->io_regions[VAR_1].base_addr = VAR_6;

            VAR_0->io_regions[VAR_1].VAR_9 = VAR_9;

            VAR_0->io_regions[VAR_1].type = type;

            VAR_0->io_regions[VAR_1].bus_flags = VAR_8 & IORESOURCE_BITS;

        } else {

            VAR_0->rom.base_addr = VAR_6;

            VAR_0->rom.VAR_9 = VAR_9;

            VAR_0->rom.type = type;

            VAR_0->rom.bus_flags = VAR_8 & IORESOURCE_BITS;

        }

    }

    if (VAR_1 != PCI_NUM_REGIONS) {

        

        VAR_2 = -ENODEV;

    }



out:

    close(VAR_3);

    return VAR_2;

}

static int FUNC_0(XenHostPCIDevice *VAR_0)
{ int VAR_1, VAR_2, VAR_3; char VAR_4[PATH_MAX]; char VAR_5[XEN_HOST_PCI_RESOURCE_BUFFER_SIZE]; unsigned long long VAR_6, VAR_7, VAR_8, VAR_9; char *VAR_10, *VAR_11; uint8_t type; VAR_2 = xen_host_pci_sysfs_path(VAR_0, "resource", VAR_4, sizeof (VAR_4)); if (VAR_2) { return VAR_2; } VAR_3 = open(VAR_4, O_RDONLY); if (VAR_3 == -1) { XEN_HOST_PCI_LOG("Error: Can't open %VAR_11: %VAR_11\n", VAR_4, strerror(errno)); return -errno; } do { VAR_2 = read(VAR_3, &VAR_5, sizeof (VAR_5) - 1); if (VAR_2 < 0 && errno != EINTR) { VAR_2 = -errno; goto out; } } while (VAR_2 < 0); VAR_5[VAR_2] = 0; VAR_2 = 0; VAR_11 = VAR_5; for (VAR_1 = 0; VAR_1 < PCI_NUM_REGIONS; VAR_1++) { type = 0; VAR_6 = strtoll(VAR_11, &VAR_10, 16); if (*VAR_10 != ' ' || VAR_11 == VAR_10) { break; } VAR_11 = VAR_10 + 1; VAR_7 = strtoll(VAR_11, &VAR_10, 16); if (*VAR_10 != ' ' || VAR_11 == VAR_10) { break; } VAR_11 = VAR_10 + 1; VAR_8 = strtoll(VAR_11, &VAR_10, 16); if (*VAR_10 != '\n' || VAR_11 == VAR_10) { break; } VAR_11 = VAR_10 + 1; if (VAR_6) { VAR_9 = VAR_7 - VAR_6 + 1; } else { VAR_9 = 0; } if (VAR_8 & IORESOURCE_IO) { type |= XEN_HOST_PCI_REGION_TYPE_IO; } if (VAR_8 & IORESOURCE_MEM) { type |= XEN_HOST_PCI_REGION_TYPE_MEM; } if (VAR_8 & IORESOURCE_PREFETCH) { type |= XEN_HOST_PCI_REGION_TYPE_PREFETCH; } if (VAR_8 & IORESOURCE_MEM_64) { type |= XEN_HOST_PCI_REGION_TYPE_MEM_64; } if (VAR_1 < PCI_ROM_SLOT) { VAR_0->io_regions[VAR_1].base_addr = VAR_6; VAR_0->io_regions[VAR_1].VAR_9 = VAR_9; VAR_0->io_regions[VAR_1].type = type; VAR_0->io_regions[VAR_1].bus_flags = VAR_8 & IORESOURCE_BITS; } else { VAR_0->rom.base_addr = VAR_6; VAR_0->rom.VAR_9 = VAR_9; VAR_0->rom.type = type; VAR_0->rom.bus_flags = VAR_8 & IORESOURCE_BITS; } } if (VAR_1 != PCI_NUM_REGIONS) { VAR_2 = -ENODEV; } out:
close(VAR_3); return VAR_2; }