コード例 #1
0
ファイル: Data.cpp プロジェクト: december0123/MhwdRedone
void Data::fillDevices(MHWD::DEVICETYPE type)
{
	hd_data_t *hd_data;
	hd_t *hd;
	hw_item hw;
	std::vector<Device*>* devices;

	if (type == MHWD::DEVICETYPE::USB)
	{
		hw = hw_usb;
		devices = &USBDevices;
	}
	else
	{
		hw = hw_pci;
		devices = &PCIDevices;
	}

	// Get the hardware devices
	hd_data = (hd_data_t*) calloc(1, sizeof *hd_data);
	hd = hd_list(hd_data, hw, 1, nullptr);

	Device *device;
	for (; hd; hd = hd->next)
	{
		device = new Device();
		device->type = type;
		device->classID = from_Hex(hd->base_class.id, 2) + from_Hex(hd->sub_class.id, 2).toLower();
		device->vendorID = from_Hex(hd->vendor.id, 4).toLower();
		device->deviceID = from_Hex(hd->device.id, 4).toLower();
		device->className = from_CharArray(hd->base_class.name);
		device->vendorName = from_CharArray(hd->vendor.name);
		device->deviceName = from_CharArray(hd->device.name);
		device->sysfsBusID = from_CharArray(hd->sysfs_bus_id);
		device->sysfsID = from_CharArray(hd->sysfs_id);
		devices->push_back(device);
	}

	hd_free_hd_list(hd);
	hd_free_hd_data(hd_data);
	free(hd_data);
}
コード例 #2
0
ファイル: example1.c プロジェクト: jakeogh/hwinfo
int main(int argc, char **argv)
{
    hd_data_t *hd_data;
    hd_t *hd;

    hd_data = calloc(1, sizeof *hd_data);

    hd = hd_list(hd_data, hw_scsi, 1, NULL);

    for(; hd; hd = hd->next) {
        hd_dump_entry(hd_data, hd, stdout)
    }

    hd_free_hd_list(hd);		/* free it */
    hd_free_hd_data(hd_data);

    free(hd_data);

    return 0;
}
コード例 #3
0
ファイル: mhwd.cpp プロジェクト: Acidburn0zzz/mhwd
void mhwd::printDeviceDetails(mhwd::TYPE type, FILE *f) {
    hd_data_t *hd_data;
    hd_t *hd;
    hw_item hw;

    if (type == mhwd::TYPE_USB)
        hw = hw_usb;
    else
        hw = hw_pci;

    hd_data = (hd_data_t*)calloc(1, sizeof *hd_data);
    hd = hd_list(hd_data, hw, 1, NULL);

    for(; hd; hd = hd->next) {
        hd_dump_entry(hd_data, hd, f);
    }

    hd_free_hd_list(hd);
    hd_free_hd_data(hd_data);
    free(hd_data);
}
コード例 #4
0
ファイル: mhwd.cpp プロジェクト: Acidburn0zzz/mhwd
void mhwd::fillDevices(mhwd::Data *data, mhwd::TYPE type) {
    hd_data_t *hd_data;
    hd_t *hd;
    hw_item hw;
    std::vector<mhwd::Device*>* devices;

    if (type == mhwd::TYPE_USB) {
        hw = hw_usb;
        devices = &data->USBDevices;
    }
    else {
        hw = hw_pci;
        devices = &data->PCIDevices;
    }


    // Get the hardware devices
    hd_data = (hd_data_t*)calloc(1, sizeof *hd_data);
    hd = hd_list(hd_data, hw, 1, NULL);

    for(; hd; hd = hd->next) {
        struct mhwd::Device *device = new mhwd::Device();
        device->type = type;
        device->classID = from_Hex(hd->base_class.id, 2) + from_Hex(hd->sub_class.id, 2).toLower();
        device->vendorID = from_Hex(hd->vendor.id, 4).toLower();
        device->deviceID = from_Hex(hd->device.id, 4).toLower();
        device->className = from_CharArray(hd->base_class.name);
        device->vendorName = from_CharArray(hd->vendor.name);
        device->deviceName = from_CharArray(hd->device.name);
        device->sysfsBusID = from_CharArray(hd->sysfs_bus_id);
        device->sysfsID = from_CharArray(hd->sysfs_id);

        devices->push_back(device);
    }

    hd_free_hd_list(hd);
    hd_free_hd_data(hd_data);
    free(hd_data);
}
コード例 #5
0
ファイル: helper.cpp プロジェクト: houzhenggang/grub2-editor
ActionReply Helper::probevbe(QVariantMap args)
{
    Q_UNUSED(args)
    ActionReply reply;

#if HAVE_HD
    QStringList gfxmodes;
    hd_data_t hd_data;
    memset(&hd_data, 0, sizeof(hd_data));
    hd_t *hd = hd_list(&hd_data, hw_framebuffer, 1, NULL);
    for (hd_res_t *res = hd->res; res; res = res->next) {
        if (res->any.type == res_framebuffer) {
            gfxmodes += QString("%1x%2x%3").arg(QString::number(res->framebuffer.width), QString::number(res->framebuffer.height), QString::number(res->framebuffer.colorbits));
        }
    }
    hd_free_hd_list(hd);
    hd_free_hd_data(&hd_data);
    reply.addData("gfxmodes", gfxmodes);
#else
    reply = ActionReply::HelperErrorReply();
#endif

    return reply;
}
コード例 #6
0
ファイル: manual.c プロジェクト: jakeogh/hwinfo
void hd_scan_manual(hd_data_t *hd_data)
{
  DIR *dir;
  struct dirent *de;
  int i, j;
  hd_t *hd, *hd1, *next, *hdm, **next2;
  char *s;
  char *udi_dir[] = { "/org/freedesktop/Hal/devices", "", "" };

  if(!hd_probe_feature(hd_data, pr_manual)) return;

  hd_data->module = mod_manual;

  /* some clean-up */
  remove_hd_entries(hd_data);

  for(hd = hd_data->manual; hd; hd = next) {
    next = hd->next; 
    hd->next = NULL;
    hd_free_hd_list(hd);
  }
  hd_data->manual = NULL;

  next2 = &hd_data->manual;

  s = NULL;
  for(j = 0; j < sizeof udi_dir / sizeof *udi_dir; j++) {
    str_printf(&s, 0, "%s%s", j == 2 ? "unique-keys" : "udi", udi_dir[j]);
    if((dir = opendir(hd_get_hddb_path(s)))) {
      i = 0;
      while((de = readdir(dir))) {
        if(*de->d_name == '.') continue;
        PROGRESS(1, ++i, "read");
        str_printf(&s, 0, "%s%s%s", udi_dir[j], *udi_dir[j] ? "/" : "", de->d_name);
        if((hd = hd_read_config(hd_data, s))) {
          if(hd->status.available != status_unknown) hd->status.available = status_no;
          ADD2LOG("  got %s\n", hd->unique_id);
          *next2 = hd;
          next2 = &hd->next;
        }
      }
      closedir(dir);
    }
  }
  s = free_mem(s);

  hd_data->flags.keep_kmods = 1;
  for(hdm = hd_data->manual; hdm; hdm = next) {
    next = hdm->next;

    for(hd = hd_data->hd; hd; hd = hd->next) {
      if(hd->unique_id && hdm->unique_id && !strcmp(hd->unique_id, hdm->unique_id)) break;
    }

    if(hd) {
      /* just update config status */
      hd->status = hdm->status;
      if(hd->status.available != status_unknown) hd->status.available = status_yes;

      if(hdm->config_string) hd->config_string = new_str(hdm->config_string);

      if(hdm->persistent_prop) {
        hd->persistent_prop = hdm->persistent_prop;
        hdm->persistent_prop = NULL;
      }
    }
    else {
      /* add new entry */
      hd = add_hd_entry(hd_data, __LINE__, 0);
      *hd = *hdm;
      hd->next = NULL;
      hd->tag.freeit = 0;

      hdm->tag.remove = 1;

      if(hd->status.available != status_unknown) hd->status.available = status_no;

      // FIXME: do it really here?
      if(hd->parent_id) {
        for(hd1 = hd_data->hd; hd1; hd1 = hd1->next) {
          if(hd1->unique_id && !strcmp(hd1->unique_id, hd->parent_id)) {
            hd->attached_to = hd1->idx;
            break;
          }
        }
      }
    }
  }
  hd_data->flags.keep_kmods = 0;

  for(hd = hd_data->manual; hd; hd = next) {
    next = hd->next;
    hd->next = NULL;
    if(!hd->tag.remove) {
      hd_free_hd_list(hd);
    }
    else {
      free_mem(hd);
    }
  }
  hd_data->manual = NULL;

}
コード例 #7
0
ファイル: device.c プロジェクト: salass00/ntfs-3g
static int ntfs_device_get_geo(struct ntfs_device *dev)
{
	int err;

	if (!dev) {
		errno = EINVAL;
		return -1;
	}
	err = EOPNOTSUPP;
#ifdef ENABLE_HD
	{
		hd_data_t *hddata;
		hd_t *hd, *devlist, *partlist = NULL;
		str_list_t *names;
		hd_res_t *res;
		const int d_name_len = strlen(dev->d_name) + 1;
		int done = 0;

		hddata = calloc(1, sizeof(*hddata));
		if (!hddata) {
			err = ENOMEM;
			goto skip_hd;
		}
		/* List all "disk" class devices on the system. */
		devlist = hd_list(hddata, hw_disk, 1, NULL);
		if (!devlist) {
			free(hddata);
			err = ENOMEM;
			goto skip_hd;
		}
		/*
		 * Loop over each disk device looking for the device with the
		 * same unix name as @dev.
		 */
		for (hd = devlist; hd; hd = hd->next) {
			if (hd->unix_dev_name && !strncmp(dev->d_name,
					hd->unix_dev_name, d_name_len))
				goto got_hd;
			if (hd->unix_dev_name2 && !strncmp(dev->d_name,
					hd->unix_dev_name2, d_name_len))
				goto got_hd;
			for (names = hd->unix_dev_names; names;
					names = names->next) {
				if (names->str && !strncmp(dev->d_name,
						names->str, d_name_len))
					goto got_hd;
			}
		}
		/*
		 * Device was not a whole disk device.  Unless it is a file it
		 * is likely to be a partition device.  List all "partition"
		 * class devices on the system.
		 */
		partlist = hd_list(hddata, hw_partition, 1, NULL);
		for (hd = partlist; hd; hd = hd->next) {
			if (hd->unix_dev_name && !strncmp(dev->d_name,
					hd->unix_dev_name, d_name_len))
				goto got_part_hd;
			if (hd->unix_dev_name2 && !strncmp(dev->d_name,
					hd->unix_dev_name2, d_name_len))
				goto got_part_hd;
			for (names = hd->unix_dev_names; names;
					names = names->next) {
				if (names->str && !strncmp(dev->d_name,
						names->str, d_name_len))
					goto got_part_hd;
			}
		}
		/* Failed to find the device.  Stop trying and clean up. */
		goto end_hd;
got_part_hd:
		/* Get the whole block device the partition device is on. */
		hd = hd_get_device_by_idx(hddata, hd->attached_to);
		if (!hd)
			goto end_hd;
got_hd:
		/*
		 * @hd is now the whole block device either being formatted or
		 * that the partition being formatted is on.
		 *
		 * Loop over each resource of the disk device looking for the
		 * BIOS legacy geometry obtained from EDD which is what Windows
		 * needs to boot.
		 */
		for (res = hd->res; res; res = res->next) {
			/* geotype 3 is BIOS legacy. */
			if (res->any.type != res_disk_geo ||
					res->disk_geo.geotype != 3)
				continue;
			dev->d_heads = res->disk_geo.heads;
			dev->d_sectors_per_track = res->disk_geo.sectors;
			done = 1;
		}
end_hd:
		if (partlist)
			hd_free_hd_list(partlist);
		hd_free_hd_list(devlist);
		hd_free_hd_data(hddata);
		free(hddata);
		if (done) {
			ntfs_log_debug("EDD/BIOD legacy heads = %u, sectors "
					"per track = %u\n", dev->d_heads,
					dev->d_sectors_per_track);
			return 0;
		}
	}
skip_hd:
#endif
#ifdef HDIO_GETGEO
	{	struct hd_geometry geo;

		if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) {
			dev->d_heads = geo.heads;
			dev->d_sectors_per_track = geo.sectors;
			ntfs_log_debug("HDIO_GETGEO heads = %u, sectors per "
					"track = %u\n", dev->d_heads,
					dev->d_sectors_per_track);
			return 0;
		}
		err = errno;
	}
#endif
	errno = err;
	return -1;
}
コード例 #8
0
ファイル: ldc_core.c プロジェクト: adrianomelo/ldc-desktop
void free_hd_structs (hd_data_t * hd_data, hd_t * hd) {
    hd_free_hd_list(hd);          /* free it */
    hd_free_hd_data(hd_data);

    free(hd_data);
}