hgfs

package
v0.0.0-...-29a6359 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpOpen               = iota /* Open file */
	OpRead                      /* Read from file */
	OpWrite                     /* Write to file */
	OpClose                     /* Close file */
	OpSearchOpen                /* Start new search */
	OpSearchRead                /* Get next search response */
	OpSearchClose               /* End a search */
	OpGetattr                   /* Get file attributes */
	OpSetattr                   /* Set file attributes */
	OpCreateDir                 /* Create new directory */
	OpDeleteFile                /* Delete a file */
	OpDeleteDir                 /* Delete a directory */
	OpRename                    /* Rename a file or directory */
	OpQueryVolumeInfo           /* Query volume information */
	OpOpenV2                    /* Open file */
	OpGetattrV2                 /* Get file attributes */
	OpSetattrV2                 /* Set file attributes */
	OpSearchReadV2              /* Get next search response */
	OpCreateSymlink             /* Create a symlink */
	OpServerLockChange          /* Change the oplock on a file */
	OpCreateDirV2               /* Create a directory */
	OpDeleteFileV2              /* Delete a file */
	OpDeleteDirV2               /* Delete a directory */
	OpRenameV2                  /* Rename a file or directory */
	OpOpenV3                    /* Open file */
	OpReadV3                    /* Read from file */
	OpWriteV3                   /* Write to file */
	OpCloseV3                   /* Close file */
	OpSearchOpenV3              /* Start new search */
	OpSearchReadV3              /* Read V3 directory entries */
	OpSearchCloseV3             /* End a search */
	OpGetattrV3                 /* Get file attributes */
	OpSetattrV3                 /* Set file attributes */
	OpCreateDirV3               /* Create new directory */
	OpDeleteFileV3              /* Delete a file */
	OpDeleteDirV3               /* Delete a directory */
	OpRenameV3                  /* Rename a file or directory */
	OpQueryVolumeInfoV3         /* Query volume information */
	OpCreateSymlinkV3           /* Create a symlink */
	OpServerLockChangeV3        /* Change the oplock on a file */
	OpWriteWin32StreamV3        /* Write WIN32_STREAM_ID format data to file */
	OpCreateSessionV4           /* Create a session and return host capabilities. */
	OpDestroySessionV4          /* Destroy/close session. */
	OpReadFastV4                /* Read */
	OpWriteFastV4               /* Write */
	OpSetWatchV4                /* Start monitoring directory changes. */
	OpRemoveWatchV4             /* Stop monitoring directory changes. */
	OpNotifyV4                  /* Notification for a directory change event. */
	OpSearchReadV4              /* Read V4 directory entries. */
	OpOpenV4                    /* Open file */
	OpEnumerateStreamsV4        /* Enumerate alternative named streams for a file. */
	OpGetattrV4                 /* Get file attributes */
	OpSetattrV4                 /* Set file attributes */
	OpDeleteV4                  /* Delete a file or a directory */
	OpLinkmoveV4                /* Rename/move/create hard link. */
	OpFsctlV4                   /* Sending FS control requests. */
	OpAccessCheckV4             /* Access check. */
	OpFsyncV4                   /* Flush all cached data to the disk. */
	OpQueryVolumeInfoV4         /* Query volume information. */
	OpOplockAcquireV4           /* Acquire OPLOCK. */
	OpOplockBreakV4             /* Break or downgrade OPLOCK. */
	OpLockByteRangeV4           /* Acquire byte range lock. */
	OpUnlockByteRangeV4         /* Release byte range lock. */
	OpQueryEasV4                /* Query extended attributes. */
	OpSetEasV4                  /* Add or modify extended attributes. */
	OpNewHeader          = 0xff /* Header op, must be unique, distinguishes packet headers. */
)

Opcodes for server operations as defined in hgfsProto.h

