| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/}; |
| 2 | |
| 3 | use craterust-analyzer cargo udevrs 0.4.0 crate/::{Errorrust-analyzer cargo udevrs 0.4.0 error/Error#, Resultrust-analyzer cargo udevrs 0.4.0 error/Result#}; |
| 4 | |
| 5 | /// Represents an FFI type from `fcntl.h` for a `file_handle`. |
| 6 | #[repr(C)] |
| 7 | #[allow(non_snake_case)] |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 9 | pub struct file_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle# { |
| 10 | handle_bytesrust-analyzer cargo udevrs 0.4.0 file/file_handle#handle_bytes.: u8, |
| 11 | handle_typerust-analyzer cargo udevrs 0.4.0 file/file_handle#handle_type.: i32, |
| 12 | f_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle#f_handle.: *mut u8, |
| 13 | } |
| 14 | |
| 15 | impl file_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle# { |
| 16 | /// Creates a new [file_handle]. |
| 17 | pub const fn newrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]new().() -> Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle] { |
| 18 | Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle] { |
| 19 | handle_bytesrust-analyzer cargo udevrs 0.4.0 file/file_handle#handle_bytes.: 0, |
| 20 | handle_typerust-analyzer cargo udevrs 0.4.0 file/file_handle#handle_type.: 0, |
| 21 | f_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle#f_handle.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(), |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | pub fn as_ptrrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_ptr().(&self) -> *const Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle] { |
| 26 | self as *const _ |
| 27 | } |
| 28 | |
| 29 | pub fn as_void_ptrrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_void_ptr().(&self) -> *const ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void# { |
| 30 | self.as_ptrrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_ptr().() as *const _ |
| 31 | } |
| 32 | |
| 33 | pub fn as_ptr_mutrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_ptr_mut().(&mut self) -> *mut Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle] { |
| 34 | self as *mut _ |
| 35 | } |
| 36 | |
| 37 | pub fn as_void_ptr_mutrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_void_ptr_mut().(&mut self) -> *mut ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void# { |
| 38 | self.as_ptr_mutrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_ptr_mut().() as *mut _ |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for file_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle# { |
| 43 | fn defaultrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle][Default]default().() -> Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle][Default] { |
| 44 | Selfrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle][Default]::newrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]new().() |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// Wrapper around a syscall that returns an opaque handle that corresponds to a specified file. |
| 49 | pub fn name_to_handle_atrust-analyzer cargo udevrs 0.4.0 file/name_to_handle_at().( |
| 50 | dir_fd: i32, |
| 51 | path: &str, |
| 52 | handle: &mut file_handlerust-analyzer cargo udevrs 0.4.0 file/file_handle#, |
| 53 | mount_id: &mut i32, |
| 54 | flags: i32, |
| 55 | ) -> Resultrust-analyzer cargo udevrs 0.4.0 error/Result#<()> { |
| 56 | let path_str = 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#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 | |
| 58 | // SAFETY: parameters are initialized properly, and pointers reference valid memory. |
| 59 | let ret = unsafe { |
| 60 | libcrust-analyzer cargo libc 0.2.169 crate/::syscallrust-analyzer cargo libc 0.2.169 syscall().( |
| 61 | libcrust-analyzer cargo libc 0.2.169 crate/::SYS_name_to_handle_atrust-analyzer cargo libc 0.2.169 unix/linux_like/linux/gnu/b64/x86_64/not_x32/SYS_name_to_handle_at., |
| 62 | dir_fd, |
| 63 | path_str.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), |
| 64 | handle.as_void_ptr_mutrust-analyzer cargo udevrs 0.4.0 file/impl#[file_handle]as_void_ptr_mut().(), |
| 65 | mount_id as *mut i32, |
| 66 | flags, |
| 67 | ) |
| 68 | }; |
| 69 | |
| 70 | if ret rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().0 { |
| 71 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 72 | } else { |
| 73 | let errno = 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#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 74 | let errmsg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error calling `name_to_handle_at`, ret: {ret}, errno: {errno}"); |
| 75 | |
| 76 | logrust-analyzer cargo log 0.4.25 crate/::warnrust-analyzer cargo log 0.4.25 macros/warn!!("{errmsg}"); |
| 77 | |
| 78 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo udevrs 0.4.0 error/Error#::Iorust-analyzer cargo udevrs 0.4.0 error/Error#Io#(errmsg)) |
| 79 | } |
| 80 | } |