github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/features.go (about)

     1  //
     2  //  Copyright 2023 The AVFS authors
     3  //
     4  //  Licensed under the Apache License, Version 2.0 (the "License");
     5  //  you may not use this file except in compliance with the License.
     6  //  You may obtain a copy of the License at
     7  //
     8  //  	http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  //  Unless required by applicable law or agreed to in writing, software
    11  //  distributed under the License is distributed on an "AS IS" BASIS,
    12  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  //  See the License for the specific language governing permissions and
    14  //  limitations under the License.
    15  //
    16  
    17  package avfs
    18  
    19  // Features defines the set of features available on a file system.
    20  type Features uint64
    21  
    22  //go:generate stringer -type Features -trimprefix Feat -bitmask -output features_string.go
    23  
    24  const (
    25  	// FeatHardlink indicates that the file system supports hard links (link(), readlink() functions).
    26  	FeatHardlink Features = 1 << iota
    27  
    28  	// FeatIdentityMgr indicates that the file system features and identity manager and supports multiple users.
    29  	FeatIdentityMgr
    30  
    31  	// FeatSetOSType is set if the OS of the emulated file system can be changed (see MemFS).
    32  	FeatSetOSType
    33  
    34  	// FeatReadOnly is set for read only file systems (see RoFs).
    35  	FeatReadOnly
    36  
    37  	// FeatReadOnlyIdm is set when identity manager is read only (see OsIdm).
    38  	FeatReadOnlyIdm
    39  
    40  	// FeatRealFS indicates that the file system is a real one, not emulated (see OsFS).
    41  	FeatRealFS
    42  
    43  	// FeatSubFS allow to create a new file system from the subtree rooted at an arbitrary directory.
    44  	FeatSubFS
    45  
    46  	// FeatSymlink indicates that the file system supports symbolic links (symlink(), evalSymlink() functions).
    47  	FeatSymlink
    48  )
    49  
    50  // Featurer is the interface that wraps the Features and HasFeature methods.
    51  type Featurer interface {
    52  	// Features returns the set of features provided by the file system or identity manager.
    53  	Features() Features
    54  
    55  	// HasFeature returns true if the file system or identity manager provides a given feature.
    56  	HasFeature(feature Features) bool
    57  }
    58  
    59  // FeaturesFn provides features functions to a file system or an identity manager.
    60  type FeaturesFn struct {
    61  	features Features // features defines the list of features available.
    62  }
    63  
    64  // Features returns the set of features provided by the file system or identity manager.
    65  func (ftf *FeaturesFn) Features() Features {
    66  	return ftf.features
    67  }
    68  
    69  // HasFeature returns true if the file system or identity manager provides a given feature.
    70  func (ftf *FeaturesFn) HasFeature(feature Features) bool {
    71  	return ftf.features&feature == feature
    72  }
    73  
    74  // SetFeatures sets the features of the file system or identity manager.
    75  func (ftf *FeaturesFn) SetFeatures(feature Features) error {
    76  	ftf.features = feature
    77  
    78  	return nil
    79  }
    80  
    81  // BuildFeatures returns the features available depending on build tags.
    82  func BuildFeatures() Features {
    83  	return buildFeatSetOSType
    84  }