nbd

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NEGOTIATION_MAGIC_OLDSTYLE = uint64(0x4e42444d41474943)
	NEGOTIATION_MAGIC_OPTION   = uint64(0x49484156454F5054)
	NEGOTIATION_MAGIC_REPLY    = uint64(0x3e889045565a9)

	NEGOTIATION_HANDSHAKE_FLAG_FIXED_NEWSTYLE = uint16(1 << 0)

	NEGOTIATION_ID_OPTION_ABORT = uint32(2)
	NEGOTIATION_ID_OPTION_LIST  = uint32(3)
	NEGOTIATION_ID_OPTION_INFO  = uint32(6)
	NEGOTIATION_ID_OPTION_GO    = uint32(7)

	NEGOTIATION_TYPE_REPLY_ACK             = uint32(1)
	NEGOTIATION_TYPE_REPLY_SERVER          = uint32(2)
	NEGOTIATION_TYPE_REPLY_INFO            = uint32(3)
	NEGOTIATION_TYPE_REPLY_ERR_UNSUPPORTED = uint32(1 | uint32(1<<31))
	NEGOTIATION_TYPE_REPLY_ERR_UNKNOWN     = uint32(6 | uint32(1<<31))

	NEGOTIATION_TYPE_INFO_EXPORT      = uint16(0)
	NEGOTIATION_TYPE_INFO_NAME        = uint16(1)
	NEGOTIATION_TYPE_INFO_DESCRIPTION = uint16(2)
	NEGOTIATION_TYPE_INFO_BLOCKSIZE   = uint16(3)

	NEGOTIATION_REPLY_FLAGS_HAS_FLAGS      = uint16((1 << 0))
	NEGOTIATION_REPLY_FLAGS_CAN_MULTI_CONN = uint16((1 << 8))

	NEGO_FLAG_READONLY          = uint16(1 << 1)
	NEGO_FLAG_SEND_FLUSH        = uint16(1 << 2)
	NEGO_FLAG_SEND_FUA          = uint16(1 << 3)
	NEGO_FLAG_ROTATIONAL        = uint16(1 << 4)
	NEGO_FLAG_SEND_TRIM         = uint16(1 << 5)
	NEGO_FLAG_SEND_WRITE_ZEROES = uint16(1 << 6)
	NEGO_FLAG_SEND_DF           = uint16(1 << 7)
	NEGO_FLAG_SEND_RESIZE       = uint16(1 << 9)
	NEGO_FLAG_SEND_CACHE        = uint16(1 << 10)
	NEGO_FLAG_FAST_ZERO         = uint16(1 << 11)
	NEGO_FLAG_BLOCK_STATUS      = uint16(1 << 12)
)
View Source
const (
	TRANSMISSION_MAGIC_REQUEST = uint32(0x25609513)
	TRANSMISSION_MAGIC_REPLY   = uint32(0x67446698)

	TRANSMISSION_TYPE_REQUEST_READ   = uint16(0)
	TRANSMISSION_TYPE_REQUEST_WRITE  = uint16(1)
	TRANSMISSION_TYPE_REQUEST_DISC   = uint16(2)
	TRANSMISSION_TYPE_REQUEST_FLUSH  = uint16(3)
	TRANSMISSION_TYPE_REQUEST_TRIM   = uint16(4)
	TRANSMISSION_TYPE_REQUEST_CACHE  = uint16(5)
	TRANSMISSION_TYPE_REQUEST_WRITEZ = uint16(6)
	TRANSMISSION_TYPE_REQUEST_STATUS = uint16(7)

	TRANSMISSION_ERROR_EPERM  = uint32(1)
	TRANSMISSION_ERROR_EINVAL = uint32(22)
)
View Source
const (
	MaxInsaneLength = 512 * 1024 * 1024 // Reject requests larger than 512M as insane
)

Variables

View Source
var (
	ErrInvalidMagic     = errors.New("invalid magic")
	ErrInvalidBlocksize = errors.New("invalid blocksize")
)

Functions

func Handle

func Handle(log *slog.Logger, conn net.Conn, exports []*Export, options *Options) error

func HandleTransport

func HandleTransport(log *slog.Logger, conn net.Conn, backend Backend, options *Options) error

Types

type Backend

type Backend interface {
	io.ReaderAt
	io.WriterAt

	ReadIntoConn(optional []byte, off int64, output *os.File) (bool, error)

	ZeroAt(off, sz int64) error
	Trim(off, sz int64) error

	Size() (int64, error)
	Sync() error

	Tick()
}

type BackendOpen

type BackendOpen interface {
	Open() Backend
	Close(b Backend)
}

type Export

type Export struct {
	Name        string
	Description string

	BackendOpen BackendOpen
	Backend     Backend
}

type NegotiationNewstyleHeader

type NegotiationNewstyleHeader struct {
	OldstyleMagic  uint64
	OptionMagic    uint64
	HandshakeFlags uint16
}

type NegotiationOptionHeader

type NegotiationOptionHeader struct {
	OptionMagic uint64
	ID          uint32
	Length      uint32
}

type NegotiationReplyBlockSize

type NegotiationReplyBlockSize struct {
	Type               uint16
	MinimumBlockSize   uint32
	PreferredBlockSize uint32
	MaximumRequestSize uint32
}

type NegotiationReplyDescriptionHeader

type NegotiationReplyDescriptionHeader NegotiationReplyNameHeader

type NegotiationReplyHeader

type NegotiationReplyHeader struct {
	ReplyMagic uint64
	ID         uint32
	Type       uint32
	Length     uint32
}

type NegotiationReplyInfo

type NegotiationReplyInfo struct {
	Type              uint16
	Size              uint64
	TransmissionFlags uint16
}

type NegotiationReplyNameHeader

type NegotiationReplyNameHeader struct {
	Type uint16
}

type Options

type Options struct {
	ReadOnly bool

	MinimumBlockSize   uint32
	PreferredBlockSize uint32
	MaximumRequestSize uint32
	SupportsMultiConn  bool

	RawFile *os.File
}

type TransmissionReplyHeader

type TransmissionReplyHeader struct {
	ReplyMagic uint32
	Error      uint32
	Handle     uint64
}

type TransmissionRequestHeader

type TransmissionRequestHeader struct {
	RequestMagic uint32
	CommandFlags uint16
	Type         uint16
	Handle       uint64
	Offset       uint64
	Length       uint32
}

Jump to

Keyboard shortcuts

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