创建Windows驱动程序以访问网络存储 [英] Create a Windows driver to access network storage

查看:135
本文介绍了创建Windows驱动程序以访问网络存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序需要管理(访问,创建,写入,读取)远程服务器上的文件,并将该存储作为虚拟驱动器/卷安装在计算机上的指定位置(例如H)。 :),例如本地USB设备。



在Linux上,可以使用FUSE进行此类操作。但是,在Windows上没有等效项,唯一的方法是使用驱动程序。
所以我开始使用WDF创建驱动程序,但是一开始我就陷入了inf文件和适应我需要的最小代码适应的问题。

我看过很多官方驱动程序样本(例如nonpnp 样本)互联网上的各种资源(例如 OSR在线),但我无法



我遵循的步骤



要启动我的驱动程序项目,我创建了一个 Visual Studio 2013中的内核模式驱动程序(KMDF)。这是一个模板项目。
我能够使用该项目设置我的整个测试环境(测试机+签名内容+部署配置),因此这些工作正常。



但是,模板项目无法很好地满足我的需求:我需要有一个桌面应用程序,该应用程序将与(仅软件支持的)驱动程序进行交互,并且将要求该驱动程序安装/卸载卷并提供特定的(连接)信息。每卷。基于此,必须更改初始inf文件,因为它是用于硬件驱动程序(等待插入实际设备),此处不是这种情况。 inf文件的更改还意味着模板的初始代码有所更改。
但是,由于我开始修改inf文件和代码以满足我的最低需求,因此在部署步骤中驱动程序安装失败。



这是错误我得到:

  1> ------Débutde lagénération:Projet:cadwd Package,Configuration:Win7 Debug Win32 ------ 
1> ....................................
1>签名测试完成。
1>
1>错误:
1>无
1>
1>警告:
1>无
1>
1>目录生成完成。
1> C:\项目\驱动程序\Win7Debug\cadwd软件包\cadwd.cat
1>完成添加其他商店
1>成功签名:C:\project\driver\Win7Debug\cadwd包\cadwd.cat
1>
1>为项目 C:\project\driver\cadwd Package\cadwd Package.vcxproj部署驱动程序文件。部署可能需要几分钟...
1> C:\Program Files(x86)\Windows Kits\8.1\build\Win32\ImportAfter\DriverDeployment.targets(69,9) :错误:驱动程序部署任务失败:默认驱动程序包安装任务(可能重启)
==================== 0 = 0,1 = 0,1错误,0 0忽略==========

这是最小的代码: https://github.com/gupascal/StackOverflow-Q201503-1 。第一个提交是由VS项目生成的初始代码,
是第二个,显示了我的测试的当前状态(但是,我做了很多小型测试[没有一个工作],我无法列出所有测试)



有人可以帮我解决这个问题吗?我花了很多时间,真的很困。



感谢您的帮助,

纪尧姆

解决方案

首先:编写(内核)驱动程序并非易事。如果这不是出于教育目的,我强烈建议您向真正的专家寻求商业支持,例如看看 https://www.osr.com/custom-development



(我与OSR没有关系,但他们似乎非常称职)



通过对FS过滤器有了新的了解,我发现可以通过从preop例程返回FLT_PREOP_COMPLETE来完成I / O操作(如果我错了,请更正我),而不是简单地通过对下一个过滤器的I / O操作。



正确



其次,必须将FS筛选器驱动程序附加到卷上,但就我而言,我需要创建一个虚拟卷。事实是我不知道该怎么做。



成为这里的主要问题。我发现没有办法通过迷你过滤器引入一个新的(虚拟)体积,您只能附加和过滤一个已经存在的体积。



我可以想到这些选项:





如果使用subst,则可以映射例如X:到C:\fakepath,然后在过滤器中解析文件名,如果文件名位于伪路径下,则可以在过滤器中完成I / O。



我搜索了其他解决方案:



https ://www.eldos.com/cbfs (看起来很有趣)



也请点击此处:如何创建虚拟Windows驱动器



自从我开发以来(一个概念证明)(一个简单的微型过滤器),我记录了我的经验。



