Skip to content

Commit e9de9e6

Browse files
authored
Merge pull request #28 from CalebQ42/exp1
Separation
2 parents fcd8c4c + ef72408 commit e9de9e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1976
-2296
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,36 @@
22

33
[![PkgGoDev](https://pkg.go.dev/badge/github.com/CalebQ42/squashfs)](https://pkg.go.dev/github.com/CalebQ42/squashfs) [![Go Report Card](https://goreportcard.com/badge/github.com/CalebQ42/squashfs)](https://goreportcard.com/report/github.com/CalebQ42/squashfs)
44

5-
A PURE Go library to read squashfs. There is currently no plans to add archive creation support as it will almost always be better to just call `mksquashfs`. I could see some possible use cases, but probably won't spend time on it unless it's requested (open a discussion fi you want this feature).
5+
A PURE Go library to read squashfs. There is currently no plans to add archive creation support as it will almost always be better to just call `mksquashfs`. I could see some possible use cases, but probably won't spend time on it unless it's requested (open a discussion if you want this feature).
6+
7+
The library has two parts with this `github.com/CalebQ42/squashfs` being easy to use as it implements `io/fs` interfaces and doesn't expose unnecessary information. 95% this is the library you want. If you need lower level access to the information, use `github.com/CalebQ42/squashfs/low` where far more information is exposed.
68

79
Currently has support for reading squashfs files and extracting files and folders.
810

911
Special thanks to <https://dr-emann.github.io/squashfs/> for some VERY important information in an easy to understand format.
1012
Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree/master/internal/squashfs) as I referenced it to figure some things out (and double check others).
1113

12-
## [TODO](https://github.com/CalebQ42/squashfs/projects/1?fullscreen=true)
14+
## FUSE
15+
16+
As of `v1.0`, FUSE capabilities has been moved to [a separate library](https://github.com/CalebQ42/squashfuse).
1317

1418
## Limitations
1519

16-
* No Xattr parsing. This is simply because I haven't done any research on it and how to apply these in a pure go way.
20+
* No Xattr parsing.
1721
* Socket files are not extracted.
1822
* From my research, it seems like a socket file would be useless if it could be created.
1923
* Fifo files are ignored on `darwin`
2024

2125
## Issues
2226

23-
* Significantly slower then `unsquashfs` when extracting folders (about 5 ~ 7 times slower on a ~100MB archive using zstd compression)
27+
* Significantly slower then `unsquashfs` when extracting folders
2428
* This seems to be related to above along with the general optimization of `unsquashfs` and it's compression libraries.
25-
* The larger the file's tree, the slower the extraction will be. Arch Linux's Live USB's airootfs.sfs takes ~35x longer for a full extraction.
29+
* Times seem to be largely dependent on file tree size and compression type.
30+
* My main testing image (~100MB) using Zstd takes about 6x longer.
31+
* An Arch Linux airootfs image (~780MB) using XZ compression with LZMA filters takes about 32x longer.
32+
* A Tensorflow docker image (~3.3GB) using Zstd takes about 12x longer.
33+
34+
Note: These numbers are using `FastOptions()`. `DefaultOptions()` takes about 2x longer.
2635

2736
## Recommendations on Usage
2837

extraction_options.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package squashfs
2+
3+
import (
4+
"io"
5+
"io/fs"
6+
"runtime"
7+
8+
"github.com/CalebQ42/squashfs/internal/routinemanager"
9+
)
10+
11+
type ExtractionOptions struct {
12+
manager *routinemanager.Manager
13+
LogOutput io.Writer //Where the verbose log should write.
14+
DereferenceSymlink bool //Replace symlinks with the target file.
15+
UnbreakSymlink bool //Try to make sure symlinks remain unbroken when extracted, without changing the symlink.
16+
Verbose bool //Prints extra info to log on an error.
17+
IgnorePerm bool //Ignore file's permissions and instead use Perm.
18+
Perm fs.FileMode //Permission to use when IgnorePerm. Defaults to 0777.
19+
SimultaneousFiles uint16 //Number of files to process in parallel. Default set based on runtime.NumCPU().
20+
ExtractionRoutines uint16 //Number of goroutines to use for each file's extraction. Only applies to regular files. Default set based on runtime.NumCPU().
21+
}
22+
23+
// The default extraction options.
24+
func DefaultOptions() *ExtractionOptions {
25+
cores := uint16(runtime.NumCPU() / 2)
26+
var files, routines uint16
27+
if cores <= 4 {
28+
files = 1
29+
routines = cores
30+
} else {
31+
files = cores - 4
32+
routines = 4
33+
}
34+
return &ExtractionOptions{
35+
Perm: 0777,
36+
SimultaneousFiles: files,
37+
ExtractionRoutines: routines,
38+
}
39+
}
40+
41+
// Less limited default options. Can run up 2x faster than DefaultOptions.
42+
// Tends to use all available CPU resources.
43+
func FastOptions() *ExtractionOptions {
44+
return &ExtractionOptions{
45+
Perm: 0777,
46+
SimultaneousFiles: uint16(runtime.NumCPU()),
47+
ExtractionRoutines: uint16(runtime.NumCPU()),
48+
}
49+
}

0 commit comments

Comments
 (0)