5
5
//! C header: [`include/linux/fs.h`](../../../../include/linux/fs.h)
6
6
7
7
use core:: convert:: { TryFrom , TryInto } ;
8
- use core:: { marker, mem, ops :: Deref , ptr} ;
8
+ use core:: { marker, mem, ptr} ;
9
9
10
10
use alloc:: boxed:: Box ;
11
11
@@ -122,7 +122,7 @@ unsafe extern "C" fn read_callback<T: FileOperations>(
122
122
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
123
123
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
124
124
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
125
- let read = T :: read( & f, unsafe { & FileRef :: from_ptr( file) } , & mut data, unsafe { * offset } . try_into( ) ?) ?;
125
+ let read = T :: read( f, unsafe { & FileRef :: from_ptr( file) } , & mut data, unsafe { * offset } . try_into( ) ?) ?;
126
126
unsafe { ( * offset) += bindings:: loff_t:: try_from( read) . unwrap( ) } ;
127
127
Ok ( read as _)
128
128
}
@@ -141,7 +141,7 @@ unsafe extern "C" fn read_iter_callback<T: FileOperations>(
141
141
// callback, which the C API guarantees that will be called only when all references to
142
142
// `file` have been released, so we know it can't be called while this function is running.
143
143
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
144
- let read = T :: read( & f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
144
+ let read = T :: read( f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
145
145
unsafe { ( * iocb) . ki_pos += bindings:: loff_t:: try_from( read) . unwrap( ) } ;
146
146
Ok ( read as _)
147
147
}
@@ -162,7 +162,7 @@ unsafe extern "C" fn write_callback<T: FileOperations>(
162
162
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
163
163
// No `FMODE_UNSIGNED_OFFSET` support, so `offset` must be in [0, 2^63).
164
164
// See discussion in https://github.com/fishinabarrel/linux-kernel-module-rust/pull/113
165
- let written = T :: write( & f, unsafe { & FileRef :: from_ptr( file) } , & mut data, unsafe { * offset } . try_into( ) ?) ?;
165
+ let written = T :: write( f, unsafe { & FileRef :: from_ptr( file) } , & mut data, unsafe { * offset } . try_into( ) ?) ?;
166
166
unsafe { ( * offset) += bindings:: loff_t:: try_from( written) . unwrap( ) } ;
167
167
Ok ( written as _)
168
168
}
@@ -181,7 +181,7 @@ unsafe extern "C" fn write_iter_callback<T: FileOperations>(
181
181
// callback, which the C API guarantees that will be called only when all references to
182
182
// `file` have been released, so we know it can't be called while this function is running.
183
183
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
184
- let written = T :: write( & f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
184
+ let written = T :: write( f, unsafe { & FileRef :: from_ptr( file) } , & mut iter, offset. try_into( ) ?) ?;
185
185
unsafe { ( * iocb) . ki_pos += bindings:: loff_t:: try_from( written) . unwrap( ) } ;
186
186
Ok ( written as _)
187
187
}
@@ -215,7 +215,7 @@ unsafe extern "C" fn llseek_callback<T: FileOperations>(
215
215
// callback, which the C API guarantees that will be called only when all references to
216
216
// `file` have been released, so we know it can't be called while this function is running.
217
217
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
218
- let off = T :: seek( & f, unsafe { & FileRef :: from_ptr( file) } , off) ?;
218
+ let off = T :: seek( f, unsafe { & FileRef :: from_ptr( file) } , off) ?;
219
219
Ok ( off as bindings:: loff_t)
220
220
}
221
221
}
@@ -232,7 +232,7 @@ unsafe extern "C" fn unlocked_ioctl_callback<T: FileOperations>(
232
232
// `file` have been released, so we know it can't be called while this function is running.
233
233
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
234
234
let mut cmd = IoctlCommand :: new( cmd as _, arg as _) ;
235
- let ret = T :: ioctl( & f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
235
+ let ret = T :: ioctl( f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
236
236
Ok ( ret as _)
237
237
}
238
238
}
@@ -249,7 +249,7 @@ unsafe extern "C" fn compat_ioctl_callback<T: FileOperations>(
249
249
// `file` have been released, so we know it can't be called while this function is running.
250
250
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
251
251
let mut cmd = IoctlCommand :: new( cmd as _, arg as _) ;
252
- let ret = T :: compat_ioctl( & f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
252
+ let ret = T :: compat_ioctl( f, unsafe { & FileRef :: from_ptr( file) } , & mut cmd) ?;
253
253
Ok ( ret as _)
254
254
}
255
255
}
@@ -264,7 +264,7 @@ unsafe extern "C" fn mmap_callback<T: FileOperations>(
264
264
// callback, which the C API guarantees that will be called only when all references to
265
265
// `file` have been released, so we know it can't be called while this function is running.
266
266
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
267
- T :: mmap( & f, unsafe { & FileRef :: from_ptr( file) } , unsafe { & mut * vma } ) ?;
267
+ T :: mmap( f, unsafe { & FileRef :: from_ptr( file) } , unsafe { & mut * vma } ) ?;
268
268
Ok ( 0 )
269
269
}
270
270
}
@@ -284,7 +284,7 @@ unsafe extern "C" fn fsync_callback<T: FileOperations>(
284
284
// callback, which the C API guarantees that will be called only when all references to
285
285
// `file` have been released, so we know it can't be called while this function is running.
286
286
let f = unsafe { T :: Wrapper :: borrow( ( * file) . private_data) } ;
287
- let res = T :: fsync( & f, unsafe { & FileRef :: from_ptr( file) } , start, end, datasync) ?;
287
+ let res = T :: fsync( f, unsafe { & FileRef :: from_ptr( file) } , start, end, datasync) ?;
288
288
Ok ( res. try_into( ) . unwrap( ) )
289
289
}
290
290
}
@@ -298,7 +298,7 @@ unsafe extern "C" fn poll_callback<T: FileOperations>(
298
298
// callback, which the C API guarantees that will be called only when all references to `file`
299
299
// have been released, so we know it can't be called while this function is running.
300
300
let f = unsafe { T :: Wrapper :: borrow ( ( * file) . private_data ) } ;
301
- match T :: poll ( & f, unsafe { & FileRef :: from_ptr ( file) } , unsafe {
301
+ match T :: poll ( f, unsafe { & FileRef :: from_ptr ( file) } , unsafe {
302
302
& PollTable :: from_ptr ( wait)
303
303
} ) {
304
304
Ok ( v) => v,
@@ -463,17 +463,17 @@ macro_rules! declare_file_operations {
463
463
/// For each macro, there is a handler function that takes the appropriate types as arguments.
464
464
pub trait IoctlHandler : Sync {
465
465
/// The type of the first argument to each associated function.
466
- type Target ;
466
+ type Target < ' a > ;
467
467
468
468
/// Handles ioctls defined with the `_IO` macro, that is, with no buffer as argument.
469
- fn pure ( _this : & Self :: Target , _file : & File , _cmd : u32 , _arg : usize ) -> Result < i32 > {
469
+ fn pure ( _this : Self :: Target < ' _ > , _file : & File , _cmd : u32 , _arg : usize ) -> Result < i32 > {
470
470
Err ( Error :: EINVAL )
471
471
}
472
472
473
473
/// Handles ioctls defined with the `_IOR` macro, that is, with an output buffer provided as
474
474
/// argument.
475
475
fn read (
476
- _this : & Self :: Target ,
476
+ _this : Self :: Target < ' _ > ,
477
477
_file : & File ,
478
478
_cmd : u32 ,
479
479
_writer : & mut UserSlicePtrWriter ,
@@ -484,7 +484,7 @@ pub trait IoctlHandler: Sync {
484
484
/// Handles ioctls defined with the `_IOW` macro, that is, with an input buffer provided as
485
485
/// argument.
486
486
fn write (
487
- _this : & Self :: Target ,
487
+ _this : Self :: Target < ' _ > ,
488
488
_file : & File ,
489
489
_cmd : u32 ,
490
490
_reader : & mut UserSlicePtrReader ,
@@ -495,7 +495,7 @@ pub trait IoctlHandler: Sync {
495
495
/// Handles ioctls defined with the `_IOWR` macro, that is, with a buffer for both input and
496
496
/// output provided as argument.
497
497
fn read_write (
498
- _this : & Self :: Target ,
498
+ _this : Self :: Target < ' _ > ,
499
499
_file : & File ,
500
500
_cmd : u32 ,
501
501
_data : UserSlicePtr ,
@@ -535,7 +535,11 @@ impl IoctlCommand {
535
535
///
536
536
/// It is meant to be used in implementations of [`FileOperations::ioctl`] and
537
537
/// [`FileOperations::compat_ioctl`].
538
- pub fn dispatch < T : IoctlHandler > ( & mut self , handler : & T :: Target , file : & File ) -> Result < i32 > {
538
+ pub fn dispatch < T : IoctlHandler > (
539
+ & mut self ,
540
+ handler : T :: Target < ' _ > ,
541
+ file : & File ,
542
+ ) -> Result < i32 > {
539
543
let dir = ( self . cmd >> bindings:: _IOC_DIRSHIFT) & bindings:: _IOC_DIRMASK;
540
544
if dir == bindings:: _IOC_NONE {
541
545
return T :: pure ( handler, file, self . cmd , self . arg ) ;
@@ -604,7 +608,7 @@ impl<T: FileOperations<Wrapper = Box<T>> + Default> FileOpener<()> for T {
604
608
/// File descriptors may be used from multiple threads/processes concurrently, so your type must be
605
609
/// [`Sync`]. It must also be [`Send`] because [`FileOperations::release`] will be called from the
606
610
/// thread that decrements that associated file's refcount to zero.
607
- pub trait FileOperations : Send + Sync + Sized {
611
+ pub trait FileOperations : Send + Sync + Sized + ' static {
608
612
/// The methods to use to populate [`struct file_operations`].
609
613
const TO_USE : ToUse ;
610
614
@@ -623,7 +627,7 @@ pub trait FileOperations: Send + Sync + Sized {
623
627
///
624
628
/// Corresponds to the `read` and `read_iter` function pointers in `struct file_operations`.
625
629
fn read (
626
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
630
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
627
631
_file : & File ,
628
632
_data : & mut impl IoBufferWriter ,
629
633
_offset : u64 ,
@@ -635,7 +639,7 @@ pub trait FileOperations: Send + Sync + Sized {
635
639
///
636
640
/// Corresponds to the `write` and `write_iter` function pointers in `struct file_operations`.
637
641
fn write (
638
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
642
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
639
643
_file : & File ,
640
644
_data : & mut impl IoBufferReader ,
641
645
_offset : u64 ,
@@ -647,7 +651,7 @@ pub trait FileOperations: Send + Sync + Sized {
647
651
///
648
652
/// Corresponds to the `llseek` function pointer in `struct file_operations`.
649
653
fn seek (
650
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
654
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
651
655
_file : & File ,
652
656
_offset : SeekFrom ,
653
657
) -> Result < u64 > {
@@ -658,7 +662,7 @@ pub trait FileOperations: Send + Sync + Sized {
658
662
///
659
663
/// Corresponds to the `unlocked_ioctl` function pointer in `struct file_operations`.
660
664
fn ioctl (
661
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
665
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
662
666
_file : & File ,
663
667
_cmd : & mut IoctlCommand ,
664
668
) -> Result < i32 > {
@@ -669,7 +673,7 @@ pub trait FileOperations: Send + Sync + Sized {
669
673
///
670
674
/// Corresponds to the `compat_ioctl` function pointer in `struct file_operations`.
671
675
fn compat_ioctl (
672
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
676
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
673
677
_file : & File ,
674
678
_cmd : & mut IoctlCommand ,
675
679
) -> Result < i32 > {
@@ -680,7 +684,7 @@ pub trait FileOperations: Send + Sync + Sized {
680
684
///
681
685
/// Corresponds to the `fsync` function pointer in `struct file_operations`.
682
686
fn fsync (
683
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
687
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
684
688
_file : & File ,
685
689
_start : u64 ,
686
690
_end : u64 ,
@@ -694,7 +698,7 @@ pub trait FileOperations: Send + Sync + Sized {
694
698
/// Corresponds to the `mmap` function pointer in `struct file_operations`.
695
699
/// TODO: wrap `vm_area_struct` so that we don't have to expose it.
696
700
fn mmap (
697
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
701
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
698
702
_file : & File ,
699
703
_vma : & mut bindings:: vm_area_struct ,
700
704
) -> Result {
@@ -706,7 +710,7 @@ pub trait FileOperations: Send + Sync + Sized {
706
710
///
707
711
/// Corresponds to the `poll` function pointer in `struct file_operations`.
708
712
fn poll (
709
- _this : & << Self :: Wrapper as PointerWrapper >:: Borrowed as Deref > :: Target ,
713
+ _this : < Self :: Wrapper as PointerWrapper >:: Borrowed < ' _ > ,
710
714
_file : & File ,
711
715
_table : & PollTable ,
712
716
) -> Result < u32 > {
0 commit comments