From 3fd0ff505b952eb8ca80b47e0f1fb5b76cf0e960 Mon Sep 17 00:00:00 2001 From: libaoshan Date: Sat, 30 Aug 2025 14:38:55 +0800 Subject: [PATCH] libusb hide sn write log fix. Signed-off-by: libaoshan --- hide-log-dev-id.patch | 185 ++++++++++++++++++++++++++++++++++++++++++ install.sh | 2 + 2 files changed, 187 insertions(+) create mode 100644 hide-log-dev-id.patch diff --git a/hide-log-dev-id.patch b/hide-log-dev-id.patch new file mode 100644 index 0000000..98df775 --- /dev/null +++ b/hide-log-dev-id.patch @@ -0,0 +1,185 @@ +diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c +index 285d9ca..52aa118 100644 +--- a/libusb/os/linux_usbfs.c ++++ b/libusb/os/linux_usbfs.c +@@ -213,7 +213,7 @@ static int get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent) + } + + if (!silent) { +- usbi_err(ctx, "libusb couldn't open USB device %s, errno=%d", path, errno); ++ usbi_err(ctx, "libusb couldn't open USB device, errno=%d", errno); + if (errno == EACCES && mode == O_RDWR) + usbi_err(ctx, "libusb requires write access to USB device nodes"); + } +diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c +index 28b167f..e31554e 100644 +--- a/libusb/os/sunos_usb.c ++++ b/libusb/os/sunos_usb.c +@@ -173,7 +173,6 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd) + nvlist_add_int32(nvlist, "port", dev->port_number); + //find the hub path + snprintf(path_arg, sizeof(path_arg), "/devices%s:hubd", hubpath); +- usbi_dbg(DEVICE_CTX(dev), "ioctl hub path: %s", path_arg); + + fd = open(path_arg, O_RDONLY); + if (fd < 0) { +@@ -530,9 +529,9 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev) + dev->speed = LIBUSB_SPEED_SUPER; + } + +- usbi_dbg(DEVICE_CTX(dev), "vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, speed=%d", ++ usbi_dbg(DEVICE_CTX(dev), "vid=%x pid=%x, bus_nmber=0x%x, port_number=%d, speed=%d", + dev->device_descriptor.idVendor, dev->device_descriptor.idProduct, +- dpriv->phypath, dev->bus_number, dev->port_number, dev->speed); ++ dev->bus_number, dev->port_number, dev->speed); + + return (LIBUSB_SUCCESS); + } +diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c +index ffc1612..a2faad3 100644 +--- a/libusb/os/windows_winusb.c ++++ b/libusb/os/windows_winusb.c +@@ -898,7 +898,7 @@ static int init_root_hub(struct libusb_device *dev) + // changes if/how Windows returns any useful speed information. + handle = CreateFileA(priv->path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (handle == INVALID_HANDLE_VALUE) { +- usbi_err(ctx, "could not open root hub %s: %s", priv->path, windows_error_str(0)); ++ usbi_err(ctx, "could not open root hub: %s", windows_error_str(0)); + return LIBUSB_ERROR_ACCESS; + } + +@@ -1108,7 +1108,7 @@ static int init_device(struct libusb_device *dev, struct libusb_device *parent_d + + hub_handle = CreateFileA(parent_priv->path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hub_handle == INVALID_HANDLE_VALUE) { +- usbi_warn(ctx, "could not open hub %s: %s", parent_priv->path, windows_error_str(0)); ++ usbi_warn(ctx, "could not open hub: %s", windows_error_str(0)); + return LIBUSB_ERROR_ACCESS; + } + +@@ -1273,24 +1273,24 @@ static int enumerate_hcd_root_hub(struct libusb_context *ctx, const char *dev_id + DEVINST child_devinst; + + if (CM_Get_Child(&child_devinst, devinst, 0) != CR_SUCCESS) { +- usbi_warn(ctx, "could not get child devinst for '%s'", dev_id); ++ usbi_warn(ctx, "could not get child devinst"); + return LIBUSB_SUCCESS; + } + + session_id = (unsigned long)child_devinst; + dev = usbi_get_device_by_session_id(ctx, session_id); + if (dev == NULL) { +- usbi_err(ctx, "program assertion failed - HCD '%s' child not found", dev_id); ++ usbi_err(ctx, "program assertion failed - HCD child not found"); + return LIBUSB_SUCCESS; + } + + if (dev->bus_number == 0) { + // Only do this once +- usbi_dbg(ctx, "assigning HCD '%s' bus number %u", dev_id, bus_number); ++ usbi_dbg(ctx, "assigning HCD bus number %u", bus_number); + dev->bus_number = bus_number; + + if (sscanf(dev_id, "PCI\\VEN_%04hx&DEV_%04hx%*s", &dev->device_descriptor.idVendor, &dev->device_descriptor.idProduct) != 2) +- usbi_warn(ctx, "could not infer VID/PID of HCD root hub from '%s'", dev_id); ++ usbi_warn(ctx, "could not infer VID/PID of HCD root hub"); + + priv = usbi_get_device_priv(dev); + priv->root_hub = true; +@@ -1585,7 +1585,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + // This will allow us to enumerate all classes during the GEN pass + if (!pSetupDiGetDeviceRegistryPropertyA(*dev_info, &dev_info_data, SPDRP_ENUMERATOR_NAME, + NULL, (PBYTE)enumerator, sizeof(enumerator), NULL)) { +- usbi_err(ctx, "could not read enumerator string for device '%s': %s", dev_id, windows_error_str(0)); ++ usbi_err(ctx, "could not read enumerator string: %s", windows_error_str(0)); + LOOP_BREAK(LIBUSB_ERROR_OTHER); + } + for (j = 0; j < nb_usb_enumerators; j++) { +@@ -1611,7 +1611,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + // We use the GEN pass to detect driverless devices... + if (!pSetupDiGetDeviceRegistryPropertyA(*dev_info, &dev_info_data, SPDRP_DRIVER, + NULL, NULL, 0, NULL) && (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) { +- usbi_info(ctx, "The following device has no driver: '%s'", dev_id); ++ usbi_info(ctx, "The following device has no driver"); + usbi_info(ctx, "libusb will not be able to access it"); + } + // ...and to add the additional device interface GUIDs +@@ -1630,7 +1630,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + if (s == ERROR_FILE_NOT_FOUND) { + break; /* no DeviceInterfaceGUID registered */ + } else if (s != ERROR_SUCCESS && s != ERROR_MORE_DATA) { +- usbi_warn(ctx, "unexpected error from pRegQueryValueExA for '%s'", dev_id); ++ usbi_warn(ctx, "unexpected error from pRegQueryValueExA"); + break; + } + // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexa#remarks +@@ -1653,7 +1653,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + LOOP_BREAK(LIBUSB_ERROR_NO_MEM); + } + if (!string_to_guid(guid_string, if_guid)) { +- usbi_warn(ctx, "device '%s' has malformed DeviceInterfaceGUID string '%s', skipping", dev_id, guid_string); ++ usbi_warn(ctx, "device has malformed DeviceInterfaceGUID string '%s', skipping", guid_string); + free(if_guid); + } else { + // Check if we've already seen this GUID +@@ -1670,7 +1670,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + } + } + } else { +- usbi_warn(ctx, "unexpected type/size of DeviceInterfaceGUID for '%s'", dev_id); ++ usbi_warn(ctx, "unexpected type/size of DeviceInterfaceGUID"); + } + break; + case HID_PASS: +@@ -1680,11 +1680,11 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + // Get the API type (after checking that the driver installation is OK) + if ((!pSetupDiGetDeviceRegistryPropertyA(*dev_info, &dev_info_data, SPDRP_INSTALL_STATE, + NULL, (PBYTE)&install_state, sizeof(install_state), &size)) || (size != sizeof(install_state))) { +- usbi_warn(ctx, "could not detect installation state of driver for '%s': %s", +- dev_id, windows_error_str(0)); ++ usbi_warn(ctx, "could not detect installation state of driver: %s", ++ windows_error_str(0)); + } else if (install_state != 0) { +- usbi_warn(ctx, "driver for device '%s' is reporting an issue (code: %lu) - skipping", +- dev_id, ULONG_CAST(install_state)); ++ usbi_warn(ctx, "driver is reporting an issue (code: %lu) - skipping", ++ ULONG_CAST(install_state)); + continue; + } + get_api_type(dev_info, &dev_info_data, &api, &sub_api); +@@ -1704,7 +1704,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + libusb_unref_device(dev); + } + +- usbi_dbg(ctx, "unlisted ancestor for '%s' (non USB HID, newly connected, etc.) - ignoring", dev_id); ++ usbi_dbg(ctx, "unlisted ancestor (non USB HID, newly connected, etc.) - ignoring"); + continue; + } + +@@ -1806,7 +1806,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_ + case GEN_PASS: + port_nr = 0; + if (!get_dev_port_number(*dev_info, &dev_info_data, &port_nr)) +- usbi_warn(ctx, "could not retrieve port number for device '%s': %s", dev_id, windows_error_str(0)); ++ usbi_warn(ctx, "could not retrieve port number: %s", windows_error_str(0)); + r = init_device(dev, parent_dev, (uint8_t)port_nr, dev_info_data.DevInst); + if (r == LIBUSB_SUCCESS) { + // Append device to the list of discovered devices +@@ -2440,7 +2440,7 @@ static int winusbx_open(int sub_api, struct libusb_device_handle *dev_handle) + && (priv->usb_interface[i].apib->id == USB_API_WINUSBX)) { + file_handle = windows_open(dev_handle, priv->usb_interface[i].path, GENERIC_READ | GENERIC_WRITE); + if (file_handle == INVALID_HANDLE_VALUE) { +- usbi_err(HANDLE_CTX(dev_handle), "could not open device %s (interface %d): %s", priv->usb_interface[i].path, i, windows_error_str(0)); ++ usbi_err(HANDLE_CTX(dev_handle), "could not open device (interface %d): %s", i, windows_error_str(0)); + switch (GetLastError()) { + case ERROR_FILE_NOT_FOUND: // The device was disconnected + return LIBUSB_ERROR_NO_DEVICE; +@@ -3792,7 +3792,7 @@ static int hid_open(int sub_api, struct libusb_device_handle *dev_handle) + usbi_warn(HANDLE_CTX(dev_handle), "could not open HID device in R/W mode (keyboard or mouse?) - trying without"); + hid_handle = windows_open(dev_handle, priv->usb_interface[i].path, 0); + if (hid_handle == INVALID_HANDLE_VALUE) { +- usbi_err(HANDLE_CTX(dev_handle), "could not open device %s (interface %d): %s", priv->path, i, windows_error_str(0)); ++ usbi_err(HANDLE_CTX(dev_handle), "could not open device (interface %d): %s", i, windows_error_str(0)); + switch (GetLastError()) { + case ERROR_FILE_NOT_FOUND: // The device was disconnected + return LIBUSB_ERROR_NO_DEVICE; diff --git a/install.sh b/install.sh index 8b67052..dc51d78 100755 --- a/install.sh +++ b/install.sh @@ -21,8 +21,10 @@ if [ -d "$1/libusb-1.0.26" ];then rm -rf $1/libusb-1.0.26 fi tar jxvf $2/libusb-1.0.26.tar.bz2 -C $1 +cp $2/hide-log-dev-id.patch $1/ cp $2/fix-init-fail.patch $1/ cd $1/libusb-1.0.26/ +patch -p1 < ../hide-log-dev-id.patch patch -p1 < ../fix-init-fail.patch if [ "$(uname)" != "Darwin" ];then flock -u 100 -- Gitee