错误我得到的是默认驱动程序包安装任务(可能会重新启动):失败



我没有经验在VS部署方案中,我手动安装了驱动程序。我不确定什么是正确/最佳/最简单的方法。



我只能告诉您以下说明对我有用(而且我甚至使用



我在此处添加了以下说明,可能是它们可以帮助您尝试这种方式:






文档



https://msdn.microsoft.com/zh-CN/library/windows/hardware/ff548202 %28v = vs.85%29.aspx



通过此链接:



A文件系统过滤器驱动程序可以过滤一个或多个文件系统或文件系统卷的I / O操作,根据驱动程序的性质,过滤器可以记录,观察,修改甚至阻止,文件系统过滤器驱动程序的典型应用包括防病毒实用程序,加密程序和分层存储管理系统。



有些其他有价值的信息:



http://download.microsoft.com/download/f/0/5/f05a42ce-575b-4c60-82d6-208d3754b2d6/Filter_Manager.ppt



http://download.microsoft.com/download/e/b/a/eba1050f-a31d-436b-9281-92cdfeae4b45/FilterDriverDeveloperGuide.doc



从何处开始



将安装在64位操作系统(Windows 7,Server 2008R2)上的筛选器驱动程序...)必须签名。如果要在普通系统上安装这样的驱动程序,则必须购买官方的驱动程序证书。为了进行开发和测试,您可以将系统设置为测试模式,在该模式下可以使用自签名证书(不需要正式证书或注册)



第一个示例驱动程序



Microsoft提供了一些示例驱动程序,可以作为起点。我可以建议从Minispy过滤器开始。



先决条件





构建



开放式迷你解决方案



有一些已定义的配置。由于我们要在Windows Server 2008 R2上安装驱动程序,因此在此处设置 Win7 Release。



然后在解决方案资源管理器中右键单击解决方案,然后选择配置管理器



从配置管理器中,选择活动解决方案配置:



Win7版本



对,在活动解决方案平台下设置为x64



可选:



minispy属性(过滤器和用户)



配置属性=> C / C ++ =>代码生成=>运行时库:



从多线程DLL更改为多线程(静态链接)



优点:不需要将MSVCR120.DLL安装到目标系统



构建解决方案



下一步,需要三个文件:




  • minispy.sys(MiniSpy\C ++ \filter\x64\Win7Release)

  • minispy.exe(MiniSpy\ C ++ \user\x64\Win7Release)

  • minispy.inf(MiniSpy\C ++)



将这些文件复制到一个目录中



Visual Studio 2013 => Visual Studio工具=> VS2013 x64本机工具命令提示符



cd到包含文件的目录

  makecert -r -pe -ss PrivateCertStore -n CN = TestCert test.cer 

编辑minispy.inf
更改行



DriverVer = 06/16/2007, 1.0.0.0到当前日期

  inf2cat / driver:[path-to-dir] \ / os:Server2008R2_IA64 

signtool标志/ v / s PrivateCertStore / n TestCert / t http://timestamp.verisign.com/scripts/timestamp.dll minispy.cat

signtool标志/ v / s PrivateCertStore / n TestCert / t http://timestamp.verisign.com/scripts/timestamp.dll minispy.sys

将这些文件复制到Windows Server 2008 R2:




  • minispy.cat

  • minispy。 exe

  • minispy.inf

  • minispy.sys

  • test.cer



在Server 2008 R2上:



要能够加载驱动程序,必须将服务器置于测试模式。



命令提示符(以管理员身份运行)

  bcdedit.exe-在


重新启动



重新启动后,测试模式将显示在右下方



导入测试证书



启动 certmgr



选择受信任的根证书颁发机构



主菜单=>操作=>所有任务=>导入...



选择test.cer



将所有证书放入以下商店:受信任的根证书颁发机构



安装过滤器驱动程序



在Windows资源管理器中,选择minispy.inf,右键单击=>安装



(您只会看到短暂的闪烁,而没有看到成功类型消息e)



在命令提示符下:

  fltmc load minispy 

