Summary of the invention
The invention provides the unloading method of movable storage device and device, can when movable storage device owing to being taken by process cannot normal safe eject, the solution of effective unloading movable storage device is provided.
The invention provides following scheme:
Unload a method for movable storage device, comprising:
After movable storage device access being detected, create the administration portal of described movable storage device;
When being received the request unloading described movable storage device by described administration portal, if there is process taking described movable storage device, then taking the progress information of described movable storage device to the driver inquiry operating in inner nuclear layer;
In process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device.
Wherein, described in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device and comprises:
The progress information taking described movable storage device is prompted to user, so that user removes process to after the taking of described movable storage device according to information, again initiates the request of the described movable storage device of unloading;
When again receiving the request unloading described movable storage device, described movable storage device is unloaded.
Wherein, described in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device and comprises:
Send message to the described process taking movable storage device, so as described in take movable storage device process remove taking described movable storage device;
When the described process taking movable storage device is removed after the taking of described movable storage device, described movable storage device is unloaded.
Wherein, describedly send message to the described process taking movable storage device, so as described in take movable storage device process remove taking of described movable storage device comprised:
Send the message of end process to the described process taking movable storage device, so as described in take movable storage device process remove taking described movable storage device.
Wherein, described in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device and comprises:
By described driver, process is taken the handle closedown of movable storage device, to remove process taking described movable storage device;
Described movable storage device, to after the taking of described movable storage device, unloads by releasing process.
Unload a device for movable storage device, comprising:
Administration portal providing unit, after movable storage device access being detected, creates the administration portal of described movable storage device;
Kernel query unit, for when being received the request unloading described movable storage device by described administration portal, if there is process taking described movable storage device, then taking the progress information of described movable storage device to the driver inquiry operating in inner nuclear layer;
Unloading unit, in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device.
Wherein, described unloading unit comprises:
Prompting subelement, for the progress information taking described movable storage device is prompted to user, so that user removes process to after the taking of described movable storage device according to information, initiates the request of the described movable storage device of unloading again;
First unloads subelements, for when again receiving the request unloading described movable storage device, is unloaded by described movable storage device.
Wherein, described unloading unit comprises:
Message sends subelement, for sending message to the described process taking movable storage device so that described in take movable storage device process remove taking described movable storage device;
Second unloads subelements, for when described in take movable storage device process remove after the taking of described movable storage device, described movable storage device is unloaded.
Wherein, described message transmission subelement comprises:
Terminate process message and send subelement, for sending the message of end process to the described process taking movable storage device so that described in take movable storage device process remove taking described movable storage device.
Wherein, described unloading unit comprises:
Handle closes subelement, for process being taken by described driver the handle closedown of movable storage device, to remove process taking described movable storage device;
3rd unloads subelements, for removing process to after the taking of described movable storage device, is unloaded by described movable storage device.
According to specific embodiment provided by the invention, the invention discloses following technique effect:
Pass through the present invention, when movable storage device owing to being taken by process cannot normal safe eject, can be inquired what take movable storage device by the driver operating in inner nuclear layer be which or which process, and then in releasing process to after the taking of movable storage device, unloading operation can be performed to movable storage device.Visible, movable storage device owing to being taken by process cannot normal safe eject time, do not need user to go manually to search the process taking movable storage device, just can complete the associative operation that take of releasing process to movable storage device.
Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, the every other embodiment that those of ordinary skill in the art obtain, all belongs to the scope of protection of the invention.
Described computer refers to the main frame that the operating system supporting access peripheral storage device is housed, the operating system that described main frame fills comprises Unix, Linux, Windows 98, Windows 2000, the subsequent operation system of Windows me, Window XP and Microsoft company, described main frame includes but not limited to that various personal desktop computer, notebook, handheld computer, minicom are with, data processing stations and hand-held personal data's treating apparatus.
Described movable storage device can comprise the data storage device such as flash disk, portable hard drive supporting plug and play on computers.
The interface of described movable storage device includes but not limited to USB, CF, SM, MMC, SD, MS, MD, X-D, pcmcia interface, can also comprise that IEEE1394, serial ATA, IDE/SCSI and HiperLAN, bluetooth, IrDA are infrared, HomeRF, IEEE802.11x, IEEE802.11a, 802.11b, 802.11d, 802.11.g, 802.15,802.16,802.3, RS232, RS485, USB_OTG, UWB, GPIO, UART interface, and one or more in GSM, GPRS, CDMA, 2.75G, 3G interface and parallel interface.In order to method of the present invention is clearly described, the movable storage device of the present embodiment for Flash as storage medium interface for USB is described.
See Fig. 1, the method for the ejection movable storage device that the embodiment of the present invention provides comprises the following steps:
S101: after movable storage device access being detected, create the administration portal of described movable storage device;
First it should be noted that,
In embodiments of the present invention, be equivalent to for user provides the client-side program of management movable storage device (for ease of describing, in the embodiment of the present invention, this client-side program is become " external equipment guard process "), user can manage by this program the movable storage device be inserted on computer.During specific implementation, client-side program in the embodiment of the present invention is after finding that there is movable storage device access, the administration portal of movable storage device can be provided (such as user, can be the icon etc. in desktop or toolbar), user can by this administration portal check movable storage device remaining space, open attribute etc., in addition, interfaces such as " safety eject movable storage device " can also be provided in Administration menu, when user needs unloading movable storage device, just can select to click this option.
Concrete, the administration portal of movable storage device can be provided for user on the table, such as,
Clisid represents object, HKEY_CLASSES_ROOT CLSID set up a CLSID key be used for manage movable storage device, sub-key DefaultIcon can be set up under it to arrange corresponding icon.
If allow CLISID show desktop icons, can set up a sub-key under NameSpace, title is exactly this CLSID.
Active user's desktop generate icon: HKEY_CURRENT_USER Software Microsoft Windows CurrentVersion Explorer Desktop NameSpace.
All user's desktops generate icon: HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows CurrentVersion Explorer Desktop NameSpace, thus provide the administration portal of movable storage device for user.
When specific implementation, when there being movable storage device to insert a computer, operating system can find this movable storage device at first, under traditional mode, operating system can be given tacit consent at the interface providing an ejection, and drive can be generated for movable storage device, in " my computer " interface, then provide the icon of this movable storage device.But in embodiments of the present invention, be the management realizing movable storage device by an external equipment guard process, therefore, can be different with traditional mode in the mechanism realized.Concrete, because operating system is after discovery movable storage device access, can broadcast a system message (WM_DEVICECHANGE), therefore, external equipment guard process can find the access of movable storage device by listening to this broadcast.Then the operation generating administration portal can just be performed.Specifically when generating administration portal, first the specifically movable storage device type accessed can also be judged, such as USB flash disk or portable hard drive etc., then for different movable storage device types, generate different icons (such as, USB flash disk is blue icons, portable hard drive is green icon etc.), that is, if user inserts a USB flash disk and a portable hard drive in computer simultaneously, after icon in right-click desktop or taskbar, the selection of USB flash disk and portable hard drive can be listed successively in the menu ejected, when needs unloading USB flash disk/portable hard drive, corresponding operation can be performed by the administration portal that the option of this USB flash disk/portable hard drive is corresponding.In addition, user is at needs.When user needs to be opened movable storage device by the execution of this administration portal or checked the operations such as movable storage device remaining space, external equipment guard process can also provide corresponding response.
Wherein, no matter be the type obtaining movable storage device, or obtain the information such as the remaining space of movable storage device, the file that comprises, external equipment guard process can realize the relevant information of inquiring about movable storage device by the api function of operating system.Such as, in Windows NT/2000/XP system, the access that application program can realize equipment by api function DeviceIoControl, comprises obtaining information, sends order, exchanges data etc.Utilize this interface function to send correct control code and data to the device driver of specifying, then analyze its response, just can reach corresponding object.During specific implementation, can know insertion USB flash disk by WMDeviceChange message, obtain movable storage device, obtain movable storage device drive corresponding in systems in which.Wherein, as wParam==DBT_DEVICEARRIVAL, lParam is a pointer pointing to DEV_BROADCAST_VOLUME structure, dbcv_unitmask in structure represents drive, then, can equipment be opened with drive, can taking equipment information with DeviceIoControl.Wherein, the function prototype of DeviceIoControl is BOOLDeviceIoControl (HANDLE hDevice, // equipment handle DWORD dwIoControlCode, // control code LPVOID lpInBuffer, // input data buffer zone pointer DWORD nInBufferSize, // input data buffer length LPVOID lpOutBuffer, // data output buffer district pointer DWORD nOutBufferSize, // data output buffer section length LPDWORD lpBytesReturned, // export data physical length element length LPOVERLAPPED lpOverlapped//overlap operation structured fingers).Wherein, equipment handle is used for identifying the equipment of accessing.
S102: when being received the request unloading described movable storage device by described administration portal, if there is process taking described movable storage device, then taking the progress information of described movable storage device to the driver inquiry operating in inner nuclear layer;
If user by external equipment guard process for mobile storage device management entrance that it provides unloads movable storage device (is also, user can select in management interface menu " safety ejects movable storage device "), then external equipment guard process can learn that user wants to unload movable storage device, now, the api function that external equipment guard process can be provided by system judges currently whether have process just taking this movable storage device.If had, then can take the progress information of movable storage device to the driver inquiry operating in inner nuclear layer, also, inquire about and have which or which process to take movable storage device.
It should be noted that, in the process operated the file or folder in movable storage device, operating system can carry out corresponding record, comprises and opens which process, which file of operation etc.By these information, just can know which the process taking movable storage device has.But these information are generally all recorded in the inner nuclear layer of operating system, and common upper level applications cannot directly be known.Therefore, in embodiments of the present invention, in order to obtain these information, can in advance for external equipment guard process configures a driver, this driver can start along with the startup of external equipment guard process, and operates in inner nuclear layer, can get the information that inner nuclear layer is preserved.It should be noted that, if the program under being in user model attempts to read a byte or attempt to perform assembly instruction from kernel spacing all can be terminated immediately, and driver be operate in system trust ring 0 (Ring0) environment under code, it has the access rights to any software and hardware of system.This means that Kernel Driver can access all system resource, all memory headrooms can be read, and be allowed to the privileged instruction performing CPU, e.g., read the currency etc. of CPU control register.Therefore, driver just because of kernel level has These characteristics, therefore, the external equipment guard process in the embodiment of the present invention just can be obtained by this driver and take relevant information with movable storage device, thus reaches the object of unloading movable storage device.
S103: in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device.
Due to the process taking movable storage device inquired by driver, therefore, just first can take releasing by this, then just normally can complete the unloading operation to movable storage device.Certainly, if find the current process not taking movable storage device, directly perform the unloading operation of movable storage device.Wherein, external equipment guard process, when performing unloading operation, can be realized by the api function of calling system equally, and the concrete api function used still can be DeviceIoControl.
Wherein, when removing process according to the progress information that inquires to the taking of movable storage device, multiple implementation can be had.Such as, wherein a kind of implementation can be, the progress information taking movable storage device is prompted to user and (such as can ejects dialog box, in dialog box, the information such as the title of process are presented to user with forms such as lists, or can also point out by ejecting the modes such as bubble), like this, user just can according to this prompting, find the current process taking movable storage device, then this process is terminated, again the administration portal provided by external equipment guard process again initiates the request of unloading movable storage device, external equipment guard process is after receiving new unload request, still first can judge currently whether have process to take movable storage device by Using API Function, if find without, the unloading that then can come movable storage device by the api function of calling system.If certainly find still have process to take movable storage device, then again can obtain the current progress information taken by driver, and be prompted to user, by that analogy.
Or, under another kind of implementation, outside equipment protection program know current taking the progress information of movable storage device after, can directly to take movable storage device process send message, make this process remove taking movable storage device.Wherein, specifically when sending message to the process taking movable storage device, directly can send the message terminating this process, like this, after process terminates, generally speaking, taking movable storage device will be discharged, and then by Using API Function, unload movable storage device.Certainly, if whole process is all terminated, then may influence the course the realization of middle normal function, therefore, in embodiments of the present invention, also can be directly the handle taking movable storage device in process is closed by driver, like this, process taking movable storage device will be removed, and the realization of other functions in can not influencing the course.Certainly, also may there is following situation in actual applications: user is in certain accounting process program of use, but there is a bug in process, to such an extent as to the handle of certain file stored in release busy movable storage device is not had when ends file process, for this situation, both the described process to accounting process program above can have been used to send the message of end process, this process is all terminated, process finishes, all relevant to this process are not just present in, and certainly also will discharge taking movable storage device.Or, also can directly by driver this should to be discharged but the handle not discharging, take always movable storage device due to the existence of bug is closed, like this because other process in process can't take movable storage device, the object that take of releasing process to movable storage device therefore also can be reached.
In addition, in actual applications, various ways can also be combined, such as, can know current take the progress information of movable storage device after, first can point out that user is current has taking movable storage device for which process by ejecting the mode such as dialog box, simultaneously, occupied file or folder can also be pointed out out, and the button continuing to use is provided in dialog box, and the button of " releasing takies and safety ejects ", user can select to continue to use, or select the latter, if have selected the latter, then can send message to the process taking movable storage device, corresponding process is made to remove taking movable storage device, then the api function of call operation system, movable storage device is unloaded.Certainly, after the offload is complete, the informations such as user " can extract movable storage device safely " can be pointed out equally.
Corresponding with the method for the unloading movable storage device that the embodiment of the present invention provides, the embodiment of the present invention additionally provides a kind of device unloading movable storage device, and see Fig. 2, this device can comprise:
Administration portal providing unit 201, after movable storage device access being detected, creates the administration portal of described movable storage device;
Kernel query unit 202, for when being received the request unloading described movable storage device by described administration portal, if there is process taking described movable storage device, then taking the progress information of described movable storage device to the driver inquiry operating in inner nuclear layer;
Unloading unit 203, in process of removing according to the described progress information inquired to after the taking of described movable storage device, unloading operation is performed to described movable storage device.
During specific implementation, unloading unit 203 specifically can comprise:
Prompting subelement, for the progress information taking described movable storage device is prompted to user, so that user removes process to after the taking of described movable storage device according to information, initiates the request of the described movable storage device of unloading again;
First unloads subelements, for when again receiving the request unloading described movable storage device, is unloaded by described movable storage device.
Or under another kind of implementation, unloading unit 203 also can comprise:
Message sends subelement, for sending message to the described process taking movable storage device so that described in take movable storage device process remove taking described movable storage device;
Second unloads subelements, for when described in take movable storage device process remove after the taking of described movable storage device, described movable storage device is unloaded.
Wherein, message transmission subelement specifically can comprise:
Terminate process message and send subelement, for sending the message of end process to the described process taking movable storage device so that described in take movable storage device process remove taking described movable storage device.
Or in order to avoid impacting the normal function of process, unloading unit 203 also can comprise:
Handle closes subelement, for process being taken by described driver the handle closedown of movable storage device, to remove process taking described movable storage device;
3rd unloads subelements, for removing process to after the taking of described movable storage device, is unloaded by described movable storage device.
By the said apparatus that the embodiment of the present invention provides, when movable storage device owing to being taken by process cannot normal safe eject, can be inquired what take movable storage device by the driver operating in inner nuclear layer be which or which process, and then in releasing process to after the taking of movable storage device, unloading operation can be performed to movable storage device.Visible, movable storage device owing to being taken by process cannot normal safe eject time, do not need user to go manually to search the process taking movable storage device, just can complete the associative operation that take of releasing process to movable storage device.
As seen through the above description of the embodiments, those skilled in the art can be well understood to the mode that the present invention can add required general hardware platform by software and realizes.Based on such understanding, technical scheme of the present invention can embody with the form of software product the part that prior art contributes in essence in other words, this computer software product can be stored in storage medium, as ROM/RAM, magnetic disc, CD etc., comprising some instructions in order to make a computer equipment (can be personal computer, server, or the network equipment etc.) perform the method described in some part of each embodiment of the present invention or embodiment.
Each embodiment in this description all adopts the mode of going forward one by one to describe, between each embodiment identical similar part mutually see, what each embodiment stressed is the difference with other embodiments.Especially, for device or system embodiment, because it is substantially similar to embodiment of the method, so describe fairly simple, relevant part illustrates see the part of embodiment of the method.Apparatus and system embodiment described above is only schematic, the wherein said unit illustrated as separating component or can may not be and physically separates, parts as unit display can be or may not be physical location, namely can be positioned at a place, or also can be distributed on multiple NE.Some or all of module wherein can be selected according to the actual needs to realize the object of the present embodiment scheme.Those of ordinary skill in the art, when not paying creative work, are namely appreciated that and implement.
Above to method and the device of unloading movable storage device provided by the present invention, be described in detail, apply specific case herein to set forth principle of the present invention and embodiment, the explanation of above embodiment just understands method of the present invention and core concept thereof for helping; Meanwhile, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications.In sum, this description should not be construed as limitation of the present invention.