@@ -19,6 +19,7 @@ use crate::{
1919} ;
2020use core:: convert:: { TryFrom , TryInto } ;
2121use core:: { cell:: UnsafeCell , marker, mem, ptr} ;
22+ use macros:: vtable;
2223
2324/// Wraps the kernel's `struct file`.
2425///
@@ -468,24 +469,24 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
468469 const VTABLE : bindings:: file_operations = bindings:: file_operations {
469470 open : Some ( Self :: open_callback) ,
470471 release : Some ( Self :: release_callback) ,
471- read : if T :: TO_USE . read {
472+ read : if T :: HAS_READ {
472473 Some ( Self :: read_callback)
473474 } else {
474475 None
475476 } ,
476- write : if T :: TO_USE . write {
477+ write : if T :: HAS_WRITE {
477478 Some ( Self :: write_callback)
478479 } else {
479480 None
480481 } ,
481- llseek : if T :: TO_USE . seek {
482+ llseek : if T :: HAS_SEEK {
482483 Some ( Self :: llseek_callback)
483484 } else {
484485 None
485486 } ,
486487
487488 check_flags : None ,
488- compat_ioctl : if T :: TO_USE . compat_ioctl {
489+ compat_ioctl : if T :: HAS_COMPAT_IOCTL {
489490 Some ( Self :: compat_ioctl_callback)
490491 } else {
491492 None
@@ -496,7 +497,7 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
496497 fasync : None ,
497498 flock : None ,
498499 flush : None ,
499- fsync : if T :: TO_USE . fsync {
500+ fsync : if T :: HAS_FSYNC {
500501 Some ( Self :: fsync_callback)
501502 } else {
502503 None
@@ -506,19 +507,19 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
506507 iterate_shared : None ,
507508 iopoll : None ,
508509 lock : None ,
509- mmap : if T :: TO_USE . mmap {
510+ mmap : if T :: HAS_MMAP {
510511 Some ( Self :: mmap_callback)
511512 } else {
512513 None
513514 } ,
514515 mmap_supported_flags : 0 ,
515516 owner : ptr:: null_mut ( ) ,
516- poll : if T :: TO_USE . poll {
517+ poll : if T :: HAS_POLL {
517518 Some ( Self :: poll_callback)
518519 } else {
519520 None
520521 } ,
521- read_iter : if T :: TO_USE . read_iter {
522+ read_iter : if T :: HAS_READ {
522523 Some ( Self :: read_iter_callback)
523524 } else {
524525 None
@@ -529,13 +530,13 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
529530 show_fdinfo : None ,
530531 splice_read : None ,
531532 splice_write : None ,
532- unlocked_ioctl : if T :: TO_USE . ioctl {
533+ unlocked_ioctl : if T :: HAS_IOCTL {
533534 Some ( Self :: unlocked_ioctl_callback)
534535 } else {
535536 None
536537 } ,
537538 uring_cmd : None ,
538- write_iter : if T :: TO_USE . write_iter {
539+ write_iter : if T :: HAS_WRITE {
539540 Some ( Self :: write_iter_callback)
540541 } else {
541542 None
@@ -552,69 +553,6 @@ impl<A: OpenAdapter<T::OpenData>, T: Operations> OperationsVtable<A, T> {
552553 }
553554}
554555
555- /// Represents which fields of [`struct file_operations`] should be populated with pointers.
556- pub struct ToUse {
557- /// The `read` field of [`struct file_operations`].
558- pub read : bool ,
559-
560- /// The `read_iter` field of [`struct file_operations`].
561- pub read_iter : bool ,
562-
563- /// The `write` field of [`struct file_operations`].
564- pub write : bool ,
565-
566- /// The `write_iter` field of [`struct file_operations`].
567- pub write_iter : bool ,
568-
569- /// The `llseek` field of [`struct file_operations`].
570- pub seek : bool ,
571-
572- /// The `unlocked_ioctl` field of [`struct file_operations`].
573- pub ioctl : bool ,
574-
575- /// The `compat_ioctl` field of [`struct file_operations`].
576- pub compat_ioctl : bool ,
577-
578- /// The `fsync` field of [`struct file_operations`].
579- pub fsync : bool ,
580-
581- /// The `mmap` field of [`struct file_operations`].
582- pub mmap : bool ,
583-
584- /// The `poll` field of [`struct file_operations`].
585- pub poll : bool ,
586- }
587-
588- /// A constant version where all values are to set to `false`, that is, all supported fields will
589- /// be set to null pointers.
590- pub const USE_NONE : ToUse = ToUse {
591- read : false ,
592- read_iter : false ,
593- write : false ,
594- write_iter : false ,
595- seek : false ,
596- ioctl : false ,
597- compat_ioctl : false ,
598- fsync : false ,
599- mmap : false ,
600- poll : false ,
601- } ;
602-
603- /// Defines the [`Operations::TO_USE`] field based on a list of fields to be populated.
604- #[ macro_export]
605- macro_rules! declare_file_operations {
606- ( ) => {
607- const TO_USE : $crate:: file:: ToUse = $crate:: file:: USE_NONE ;
608- } ;
609- ( $( $i: ident) ,+) => {
610- const TO_USE : kernel:: file:: ToUse =
611- $crate:: file:: ToUse {
612- $( $i: true ) ,+ ,
613- ..$crate:: file:: USE_NONE
614- } ;
615- } ;
616- }
617-
618556/// Allows the handling of ioctls defined with the `_IO`, `_IOR`, `_IOW`, and `_IOWR` macros.
619557///
620558/// For each macro, there is a handler function that takes the appropriate types as arguments.
@@ -742,10 +680,8 @@ pub trait OpenAdapter<T: Sync> {
742680/// File descriptors may be used from multiple threads/processes concurrently, so your type must be
743681/// [`Sync`]. It must also be [`Send`] because [`Operations::release`] will be called from the
744682/// thread that decrements that associated file's refcount to zero.
683+ #[ vtable]
745684pub trait Operations {
746- /// The methods to use to populate [`struct file_operations`].
747- const TO_USE : ToUse ;
748-
749685 /// The type of the context data returned by [`Operations::open`] and made available to
750686 /// other methods.
751687 type Data : PointerWrapper + Send + Sync = ( ) ;
0 commit comments