-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: start the blkid work #77
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. | ||
# | ||
# Generated on 2024-02-05T11:19:51Z by kres 0e666ea. | ||
# Generated on 2024-02-09T14:38:27Z by kres latest. | ||
|
||
* | ||
!blkid | ||
!block | ||
!go.mod | ||
!go.sum | ||
!.golangci.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
kind: common.Repository | ||
spec: | ||
mainBranch: v2 | ||
--- | ||
kind: common.Docker | ||
name: setup-ci | ||
spec: | ||
allowInsecure: true | ||
--- | ||
kind: golang.UnitTests | ||
name: unit-tests | ||
spec: | ||
requiresInsecure: true | ||
--- | ||
kind: golang.Toolchain | ||
spec: | ||
extraPackages: | ||
- cdrkit | ||
- cryptsetup | ||
- dosfstools | ||
- e2fsprogs | ||
- xfsprogs | ||
--- | ||
kind: service.CodeCov | ||
spec: | ||
targetThreshold: 40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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 blkid provides information about blockdevice filesystem types and IDs. | ||
package blkid | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
|
||
"github.com/siderolabs/go-blockdevice/v2/block" | ||
) | ||
|
||
// Info represents the result of the probe. | ||
type Info struct { //nolint:govet | ||
// Link to the block device, only if the probed file is a blockdevice. | ||
BlockDevice *block.Device | ||
|
||
// Overall size of the probed device (in bytes). | ||
Size uint64 | ||
|
||
// Optimal I/O size for the device (in bytes). | ||
IOSize uint64 | ||
|
||
// TODO: API might be different. | ||
Name string | ||
UUID *uuid.UUID | ||
Label *string | ||
|
||
BlockSize uint32 | ||
FilesystemBlockSize uint32 | ||
FilesystemSize uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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/. | ||
|
||
//go:build linux | ||
|
||
package blkid | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/siderolabs/go-blockdevice/v2/block" | ||
) | ||
|
||
// ProbePath returns the probe information for the specified path. | ||
func ProbePath(devpath string) (*Info, error) { | ||
f, err := os.OpenFile(devpath, os.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer f.Close() //nolint:errcheck | ||
|
||
return Probe(f) | ||
} | ||
|
||
// Probe returns the probe information for the specified file. | ||
func Probe(f *os.File) (*Info, error) { | ||
unix.Fadvise(int(f.Fd()), 0, 0, unix.FADV_RANDOM) //nolint:errcheck // best-effort: we don't care if this fails | ||
|
||
st, err := f.Stat() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to stat: %w", err) | ||
} | ||
|
||
info := &Info{} | ||
|
||
sysStat := st.Sys().(*syscall.Stat_t) //nolint:errcheck,forcetypeassert // we know it's a syscall.Stat_t | ||
|
||
switch sysStat.Mode & unix.S_IFMT { | ||
case unix.S_IFBLK: | ||
// block device, initialize full support | ||
info.BlockDevice = block.NewFromFile(f) | ||
|
||
if size, err := info.BlockDevice.GetSize(); err == nil { | ||
info.Size = size | ||
} else { | ||
return nil, fmt.Errorf("failed to get block device size: %w", err) | ||
} | ||
|
||
if ioSize, err := info.BlockDevice.GetIOSize(); err == nil { | ||
info.IOSize = ioSize | ||
} else { | ||
return nil, fmt.Errorf("failed to get block device I/O size: %w", err) | ||
} | ||
case unix.S_IFREG: | ||
// regular file (an image?), so use different settings | ||
info.Size = uint64(st.Size()) | ||
info.IOSize = block.DefaultBlockSize | ||
default: | ||
return nil, fmt.Errorf("unsupported file type: %s", st.Mode().Type()) | ||
} | ||
|
||
if err := info.probe(f, 0, info.Size); err != nil { | ||
return nil, fmt.Errorf("failed to probe: %w", err) | ||
} | ||
|
||
return info, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had to look up what was this 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go find
mkisofs
:-D