heim_disk/os/windows/
partitions.rs

1use winapi::shared::minwindef::DWORD;
2use winapi::um::winnt;
3
4/// Windows-specific drive type.
5#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
6pub enum DriveType {
7    /// CD-ROM drive
8    CdRom,
9    /// Drive is fixed media; for example, a hard disk drive or a flash drive
10    Fixed,
11    /// The root path is invalid; for example, there is no volume mounted at the specified path.
12    NoRootDir,
13    /// RAM disk
14    RamDisk,
15    /// Drive is a remote (network) disk
16    Remote,
17    /// Drive has removable media; for example, a floppy drive, thumb drive, or flash card reader.
18    Removable,
19}
20
21bitflags::bitflags! {
22    /// Windows volume file system flags.
23    ///
24    /// Reference: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getvolumeinformationw
25    pub struct Flags: DWORD {
26        /// The specified volume supports preserved case of file names when it places a name on disk.
27        const FILE_CASE_PRESERVED_NAMES = winnt::FILE_CASE_PRESERVED_NAMES;
28
29        /// The specified volume supports case-sensitive file names.
30        const FILE_CASE_SENSITIVE_SEARCH = winnt::FILE_CASE_SENSITIVE_SEARCH;
31
32        /// The specified volume is a direct access (DAX) volume.
33        const FILE_DAX_VOLUME = winnt::FILE_DAX_VOLUME;
34
35        /// The specified volume supports file-based compression.
36        const FILE_FILE_COMPRESSION = winnt::FILE_FILE_COMPRESSION;
37
38        /// The specified volume supports named streams.
39        const FILE_NAMED_STREAMS = winnt::FILE_NAMED_STREAMS;
40
41        /// The specified volume preserves and enforces access control lists (ACL).
42        const FILE_PERSISTENT_ACLS = winnt::FILE_PERSISTENT_ACLS;
43
44        /// The specified volume is read-only.
45        const FILE_READ_ONLY_VOLUME = winnt::FILE_READ_ONLY_VOLUME;
46
47        /// The specified volume supports a single sequential write.
48        const FILE_SEQUENTIAL_WRITE_ONCE = winnt::FILE_SEQUENTIAL_WRITE_ONCE;
49
50        /// The specified volume supports the Encrypted File System (EFS).
51        const FILE_SUPPORTS_ENCRYPTION = winnt::FILE_SUPPORTS_ENCRYPTION;
52
53        /// The specified volume supports extended attributes.
54        const FILE_SUPPORTS_EXTENDED_ATTRIBUTES = winnt::FILE_SUPPORTS_EXTENDED_ATTRIBUTES;
55
56        /// The specified volume supports hard links. For more information, see Hard Links and Junctions.
57        const FILE_SUPPORTS_HARD_LINKS = winnt::FILE_SUPPORTS_HARD_LINKS;
58
59        /// The specified volume supports object identifiers.
60        const FILE_SUPPORTS_OBJECT_IDS = winnt::FILE_SUPPORTS_OBJECT_IDS;
61
62        /// The file system supports open by FileID.
63        const FILE_SUPPORTS_OPEN_BY_FILE_ID = winnt::FILE_SUPPORTS_OPEN_BY_FILE_ID;
64
65        /// The specified volume supports reparse points.
66        const FILE_SUPPORTS_REPARSE_POINTS = winnt::FILE_SUPPORTS_REPARSE_POINTS;
67
68        /// The specified volume supports sparse files.
69        const FILE_SUPPORTS_SPARSE_FILES = winnt::FILE_SUPPORTS_SPARSE_FILES;
70
71        /// The specified volume supports transactions.
72        const FILE_SUPPORTS_TRANSACTIONS = winnt::FILE_SUPPORTS_TRANSACTIONS;
73
74        /// The specified volume supports update sequence number (USN) journals.
75        const FILE_SUPPORTS_USN_JOURNAL = winnt::FILE_SUPPORTS_USN_JOURNAL;
76
77        /// The specified volume supports Unicode in file names as they appear on disk.
78        const FILE_UNICODE_ON_DISK = winnt::FILE_UNICODE_ON_DISK;
79
80        /// The specified volume is a compressed volume, for example, a DoubleSpace volume.
81        const FILE_VOLUME_IS_COMPRESSED = winnt::FILE_VOLUME_IS_COMPRESSED;
82
83        /// The specified volume supports disk quotas.
84        const FILE_VOLUME_QUOTAS = winnt::FILE_VOLUME_QUOTAS;
85    }
86}
87
88/// Extension for [Partition] struct.
89///
90/// [Partition]: ../../struct.Partition.html
91pub trait PartitionExt {
92    /// Gets mount flags for this partition.
93    fn flags(&self) -> Flags;
94
95    /// Get drive type for this partition, if can be determined.
96    fn drive_type(&self) -> Option<DriveType>;
97}
98
99#[cfg(target_os = "windows")]
100impl PartitionExt for crate::Partition {
101    fn flags(&self) -> Flags {
102        self.as_ref().flags()
103    }
104
105    fn drive_type(&self) -> Option<DriveType> {
106        self.as_ref().drive_type()
107    }
108}