github.com/vmware/govmomi@v0.51.0/toolbox/hgfs/hgfs_linux.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package hgfs
     6  
     7  import (
     8  	"os"
     9  	"syscall"
    10  )
    11  
    12  const attrMask = AttrValidAllocationSize |
    13  	AttrValidAccessTime | AttrValidWriteTime | AttrValidCreateTime | AttrValidChangeTime |
    14  	AttrValidSpecialPerms | AttrValidOwnerPerms | AttrValidGroupPerms | AttrValidOtherPerms | AttrValidEffectivePerms |
    15  	AttrValidUserID | AttrValidGroupID | AttrValidFileID | AttrValidVolID
    16  
    17  func (a *AttrV2) sysStat(info os.FileInfo) {
    18  	sys, ok := info.Sys().(*syscall.Stat_t)
    19  
    20  	if !ok {
    21  		return
    22  	}
    23  
    24  	a.AllocationSize = uint64(sys.Blocks * 512)
    25  
    26  	nt := func(t syscall.Timespec) uint64 {
    27  		return uint64(t.Nano()) // TODO: this is supposed to be Windows NT system time, not needed atm
    28  	}
    29  
    30  	a.AccessTime = nt(sys.Atim)
    31  	a.WriteTime = nt(sys.Mtim)
    32  	a.CreationTime = a.WriteTime // see HgfsGetCreationTime
    33  	a.AttrChangeTime = nt(sys.Ctim)
    34  
    35  	a.SpecialPerms = uint8((sys.Mode & (syscall.S_ISUID | syscall.S_ISGID | syscall.S_ISVTX)) >> 9)
    36  	a.OwnerPerms = uint8((sys.Mode & syscall.S_IRWXU) >> 6)
    37  	a.GroupPerms = uint8((sys.Mode & syscall.S_IRWXG) >> 3)
    38  	a.OtherPerms = uint8(sys.Mode & syscall.S_IRWXO)
    39  
    40  	a.UserID = sys.Uid
    41  	a.GroupID = sys.Gid
    42  	a.HostFileID = sys.Ino
    43  	a.VolumeID = uint32(sys.Dev)
    44  
    45  	a.Mask |= attrMask
    46  }