github.com/hugelgupf/u-root@v0.0.0-20191023214958-4807c632154c/pkg/mount/fs_linux.go (about)

     1  // Copyright 2014-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mount
     6  
     7  import (
     8  	"fmt"
     9  	"io/ioutil"
    10  	"strings"
    11  )
    12  
    13  // FindFileSystem returns nil if a file system is available for use.
    14  //
    15  // It rereads /proc/filesystems each time as the supported file systems can change
    16  // as modules are added and removed.
    17  func FindFileSystem(fs string) error {
    18  	b, err := ioutil.ReadFile("/proc/filesystems")
    19  	if err != nil {
    20  		return err
    21  	}
    22  	for _, l := range strings.Split(string(b), "\n") {
    23  		f := strings.Fields(l)
    24  		if (len(f) > 1 && f[0] == "nodev" && f[1] == fs) || (len(f) > 0 && f[0] != "nodev" && f[0] == fs) {
    25  			return nil
    26  		}
    27  	}
    28  	return fmt.Errorf("%s not found", fs)
    29  }