pub struct LocalFile { /* private fields */ }Expand description
Wraps the kernel’s struct file. Not thread safe.
This type represents a file that is not known to be safe to transfer across thread boundaries.
To obtain a thread-safe File, use the assume_no_fdget_pos conversion.
See the documentation for File for more information.
§Invariants
- All instances of this type are refcounted using the
f_countfield. - If there is an active call to
fdget_posthat did not take thef_pos_lockmutex, then it must be on the same thread as this file.
Implementations§
Source§impl LocalFile
impl LocalFile
Sourcepub fn fget(fd: u32) -> Result<ARef<LocalFile>, BadFdError>
pub fn fget(fd: u32) -> Result<ARef<LocalFile>, BadFdError>
Constructs a new struct file wrapper from a file descriptor.
The file descriptor belongs to the current process, and there might be active local calls
to fdget_pos on the same file.
To obtain an ARef<File>, use the assume_no_fdget_pos function to convert.
Sourcepub unsafe fn from_raw_file<'a>(ptr: *const file) -> &'a LocalFile
pub unsafe fn from_raw_file<'a>(ptr: *const file) -> &'a LocalFile
Creates a reference to a LocalFile from a valid pointer.
§Safety
- The caller must ensure that
ptrpoints at a valid file and that the file’s refcount is positive for the duration of'a. - The caller must ensure that if there is an active call to
fdget_posthat did not take thef_pos_lockmutex, then that call is on the current thread.
Sourcepub unsafe fn assume_no_fdget_pos(me: ARef<LocalFile>) -> ARef<File>
pub unsafe fn assume_no_fdget_pos(me: ARef<LocalFile>) -> ARef<File>
Assume that there are no active fdget_pos calls that prevent us from sharing this file.
This makes it safe to transfer this file to other threads. No checks are performed, and using it incorrectly may lead to a data race on the file position if the file is shared with another thread.
This method is intended to be used together with LocalFile::fget when the caller knows
statically that there are no fdget_pos calls on the current thread. For example, you
might use it when calling fget from an ioctl, since ioctls usually do not touch the file
position.
§Safety
There must not be any active fdget_pos calls on the current thread.
Sourcepub fn cred(&self) -> &Credential
pub fn cred(&self) -> &Credential
Returns the credentials of the task that originally opened the file.