View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware;
6   
7   import oshi.annotation.concurrent.Immutable;
8   import oshi.util.FormatUtil;
9   
10  /**
11   * A region on a hard disk or other secondary storage, so that an operating system can manage information in each region
12   * separately. A partition appears in the operating system as a distinct "logical" disk that uses part of the actual
13   * disk.
14   */
15  @Immutable
16  public class HWPartition {
17  
18      private final String identification;
19      private final String name;
20      private final String type;
21      private final String uuid;
22      private final long size;
23      private final int major;
24      private final int minor;
25      private final String mountPoint;
26  
27      /**
28       * Creates a new HWPartition
29       *
30       * @param identification The unique partition id
31       * @param name           Friendly name of the partition
32       * @param type           Type or description of the partition
33       * @param uuid           UUID
34       * @param size           Size in bytes
35       * @param major          Device ID (Major)
36       * @param minor          Device ID (Minor)
37       * @param mountPoint     Where the partition is mounted
38       */
39      public HWPartition(String identification, String name, String type, String uuid, long size, int major, int minor,
40              String mountPoint) {
41          this.identification = identification;
42          this.name = name;
43          this.type = type;
44          this.uuid = uuid;
45          this.size = size;
46          this.major = major;
47          this.minor = minor;
48          this.mountPoint = mountPoint;
49      }
50  
51      /**
52       * <p>
53       * Getter for the field <code>identification</code>.
54       * </p>
55       *
56       * @return Returns the identification.
57       */
58      public String getIdentification() {
59          return this.identification;
60      }
61  
62      /**
63       * <p>
64       * Getter for the field <code>name</code>.
65       * </p>
66       *
67       * @return Returns the name.
68       */
69      public String getName() {
70          return this.name;
71      }
72  
73      /**
74       * <p>
75       * Getter for the field <code>type</code>.
76       * </p>
77       *
78       * @return Returns the type.
79       */
80      public String getType() {
81          return this.type;
82      }
83  
84      /**
85       * <p>
86       * Getter for the field <code>uuid</code>.
87       * </p>
88       *
89       * @return Returns the uuid.
90       */
91      public String getUuid() {
92          return this.uuid;
93      }
94  
95      /**
96       * <p>
97       * Getter for the field <code>size</code>.
98       * </p>
99       *
100      * @return Returns the size in bytes.
101      */
102     public long getSize() {
103         return this.size;
104     }
105 
106     /**
107      * <p>
108      * Getter for the field <code>major</code>.
109      * </p>
110      *
111      * @return Returns the major device ID.
112      */
113     public int getMajor() {
114         return this.major;
115     }
116 
117     /**
118      * <p>
119      * Getter for the field <code>minor</code>.
120      * </p>
121      *
122      * @return Returns the minor device ID.
123      */
124     public int getMinor() {
125         return this.minor;
126     }
127 
128     /**
129      * <p>
130      * Getter for the field <code>mountPoint</code>.
131      * </p>
132      *
133      * @return Returns the mount point.
134      */
135     public String getMountPoint() {
136         return this.mountPoint;
137     }
138 
139     @Override
140     public String toString() {
141         StringBuilder sb = new StringBuilder();
142         sb.append(getIdentification()).append(": ");
143         sb.append(getName()).append(" ");
144         sb.append("(").append(getType()).append(") ");
145         sb.append("Maj:Min=").append(getMajor()).append(":").append(getMinor()).append(", ");
146         sb.append("size: ").append(FormatUtil.formatBytesDecimal(getSize()));
147         sb.append(getMountPoint().isEmpty() ? "" : " @ " + getMountPoint());
148         return sb.toString();
149     }
150 }