如果没有看到消息,则说明驱动程序已成功加载。



要检查驱动程序是否已加载,可以使用

  fltmc 

将显示所有已加载的过滤器驱动程序



首次测试:

  minispy / ac:/ f:log.txt 

按Enter键启动命令模式。在这里,您可以输入退出


I am working on an application which need to manage (access, create, write, read) files on a distant server and which will mount the storage as a virtual drive/volume on a specified location on the computer (eg. H:), like a local USB device for example.

On Linux, it is possible to do such a thing using FUSE. However, on Windows, there is no equivalent and the only way is to use a driver. So I started to create a driver using the WDF but I get stuck at the very beginning with the inf file and the minimal code adaptation to fit my needs.
I have looked at many official driver samples (eg. the nonpnp sample) and also many various resources on the internet (eg. OSR Online), but I was not able to get this working.

Steps I have followed

To start my driver project, I created a Kernel Mode Driver (KMDF) in Visual Studio 2013. It is a template project. I was able to set up my whole test environment with this project (test machine + signing stuff + deployment configuration), so these things are properly working.

However, the template project does not fit my needs very well: I need to have a desktop application which will interact with the (sofware-only) driver and which will ask the driver to mount/unmount volumes and give specifics (connection) information for each volume. Based on this, the initial inf file has to be changed because it's for an hardware driver (waiting for a real device being plugged in) which is not the case here. The change of the inf file also implies some changes in the initial code of the template. But, since I started to modify both inf file and code to fit my minimal needs, the driver installation fails during the deployment step.

This is the error I get:

1>------ Début de la génération : Projet : cadwd Package, Configuration : Win7 Debug Win32 ------
1>  ..........................
1>  Signability test complete.
1>
1>  Errors:
1>  None
1>
1>  Warnings:
1>  None
1>
1>  Catalog generation complete.
1>  C:\project\driver\Win7Debug\cadwd Package\cadwd.cat
1>  Done Adding Additional Store
1>  Successfully signed: C:\project\driver\Win7Debug\cadwd Package\cadwd.cat
1>
1>  Deploying driver files for project "C:\project\driver\cadwd Package\cadwd Package.vcxproj".  Deployment may take a few minutes...
1>C:\Program Files (x86)\Windows Kits\8.1\build\Win32\ImportAfter\DriverDeployment.targets(69,9): error : Driver Deployment Task Failed: Default Driver Package Installation Task (possible reboot)
========== Génération : 0 a réussi, 1 a échoué, 1 mis à jour, 0 a été ignoré ==========

Here is the minimal code : https://github.com/gupascal/StackOverflow-Q201503-1. The first commit is the initial code generated by the VS project, the second one shows the current state of my tests (however, I made tons of small tests [none of them worked], and I can't list all of them here).

Can anyone help me on this problem please? I spent a lot of time on this and I am really stuck.

Thanks for your help,
Guillaume

解决方案

First: Writing a (kernel) driver is not an easy task. If this is not for educational purposes, I strongly recommend to ask the real experts for commercial support, e.g. take a look at https://www.osr.com/custom-development

(I have no relationship to OSR, but they seem to be very competent)

By having a new look on FS filter, I found that it is possible to complete an I/O operation by returning FLT_PREOP_COMPLETE from the preop routine (please correct me if I am wrong) instead of simply passing the I/O operation to the next filter.

Correct

Secondly, a FS filter driver has to be attached to a volume, but in my case I need to create a virtual volume. The fact is that I don't know how neither where to do that.

This seems to be the main problem here. I found no way to "introduce" a new (virtual) volume by the mini filter, you can only attach and filter an already existing one.

I can think of these options:

If using subst, you map e.g. X: to C:\fakepath, and in the filter, you parse the filename, and if it is beneath the fake path, you can complete the I/O in the filter.

I searched for other solutions:

https://www.eldos.com/cbfs (looks interesting)

Also look here: How to Create a Virtual Windows Drive

Since I developed (as a proof-of-concept) a simple mini filter, I documented my experiences with this.