View Source
const (
	StatusSuccess = iota
	StatusNoSuchFileOrDir
	StatusInvalidHandle
	StatusOperationNotPermitted
	StatusFileExists
	StatusNotDirectory
	StatusDirNotEmpty
	StatusProtocolError
	StatusAccessDenied
	StatusInvalidName
	StatusGenericError
	StatusSharingViolation
	StatusNoSpace
	StatusOperationNotSupported
	StatusNameTooLong
	StatusInvalidParameter
	StatusNotSameDevice
	StatusStaleSession
	StatusTooManySessions
	StatusTransportError
)

Status codes

View Source
const (
	AttrValidType = 1 << iota
	AttrValidSize
	AttrValidCreateTime
	AttrValidAccessTime
	AttrValidWriteTime
	AttrValidChangeTime
	AttrValidSpecialPerms
	AttrValidOwnerPerms
	AttrValidGroupPerms
	AttrValidOtherPerms
	AttrValidFlags
	AttrValidAllocationSize
	AttrValidUserID
	AttrValidGroupID
	AttrValidFileID
	AttrValidVolID
	AttrValidNonStaticFileID
	AttrValidEffectivePerms
	AttrValidExtendAttrSize
	AttrValidReparsePoint
	AttrValidShortName
)

Flags for attr mask

View Source
const (
	PacketFlagRequest = 1 << iota
	PacketFlagReply
	PacketFlagInfoExterror
	PacketFlagValidFlags = 0x7
)

Packet flags

View Source
const (
	FileTypeRegular = iota
	FileTypeDirectory
	FileTypeSymlink
)

FileType

View Source
const (
	OpenModeReadOnly = iota
	OpenModeWriteOnly
	OpenModeReadWrite
	OpenModeAccmodes
)

OpenMode

View Source
const (
	Open = iota
	OpenEmpty
	OpenCreate
	OpenCreateSafe
	OpenCreateEmpty
)

OpenFlags

View Source
const (
	PermRead  = 4
	PermWrite = 2
	PermExec  = 1
)

Permissions

View Source
const (
	LockNone = iota
	LockOpportunistic
	LockExclusive
	LockShared
	LockBatch
	LockLease
)

Lock type

View Source
const HeaderVersion = 0x1

HeaderVersion for HGFS protocol version 4

View Source
const LargePacketMax = 0xf800 // HGFS_LARGE_PACKET_MAX

LargePacketMax is maximum size of an hgfs packet

View Source
const (
	WriteAppend = 1
)

Write flags

Variables

View Source
var ArchiveScheme = "archive"

ArchiveScheme is the default scheme used to register the archive FileHandler

View Source
var (
	// Trace enables hgfs packet tracing
	Trace = false
)

Functions

func MarshalBinary

func MarshalBinary(fields ...interface{}) ([]byte, error)

MarshalBinary is a wrapper around binary.Write

func ProtocolError

func ProtocolError(err error) error

ProtocolError wraps the given error as a Status type

func UnmarshalBinary

func UnmarshalBinary(data []byte, fields ...interface{}) error

UnmarshalBinary is a wrapper around binary.Read

Types

type ArchiveHandler

type ArchiveHandler struct {
	Read  func(*url.URL, *tar.Reader) error
	Write func(*url.URL, *tar.Writer) error
}

ArchiveHandler implements a FileHandler for transferring directories.

func (*ArchiveHandler) Open

func (h *ArchiveHandler) Open(u *url.URL, mode int32) (File, error)

Open implements FileHandler.Open

func (*ArchiveHandler) Stat

func (*ArchiveHandler) Stat(u *url.URL) (os.FileInfo, error)

Stat implements FileHandler.Stat

type AttrV2

type AttrV2 struct {
	Mask           uint64
	Type           int32
	Size           uint64
	CreationTime   uint64
	AccessTime     uint64
	WriteTime      uint64
	AttrChangeTime uint64
	SpecialPerms   uint8
	OwnerPerms     uint8
	GroupPerms     uint8
	OtherPerms     uint8
	AttrFlags      uint64
	AllocationSize uint64
	UserID         uint32
	GroupID        uint32
	HostFileID     uint64
	VolumeID       uint32
	EffectivePerms uint32
	Reserved2      uint64
}

AttrV2 as defined in hgfsProto.h:HgfsAttrV2

