An adaptation method and apparatus

By prioritizing writing to the system buffer in a cross-process environment and switching to the system buffer as the source of response data, the problem of data write-back anomalies is solved, and the compatibility and reliability of the scanner driver are achieved. It is applicable to Universal Serial Bus scanners and other cross-process peripheral drivers.

CN123068147APending Publication Date: 2026-11-10联想开天科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611223415.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-12
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

In a cross-process environment, data write-back operations between the data source and the driver process are prone to errors due to inaccessible addresses, leading to interruptions in the scanning process. Existing technologies struggle to balance the compatibility and reliability of data write-back.

Method used

By prioritizing writing returned data to the system buffer and switching to the system buffer as the source of response data when writing to the user buffer fails, a compatible and reliable data write-back mechanism is built to ensure that data is returned completely.

Benefits of technology

In a cross-process architecture, the system robustness of the scanner driver is improved, scanning process interruption is avoided, and the behavior of vendor drivers that rely on direct access to user pointers is compatible. It is suitable for Universal Serial Bus scanners and other cross-process peripheral driver scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123068147A_ABST
    Figure CN123068147A_ABST
Patent Text Reader

Abstract

This application provides an adaptation method and apparatus, relating to the field of data processing technology. The method includes: acquiring return data from a scanner based on an input / output control request sent by a data source; writing the return data into a system buffer corresponding to the input / output control request; writing the return data into a user buffer indicated by a user data pointer in the input / output control request; in response to failure to successfully write the return data into the user buffer, using the return data in the system buffer as response data, generating a processing result for the input / output control request based on the response data, and returning the processing result to the data source; in response to successful writing of the return data into the system buffer, using the return data in the user buffer as response data, performing the step of: generating a processing result for the input / output control request based on the response data, and returning the processing result to the data source. This application can improve the reliability of data write-back in a cross-process environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to an adaptation method and apparatus. Background Technology

[0002] In operating systems, data sources and driver processes typically employ independent architectures. Input / output control requests initiated by the data source often involve cross-process data transfer, with the user data pointer passed from the data source pointing to the address space of the process residing in the data source. Since the driver process cannot directly access this address space, if it directly performs write operations on the user buffer, it is highly susceptible to exceptions due to address inaccessibility, leading to data write-back failure and ultimately interrupting the scanning process. Therefore, a scanner driver adaptation method that balances data write-back compatibility and reliability in a cross-process environment is urgently needed. Summary of the Invention

[0003] This application is made in view of at least one of the above-mentioned technical problems existing in the prior art, and the application can improve the reliability of data write-back in cross-process environment.

[0004] In a first aspect, embodiments of this application provide an adaptation method, including: Based on the input / output control requests sent from the data source, retrieve the returned data from the scanner; Write the returned data into the system buffer corresponding to the input / output control request; Based on the user data pointer in the input / output control request, write the returned data into the user buffer indicated by the user data pointer; In response to the failure to successfully write the returned data to the user buffer, the returned data in the system buffer is used as the response data, the processing result of the input / output control request is generated based on the response data, and the processing result is returned to the data source; In response to successfully writing the returned data into the system buffer, using the returned data in the user buffer as response data, the following steps are performed: generating a processing result for the input / output control request based on the response data, and returning the processing result to the data source.

[0005] Secondly, embodiments of this application provide an adapter, including: The acquisition module is configured to acquire returned data from the scanner based on input / output control requests sent from the data source; The writing module is configured to write the returned data into the system buffer corresponding to the input / output control request; and to write the returned data into the user buffer indicated by the user data pointer based on the user data pointer in the input / output control request. The processing module is configured to, in response to failure to successfully write the returned data to the user buffer, use the returned data in the system buffer as response data, generate a processing result for the input / output control request based on the response data, and return the processing result to the data source; and in response to successful writing of the returned data to the system buffer, use the returned data in the user buffer as response data, and perform the following steps: generate a processing result for the input / output control request based on the response data, and return the processing result to the data source.

[0006] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores an executable program, and the processor executes the executable program to perform the steps of the method as described in any of the preceding claims.

[0007] This application provides an adaptation method and apparatus that constructs a driver data write-back mechanism that balances compatibility and reliability in a cross-process architecture. On one hand, returned data is preferentially written to the system buffer, forming a safety fallback mechanism unaffected by the user address space. This ensures that even if writing to the user buffer fails, the data requested for input / output control can still be returned intact, preventing scan interruption. On the other hand, by retaining the attempt to write to the user buffer, it is compatible with vendor driver behavior that relies on direct access to user pointers. Furthermore, by handling parallel branches in response to write success or failure, abnormal situations such as inaccessible addresses are transformed into fault-tolerant switching transparent to the upper-layer data source, significantly improving the system robustness of the scanner driver. Moreover, this application is not only applicable to Universal Serial Bus scanners but can also flexibly adjust the step order or be applied to other cross-process peripheral driver scenarios according to actual needs, demonstrating strong adaptability and application prospects. Attached Figure Description

[0008] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0009] Figure 1 This is a flowchart illustrating an adaptation method provided in one embodiment of this application; Figure 2 This is a flowchart of an adaptation method provided in another embodiment of this application; Figure 3 This is a schematic diagram of an adapter device provided in one embodiment of this application; Figure 4 This is a schematic diagram of an electronic device provided in one embodiment of this application. Detailed Implementation

[0010] To enable those skilled in the art to better understand the technical solutions of the embodiments of this application, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0011] like Figure 1 As shown in the embodiments of this application, an adaptation method is provided, including: Step 101: Obtain the returned data from the scanner based on the input / output control request sent by the data source.

[0012] The execution entity of this method is the driver. In this embodiment, the data source refers to the native scanner driver data source running in the application process space, such as a driver module conforming to the TWAIN or WIA specification. The driver refers to a Universal Serial Bus scanner driver running in an independent process space, responsible for receiving and processing input / output control requests from the data source, and communicating with the physical scanner through the underlying transport library.

[0013] In this step, the driver receives input / output control requests, or IOCTL requests, initiated by the data source. These requests are generated by the data source based on application-layer instructions and typically include the request type, input parameters, and buffer information for receiving output data. Upon receiving the request, the driver parses its type and parameters, and sends corresponding control or data reading instructions to the physical scanner based on the request content. The driver then waits for the scanner to complete its operation and return the corresponding data.

