亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? linux_usbfs.c

?? 最新的libusb庫
?? C
?? 第 1 頁 / 共 4 頁
字號:
/* * Linux usbfs backend for libusb * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org> * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include <config.h>#include <ctype.h>#include <dirent.h>#include <errno.h>#include <fcntl.h>#include <poll.h>#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include "libusb.h"#include "libusbi.h"#include "linux_usbfs.h"/* sysfs vs usbfs: * opening a usbfs node causes the device to be resumed, so we attempt to * avoid this during enumeration. * * sysfs allows us to read the kernel's in-memory copies of device descriptors * and so forth, avoiding the need to open the device: *  - The binary "descriptors" file was added in 2.6.23. *  - The "busnum" file was added in 2.6.22 *  - The "devnum" file has been present since pre-2.6.18 *  - the "bConfigurationValue" file has been present since pre-2.6.18 * * If we have bConfigurationValue, busnum, and devnum, then we can determine * the active configuration without having to open the usbfs node in RDWR mode. * We assume this is the case if we see the busnum file (indicates 2.6.22+). * The busnum file is important as that is the only way we can relate sysfs * devices to usbfs nodes. * * If we also have descriptors, we can obtain the device descriptor and active  * configuration without touching usbfs at all. * * The descriptors file originally only contained the active configuration * descriptor alongside the device descriptor, but all configurations are * included as of Linux 2.6.26. */static const char *usbfs_path = NULL;/* do we have a busnum to relate devices? this also implies that we can read * the active configuration through bConfigurationValue */static int sysfs_can_relate_devices = -1;/* do we have a descriptors file? */static int sysfs_has_descriptors = -1;struct linux_device_priv {	char *sysfs_dir;	unsigned char *dev_descriptor;	unsigned char *config_descriptor;};struct linux_device_handle_priv {	int fd;};enum reap_action {	NORMAL = 0,	/* submission failed after the first URB, so await cancellation/completion	 * of all the others */	SUBMIT_FAILED,	/* cancelled by user or timeout */	CANCELLED,	/* completed multi-URB transfer in non-final URB */	COMPLETED_EARLY,};struct linux_transfer_priv {	union {		struct usbfs_urb *urbs;		struct usbfs_urb **iso_urbs;	};	enum reap_action reap_action;	int num_urbs;	unsigned int awaiting_reap;	unsigned int awaiting_discard;	/* next iso packet in user-supplied transfer to be populated */	int iso_packet_offset;};static void __get_usbfs_path(struct libusb_device *dev, char *path){	snprintf(path, PATH_MAX, "%s/%03d/%03d", usbfs_path, dev->bus_number,		dev->device_address);}static struct linux_device_priv *__device_priv(struct libusb_device *dev){	return (struct linux_device_priv *) dev->os_priv;}static struct linux_device_handle_priv *__device_handle_priv(	struct libusb_device_handle *handle){	return (struct linux_device_handle_priv *) handle->os_priv;}static int check_usb_vfs(const char *dirname){	DIR *dir;	struct dirent *entry;	int found = 0;	dir = opendir(dirname);	if (!dir)		return 0;	while ((entry = readdir(dir)) != NULL) {		if (entry->d_name[0] == '.')			continue;		/* We assume if we find any files that it must be the right place */		found = 1;		break;	}	closedir(dir);	return found;}static const char *find_usbfs_path(void){	const char *path = "/dev/bus/usb";	const char *ret = NULL;	if (check_usb_vfs(path)) {		ret = path;	} else {		path = "/proc/bus/usb";		if (check_usb_vfs(path))			ret = path;	}	usbi_dbg("found usbfs at %s", ret);	return ret;}static int op_init(struct libusb_context *ctx){	struct stat statbuf;	int r;	usbfs_path = find_usbfs_path();	if (!usbfs_path) {		usbi_err(ctx, "could not find usbfs");		return LIBUSB_ERROR_OTHER;	}	r = stat(SYSFS_DEVICE_PATH, &statbuf);	if (r == 0 && S_ISDIR(statbuf.st_mode)) {		usbi_dbg("found usb devices in sysfs");	} else {		usbi_dbg("sysfs usb info not available");		sysfs_has_descriptors = 0;		sysfs_can_relate_devices = 0;	}	return 0;}static int usbfs_get_device_descriptor(struct libusb_device *dev,	unsigned char *buffer){	struct linux_device_priv *priv = __device_priv(dev);	/* return cached copy */	memcpy(buffer, priv->dev_descriptor, DEVICE_DESC_LENGTH);	return 0;}static int __open_sysfs_attr(struct libusb_device *dev, const char *attr){	struct linux_device_priv *priv = __device_priv(dev);	char filename[PATH_MAX];	int fd;	snprintf(filename, PATH_MAX, "%s/%s/%s",		SYSFS_DEVICE_PATH, priv->sysfs_dir, attr);	fd = open(filename, O_RDONLY);	if (fd < 0) {		usbi_err(DEVICE_CTX(dev),			"open %s failed ret=%d errno=%d", filename, fd, errno);		return LIBUSB_ERROR_IO;	}	return fd;}static int sysfs_get_device_descriptor(struct libusb_device *dev,	unsigned char *buffer){	int fd;	ssize_t r;	/* sysfs provides access to an in-memory copy of the device descriptor,	 * so we use that rather than keeping our own copy */	fd = __open_sysfs_attr(dev, "descriptors");	if (fd < 0)		return fd;	r = read(fd, buffer, DEVICE_DESC_LENGTH);;	close(fd);	if (r < 0) {		usbi_err(DEVICE_CTX(dev), "read failed, ret=%d errno=%d", fd, errno);		return LIBUSB_ERROR_IO;	} else if (r < DEVICE_DESC_LENGTH) {		usbi_err(DEVICE_CTX(dev), "short read %d/%d", r, DEVICE_DESC_LENGTH);		return LIBUSB_ERROR_IO;	}	return 0;}static int op_get_device_descriptor(struct libusb_device *dev,	unsigned char *buffer, int *host_endian){	if (sysfs_has_descriptors) {		return sysfs_get_device_descriptor(dev, buffer);	} else {		*host_endian = 1;		return usbfs_get_device_descriptor(dev, buffer);	}}static int usbfs_get_active_config_descriptor(struct libusb_device *dev,	unsigned char *buffer, size_t len){	struct linux_device_priv *priv = __device_priv(dev);	if (!priv->config_descriptor)		return LIBUSB_ERROR_NOT_FOUND; /* device is unconfigured */	/* retrieve cached copy */	memcpy(buffer, priv->config_descriptor, len);	return 0;}/* read the bConfigurationValue for a device */static int sysfs_get_active_config(struct libusb_device *dev, int *config){	char *endptr;	char tmp[4] = {0, 0, 0, 0};	long num;	int fd;	size_t r;	fd = __open_sysfs_attr(dev, "bConfigurationValue");	if (fd < 0)		return fd;	r = read(fd, tmp, sizeof(tmp));	close(fd);	if (r < 0) {		usbi_err(DEVICE_CTX(dev), 			"read bConfigurationValue failed ret=%d errno=%d", r, errno);		return LIBUSB_ERROR_IO;	} else if (r == 0) {		usbi_err(DEVICE_CTX(dev), "device unconfigured");		*config = -1;		return 0;	}	if (tmp[sizeof(tmp) - 1] != 0) {		usbi_err(DEVICE_CTX(dev), "not null-terminated?");		return LIBUSB_ERROR_IO;	} else if (tmp[0] == 0) {		usbi_err(DEVICE_CTX(dev), "no configuration value?");		return LIBUSB_ERROR_IO;	}	num = strtol(tmp, &endptr, 10);	if (endptr == tmp) {		usbi_err(DEVICE_CTX(dev), "error converting '%s' to integer", tmp);		return LIBUSB_ERROR_IO;	}	*config = (int) num;	return 0;}/* takes a usbfs/descriptors fd seeked to the start of a configuration, and * seeks to the next one. */static int seek_to_next_config(struct libusb_context *ctx, int fd){	struct libusb_config_descriptor config;	unsigned char tmp[6];	off_t off;	int r;	/* read first 6 bytes of descriptor */	r = read(fd, tmp, sizeof(tmp));	if (r < 0) {		usbi_err(ctx, "read failed ret=%d errno=%d", r, errno);		return LIBUSB_ERROR_IO;	} else if (r < sizeof(tmp)) {		usbi_err(ctx, "short descriptor read %d/%d", r, sizeof(tmp));		return LIBUSB_ERROR_IO;	}	/* seek forward to end of config */	usbi_parse_descriptor(tmp, "bbwbb", &config, 1);	off = lseek(fd, config.wTotalLength - sizeof(tmp), SEEK_CUR);	if (off < 0) {		usbi_err(ctx, "seek failed ret=%d errno=%d", off, errno);		return LIBUSB_ERROR_IO;	}	return 0;}static int sysfs_get_active_config_descriptor(struct libusb_device *dev,	unsigned char *buffer, size_t len){	int fd;	ssize_t r;	off_t off;	int to_copy;	int config;	unsigned char tmp[6];	r = sysfs_get_active_config(dev, &config);	if (r < 0)		return r;	if (config == -1)		return LIBUSB_ERROR_NOT_FOUND;	usbi_dbg("active configuration %d", config);	/* sysfs provides access to an in-memory copy of the device descriptor,	 * so we use that rather than keeping our own copy */	fd = __open_sysfs_attr(dev, "descriptors");	if (fd < 0)		return fd;	/* device might have been unconfigured since we read bConfigurationValue,	 * so first check that there is any config descriptor data at all... */	off = lseek(fd, 0, SEEK_END);	if (off < 1) {		usbi_err(DEVICE_CTX(dev), "end seek failed, ret=%d errno=%d",			off, errno);		close(fd);		return LIBUSB_ERROR_IO;	} else if (off == DEVICE_DESC_LENGTH) {		close(fd);		return LIBUSB_ERROR_NOT_FOUND;	}	off = lseek(fd, DEVICE_DESC_LENGTH, SEEK_SET);	if (off < 0) {		usbi_err(DEVICE_CTX(dev), "seek failed, ret=%d errno=%d", off, errno);		close(fd);		return LIBUSB_ERROR_IO;	}	/* unbounded loop: we expect the descriptor to be present under all	 * circumstances */	while (1) {		r = read(fd, tmp, sizeof(tmp));		if (r < 0) {			usbi_err(DEVICE_CTX(dev), "read failed, ret=%d errno=%d",				fd, errno);			return LIBUSB_ERROR_IO;		} else if (r < sizeof(tmp)) {			usbi_err(DEVICE_CTX(dev), "short read %d/%d", r, sizeof(tmp));			return LIBUSB_ERROR_IO;		}		/* check bConfigurationValue */		if (tmp[5] == config)			break;		/* try the next descriptor */		off = lseek(fd, 0 - sizeof(tmp), SEEK_CUR);		if (off < 0)			return LIBUSB_ERROR_IO;		r = seek_to_next_config(DEVICE_CTX(dev), fd);		if (r < 0)			return r;	}	to_copy = (len < sizeof(tmp)) ? len : sizeof(tmp);	memcpy(buffer, tmp, to_copy);	if (len > sizeof(tmp)) {		r = read(fd, buffer + sizeof(tmp), len - sizeof(tmp));		if (r < 0) {			usbi_err(DEVICE_CTX(dev), "read failed, ret=%d errno=%d",				fd, errno);			r = LIBUSB_ERROR_IO;		} else if (r == 0) {			usbi_dbg("device is unconfigured");			r = LIBUSB_ERROR_NOT_FOUND;		} else if (r < len - sizeof(tmp)) {			usbi_err(DEVICE_CTX(dev), "short read %d/%d", r, len);			r = LIBUSB_ERROR_IO;		}	} else {		r = 0;	}	close(fd);	return r;}static int op_get_active_config_descriptor(struct libusb_device *dev,	unsigned char *buffer, size_t len, int *host_endian){	if (sysfs_has_descriptors) {		return sysfs_get_active_config_descriptor(dev, buffer, len);	} else {		*host_endian = 1;		return usbfs_get_active_config_descriptor(dev, buffer, len);	}}/* takes a usbfs fd, attempts to find the requested config and copy a certain * amount of it into an output buffer. */static int get_config_descriptor(struct libusb_context *ctx, int fd,	uint8_t config_index, unsigned char *buffer, size_t len){	off_t off;	ssize_t r;	off = lseek(fd, DEVICE_DESC_LENGTH, SEEK_SET);	if (off < 0) {		usbi_err(ctx, "seek failed ret=%d errno=%d", off, errno);		return LIBUSB_ERROR_IO;	}	/* might need to skip some configuration descriptors to reach the	 * requested configuration */	while (config_index > 0) {		r = seek_to_next_config(ctx, fd);		if (r < 0)			return r;		config_index--;	}	/* read the rest of the descriptor */	r = read(fd, buffer, len);	if (r < 0) {		usbi_err(ctx, "read failed ret=%d errno=%d", r, errno);		return LIBUSB_ERROR_IO;	} else if (r < len) {		usbi_err(ctx, "short output read %d/%d", r, len);		return LIBUSB_ERROR_IO;	}	return 0;}static int op_get_config_descriptor(struct libusb_device *dev,	uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian){	char filename[PATH_MAX];	int fd;	int r;	/* always read from usbfs: sysfs only has the active descriptor	 * this will involve waking the device up, but oh well! */	/* FIXME: the above is no longer true, new kernels have all descriptors	 * in the descriptors file. but its kinda hard to detect if the kernel	 * is sufficiently new. */	__get_usbfs_path(dev, filename);	fd = open(filename, O_RDONLY);	if (fd < 0) {		usbi_err(DEVICE_CTX(dev),			"open '%s' failed, ret=%d errno=%d", filename, fd, errno);		return LIBUSB_ERROR_IO;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美二区在线观看| 久久久综合精品| 91精品国产一区二区人妖| 国产色一区二区| 久久久99免费| 亚洲成人免费影院| 在线综合视频播放| 一个色综合av| 91福利视频网站| 亚洲精品中文在线影院| 国产成人精品免费一区二区| 精品国产三级a在线观看| 久久99久久久久久久久久久| 欧美一区二区在线免费观看| 久久国产日韩欧美精品| 精品国产乱码久久久久久久久| 久草热8精品视频在线观看| 亚洲精品一区二区三区在线观看 | 成人免费福利片| 亚洲专区一二三| 日韩一区二区三区视频在线观看| 久久99精品国产麻豆婷婷| 国产午夜精品一区二区三区嫩草| 成人精品高清在线| 视频一区二区国产| 国产拍揄自揄精品视频麻豆| 欧美伊人久久大香线蕉综合69 | 欧美专区在线观看一区| 久久草av在线| 一卡二卡三卡日韩欧美| 久久久777精品电影网影网| 欧美午夜片在线观看| 国产乱码精品一区二区三区av| 一区二区三区四区av| 欧美激情在线一区二区| 欧美肥妇bbw| 成人午夜精品一区二区三区| 日本在线播放一区二区三区| 日韩国产精品久久| 精品一区二区三区香蕉蜜桃| 成人午夜在线视频| 国产精品一二二区| 91免费国产在线| 欧美亚洲图片小说| 2020国产精品| 亚洲素人一区二区| 日本亚洲欧美天堂免费| 精品国产sm最大网站免费看| 国产综合久久久久影院| 麻豆传媒一区二区三区| 日本不卡在线视频| 日韩二区在线观看| 日韩成人午夜电影| 麻豆精品视频在线观看免费 | 色婷婷激情一区二区三区| 成人黄色小视频| 91亚洲精华国产精华精华液| 91免费看视频| 777a∨成人精品桃花网| 欧美一级搡bbbb搡bbbb| 欧美大片在线观看一区| 久久精品一级爱片| 亚洲图片欧美激情| 日本欧美在线观看| 国产乱码精品一区二区三区忘忧草| 成人午夜视频在线| 欧美日高清视频| 亚洲精品在线免费播放| 国产精品国产自产拍高清av| 午夜精品一区二区三区免费视频 | 六月婷婷色综合| 亚洲国产视频a| 亚洲大片在线观看| 日本一区二区三区免费乱视频 | 欧美一区二区在线观看| 91黄色激情网站| 91精品欧美综合在线观看最新 | 欧美精品v国产精品v日韩精品| 亚洲精品国产一区二区精华液| 日本午夜一区二区| 播五月开心婷婷综合| 日韩女优制服丝袜电影| 亚洲精品国久久99热| 国产成人一级电影| 4438成人网| 亚洲综合在线免费观看| 国产美女av一区二区三区| 欧美一卡二卡三卡四卡| 亚洲精品写真福利| 成人理论电影网| 久久精品人人爽人人爽| 蜜臀久久99精品久久久久宅男 | 国产日韩v精品一区二区| 日韩精品电影一区亚洲| 欧美影视一区二区三区| 亚洲色图视频网站| 99re成人在线| 亚洲同性gay激情无套| 成人av在线影院| 欧美国产日韩一二三区| 国产超碰在线一区| 国产欧美一区二区精品婷婷| 国产精品自拍av| 国产亚洲精品资源在线26u| 国产在线精品不卡| 久久精品人人做人人综合 | 欧美二区三区91| 丝瓜av网站精品一区二区| 91精品免费观看| 精品无人区卡一卡二卡三乱码免费卡| 日韩一卡二卡三卡四卡| 经典一区二区三区| 中文字幕一区二区三区乱码在线| 成人国产精品免费观看动漫| 亚洲日本一区二区三区| 制服丝袜在线91| 国产精品66部| 日日夜夜免费精品| 久久久久久久性| 欧美日韩综合一区| 国产激情视频一区二区在线观看 | 国产一区在线精品| 日韩码欧中文字| 欧美mv日韩mv亚洲| 色婷婷av一区二区三区大白胸 | 成人免费一区二区三区视频| 欧美高清性hdvideosex| 国产精品一区二区91| 视频一区二区中文字幕| 国产精品成人午夜| 亚洲精品在线观看网站| 欧美日韩在线一区二区| jizzjizzjizz欧美| 久久99国产精品久久99| 午夜亚洲福利老司机| 久久精品一区二区三区四区| 欧美理论片在线| 在线这里只有精品| 成人白浆超碰人人人人| 国产一区二区视频在线播放| 亚洲国产精品欧美一二99| 中文字幕一区在线| 国产精品国产三级国产普通话蜜臀| 欧美一区二区三区人| 欧美在线观看一区| 99国产精品久久久| www.99精品| 91久久精品网| 91成人在线精品| 欧美片在线播放| 欧美男同性恋视频网站| 欧美日韩国产高清一区| 欧美人动与zoxxxx乱| 91精品在线一区二区| 欧美一级夜夜爽| 国产精品情趣视频| 欧美最猛性xxxxx直播| 欧美一区二区网站| 亚洲一区在线观看网站| 视频一区免费在线观看| 国产日韩高清在线| 日韩精品亚洲一区二区三区免费| 粉嫩高潮美女一区二区三区| 欧美日韩高清一区二区不卡| 国产精品网站导航| 日本亚洲电影天堂| 欧美揉bbbbb揉bbbbb| 欧美精品一区男女天堂| 日韩电影一区二区三区四区| 一本一道波多野结衣一区二区| 久久久久久97三级| 国内外精品视频| 日韩三级视频在线观看| 日韩黄色片在线观看| 欧美在线三级电影| 一区二区三区在线播| www.日韩精品| 1024成人网| 国产白丝网站精品污在线入口| 宅男在线国产精品| 日韩成人免费看| 欧美大胆一级视频| 精品一区二区在线免费观看| 日韩一区二区麻豆国产| 麻豆精品久久久| 精品91自产拍在线观看一区| 狠狠色综合播放一区二区| 欧美一级一区二区| 美女高潮久久久| 日韩欧美激情一区| 久久99最新地址| 欧美精品一区二区不卡| 精品一区二区三区日韩| 欧美一二三在线| 国产最新精品免费| 亚洲色图另类专区| 制服丝袜亚洲精品中文字幕| 免费看欧美女人艹b| 日韩视频免费观看高清完整版 | 一卡二卡欧美日韩|