...

Source file src/k8s.io/kubernetes/test/images/agnhost/mounttest/mt_utils.go

Documentation: k8s.io/kubernetes/test/images/agnhost/mounttest

     1  //go:build !windows
     2  // +build !windows
     3  
     4  /*
     5  Copyright 2019 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package mounttest
    21  
    22  import (
    23  	"fmt"
    24  	"os"
    25  	"syscall"
    26  )
    27  
    28  func umask(mask int) int {
    29  	return syscall.Umask(mask)
    30  }
    31  
    32  // Defined by Linux (sys/statfs.h) - the type number for tmpfs mounts.
    33  const linuxTmpfsMagic = 0x01021994
    34  
    35  func fsType(path string) error {
    36  	if path == "" {
    37  		return nil
    38  	}
    39  
    40  	buf := syscall.Statfs_t{}
    41  	if err := syscall.Statfs(path, &buf); err != nil {
    42  		fmt.Printf("error from statfs(%q): %v\n", path, err)
    43  		return err
    44  	}
    45  
    46  	if buf.Type == linuxTmpfsMagic {
    47  		fmt.Printf("mount type of %q: tmpfs\n", path)
    48  	} else {
    49  		fmt.Printf("mount type of %q: %v\n", path, buf.Type)
    50  	}
    51  
    52  	return nil
    53  }
    54  
    55  func fileMode(path string) error {
    56  	if path == "" {
    57  		return nil
    58  	}
    59  
    60  	fileinfo, err := os.Stat(path)
    61  	if err != nil {
    62  		fmt.Printf("error from Stat(%q): %v\n", path, err)
    63  		return err
    64  	}
    65  
    66  	fmt.Printf("mode of file %q: %v\n", path, fileinfo.Mode())
    67  	return nil
    68  }
    69  
    70  func filePerm(path string) error {
    71  	if path == "" {
    72  		return nil
    73  	}
    74  
    75  	fileinfo, err := os.Stat(path)
    76  	if err != nil {
    77  		fmt.Printf("error from Stat(%q): %v\n", path, err)
    78  		return err
    79  	}
    80  
    81  	fmt.Printf("perms of file %q: %v\n", path, fileinfo.Mode().Perm())
    82  	return nil
    83  }
    84  
    85  func fileOwner(path string) error {
    86  	if path == "" {
    87  		return nil
    88  	}
    89  
    90  	buf := syscall.Stat_t{}
    91  	if err := syscall.Stat(path, &buf); err != nil {
    92  		fmt.Printf("error from stat(%q): %v\n", path, err)
    93  		return err
    94  	}
    95  
    96  	fmt.Printf("owner UID of %q: %v\n", path, buf.Uid)
    97  	fmt.Printf("owner GID of %q: %v\n", path, buf.Gid)
    98  	return nil
    99  }
   100  

View as plain text