[0014] Specifically, input / output control requests can have different function codes and parameter structures, such as those used to obtain device status, set scanning parameters, start the scanning process, or read scanned images. In this embodiment, the request is not limited to a specific type; the driver performs corresponding hardware access operations based on its specific content. Returned data may include, but is not limited to, image data, status data, calibration data, or error codes fed back by the scanner. The method of obtaining the returned data depends on the request type. For example, for a request to read image data, the driver initiates a batch transmission through the underlying transmission library; for a request to read device status, the driver initiates a control transmission or interrupts the transmission. The specific method of obtaining the returned data can be flexibly selected according to the actual application scenario and is not limited to a specific transmission protocol or hardware interface.

[0015] Step 102: Write the returned data into the system buffer corresponding to the input / output control request.

[0016] In this step, after the driver obtains the returned data from the scanner, it first writes the returned data to the system buffer. This system buffer is a kernel-mode buffer allocated by the operating system for the METHOD_BUFFERED mode during the dispatch phase of the input / output control request. It is part of the system kernel space and has security independent of the application process's address space, ensuring that the data is safely copied back to user space after the driver completes the request.

[0017] It should be noted that this embodiment uses the METHOD_BUFFERED mode for data marshalling. In this mode, the operating system automatically allocates a system buffer for each input / output control request and copies user-mode input data to the system buffer for the driver to read. The driver then fills the system buffer with the output data to be returned to the data source. This mechanism is particularly important in cross-process architectures because the access permissions to the system buffer are uniformly managed by the operating system, which can avoid the risk of direct memory access caused by address space isolation. In other embodiments, if the operating system does not support the METHOD_BUFFERED mode, or uses other data marshalling methods, such as METHOD_NEITHER or METHOD_OUT_DIRECT, the method of obtaining the system buffer can be adjusted accordingly. However, the core of this step is to prioritize storing the returned data in a safe, stable, and cross-process accessible storage area as the data base for subsequent processes.

[0018] Step 103: Based on the user data pointer in the input / output control request, write the return data to the user buffer indicated by the user data pointer. If the return data is not successfully written to the user buffer, use the return data in the system buffer as the response data and execute step 104. Otherwise, use the return data in the user buffer as the response data and execute step 104.

[0019] In this step, the driver reads the user data pointer attached to the input / output control request. This pointer is specified by the data source when initiating the request and points to a user buffer in the data source process space. The driver then attempts to write the retrieved return data to this user buffer.

[0020] It's important to note that this step is a secondary write-back path, designed to be compatible with native driver behaviors that rely on the driver directly writing data back to the user buffer. In the Windows native driver model, the driver and application process share the same kernel address space, and writing data directly to the buffer pointed to by the user pointer is standard practice. However, in a cross-process architecture, because the application process and driver process are independent and their address spaces are isolated, the driver process cannot directly access the application process's user buffer. Therefore, the actual execution of this step is uncertain: if the user buffer is accessible in the driver process, for example, through memory mapping or shared memory mechanisms, it can be written to directly; if the user buffer is inaccessible, a page fault or access violation exception will occur.

[0021] If the driver process and the application process communicate through a shared memory region, or use other cross-process data transfer protocols, the accessibility determination mechanism for the user buffer may differ. The driver does not require this step to succeed, but rather determines the access result during the execution of this step to inform subsequent decisions about the source of the final response data.

[0022] Step 104: Generate the processing result of the input / output control request based on the response data, and return the processing result to the data source.

[0023] In this step, when an attempt to write data to the user buffer fails, for example, due to an exception such as a page fault, access violation, or invalid address caused by the user buffer address being inaccessible in the driver process, the driver abandons further writing to the user buffer and uses the returned data written to the system buffer as the final response data for the input / output control request.

[0024] Specifically, upon detecting a write failure to the user buffer, the driver does not interrupt the request processing flow but instead rolls back the data source to the system buffer. Since step 102 has already completely saved the returned data in the system buffer, the driver directly generates the processing result of the input / output control request based on the data in the system buffer. This result typically includes the response data itself, the response data length, and the request completion status code. Subsequently, the driver uses the I / O manager mechanism provided by the operating system to copy the response data from the system buffer back to the user-mode address space of the data source and returns a request processing completion signal to the data source. This process ensures that even in the event of an abnormal situation where a cross-process address is inaccessible, the input / output control request can still be completed normally, and the data source can obtain valid return data, thereby avoiding interruption of the scanning process or application crashes.

[0025] It should be noted that the driver can implement the condition for a failed write operation in several ways. For example, the driver can use a structured exception handling mechanism to protect the write operation, and determine the write operation as unsuccessful when a page fault is caught; alternatively, it can perform a pre-validation check on the pointer to determine the feasibility of the write operation. The differences between the different judgment methods lie only in the implementation details, and their core logic is to actively switch the data source to the system buffer when the write operation fails.

[0026] When an attempt to write data to the user buffer is successful, meaning the user pointer is accessible in the driver process and no exception occurred during the data writing process, the driver uses the returned data in the user buffer as the final response data for this input / output control request.

[0027] Since the user buffer itself resides in the user-space address space of the data source, the driver does not need to perform an additional kernel-to-user-space data copying step when generating the processing result. The driver directly generates the processing result based on the valid data already written to the user buffer and returns a completion signal to the data source. This approach ensures successful data write-back while reducing the number of data copies, thus improving the overall data transmission efficiency of the system.

[0028] It's important to understand that regardless of whether the write to the user buffer succeeds or fails, the input / output control request will ultimately be processed normally and a result will be returned. When the write succeeds, the data in the system buffer exists as a backup, but the actual response data comes from the user buffer; when the write fails, the data in the system buffer is used as a backup and becomes the actual source of the response data. The two branches ultimately have the same execution effect, but their internal data paths are different. This branching logic ensures the reliability and compatibility of this method in cross-process environments.

