View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.software.os.windows;
6   
7   import java.util.List;
8   
9   import oshi.annotation.concurrent.ThreadSafe;
10  import oshi.software.common.AbstractOSFileStore;
11  import oshi.software.os.OSFileStore;
12  
13  /**
14   * OSFileStore implementation
15   */
16  @ThreadSafe
17  public class WindowsOSFileStore extends AbstractOSFileStore {
18  
19      private String logicalVolume;
20      private String description;
21      private String fsType;
22  
23      private long freeSpace;
24      private long usableSpace;
25      private long totalSpace;
26      private long freeInodes;
27      private long totalInodes;
28  
29      public WindowsOSFileStore(String name, String volume, String label, String mount, String options, String uuid,
30              String logicalVolume, String description, String fsType, long freeSpace, long usableSpace, long totalSpace,
31              long freeInodes, long totalInodes) {
32          super(name, volume, label, mount, options, uuid);
33          this.logicalVolume = logicalVolume;
34          this.description = description;
35          this.fsType = fsType;
36          this.freeSpace = freeSpace;
37          this.usableSpace = usableSpace;
38          this.totalSpace = totalSpace;
39          this.freeInodes = freeInodes;
40          this.totalInodes = totalInodes;
41      }
42  
43      @Override
44      public String getLogicalVolume() {
45          return this.logicalVolume;
46      }
47  
48      @Override
49      public String getDescription() {
50          return this.description;
51      }
52  
53      @Override
54      public String getType() {
55          return this.fsType;
56      }
57  
58      @Override
59      public long getFreeSpace() {
60          return this.freeSpace;
61      }
62  
63      @Override
64      public long getUsableSpace() {
65          return this.usableSpace;
66      }
67  
68      @Override
69      public long getTotalSpace() {
70          return this.totalSpace;
71      }
72  
73      @Override
74      public long getFreeInodes() {
75          return this.freeInodes;
76      }
77  
78      @Override
79      public long getTotalInodes() {
80          return this.totalInodes;
81      }
82  
83      @Override
84      public boolean updateAttributes() {
85          // Check if we have the volume locally
86          List<OSFileStore> volumes = WindowsFileSystem.getLocalVolumes(getVolume());
87          if (volumes.isEmpty()) {
88              // Not locally, search WMI
89              String nameToMatch = getMount().length() < 2 ? null : getMount().substring(0, 2);
90              volumes = WindowsFileSystem.getWmiVolumes(nameToMatch, false);
91          }
92          for (OSFileStore fileStore : volumes) {
93              if (getVolume().equals(fileStore.getVolume()) && getMount().equals(fileStore.getMount())) {
94                  this.logicalVolume = fileStore.getLogicalVolume();
95                  this.description = fileStore.getDescription();
96                  this.fsType = fileStore.getType();
97                  this.freeSpace = fileStore.getFreeSpace();
98                  this.usableSpace = fileStore.getUsableSpace();
99                  this.totalSpace = fileStore.getTotalSpace();
100                 this.freeInodes = fileStore.getFreeInodes();
101                 this.totalInodes = fileStore.getTotalInodes();
102                 return true;
103             }
104         }
105         return false;
106     }
107 }