如何由AP來停止USB裝置 ? |
答題得分者是:conundrum
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
以USB姆指碟裝置而言,要拔出時,會先用Applet"Safely Remove Hareware"來移除.
使得主機寫回資料到USB姆指碟裝置,以免有未寫入的資料還在快取記憶體中,
使得USB姆指碟裝置錯亂.
(參考,執行,%windir%\system32\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll_ ) 根據測試瞭解,Applet"Safely Remove Hareware"
會使USB姆指碟裝置收到如下IRP
IRP_MN_QUERY_REMOVE_DEVICE
IRP_MN_REMOVE_DEVICE 好奇的,AP層如何對driver層發出IRP呢?
還是是透過PnP/IO/Device manager來發呢? 我喵故我在
------
我喵故我在 |
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
|
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
嗯嗯,
WDM的書,有些書是出來串場的,
實際上有用的,
大約四~五本吧... 但是,都沒說到,
如何從AP層,如何使裝置卸載的寫法.
只有提到,AP層的"裝置管理員"及"安全移除"會發IRP使裝置drvier啟動卸載機制,但沒提到如何使AP能發出訊息來卸載其它的drvier. 目前想到可行的,
是先掛上一只dummy driver,AP與這隻dummy driver通訊,由dummy driver對USB
USB disk driver丟 remove IRP,使USB disk driver啟動卸載機制,超麻煩的. 我喵故我在
------
我喵故我在 |
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
hi greatcat 請問一個問題 如果以USB姆指碟裝置而言 工作型態
庵要可讀取所有USB任何資料檔案型態 但無法寫入於USB 原因
很多企業公司因PC的便利性 由於USB可以十分方便攜帶大量資料 所以
要求有無這樣 防寫機制 如同1.44的方式 未經授權資料無法由USB攜帶 ///////////////////////
聽你看了這麼多 driver層的書 WDM 不知道是否有提過這樣需求解法 基本上 答案庵知道 等你解看看 台灣災難都是事後算帳
無人飛行載具(Unmanned Aerial Vehicle,UAV)為什麼沒大量應用於救災行列
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
嗯,我只玩HID類,
storage類就不熟了.就猜看看囉...
我分析USB架構如下 [AP]
---[IO manager]--[file system]----
[USB storage driver]
[USB bus driver]
----------------
[HAL]
---------------
|
|
|
---------
[USB disk]
///////////
所以,有三種可能的方法,
(1)寫類以防毒程式,要寫入時,若為可抽取裝置,就回報錯誤...電腦效能會降低.
(2)換掉USB storage driver,接到write 的URB,就回報錯誤...工程大浩大,如果有driver tools中的USB storage driver來改,才可行.
(3)在[USB storage driver]上,加一層filter driver,攔掉write 的URB...filter driver不好學. 對嗎? /////
無人飛行載具為什麼沒大量應用於救災行列...利委不是股東呀,台灣就是這樣子:P
///// 我喵故我在
------
我喵故我在 |
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
|
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
程式中有兩個bug那已經有人修正過了 資料在那 1 某大陸程式討論區 2 google就找的到了 庵不喜歡回這種問題 所以你自己善用 google 的搜索技巧把 庵只給方向 哈哈 接下來要挑戰的,是不是如何不用USB碟拷出資料?不用 查查 BS7799 認證標準 就有一車的機制要解決了 導入BS7799 標準─企業責無旁貸 http://delphi.ktop.com.tw/topic.php?topic_id=51644 台灣災難都是事後算帳 無人飛行載具(Unmanned Aerial Vehicle,UAV)為什麼沒大量應用於救災行列 |
conundrum
尊榮會員 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
http://www.book23.com/data/web5304/20050228/20050228__3530331.html 我copy人家的代碼給你: 絕對可用的,100% Delphi代碼!! http://www.yeahware.com/download/eject.zip 選擇Show hidden device後在USB Mass Storage Device處就是Eject了!!! 關鍵代碼 function CM_Get_DevNode_Status(pulStatus: PULong; pulProblemNumber: PULong; dnDevInst: DWord; ulFlags: ULong): DWord; stdcall; external CfgMgr32ModuleName name 'CM_Get_DevNode_Status'; function CM_Request_Device_Eject(dnDevInst: DWord; out pVetoType: TPNPVetoType; pszVetoName: PChar; ulNameLength: ULong; ulFlags: ULong): DWord; stdcall; external SetupApiModuleName name 'CM_Request_Device_EjectA'; if (CM_Get_DevNode_Status(@Status, @Problem, DeviceInfoData.DevInst, 0) <> CR_SUCCESS) then begin exit; end; VetoName[0] := #0; case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of CR_SUCCESS: begin MessageBox(Handle, PChar(’Eject OK (Veto: ' VetoName ')'), 'Vetoed', MB_OK); end; CR_REMOVE_VETOED: begin MessageBox(Handle, PChar('Failed to eject the Device (Veto: ' VetoName ')'), 'Vetoed', MB_OK); end; else begin MessageBox(Handle, PChar('Failed to eject the Device (' SysErrorMessage(GetLastError) ')'), 'Failure', MB_OK); end; end; 那個Eject原代碼是有Bug的,修正如下 添加 function TForm1.GetDevInfo(var hDevInfo: hDevInfo): boolean; begin // Get a handle to all devices in all classes present on system hDevInfo := SetupDiGetClassDevs(nil, nil, 0, DIGCF_PRESENT or DIGCF_ALLCLASSES); Result := hDevInfo <> Pointer(INVALID_HANDLE_VALUE); end; 調用為: procedure TForm1.FormCreate(Sender: TObject); begin if (not LoadSetupAPI) then begin ShowMessage('Could not load SetupAPI.dll'); exit; end; DevInfo := nil; ShowHidden := false; // Get a handle to all devices in all classes present on system if not GetDevInfo(DevInfo) then begin ShowMessage('GetClassDevs'); exit; end; // Get the Images for all classes, and bind to the TreeView ClassImageListData.cbSize := SizeOf(TSPClassImageListData); if (not SetupDiGetClassImageList(ClassImageListData)) then begin ShowMessage('GetClassImageList'); exit; end; ImageList.Handle := ClassImageListData.ImageList; TreeView.Images := ImageList; // Add the devices to the TreeView window. EnumAddDevices(ShowHidden, TreeView, DevInfo); end; procedure TForm1.mRefreshDisplayClick(Sender: TObject); begin if not GetDevInfo(DevInfo) then begin ShowMessage('GetClassDevs'); exit; end; EnumAddDevices(ShowHidden, TreeView, DevInfo); end; case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of CR_SUCCESS: begin MessageBox(Handle, 'Successful to eject the Device', 'Done', MB_OK); if not GetDevInfo(DevInfo) then begin ShowMessage('GetClassDevs'); exit; end; EnumAddDevices(ShowHidden, TreeView, DevInfo); end;試看看 庵以前看的那篇 懶的找了 台灣災難都是事後算帳 無人飛行載具(Unmanned Aerial Vehicle,UAV)為什麼沒大量應用於救災行列 |
greatcat
一般會員 發表:7 回覆:9 積分:3 註冊:2005-01-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |