Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1108 from jcrussell/issue-1107
minimega/ron/miniccc: add ufs to miniccc
- Loading branch information
Showing
39 changed files
with
5,926 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/vendor/github.com/Harvey-OS/ninep/LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (2014) Sandia Corporation. | ||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, | ||
// the U.S. Government retains certain rights in this software. | ||
|
||
package main | ||
|
||
import ( | ||
log "minilog" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
"ron" | ||
"runtime" | ||
|
||
"github.com/Harvey-OS/ninep/filesystem" | ||
"github.com/Harvey-OS/ninep/protocol" | ||
) | ||
|
||
var rootFS struct { | ||
// embed | ||
*protocol.Server | ||
|
||
running bool | ||
|
||
// active connection, set when running | ||
remote, local net.Conn | ||
} | ||
|
||
// ufsMessage handles a message from the server and relays it to UFS | ||
func ufsMessage(m *ron.Message) { | ||
switch m.UfsMode { | ||
case ron.UFS_OPEN: | ||
if rootFS.running { | ||
log.Error("ufs is already running") | ||
return | ||
} | ||
|
||
if rootFS.Server == nil { | ||
log.Info("init rootFS") | ||
root := "/" | ||
if runtime.GOOS == "windows" { | ||
// TODO: what if there is more that one volume? | ||
root = filepath.VolumeName(os.Getenv("SYSTEMROOT")) + "\\" | ||
} | ||
|
||
fs, err := ufs.NewServer(ufs.Root(root), ufs.Trace(log.Debug)) | ||
if err != nil { | ||
log.Error("unable to create file server: %v", err) | ||
return | ||
} | ||
|
||
ps, err := protocol.NewServer(fs, protocol.Trace(log.Debug)) | ||
if err != nil { | ||
log.Error("unable to create ninep server: %v", err) | ||
return | ||
} | ||
rootFS.Server = ps | ||
|
||
log.Info("init'd rootFS") | ||
} | ||
|
||
rootFS.running = true | ||
|
||
rootFS.remote, rootFS.local = net.Pipe() | ||
|
||
go ron.Trunk(rootFS.remote, client.UUID, ufsSendMessage) | ||
|
||
log.Info("accepting tunneled connection") | ||
|
||
if err := rootFS.Accept(rootFS.local); err != nil { | ||
log.Error("ufs error: %v", err) | ||
rootFS.running = false | ||
} | ||
case ron.UFS_CLOSE: | ||
if !rootFS.running { | ||
log.Error("ufs not running") | ||
return | ||
} | ||
|
||
rootFS.running = false | ||
rootFS.remote.Close() | ||
case ron.UFS_DATA: | ||
if !rootFS.running { | ||
log.Error("ufs not running") | ||
return | ||
} | ||
|
||
// relay the Tunnel data from ron | ||
rootFS.remote.Write(m.Tunnel) | ||
} | ||
} | ||
|
||
// ufsSendMessage tweaks the message generated by ron.Trunk before calling | ||
// sendMessage. | ||
func ufsSendMessage(m *ron.Message) error { | ||
m.Type = ron.MESSAGE_UFS | ||
m.UfsMode = ron.UFS_DATA | ||
|
||
return sendMessage(m) | ||
} |
Oops, something went wrong.