サブデバイスの作成

サブデバイスという用語は、次の表に示す 4 つのコンポーネントのバインドを記述するために使用されます。

コンポーネント 説明

ミニポート オブジェクト

ミニポート ドライバーの IMiniportXxx インターフェイスを公開するオブジェクト

Port オブジェクト

ポート ドライバーの IPortXxx インターフェイスを公開するオブジェクト

リソース リスト オブジェクト

サブデバイスに割り当てられているアダプター ドライバー リソースの一覧を含むオブジェクト

参照文字列

フィルターの作成時にサブデバイスを指定するためにデバイス パス名に追加された名前

サブデバイスの IMiniportXxx インターフェイスと IPortXxx インターフェイスは、それぞれ基本インターフェイス IMiniport と IPort を継承します。

PortCls システム ドライバーは、ポート ドライバーとミニポート ドライバーを区別しません。 単に、ポート オブジェクトなどのオブジェクトと、システムによって生成された要求を処理できるインターフェイスが必要です。

同様に、PortCls はリソースの管理に直接関与しません。 要求ハンドラー (ポート ドライバー) をリソース一覧にバインドするだけで済みます。 アダプター ドライバーは、ポート、ミニポート、およびリソースの一覧のオブジェクトをバインドする役割を担います。

次のコード例は、アダプター ドライバーがこれらのアクションを実行する方法を示しています。

  //
  // Instantiate the port by calling a function supplied by PortCls.
  //
  PPORT    port;
  NTSTATUS ntStatus = PcNewPort(&port, PortClassId);

  if (NT_SUCCESS(ntStatus))
  {
      PUNKNOWN miniport;
      //
      // Create the miniport object.
      //
      if (MiniportCreate)   // a function to create a proprietary miniport
      {
          ntStatus = MiniportCreate(&miniport,
                                    MiniportClassId, NULL, NonPagedPool);
      }
      else   // Ask PortCls for one of its built-in miniports.
      {
          ntStatus = PcNewMiniport((PMINIPORT*)&miniport,
                                   MiniportClassId);
      }

      if (NT_SUCCESS(ntStatus))
      {
          //
          // Bind the port, miniport, and resources.
          //
          ntStatus = port->Init(DeviceObject,
                                Irp, miniport, UnknownAdapter, ResourceList);
          if (NT_SUCCESS(ntStatus))
          {
              //
              // Hand the port driver and the reference
              // string to PortCls.
              //
              ntStatus = PcRegisterSubdevice(DeviceObject,
                                             Name, port);
          }

          //
          // We no longer need to reference the miniport driver.
          // Either the port driver now references it,
          // or binding failed and it should be deleted.
          //
          miniport->Release();
      }

      //
      // Release the reference that existed when PcNewPort() gave us
      // the pointer in the first place. This reference must be released
      // regardless of whether the binding of the port and miniport
      // drivers succeeded.
      //
      port->Release();
  }

前のコード例の PortCls 関数呼び出しの詳細については、「 PcNewPort、 PcNewMiniport、 および PcRegisterSubdevice」を参照してください。