github.com/scaleoutsean/fusego@v0.0.0-20220224074057-4a6429e46bb8/internal/fusekernel/protocol.go (about)

     1  package fusekernel
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // Protocol is a FUSE protocol version number.
     8  type Protocol struct {
     9  	Major uint32
    10  	Minor uint32
    11  }
    12  
    13  func (p Protocol) String() string {
    14  	return fmt.Sprintf("%d.%d", p.Major, p.Minor)
    15  }
    16  
    17  // LT returns whether a is less than b.
    18  func (a Protocol) LT(b Protocol) bool {
    19  	return a.Major < b.Major ||
    20  		(a.Major == b.Major && a.Minor < b.Minor)
    21  }
    22  
    23  // GE returns whether a is greater than or equal to b.
    24  func (a Protocol) GE(b Protocol) bool {
    25  	return a.Major > b.Major ||
    26  		(a.Major == b.Major && a.Minor >= b.Minor)
    27  }
    28  
    29  func (a Protocol) is79() bool {
    30  	return a.GE(Protocol{7, 9})
    31  }
    32  
    33  // HasAttrBlockSize returns whether Attr.BlockSize is respected by the
    34  // kernel.
    35  func (a Protocol) HasAttrBlockSize() bool {
    36  	return a.is79()
    37  }
    38  
    39  // HasReadWriteFlags returns whether ReadRequest/WriteRequest
    40  // fields Flags and FileFlags are valid.
    41  func (a Protocol) HasReadWriteFlags() bool {
    42  	return a.is79()
    43  }
    44  
    45  // HasGetattrFlags returns whether GetattrRequest field Flags is
    46  // valid.
    47  func (a Protocol) HasGetattrFlags() bool {
    48  	return a.is79()
    49  }
    50  
    51  func (a Protocol) is710() bool {
    52  	return a.GE(Protocol{7, 10})
    53  }
    54  
    55  // HasOpenNonSeekable returns whether OpenResponse field Flags flag
    56  // OpenNonSeekable is supported.
    57  func (a Protocol) HasOpenNonSeekable() bool {
    58  	return a.is710()
    59  }
    60  
    61  func (a Protocol) is712() bool {
    62  	return a.GE(Protocol{7, 12})
    63  }
    64  
    65  // HasUmask returns whether CreateRequest/MkdirRequest/MknodRequest
    66  // field Umask is valid.
    67  func (a Protocol) HasUmask() bool {
    68  	return a.is712()
    69  }
    70  
    71  // HasInvalidate returns whether InvalidateNode/InvalidateEntry are
    72  // supported.
    73  func (a Protocol) HasInvalidate() bool {
    74  	return a.is712()
    75  }