func (*AttrV2) Stat

func (a *AttrV2) Stat(info os.FileInfo)

Stat maps os.FileInfo to AttrV2

type Capability

type Capability struct {
	Op    int32
	Flags uint32
}

Capability as defined in hgfsProto.h:HgfsCapability

type File

type File interface {
	io.Reader
	io.Writer
	io.Closer

	Name() string
}

File interface abstracts standard i/o methods to support transfer of regular files and archives of directories.

type FileHandler

type FileHandler interface {
	Stat(*url.URL) (os.FileInfo, error)
	Open(*url.URL, int32) (File, error)
}

FileHandler is the plugin interface for hgfs file transport.

func NewArchiveHandler

func NewArchiveHandler() FileHandler

NewArchiveHandler returns a FileHandler implementation for transferring directories using gzip'd tar files.

type FileName

type FileName struct {
	Length uint32
	Name   string
}

FileName as defined in hgfsProto.h:HgfsFileName

func (*FileName) FromString

func (f *FileName) FromString(name string)

FromString converts name to a FileName

func (*FileName) MarshalBinary

func (f *FileName) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*FileName) Path

func (f *FileName) Path() string

Path converts FileName to a string

func (*FileName) UnmarshalBinary

func (f *FileName) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type FileNameV3

type FileNameV3 struct {
	Length   uint32
	Flags    uint32
	CaseType int32
	ID       uint32
	Name     string
}

FileNameV3 as defined in hgfsProto.h:HgfsFileNameV3

func (*FileNameV3) FromString

func (f *FileNameV3) FromString(name string)

FromString converts name to a FileNameV3

func (*FileNameV3) MarshalBinary

func (f *FileNameV3) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*FileNameV3) Path

func (f *FileNameV3) Path() string

Path converts FileNameV3 to a string

func (*FileNameV3) UnmarshalBinary

func (f *FileNameV3) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type Header struct {
	Version     uint8
	Reserved1   [3]uint8
	Dummy       int32
	PacketSize  uint32
	HeaderSize  uint32
	RequestID   uint32
	Op          int32
	Status      uint32
	Flags       uint32
	Information uint32
	SessionID   uint64
	Reserved    uint64
}

Header as defined in hgfsProto.h:HgfsHeader

func (*Header) UnmarshalBinary

func (h *Header) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type Packet

type Packet struct {
	Header

	Payload []byte
}

Packet encapsulates an hgfs Header and Payload

func (*Packet) MarshalBinary

func (r *Packet) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*Packet) Reply

func (r *Packet) Reply(payload interface{}, err error) ([]byte, error)

Reply composes a new Packet with the given payload or error

func (*Packet) UnmarshalBinary

func (r *Packet) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type Reply

type Reply struct {
	Handle uint32
	Status uint32
}

Reply as defined in hgfsProto.h:HgfsReply

type ReplyClose

type ReplyClose struct {
	Reply
}

ReplyClose as defined in hgfsProto.h:HgfsReplyClose

type ReplyCreateSessionV4

type ReplyCreateSessionV4 struct {
	SessionID       uint64
	NumCapabilities uint32
	MaxPacketSize   uint32
	IdentityOffset  uint32
	Flags           uint32
	Reserved        uint32
	Capabilities    []Capability
}

ReplyCreateSessionV4 as defined in hgfsProto.h:HgfsReplyCreateSessionV4

func (*ReplyCreateSessionV4) MarshalBinary

func (r *ReplyCreateSessionV4) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*ReplyCreateSessionV4) UnmarshalBinary

func (r *ReplyCreateSessionV4) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type ReplyDestroySessionV4

type ReplyDestroySessionV4 struct {
	Reserved uint64
}

ReplyDestroySessionV4 as defined in hgfsProto.h:HgfsReplyDestroySessionV4

type ReplyGetattrV2

type ReplyGetattrV2 struct {
	Reply
	Attr          AttrV2
	SymlinkTarget FileName
}

ReplyGetattrV2 as defined in hgfsProto.h:HgfsReplyGetattrV2