[0029] This application's embodiments construct a driver data write-back mechanism that balances compatibility and reliability within a cross-process architecture. On one hand, returned data is preferentially written to the system buffer, forming a safety fallback mechanism unaffected by the user address space. This ensures that even if writing to the user buffer fails, the input / output control request data can still be returned intact, preventing scan interruption. On the other hand, by retaining the attempt to write to the user buffer, it is compatible with vendor driver behavior that relies on direct access to user pointers. Furthermore, by handling parallel branches in response to write success or failure, abnormal situations such as inaccessible addresses are transformed into fault-tolerant switching transparent to the upper-layer data source, significantly improving the system robustness of the scanner driver. Moreover, this application is not only applicable to Universal Serial Bus scanners but can also flexibly adjust the step order or be applied to other cross-process peripheral driver scenarios according to actual needs, demonstrating strong adaptability and application prospects.

[0030] In one embodiment of this application, such as Figure 2As shown, before obtaining the returned data from the scanner based on the input / output control request sent from the data source, the method further includes: Step 201: During the scanner driver startup phase, write device instance information to the registry enumeration key.

[0031] In this step, the driver proactively writes the current scanner's device instance information to the operating system's registry enumeration keys during its startup phase. These registry enumeration keys are crucial locations used by the system to record information about installed devices, typically including device enumeration keys such as Enum\USB\VID_xxxx&PID_yyyy, and service enumeration keys such as Services\usbscan\Enum. Based on the physical scanner's device descriptor, the driver writes information such as device description, hardware identifier, compatibility identifier, interface number, endpoint configuration, and instance path into the corresponding key values, enabling the registry to accurately reflect the device's connection status and attributes.

[0032] It should be noted that the specific path and name of the registry enumeration key may vary depending on the operating system version, manufacturer implementation, or driver installation and configuration. The core of this step is that the driver actively establishes a device record for the scanner in the registry after startup, so that subsequent data sources can query the registry to find the device's existence. If the operating system provides different device enumeration mechanisms, the driver can also complete device information registration in a corresponding way, without strictly relying on a specific registry key path.

[0033] Step 202: In response to the input / output control request being the first request received after the driver starts, modify the device instance information to trigger a registry change notification.

[0034] The registry change notification is used to release threads in the data source that are waiting for registry changes from their waiting state, so that the data source can communicate with the scanner.

[0035] In this step, after receiving an input / output control request from the data source, the driver first determines whether this request is the first request received since the driver started. If so, the driver proactively modifies the device instance information already written to the registry enumeration key, thereby creating a physical change event at the registry level. This key modification action is monitored by the operating system's registry management module, which immediately sends a registry change notification to all threads that have called the RegNotifyChangeKeyValue function and are waiting for the registry key to change.

[0036] The purpose of this modification is not to update device information, but to artificially trigger a registry change notification to wake up data source threads that may be stuck in a waiting state due to missing the first notification. In practical applications, data sources typically call the RegNotifyChangeKeyValue function during the initialization phase to listen for changes in registry enumeration keys, hoping to receive timely notifications when a device is connected. However, due to the uncertain timing of device registration and data source initialization in Wine's cross-process environment, the data source may miss the registry change notification generated by the driver writing device instance information before its listening action is executed, causing the data source to wait indefinitely. This step, by actively modifying the notification during the first request, is equivalent to artificially generating a new notification when the data source initiates a communication request, thereby compensating for this timing misalignment.

[0037] Registry change notifications can also be triggered by modifying other device-related registry keys or by directly sending a notification signal through the operating system's registry notification API, without being limited to modifying the device instance information itself. Any method that can release the waiting data source thread from its waiting state can be used as an alternative implementation for this step.

[0038] In this step, the triggered registry change notification is sent by the operating system's registry management module to all threads waiting for the registry enumeration key to change. Specifically, threads in the data source that were suspended due to the call to the RegNotifyChangeKeyValue function will immediately return from the function call upon receiving this notification, thus ending their blocked state. After the thread returns, the data source will continue to execute according to the predetermined initialization process, including obtaining the scanner's device instance path through registry queries, obtaining the device handle by calling the open device operation, negotiating parameters, and initializing scan communication, ultimately successfully establishing a communication link with the scanner.

[0039] Releasing the wait state refers to transitioning the data source thread from a blocked / suspended state to a runnable state, allowing the thread to continue executing subsequent code. After releasing the wait, the specific subsequent operations performed by the data source depend on its own driver implementation logic; this application does not limit its specific business steps. For example, data sources from different vendors may execute different initialization processes after releasing the wait. If the data source does not wait through the RegNotifyChangeKeyValue function but uses other mechanisms to detect device changes, the triggering method for this step can also be adjusted accordingly.

[0040] This application's embodiments construct a complete driver adaptation chain from device discovery to data write-back within a cross-process architecture. Specifically, during the driver startup phase, registry device information is pre-established to provide a foundation for subsequent data source device queries; the first request triggers a registry key value modification, artificially generating a registry change notification, effectively compensating for data source initialization deadlocks caused by timing misalignments; this notification wakes up waiting threads, enabling the data source to smoothly enter the communication establishment phase and ultimately complete the connection with the scanner. The combined effect of these steps ensures that even in a Wine cross-process environment, the scanner driver can achieve reliable adaptation throughout the entire process from device discovery to data write-back, significantly improving system stability and compatibility, while requiring no modifications to the vendor's native data source.

[0041] In one embodiment of this application, writing device instance information to a registry enumeration key includes: Based on the scanner's device descriptor, generate registry device enumeration keys and registry service enumeration keys; Write at least one of the scanner's device description, hardware identifier, compatibility identifier, interface number, endpoint, and instance path to the registry device enumeration key; Write at least one of the following to the registry service enumeration key: the number of scanner devices, instance index, and service association.

[0042] After obtaining the scanner's device descriptor (which typically contains hardware-specific information such as device identifier, product identifier, interface type, and endpoint configuration), the driver first generates two independent enumeration keys in the registry based on this information. The first is a registry device enumeration key, used to record the specific location and configuration information of a single physical device in the system enumeration tree, and its path usually follows the format Enum\USB\VID_xxxx&PID_yyyy; the second is a registry service enumeration key, used to record device group information associated with this type of driver service, and its path is usually Services\usbscan\Enum.

[0043] It should be noted that the specific path and name of the registry enumeration key are not fixed. The specific path may differ depending on the operating system version, driver installation configuration, or hardware abstraction layer implementation. For example, in some implementations, the device enumeration key may be located under Enum\USBSTOR or other bus enumeration branches.

