Skip to content

Commit

Permalink
feat: implement GPT editing
Browse files Browse the repository at this point in the history
Lots of ideas from v1, coupled with new data structures and simplified
ideas plus proper testing.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Jul 24, 2024
1 parent 9d8d8e7 commit cfdeb03
Show file tree
Hide file tree
Showing 44 changed files with 1,527 additions and 211 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-05-06T05:59:06Z by kres d15226e.
# Generated on 2024-07-17T17:13:05Z by kres ac94478-dirty.

*
!internal
!blkid
!block
!go.mod
Expand Down
2 changes: 2 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
kind: custom.Step
name: zfs-img
spec:
makefile:
enabled: true
docker:
enabled: true
stages:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-15T11:59:50Z by kres ac94478.
# Generated on 2024-07-17T17:17:17Z by kres ac94478-dirty.

ARG TOOLCHAIN

Expand Down Expand Up @@ -56,6 +56,7 @@ COPY go.sum go.sum
RUN cd .
RUN --mount=type=cache,target=/go/pkg go mod download
RUN --mount=type=cache,target=/go/pkg go mod verify
COPY ./internal ./internal
COPY ./blkid ./blkid
COPY ./block ./block
RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-07-15T11:59:50Z by kres ac94478.
# Generated on 2024-07-17T17:17:17Z by kres ac94478-dirty.

# common variables

Expand Down Expand Up @@ -175,6 +175,8 @@ unit-tests: ## Performs unit tests
unit-tests-race: ## Performs unit tests with race detection enabled.
@$(MAKE) target-$@ TARGET_ARGS="--allow security.insecure"

zfs-img:

.PHONY: lint
lint: lint-golangci-lint lint-gofumpt lint-govulncheck ## Run all linters for the project.

Expand Down
5 changes: 3 additions & 2 deletions blkid/internal/filesystems/ext/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Package ext probes extfs filesystems.
package ext

//go:generate go run ../../cstruct/cstruct.go -pkg ext -struct SuperBlock -input superblock.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg ext -struct SuperBlock -input superblock.h -endianness LittleEndian

