Summary of the invention
The invention provides the method and the device of unloading movable storage device, can under the movable storage device situation that normally safety ejects owing to being taken by process, the solution of effective unloading movable storage device be provided.
The invention provides following scheme:
A kind of method that unloads movable storage device comprises:
After detecting the movable storage device access, create the administration portal of said movable storage device;
When receiving the request of the said movable storage device of unloading through said administration portal,, then taking the progress information of said movable storage device to the driver inquiry that operates in inner nuclear layer if there is process taking said movable storage device;
To after the taking of said movable storage device, said movable storage device is carried out unloading operation in the process of removing according to the said progress information that inquires.
Wherein, said in the process of removing according to the said progress information that inquires to after the taking of said movable storage device, said movable storage device is carried out unloading operation comprises:
The progress information that takies said movable storage device is prompted to the user,, initiates the request of the said movable storage device of unloading again so that the user removes process to after the taking of said movable storage device according to information;
When receiving the request of the said movable storage device of unloading again, with said movable storage device unloading.
Wherein, said in the process of removing according to the said progress information that inquires to after the taking of said movable storage device, said movable storage device is carried out unloading operation comprises:
Send message to the said process that takies movable storage device, so that the said process that takies movable storage device is removed taking said movable storage device;
When the said process that takies movable storage device is removed after the taking of said movable storage device, with said movable storage device unloading.
Wherein, said to the said process transmission message that takies movable storage device, so that the said process that takies movable storage device is removed taking of said movable storage device comprised:
To the said message that takies the process transmission end process of movable storage device, so that the said process that takies movable storage device is removed taking said movable storage device.
Wherein, said in the process of removing according to the said progress information that inquires to after the taking of said movable storage device, said movable storage device is carried out unloading operation comprises:
By said driver the handle that process takies movable storage device is closed, so that releasing process taking said movable storage device;
The releasing process is to after the taking of said movable storage device, with said movable storage device unloading.
A kind of device that unloads movable storage device comprises:
Administration portal provides the unit, after being used to detect movable storage device and inserting, creates the administration portal of said movable storage device;
The kernel query unit; Be used for when receiving the request of the said movable storage device of unloading through said administration portal; If there is process taking said movable storage device, then taking the progress information of said movable storage device to the driver inquiry that operates in inner nuclear layer;
Unloading unit is used in the process of removing according to the said progress information that inquires to after the taking of said movable storage device said movable storage device being carried out unloading operation.
Wherein, said unloading unit comprises:
The prompting subelement is used for the progress information that takies said movable storage device is prompted to the user, so that the user removes process to after the taking of said movable storage device according to information, initiates the request of the said movable storage device of unloading again;
The first unloading subelement is used for when receiving the request of the said movable storage device of unloading again, with said movable storage device unloading.
Wherein, said unloading unit comprises:
Message is sent subelement, is used for sending message to the said process that takies movable storage device, so that the said process that takies movable storage device is removed taking said movable storage device;
The second unloading subelement is used for removing after the taking of said movable storage device, with said movable storage device unloading when the said process that takies movable storage device.
Wherein, said message transmission subelement comprises:
Finish process message and send subelement, be used for sending the message of end process, so that the said process that takies movable storage device is removed taking said movable storage device to the said process that takies movable storage device.
Wherein, said unloading unit comprises:
Handle is closed subelement, is used for by said driver the handle that process takies movable storage device being closed, so that releasing process taking said movable storage device;
The 3rd unloading subelement is used for the releasing process to after the taking of said movable storage device, with said movable storage device unloading.
According to specific embodiment provided by the invention, the invention discloses following technique effect:
Through the present invention; Under the movable storage device situation that normally safety ejects owing to being taken by process; Can inquire what take movable storage device through the driver that operates in inner nuclear layer is which or which process; And then can carry out unloading operation to movable storage device in the releasing process to after the taking of movable storage device.It is thus clear that, owing to taken and can't normal safe At time of eject, do not need the user to go manually to search the process that takies movable storage device at movable storage device by process, just can accomplish the associative operation that take of releasing process to movable storage device.
Embodiment
To combine the accompanying drawing in the embodiment of the invention below, the technical scheme in the embodiment of the invention is carried out clear, intactly description, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, the every other embodiment that those of ordinary skills obtained belongs to the scope that the present invention protects.
Described computing machine is meant the main frame that the operating system of supporting the access peripheral storage device is housed; The operating system that said main frame is adorned 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, small-size computer are with, data processing work station and hand-held personal data treating apparatus.
Said movable storage device can comprise data storage devices such as the flash disk of supporting plug and play on computers, portable hard drive.
The interface of said 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 in GSM, GPRS, CDMA, 2.75G, 3G interface and the parallel interface one or more.For method of the present invention clearly is described, present embodiment is that the movable storage device of USB is that example describes with Flash as storage medium interface.
Referring to Fig. 1, the method for the ejection movable storage device that the embodiment of the invention provides may further comprise the steps:
S101: after detecting the movable storage device access, create the administration portal of said movable storage device;
At first need to prove,
In embodiments of the present invention; The client-side program that is equivalent to for the user management movable storage device is provided is (for ease of describing; In the embodiment of the invention this client-side program become " external unit guard process "), the user can manage the movable storage device that is inserted on the computer through this program.During concrete the realization; Client-side program in the embodiment of the invention is after finding have movable storage device to insert; The administration portal (for example, can be the icon etc. in desktop or the toolbar) of movable storage device can be provided for the user, the user can through this administration portal check movable storage device remaining space, open attribute or the like; In addition; Interfaces such as " safety eject movable storage device " can also be provided in Administration menu, when the user need unload movable storage device, just can select to click this option.
Concrete, the administration portal of movable storage device can be provided for the user on the table, for example,
Clisid represents object, CLSID set up a CLSID key and be used for managing movable storage device, can set up sub-key DefaultIcon under it corresponding icon is set.
If let CLISID show desktop icons, can under NameSpace, set up a sub-key, title is to be exactly this CLSID.
Generate icon at active user's desktop: Software Explorer.
Generate icon at all user's desktops: SOFTWARE Explorer, thereby the administration portal of movable storage device is provided for the user.
When concrete the realization; When movable storage device inserts a computer; Operating system can be found this movable storage device at first, and under traditional mode, operating system can be given tacit consent at the interface that provides an ejection; And can generate drive for movable storage device, in " my computer " interface, provide the icon of this movable storage device then.But in embodiments of the present invention, be to realize management to movable storage device through an external unit guard process, therefore, can be different on the mechanism that realizes with traditional mode.Concrete, because operating system can be broadcasted a system message (WM_DEVICECHANGE) after finding that a movable storage device inserts, therefore, the external unit guard process can be found the access of movable storage device through listening to this broadcast.Just can carry out the operation that generates administration portal then.Specifically when generating administration portal, what can also at first judge access specifically is the movable storage device type, for example is USB flash disk or portable hard drive or the like; To different movable storage device types, (for example, USB flash disk is blue icon to generate different icons then; Portable hard drive is green icon or the like), that is to say, if the user inserts a USB flash disk and a portable hard drive simultaneously in computer; Behind the icon in right-click desktop or the taskbar; Can list the selection of USB flash disk and portable hard drive in the menu that ejects successively, when needs unloading USB flash disk/portable hard drive, can carry out accordingly through the corresponding administration portal of the option of this USB flash disk/portable hard drive and operate.In addition, the user is at needs.Open movable storage device when the user need carry out through this administration portal, or when checking operation such as movable storage device remaining space, the external unit guard process can also provide corresponding response.
Wherein, No matter be the type of obtaining movable storage device; Still obtain the remaining space of movable storage device, the information such as file that comprise, the external unit guard process can realize inquiring about the relevant information of movable storage device through the api function of operating system.For example, in Windows NT/2000/XP system, application program can realize the visit to equipment through api function DeviceIoControl, comprises the information of obtaining, sends order, swap data etc.Utilize this interface function to send correct control code and data, analyze its response then, just can reach corresponding target to the appointed equipment driver.During concrete the realization, can know through WMDeviceChange message and insert USB flash disk, obtain movable storage device, obtain movable storage device corresponding drive in system.Wherein, when wParam==DBT_DEVICEARRIVAL, lParam is a pointer that points to the DEV_BROADCAST_VOLUME structure; Dbcv_unitmask in the structure representes drive; Then, can open equipment 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 pointer DWORD nInBufferSize; // input data buffer length LPVOID lpOutBuffer; // data output buffer district pointer DWORD nOutBufferSize, // data output buffer section length LPDWORD lpBytesReturned, // output data physical length element length LPOVERLAPPED lpOverlapped//overlapping processing structured fingers).Wherein, the equipment handle is used for identifying the equipment of being visited.
S102: when receiving the request of the said movable storage device of unloading through said administration portal; If there is process taking said movable storage device, then taking the progress information of said movable storage device to the driver inquiry that operates in inner nuclear layer;
If the user unloads movable storage device through the external unit guard process for its mobile storage device management that provides enters the mouth; The user can select " safety ejects movable storage device " in the management interface menu); Then the external unit guard process can learn that the user wants to unload movable storage device; At this moment, the external unit guard process can judge currently whether have process just taking this movable storage device through the api function that system provides.If have, then can take the progress information of movable storage device to the driver inquiry that operates in inner nuclear layer, also promptly, inquiring about has which or which process taking movable storage device.
Need to prove that in the process that the file or folder in the movable storage device is operated, operating system can be carried out corresponding record, comprises which process of having opened, which file of operation or the like.Through these information, just can know which the process that is taking movable storage device has.But these information generally all are recorded in the inner nuclear layer of operating system, and common upper level applications can't directly be known.Therefore, in embodiments of the present invention, in order to obtain these information; Can be driver of external unit guard process configuration in advance; This driver can start along with the startup of external unit guard process, and operates in inner nuclear layer, can get access to the information that inner nuclear layer is preserved.Need to prove; If being in program under the user model attempts from kernel spacing, to read a byte or attempts to carry out assembly instruction and all can be stopped immediately; And driver is the code that operates under ring 0 (Ring0) environment that system trusts, and it has the access rights to any software and hardware of system.This means that Kernel Driver can visit all system resource, can read all memory headrooms, and be allowed to carry out the privileged instruction of CPU, as, read the currency of CPU control register etc.Therefore; Driver just because of kernel level has These characteristics; Therefore, the external unit guard process in the embodiment of the invention just can be obtained with movable storage device through this driver and take relevant information, thereby reaches the purpose of unloading movable storage device.
S103: to after the taking of said movable storage device, said movable storage device is carried out unloading operation in the process of removing according to the said progress information that inquires.
Because the process that takies movable storage device that inquires through driver, therefore, just can be at first take releasing with this, just can normally accomplish unloading operation then to movable storage device.Certainly, if find the current process that does not take movable storage device, the unloading operation of directly carrying out movable storage device gets final product.Wherein, the external unit guard process can realize equally that when carrying out unloading operation the concrete api function that uses still can be DeviceIoControl through the api function of calling system.
Wherein, when removing process according to the progress information that inquires, multiple implementation can be arranged to the taking of movable storage device.For example, wherein a kind of implementation can be the progress information that takies movable storage device to be prompted to the user (for example can to eject dialog box; Information such as title with process in dialog box represent to the user with forms such as tabulations, perhaps can also point out through ejecting modes such as bubble), like this; The user just can point out according to this; Find the current process that takies movable storage device, finish this process then, the administration portal that provides through the external unit guard process is again again initiated the request of unloading movable storage device; The external unit guard process is after receiving new unload request; Still can be at first judge currently whether have process to take movable storage device,, then can accomplish unloading through the api function of calling system to movable storage device if find not had through calling api function.If finding certainly still has process to take movable storage device, then can obtain the current progress information that takies through driver once more, and be prompted to the user, by that analogy.
Perhaps; Under another kind of implementation; The external apparatus guard process is known can directly send message to the process that takies movable storage device after the current progress information that is taking movable storage device, make this process remove taking movable storage device.Wherein, specifically, can directly send the message of this process of end when the process that takies movable storage device is sent message; Like this; After process finishes, generally speaking, will discharge taking to movable storage device; And then, unload movable storage device and get final product through calling api function.Certainly, if whole process is all finished, the realization of normal function in then possibly influencing the course; Therefore; In embodiments of the present invention, also can be directly the handle that takies movable storage device in the process to be closed, like this by driver; The process of will removing is to the taking of movable storage device, and the realization of other functions in can not influencing the course.Certainly; In practical application, also possibly have following situation: the user is using certain accounting process program, but has a bug in the process, to such an extent as to the handle of certain file that when ends file is handled, does not have to store in the release busy movable storage device; To this situation; Both can use the said process to the accounting process program of preamble to send the message of end process, and make this process be all over, process is through with; All relevant with this process have not just existed, and will discharge taking movable storage device certainly yet.Perhaps; Also can directly this should be discharged but because the existence of bug and the handle that discharges, take movable storage device is closed always by driver; Because other processing in the process can't take movable storage device, therefore also can reach the purpose that take of releasing process like this to movable storage device.
In addition, in practical application, can also multiple mode be combined; For example, can after having known the current progress information that takies movable storage device, can at first point out through ejecting modes such as dialog box the user is current to have taking movable storage device for which process; Simultaneously, can also point out out occupied file or folder, and the button that continues use is provided in dialog box; And the button of " releasing takies and safety ejects ", the user can select to continue to use, and perhaps selects the latter; If selected the latter, then can send message to the process that takies movable storage device, make corresponding process remove taking to movable storage device; The api function of call operation system gets final product the movable storage device unloading then.Certainly, after unloading is accomplished, can point out informations such as the user " can extract movable storage device safely " equally.
The method of the unloading movable storage device that provides with the embodiment of the invention is corresponding, and the embodiment of the invention also provides a kind of device that unloads movable storage device, and referring to Fig. 2, this device can comprise:
Administration portal provides unit 201, after being used to detect movable storage device and inserting, creates the administration portal of said movable storage device;
Kernel query unit 202; Be used for when receiving the request of the said movable storage device of unloading through said administration portal; If there is process taking said movable storage device, then taking the progress information of said movable storage device to the driver inquiry that operates in inner nuclear layer;
Unloading unit 203 is used in the process of removing according to the said progress information that inquires to after the taking of said movable storage device said movable storage device being carried out unloading operation.
During concrete the realization, unloading unit 203 specifically can comprise:
The prompting subelement is used for the progress information that takies said movable storage device is prompted to the user, so that the user removes process to after the taking of said movable storage device according to information, initiates the request of the said movable storage device of unloading again;
The first unloading subelement is used for when receiving the request of the said movable storage device of unloading again, with said movable storage device unloading.
Perhaps, under another kind of implementation, unloading unit 203 also can comprise:
Message is sent subelement, is used for sending message to the said process that takies movable storage device, so that the said process that takies movable storage device is removed taking said movable storage device;
The second unloading subelement is used for removing after the taking of said movable storage device, with said movable storage device unloading when the said process that takies movable storage device.
Wherein, message transmission subelement specifically can comprise:
Finish process message and send subelement, be used for sending the message of end process, so that the said process that takies movable storage device is removed taking said movable storage device to the said process that takies movable storage device.
Perhaps, impact for fear of the normal function to process, unloading unit 203 also can comprise:
Handle is closed subelement, is used for by said driver the handle that process takies movable storage device being closed, so that releasing process taking said movable storage device;
The 3rd unloading subelement is used for the releasing process to after the taking of said movable storage device, with said movable storage device unloading.
The said apparatus that provides through the embodiment of the invention; Under the movable storage device situation that normally safety ejects owing to being taken by process; Can inquire what take movable storage device through the driver that operates in inner nuclear layer is which or which process; And then can carry out unloading operation to movable storage device in the releasing process to after the taking of movable storage device.It is thus clear that, owing to taken and can't normal safe At time of eject, do not need the user to go manually to search the process that takies movable storage device at movable storage device by process, just can accomplish the associative operation that take of releasing process to movable storage device.
Description through above embodiment can know, those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential general hardware platform.Based on such understanding; The part that technical scheme of the present invention contributes to prior art in essence in other words can be come out with the embodied of software product; This computer software product can be stored in the storage medium, like ROM/RAM, magnetic disc, CD etc., comprises that some instructions are with so that a computer equipment (can be a personal computer; Server, the perhaps network equipment etc.) carry out the described method of some part of each embodiment of the present invention or embodiment.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and identical similar part is mutually referring to getting final product between each embodiment, and each embodiment stresses all is the difference with other embodiment.Especially, for device or system embodiment, because it is basically similar in appearance to method embodiment, so describe fairly simplely, relevant part gets final product referring to the part explanation of method embodiment.Apparatus and system embodiment described above only is schematic; Wherein said unit as the separating component explanation can or can not be physically to separate also; The parts that show as the unit can be or can not be physical locations also; Promptly can be positioned at a place, perhaps also can be distributed on a plurality of NEs.Can realize the purpose of present embodiment scheme according to the needs selection some or all of module wherein of reality.Those of ordinary skills promptly can understand and implement under the situation of not paying creative work.
More than to the method and the device of unloading movable storage device provided by the present invention; Carried out detailed introduction; Used concrete example among this paper principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, part all can change on embodiment and range of application.In sum, this description should not be construed as limitation of the present invention.