Skip to content

Commit

Permalink
Merge pull request #299 from salvete/main
Browse files Browse the repository at this point in the history
Set the correct fsType for erofs when prefetching through the file list
  • Loading branch information
BigVan authored Aug 28, 2024
2 parents d4e1949 + b72e203 commit f2e9556
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package snapshot
import (
"bufio"
"context"
"encoding/binary"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -211,6 +212,23 @@ func (o *snapshotter) unmountAndDetachBlockDevice(ctx context.Context, snID stri
return nil
}

// determine whether the block device represented
// by @path is eorfs filesystem
func IsErofsFilesystem(path string) bool {
f, err := os.Open(path)
if err != nil {
return false
}
defer f.Close()

byte4 := make([]byte, 4)
_, err = f.ReadAt(byte4, 1024)
if err != nil {
return false
}
return binary.LittleEndian.Uint32(byte4) == 0xe0f5e1e2
}

// attachAndMountBlockDevice
//
// TODO(fuweid): need to track the middle state if the process has been killed.
Expand Down Expand Up @@ -363,6 +381,10 @@ func (o *snapshotter) attachAndMountBlockDevice(ctx context.Context, snID string
options := strings.Split(fsType, ";")
fstype := options[0]

if IsErofsFilesystem(device) {
fstype = "erofs"
}

if mkfs {
args := []string{"-t", fstype}
if len(options) > 2 {
Expand Down

0 comments on commit f2e9556

Please sign in to comment.