github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/syscalls/linux/sys_stat_arm64.go (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build arm64
    16  // +build arm64
    17  
    18  package linux
    19  
    20  import (
    21  	"github.com/nicocha30/gvisor-ligolo/pkg/abi/linux"
    22  	"github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel"
    23  	"github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel/auth"
    24  )
    25  
    26  // This takes both input and output as pointer arguments to avoid copying large
    27  // structs.
    28  func convertStatxToUserStat(t *kernel.Task, statx *linux.Statx, stat *linux.Stat) {
    29  	// Linux just copies fields from struct kstat without regard to struct
    30  	// kstat::result_mask (fs/stat.c:cp_new_stat()), so we do too.
    31  	userns := t.UserNamespace()
    32  	*stat = linux.Stat{
    33  		Dev:     uint64(linux.MakeDeviceID(uint16(statx.DevMajor), statx.DevMinor)),
    34  		Ino:     statx.Ino,
    35  		Nlink:   uint32(statx.Nlink),
    36  		Mode:    uint32(statx.Mode),
    37  		UID:     uint32(auth.KUID(statx.UID).In(userns).OrOverflow()),
    38  		GID:     uint32(auth.KGID(statx.GID).In(userns).OrOverflow()),
    39  		Rdev:    uint64(linux.MakeDeviceID(uint16(statx.RdevMajor), statx.RdevMinor)),
    40  		Size:    int64(statx.Size),
    41  		Blksize: int32(statx.Blksize),
    42  		Blocks:  int64(statx.Blocks),
    43  		ATime:   timespecFromStatxTimestamp(statx.Atime),
    44  		MTime:   timespecFromStatxTimestamp(statx.Mtime),
    45  		CTime:   timespecFromStatxTimestamp(statx.Ctime),
    46  	}
    47  }