[0044] After generating the device enumeration key in the registry, the driver writes various physical attribute information of the scanner into that key. The specific content written may include: device description, such as the manufacturer-defined device name; hardware identifiers, such as device identification code and product identification code; compatibility identifiers, such as other drivers or protocols that the device is compatible with; interface number, indicating the Universal Serial Bus interface number used by the device; endpoint configuration information, such as the address and transmission method of control endpoints, bulk endpoints, and interrupt endpoints; and the device instance path, which is the unique instance identifier of the device in the system enumeration tree.

[0045] Because different scanner devices have different hardware configurations, not all of the above fields need to be written during the actual writing process. For example, if a scanner does not have an interrupt transmission endpoint configured, the driver can skip writing the endpoint information; if the scanner does not have a specific compatibility identifier, the field can be empty. The driver can flexibly choose to write one or more of these fields based on the actual device descriptor content carried by the scanner. If the data source obtains device attributes through other mechanisms without relying on the registry device enumeration key, the types and number of fields written in this step can also be adjusted accordingly.

[0046] After generating the registry service enumeration key, the driver writes statistical and management information related to that type of driver service into the key. The specific content written may include: the number of devices, recording the total number of scanners of that type connected to the current system; the instance index, a unique incrementing number assigned to the current scanner to distinguish different device instances of the same type; and the service association, indicating the specific driver service name or service identifier bound to the current scanner.

[0047] It's important to note that the primary function of the registry service enumeration key is to allow the operating system and peripheral manager to track the total number of devices managed by this type of driver and to provide logical identifiers for device enumeration. During the actual writing process, the driver can flexibly choose to write one or more fields. For example, if the driver only cares about the number of devices and doesn't need to distinguish between different instances, it can only write the number of devices; if the driver needs to assign a separate management handle to each scanner, it needs to write the instance index as well. If the operating system provides a different device statistics and identification mechanism than the registry, the driver can also use the corresponding alternative.

[0048] This application specifies that the modification operation applies to the device count and / or instance index in the registry service enumeration key, and / or the instance path in the registry device enumeration key. This limitation ensures that when the first input / output control request arrives, the driver can trigger a registry change notification by modifying explicit and controlled registry key values ​​while maintaining the semantic stability of the device instance. Since the device count and instance index represent the device count at the service level, and the instance path represents the unique identifier of a single device, the driver can flexibly choose to modify any one or more of them, which will generate a valid registry change event, thereby avoiding the risk of notification failure due to ambiguous or invalid modification actions.

[0049] In one embodiment of this application, modifying device instance information includes: Modify the number of devices and / or instance index in the registry service enumeration key; and / or modify the instance path in the registry device enumeration key.

[0050] When the driver determines that the current input / output control request is the first request, it can choose to modify fields in the registry service enumeration key. Specific fields to modify include the number of devices and / or the instance index.

[0051] Modifying the number of devices and modifying the instance index produce equivalent notification effects, but their underlying implementations differ slightly. Modifying the number of devices is typically interpreted by the operating system's registry monitoring mechanism as a change in the service-level device list, triggering a global re-enumeration. Modifying the instance index, on the other hand, is equivalent to reassigning a logical identity to the current device, also triggering a registry change notification. Drivers can choose to modify the number of devices, the instance index alone, or both simultaneously, depending on their implementation needs.

[0052] When the driver determines that the current input / output control request is the first request, it can also choose to modify the registry device enumeration key, specifically the instance path.

[0053] The instance path is a key identifier representing the identity of a single scanner hardware device. Modifying the instance path will immediately be recognized by the operating system's registry monitoring process as a change in device information, triggering a registry change notification. Since the actual content of this path does not affect the driver's subsequent access logic to the device, this modification is a safe and effective method. If the instance path in the device enumeration key does not allow direct writing, the driver can also trigger a notification by modifying other ancillary fields under the device enumeration key or the security access attributes of the modification key.

[0054] This application's embodiments enable the driver to reliably make a physical change to the registry in a highly operable manner upon the arrival of the first input / output control request. This solution not only avoids the risk of registry change notifications failing to trigger due to unclear modification targets, but also gives the driver flexible adaptability across different operating system environments and data source implementations. Regardless of whether the data source only listens to service enumeration keys or only listens to device enumeration keys, the driver can ensure successful notification delivery through precisely matched key value modifications.

[0055] In one embodiment of this application, a failure to write to the user buffer includes: failure due to a page fault; The method also includes: capturing page errors, terminating writing to the user buffer, and performing the following steps: using the returned data in the system buffer as response data, generating the processing result of the input / output control request based on the response data, and returning the processing result to the data source.

[0056] When a driver attempts to write data to the user buffer pointed to by the user data pointer, the write operation may fail for various reasons. Among these, the most common and representative exception type is a page fault. A page fault is a hardware exception that occurs when a driver process attempts to access a memory page that is not currently in physical memory or is not mapped to the current process's address space. Specifically, in a cross-process architecture, the user data pointer points to the address space of the data source process, while the driver process and the data source process have their own independent page tables. Therefore, when the driver process reads or writes to the address pointed to by this pointer, if the address is invalid in the driver process's page table, the CPU will immediately trigger a page fault exception, and the operating system will pass the exception to the driver program.

[0057] It should be noted that page faults are not the only possible cause. In actual implementations, failures may also include: a null user pointer, the address range pointed to by the user pointer exceeding the valid limit of the user buffer, the user buffer being locked or marked as unwritable in the data source process, or the memory pages of the user buffer having been swapped to disk and unable to be loaded immediately. However, in this embodiment, page faults are described as a typical triggering condition for failure, and the applicability of other exception types is not excluded. If the driver catches other types of exceptions, it can also switch to the system buffer according to the logic of this embodiment.

[0058] Upon detecting a page fault or other exception, the driver immediately intercepts the exception signal through the exception handling mechanism and performs the following physical actions: Terminate write operation: The driver immediately stops writing to the user buffer and does not perform any further memory operations on the buffer to prevent more serious system crashes or data corruption caused by illegal access.

[0059] Switching data source: The driver uses the return data already written to the system buffer as the final response data. Since the system buffer is legitimate kernel-mode memory allocated by the operating system during the request dispatch phase and has fully stored the return data, this data is safe and valid.

