-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial commit for erofs support
Before this commit, only squashfs was supported. However, there are other filesystems such as erofs that fit the same theme, and additional filesystem support requires refactoring and exposing a more generic filesystem interface. pkg/fs/fs.go - Filesystem interface pkg/squashfs - squashfs pkg/erofs - erofs pkg/common - filesystem-agnostic common routines pkg/verity - verity routines Signed-off-by: Ramkumar Chinchani <[email protected]>
- Loading branch information
Showing
34 changed files
with
1,617 additions
and
402 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package atomfs |
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
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,49 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type uidmapTestcase struct { | ||
uidmap string | ||
expected bool | ||
} | ||
|
||
var uidmapTests = []uidmapTestcase{ | ||
{ | ||
uidmap: ` 0 0 4294967295`, | ||
expected: true, | ||
}, | ||
{ | ||
uidmap: ` 0 0 1000 | ||
2000 2000 1`, | ||
expected: false, | ||
}, | ||
{ | ||
uidmap: ` 0 0 1000`, | ||
expected: false, | ||
}, | ||
{ | ||
uidmap: ` 10 0 4294967295`, | ||
expected: false, | ||
}, | ||
{ | ||
uidmap: ` 0 10 4294967295`, | ||
expected: false, | ||
}, | ||
{ | ||
uidmap: ` 0 0 1`, | ||
expected: false, | ||
}, | ||
} | ||
|
||
func TestAmHostRoot(t *testing.T) { | ||
t.Parallel() | ||
assert := assert.New(t) | ||
for _, testcase := range uidmapTests { | ||
v := uidmapIsHost(testcase.uidmap) | ||
assert.Equal(v, testcase.expected) | ||
} | ||
} |
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,84 @@ | ||
package common | ||
|
||
import ( | ||
"bytes" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// ExcludePaths represents a list of paths to exclude in a filesystem listing. | ||
// Users should do something like filepath.Walk() over the whole filesystem, | ||
// calling AddExclude() or AddInclude() based on whether they want to include | ||
// or exclude a particular file. Note that if e.g. /usr is excluded, then | ||
// everyting underneath is also implicitly excluded. The | ||
// AddExclude()/AddInclude() methods do the math to figure out what is the | ||
// correct set of things to exclude or include based on what paths have been | ||
// previously included or excluded. | ||
type ExcludePaths struct { | ||
exclude map[string]bool | ||
include []string | ||
} | ||
|
||
func NewExcludePaths() *ExcludePaths { | ||
return &ExcludePaths{ | ||
exclude: map[string]bool{}, | ||
include: []string{}, | ||
} | ||
} | ||
|
||
func (eps *ExcludePaths) AddExclude(p string) { | ||
for _, inc := range eps.include { | ||
// If /usr/bin/ls has changed but /usr hasn't, we don't want to list | ||
// /usr in the include paths any more, so let's be sure to only | ||
// add things which aren't prefixes. | ||
if strings.HasPrefix(inc, p) { | ||
return | ||
} | ||
} | ||
eps.exclude[p] = true | ||
} | ||
|
||
func (eps *ExcludePaths) AddInclude(orig string, isDir bool) { | ||
// First, remove this thing and all its parents from exclude. | ||
p := orig | ||
|
||
// normalize to the first dir | ||
if !isDir { | ||
p = path.Dir(p) | ||
} | ||
for { | ||
// our paths are all absolute, so this is a base case | ||
if p == "/" { | ||
break | ||
} | ||
|
||
delete(eps.exclude, p) | ||
p = filepath.Dir(p) | ||
} | ||
|
||
// now add it to the list of includes, so we don't accidentally re-add | ||
// anything above. | ||
eps.include = append(eps.include, orig) | ||
} | ||
|
||
func (eps *ExcludePaths) String() (string, error) { | ||
var buf bytes.Buffer | ||
for p := range eps.exclude { | ||
_, err := buf.WriteString(p) | ||
if err != nil { | ||
return "", err | ||
} | ||
_, err = buf.WriteString("\n") | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
|
||
_, err := buf.WriteString("\n") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} |
Oops, something went wrong.