Debian Codegraph @

src/collection/disks/unix/linux/partition.rs

raw symbols SCIP
1 //! Implementation based on [heim's](https://github.com/heim-rs/heim)
2 //! Unix disk usage.
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
5 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#,
6 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#,
7 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#},
8 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/,
9 pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#},
10 strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#,
11 };
12
13 use anyhowrust-analyzer cargo anyhow 1.0.104 crate/::bailrust-analyzer cargo anyhow 1.0.104 macros/bail!;
14
15 use craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::disksrust-analyzer cargo bottom 0.14.9 collection/disks/::unixrust-analyzer cargo bottom 0.14.9 collection/disks/unix/::{FileSystemrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/FileSystem#, Usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/Usage#};
16
17 /// Representation of partition details. Based on [`heim`](https://github.com/heim-rs/heim/tree/master).
18 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition# {
19 devicerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#device.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
20 mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#mount_point.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
21 fs_typerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#fs_type.: FileSystemrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/FileSystem#,
22 }
23
24 impl Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition# {
25 /// Returns the device name, if there is one.
26 #[inline]
27 pub fn devicerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]device().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str> {
28 self.devicerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#device..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().()
29 }
30
31 /// Returns the mount point for this partition.
32 #[inline]
33 pub fn mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]mount_point().(&self) -> &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path# {
34 self.mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#mount_point..as_pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]as_path().()
35 }
36
37 /// Returns the [`FileSystem`] of this partition.
38 #[inline]
39 pub fn fs_typerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]fs_type().(&self) -> &FileSystemrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/FileSystem# {
40 &self.fs_typerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#fs_type.
41 }
42
43 /// Returns the device name for the partition.
44 pub fn get_device_namerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]get_device_name().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
45 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(device) = self.devicerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]device().() {
46 // See if this disk is actually mounted elsewhere on Linux. This is a workaround
47 // properly map I/O in some cases (i.e. disk encryption, https://github.com/ClementTsang/bottom/issues/419).
48 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(path) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_linkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_link().(device) {
49 if path.is_absoluterust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_absolute().() {
50 path.into_os_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]into_os_string().()
51 .into_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]into_string().()
52 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| "Name Unavailable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
53 } else {
54 let mut combined_path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]new().();
55 combined_path.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]push().(device);
56 combined_path.poprust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]pop().(); // Pop the current file...
57 combined_path.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]push().(path);
58
59 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(canon_path) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::canonicalizerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/canonicalize().(combined_path) {
60 // Resolve the local path into an absolute one...
61 canon_path
62 .into_os_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]into_os_string().()
63 .into_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]into_string().()
64 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| "Name Unavailable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
65 } else {
66 device.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
67 }
68 }
69 } else {
70 device.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
71 }
72 } else {
73 "Name Unavailable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
74 }
75 }
76
77 /// Returns the usage stats for this partition.
78 pub fn usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]usage().(&self) -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#<Usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/Usage#> {
79 // TODO: This might be unoptimal.
80 let path = self
81 .mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#mount_point.
82 .to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().()
83 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#))
84 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|string| {
85 CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(string).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#))
86 })
87 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| anyhowrust-analyzer cargo anyhow 1.0.104 crate/::anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!("invalid path: {e:?}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
88
89 let mut vfs = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<libcrust-analyzer cargo libc 0.2.189 crate/::statvfsrust-analyzer cargo libc 0.2.189 unix/linux_like/linux/gnu/b64/x86_64/not_x32/statvfs#>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
90
91 // SAFETY: libc call, `path` is a valid C string and buf is a valid pointer to
92 // write to.
93 let result = unsafe { libcrust-analyzer cargo libc 0.2.189 crate/::statvfsrust-analyzer cargo libc 0.2.189 statvfs().(path.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), vfs.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().()) };
94
95 if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 {
96 // SAFETY: If result is 0, it succeeded, and vfs should be non-null.
97 let vfs = unsafe { vfs.assume_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]assume_init().() };
98 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/Usage#::newrust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/impl#[Usage]new().(vfs))
99 } else {
100 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(anyhowrust-analyzer cargo anyhow 1.0.104 crate/::anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!(
101 "statvfs had an issue getting info from {path:?}"
102 ))
103 }
104 }
105 }
106
107 fn fix_mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/fix_mount_point().(s: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
108 const ESCAPED_BACKSLASHrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_BACKSLASH.: &str = "\\134";
109 const ESCAPED_SPACErust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_SPACE.: &str = "\\040";
110 const ESCAPED_TABrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_TAB.: &str = "\\011";
111 const ESCAPED_NEWLINErust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_NEWLINE.: &str = "\\012";
112
113 s.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(ESCAPED_BACKSLASHrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_BACKSLASH., "\\")
114 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(ESCAPED_SPACErust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_SPACE., " ")
115 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(ESCAPED_TABrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_TAB., "\t")
116 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(ESCAPED_NEWLINErust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/ESCAPED_NEWLINE., "\n")
117 }
118
119 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition# {
120 type Errrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition][FromStr]Err# = anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Errorrust-analyzer cargo anyhow 1.0.104 Error#;
121
122 fn from_strrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition][FromStr]from_str().(line: &str) -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#<Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#> {
123 // Example: `/dev/sda3 /home ext4 rw,relatime,data=ordered 0 0`
124 let mut parts = line.trim_startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start().().splitnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]splitn().(5, ' ');
125
126 let device = match parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().() {
127 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("none") => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
128 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(device) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(device.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
129 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
130 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("missing device");
131 }
132 };
133
134 let mount_point = match parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().() {
135 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mount_point) => PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<String>`]from().(fix_mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/fix_mount_point().(mount_point)),
136 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
137 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("missing mount point");
138 }
139 };
140 let fs_type = match parts.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitN<'a, P>`][Iterator]next().() {
141 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fs) => FileSystemrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/FileSystem#::from_strrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/impl#[FileSystem][FromStr]from_str().(fs)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
142 _ => {
143 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("missing filesystem type");
144 }
145 };
146
147 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition# {
148 devicerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#device.,
149 mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#mount_point.,
150 fs_typerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#fs_type.,
151 })
152 }
153 }
154
155 #[expect(dead_code)]
156 /// Returns a [`Vec`] containing all partitions.
157 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn partitionsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/partitions().() -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#>> {
158 const PROC_MOUNTSrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/PROC_MOUNTS.: &str = "/proc/mounts";
159
160 let mut results = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
161 let mut reader = BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(PROC_MOUNTSrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/PROC_MOUNTS.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
162 let mut line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
163
164 // This saves us from doing a string allocation on each iteration compared to
165 // `lines()`.
166 while let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes) = reader.read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#read_line().(&mut line) {
167 if bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
168 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(partition) = Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#::from_strrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition][FromStr]from_str().(&line) {
169 results.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(partition);
170 }
171
172 line.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
173 } else {
174 break;
175 }
176 }
177
178 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(results)
179 }
180
181 /// Returns a [`Vec`] containing all *physical* partitions. This is defined by
182 /// [`FileSystem::is_physical()`].
183 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn physical_partitionsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/physical_partitions().() -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#>> {
184 const PROC_MOUNTSrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/PROC_MOUNTS.: &str = "/proc/mounts";
185
186 let mut results = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
187 let mut reader = BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(PROC_MOUNTSrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/PROC_MOUNTS.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
188 let mut line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
189
190 // This saves us from doing a string allocation on each iteration compared to
191 // `lines()`.
192 while let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes) = reader.read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#read_line().(&mut line) {
193 if bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
194 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(partition) = Partitionrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/Partition#::from_strrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition][FromStr]from_str().(&line)
195 && partition.fs_typerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]fs_type().().is_physicalrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/impl#[FileSystem]is_physical().()
196 {
197 results.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(partition);
198 }
199
200 line.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
201 } else {
202 break;
203 }
204 }
205
206 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(results)
207 }
208
209 #[cfg(test)]
210 mod testsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/tests/ {
211 use superrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/::*;
212
213 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
214 fn test_fix_mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/tests/test_fix_mount_point().() {
215 let line = "/run/media/test/Samsung\\040980";
216
217 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(fix_mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/fix_mount_point().(line), "/run/media/test/Samsung 980");
218 }
219 }