[0060] Generate and return processing results: The driver generates a complete processing result based on the response data in the system buffer, combined with information such as the completion status of the current input / output control request, transmission length, and error code, and returns the result to the data source through the system I / O manager.

[0061] Specific implementations of exception handling can include structured exception handling, such as the __TRY / __EXCEPT blocks in Windows driver development; signal-based exception handling, such as sigaction signal capture in Unix / Linux environments; or hardware trap mechanisms based on memory access protection, such as predicting access permissions in advance through mprotect or virtual memory protection mechanisms. Different implementation methods differ in their underlying mechanisms, but their purpose is to intercept exceptions promptly when illegal memory access occurs and switch the execution flow to pre-defined fault-tolerant logic. This embodiment does not limit specific exception handling techniques; any alternative implementation method that allows the driver to detect page faults promptly and terminate writing to the user buffer is acceptable. Furthermore, after catching an exception, the driver can also perform format or integrity verification on the data in the system buffer before switching to the system buffer to improve the reliability of the returned data.

[0062] This application, starting from the operating system's memory management mechanism, accurately defines the typical obstacles that drivers may encounter when accessing the data source address space, avoiding misunderstandings caused by vague descriptions of the reasons for failure. Secondly, by executing consecutive actions of capturing page faults and terminating writes to the user buffer when a page fault occurs, this application can immediately interrupt erroneous operations upon detecting illegal memory access, preventing the continued execution of subsequent invalid memory instructions, thereby preventing driver process crashes or abnormal operating system states due to access violations. This capture and termination action does not interrupt the input / output control request processing flow, but directly connects to a fault-tolerant path that uses the return data in the system buffer as the response data. Since the data in the system buffer is independently saved before the driver attempts to write to the user buffer, this switching action is safe and reliable, ensuring that the data source obtains valid processing results regardless of whether the underlying access is successful, significantly reducing the risk of driver anomalies in cross-process architectures.

[0063] In one embodiment of this application, in response to the input / output control request being the first request received after the driver starts, the method further includes: determining whether to set a one-time trigger flag; in response to not setting a one-time trigger flag, performing the step of: modifying device instance information; After modifying the device instance information, the method also includes setting a one-time trigger flag.

[0064] After confirming that the received input / output control request is the first request received since driver startup, the driver does not immediately perform registry modification operations. Instead, it first checks the status of an internally maintained one-time trigger flag. This flag is a boolean variable or integer counter used to record whether the modification operation for the first request has already been performed. Its initial state is unset, such as a value of 0 or False. The driver checks the status of this flag every time it receives an input / output control request. If the flag is unset, it means that this is the first time the trigger condition has been met, and the driver can perform the operation to modify the device instance information. If the flag is set, it means that the modification operation has already been performed, and the driver will skip the modification step and directly enter the subsequent normal processing flow.

[0065] The specific storage location of this one-time trigger flag can be flexibly chosen based on the actual implementation. For example, the flag can be stored in the driver process's local memory as a state variable within the driver; it can also be stored in the registry to retain its state after a driver or system restart; or its existence can be characterized by a named event object or a system synchronization object such as a mutex. In practice, if the driver fails to check the flag again upon receiving an I / O control request after the initial execution, the same device instance may be triggered multiple times, leading to system errors or unstable device enumeration. Therefore, this step requires checking the flag every time an I / O control request is received to ensure that the modification action is executed only once.

[0066] After successfully modifying the device instance information, the driver immediately sets the one-time trigger flag to "set" to clearly indicate that the modification is complete. Subsequently, when the driver receives any subsequent input / output control requests, it will skip the modification step because the flag is already set, thus completely avoiding repeated triggering of registry change notifications.

[0067] The action of setting a flag must maintain a strict logical sequence with the action of modifying device instance information; that is, the modification action must be completed before setting the flag to ensure that the change in the flag state is not mistaken for an independent trigger action. After setting the flag, the driver records the state that the modification action has been successfully executed. If a driver restart or system abnormality occurs subsequently, this flag can be used in conjunction with persistent storage to achieve state retention across restarts, so that the driver can still recognize that the device has processed the first request after restarting.

[0068] This application effectively solves the device enumeration jitter problem caused by repeated triggering of registry change notifications. The mechanism introduces a status flag to limit the modification action of the first request to only one execution. This allows the driver to stably enter the normal processing flow after completing the initial timing compensation, without being repeatedly interrupted by subsequent requests. This not only significantly improves the stability of the system during long-term operation but also avoids data source loop initialization or device state inconsistencies caused by frequent registry changes.

[0069] In one embodiment of this application, obtaining returned data from the scanner based on an input / output control request sent by a data source includes: In response to input / output control requests sent by the data source, the scanner information is retrieved from a pre-configured configuration file; Based on the information from the scanner and input / output control requests, retrieve the returned data from the scanner.

[0070] Upon receiving an input / output control request from the data source, the driver does not immediately send hardware commands to the scanner. Instead, it first reads a pre-configured configuration file to retrieve relevant information about the currently connected scanner. This configuration file is typically stored in a predetermined path in the system file system, such as / etc / wine-scanner.conf or another user-specified location. The configuration file records key information such as the scanner's device identifier, product identifier, feature flags, support status, and device description. The driver then searches the configuration file for a matching record based on the scanner's actual device identifier and product identifier.

[0071] The configuration file format is not limited to a specific text format. The driver can read and parse the file using the corresponding parser to obtain the configuration entries matching the current scanner. Furthermore, the storage location of the configuration file can be flexibly adjusted according to actual deployment needs. For example, it can be placed in the ` / etc / ` directory on Linux systems, and under a specified key value in the registry on Windows systems. In practical applications, if the system administrator needs to adapt multiple scanners simultaneously, the configuration file can also be stored using a centralized database server. In this case, the driver only needs to retrieve the configuration information via network query based on the IP address or Uniform Resource Locator (URL), instead of relying on local files.

[0072] Furthermore, before reading the configuration file, the driver can first check the file's last modification time or whether the file has been modified at all, to avoid rereading the file with every IOCTL request. If the configuration file has not been modified, the driver can directly use the previously read memory-cached data, thereby improving system response speed and throughput. In another implementation, the driver can also adopt a lazy loading strategy, that is, only reading the file once during the startup phase or the first query of configuration information and caching it in local memory. Subsequent requests directly use the memory-cached data, and only reloading it when the file is modified or the driver restarts. This strategy can effectively reduce disk I / O operations and improve driver performance in high-concurrency scenarios.

