Skip to main content

gio_unix/auto/
mount_entry.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// Defines a Unix mount entry (e.g. `/media/cdrom`).
10    /// This corresponds roughly to a mtab entry.
11    #[derive(Debug)]
12    pub struct MountEntry(Boxed<ffi::GUnixMountEntry>);
13
14    match fn {
15        copy => |ptr| ffi::g_unix_mount_entry_copy(ptr),
16        free => |ptr| ffi::g_unix_mount_entry_free(ptr),
17        type_ => || ffi::g_unix_mount_entry_get_type(),
18    }
19}
20
21impl MountEntry {
22    #[doc(alias = "g_unix_mount_entry_compare")]
23    fn compare(&self, mount2: &MountEntry) -> i32 {
24        unsafe {
25            ffi::g_unix_mount_entry_compare(
26                mut_override(self.to_glib_none().0),
27                mut_override(mount2.to_glib_none().0),
28            )
29        }
30    }
31
32    /// Gets the device path for a Unix mount.
33    ///
34    /// # Returns
35    ///
36    /// a string containing the device path
37    #[doc(alias = "g_unix_mount_entry_get_device_path")]
38    #[doc(alias = "get_device_path")]
39    pub fn device_path(&self) -> std::path::PathBuf {
40        unsafe {
41            from_glib_none(ffi::g_unix_mount_entry_get_device_path(mut_override(
42                self.to_glib_none().0,
43            )))
44        }
45    }
46
47    /// Gets the filesystem type for the Unix mount.
48    ///
49    /// # Returns
50    ///
51    /// a string containing the file system type
52    #[doc(alias = "g_unix_mount_entry_get_fs_type")]
53    #[doc(alias = "get_fs_type")]
54    pub fn fs_type(&self) -> glib::GString {
55        unsafe {
56            from_glib_none(ffi::g_unix_mount_entry_get_fs_type(mut_override(
57                self.to_glib_none().0,
58            )))
59        }
60    }
61
62    /// Gets the mount path for a Unix mount.
63    ///
64    /// # Returns
65    ///
66    /// the mount path for @self
67    #[doc(alias = "g_unix_mount_entry_get_mount_path")]
68    #[doc(alias = "get_mount_path")]
69    pub fn mount_path(&self) -> std::path::PathBuf {
70        unsafe {
71            from_glib_none(ffi::g_unix_mount_entry_get_mount_path(mut_override(
72                self.to_glib_none().0,
73            )))
74        }
75    }
76
77    /// Gets a comma separated list of mount options for the Unix mount.
78    ///
79    /// For example: `rw,relatime,seclabel,data=ordered`.
80    ///
81    /// This is similar to [`MountPoint::options()`][crate::MountPoint::options()], but it takes
82    /// a [`MountEntry`][crate::MountEntry] as an argument.
83    ///
84    /// # Returns
85    ///
86    /// a string containing the options, or `NULL` if not
87    ///    available.
88    #[doc(alias = "g_unix_mount_entry_get_options")]
89    #[doc(alias = "get_options")]
90    pub fn options(&self) -> Option<glib::GString> {
91        unsafe {
92            from_glib_none(ffi::g_unix_mount_entry_get_options(mut_override(
93                self.to_glib_none().0,
94            )))
95        }
96    }
97
98    /// Gets the root of the mount within the filesystem. This is useful e.g. for
99    /// mounts created by bind operation, or btrfs subvolumes.
100    ///
101    /// For example, the root path is equal to `/` for a mount created by
102    /// `mount /dev/sda1 /mnt/foo` and `/bar` for
103    /// `mount --bind /mnt/foo/bar /mnt/bar`.
104    ///
105    /// # Returns
106    ///
107    /// a string containing the root, or `NULL` if not supported
108    #[doc(alias = "g_unix_mount_entry_get_root_path")]
109    #[doc(alias = "get_root_path")]
110    pub fn root_path(&self) -> Option<glib::GString> {
111        unsafe {
112            from_glib_none(ffi::g_unix_mount_entry_get_root_path(mut_override(
113                self.to_glib_none().0,
114            )))
115        }
116    }
117
118    /// Guesses whether a Unix mount entry can be ejected.
119    ///
120    /// # Returns
121    ///
122    /// true if @self is deemed to be ejectable; false otherwise
123    #[doc(alias = "g_unix_mount_entry_guess_can_eject")]
124    pub fn guess_can_eject(&self) -> bool {
125        unsafe {
126            from_glib(ffi::g_unix_mount_entry_guess_can_eject(mut_override(
127                self.to_glib_none().0,
128            )))
129        }
130    }
131
132    /// Guesses the icon of a Unix mount entry.
133    ///
134    /// # Returns
135    ///
136    /// a [`gio::Icon`][crate::gio::Icon]
137    #[doc(alias = "g_unix_mount_entry_guess_icon")]
138    pub fn guess_icon(&self) -> gio::Icon {
139        unsafe {
140            from_glib_full(ffi::g_unix_mount_entry_guess_icon(mut_override(
141                self.to_glib_none().0,
142            )))
143        }
144    }
145
146    /// Guesses the name of a Unix mount entry.
147    ///
148    /// The result is a translated string.
149    ///
150    /// # Returns
151    ///
152    /// a newly allocated translated string
153    #[doc(alias = "g_unix_mount_entry_guess_name")]
154    pub fn guess_name(&self) -> glib::GString {
155        unsafe {
156            from_glib_full(ffi::g_unix_mount_entry_guess_name(mut_override(
157                self.to_glib_none().0,
158            )))
159        }
160    }
161
162    /// Guesses whether a Unix mount entry should be displayed in the UI.
163    ///
164    /// # Returns
165    ///
166    /// true if @self is deemed to be displayable; false otherwise
167    #[doc(alias = "g_unix_mount_entry_guess_should_display")]
168    pub fn guess_should_display(&self) -> bool {
169        unsafe {
170            from_glib(ffi::g_unix_mount_entry_guess_should_display(mut_override(
171                self.to_glib_none().0,
172            )))
173        }
174    }
175
176    /// Guesses the symbolic icon of a Unix mount entry.
177    ///
178    /// # Returns
179    ///
180    /// a [`gio::Icon`][crate::gio::Icon]
181    #[doc(alias = "g_unix_mount_entry_guess_symbolic_icon")]
182    pub fn guess_symbolic_icon(&self) -> gio::Icon {
183        unsafe {
184            from_glib_full(ffi::g_unix_mount_entry_guess_symbolic_icon(mut_override(
185                self.to_glib_none().0,
186            )))
187        }
188    }
189
190    /// Checks if a Unix mount is mounted read only.
191    ///
192    /// # Returns
193    ///
194    /// true if @self is read only; false otherwise
195    #[doc(alias = "g_unix_mount_entry_is_readonly")]
196    pub fn is_readonly(&self) -> bool {
197        unsafe {
198            from_glib(ffi::g_unix_mount_entry_is_readonly(mut_override(
199                self.to_glib_none().0,
200            )))
201        }
202    }
203
204    ///  mount entry is may change over time as new
205    /// file system types and device paths are ignored.
206    ///
207    /// # Returns
208    ///
209    /// true if the Unix mount is for a system path; false otherwise
210    #[doc(alias = "g_unix_mount_entry_is_system_internal")]
211    pub fn is_system_internal(&self) -> bool {
212        unsafe {
213            from_glib(ffi::g_unix_mount_entry_is_system_internal(mut_override(
214                self.to_glib_none().0,
215            )))
216        }
217    }
218
219    /// Gets a [`MountEntry`][crate::MountEntry] for a given mount path.
220    ///
221    /// If @time_read is set, it will be filled with a Unix timestamp for checking
222    /// if the mounts have changed since with
223    /// [`mount_entries_changed_since()`][crate::mount_entries_changed_since()].
224    ///
225    /// If more mounts have the same mount path, the last matching mount
226    /// is returned.
227    ///
228    /// This will return `NULL` if there is no mount point at @mount_path.
229    /// ## `mount_path`
230    /// path for a possible Unix mount
231    ///
232    /// # Returns
233    ///
234    /// a [`MountEntry`][crate::MountEntry]
235    ///
236    /// ## `time_read`
237    /// return location for a timestamp
238    #[doc(alias = "g_unix_mount_entry_at")]
239    #[doc(alias = "at")]
240    pub fn for_mount_path(mount_path: impl AsRef<std::path::Path>) -> (Option<MountEntry>, u64) {
241        unsafe {
242            let mut time_read = std::mem::MaybeUninit::uninit();
243            let ret = from_glib_full(ffi::g_unix_mount_entry_at(
244                mount_path.as_ref().to_glib_none().0,
245                time_read.as_mut_ptr(),
246            ));
247            (ret, time_read.assume_init())
248        }
249    }
250
251    /// t exist or there is an I/O error.
252    /// ## `file_path`
253    /// file path on some Unix mount
254    ///
255    /// # Returns
256    ///
257    /// a [`MountEntry`][crate::MountEntry]
258    ///
259    /// ## `time_read`
260    /// return location for a timestamp
261    #[doc(alias = "g_unix_mount_entry_for")]
262    #[doc(alias = "for")]
263    pub fn for_file_path(file_path: impl AsRef<std::path::Path>) -> (Option<MountEntry>, u64) {
264        unsafe {
265            let mut time_read = std::mem::MaybeUninit::uninit();
266            let ret = from_glib_full(ffi::g_unix_mount_entry_for(
267                file_path.as_ref().to_glib_none().0,
268                time_read.as_mut_ptr(),
269            ));
270            (ret, time_read.assume_init())
271        }
272    }
273}
274
275impl PartialEq for MountEntry {
276    #[inline]
277    fn eq(&self, other: &Self) -> bool {
278        self.compare(other) == 0
279    }
280}
281
282impl Eq for MountEntry {}
283
284impl PartialOrd for MountEntry {
285    #[inline]
286    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
287        Some(self.cmp(other))
288    }
289}
290
291impl Ord for MountEntry {
292    #[inline]
293    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
294        self.compare(other).cmp(&0)
295    }
296}
297
298unsafe impl Send for MountEntry {}
299unsafe impl Sync for MountEntry {}