@@ -79,7 +79,7 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
7979 0
8080}
8181
82- unsafe extern "C" fn llseek_callback < T : FileOperations > (
82+ unsafe extern "C" fn llseek_callback < T : Seek > (
8383 file : * mut bindings:: file ,
8484 offset : bindings:: loff_t ,
8585 whence : c_types:: c_int ,
@@ -106,7 +106,6 @@ impl FileOperationsVtable {
106106 bindings:: file_operations {
107107 open : Some ( open_callback :: < T > ) ,
108108 release : Some ( release_callback :: < T > ) ,
109- llseek : Some ( llseek_callback :: < T > ) ,
110109
111110 check_flags : None ,
112111 #[ cfg( not( kernel_4_20_0_or_greater) ) ]
@@ -127,6 +126,7 @@ impl FileOperationsVtable {
127126 iterate_shared : None ,
128127 #[ cfg( kernel_5_1_0_or_greater) ]
129128 iopoll : None ,
129+ llseek : None ,
130130 lock : None ,
131131 mmap : None ,
132132 #[ cfg( kernel_4_15_0_or_greater) ]
@@ -168,6 +168,13 @@ impl<T: Read> FileOperationsVtableBuilder<T> {
168168 }
169169}
170170
171+ impl < T : Seek > FileOperationsVtableBuilder < T > {
172+ pub const fn seek ( mut self ) -> FileOperationsVtableBuilder < T > {
173+ self . 0 . llseek = Some ( llseek_callback :: < T > ) ;
174+ self
175+ }
176+ }
177+
171178/// `FileOperations` corresponds to the kernel's `struct file_operations`. You
172179/// implement this trait whenever you'd create a `struct file_operations`, and
173180/// also an additional trait for each function pointer in the
@@ -184,16 +191,16 @@ pub trait FileOperations: Sync + Sized {
184191 /// Creates a new instance of this file. Corresponds to the `open` function
185192 /// pointer in `struct file_operations`.
186193 fn open ( ) -> KernelResult < Self > ;
187-
188- /// Changes the position of the file. Corresponds to the `llseek` function
189- /// pointer in `struct file_operations`.
190- fn seek ( & self , _file : & File , _offset : SeekFrom ) -> KernelResult < u64 > {
191- Err ( Error :: ESPIPE )
192- }
193194}
194195
195196pub trait Read {
196197 /// Reads data from this file to userspace. Corresponds to the `read`
197198 /// function pointer in `struct file_operations`.
198199 fn read ( & self , buf : & mut UserSlicePtrWriter , offset : u64 ) -> KernelResult < ( ) > ;
199200}
201+
202+ pub trait Seek {
203+ /// Changes the position of the file. Corresponds to the `llseek` function
204+ /// pointer in `struct file_operations`.
205+ fn seek ( & self , file : & File , offset : SeekFrom ) -> KernelResult < u64 > ;
206+ }
0 commit comments