[0073] After obtaining the configuration information corresponding to the current scanner, such as feature bit flags and transmission parameter correction flags, the driver performs the actual hardware transmission operation based on this information and the content of the original input / output control request, and obtains the returned data from the scanner.

[0074] Specifically, the characteristic flags in the configuration information can indicate what special processing the driver needs to perform when sending control commands or executing data transmission. For example, if the characteristic flag indicates that the scanner needs calibration data correction, the driver will perform specific correction operations on the data after receiving the returned data; if the flag indicates that transmission parameter correction is needed, the driver will adjust the timeout or endpoint configuration of batch transmission; if the flag indicates that device discovery file generation is needed, the driver will create the corresponding device file in the predetermined path. These correction and adjustment actions are all automatically completed by the driver according to the instructions in the configuration file before or after the actual sending of hardware commands, without the need for additional intervention from the upper-layer data source.

[0075] The driver can also determine whether to proactively send additional calibration or initialization commands to the scanner based on the device descriptor and product identifier in the configuration information. For example, for certain scanner models, the configuration information may instruct the driver to send a white balance calibration command before each scan; otherwise, the returned image data will have color cast. The driver will automatically insert this calibration command based on the configuration information, thereby ensuring the quality of the returned image data. This configuration-based automatic calibration mechanism allows the driver to quickly adapt to different scanner models without modifying the source code, improving the scalability and maintainability of the driver adaptation solution.

[0076] It should be noted that the specific method, timing, and actions by which the driver executes specific processing logic based on configuration information can be flexibly adjusted according to actual needs. For example, correction operations can be performed before or after data is written to the system buffer; adjustments to transmission parameters can be made before sending control commands or dynamically during data transmission.

[0077] This application embodiment, in response to input / output control requests, first reads scanner information from a configuration file and then adjusts the method of obtaining returned data based on this information. This allows the driver to flexibly adapt to hardware differences of different brands or models of scanners without modifying the core code. The characteristic bit flags recorded in the configuration file can instruct the driver to perform specific actions such as parameter adjustment, data correction, and file generation for specific devices. This avoids piling up numerous hardware condition branches specific to certain devices in the driver code, transforming support for new scanner models from code modification to configuration updates, significantly reducing adaptation costs and maintenance difficulty.

[0078] In one embodiment of this application, obtaining returned data from the scanner based on an input / output control request sent by a data source includes: In response to input / output control requests, the underlying transmission execution layer is controlled to perform control transmissions, bulk transmissions, or interrupt transmissions to obtain returned data from the scanner.

[0079] After receiving an input / output control request from the data source, the driver selects the appropriate transmission method based on the request type and content, and controls the underlying transmission execution layer to initiate the actual hardware data exchange with the scanner. The underlying transmission execution layer is the software layer in the driver adapter stack responsible for communicating with the physical hardware. It encapsulates the details of the underlying hardware interface and provides a unified transmission call interface to the upper-layer driver. The driver does not directly manipulate hardware registers or memory-mapped addresses; instead, it initiates transmission requests by calling the interfaces provided by the underlying transmission execution layer.

[0080] Specifically, the underlying transport execution layer can perform one of the following three transport types to obtain returned data from the scanner: Control transfers: Primarily used to send commands or read small amounts of configuration data. For example, when the input / output control request involves setting scan parameters, reading device status, or obtaining calibration data, the underlying control transfer execution layer executes the control transfer. Control transfers are deterministic and reliable, but their data transmission volume is relatively small, typically used for device initialization and parameter configuration.

[0081] Batch transfer: Primarily used for transferring large amounts of data, such as image data generated by a scanner. When the input / output control request is to start scanning and acquire images, the driver controls the underlying transfer execution layer to perform batch transfer. Batch transfer can efficiently transmit large blocks of data and ensure data integrity through error retransmission mechanisms, making it suitable for image acquisition scenarios with high requirements for transmission reliability.

[0082] Interrupted transmission: Primarily used to receive sudden status information or event notifications proactively reported by the scanner. For example, when the scanner completes a scan, runs out of paper, or experiences an anomaly, it will send status change information to the host via interrupt transmission. Upon receiving such a request, the driver controls the underlying transmission execution layer to perform interrupt transmission to obtain this status data.

[0083] It should be noted that the three transmission types described above are typical transmission modes defined in the USB protocol standard, and not all possible transmission methods in this application. In other embodiments, if the scanner uses different communication protocols, the underlying transmission execution layer can adjust the transmission type accordingly.

[0084] Furthermore, when selecting the transfer type, the driver can automatically determine it based on the IOCTL code or function identifier of the input / output control request. For example, when the IOCTL code is IOCTL_USBSCAN_GET_IMAGE, the driver selects bulk transfer; when the IOCTL code is IOCTL_USBSCAN_GET_STATUS, the driver selects control transfer. The driver can also determine the transfer type by analyzing the data structure carried in the request.

[0085] If the underlying transport execution layer supports multiple transport methods simultaneously, the driver can even employ a combined transport strategy for the same request. For example, for a request that needs to acquire both image data and status data simultaneously, the driver can first acquire the status data through control transport, then acquire the image data through batch transport, and finally merge the two and return them to the data source.

[0086] This application's embodiments separate control logic from physical transmission, allowing the driver to focus on request parsing, data write-back, and exception handling, while delegating specific hardware interaction details to the underlying transmission execution layer, thereby reducing the complexity of driver development. Furthermore, by introducing three standardized transmission types—control transmission, batch transmission, and interrupt transmission—this application can cover the communication needs of scanners in different scenarios such as status queries, image acquisition, and event notifications, enabling the driver to select the appropriate transmission method when faced with different types of input / output control requests.

[0087] This embodiment uses a scanner, a Linux desktop system, a Wine-compatible runtime environment, a Windows scanning application, and a data source as examples to explain in detail the specific implementation process of the adaptation method.

