Esempio n. 1
0
static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
{
	unsigned int maj, min;
	const char *attr;

	dbg("%s", devpath);
	attr = sysfs_attr_get_value(devpath, "dev");
	if (attr == NULL) {
		dbg("%s: could not get dev attribute: %s", devpath, strerror(errno));
		return -1;
	}

	dbg("dev value %s", attr);
	if (sscanf(attr, "%u:%u", &maj, &min) != 2) {
		err("%s: invalid dev major/minor", devpath);
		return -1;
	}

	snprintf(tmpdev, MAX_PATH_LEN, "%s/%s-maj%d-min%d-%u",
		 TMP_DIR, TMP_PREFIX, maj, min, getpid());

	dbg("tmpdev '%s'", tmpdev);
	if (mknod(tmpdev, 0600 | dev_type, makedev(maj, min))) {
		err("mknod failed: %s", strerror(errno));
		return -1;
	}
	return 0;
}
Esempio n. 2
0
dev_t udev_device_get_devt(struct udevice *udev)
{
	const char *attr;
	unsigned int maj, min;

	/* read it from sysfs  */
	attr = sysfs_attr_get_value(udev->dev->devpath, "dev");
	if (attr != NULL) {
		if (sscanf(attr, "%u:%u", &maj, &min) == 2)
			return makedev(maj, min);
	}
	return makedev(0, 0);
}
Esempio n. 3
0
static int per_dev_options(struct sysfs_device *dev_scsi, int *good_bad, int *page_code)
{
	int retval;
	int newargc;
	char **newargv = NULL;
	const char *vendor, *model, *type;
	int option;

	*good_bad = all_good;
	*page_code = default_page_code;

	vendor = sysfs_attr_get_value(dev_scsi->devpath, "vendor");
	if (!vendor) {
		info("%s: cannot get vendor attribute", dev_scsi->devpath);
		return -1;
	}
	set_str(vendor_str, vendor, sizeof(vendor_str)-1);

	model = sysfs_attr_get_value(dev_scsi->devpath, "model");
	if (!model) {
		info("%s: cannot get model attribute\n", dev_scsi->devpath);
		return -1;
	}
	set_str(model_str, model, sizeof(model_str)-1);

	type = sysfs_attr_get_value(dev_scsi->devpath, "type");
	if (!type) {
		info("%s: cannot get type attribute", dev_scsi->devpath);
		return -1;
	}
	set_type(type_str, type, sizeof(type_str));

	type = sysfs_attr_get_value(dev_scsi->devpath, "rev");
	if (!type) {
		info("%s: cannot get type attribute\n", dev_scsi->devpath);
		return -1;
	}
	set_str(revision_str, type, sizeof(revision_str)-1);

	retval = get_file_options(vendor, model, &newargc, &newargv);

	optind = 1; /* reset this global extern */
	while (retval == 0) {
		option = getopt(newargc, newargv, dev_short_options);
		if (option == -1)
			break;

		if (optarg)
			dbg("option '%c' arg '%s'\n", option, optarg);
		else
			dbg("option '%c'\n", option);

		switch (option) {
		case 'b':
			*good_bad = 0;
			break;

		case 'g':
			*good_bad = 1;
			break;

		case 'p':
			if (strcmp(optarg, "0x80") == 0) {
				*page_code = PAGE_80;
			} else if (strcmp(optarg, "0x83") == 0) {
				*page_code = PAGE_83;
			} else if (strcmp(optarg, "pre-spc3-83") == 0) {
				*page_code = PAGE_83_PRE_SPC3; 
			} else {
				info("Unknown page code '%s'", optarg);
				retval = -1;
			}
			break;

		default:
			info("Unknown or bad option '%c' (0x%x)", option, option);
			retval = -1;
			break;
		}
	}

	if (newargv) {
		free(newargv[0]);
		free(newargv);
	}
	return retval;
}