Skip to content
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: support reading VFAT volume labels #118

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions blkid/blkid_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -83,14 +84,16 @@ func ext4Setup(t *testing.T, path string) {
require.NoError(t, cmd.Run())
}

func vfatSetup(t *testing.T, path string) {
t.Helper()
func vfatSetup(bits int) func(t *testing.T, path string) {
return func(t *testing.T, path string) {
t.Helper()

cmd := exec.Command("mkfs.vfat", "-v", path)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd := exec.Command("mkfs.vfat", "-F", strconv.Itoa(bits), "-n", "TALOS_V1", "-v", path)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

require.NoError(t, cmd.Run())
require.NoError(t, cmd.Run())
}
}

func luksSetup(t *testing.T, path string) {
Expand Down Expand Up @@ -325,7 +328,7 @@ func TestProbePathFilesystems(t *testing.T) {
name: "vfat small",

size: 100 * MiB,
setup: vfatSetup,
setup: vfatSetup(16),

expectedName: "vfat",
expectedBlockSize: []uint32{512},
Expand All @@ -334,20 +337,22 @@ func TestProbePathFilesystems(t *testing.T) {
expectedSignatures: []blkid.SignatureRange{
{Offset: 54, Size: 8},
},
expectedLabel: "TALOS_V1",
},
{
name: "vfat big",

size: 500 * MiB,
setup: vfatSetup,
setup: vfatSetup(32),

expectedName: "vfat",
expectedBlockSize: []uint32{512},
expectedFSBlockSize: []uint32{8192},
expectedFSBlockSize: []uint32{4096},
expectedFSSize: 524256768,
expectedSignatures: []blkid.SignatureRange{
{Offset: 54, Size: 8},
{Offset: 82, Size: 8},
},
expectedLabel: "TALOS_V1",
},
{
name: "luks",
Expand Down Expand Up @@ -887,7 +892,7 @@ func setupNestedGPT(t *testing.T, path string) {

require.NoError(t, exec.Command("partprobe", path).Run())

vfatSetup(t, path+"p1")
vfatSetup(16)(t, path+"p1")
ext4Setup(t, path+"p3")
xfsSetup(t, path+"p6")
}
Expand Down Expand Up @@ -1066,7 +1071,7 @@ func setupOurGPT(t *testing.T, path string, createFilesystems bool) {
require.NoError(t, part.Write())

if createFilesystems {
vfatSetup(t, path+"p1")
vfatSetup(16)(t, path+"p1")
xfsSetup(t, path+"p3")
xfsSetup(t, path+"p5")
xfsSetup(t, path+"p6")
Expand Down
127 changes: 127 additions & 0 deletions blkid/internal/filesystems/vfat/direntry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions blkid/internal/filesystems/vfat/direntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdint.h>

struct vfat_dir_entry {
uint8_t name[11];
uint8_t attr;
uint16_t time_creat;
uint16_t date_creat;
uint16_t time_acc;
uint16_t date_acc;
uint16_t cluster_high;
uint16_t time_write;
uint16_t date_write;
uint16_t cluster_low;
uint32_t size;
} __attribute__((packed));
Loading