Skip to content

Commit

Permalink
feat: implement GPT partition discovery
Browse files Browse the repository at this point in the history
Fixes #79

Handles discovery of GPT partitions, including discovery of partition
filesystems.

The GPT code will be later refactored to support also writing GPT
partitions in addition to discovering them.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Mar 1, 2024
1 parent 9beb2bd commit a5481f5
Show file tree
Hide file tree
Showing 29 changed files with 1,076 additions and 140 deletions.
77 changes: 44 additions & 33 deletions .conform.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2024-02-05T11:19:51Z by kres 0e666ea.
# Generated on 2024-02-29T11:53:44Z by kres latest.

---
policies:
- type: commit
spec:
dco: true
gpg:
required: true
identity:
gitHubOrganization: siderolabs
spellcheck:
locale: US
maximumOfOneCommit: true
header:
length: 89
imperative: true
case: lower
invalidLastCharacters: .
body:
required: true
conventional:
types: ["chore","docs","perf","refactor","style","test","release"]
scopes: [".*"]
- type: license
spec:
skipPaths:
- .git/
- testdata/
includeSuffixes:
- .go
excludeSuffixes:
- .pb.go
- .pb.gw.go
header: "// This Source Code Form is subject to the terms of the Mozilla Public\u000A// License, v. 2.0. If a copy of the MPL was not distributed with this\u000A// file, You can obtain one at http://mozilla.org/MPL/2.0/.\u000A"
- type: commit
spec:
dco: true
gpg:
required: true
identity:
gitHubOrganization: siderolabs
spellcheck:
locale: US
maximumOfOneCommit: true
header:
length: 89
imperative: true
case: lower
invalidLastCharacters: .
body:
required: true
conventional:
types:
- chore
- docs
- perf
- refactor
- style
- test
- release
scopes:
- .*
- type: license
spec:
root: .
skipPaths:
- .git/
- testdata/
includeSuffixes:
- .go
excludeSuffixes:
- .pb.go
- .pb.gw.go
header: |
// 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/.
2 changes: 2 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spec:
- cryptsetup
- dosfstools
- e2fsprogs
- parted
- util-linux
- xfsprogs
---
kind: service.CodeCov
Expand Down
4 changes: 2 additions & 2 deletions 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-02-23T15:08:58Z by kres latest.
# Generated on 2024-03-01T13:44:11Z by kres latest.

ARG TOOLCHAIN

Expand All @@ -11,7 +11,7 @@ FROM scratch AS generate

# base toolchain image
FROM ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev cdrkit cryptsetup dosfstools e2fsprogs xfsprogs
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev cdrkit cryptsetup dosfstools e2fsprogs parted util-linux xfsprogs

# build tools
FROM --platform=${BUILDPLATFORM} toolchain AS tools
Expand Down
37 changes: 34 additions & 3 deletions blkid/blkdid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,46 @@ type Info struct { //nolint:govet
// Overall size of the probed device (in bytes).
Size uint64

// Sector size of the device (in bytes).
SectorSize uint

// Optimal I/O size for the device (in bytes).
IOSize uint64
IOSize uint

// ProbeResult is the result of probing the device.
ProbeResult

// TODO: API might be different.
// Parts is the result of probing the nested filesystem/partitions.
Parts []NestedProbeResult
}

// ProbeResult is a result of probing a single filesystem/partition.
type ProbeResult struct { //nolint:govet
Name string
UUID *uuid.UUID
Label *string

BlockSize uint32
FilesystemBlockSize uint32
FilesystemSize uint64
ProbedSize uint64
}

// NestedResult is result of probing a nested filesystem/partition.
//
// It annotates the ProbeResult with the partition information.
type NestedResult struct {
PartitionUUID *uuid.UUID
PartitionType *uuid.UUID
PartitionLabel *string
PartitionIndex uint // 1-based index

PartitionOffset, PartitionSize uint64
}

// NestedProbeResult is a result of probing a nested filesystem/partition.
type NestedProbeResult struct { //nolint:govet
NestedResult
ProbeResult

Parts []NestedProbeResult
}
5 changes: 4 additions & 1 deletion blkid/blkid_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ func Probe(f *os.File) (*Info, error) {
} else {
return nil, fmt.Errorf("failed to get block device I/O size: %w", err)
}

info.SectorSize = info.BlockDevice.GetSectorSize()
case unix.S_IFREG:
// regular file (an image?), so use different settings
info.Size = uint64(st.Size())
info.IOSize = block.DefaultBlockSize
info.SectorSize = block.DefaultBlockSize
default:
return nil, fmt.Errorf("unsupported file type: %s", st.Mode().Type())
}

if err := info.probe(f, 0, info.Size); err != nil {
if err := info.fillProbeResult(f); err != nil {
return nil, fmt.Errorf("failed to probe: %w", err)
}

Expand Down
Loading

0 comments on commit a5481f5

Please sign in to comment.