@@ -43,7 +43,7 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
43
43
0
44
44
}
45
45
46
- unsafe extern "C" fn read_callback < T : FileOperations > (
46
+ unsafe extern "C" fn read_callback < T : Read > (
47
47
file : * mut bindings:: file ,
48
48
buf : * mut c_types:: c_char ,
49
49
len : c_types:: c_size_t ,
@@ -105,7 +105,6 @@ impl FileOperationsVtable {
105
105
FileOperationsVtableBuilder (
106
106
bindings:: file_operations {
107
107
open : Some ( open_callback :: < T > ) ,
108
- read : Some ( read_callback :: < T > ) ,
109
108
release : Some ( release_callback :: < T > ) ,
110
109
llseek : Some ( llseek_callback :: < T > ) ,
111
110
@@ -134,6 +133,7 @@ impl FileOperationsVtable {
134
133
mmap_supported_flags : 0 ,
135
134
owner : ptr:: null_mut ( ) ,
136
135
poll : None ,
136
+ read : None ,
137
137
read_iter : None ,
138
138
#[ cfg( kernel_4_20_0_or_greater) ]
139
139
remap_file_range : None ,
@@ -161,10 +161,18 @@ impl<T> FileOperationsVtableBuilder<T> {
161
161
}
162
162
}
163
163
164
+ impl < T : Read > FileOperationsVtableBuilder < T > {
165
+ pub const fn read ( mut self ) -> FileOperationsVtableBuilder < T > {
166
+ self . 0 . read = Some ( read_callback :: < T > ) ;
167
+ self
168
+ }
169
+ }
170
+
164
171
/// `FileOperations` corresponds to the kernel's `struct file_operations`. You
165
- /// implement this trait whenever you'd create a `struct file_operations`. File
166
- /// descriptors may be used from multiple threads (or processes) concurrently,
167
- /// so your type must be `Sync`.
172
+ /// implement this trait whenever you'd create a `struct file_operations`, and
173
+ /// also an additional trait for each function pointer in the
174
+ /// `struct file_operations`. File descriptors may be used from multiple threads
175
+ /// (or processes) concurrently, so your type must be `Sync`.
168
176
pub trait FileOperations : Sync + Sized {
169
177
/// A container for the actual `file_operations` value. This will always be:
170
178
/// ```
@@ -177,15 +185,15 @@ pub trait FileOperations: Sync + Sized {
177
185
/// pointer in `struct file_operations`.
178
186
fn open ( ) -> KernelResult < Self > ;
179
187
180
- /// Reads data from this file to userspace. Corresponds to the `read`
181
- /// function pointer in `struct file_operations`.
182
- fn read ( & self , _buf : & mut UserSlicePtrWriter , _offset : u64 ) -> KernelResult < ( ) > {
183
- Err ( Error :: EINVAL )
184
- }
185
-
186
188
/// Changes the position of the file. Corresponds to the `llseek` function
187
189
/// pointer in `struct file_operations`.
188
190
fn seek ( & self , _file : & File , _offset : SeekFrom ) -> KernelResult < u64 > {
189
191
Err ( Error :: ESPIPE )
190
192
}
191
193
}
194
+
195
+ pub trait Read {
196
+ /// Reads data from this file to userspace. Corresponds to the `read`
197
+ /// function pointer in `struct file_operations`.
198
+ fn read ( & self , buf : & mut UserSlicePtrWriter , offset : u64 ) -> KernelResult < ( ) > ;
199
+ }
0 commit comments