Skip to content

Commit

Permalink
example: add support for zstd compression
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorjan committed Nov 3, 2022
1 parent 378c4d6 commit d86f86e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/modprobe/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
replace github.com/pmorjan/kmod => ../..

require (
github.com/klauspost/compress v1.15.12
github.com/pmorjan/kmod v0.0.0-00010101000000-000000000000
github.com/ulikunitz/xz v0.5.10
golang.org/x/sys v0.1.0
Expand Down
2 changes: 2 additions & 0 deletions cmd/modprobe/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
Expand Down
10 changes: 9 additions & 1 deletion cmd/modprobe/modprobe.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The modprobe command loads and unloads Linux kernel modules and dependencies.
// It supports uncompressed, gzip and xz compressed module files.
// It supports uncompressed, gzip, xz and zstd compressed module files.
//
// Usage:
// modprobe [options] MODULE [SYMBOL=VALUE]...
Expand Down Expand Up @@ -34,6 +34,7 @@ import (
"path/filepath"
"strings"

"github.com/klauspost/compress/zstd"
"github.com/pmorjan/kmod"
"github.com/ulikunitz/xz"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -149,6 +150,13 @@ func modInitFunc(path, params string, flags int) error {
return err
}
return initModule(rd, params)
case ".zst":
rd, err := zstd.NewReader(f)
if err != nil {
return err
}
defer rd.Close()
return initModule(rd, params)
}

// uncompressed file, first try finitModule then initModule
Expand Down

0 comments on commit d86f86e

Please sign in to comment.