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

     1  /*
     2  Copyright (c) 2017 VMware, Inc. All Rights Reserved.
     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 hgfs
    18  
    19  import (
    20  	"os"
    21  	"syscall"
    22  )
    23  
    24  const attrMask = AttrValidAllocationSize |
    25  	AttrValidAccessTime | AttrValidWriteTime | AttrValidCreateTime | AttrValidChangeTime |
    26  	AttrValidSpecialPerms | AttrValidOwnerPerms | AttrValidGroupPerms | AttrValidOtherPerms | AttrValidEffectivePerms |
    27  	AttrValidUserID | AttrValidGroupID | AttrValidFileID | AttrValidVolID
    28  
    29  func (a *AttrV2) sysStat(info os.FileInfo) {
    30  	sys, ok := info.Sys().(*syscall.Stat_t)
    31  
    32  	if !ok {
    33  		return
    34  	}
    35  
    36  	a.AllocationSize = uint64(sys.Blocks * 512)
    37  
    38  	nt := func(t syscall.Timespec) uint64 {
    39  		return uint64(t.Nano()) // TODO: this is supposed to be Windows NT system time, not needed atm
    40  	}
    41  
    42  	a.AccessTime = nt(sys.Atim)
    43  	a.WriteTime = nt(sys.Mtim)
    44  	a.CreationTime = a.WriteTime // see HgfsGetCreationTime
    45  	a.AttrChangeTime = nt(sys.Ctim)
    46  
    47  	a.SpecialPerms = uint8((sys.Mode & (syscall.S_ISUID | syscall.S_ISGID | syscall.S_ISVTX)) >> 9)
    48  	a.OwnerPerms = uint8((sys.Mode & syscall.S_IRWXU) >> 6)
    49  	a.GroupPerms = uint8((sys.Mode & syscall.S_IRWXG) >> 3)
    50  	a.OtherPerms = uint8(sys.Mode & syscall.S_IRWXO)
    51  
    52  	a.UserID = sys.Uid
    53  	a.GroupID = sys.Gid
    54  	a.HostFileID = sys.Ino
    55  	a.VolumeID = uint32(sys.Dev)
    56  
    57  	a.Mask |= attrMask
    58  }