diff --git a/LICENSE b/LICENSE index 119dc239..e1a6cc6e 100644 --- a/LICENSE +++ b/LICENSE @@ -27,3 +27,209 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Some work is licensed under Apache 2.0, particularly code from gvisor. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/client/client.go b/client/client.go index 703fb691..ff85879c 100644 --- a/client/client.go +++ b/client/client.go @@ -17,8 +17,8 @@ import ( "github.com/hugelgupf/p9/p9" "github.com/mdlayher/vsock" - "github.com/u-root/u-root/pkg/termios" "golang.org/x/crypto/ssh" + "golang.org/x/term" ) const ( @@ -111,11 +111,17 @@ func Command(host string, args ...string) *Cmd { } col, row := 80, 40 - if w, err := termios.GetWinSize(0); err != nil { + if c, r, err := term.GetSize(int(os.Stdin.Fd())); err != nil { verbose("Can not get winsize: %v; assuming %dx%d and non-interactive", err, col, row) + // ah, windows. You suck. + oldState, err := term.MakeRaw(int(os.Stdin.Fd())) + if err == nil { + hasTTY = true + term.Restore(int(os.Stdin.Fd()), oldState) + } } else { hasTTY = true - col, row = int(w.Col), int(w.Row) + col, row = c, r } return &Cmd{ @@ -588,23 +594,14 @@ func (c *Cmd) TTYIn(s *ssh.Session, w io.WriteCloser, r io.Reader) { } // SetupInteractive sets up a cpu client for interactive access. -// It returns a function to be run when the session ends. +// It adds a function to c.Closers to clean up the terminal. func (c *Cmd) SetupInteractive() error { - t, err := termios.New() - if err != nil { - return err - } - r, err := t.Get() + oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { return err } - if _, err = t.Raw(); err != nil { - return err - } c.closers = append(c.closers, func() error { - if err := t.Set(r); err != nil { - return err - } + term.Restore(int(os.Stdin.Fd()), oldState) return nil }) diff --git a/client/cpio9p.go b/client/cpio9p.go index f1866363..8c02415f 100644 --- a/client/cpio9p.go +++ b/client/cpio9p.go @@ -19,7 +19,8 @@ import ( "io" "io/fs" "os" - "path/filepath" + "path" + "strings" "syscall" "github.com/hugelgupf/p9/fsimpl/templatefs" @@ -166,7 +167,7 @@ func (l *CPIO9PFID) Walk(names []string) ([]p9.QID, p9.File, error) { fullpath = r.Name } for _, name := range names { - fullpath = filepath.Join(fullpath, name) + fullpath = path.Join(fullpath, name) ix, ok := l.fs.m[fullpath] verbose("cpio:Walk %q get %v, %v", fullpath, ix, ok) if !ok { @@ -258,13 +259,16 @@ func (l *CPIO9PFID) readdir() ([]uint64, error) { // contents of all subdirs. var list []uint64 for i, r := range l.fs.recs[l.path+1:] { + // We can not use filepath.Rel, thank you Windows. // filepath.Rel fails, we're done here. - b, err := filepath.Rel(dn, r.Name) - if err != nil { - verbose("cpio:r.Name %q: DONE", r.Name) + // b, err := filepath.Rel(dn, r.Name) + if dn != "." && !strings.HasPrefix(r.Name, dn) { + verbose("cpio:dn %q, r.Name %q: DONE", dn, r.Name) break } - dir, _ := filepath.Split(b) + b := strings.TrimPrefix(strings.TrimPrefix(r.Name, dn), "/") + dir, _ := path.Split(b) + verbose("readdir: dn %q, r.Name %q, dir %q, b %q", dn, r.Name, dir, b) if len(dir) > 0 { continue } @@ -309,11 +313,11 @@ func (l *CPIO9PFID) Readdir(offset uint64, count uint32) (p9.Dirents, error) { if err != nil { continue } - verbose("cpio:add path %d %q", i, filepath.Base(r.Info.Name)) + verbose("cpio:add path %d %q", i, path.Base(r.Info.Name)) dirents = append(dirents, p9.Dirent{ QID: qid, Type: qid.Type, - Name: filepath.Base(r.Info.Name), + Name: path.Base(r.Info.Name), Offset: i, }) } diff --git a/client/cpio9p_test.go b/client/cpio9p_test.go index ea97029b..7cb49ec2 100644 --- a/client/cpio9p_test.go +++ b/client/cpio9p_test.go @@ -12,7 +12,7 @@ import ( "github.com/hugelgupf/p9/p9" ) -func TestCPIO9P(t *testing.T) { +func TestCPIO9PBadFile(t *testing.T) { d := t.TempDir() bogus := filepath.Join(d, "bogus") if _, err := NewCPIO9P(bogus); err == nil { @@ -26,12 +26,85 @@ func TestCPIO9P(t *testing.T) { if _, err := NewCPIO9P(bogus); err == nil { t.Fatalf("Opening bad file: got nil, want err") } +} +func TestCPIOBadOperators(t *testing.T) { fs, err := NewCPIO9P("data/a.cpio") if err != nil { t.Fatalf("data/a.cpio: got %v, want nil", err) } + // See if anything is there. + attach, err := fs.Attach() + if err != nil { + t.Fatalf("Attach: got %v, want nil", err) + } + t.Logf("root:%v", attach) + + _, root, err := attach.Walk([]string{}) + if err != nil { + t.Fatalf("walking '': want nil, got %v", err) + } + + walkto := []string{"b", "c", "hi"} + _, hi, err := root.Walk(walkto) + if err != nil { + t.Fatalf("walking %v from /: want nil, got %v", walkto, err) + } + var data [2]byte + off := int64(1) + if n, err := hi.WriteAt(data[:], off); err == nil || n != -1 { + t.Fatalf("WriteAt: got (%d, nil), want (-1, err)", n) + } + if _, err := hi.Symlink("", "", p9.UID(0), p9.GID(0)); err == nil { + t.Fatalf("symlink: got nil, want err") + } + + if err := hi.Link(root, ""); err == nil { + t.Fatalf("link: got nil, want err") + } + + var m p9.FileMode + if _, err := hi.Mknod("", m, 0, 0, p9.UID(0), p9.GID(0)); err == nil { + t.Fatalf("Mknod: got nil, want err") + } + + if err := hi.Rename(root, "k"); err == nil { + t.Fatalf("rename: got nil, want err") + } + + if err := hi.RenameAt("", root, ""); err == nil { + t.Fatalf("renameat: got nil, want err") + } + + if err := hi.UnlinkAt("hi", 0); err == nil { + t.Fatalf("unlinkat: got nil, want err") + } + + if _, err := root.StatFS(); err == nil { + t.Fatalf("statfs: got nil, want err") + } + +} + +func TestCPIO9PAttach(t *testing.T) { + fs, err := NewCPIO9P("data/a.cpio") + if err != nil { + t.Fatalf("data/a.cpio: got %v, want nil", err) + } + // See if anything is there. + attach, err := fs.Attach() + if err != nil { + t.Fatalf("Attach: got %v, want nil", err) + } + t.Logf("root:%v", attach) +} + +func TestCPIO9PAttachWalk(t *testing.T) { + fs, err := NewCPIO9P("data/a.cpio") + if err != nil { + t.Fatalf("data/a.cpio: got %v, want nil", err) + } // See if anything is there. attach, err := fs.Attach() if err != nil { @@ -54,15 +127,33 @@ func TestCPIO9P(t *testing.T) { } t.Logf("b %v", b) - q, c, err := root.Walk([]string{"b", "c"}) + walkto := []string{"b", "c"} + q, c, err := root.Walk(walkto) if err != nil { - t.Fatalf("walking a/b: want nil, got %v", err) + t.Fatalf("walking %v: want nil, got %v", walkto, err) } if len(q) != 2 { - t.Fatalf("walking a/b: want 2 qids, got (%v,%v)", q, err) + t.Fatalf("walking %v: want 2 qids, got (%v,%v)", walkto, q, err) } if c == nil { - t.Fatalf("walking a/b: want non-nil file, got nil") + t.Fatalf("walking %v: want non-nil file, got nil", walkto) + } +} + +func TestCPIO9PAttachWalkCreate(t *testing.T) { + fs, err := NewCPIO9P("data/a.cpio") + if err != nil { + t.Fatalf("data/a.cpio: got %v, want nil", err) + } + // See if anything is there. + attach, err := fs.Attach() + if err != nil { + t.Fatalf("Attach: got %v, want nil", err) + } + t.Logf("root:%v", attach) + _, root, err := attach.Walk([]string{}) + if err != nil { + t.Fatalf("walking '': want nil, got %v", err) } var ( @@ -77,13 +168,19 @@ func TestCPIO9P(t *testing.T) { t.Fatalf("mkdir in root: got hil, want err") } + walkto := []string{"b", "c"} + _, c, err := root.Walk(walkto) + if err != nil { + t.Fatalf("walking %v: want nil, got %v", walkto, err) + } + if _, _, err := c.Walk([]string{"d"}); err != nil { - t.Fatalf("walking d from b/c: want nil, got %v", err) + t.Fatalf("walking d from %v: want nil, got %v", walkto, err) } _, hi, err := c.Walk([]string{"hi"}) if err != nil { - t.Fatalf("walking hi from b/c: want nil, got %v", err) + t.Fatalf("walking hi from %v: want nil, got %v", walkto, err) } var data [2]byte off := int64(1) @@ -97,39 +194,6 @@ func TestCPIO9P(t *testing.T) { t.Fatalf("Reading hi: want %q, got %q", "i\n", string(data[:])) } - // test bad operators - if n, err := hi.WriteAt(data[:], 0); err == nil || n != -1 { - t.Fatalf("WriteAt: got (%d, nil), want (-1, err)", n) - } - - if _, err := hi.Symlink("", "", p9.UID(0), p9.GID(0)); err == nil { - t.Fatalf("symlink: got nil, want err") - } - - if err := hi.Link(root, ""); err == nil { - t.Fatalf("link: got nil, want err") - } - - if _, err := hi.Mknod("", m, 0, 0, p9.UID(0), p9.GID(0)); err == nil { - t.Fatalf("Mknod: got nil, want err") - } - - if err := hi.Rename(root, "k"); err == nil { - t.Fatalf("rename: got nil, want err") - } - - if err := hi.RenameAt("", root, ""); err == nil { - t.Fatalf("renameat: got nil, want err") - } - - if err := hi.UnlinkAt("hi", 0); err == nil { - t.Fatalf("unlinkat: got nil, want err") - } - - if _, err := hi.StatFS(); err == nil { - t.Fatalf("statfs: got nil, want err") - } - var ( mask p9.SetAttrMask attr p9.SetAttr @@ -144,6 +208,31 @@ func TestCPIO9P(t *testing.T) { t.Fatalf("getattr: want nil, got %v", err) } +} + +func TestCPIORootReaddir(t *testing.T) { + v = t.Logf + fs, err := NewCPIO9P("data/a.cpio") + if err != nil { + t.Fatalf("data/a.cpio: got %v, want nil", err) + } + // See if anything is there. + attach, err := fs.Attach() + if err != nil { + t.Fatalf("Attach: got %v, want nil", err) + } + t.Logf("root:%v", attach) + _, root, err := attach.Walk([]string{}) + if err != nil { + t.Fatalf("walking '': want nil, got %v", err) + } + + walkto := []string{"b", "c"} + _, c, err := root.Walk(walkto) + if err != nil { + t.Fatalf("walking %v: want nil, got %v", walkto, err) + } + dirs, err := c.Readdir(0, 64*1024) if err != nil { t.Fatalf("readdir on root: want nil, got %v", err) diff --git a/client/cpu9p.go b/client/cpu9p.go index 51c56f83..43603489 100644 --- a/client/cpu9p.go +++ b/client/cpu9p.go @@ -22,9 +22,7 @@ import ( "strings" "syscall" - "github.com/hugelgupf/p9/fsimpl/xattr" "github.com/hugelgupf/p9/p9" - "golang.org/x/sys/unix" ) // CPU9P is a p9.Attacher. @@ -73,30 +71,10 @@ func (l *CPU9P) info() (p9.QID, os.FileInfo, error) { qid.Type = p9.ModeFromOS(fi.Mode()).QIDType() // Save the path from the Ino. - qid.Path = fi.Sys().(*syscall.Stat_t).Ino + qid.Path = inode(fi) return qid, fi, nil } -// SetXattr implements p9.File.SetXattr -func (l *CPU9P) SetXattr(attr string, data []byte, flags p9.XattrFlags) error { - return unix.Setxattr(l.path, attr, data, int(flags)) -} - -// ListXattrs implements p9.File.ListXattrs -func (l *CPU9P) ListXattrs() ([]string, error) { - return xattr.List(l.path) -} - -// GetXattr implements p9.File.GetXattr -func (l *CPU9P) GetXattr(attr string) ([]byte, error) { - return xattr.Get(l.path, attr) -} - -// RemoveXattr implements p9.File.RemoveXattr -func (l *CPU9P) RemoveXattr(attr string) error { - return unix.Removexattr(l.path, attr) -} - // Walk implements p9.File.Walk. func (l *CPU9P) Walk(names []string) ([]p9.QID, p9.File, error) { var qids []p9.QID diff --git a/client/cpu9p_unix.go b/client/cpu9p_unix.go index f132098a..64116923 100644 --- a/client/cpu9p_unix.go +++ b/client/cpu9p_unix.go @@ -10,8 +10,10 @@ package client import ( "errors" "os" + "syscall" "time" + "github.com/hugelgupf/p9/fsimpl/xattr" "github.com/hugelgupf/p9/p9" "golang.org/x/sys/unix" ) @@ -110,3 +112,27 @@ func (l *CPU9P) Lock(pid int, locktype p9.LockType, flags p9.LockFlags, start, l } return p9.LockStatusOK, nil } + +func inode(fi os.FileInfo) uint64 { + return fi.Sys().(*syscall.Stat_t).Ino +} + +// SetXattr implements p9.File.SetXattr +func (l *CPU9P) SetXattr(attr string, data []byte, flags p9.XattrFlags) error { + return unix.Setxattr(l.path, attr, data, int(flags)) +} + +// ListXattrs implements p9.File.ListXattrs +func (l *CPU9P) ListXattrs() ([]string, error) { + return xattr.List(l.path) +} + +// GetXattr implements p9.File.GetXattr +func (l *CPU9P) GetXattr(attr string) ([]byte, error) { + return xattr.Get(l.path, attr) +} + +// RemoveXattr implements p9.File.RemoveXattr +func (l *CPU9P) RemoveXattr(attr string) error { + return unix.Removexattr(l.path, attr) +} diff --git a/client/cpu9p_windows.go b/client/cpu9p_windows.go new file mode 100644 index 00000000..e6e2d8c4 --- /dev/null +++ b/client/cpu9p_windows.go @@ -0,0 +1,141 @@ +// 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" + "os" + + "github.com/hugelgupf/p9/p9" +) + +// 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. + // A setattr could include things to set, + // and a permission value that makes setting those + // things impossible. Therefore, do these + // permission-y things last: + // Permissions + // GID + // UID + // Since changing, e.g., UID or GID might make + // changing permissions impossible. + // + // The test actually caught this ... + + if mask.Size { + err = errors.Join(err, os.ErrInvalid) + } + if mask.ATime || mask.MTime { + err = errors.Join(err, os.ErrInvalid) + } + + if mask.CTime { + err = errors.Join(err, os.ErrInvalid) + verbose("mask.CTime is set by client; ignoring") + } + if mask.Permissions { + err = errors.Join(err, os.ErrInvalid) + } + + if mask.GID { + err = errors.Join(err, os.ErrInvalid) + } + if mask.UID { + err = errors.Join(err, os.ErrInvalid) + } + return err +} + +// SetXattr implements p9.File.SetXattr +func (l *CPU9P) SetXattr(attr string, data []byte, flags p9.XattrFlags) error { + return os.ErrInvalid +} + +// ListXattrs implements p9.File.ListXattrs +func (l *CPU9P) ListXattrs() ([]string, error) { + return nil, os.ErrInvalid +} + +// GetXattr implements p9.File.GetXattr +func (l *CPU9P) GetXattr(attr string) ([]byte, error) { + return nil, os.ErrInvalid +} + +// RemoveXattr implements p9.File.RemoveXattr +func (l *CPU9P) RemoveXattr(attr string) error { + return os.ErrInvalid +} + +func inode(_ os.FileInfo) uint64 { + return 0xd00dfeed +} diff --git a/client/cpu_windows.go b/client/cpu_windows.go new file mode 100644 index 00000000..71c2f21a --- /dev/null +++ b/client/cpu_windows.go @@ -0,0 +1,16 @@ +// Copyright 2018-2019 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" + + "github.com/hugelgupf/p9/p9" +) + +func osflags(fi os.FileInfo, mode p9.OpenFlags) int { + flags := int(mode) + return flags +} diff --git a/go.mod b/go.mod index 9e625c84..189fdf0c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/gliderlabs/ssh v0.3.5 github.com/hugelgupf/p9 v0.2.1-0.20230814004337-e6037077d6dc github.com/kevinburke/ssh_config v1.2.0 - github.com/u-root/u-root v0.11.1-0.20230913033713-004977728a9d + github.com/u-root/u-root v1.0.1 golang.org/x/crypto v0.14.0 golang.org/x/sys v0.13.0 ) @@ -17,6 +17,7 @@ require ( github.com/mdlayher/vsock v1.2.1 github.com/shirou/gopsutil v3.21.11+incompatible golang.org/x/exp v0.0.0-20230810033253-352e893a4cad + golang.org/x/term v0.13.0 ) require ( diff --git a/go.sum b/go.sum index 4af88c45..f8ba1c7c 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,8 @@ github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/u-root/gobusybox/src v0.0.0-20230806212452-e9366a5b9fdc h1:udgfN9Qy573qgHWMEORFgy6YXNDiN/Fd5LlKdlp+/Mo= -github.com/u-root/u-root v0.11.1-0.20230913033713-004977728a9d h1:gMLGaE12VpD7C+XbCsDQ4p+BC4pw26X46ezR3kXhUu0= -github.com/u-root/u-root v0.11.1-0.20230913033713-004977728a9d/go.mod h1:PQzg9XJGp6Y1hRmTUruSO7lR7kKR6FpoSObf5n5bTfE= +github.com/u-root/u-root v1.0.1 h1:whxd3I9dKS8TZQueq1buXLsVw01M/mN/mc+tey/L1/M= +github.com/u-root/u-root v1.0.1/go.mod h1:Dog44Z3KdqyYHvX0cCkTdMQFWP5eX6PhaIx40TKCvEc= github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 h1:YcojQL98T/OO+rybuzn2+5KrD5dBwXIvYBvQ2cD3Avg= github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63/go.mod h1:eLL9Nub3yfAho7qB0MzZizFhTU2QkLeoVsWdHtDW264= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= @@ -96,6 +96,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=