@@ -79,13 +79,29 @@ pub enum SeekFrom {
79
79
Current ( i64 ) ,
80
80
}
81
81
82
+ /// Called by the VFS when an inode should be opened.
83
+ ///
84
+ /// Calls `T::open` on the returned value of `A::convert`.
85
+ ///
86
+ /// # Safety
87
+ ///
88
+ /// The returned value of `A::convert` must be a valid non-null pointer and
89
+ /// `T:open` must return a valid non-null pointer on an `Ok` result.
82
90
unsafe extern "C" fn open_callback < A : FileOpenAdapter , T : FileOpener < A :: Arg > > (
83
91
inode : * mut bindings:: inode ,
84
92
file : * mut bindings:: file ,
85
93
) -> c_types:: c_int {
86
94
from_kernel_result ! {
95
+ // SAFETY: `A::convert` must return a valid non-null pointer that
96
+ // should point to data in the inode or file that lives longer
97
+ // than the following use of `T::open`.
87
98
let arg = unsafe { A :: convert( inode, file) } ;
99
+ // SAFETY: `arg` was previously returned by `A::convert` and must
100
+ // be a valid non-null pointer.
88
101
let ptr = T :: open( unsafe { & * arg } ) ?. into_pointer( ) ;
102
+ // SAFETY: `ptr` was previously returned by `T::open`. The returned
103
+ // value should be a boxed value and should live the length of the
104
+ // given file.
89
105
unsafe { ( * file) . private_data = ptr as * mut c_types:: c_void } ;
90
106
Ok ( 0 )
91
107
}
@@ -556,7 +572,8 @@ pub trait FileOpenAdapter {
556
572
/// # Safety
557
573
///
558
574
/// This function must be called only when [`struct file_operations::open`] is being called for
559
- /// a file that was registered by the implementer.
575
+ /// a file that was registered by the implementer. The returned pointer must be valid and
576
+ /// not-null.
560
577
unsafe fn convert ( _inode : * mut bindings:: inode , _file : * mut bindings:: file )
561
578
-> * const Self :: Arg ;
562
579
}
0 commit comments