forked from microsoft/hcsshim
-
Notifications
You must be signed in to change notification settings - Fork 0
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 microsoft#94 from Microsoft/remotefs-sync
remotefs: Added sync to writes and OpenFile
- Loading branch information
Showing
7 changed files
with
636 additions
and
507 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
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,103 @@ | ||
package remotefs | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"time" | ||
) | ||
|
||
// RemotefsCmd is the name of the remotefs meta command | ||
const RemotefsCmd = "remotefs" | ||
|
||
// Name of the commands when called from the cli context (remotefs <CMD> ...) | ||
const ( | ||
StatCmd = "stat" | ||
LstatCmd = "lstat" | ||
ReadlinkCmd = "readlink" | ||
MkdirCmd = "mkdir" | ||
MkdirAllCmd = "mkdirall" | ||
RemoveCmd = "remove" | ||
RemoveAllCmd = "removeall" | ||
LinkCmd = "link" | ||
SymlinkCmd = "symlink" | ||
LchmodCmd = "lchmod" | ||
LchownCmd = "lchown" | ||
MknodCmd = "mknod" | ||
MkfifoCmd = "mkfifo" | ||
OpenFileCmd = "openfile" | ||
ReadFileCmd = "readfile" | ||
WriteFileCmd = "writefile" | ||
ReadDirCmd = "readdir" | ||
ResolvePathCmd = "resolvepath" | ||
ExtractArchiveCmd = "extractarchive" | ||
ArchivePathCmd = "archivepath" | ||
) | ||
|
||
// ErrInvalid is returned if the parameters are invalid | ||
var ErrInvalid = errors.New("invalid arguments") | ||
|
||
// ErrUnknown is returned for an unknown remotefs command | ||
var ErrUnknown = errors.New("unkown command") | ||
|
||
// ExportedError is the serialized version of the a Go error. | ||
// It also provides a trivial implementation of the error interface. | ||
type ExportedError struct { | ||
ErrString string | ||
ErrNum int `json:",omitempty"` | ||
} | ||
|
||
// Error returns an error string | ||
func (ee *ExportedError) Error() string { | ||
return ee.ErrString | ||
} | ||
|
||
// FileInfo is the stat struct returned by the remotefs system. It | ||
// fulfills the os.FileInfo interface. | ||
type FileInfo struct { | ||
NameVar string | ||
SizeVar int64 | ||
ModeVar os.FileMode | ||
ModTimeVar int64 // Serialization of time.Time breaks in travis, so use an int | ||
IsDirVar bool | ||
} | ||
|
||
var _ os.FileInfo = &FileInfo{} | ||
|
||
// Name returns the filename from a FileInfo structure | ||
func (f *FileInfo) Name() string { return f.NameVar } | ||
|
||
// Size returns the size from a FileInfo structure | ||
func (f *FileInfo) Size() int64 { return f.SizeVar } | ||
|
||
// Mode returns the mode from a FileInfo structure | ||
func (f *FileInfo) Mode() os.FileMode { return f.ModeVar } | ||
|
||
// ModTime returns the modification time from a FileInfo structure | ||
func (f *FileInfo) ModTime() time.Time { return time.Unix(0, f.ModTimeVar) } | ||
|
||
// IsDir returns the is-directory indicator from a FileInfo structure | ||
func (f *FileInfo) IsDir() bool { return f.IsDirVar } | ||
|
||
// Sys provides an interface to a FileInfo structure | ||
func (f *FileInfo) Sys() interface{} { return nil } | ||
|
||
// FileHeader is a header for remote *os.File operations for remotefs.OpenFile | ||
type FileHeader struct { | ||
Cmd uint32 | ||
Size uint64 | ||
} | ||
|
||
const ( | ||
Read uint32 = iota // Read request command | ||
Write // Write request command | ||
Seek // Seek request command | ||
Close // Close request command | ||
CmdOK // CmdOK is a response meaning request succeeded | ||
CmdFailed // CmdFailed is a response meaning request failed. | ||
) | ||
|
||
// SeekHeader is header for the Seek operation for remotefs.OpenFile | ||
type SeekHeader struct { | ||
Offset int64 | ||
Whence int32 | ||
} |
Oops, something went wrong.