gio/auto/
unix_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, Icon};
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 UnixMountEntry(Boxed<ffi::GUnixMountEntry>);
13
14    match fn {
15        copy => |ptr| ffi::g_unix_mount_entry_copy(mut_override(ptr)),
16        free => |ptr| ffi::g_unix_mount_entry_free(ptr),
17        type_ => || ffi::g_unix_mount_entry_get_type(),
18    }
19}
20
21impl UnixMountEntry {
22    #[doc(alias = "g_unix_mount_entry_compare")]
23    fn compare(&self, mount2: &UnixMountEntry) -> 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 `GioUnix::MountPoint::get_options()`, but it takes
82    /// a `GioUnix::MountEntry` as an argument.
83    ///
84    /// # Returns
85    ///
86    /// a string containing the options, or `NULL` if not
87    ///    available.
88    #[cfg(feature = "v2_58")]
89    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
90    #[doc(alias = "g_unix_mount_entry_get_options")]
91    #[doc(alias = "get_options")]
92    pub fn options(&self) -> Option<glib::GString> {
93        unsafe {
94            from_glib_none(ffi::g_unix_mount_entry_get_options(mut_override(
95                self.to_glib_none().0,
96            )))
97        }
98    }
99
100    /// Gets the root of the mount within the filesystem. This is useful e.g. for
101    /// mounts created by bind operation, or btrfs subvolumes.
102    ///
103    /// For example, the root path is equal to `/` for a mount created by
104    /// `mount /dev/sda1 /mnt/foo` and `/bar` for
105    /// `mount --bind /mnt/foo/bar /mnt/bar`.
106    ///
107    /// # Returns
108    ///
109    /// a string containing the root, or `NULL` if not supported
110    #[cfg(feature = "v2_60")]
111    #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
112    #[doc(alias = "g_unix_mount_entry_get_root_path")]
113    #[doc(alias = "get_root_path")]
114    pub fn root_path(&self) -> Option<glib::GString> {
115        unsafe {
116            from_glib_none(ffi::g_unix_mount_entry_get_root_path(mut_override(
117                self.to_glib_none().0,
118            )))
119        }
120    }
121
122    /// Guesses whether a Unix mount entry can be ejected.
123    ///
124    /// # Returns
125    ///
126    /// true if @self is deemed to be ejectable; false otherwise
127    #[doc(alias = "g_unix_mount_entry_guess_can_eject")]
128    pub fn guess_can_eject(&self) -> bool {
129        unsafe {
130            from_glib(ffi::g_unix_mount_entry_guess_can_eject(mut_override(
131                self.to_glib_none().0,
132            )))
133        }
134    }
135
136    /// Guesses the icon of a Unix mount entry.
137    ///
138    /// # Returns
139    ///
140    /// a [`Icon`][crate::Icon]
141    #[doc(alias = "g_unix_mount_entry_guess_icon")]
142    pub fn guess_icon(&self) -> Icon {
143        unsafe {
144            from_glib_full(ffi::g_unix_mount_entry_guess_icon(mut_override(
145                self.to_glib_none().0,
146            )))
147        }
148    }
149
150    /// Guesses the name of a Unix mount entry.
151    ///
152    /// The result is a translated string.
153    ///
154    /// # Returns
155    ///
156    /// a newly allocated translated string
157    #[doc(alias = "g_unix_mount_entry_guess_name")]
158    pub fn guess_name(&self) -> glib::GString {
159        unsafe {
160            from_glib_full(ffi::g_unix_mount_entry_guess_name(mut_override(
161                self.to_glib_none().0,
162            )))
163        }
164    }
165
166    /// Guesses whether a Unix mount entry should be displayed in the UI.
167    ///
168    /// # Returns
169    ///
170    /// true if @self is deemed to be displayable; false otherwise
171    #[doc(alias = "g_unix_mount_entry_guess_should_display")]
172    pub fn guess_should_display(&self) -> bool {
173        unsafe {
174            from_glib(ffi::g_unix_mount_entry_guess_should_display(mut_override(
175                self.to_glib_none().0,
176            )))
177        }
178    }
179
180    /// Guesses the symbolic icon of a Unix mount entry.
181    ///
182    /// # Returns
183    ///
184    /// a [`Icon`][crate::Icon]
185    #[doc(alias = "g_unix_mount_entry_guess_symbolic_icon")]
186    pub fn guess_symbolic_icon(&self) -> Icon {
187        unsafe {
188            from_glib_full(ffi::g_unix_mount_entry_guess_symbolic_icon(mut_override(
189                self.to_glib_none().0,
190            )))
191        }
192    }
193
194    /// Checks if a Unix mount is mounted read only.
195    ///
196    /// # Returns
197    ///
198    /// true if @self is read only; false otherwise
199    #[doc(alias = "g_unix_mount_entry_is_readonly")]
200    pub fn is_readonly(&self) -> bool {
201        unsafe {
202            from_glib(ffi::g_unix_mount_entry_is_readonly(mut_override(
203                self.to_glib_none().0,
204            )))
205        }
206    }
207
208    /// Checks if a Unix mount is a system mount.
209    ///
210    /// This is the Boolean OR of
211    /// `is_system_fs_type()`, `is_system_device_path()` and
212    /// `is_mount_path_system_internal()` on @self’s properties.
213    ///
214    /// The definition of what a ‘system’ mount entry is may change over time as new
215    /// file system types and device paths are ignored.
216    ///
217    /// # Returns
218    ///
219    /// true if the Unix mount is for a system path; false otherwise
220    #[doc(alias = "g_unix_mount_entry_is_system_internal")]
221    pub fn is_system_internal(&self) -> bool {
222        unsafe {
223            from_glib(ffi::g_unix_mount_entry_is_system_internal(mut_override(
224                self.to_glib_none().0,
225            )))
226        }
227    }
228
229    /// Gets a `GioUnix::MountEntry` for a given mount path.
230    ///
231    /// If @time_read is set, it will be filled with a Unix timestamp for checking
232    /// if the mounts have changed since with
233    /// `mount_entries_changed_since()`.
234    ///
235    /// If more mounts have the same mount path, the last matching mount
236    /// is returned.
237    ///
238    /// This will return `NULL` if there is no mount point at @mount_path.
239    /// ## `mount_path`
240    /// path for a possible Unix mount
241    ///
242    /// # Returns
243    ///
244    /// a `GioUnix::MountEntry`
245    ///
246    /// ## `time_read`
247    /// return location for a timestamp
248    #[doc(alias = "g_unix_mount_entry_at")]
249    #[doc(alias = "at")]
250    pub fn for_mount_path(
251        mount_path: impl AsRef<std::path::Path>,
252    ) -> (Option<UnixMountEntry>, u64) {
253        unsafe {
254            let mut time_read = std::mem::MaybeUninit::uninit();
255            let ret = from_glib_full(ffi::g_unix_mount_entry_at(
256                mount_path.as_ref().to_glib_none().0,
257                time_read.as_mut_ptr(),
258            ));
259            (ret, time_read.assume_init())
260        }
261    }
262
263    /// Gets a `GioUnix::MountEntry` for a given file path.
264    ///
265    /// If @time_read is set, it will be filled with a Unix timestamp for checking
266    /// if the mounts have changed since with
267    /// `mount_entries_changed_since()`.
268    ///
269    /// If more mounts have the same mount path, the last matching mount
270    /// is returned.
271    ///
272    /// This will return `NULL` if looking up the mount entry fails, if
273    /// @file_path doesn’t exist or there is an I/O error.
274    /// ## `file_path`
275    /// file path on some Unix mount
276    ///
277    /// # Returns
278    ///
279    /// a `GioUnix::MountEntry`
280    ///
281    /// ## `time_read`
282    /// return location for a timestamp
283    #[doc(alias = "g_unix_mount_entry_for")]
284    #[doc(alias = "for")]
285    pub fn for_file_path(file_path: impl AsRef<std::path::Path>) -> (Option<UnixMountEntry>, u64) {
286        unsafe {
287            let mut time_read = std::mem::MaybeUninit::uninit();
288            let ret = from_glib_full(ffi::g_unix_mount_entry_for(
289                file_path.as_ref().to_glib_none().0,
290                time_read.as_mut_ptr(),
291            ));
292            (ret, time_read.assume_init())
293        }
294    }
295}
296
297impl PartialEq for UnixMountEntry {
298    #[inline]
299    fn eq(&self, other: &Self) -> bool {
300        self.compare(other) == 0
301    }
302}
303
304impl Eq for UnixMountEntry {}
305
306impl PartialOrd for UnixMountEntry {
307    #[inline]
308    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
309        Some(self.cmp(other))
310    }
311}
312
313impl Ord for UnixMountEntry {
314    #[inline]
315    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
316        self.compare(other).cmp(&0)
317    }
318}
319
320unsafe impl Send for UnixMountEntry {}
321unsafe impl Sync for UnixMountEntry {}