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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? linux_usbfs.c

?? 最新的libusb庫(kù)
?? C
?? 第 1 頁(yè) / 共 4 頁(yè)
字號(hào):
/* * 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;

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品传媒入口麻豆| 亚洲国产精品久久人人爱蜜臀 | 欧美成人a∨高清免费观看| 亚洲国产综合91精品麻豆| 成人白浆超碰人人人人| 国产日韩欧美不卡在线| 国产毛片精品视频| 久久先锋影音av鲁色资源网| 美女一区二区在线观看| 欧美一区二视频| 日韩一区欧美二区| 在线不卡中文字幕播放| 午夜视频一区二区| 欧美精品欧美精品系列| 亚洲第一激情av| 欧美日韩中文精品| 亚洲va在线va天堂| 8x福利精品第一导航| 视频一区二区中文字幕| 777久久久精品| 日韩电影在线观看网站| 日韩欧美在线不卡| 久色婷婷小香蕉久久| 欧美mv日韩mv国产网站| 国产乱人伦偷精品视频不卡| 久久久久亚洲蜜桃| 成人av在线网| 亚洲特黄一级片| 欧美亚一区二区| 日日夜夜精品视频天天综合网| 欧美肥妇毛茸茸| 午夜av电影一区| 日韩精品资源二区在线| 九色porny丨国产精品| 国产亚洲一区二区三区| 大胆欧美人体老妇| 一区二区在线看| 欧美日韩mp4| 老色鬼精品视频在线观看播放| 精品国产91亚洲一区二区三区婷婷 | 欧美一级片在线看| 精一区二区三区| 国产日韩亚洲欧美综合| 色综合一区二区三区| 亚洲国产精品综合小说图片区| 6080yy午夜一二三区久久| 国产综合久久久久久鬼色 | 久久精品一区二区三区不卡牛牛| 国产高清无密码一区二区三区| 中文字幕精品一区二区精品绿巨人| av中文字幕亚洲| 香蕉成人啪国产精品视频综合网| 日韩女优av电影在线观看| 国产盗摄视频一区二区三区| 国产精品白丝在线| 91精品国产色综合久久不卡电影 | 亚洲第一久久影院| 精品国产免费久久| 96av麻豆蜜桃一区二区| 日韩国产欧美三级| 国产日韩欧美一区二区三区综合 | 99国产精品久久久| 日韩专区一卡二卡| 国产欧美精品一区| 欧美性色综合网| 国产福利一区二区三区视频在线 | 国产欧美一区二区三区网站| 一本到不卡精品视频在线观看| 七七婷婷婷婷精品国产| 中文无字幕一区二区三区| 精品视频一区三区九区| 国产一区激情在线| 亚洲国产精品精华液网站| 精品国产青草久久久久福利| 91麻豆国产自产在线观看| 蜜臀a∨国产成人精品| 亚洲欧洲成人自拍| 日韩免费看的电影| 91麻豆视频网站| 国内成人免费视频| 亚洲成在人线在线播放| 中文字幕不卡的av| 欧美一区二区私人影院日本| 不卡一卡二卡三乱码免费网站| 日本美女视频一区二区| 亚洲四区在线观看| 久久久久久久久久电影| 欧美久久久久久蜜桃| 成人av资源网站| 国产真实乱对白精彩久久| 一区二区三区精密机械公司| 国产日韩欧美不卡| 日韩一区二区三区视频在线观看| 91在线丨porny丨国产| 欧美a级一区二区| 一二三区精品视频| 中文字幕欧美日本乱码一线二线| 91精品国产综合久久国产大片| gogo大胆日本视频一区| 久久国产精品99久久人人澡| 亚洲成人在线网站| 亚洲欧美福利一区二区| 久久久不卡影院| 欧美v日韩v国产v| 在线成人高清不卡| 色婷婷av一区二区三区gif| 国产成人福利片| 狠狠色狠狠色综合系列| 亚洲成人综合视频| 一区二区三区加勒比av| 亚洲欧美自拍偷拍| 国产欧美视频一区二区| 日韩欧美精品在线视频| 欧美久久久久免费| 精品1区2区3区| 在线视频亚洲一区| 91麻豆免费观看| 国产福利91精品一区| 精品午夜一区二区三区在线观看 | 无码av中文一区二区三区桃花岛| 亚洲色图在线视频| 中文字幕日韩一区二区| 中文乱码免费一区二区| 国产亚洲美州欧州综合国| 精品99999| 精品日韩在线一区| 欧美大片国产精品| 欧美一二区视频| 91精品国产高清一区二区三区蜜臀 | 激情深爱一区二区| 麻豆精品国产91久久久久久| 日韩精品免费专区| 日韩在线播放一区二区| 亚洲成a人片综合在线| 亚洲国产另类av| 五月天亚洲婷婷| 天天亚洲美女在线视频| 丝袜国产日韩另类美女| 日本不卡123| 蜜桃视频第一区免费观看| 日本不卡一区二区| 美国十次综合导航| 美女脱光内衣内裤视频久久影院| 免费观看久久久4p| 国内精品国产成人国产三级粉色| 久久爱另类一区二区小说| 国产一区欧美一区| 丰满少妇久久久久久久| 成人福利视频网站| 91福利视频久久久久| 在线观看日韩电影| 欧美日韩的一区二区| 欧美一级高清片| 欧美精品一区二区三区在线播放| 2021久久国产精品不只是精品| 久久先锋影音av鲁色资源| 欧美国产日本视频| 亚洲欧美一区二区三区极速播放 | 福利电影一区二区| 91麻豆免费观看| 欧美日本乱大交xxxxx| 69堂亚洲精品首页| 久久亚洲精华国产精华液| 中文无字幕一区二区三区| 亚洲日本免费电影| 亚洲图片欧美综合| 久草热8精品视频在线观看| 懂色av中文字幕一区二区三区 | 色欧美88888久久久久久影院| 色综合久久久久久久久| 欧美日精品一区视频| 欧美一级黄色片| 日本一区二区三区四区在线视频| 亚洲国产高清在线观看视频| 亚洲精品成人精品456| 日本成人中文字幕在线视频| 国产成人a级片| 在线观看区一区二| 精品久久人人做人人爱| 综合久久综合久久| 日韩制服丝袜av| 成人综合婷婷国产精品久久免费| 色综合一个色综合亚洲| 在线综合+亚洲+欧美中文字幕| 久久综合久久综合亚洲| ㊣最新国产の精品bt伙计久久| 亚洲高清视频在线| 国产毛片一区二区| 在线观看成人免费视频| 亚洲精品一区二区三区四区高清| 1000部国产精品成人观看| 日本强好片久久久久久aaa| 国产成人免费视频网站高清观看视频| 在线视频欧美区| 久久免费精品国产久精品久久久久| 亚洲人成网站精品片在线观看| 免费成人在线网站| 91蜜桃网址入口| 欧美成人一区二区三区片免费| 成人欧美一区二区三区小说|