[0088] After the scanner is plugged into the Linux desktop system, the operating system recognizes the hardware device through the device permission management mechanism and grants the user or Wine process access permissions to the device according to the pre-configured device permission rules. The underlying transport execution layer successfully enumerates the scanner's device identifier, product identifier, interface number, endpoint, and device descriptor.

[0089] When the Wine-compatible runtime environment starts, the driver information file pre-installed in the deployment module associates the target physical scanner device with the driver. During the startup phase, the driver creates a functional device object and writes device instance information to the operating system's registry enumeration keys. Specifically, this includes generating registry device enumeration keys and registry service enumeration keys, and writing information such as device description, hardware identifier, compatibility identifier, interface number, endpoint, instance path, counter value, and instance index to form a registry mapping view that can be queried by upper-layer data sources.

[0090] When a Windows scanning application calls the scanning interface to select a data source, the dynamic link library in the scanning application process loads the upper-level scanning data source served by the driver.

[0091] After the data source starts, it first reads the device instance information from the registry service enumeration key by querying the registry and attempts to open the scanner device handle. In a real cross-process scenario, the data source may call the registry key change notification function and enter a suspended waiting state before initiating the first input / output control request to listen for changes in the registry enumeration key. If the data source's waiting action occurs after the application driver has written the device instance information, the waiting thread will miss the registry change notification, leading to an initialization deadlock.

[0092] At this point, after the driver in this application starts, it receives the first input / output control request from the application layer or system enumeration mechanism. Upon detecting this request, the driver first checks whether a one-time trigger flag has been set. If not, it then performs an action to modify the device instance information, such as modifying the counter value in the service enumeration key or the instance path in the device enumeration key, to trigger the operating system's registry management module to generate a new registry change notification. This notification is sent to the thread in the data source that is in a waiting state, releasing it from the waiting state in the registry key change notification function. After the thread is unblocked, it continues to complete the initialization of device opening, parameter negotiation, and scanning communication. Simultaneously, after the modification operation is successful, the driver immediately sets the one-time trigger flag to ensure that subsequent input / output control requests do not repeatedly trigger this notification, avoiding device enumeration jitter.

[0093] Once the scanner initializes successfully and enters the scanning parameter setting and image acquisition phase, the data source continuously sends various input / output control requests to the driver. After parsing the type of the input / output control request and the user data pointer and input / output block structure carried in the request, the driver executes the corresponding hardware operation according to the request type.

[0094] For instruction data that needs to be sent to the scanner, the driver reads the instruction from the system buffer and controls the underlying transmission execution layer to send the instruction to the scanner.

[0095] For data that needs to be returned from the scanner, after responding to the instruction, the underlying transport execution layer submits the hardware-returned data to the driver. The driver first completely copies the returned data to the system buffer to ensure that the driver process has a secure, cross-process-accessible backup of the data. Then, the driver reads the user data pointer carried in the input / output control request and attempts to write the returned data to the user buffer indicated by the user data pointer. This attempt is wrapped in an exception handling mechanism.

[0096] When the user buffer is accessible within the current driver process, the returned data is successfully written to the user buffer. The driver generates a processing result based on the response data in the user buffer and the IOCTL completion status and returns it to the data source. When the user data pointer becomes inaccessible within the driver process or a page fault is triggered during access, the exception handling mechanism catches the exception. The driver immediately terminates writing to the user buffer and directly uses the returned data already saved in the system buffer as the response data to generate a processing result and return it to the data source. This process is completely transparent to the data source; the data source always receives a valid return result and will not crash or lose data due to inaccessible cross-process addresses.

[0097] During the driver's processing of input / output control requests, a configuration matching step is also performed. The driver calls a query interface to search for a matching item in the configuration file based on the current scanner's device identification code and product identification code.

[0098] If a match is found, the driver reads the corresponding feature flag and adjusts the processing logic accordingly. For example, if the feature flag requires the generation of a device discovery file, the driver creates the corresponding file in the predetermined path; if the flag requires the creation of a device directory structure, the driver creates the directory in the corresponding location in the file system; if the flag requires the correction of calibration data, the driver performs a preset data conversion or calibration correction operation on the returned raw data block after a specific input / output control request is completed. If no record is matched in the configuration file, the driver executes all input / output control requests according to the general processing path, without enabling any specific correction logic.

[0099] In practical applications, the method described in this embodiment can be deployed as a patch module for a Wine-compatible runtime environment, a standalone driver adaptation component, or as a pre-built compatibility layer for a specific Linux distribution. The configuration file records the device identification code, product identification code, and corresponding characteristic flags for various scanners. Updates can be uniformly distributed through the management terminal during subsequent maintenance to achieve rapid adaptation for newly added scanner models.

[0100] Because the upper-layer Windows scanning application and data source, as well as the lower-layer Linux USB access mechanism, retain their original interfaces during the adaptation process without any binary modifications, this application effectively reduces the adaptation cost of Windows scanning peripherals during the migration of domestically produced desktop systems. The method described in this embodiment is particularly suitable for government and enterprise offices, domestically produced desktop replacements, automated document scanning, and centralized management scenarios involving multiple scanner models.

[0101] like Figure 3 This application provides an adapter device, including: The acquisition module 301 is configured to acquire returned data from the scanner based on input / output control requests sent from the data source; The writing module 302 is configured to write the returned data to the system buffer corresponding to the input / output control request; and to write the returned data to the user buffer indicated by the user data pointer based on the user data pointer in the input / output control request. The processing module 303 is configured to, in response to failure to write the returned data to the user buffer, use the returned data in the system buffer as the response data, generate the processing result of the input / output control request based on the response data, and return the processing result to the data source; in response to success to write the returned data to the system buffer, use the returned data in the user buffer as the response data, and perform the following steps: generate the processing result of the input / output control request based on the response data, and return the processing result to the data source.

[0102] In one embodiment of this application, the acquisition module 301 is configured to write device instance information to the registry enumeration key during the scanner driver startup phase; in response to the input / output control request being the first request received after driver startup, modify the device instance information to trigger a registry change notification; wherein, the registry change notification is used to release the waiting state of threads in the data source waiting for registry changes, so as to enable the data source to communicate with the scanner.

