Skip to content

Commit

Permalink
windows:bring in the corrected getattr; remove attr_windows.go
Browse files Browse the repository at this point in the history
Signed-off-by: Ron Minnich <[email protected]>
  • Loading branch information
rminnich committed Nov 30, 2023
1 parent 4eb2088 commit eed1d1a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 93 deletions.
108 changes: 76 additions & 32 deletions client/cpu9p_windows.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,82 @@
// Copyright 2022 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.
// 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 (
"errors"
"fmt"
"os"
"time"

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

// SetAttr does not implement p9.File.SetAttr.
// GetAttr implements p9.File.GetAttr.
//
// Not fully implemented.
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
}

t := uint64(fi.ModTime().Unix())
// In the unix-style code, we derive the Mode directly
// from the syscall.Stat_t. That is not available on
// Windows, so we have to reconstruct some mode bits
// in other ways.
mode := p9.FileMode(fi.Mode())
if fi.IsDir() {
mode |= p9.ModeDirectory
}
attr := p9.Attr{
Mode: mode,
UID: 0,
GID: 0,
NLink: 3,
Size: uint64(fi.Size()),
BlockSize: uint64(512),
Blocks: uint64(fi.Size() / 512),
ATimeSeconds: t,
ATimeNanoSeconds: 0,
MTimeSeconds: t,
MTimeNanoSeconds: 0,
CTimeSeconds: t,
CTimeNanoSeconds: 0,
}
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
}

// Lock implements p9.File.Lock.
// Well, not really.
func (l *CPU9P) Lock(pid int, locktype p9.LockType, flags p9.LockFlags, start, length uint64, client string) (p9.LockStatus, error) {
return p9.LockStatusOK, nil
}

// SetAttr implements p9.File.SetAttr.
func (l *CPU9P) SetAttr(mask p9.SetAttrMask, attr p9.SetAttr) error {
var err error
// Any or ALL can be set.
Expand All @@ -30,48 +93,29 @@ func (l *CPU9P) SetAttr(mask p9.SetAttrMask, attr p9.SetAttr) error {
// The test actually caught this ...

if mask.Size {
panic("truncate")
// if e := unix.Truncate(l.path, int64(attr.Size)); e != nil {
// err = errors.Join(err, e)
// }
err = errors.Join(err, os.ErrInvalid)
}
if mask.ATime || mask.MTime {
atime, mtime := time.Now(), time.Now()
if mask.ATimeNotSystemTime {
atime = time.Unix(int64(attr.ATimeSeconds), int64(attr.ATimeNanoSeconds))
}
if mask.MTimeNotSystemTime {
mtime = time.Unix(int64(attr.MTimeSeconds), int64(attr.MTimeNanoSeconds))
}
if e := os.Chtimes(l.path, atime, mtime); e != nil {
err = errors.Join(err, e)
}
err = errors.Join(err, os.ErrInvalid)
}

if mask.CTime {
// The Linux client sets CTime. I did not even know that was allowed.
// if e := errors.New("Can not set CTime on Unix"); e != nil { err = errors.Join(e)}
err = errors.Join(err, os.ErrInvalid)
verbose("mask.CTime is set by client; ignoring")
}
if mask.Permissions {
err = errors.Join(err, fmt.Errorf("chmod: %w", os.ErrInvalid))
err = errors.Join(err, os.ErrInvalid)
}

if mask.GID {
err = errors.Join(err, fmt.Errorf("chgrp: %w", os.ErrInvalid))

err = errors.Join(err, os.ErrInvalid)
}
if mask.UID {
err = errors.Join(err, fmt.Errorf("chown: %w", os.ErrInvalid))
err = errors.Join(err, os.ErrInvalid)
}
return err
}

// Lock does not implement p9.File.Lock.
func (l *CPU9P) Lock(pid int, locktype p9.LockType, flags p9.LockFlags, start, length uint64, client string) (p9.LockStatus, error) {
return p9.LockStatusError, os.ErrInvalid
}

// SetXattr implements p9.File.SetXattr
func (l *CPU9P) SetXattr(attr string, data []byte, flags p9.XattrFlags) error {
return os.ErrInvalid
Expand All @@ -93,5 +137,5 @@ func (l *CPU9P) RemoveXattr(attr string) error {
}

func inode(_ os.FileInfo) uint64 {
return 1
return 0xd00dfeed
}
61 changes: 0 additions & 61 deletions client/getattr_windows.go

This file was deleted.

0 comments on commit eed1d1a

Please sign in to comment.