From d9811569588ba44be878a00ce316f59a37abed8b Mon Sep 17 00:00:00 2001 From: Olli Janatuinen Date: Wed, 25 Aug 2021 08:10:29 -0700 Subject: [PATCH] fix: allow Build for Windows Use syscall library instead of unix specific Add non implemented versions of functions same way than they are done for Darwin Signed-off-by: Olli Janatuinen --- blockdevice/blkpg/blkpg_windows.go | 30 +++++++++++ blockdevice/blockdevice_windows.go | 80 ++++++++++++++++++++++++++++++ blockdevice/filesystem/fs.go | 4 +- blockdevice/lba/lba_windows.go | 25 ++++++++++ 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 blockdevice/blkpg/blkpg_windows.go create mode 100644 blockdevice/blockdevice_windows.go create mode 100644 blockdevice/lba/lba_windows.go diff --git a/blockdevice/blkpg/blkpg_windows.go b/blockdevice/blkpg/blkpg_windows.go new file mode 100644 index 0000000..f5cea24 --- /dev/null +++ b/blockdevice/blkpg/blkpg_windows.go @@ -0,0 +1,30 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package blkpg + +import ( + "fmt" + "os" +) + +// InformKernelOfAdd invokes the BLKPG_ADD_PARTITION ioctl. +func InformKernelOfAdd(f *os.File, first, length uint64, n int32) error { + return fmt.Errorf("not implemented") +} + +// InformKernelOfResize invokes the BLKPG_RESIZE_PARTITION ioctl. +func InformKernelOfResize(f *os.File, first, length uint64, n int32) error { + return fmt.Errorf("not implemented") +} + +// InformKernelOfDelete invokes the BLKPG_DEL_PARTITION ioctl. +func InformKernelOfDelete(f *os.File, first, length uint64, n int32) error { + return fmt.Errorf("not implemented") +} + +// GetKernelPartitions returns kernel partition table state. +func GetKernelPartitions(f *os.File) ([]KernelPartition, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/blockdevice/blockdevice_windows.go b/blockdevice/blockdevice_windows.go new file mode 100644 index 0000000..1585c7e --- /dev/null +++ b/blockdevice/blockdevice_windows.go @@ -0,0 +1,80 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package blockdevice + +import ( + "fmt" + "os" + + "github.com/talos-systems/go-blockdevice/blockdevice/partition/gpt" +) + +// BlockDevice represents a block device. +type BlockDevice struct { + table *gpt.GPT + + f *os.File +} + +// Open initializes and returns a block device. +// TODO(andrewrynhard): Use BLKGETSIZE ioctl to get the size. +func Open(devname string, setters ...Option) (bd *BlockDevice, err error) { + return nil, fmt.Errorf("not implemented") +} + +// Close closes the block devices's open file. +func (bd *BlockDevice) Close() error { + return fmt.Errorf("not implemented") +} + +// PartitionTable returns the block device partition table. +func (bd *BlockDevice) PartitionTable() (*gpt.GPT, error) { + return nil, fmt.Errorf("not implemented") +} + +// RereadPartitionTable invokes the BLKRRPART ioctl to have the kernel read the +// partition table. +// +// NB: Rereading the partition table requires that all partitions be +// unmounted or it will fail with EBUSY. +func (bd *BlockDevice) RereadPartitionTable() error { + return fmt.Errorf("not implemented") +} + +// Device returns the backing file for the block device. +func (bd *BlockDevice) Device() *os.File { + return nil +} + +// Size returns the size of the block device in bytes. +func (bd *BlockDevice) Size() (uint64, error) { + return 0, fmt.Errorf("not implemented") +} + +// Reset will reset a block device given a device name. +// Simply deletes partition table on device. +func (bd *BlockDevice) Reset() error { + return fmt.Errorf("not implemented") +} + +// Wipe the blockdevice contents. +func (bd *BlockDevice) Wipe() error { + return fmt.Errorf("not implemented") +} + +// OpenPartition opens another blockdevice using a partition of this block device. +func (bd *BlockDevice) OpenPartition(label string, setters ...Option) (*BlockDevice, error) { + return nil, fmt.Errorf("not implemented") +} + +// GetPartition returns partition by label if found. +func (bd *BlockDevice) GetPartition(label string) (*gpt.Partition, error) { + return nil, fmt.Errorf("not implemented") +} + +// PartPath returns partition path by label, verifies that partition exists. +func (bd *BlockDevice) PartPath(label string) (string, error) { + return "", fmt.Errorf("not implemented") +} diff --git a/blockdevice/filesystem/fs.go b/blockdevice/filesystem/fs.go index 4b626d2..5ae4101 100644 --- a/blockdevice/filesystem/fs.go +++ b/blockdevice/filesystem/fs.go @@ -8,10 +8,10 @@ import ( "encoding/binary" "io" "os" + "syscall" "time" "github.com/talos-systems/go-retry/retry" - "golang.org/x/sys/unix" "github.com/talos-systems/go-blockdevice/blockdevice/filesystem/iso9660" "github.com/talos-systems/go-blockdevice/blockdevice/filesystem/luks" @@ -39,7 +39,7 @@ func Probe(path string) (sb SuperBlocker, err error) { // If we dont sleep this becomes racy in that the device file does not exist // and it will fail to open. err = retry.Constant(5*time.Second, retry.WithUnits((50 * time.Millisecond))).Retry(func() error { - if f, err = os.OpenFile(path, os.O_RDONLY|unix.O_CLOEXEC, os.ModeDevice); err != nil { + if f, err = os.OpenFile(path, os.O_RDONLY|syscall.O_CLOEXEC, os.ModeDevice); err != nil { if os.IsNotExist(err) { return retry.ExpectedError(err) } diff --git a/blockdevice/lba/lba_windows.go b/blockdevice/lba/lba_windows.go new file mode 100644 index 0000000..65f9542 --- /dev/null +++ b/blockdevice/lba/lba_windows.go @@ -0,0 +1,25 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package lba + +import ( + "fmt" + "os" +) + +// NewLBA initializes and returns an `LBA`. +func NewLBA(f *os.File) (lba *LBA, err error) { + return nil, fmt.Errorf("not implemented") +} + +// ReadAt reads from a file in units of LBA. +func (l *LBA) ReadAt(lba, off, length int64) (b []byte, err error) { + return nil, fmt.Errorf("not implemented") +} + +// WriteAt writes to a file in units of LBA. +func (l *LBA) WriteAt(lba, off int64, b []byte) (err error) { + return fmt.Errorf("not implemented") +}