func (*ReplyGetattrV2) MarshalBinary

func (r *ReplyGetattrV2) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*ReplyGetattrV2) UnmarshalBinary

func (r *ReplyGetattrV2) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type ReplyOpen

type ReplyOpen struct {
	Reply
	Handle uint32
}

ReplyOpen as defined in hgfsProto.h:HgfsReplyOpen

type ReplyOpenV3

type ReplyOpenV3 struct {
	Handle       uint32
	AcquiredLock int32
	Flags        int32
	Reserved     uint32
}

ReplyOpenV3 as defined in hgfsProto.h:HgfsReplyOpenV3

type ReplyReadV3

type ReplyReadV3 struct {
	ActualSize uint32
	Reserved   uint64
	Payload    []byte
}

ReplyReadV3 as defined in hgfsProto.h:HgfsReplyReadV3

func (*ReplyReadV3) MarshalBinary

func (r *ReplyReadV3) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*ReplyReadV3) UnmarshalBinary

func (r *ReplyReadV3) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type ReplySetattrV2

type ReplySetattrV2 struct {
	Header Reply
}

ReplySetattrV2 as defined in hgfsProto.h:HgfsReplySetattrV2

type ReplyWriteV3

type ReplyWriteV3 struct {
	ActualSize uint32
	Reserved   uint64
}

ReplyWriteV3 as defined in hgfsProto.h:HgfsReplyWriteV3

type Request

type Request struct {
	Handle uint32
	Op     int32
}

Request as defined in hgfsProto.h:HgfsRequest

type RequestClose

type RequestClose struct {
	Request
	Handle uint32
}

RequestClose as defined in hgfsProto.h:HgfsRequestClose

type RequestCreateSessionV4

type RequestCreateSessionV4 struct {
	NumCapabilities uint32
	MaxPacketSize   uint32
	Flags           uint32
	Reserved        uint32
	Capabilities    []Capability
}

RequestCreateSessionV4 as defined in hgfsProto.h:HgfsRequestCreateSessionV4

func (*RequestCreateSessionV4) MarshalBinary

func (r *RequestCreateSessionV4) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestCreateSessionV4) UnmarshalBinary

func (r *RequestCreateSessionV4) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type RequestDestroySessionV4

type RequestDestroySessionV4 struct {
	Reserved uint64
}

RequestDestroySessionV4 as defined in hgfsProto.h:HgfsRequestDestroySessionV4

type RequestGetattrV2

type RequestGetattrV2 struct {
	Request
	AttrHint uint64
	Handle   uint32
	FileName FileName
}

RequestGetattrV2 as defined in hgfsProto.h:HgfsRequestGetattrV2

func (*RequestGetattrV2) MarshalBinary

func (r *RequestGetattrV2) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestGetattrV2) UnmarshalBinary

func (r *RequestGetattrV2) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type RequestOpen

type RequestOpen struct {
	Request
	OpenMode    int32
	OpenFlags   int32
	Permissions uint8
	FileName    FileName
}

RequestOpen as defined in hgfsProto.h:HgfsRequestOpen

func (*RequestOpen) MarshalBinary

func (r *RequestOpen) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestOpen) UnmarshalBinary

func (r *RequestOpen) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type RequestOpenV3

type RequestOpenV3 struct {
	Mask           uint64
	OpenMode       int32
	OpenFlags      int32
	SpecialPerms   uint8
	OwnerPerms     uint8
	GroupPerms     uint8
	OtherPerms     uint8
	AttrFlags      uint64
	AllocationSize uint64
	DesiredAccess  uint32
	ShareAccess    uint32
	DesiredLock    int32
	Reserved1      uint64
	Reserved2      uint64
	FileName       FileNameV3
}

RequestOpenV3 as defined in hgfsProto.h:HgfsRequestOpenV3

func (*RequestOpenV3) MarshalBinary

func (r *RequestOpenV3) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestOpenV3) UnmarshalBinary

func (r *RequestOpenV3) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type RequestReadV3

