@@ -79,7 +79,7 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
79
79
0
80
80
}
81
81
82
- unsafe extern "C" fn llseek_callback < T : FileOperations > (
82
+ unsafe extern "C" fn llseek_callback < T : Seek > (
83
83
file : * mut bindings:: file ,
84
84
offset : bindings:: loff_t ,
85
85
whence : c_types:: c_int ,
@@ -106,7 +106,6 @@ impl FileOperationsVtable {
106
106
bindings:: file_operations {
107
107
open : Some ( open_callback :: < T > ) ,
108
108
release : Some ( release_callback :: < T > ) ,
109
- llseek : Some ( llseek_callback :: < T > ) ,
110
109
111
110
check_flags : None ,
112
111
#[ cfg( not( kernel_4_20_0_or_greater) ) ]
@@ -127,6 +126,7 @@ impl FileOperationsVtable {
127
126
iterate_shared : None ,
128
127
#[ cfg( kernel_5_1_0_or_greater) ]
129
128
iopoll : None ,
129
+ llseek : None ,
130
130
lock : None ,
131
131
mmap : None ,
132
132
#[ cfg( kernel_4_15_0_or_greater) ]
@@ -168,6 +168,13 @@ impl<T: Read> FileOperationsVtableBuilder<T> {
168
168
}
169
169
}
170
170
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
+
171
178
/// `FileOperations` corresponds to the kernel's `struct file_operations`. You
172
179
/// implement this trait whenever you'd create a `struct file_operations`, and
173
180
/// also an additional trait for each function pointer in the
@@ -184,16 +191,16 @@ pub trait FileOperations: Sync + Sized {
184
191
/// Creates a new instance of this file. Corresponds to the `open` function
185
192
/// pointer in `struct file_operations`.
186
193
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
- }
193
194
}
194
195
195
196
pub trait Read {
196
197
/// Reads data from this file to userspace. Corresponds to the `read`
197
198
/// function pointer in `struct file_operations`.
198
199
fn read ( & self , buf : & mut UserSlicePtrWriter , offset : u64 ) -> KernelResult < ( ) > ;
199
200
}
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