mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
get and create a FileDescriptor from the fd (#43)
This commit is contained in:
committed by
GitHub
parent
c1b7009a7b
commit
5f1e03911f
@@ -1,6 +1,6 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
use std::{io::SeekFrom, pin::Pin};
|
use std::{io::SeekFrom, marker::PhantomPinned, pin::Pin};
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite};
|
||||||
|
|
||||||
@@ -13,8 +13,25 @@ pub struct FileDescriptor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FileDescriptor<'a> {
|
impl<'a> FileDescriptor<'a> {
|
||||||
pub(crate) fn new(inner: Pin<Box<InnerFileDescriptor<'a>>>) -> Self {
|
/// create a new FileDescriptor from a raw fd
|
||||||
Self { inner }
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// make sure the fd is an opened file, and that you got it from a previous
|
||||||
|
/// FileDescriptor via `as_raw_fd()` method
|
||||||
|
pub unsafe fn new(client: &'a mut super::AfcClient, fd: u64, path: String) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: Box::pin(InnerFileDescriptor {
|
||||||
|
client,
|
||||||
|
fd,
|
||||||
|
path,
|
||||||
|
pending_fut: None,
|
||||||
|
_m: PhantomPinned,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_raw_fd(&self) -> u64 {
|
||||||
|
self.inner.fd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl FileDescriptor<'_> {
|
impl FileDescriptor<'_> {
|
||||||
|
|||||||
@@ -44,17 +44,6 @@ pub(crate) struct InnerFileDescriptor<'a> {
|
|||||||
pub(crate) _m: std::marker::PhantomPinned,
|
pub(crate) _m: std::marker::PhantomPinned,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InnerFileDescriptor<'a> {
|
|
||||||
pub(crate) fn new(client: &'a mut super::AfcClient, fd: u64, path: String) -> Pin<Box<Self>> {
|
|
||||||
Box::pin(Self {
|
|
||||||
client,
|
|
||||||
fd,
|
|
||||||
path,
|
|
||||||
pending_fut: None,
|
|
||||||
_m: std::marker::PhantomPinned,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl InnerFileDescriptor<'_> {
|
impl InnerFileDescriptor<'_> {
|
||||||
/// Generic helper to send an AFC packet and read the response
|
/// Generic helper to send an AFC packet and read the response
|
||||||
pub async fn send_packet(
|
pub async fn send_packet(
|
||||||
|
|||||||
@@ -410,9 +410,9 @@ impl AfcClient {
|
|||||||
return Err(IdeviceError::UnexpectedResponse);
|
return Err(IdeviceError::UnexpectedResponse);
|
||||||
}
|
}
|
||||||
let fd = u64::from_le_bytes(res.header_payload[..8].try_into().unwrap());
|
let fd = u64::from_le_bytes(res.header_payload[..8].try_into().unwrap());
|
||||||
Ok(FileDescriptor::new(inner_file::InnerFileDescriptor::new(
|
|
||||||
self, fd, path,
|
// we know it's a valid fd
|
||||||
)))
|
Ok(unsafe { FileDescriptor::new(self, fd, path) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a hard or symbolic link
|
/// Creates a hard or symbolic link
|
||||||
|
|||||||
Reference in New Issue
Block a user