// Shows all the records in the inventory database.
// For each inventory record shown, the appropriate
// vendor record is also displayed.
int
show_all_records(MyDb &inventoryDB, MyDb &vendorDB)
{

	// Get a cursor to the inventory db
	Dbc *cursorp;
	try {
		inventoryDB.getDb().cursor(NULL, &cursorp, 0);

		// Iterate over the inventory database, from the first record
		// to the last, displaying each in turn
		Dbt key, data;
		int ret;
		while ((ret = cursorp->get(&key, &data, DB_NEXT)) == 0 ) {
			InventoryData inventoryItem(data.get_data());
			inventoryItem.show();

			show_vendor(vendorDB, inventoryItem.getVendor().c_str());
		}
	}
	catch (DbException &e) {
		inventoryDB.getDb().err(e.get_errno(), "Error in show_all_records");
		cursorp->close();
		throw e;
	}
	catch (std::exception &e) {
		cursorp->close();
		throw e;
	}

	cursorp->close();
	return (0);
}
예제 #2
0
파일: scsi.c 프로젝트: vonnyfly/recipes
void test_execute_Inquiry(char* path, int evpd, int page_code) {

  struct sg_io_hdr* p_hdr = init_io_hdr();

  set_xfer_data(p_hdr, data_buffer, BLOCK_LEN * 256);
  set_sense_data(p_hdr, sense_buffer, SENSE_LEN);

  int status = 0;

  int fd = open(path, O_RDWR);
  if (fd > 0) {
    status = execute_Inquiry(fd, page_code, evpd, p_hdr);
    printf("the return status is %d\n", status);
    if (status != 0) {
      show_sense_buffer(p_hdr);
    } else {
      show_vendor(p_hdr);
      show_product(p_hdr);
      show_product_rev(p_hdr);
    }
  } else {
    printf("failed to open sg file %s\n", path);
  }
  close(fd);
  destroy_io_hdr(p_hdr);
}
예제 #3
0
int
main (int argc, char *argv[])
{
	GnomePnpIds *ids;
	guint i;

	g_type_init ();

	ids = gnome_pnp_ids_new ();

	if (argc == 2 &&
	    g_str_equal (argv[1], "--timed")) {
		GTimer *timer;
		gdouble elapsed;

		timer = g_timer_new ();

		for (i = 0; i < NUM_ITERS; i++) {
			char *vendor;
			vendor = gnome_pnp_ids_get_pnp_id (ids, "ZZZ");
			g_free (vendor);
		}

		elapsed = g_timer_elapsed (timer, NULL);
		g_timer_destroy (timer);

		g_message ("%d iterations took %lf seconds", NUM_ITERS, elapsed);
		g_object_unref (ids);

		return 0;
	}


	for (i = 1; i < argc; i++)
		show_vendor (ids, argv[i]);
	if (argc < 2) {
		show_vendor (ids, "ELO");
		show_vendor (ids, "IBM");
	}

	g_object_unref (ids);
	return 0;
}
// Shows the records in the inventory database that
// have a specific item name. For each inventory record
// shown, the appropriate vendor record is also displayed.
int
show_item(MyDb &itemnameSDB, MyDb &vendorDB, std::string &itemName)
{

	// Get a cursor to the itemname secondary db
	Dbc *cursorp;

	try {
		itemnameSDB.getDb().cursor(NULL, &cursorp, 0);

		// Get the search key. This is the name on the inventory
		// record that we want to examine.
		std::cout << "Looking for " << itemName << std::endl;
		Dbt key((void *)itemName.c_str(), (u_int32_t)itemName.length() + 1);
		Dbt data;

		// Position the cursor to the first record in the secondary
		// database that has the appropriate key.
		int ret = cursorp->get(&key, &data, DB_SET);
		if (!ret) {
			do {
				InventoryData inventoryItem(data.get_data());
				inventoryItem.show();

				show_vendor(vendorDB, inventoryItem.getVendor().c_str());

			}
			while (cursorp->get(&key, &data, DB_NEXT_DUP) == 0);
		}
		else {
			std::cerr << "No records found for '" << itemName
			<< "'" << std::endl;
		}
	}
	catch (DbException &e) {
		itemnameSDB.getDb().err(e.get_errno(), "Error in show_item");
		cursorp->close();
		throw e;
	}
	catch (std::exception &e) {
		itemnameSDB.getDb().errx("Error in show_item: %s", e.what());
		cursorp->close();
		throw e;
	}

	cursorp->close();
	return (0);
}
예제 #5
0
void show_serial_number(struct sg_io_hdr *hdr)
{
	unsigned char *buffer = hdr->dxferp;
	int i;
	printf("serial number: ");
	for (i=0x80, 
}
#endif

#define SENSE_LEN 32
#define BLOCK_LEN 1

unsigned char sense_buffer[SENSE_LEN];
unsigned char data_buffer[BLOCK_LEN*256];
void test_execute_Inquiry(char * path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		if (status!=0) {
			show_sense_buffer(p_hdr);
		} else{
			show_vendor(p_hdr);
			show_product(p_hdr);
			show_product_rev(p_hdr);
			show_xfer_data(p_hdr);
		}
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}


void test_cmds(char *path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		//show_sense_buffer(p_hdr);
		show_xfer_data(p_hdr);
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}

void get_rpm(char *path, int evpd, int page_code)
{
	struct sg_io_hdr * p_hdr = init_io_hdr();
	set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256);
	set_sense_data(p_hdr, sense_buffer, SENSE_LEN);
	int status = 0;
	unsigned char *xfer;
	int pdt, rpm;

	int fd = open(path, O_RDWR);
	if (fd>0) {
		status = execute_Inquiry(fd, page_code, evpd, p_hdr);
		printf("the return status is %d\n", status);
		//show_sense_buffer(p_hdr);
		//show_xfer_data(p_hdr);

		// 参考代码 sg3_utils: sg_vpd.c : decode_b1_vpd()
		xfer = p_hdr->dxferp;
		pdt = (int)xfer[0];
		switch (pdt)
		{
			case 0:
				if (p_hdr->dxfer_len < 64)
				{
					printf("xfer is too short!\n");
				}
				else
				{
					rpm = (xfer[4]<<8) | xfer[5];
					printf("rpm of %s: %d rpm\n", path, rpm);
				}
				break;
			default:
				printf("unknown pdt\n");
				break;
		}
	} else {
		printf("failed to open sg file %s\n", path);
	}
	close(fd);
	destroy_io_hdr(p_hdr);
}

int main(int argc, char * argv[])
{
	//test_execute_Inquiry(argv[1], 0, 0);

	//test_cmds(argv[1], 1, 0x86);
	get_rpm(argv[1], 1, 0xb1); // rpm
	// tested:
	// 0x80,0x83

	return 0;
}