|
10 | 10 | //! For more documentation, please read
|
11 | 11 | //! [fanotify(7)](https://man7.org/linux/man-pages/man7/fanotify.7.html).
|
12 | 12 |
|
13 |
| -use crate::{NixPath, Result}; |
14 | 13 | use crate::errno::Errno;
|
15 |
| -use crate::fcntl::{OFlag, at_rawfd}; |
| 14 | +use crate::fcntl::{at_rawfd, OFlag}; |
16 | 15 | use crate::unistd::{close, read, write};
|
| 16 | +use crate::{NixPath, Result}; |
17 | 17 | use std::marker::PhantomData;
|
18 |
| -use std::mem::{MaybeUninit, size_of}; |
| 18 | +use std::mem::{size_of, MaybeUninit}; |
19 | 19 | use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
|
20 | 20 | use std::ptr;
|
21 | 21 |
|
@@ -288,11 +288,16 @@ impl Fanotify {
|
288 | 288 | /// Returns a Result containing a Fanotify instance.
|
289 | 289 | ///
|
290 | 290 | /// For more information, see [fanotify_init(2)](https://man7.org/linux/man-pages/man7/fanotify_init.2.html).
|
291 |
| - pub fn init(flags: InitFlags, event_f_flags: EventFFlags) -> Result<Fanotify> { |
| 291 | + pub fn init( |
| 292 | + flags: InitFlags, |
| 293 | + event_f_flags: EventFFlags, |
| 294 | + ) -> Result<Fanotify> { |
292 | 295 | let res = Errno::result(unsafe {
|
293 | 296 | libc::fanotify_init(flags.bits(), event_f_flags.bits())
|
294 | 297 | });
|
295 |
| - res.map(|fd| Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }}) |
| 298 | + res.map(|fd| Fanotify { |
| 299 | + fd: unsafe { OwnedFd::from_raw_fd(fd) }, |
| 300 | + }) |
296 | 301 | }
|
297 | 302 |
|
298 | 303 | /// Add, remove, or modify an fanotify mark on a filesystem object.
|
@@ -386,22 +391,21 @@ impl Fanotify {
|
386 | 391 | /// available on a group that has been initialized with the flag
|
387 | 392 | /// `InitFlags::FAN_NONBLOCK`, thus making this method nonblocking.
|
388 | 393 | pub fn write_response(&self, response: FanotifyResponse) -> Result<()> {
|
389 |
| - write( |
390 |
| - self.fd.as_fd(), |
391 |
| - unsafe { |
392 |
| - std::slice::from_raw_parts( |
393 |
| - (&response.inner as *const libc::fanotify_response).cast(), |
394 |
| - size_of::<libc::fanotify_response>(), |
395 |
| - ) |
396 |
| - }, |
397 |
| - )?; |
| 394 | + write(self.fd.as_fd(), unsafe { |
| 395 | + std::slice::from_raw_parts( |
| 396 | + (&response.inner as *const libc::fanotify_response).cast(), |
| 397 | + size_of::<libc::fanotify_response>(), |
| 398 | + ) |
| 399 | + })?; |
398 | 400 | Ok(())
|
399 | 401 | }
|
400 | 402 | }
|
401 | 403 |
|
402 | 404 | impl FromRawFd for Fanotify {
|
403 | 405 | unsafe fn from_raw_fd(fd: RawFd) -> Self {
|
404 |
| - Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }} |
| 406 | + Fanotify { |
| 407 | + fd: unsafe { OwnedFd::from_raw_fd(fd) }, |
| 408 | + } |
405 | 409 | }
|
406 | 410 | }
|
407 | 411 |
|
|
0 commit comments