|
1 | 1 | use core::convert::{TryFrom, TryInto}; |
2 | | -use core::{mem, ptr}; |
| 2 | +use core::{marker, mem, ptr}; |
3 | 3 |
|
4 | 4 | use alloc::boxed::Box; |
5 | 5 |
|
@@ -101,52 +101,63 @@ unsafe extern "C" fn llseek_callback<T: FileOperations>( |
101 | 101 | } |
102 | 102 |
|
103 | 103 | impl FileOperationsVtable { |
104 | | - pub const fn new<T: FileOperations>() -> FileOperationsVtable { |
105 | | - FileOperationsVtable(bindings::file_operations { |
106 | | - open: Some(open_callback::<T>), |
107 | | - read: Some(read_callback::<T>), |
108 | | - release: Some(release_callback::<T>), |
109 | | - llseek: Some(llseek_callback::<T>), |
110 | | - |
111 | | - check_flags: None, |
112 | | - #[cfg(not(kernel_4_20_0_or_greater))] |
113 | | - clone_file_range: None, |
114 | | - compat_ioctl: None, |
115 | | - copy_file_range: None, |
116 | | - #[cfg(not(kernel_4_20_0_or_greater))] |
117 | | - dedupe_file_range: None, |
118 | | - fallocate: None, |
119 | | - #[cfg(kernel_4_19_0_or_greater)] |
120 | | - fadvise: None, |
121 | | - fasync: None, |
122 | | - flock: None, |
123 | | - flush: None, |
124 | | - fsync: None, |
125 | | - get_unmapped_area: None, |
126 | | - iterate: None, |
127 | | - iterate_shared: None, |
128 | | - #[cfg(kernel_5_1_0_or_greater)] |
129 | | - iopoll: None, |
130 | | - lock: None, |
131 | | - mmap: None, |
132 | | - #[cfg(kernel_4_15_0_or_greater)] |
133 | | - mmap_supported_flags: 0, |
134 | | - owner: ptr::null_mut(), |
135 | | - poll: None, |
136 | | - read_iter: None, |
137 | | - #[cfg(kernel_4_20_0_or_greater)] |
138 | | - remap_file_range: None, |
139 | | - sendpage: None, |
140 | | - #[cfg(kernel_aufs_setfl)] |
141 | | - setfl: None, |
142 | | - setlease: None, |
143 | | - show_fdinfo: None, |
144 | | - splice_read: None, |
145 | | - splice_write: None, |
146 | | - unlocked_ioctl: None, |
147 | | - write: None, |
148 | | - write_iter: None, |
149 | | - }) |
| 104 | + pub const fn builder<T: FileOperations>() -> FileOperationsVtableBuilder<T> { |
| 105 | + FileOperationsVtableBuilder( |
| 106 | + bindings::file_operations { |
| 107 | + open: Some(open_callback::<T>), |
| 108 | + read: Some(read_callback::<T>), |
| 109 | + release: Some(release_callback::<T>), |
| 110 | + llseek: Some(llseek_callback::<T>), |
| 111 | + |
| 112 | + check_flags: None, |
| 113 | + #[cfg(not(kernel_4_20_0_or_greater))] |
| 114 | + clone_file_range: None, |
| 115 | + compat_ioctl: None, |
| 116 | + copy_file_range: None, |
| 117 | + #[cfg(not(kernel_4_20_0_or_greater))] |
| 118 | + dedupe_file_range: None, |
| 119 | + fallocate: None, |
| 120 | + #[cfg(kernel_4_19_0_or_greater)] |
| 121 | + fadvise: None, |
| 122 | + fasync: None, |
| 123 | + flock: None, |
| 124 | + flush: None, |
| 125 | + fsync: None, |
| 126 | + get_unmapped_area: None, |
| 127 | + iterate: None, |
| 128 | + iterate_shared: None, |
| 129 | + #[cfg(kernel_5_1_0_or_greater)] |
| 130 | + iopoll: None, |
| 131 | + lock: None, |
| 132 | + mmap: None, |
| 133 | + #[cfg(kernel_4_15_0_or_greater)] |
| 134 | + mmap_supported_flags: 0, |
| 135 | + owner: ptr::null_mut(), |
| 136 | + poll: None, |
| 137 | + read_iter: None, |
| 138 | + #[cfg(kernel_4_20_0_or_greater)] |
| 139 | + remap_file_range: None, |
| 140 | + sendpage: None, |
| 141 | + #[cfg(kernel_aufs_setfl)] |
| 142 | + setfl: None, |
| 143 | + setlease: None, |
| 144 | + show_fdinfo: None, |
| 145 | + splice_read: None, |
| 146 | + splice_write: None, |
| 147 | + unlocked_ioctl: None, |
| 148 | + write: None, |
| 149 | + write_iter: None, |
| 150 | + }, |
| 151 | + marker::PhantomData, |
| 152 | + ) |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +pub struct FileOperationsVtableBuilder<T>(bindings::file_operations, marker::PhantomData<T>); |
| 157 | + |
| 158 | +impl<T> FileOperationsVtableBuilder<T> { |
| 159 | + pub const fn build(self) -> FileOperationsVtable { |
| 160 | + FileOperationsVtable(self.0) |
150 | 161 | } |
151 | 162 | } |
152 | 163 |
|
|
0 commit comments