[0103] In one embodiment of this application, the acquisition module 301 is configured to generate a registry device enumeration key and a registry service enumeration key based on the scanner's device descriptor; write at least one of the scanner's device description, hardware identifier, compatibility identifier, interface number, endpoint, and instance path into the registry device enumeration key; and write at least one of the scanner's device quantity, instance index, and service association into the registry service enumeration key.

[0104] In one embodiment of this application, the acquisition module 301 is configured to modify the number of devices and / or instance index in the registry service enumeration key; and / or modify the instance path in the registry device enumeration key.

[0105] In one embodiment of this application, a failure to write to the user buffer includes: failure due to a page fault; the processing module 303 is configured to capture the page fault, terminate the writing to the user buffer, and perform the following steps: using the returned data in the system buffer as response data, generating a processing result of the input / output control request based on the response data, and returning the processing result to the data source.

[0106] In one embodiment of this application, the acquisition module 301 is configured to determine whether to set a one-time trigger flag in response to the input / output control request being the first request received after the driver starts; and in response to the absence of a one-time trigger flag, to perform the following steps: modifying device instance information; and setting a one-time trigger flag after modifying the device instance information.

[0107] In one embodiment of this application, the acquisition module 301 is configured to acquire scanner information from a pre-set configuration file in response to an input / output control request sent by a data source; and to acquire returned data from the scanner based on the scanner information and the input / output control request.

[0108] In one embodiment of this application, the acquisition module 301 is configured to control the underlying transmission execution layer to perform control transmission, batch transmission or interrupt transmission in response to an input / output control request in order to acquire returned data from the scanner.

[0109] like Figure 4 As shown, this application provides an electronic device including a memory and a processor. The memory stores an executable program, and the processor executes the executable program to perform the steps of the method as described in any of the above embodiments.

[0110] This application provides a computer program product that, when executed by a processor, implements the methods of any of the above embodiments.

[0111] It should be understood that in the embodiments of this application, the processor may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0112] It should also be understood that the memory mentioned in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchlink DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).

[0113] It should be noted that when the processor is a general-purpose processor, DSP, ASIC, FPGA, or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, the memory (storage module) is integrated into the processor.

[0114] It should be noted that the memories described herein are intended to include, but are not limited to, these and any other suitable types of memories.

[0115] In addition to the data bus, this bus may also include a power bus, a control bus, and a status signal bus. However, for clarity, all buses are labeled "bus" in the diagram.

[0116] It should also be understood that the first, second, third, fourth and various numerical designations used herein are merely for descriptive convenience and are not intended to limit the scope of this application.

[0117] It should be understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.

[0118] In implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, detailed descriptions are omitted here.

[0119] In the various embodiments of this application, the order of the above-mentioned processes does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0120] Those skilled in the art will recognize that the various illustrative logical blocks (ILBs) and steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.

[0121] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0122] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0123] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0124] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.

[0125] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. An adaptation method, comprising: Based on the input / output control requests sent from the data source, retrieve the returned data from the scanner; Write the returned data into the system buffer corresponding to the input / output control request; Based on the user data pointer in the input / output control request, write the returned data into the user buffer indicated by the user data pointer; In response to the failure to successfully write the returned data to the user buffer, the returned data in the system buffer is used as the response data, the processing result of the input / output control request is generated based on the response data, and the processing result is returned to the data source; In response to successfully writing the returned data into the system buffer, using the returned data in the user buffer as response data, the following steps are performed: generating a processing result for the input / output control request based on the response data, and returning the processing result to the data source.

2. The method as described in claim 1, Before obtaining the returned data from the scanner, the input / output control request sent based on the data source also includes: During the driver startup phase of the scanner, device instance information is written to the registry enumeration key; In response to the input / output control request being the first request received after driver startup, the device instance information is modified to trigger a registry change notification; wherein, the registry change notification is used to release the waiting state of the thread in the data source waiting for registry changes, so that the data source can communicate with the scanner.

3. The method as described in claim 2, Write device instance information to the registry enumeration key, including: Based on the scanner's device descriptor, generate registry device enumeration keys and registry service enumeration keys; Write at least one of the scanner's device description, hardware identifier, compatibility identifier, interface number, endpoint, and instance path into the registry device enumeration key; Write at least one of the following into the registry service enumeration key: the number of devices, instance index, and service association of the scanner.

4. The method as described in claim 2 or 3, Modifying the device instance information includes: Modify the device count and / or instance index in the registry service enumeration key; And / or, modify the instance path in the registry device enumeration key.

5. The method as described in claim 1, The failure to write to the user buffer includes: Unsuccessful due to a page fault; The method further includes: capturing the page error, terminating writing to the user buffer, and performing the steps of: using the returned data in the system buffer as response data, generating a processing result of the input / output control request based on the response data, and returning the processing result to the data source.

6. The method as described in claim 2, In response to the input / output control request being the first request received after the driver starts, the method further includes: Determine whether a one-time trigger flag is set. If no one-time trigger flag is set, execute the following step: Modify the device instance information. After modifying the device instance information, the method further includes setting the one-time trigger flag.

7. The method as described in claim 1, Based on the input / output control requests sent from the data source, retrieve the returned data from the scanner, including: In response to an input / output control request sent by the data source, information about the scanner is obtained from a pre-configured configuration file; Based on the information from the scanner and the input / output control request, return data is obtained from the scanner.

8. The method as described in claim 1, Based on the input / output control requests sent from the data source, retrieve the returned data from the scanner, including: In response to the input / output control request, the underlying transmission execution layer is controlled to perform control transmission, batch transmission, or interrupt transmission to obtain the returned data from the scanner.

9. An adapter, comprising: The acquisition module is configured to acquire returned data from the scanner based on input / output control requests sent from the data source; The writing module is configured to write the returned data into the system buffer corresponding to the input / output control request; and to write the returned data into the user buffer indicated by the user data pointer based on the user data pointer in the input / output control request. The processing module is configured to, in response to the failure to successfully write the returned data to the user buffer, use the returned data in the system buffer as response data, generate a processing result for the input / output control request based on the response data, and return the processing result to the data source; In response to successfully writing the returned data into the system buffer, using the returned data in the user buffer as response data, the following steps are performed: generating a processing result for the input / output control request based on the response data, and returning the processing result to the data source.

10. An electronic device comprising a memory and a processor, the memory storing an executable program, the processor executing the executable program to perform the method as described in any one of claims 1-8.