The error I get is Default Driver Package Installation Task (possible reboot): Fail

I have no experience with this VS deployment scenario, I installed my driver manually. I am not sure what is the correct / best / simplest way.

I can only tell you that my description below worked for me (and I even tested this again using a new installation).

I add these instructions here, may be they can help you to try this way:


Documentation

https://msdn.microsoft.com/en-us/library/windows/hardware/ff548202%28v=vs.85%29.aspx

From this link:

"A file system filter driver can filter I/O operations for one or more file systems or file system volumes. Depending on the nature of the driver, filter can mean log, observe, modify, or even prevent. Typical applications for file system filter drivers include antivirus utilities, encryption programs, and hierarchical storage management systems."

Some other valuable information:

http://download.microsoft.com/download/f/0/5/f05a42ce-575b-4c60-82d6-208d3754b2d6/Filter_Manager.ppt

http://download.microsoft.com/download/e/b/a/eba1050f-a31d-436b-9281-92cdfeae4b45/FilterDriverDeveloperGuide.doc

Where to start

A filter driver which will be installed on a 64 bit OS (Windows 7, Server 2008R2...) must be signed. If you want to install such a driver on a "normal" system, an official driver certificate must be purchased. For development and testing purposes, you can set the system into a "test mode", in which a self-signed certificate can be used (no need for official certificate or registration)

First sample driver

There are some sample drivers from Microsoft, which can be used as a starting point. I can recommend to start with the Minispy filter.

Prerequisites

Build

Open minispy solution

There are some defined configurations. Since we want to install the driver on Windows Server 2008 R2, we set "Win7 Release" here.

Then right-click the solution in the Solutions Explorer and select Configuration Manager

From the Configuration Manager, select the Active Solution Configuration:

Win7 Release

Right, under "Active solution platform" set to x64

Optionally:

minispy properties (both Filter and User)

Configuration Properties => C/C++ => Code Generation => Runtime Library:

Change from Multi-threaded DLL to Multi-threaded (statically linked)

Advantage: you do not need to install the MSVCR120.DLL to the target system

Build solution

For the next steps, three files are needed:

  • minispy.sys (MiniSpy\C++\filter\x64\Win7Release)
  • minispy.exe (MiniSpy\C++\user\x64\Win7Release)
  • minispy.inf (MiniSpy\C++)

Copy these files into one directory

Visual Studio 2013 => Visual Studio Tools => VS2013 x64 Native Tools Command Prompt

cd to the directory with the files

makecert -r -pe -ss PrivateCertStore -n CN=TestCert test.cer

Edit minispy.inf Change line

DriverVer = 06/16/2007,1.0.0.0 to current date

inf2cat /driver:[path-to-dir]\ /os:Server2008R2_IA64

signtool sign /v /s PrivateCertStore /n TestCert /t http://timestamp.verisign.com/scripts/timestamp.dll minispy.cat

signtool sign /v /s PrivateCertStore /n TestCert /t http://timestamp.verisign.com/scripts/timestamp.dll minispy.sys

Copy these files to the Windows Server 2008 R2:

  • minispy.cat
  • minispy.exe
  • minispy.inf
  • minispy.sys
  • test.cer

On the Server 2008 R2:

To be able to load the driver, the server must be brought into "test mode".

Command prompt (run as Administrator)

bcdedit.exe -set TESTSIGNING ON

reboot

After reboot, "Test Mode" will be displayed on the right bottom

Import Test certificate

Start "certmgr"

Select Trusted Root Certification Authorities

Main menu => Action => All tasks => Import...

Choose test.cer

Place all certificates in the following store: Trusted Root Certification Authorities

Install filter driver

In Windows explorer, select minispy.inf, right-click => install

(you see only a short flashing and no "success type" message)

In a command prompt:

fltmc load minispy

If you see no message, the driver was loaded successfully.

To check if the driver was loaded, you can use

fltmc

All loaded filter drivers will be shown

For a first test:

minispy /a c: /f: log.txt

Press Enter to start the command mode. There, you can enter exit

这篇关于创建Windows驱动程序以访问网络存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