View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.windows.wmi;
6   
7   import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery;
8   import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
9   
10  import oshi.annotation.concurrent.ThreadSafe;
11  import oshi.util.platform.windows.WmiQueryHandler;
12  
13  /**
14   * Utility to query WMI class {@code Win32_DiskDriveToDiskPartition}
15   */
16  @ThreadSafe
17  public final class Win32DiskDriveToDiskPartition {
18  
19      private static final String WIN32_DISK_DRIVE_TO_DISK_PARTITION = "Win32_DiskDriveToDiskPartition";
20  
21      /**
22       * Links disk drives to partitions
23       */
24      public enum DriveToPartitionProperty {
25          ANTECEDENT, DEPENDENT;
26      }
27  
28      private Win32DiskDriveToDiskPartition() {
29      }
30  
31      /**
32       * Queries the association between disk drive and partition.
33       *
34       * @param h An instantiated {@link WmiQueryHandler}. User should have already initialized COM.
35       * @return Antecedent-dependent pairs of disk and partition.
36       */
37      public static WmiResult<DriveToPartitionProperty> queryDriveToPartition(WmiQueryHandler h) {
38          WmiQuery<DriveToPartitionProperty> driveToPartitionQuery = new WmiQuery<>(WIN32_DISK_DRIVE_TO_DISK_PARTITION,
39                  DriveToPartitionProperty.class);
40          return h.queryWMI(driveToPartitionQuery, false);
41      }
42  }