import (
"bytes"
Expand All @@ -16,6 +16,7 @@ import (
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

const sbOffset = 0x400
Expand Down Expand Up @@ -49,7 +50,7 @@ func (p *Probe) Name() string {
func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
buf := make([]byte, SUPERBLOCK_SIZE)

if err := utils.ReadFullAt(r, buf, sbOffset); err != nil {
if err := ioutil.ReadFullAt(r, buf, sbOffset); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/iso9660/iso9660.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Package iso9660 probes ISO9660 filesystems.
package iso9660

//go:generate go run ../../cstruct/cstruct.go -pkg iso9660 -struct VolumeDescriptor -input volume.h -endianness NativeEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg iso9660 -struct VolumeDescriptor -input volume.h -endianness NativeEndian

import (
"strings"
Expand All @@ -15,7 +15,7 @@ import (

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

const (
Expand Down Expand Up @@ -62,7 +62,7 @@ vdLoop:
for i := range vdMax {
buf := make([]byte, VOLUMEDESCRIPTOR_SIZE)

if err := utils.ReadFullAt(r, buf, superblockOffset+sectorSize*int64(i)); err != nil {
if err := ioutil.ReadFullAt(r, buf, superblockOffset+sectorSize*int64(i)); err != nil {
break
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/luks/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Package luks probes LUKS encrypted filesystems.
package luks

//go:generate go run ../../cstruct/cstruct.go -pkg luks -struct Luks2Header -input luks2_header.h -endianness BigEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg luks -struct Luks2Header -input luks2_header.h -endianness BigEndian

import (
"bytes"
Expand All @@ -15,7 +15,7 @@ import (

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var luksMagic = magic.Magic{
Expand All @@ -40,7 +40,7 @@ func (p *Probe) Name() string {
func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
buf := make([]byte, LUKS2HEADER_SIZE)

if err := utils.ReadFullAt(r, buf, 0); err != nil {
if err := ioutil.ReadFullAt(r, buf, 0); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/lvm2/lvm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Package lvm2 probes LVM2 PVs.
package lvm2

//go:generate go run ../../cstruct/cstruct.go -pkg lvm2 -struct LVM2Header -input lvm2_header.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg lvm2 -struct LVM2Header -input lvm2_header.h -endianness LittleEndian

import (
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var (
Expand Down Expand Up @@ -44,7 +44,7 @@ func (p *Probe) Name() string {
func (p *Probe) probe(r probe.Reader, offset int64) (LVM2Header, error) {
buf := make([]byte, LVM2HEADER_SIZE)

if err := utils.ReadFullAt(r, buf, offset); err != nil {
if err := ioutil.ReadFullAt(r, buf, offset); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/squashfs/squashfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Package squashfs probes Squash filesystems.
package squashfs

//go:generate go run ../../cstruct/cstruct.go -pkg squashfs -struct SuperBlock -input superblock.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg squashfs -struct SuperBlock -input superblock.h -endianness LittleEndian

import (
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var squashfsMagic1 = magic.Magic{ // big endian
Expand Down Expand Up @@ -43,7 +43,7 @@ func (p *Probe) Name() string {
func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
buf := make([]byte, SUPERBLOCK_SIZE)

if err := utils.ReadFullAt(r, buf, 0); err != nil {
if err := ioutil.ReadFullAt(r, buf, 0); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/swap/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package swap

// TODO: is it little or host endian?
//go:generate go run ../../cstruct/cstruct.go -pkg swap -struct SwapHeader -input swap_header.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg swap -struct SwapHeader -input swap_header.h -endianness LittleEndian

import (
"bytes"
Expand All @@ -16,7 +16,7 @@ import (

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var (
Expand Down Expand Up @@ -99,7 +99,7 @@ func (p *Probe) Name() string {
func (p *Probe) Probe(r probe.Reader, m magic.Magic) (*probe.Result, error) {
buf := make([]byte, SWAPHEADER_SIZE)

if err := utils.ReadFullAt(r, buf, 1024); err != nil {
if err := ioutil.ReadFullAt(r, buf, 1024); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/talosmeta/talosmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

// META constants, from talos/internal/pkg/meta/internal/adv/talos.
Expand Down Expand Up @@ -45,15 +45,15 @@ func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
buf := make([]byte, 4)

for _, offset := range []int64{0, length} {
if err := utils.ReadFullAt(r, buf, offset); err != nil {
if err := ioutil.ReadFullAt(r, buf, offset); err != nil {
return nil, err
}

if binary.BigEndian.Uint32(buf) != magic1 {
continue
}

if err := utils.ReadFullAt(r, buf, offset+length-4); err != nil {
if err := ioutil.ReadFullAt(r, buf, offset+length-4); err != nil {
return nil, err
}

Expand Down
9 changes: 5 additions & 4 deletions blkid/internal/filesystems/vfat/vfat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
// Package vfat probes FAT12/FAT16/FAT32 filesystems.
package vfat

//go:generate go run ../../cstruct/cstruct.go -pkg vfat -struct MSDOSSB -input msdos.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg vfat -struct MSDOSSB -input msdos.h -endianness LittleEndian

//go:generate go run ../../cstruct/cstruct.go -pkg vfat -struct VFATSB -input vfat.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg vfat -struct VFATSB -input vfat.h -endianness LittleEndian

import (
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var (
Expand Down Expand Up @@ -72,11 +73,11 @@ func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
vfatBuf := make([]byte, VFATSB_SIZE)
msdosBuf := make([]byte, MSDOSSB_SIZE)

if err := utils.ReadFullAt(r, vfatBuf, 0); err != nil {
if err := ioutil.ReadFullAt(r, vfatBuf, 0); err != nil {
return nil, err
}

if err := utils.ReadFullAt(r, msdosBuf, 0); err != nil {
if err := ioutil.ReadFullAt(r, msdosBuf, 0); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/xfs/xfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Package xfs probes XFS filesystems.
package xfs

//go:generate go run ../../cstruct/cstruct.go -pkg xfs -struct SuperBlock -input superblock.h -endianness BigEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg xfs -struct SuperBlock -input superblock.h -endianness BigEndian

import (
"bytes"
Expand All @@ -16,7 +16,7 @@ import (

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

var xfsMagic = magic.Magic{
Expand All @@ -41,7 +41,7 @@ func (p *Probe) Name() string {
func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
buf := make([]byte, SUPERBLOCK_SIZE)

if err := utils.ReadFullAt(r, buf, 0); err != nil {
if err := ioutil.ReadFullAt(r, buf, 0); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions blkid/internal/filesystems/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// Package zfs probes ZFS filesystems.
package zfs

//go:generate go run ../../cstruct/cstruct.go -pkg zfs -struct ZFSUB -input zfs.h -endianness LittleEndian
//go:generate go run ../../../../internal/cstruct/cstruct.go -pkg zfs -struct ZFSUB -input zfs.h -endianness LittleEndian

import (
"fmt"

"github.com/siderolabs/go-blockdevice/v2/blkid/internal/magic"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/probe"
"github.com/siderolabs/go-blockdevice/v2/blkid/internal/utils"
"github.com/siderolabs/go-blockdevice/v2/internal/ioutil"
)

// https://github.com/util-linux/util-linux/blob/c0207d354ee47fb56acfa64b03b5b559bb301280/libblkid/src/superblocks/zfs.c
Expand Down Expand Up @@ -66,7 +66,7 @@ func (p *Probe) Probe(r probe.Reader, _ magic.Magic) (*probe.Result, error) {
size - zfsStartOffset - lastLabelOffset,
} {
labelBuf := make([]byte, zfsVdevLabelSize)
if err := utils.ReadFullAt(r, labelBuf, int64(labelOffset)); err != nil {
if err := ioutil.ReadFullAt(r, labelBuf, int64(labelOffset)); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit cfdeb03

Please sign in to comment.