前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何让 USB 设备不显示安全删除硬件弹出选项

如何让 USB 设备不显示安全删除硬件弹出选项

作者头像
林德熙
发布2019-09-27 10:22:44
2.8K0
发布2019-09-27 10:22:44
举报

插入一个 U 盘的时候,可以在右下角找到安全删除硬件图标,点击就可以删除此硬件。如果此时插入的是一个无线网卡,也就是 USB 无线 wifi 设备,此时如果逗比点了弹出 802.11 设备那么就不能再使用无线上网了 如果我是一个硬件供应商,如何让我的设备不会显示弹出安全删除硬件弹出选项

我不是做硬件的,对硬件懂的很少,以下是我找到的文档,如果有说错的,欢迎小伙伴告诉我

Using the USB Removable Capability for Device Container Grouping

可以找到这句话

The USB Removable capability allows the operating system to create a device container for legacy devices.

Overview of the Removable Device Capability可以知道一个 USB 设备是需要声明自己支持 Removable 的才可以在右下角使用安全删除硬件弹出选项

The removable device capability is a bit (Removable) that bus drivers set in the DEVICE_CAPABILITIES

Container IDs Generated from the Removable Device Capability 可以知道,在即插即用功能将会使用到这个功能,在设备插入的时候,通过发送 IRP_MN_QUERY_CAPABILITIES 获取到设备的返回信息,就可以知道这个设备支不支持移除

The Plug and Play manager uses the removable device capability to generate a container ID for all devnodes enumerated for the physical device. The bus driver reports the removable device capability in response to an IRP_MN_QUERY_CAPABILITIES request.

那么上面说的发送信息是什么,就从IRP_MN_QUERY_CAPABILITIES 可以知道,在硬件设备被枚举时,系统的 PnP 也就是即插即用功能将会发送 IRP_MN_QUERY_CAPABILITIES 信息给到硬件,此时硬件收到时将会回复 DEVICE_CAPABILITIES 信息

When a device is enumerated, but before the function and filter drivers are loaded for the device, the PnP manager sends an IRP_MN_QUERY_CAPABILITIES request to the parent bus driver for the device. The bus driver must set any relevant values in the DEVICE_CAPABILITIES structure and return it to the PnP manager.

硬件回复的消息请看 DEVICE_CAPABILITIES (wdm.h) 在 PnP 询问USB设备,此时USB设备返回 DEVICE_CAPABILITIES 里面可以设置 Removable 项说明此设备支持移除。也就是想要自己的 USB 设备不能被移除,那么就声明不支持移除

以下是 DEVICE_CAPABILITIES 定义

typedef struct _DEVICE_CAPABILITIES {
  USHORT             Size;
  USHORT             Version;
  ULONG              DeviceD1 : 1;
  ULONG              DeviceD2 : 1;
  ULONG              LockSupported : 1;
  ULONG              EjectSupported : 1;
  ULONG              Removable : 1;
  // 忽略不相关属性
} DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;

对 Removable 属性的官方注释是如果设置为 True 那么将会显示弹出或移除设备

Removable

Specifies whether the device can be dynamically removed from its immediate parent. If Removable is set to TRUE, the device does not belong to the same physical object as its parent.

For example, if Removable is set to TRUE for a USB composite device inside a multifunction printer, the composite device does not belong to the physical object of its immediate parent, such as a USB hub inside a notebook PC.

In most cases the bus driver, not the function driver, should determine the value of the Removable parameter of the device. For USB devices, the USB hub driver sets the Removable parameter. It should not be modified by the function driver.

If Removable is set to TRUE, the device is displayed in the Unplug or Eject Hardware program, unless SurpriseRemovalOK is also set to TRUE.

从可移动设备功能生成的容器 Id 重写

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档