type RequestReadV3 struct {
	Handle       uint32
	Offset       uint64
	RequiredSize uint32
	Reserved     uint64
}

RequestReadV3 as defined in hgfsProto.h:HgfsRequestReadV3

type RequestSetattrV2

type RequestSetattrV2 struct {
	Request
	Hints    uint64
	Attr     AttrV2
	Handle   uint32
	FileName FileName
}

RequestSetattrV2 as defined in hgfsProto.h:HgfsRequestSetattrV2

func (*RequestSetattrV2) MarshalBinary

func (r *RequestSetattrV2) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestSetattrV2) UnmarshalBinary

func (r *RequestSetattrV2) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type RequestWriteV3

type RequestWriteV3 struct {
	Handle       uint32
	WriteFlags   uint8
	Offset       uint64
	RequiredSize uint32
	Reserved     uint64
	Payload      []byte
}

RequestWriteV3 as defined in hgfsProto.h:HgfsRequestWriteV3

func (*RequestWriteV3) MarshalBinary

func (r *RequestWriteV3) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface

func (*RequestWriteV3) UnmarshalBinary

func (r *RequestWriteV3) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface

type Server

type Server struct {
	Capabilities []Capability
	// contains filtered or unexported fields
}

Server provides an HGFS protocol implementation to support guest tools VmxiHgfsSendPacketCommand

func NewServer

func NewServer() *Server

NewServer creates a new Server instance with the default handlers

func (*Server) Close

func (s *Server) Close(p *Packet) (interface{}, error)

Close handles OpClose requests

func (*Server) CreateSessionV4

func (s *Server) CreateSessionV4(p *Packet) (interface{}, error)

CreateSessionV4 handls OpCreateSessionV4 requests

func (*Server) DestroySessionV4

func (s *Server) DestroySessionV4(p *Packet) (interface{}, error)

DestroySessionV4 handls OpDestroySessionV4 requests

func (*Server) Dispatch

func (s *Server) Dispatch(packet []byte) ([]byte, error)

Dispatch unpacks the given request packet and dispatches to the appropriate handler

func (*Server) GetattrV2

func (s *Server) GetattrV2(p *Packet) (interface{}, error)

GetattrV2 handles OpGetattrV2 requests

func (*Server) Open

func (s *Server) Open(p *Packet) (interface{}, error)

Open handles OpOpen requests

func (*Server) OpenFile

func (s *Server) OpenFile(name string, mode int32) (File, error)

OpenFile selects the File implementation based on file type and mode.

func (*Server) OpenV3

func (s *Server) OpenV3(p *Packet) (interface{}, error)

OpenV3 handles OpOpenV3 requests

func (*Server) ReadV3

func (s *Server) ReadV3(p *Packet) (interface{}, error)

ReadV3 handles OpReadV3 requests

func (*Server) RegisterFileHandler

func (s *Server) RegisterFileHandler(scheme string, handler FileHandler)

RegisterFileHandler enables dispatch to handler for the given scheme.

func (*Server) SetattrV2

func (s *Server) SetattrV2(p *Packet) (interface{}, error)

SetattrV2 handles OpSetattrV2 requests

func (*Server) Stat

func (s *Server) Stat(name string) (os.FileInfo, error)

Stat wraps os.Stat such that we can report directory types as regular files to support archive streaming. In the case of standard vmware-tools, attempts to transfer directories result with a VIX_E_NOT_A_FILE (see InitiateFileTransfer{To,From}Guest). Note that callers on the VMX side that reach this path are only concerned with: - does the file exist? - size:

  • used for UI progress with desktop Drag-N-Drop operations, which toolbox does not support.
  • sent to as Content-Length header in response to GET of FileTransferInformation.Url, if the first ReadV3 size is > HGFS_LARGE_PACKET_MAX

func (*Server) WriteV3

func (s *Server) WriteV3(p *Packet) (interface{}, error)

WriteV3 handles OpWriteV3 requests

type Status

type Status struct {
	Err  error
	Code uint32
}

Status is an error type that encapsulates an error status code and the cause

func (*Status) Error

func (s *Status) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL