@@ -121,11 +121,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
121
121
from_kernel_result ! {
122
122
let mut data = unsafe { UserSlicePtr :: new( buf as * mut c_types:: c_void, len) . writer( ) } ;
123
123
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
124
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
124
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
125
125
// `release` callback, which the C API guarantees that will be called only when all
126
126
// references to `file` have been released, so we know it can't be called while this
127
127
// function is running.
128
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
128
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
129
129
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
130
130
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
131
131
let read = T :: read(
@@ -148,11 +148,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
148
148
let file = unsafe { ( * iocb) . ki_filp } ;
149
149
let offset = unsafe { ( * iocb) . ki_pos } ;
150
150
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
151
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
151
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
152
152
// `release` callback, which the C API guarantees that will be called only when all
153
153
// references to `file` have been released, so we know it can't be called while this
154
154
// function is running.
155
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
155
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
156
156
let read =
157
157
T :: read( f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
158
158
unsafe { ( * iocb) . ki_pos += bindings:: loff_t:: try_from( read) . unwrap( ) } ;
@@ -169,11 +169,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
169
169
from_kernel_result ! {
170
170
let mut data = unsafe { UserSlicePtr :: new( buf as * mut c_types:: c_void, len) . reader( ) } ;
171
171
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
172
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
172
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
173
173
// `release` callback, which the C API guarantees that will be called only when all
174
174
// references to `file` have been released, so we know it can't be called while this
175
175
// function is running.
176
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
176
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
177
177
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
178
178
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
179
179
let written = T :: write(
@@ -196,11 +196,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
196
196
let file = unsafe { ( * iocb) . ki_filp } ;
197
197
let offset = unsafe { ( * iocb) . ki_pos } ;
198
198
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
199
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
199
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
200
200
// `release` callback, which the C API guarantees that will be called only when all
201
201
// references to `file` have been released, so we know it can't be called while this
202
202
// function is running.
203
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
203
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
204
204
let written =
205
205
T :: write( f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
206
206
unsafe { ( * iocb) . ki_pos += bindings:: loff_t:: try_from( written) . unwrap( ) } ;
@@ -213,7 +213,7 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
213
213
file : * mut bindings:: file ,
214
214
) -> c_types:: c_int {
215
215
let ptr = mem:: replace ( unsafe { & mut ( * file) . private_data } , ptr:: null_mut ( ) ) ;
216
- T :: release ( unsafe { T :: Wrapper :: from_pointer ( ptr as _ ) } , unsafe {
216
+ T :: release ( unsafe { T :: Data :: from_pointer ( ptr as _ ) } , unsafe {
217
217
& FileRef :: from_ptr ( file)
218
218
} ) ;
219
219
0
@@ -232,11 +232,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
232
232
_ => return Err ( Error :: EINVAL ) ,
233
233
} ;
234
234
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
235
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
235
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
236
236
// `release` callback, which the C API guarantees that will be called only when all
237
237
// references to `file` have been released, so we know it can't be called while this
238
238
// function is running.
239
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
239
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
240
240
let off = T :: seek( f, unsafe { & FileRef :: from_ptr( file) } , off) ?;
241
241
Ok ( off as bindings:: loff_t)
242
242
}
@@ -249,11 +249,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
249
249
) -> c_types:: c_long {
250
250
from_kernel_result ! {
251
251
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
252
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
252
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
253
253
// `release` callback, which the C API guarantees that will be called only when all
254
254
// references to `file` have been released, so we know it can't be called while this
255
255
// function is running.
256
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
256
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
257
257
let mut cmd = IoctlCommand :: new( cmd as _, arg as _) ;
258
258
let ret = T :: ioctl( f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
259
259
Ok ( ret as _)
@@ -267,11 +267,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
267
267
) -> c_types:: c_long {
268
268
from_kernel_result ! {
269
269
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
270
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
270
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
271
271
// `release` callback, which the C API guarantees that will be called only when all
272
272
// references to `file` have been released, so we know it can't be called while this
273
273
// function is running.
274
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
274
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
275
275
let mut cmd = IoctlCommand :: new( cmd as _, arg as _) ;
276
276
let ret = T :: compat_ioctl( f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
277
277
Ok ( ret as _)
@@ -284,11 +284,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
284
284
) -> c_types:: c_int {
285
285
from_kernel_result ! {
286
286
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
287
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
287
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
288
288
// `release` callback, which the C API guarantees that will be called only when all
289
289
// references to `file` have been released, so we know it can't be called while this
290
290
// function is running.
291
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
291
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
292
292
293
293
// SAFETY: The C API guarantees that `vma` is valid for the duration of this call.
294
294
// `area` only lives within this call, so it is guaranteed to be valid.
@@ -312,11 +312,11 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
312
312
let end = end. try_into( ) ?;
313
313
let datasync = datasync != 0 ;
314
314
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
315
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the
315
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the
316
316
// `release` callback, which the C API guarantees that will be called only when all
317
317
// references to `file` have been released, so we know it can't be called while this
318
318
// function is running.
319
- let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
319
+ let f = unsafe { T :: Data :: borrow( ( * file) . private_data) } ;
320
320
let res = T :: fsync( f, unsafe { & FileRef :: from_ptr( file) } , start, end, datasync) ?;
321
321
Ok ( res. try_into( ) . unwrap( ) )
322
322
}
@@ -327,10 +327,10 @@ impl<A: FileOpenAdapter<T::OpenData>, T: FileOperations> FileOperationsVtable<A,
327
327
wait : * mut bindings:: poll_table_struct ,
328
328
) -> bindings:: __poll_t {
329
329
// SAFETY: `private_data` was initialised by `open_callback` with a value returned by
330
- // `T::Wrapper ::into_pointer`. `T::Wrapper ::from_pointer` is only called by the `release`
330
+ // `T::Data ::into_pointer`. `T::Data ::from_pointer` is only called by the `release`
331
331
// callback, which the C API guarantees that will be called only when all references to
332
332
// `file` have been released, so we know it can't be called while this function is running.
333
- let f = unsafe { T :: Wrapper :: borrow ( ( * file) . private_data ) } ;
333
+ let f = unsafe { T :: Data :: borrow ( ( * file) . private_data ) } ;
334
334
match T :: poll ( f, unsafe { & FileRef :: from_ptr ( file) } , unsafe {
335
335
& PollTable :: from_ptr ( wait)
336
336
} ) {
@@ -619,32 +619,33 @@ pub trait FileOperations {
619
619
/// The methods to use to populate [`struct file_operations`].
620
620
const TO_USE : ToUse ;
621
621
622
- /// The pointer type that will be used to hold ourselves.
623
- type Wrapper : PointerWrapper + Send + Sync = ( ) ;
622
+ /// The type of the context data returned by [`FileOperations::open`] and made available to
623
+ /// other methods.
624
+ type Data : PointerWrapper + Send + Sync = ( ) ;
624
625
625
626
/// The type of the context data passed to [`FileOperations::open`].
626
627
type OpenData : Sync = ( ) ;
627
628
628
629
/// Creates a new instance of this file.
629
630
///
630
631
/// Corresponds to the `open` function pointer in `struct file_operations`.
631
- fn open ( context : & Self :: OpenData , file : & File ) -> Result < Self :: Wrapper > ;
632
+ fn open ( context : & Self :: OpenData , file : & File ) -> Result < Self :: Data > ;
632
633
633
634
/// Cleans up after the last reference to the file goes away.
634
635
///
635
- /// Note that the object is moved, so it will be freed automatically unless the implementation
636
- /// moves it elsewhere.
636
+ /// Note that context data is moved, so it will be freed automatically unless the
637
+ /// implementation moves it elsewhere.
637
638
///
638
639
/// Corresponds to the `release` function pointer in `struct file_operations`.
639
- fn release ( _obj : Self :: Wrapper , _file : & File ) { }
640
+ fn release ( _data : Self :: Data , _file : & File ) { }
640
641
641
642
/// Reads data from this file to the caller's buffer.
642
643
///
643
644
/// Corresponds to the `read` and `read_iter` function pointers in `struct file_operations`.
644
645
fn read (
645
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
646
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
646
647
_file : & File ,
647
- _data : & mut impl IoBufferWriter ,
648
+ _writer : & mut impl IoBufferWriter ,
648
649
_offset : u64 ,
649
650
) -> Result < usize > {
650
651
Err ( Error :: EINVAL )
@@ -654,9 +655,9 @@ pub trait FileOperations {
654
655
///
655
656
/// Corresponds to the `write` and `write_iter` function pointers in `struct file_operations`.
656
657
fn write (
657
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
658
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
658
659
_file : & File ,
659
- _data : & mut impl IoBufferReader ,
660
+ _reader : & mut impl IoBufferReader ,
660
661
_offset : u64 ,
661
662
) -> Result < usize > {
662
663
Err ( Error :: EINVAL )
@@ -666,7 +667,7 @@ pub trait FileOperations {
666
667
///
667
668
/// Corresponds to the `llseek` function pointer in `struct file_operations`.
668
669
fn seek (
669
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
670
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
670
671
_file : & File ,
671
672
_offset : SeekFrom ,
672
673
) -> Result < u64 > {
@@ -677,7 +678,7 @@ pub trait FileOperations {
677
678
///
678
679
/// Corresponds to the `unlocked_ioctl` function pointer in `struct file_operations`.
679
680
fn ioctl (
680
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
681
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
681
682
_file : & File ,
682
683
_cmd : & mut IoctlCommand ,
683
684
) -> Result < i32 > {
@@ -688,7 +689,7 @@ pub trait FileOperations {
688
689
///
689
690
/// Corresponds to the `compat_ioctl` function pointer in `struct file_operations`.
690
691
fn compat_ioctl (
691
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
692
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
692
693
_file : & File ,
693
694
_cmd : & mut IoctlCommand ,
694
695
) -> Result < i32 > {
@@ -699,7 +700,7 @@ pub trait FileOperations {
699
700
///
700
701
/// Corresponds to the `fsync` function pointer in `struct file_operations`.
701
702
fn fsync (
702
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
703
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
703
704
_file : & File ,
704
705
_start : u64 ,
705
706
_end : u64 ,
@@ -711,9 +712,8 @@ pub trait FileOperations {
711
712
/// Maps areas of the caller's virtual memory with device/file memory.
712
713
///
713
714
/// Corresponds to the `mmap` function pointer in `struct file_operations`.
714
- /// TODO: Wrap `vm_area_struct` so that we don't have to expose it.
715
715
fn mmap (
716
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
716
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
717
717
_file : & File ,
718
718
_vma : & mut mm:: virt:: Area ,
719
719
) -> Result {
@@ -725,7 +725,7 @@ pub trait FileOperations {
725
725
///
726
726
/// Corresponds to the `poll` function pointer in `struct file_operations`.
727
727
fn poll (
728
- _this : <Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
728
+ _data : <Self :: Data as PointerWrapper >:: Borrowed < ' _ > ,
729
729
_file : & File ,
730
730
_table : & PollTable ,
731
731
) -> Result < u32 > {
0 commit comments