Skip to content

Commit

Permalink
Merge branch 'main' into print-mount-fail
Browse files Browse the repository at this point in the history
  • Loading branch information
rminnich authored Oct 10, 2024
2 parents bb3ac0f + 05895c1 commit 0a0e1a1
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
8 changes: 5 additions & 3 deletions client/cpu9p_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package client

import (
"errors"
"fmt"
"os"
"time"

Expand All @@ -34,7 +35,7 @@ func (l *CPU9P) SetAttr(mask p9.SetAttrMask, attr p9.SetAttr) error {

if mask.Size {
if e := unix.Truncate(l.path, int64(attr.Size)); e != nil {
err = errors.Join(err, e)
err = errors.Join(err, fmt.Errorf("truncate:%w", err))
}
}
if mask.ATime || mask.MTime {
Expand All @@ -56,8 +57,9 @@ func (l *CPU9P) SetAttr(mask p9.SetAttrMask, attr p9.SetAttr) error {
verbose("mask.CTime is set by client; ignoring")
}
if mask.Permissions {
if e := unix.Chmod(l.path, uint32(attr.Permissions)); e != nil {
err = errors.Join(err, e)
perm := uint32(attr.Permissions)
if e := unix.Chmod(l.path, perm); e != nil {
err = errors.Join(err, fmt.Errorf("%q:%o:%w", l.path, perm, err))
}
}

Expand Down
10 changes: 6 additions & 4 deletions client/cpu9p_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package client
import (
"os"
"reflect"
"runtime"

"path/filepath"
"testing"
Expand Down Expand Up @@ -87,7 +88,7 @@ func Test9pUnix(t *testing.T) {

sam.Permissions = true
if err := c.SetAttr(sam, sa); err != nil {
t.Fatalf("Setattr with mode: %v != nil", err)
t.Fatalf("Setattr(%v, %v): %v != nil", sam, sa, err)
}
_, _, ga2, err = c.GetAttr(m)
if err != nil {
Expand Down Expand Up @@ -178,13 +179,14 @@ func Test9pUnix(t *testing.T) {
sam.Permissions = true
sa.Permissions = 0
if err := c.SetAttr(sam, sa); err != nil {
t.Fatalf("Setattr with mode: %v != nil", err)
t.Fatalf("Setattr(%v,%v): %v != nil", sam, sa, err)
}

// The second time, since we blew permissions to
// zero, we ought to get an error.
if err := c.SetAttr(sam, sa); err == nil {
t.Fatalf("Setattr with mode: nil != %v", unix.EPERM)
// It seems, on freebsd, there is no error.
if err := c.SetAttr(sam, sa); runtime.GOOS != "freebsd" && err == nil {
t.Fatalf("Setattr(%v,%v): nil != %v", sam, sa, unix.EPERM)
}

// But getattr should work.
Expand Down
20 changes: 20 additions & 0 deletions client/cpu_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018-2024 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package client

import (
"os"
"syscall"

"github.com/hugelgupf/p9/p9"
)

func osflags(fi os.FileInfo, mode p9.OpenFlags) int {
flags := int(mode)
if fi.IsDir() {
flags |= syscall.O_DIRECTORY
}
return flags
}
61 changes: 61 additions & 0 deletions client/getattr_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"syscall"

"github.com/hugelgupf/p9/p9"
)

// GetAttr implements p9.File.GetAttr.
func (l *CPU9P) GetAttr(req p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error) {
qid, fi, err := l.info()
if err != nil {
return qid, p9.AttrMask{}, p9.Attr{}, err
}

stat := fi.Sys().(*syscall.Stat_t)
attr := p9.Attr{
Mode: p9.FileMode(stat.Mode),
UID: p9.UID(stat.Uid),
GID: p9.GID(stat.Gid),
NLink: p9.NLink(stat.Nlink),
RDev: p9.Dev(stat.Rdev),
Size: uint64(stat.Size),
BlockSize: uint64(stat.Blksize),
Blocks: uint64(stat.Blocks),
ATimeSeconds: uint64(stat.Atimespec.Sec),
ATimeNanoSeconds: uint64(stat.Atimespec.Nsec),
MTimeSeconds: uint64(stat.Mtimespec.Sec),
MTimeNanoSeconds: uint64(stat.Mtimespec.Nsec),
CTimeSeconds: uint64(stat.Ctimespec.Sec),
CTimeNanoSeconds: uint64(stat.Ctimespec.Nsec),
}
valid := p9.AttrMask{
Mode: true,
UID: true,
GID: true,
NLink: true,
RDev: true,
Size: true,
Blocks: true,
ATime: true,
MTime: true,
CTime: true,
}

return qid, valid, attr, nil
}

0 comments on commit 0a0e1a1

Please sign in to comment.