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    /// Checks if a Unix mount is a system mount.
205    ///
206    /// This is the Boolean OR of
207    /// [`is_system_fs_type()`][crate::is_system_fs_type()], [`is_system_device_path()`][crate::is_system_device_path()] and
208    /// [`is_mount_path_system_internal()`][crate::is_mount_path_system_internal()] on @self’s properties.
209    ///
210    /// The definition of what a ‘system’ mount entry is may change over time as new
211    /// file system types and device paths are ignored.
212    ///
213    /// # Returns
214    ///
215    /// true if the Unix mount is for a system path; false otherwise
216    #[doc(alias = "g_unix_mount_entry_is_system_internal")]
217    pub fn is_system_internal(&self) -> bool {
218        unsafe {
219            from_glib(ffi::g_unix_mount_entry_is_system_internal(mut_override(
220                self.to_glib_none().0,
221            )))
222        }
223    }
224
225    /// Gets a [`MountEntry`][crate::MountEntry] for a given mount path.
226    ///
227    /// If @time_read is set, it will be filled with a Unix timestamp for checking
228    /// if the mounts have changed since with
229    /// [`mount_entries_changed_since()`][crate::mount_entries_changed_since()].
230    ///
231    /// If more mounts have the same mount path, the last matching mount
232    /// is returned.
233    ///
234    /// This will return `NULL` if there is no mount point at @mount_path.
235    /// ## `mount_path`
236    /// path for a possible Unix mount
237    ///
238    /// # Returns
239    ///
240    /// a [`MountEntry`][crate::MountEntry]
241    ///
242    /// ## `time_read`
243    /// return location for a timestamp
244    #[doc(alias = "g_unix_mount_entry_at")]
245    #[doc(alias = "at")]
246    pub fn for_mount_path(mount_path: impl AsRef<std::path::Path>) -> (Option<MountEntry>, u64) {
247        unsafe {
248            let mut time_read = std::mem::MaybeUninit::uninit();
249            let ret = from_glib_full(ffi::g_unix_mount_entry_at(
250                mount_path.as_ref().to_glib_none().0,
251                time_read.as_mut_ptr(),
252            ));
253            (ret, time_read.assume_init())
254        }
255    }
256
257    /// Gets a [`MountEntry`][crate::MountEntry] for a given file path.
258    ///
259    /// If @time_read is set, it will be filled with a Unix timestamp for checking
260    /// if the mounts have changed since with
261    /// [`mount_entries_changed_since()`][crate::mount_entries_changed_since()].
262    ///
263    /// If more mounts have the same mount path, the last matching mount
264    /// is returned.
265    ///
266    /// This will return `NULL` if looking up the mount entry fails, if
267    /// @file_path doesn’t exist or there is an I/O error.
268    /// ## `file_path`
269    /// file path on some Unix mount
270    ///
271    /// # Returns
272    ///
273    /// a [`MountEntry`][crate::MountEntry]
274    ///
275    /// ## `time_read`
276    /// return location for a timestamp
277    #[doc(alias = "g_unix_mount_entry_for")]
278    #[doc(alias = "for")]
279    pub fn for_file_path(file_path: impl AsRef<std::path::Path>) -> (Option<MountEntry>, u64) {
280        unsafe {
281            let mut time_read = std::mem::MaybeUninit::uninit();
282            let ret = from_glib_full(ffi::g_unix_mount_entry_for(
283                file_path.as_ref().to_glib_none().0,
284                time_read.as_mut_ptr(),
285            ));
286            (ret, time_read.assume_init())
287        }
288    }
289}
290
291impl PartialEq for MountEntry {
292    #[inline]
293    fn eq(&self, other: &Self) -> bool {
294        self.compare(other) == 0
295    }
296}
297
298impl Eq for MountEntry {}
299
300impl PartialOrd for MountEntry {
301    #[inline]
302    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
303        Some(self.cmp(other))
304    }
305}
306
307impl Ord for MountEntry {
308    #[inline]
309    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
310        self.compare(other).cmp(&0)
311    }
312}
313
314unsafe impl Send for MountEntry {}
315unsafe impl Sync for MountEntry {}