如何确定“安全删除硬件”中显示的驱动器(卷)对话?

发布于 2024-11-03 10:06:41 字数 1120 浏览 2 评论 0原文

我有一个监视文件系统事件的应用程序。这需要目标卷的永久打开句柄。这对于系统启动驱动器和其他固定设备来说很好,但如果我们处理托管在可移动设备(例如 eSATA、USB、Firewire、iSCSI 等)上的卷,则非常不可取,因为用户可能希望随时拔掉这些设备但打开的手柄将阻止“安全删除硬件”成功。

理想情况下,我希望防止我的应用程序锁定其父卷可能默认出现在“安全删除硬件”中的任何卷。问题是,似乎没有记录的方法来确定哪些设备显示在那里,哪些设备不显示。我错过了什么吗?有人有线索吗?

请注意,可以查询设备的总线类型,这几乎为我完成了工作:

typedef enum _STORAGE_BUS_TYPE {
  BusTypeUnknown             = 0x00,
  BusTypeScsi                = 0x1,
  BusTypeAtapi               = 0x2,
  BusTypeAta                 = 0x3,
  BusType1394                = 0x4,
  BusTypeSsa                 = 0x5,
  BusTypeFibre               = 0x6,
  BusTypeUsb                 = 0x7,
  BusTypeRAID                = 0x8,
  BusTypeiScsi               = 0x9,
  BusTypeSas                 = 0xA,
  BusTypeSata                = 0xB,
  BusTypeSd                  = 0xC,
  BusTypeMmc                 = 0xD,
  BusTypeVirtual             = 0xE,
  BusTypeFileBackedVirtual   = 0xF,
  BusTypeMax                 = 0x10,
  BusTypeMaxReserved         = 0x7F 
} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE;

然而,IOCTL 返回 SATA 和 eSATA 的 BusTypeSata - 但操作系统将后者识别为必须在“安全删除”中显示的内容对话。

I have an application that watches for file system events. This requires a permanently open handle to the target volumes. This is fine for things like the system boot drive and other fixed devices but very undesirable if we're dealing with volumes hosted on removable devices such as eSATA, USB, Firewire, iSCSI, etc, as the user may want to unplug these at any time but the open handle will prevent "Safely Remove Hardware" from succeeding.

Ideally I'd like to prevent my application from latching onto any volume whose parent may appear in "Safely Remove Hardware" as the default. The problem is, there doesn't seem to be a documented way of determining what devices show up there and what devices don't. Am I missing something? Does anyone have a lead?

Note that it's possible to query a device's bus type and this almost gets the job done for me:

typedef enum _STORAGE_BUS_TYPE {
  BusTypeUnknown             = 0x00,
  BusTypeScsi                = 0x1,
  BusTypeAtapi               = 0x2,
  BusTypeAta                 = 0x3,
  BusType1394                = 0x4,
  BusTypeSsa                 = 0x5,
  BusTypeFibre               = 0x6,
  BusTypeUsb                 = 0x7,
  BusTypeRAID                = 0x8,
  BusTypeiScsi               = 0x9,
  BusTypeSas                 = 0xA,
  BusTypeSata                = 0xB,
  BusTypeSd                  = 0xC,
  BusTypeMmc                 = 0xD,
  BusTypeVirtual             = 0xE,
  BusTypeFileBackedVirtual   = 0xF,
  BusTypeMax                 = 0x10,
  BusTypeMaxReserved         = 0x7F 
} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE;

However the IOCTL returns BusTypeSata for both SATA and eSATA - yet the OS recognizes the latter as something that has to be shown in the "Safely Remove" dialog.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-11-10 10:06:42

您可以侦听设备事件以了解何时应该关闭句柄:

http://msdn.microsoft.com/en-us/library/aa363217(v=vs.85).aspx

请注意,对于固定设备,您也需要这个,否则您的开放手柄可能会防止诸如 chkdsk 之类的事情运行(为此您需要侦听锁定/卸载事件)。

-斯科特

You can listen for device events to know when you should close your handles:

http://msdn.microsoft.com/en-us/library/aa363217(v=vs.85).aspx

Note that you also need this for fixed devices as well, otherwise your open handle could prevent things like chkdsk from running (for that you need to listen for lock/dismount events).

-scott

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文