Skip to content

Commit

Permalink
Provide system dependend wrapper for unix.Mknod
Browse files Browse the repository at this point in the history
FreeBSD support 64bit inodes so it requires that dev provided to
unix.Mknod is type uint64. This commit creates wrapper for unix.Mknod
to fix this issue.

Signed-off-by: Mateusz Kwiatkowski <mateusz@serveraptor.com>
  • Loading branch information
mateuszkwiatkowski committed Mar 4, 2021
1 parent 6fbd32e commit b158474
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ RUN zypper -n in \
python-xattr \
runc \
skopeo \
tar
tar \
which
RUN useradd -u 1000 -m -d /home/rootless -s /bin/bash rootless

ENV GOPATH=/go PATH=/go/bin:$PATH
Expand Down
5 changes: 3 additions & 2 deletions oci/layer/generate_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/opencontainers/umoci/pkg/fseval"
"github.com/opencontainers/umoci/pkg/system"
"github.com/stretchr/testify/assert"
"github.com/vbatts/go-mtree"
"golang.org/x/sys/unix"
Expand All @@ -32,7 +33,7 @@ func TestInsertLayerTranslateOverlayWhiteouts(t *testing.T) {
}

testNode := path.Join(dir, "test")
err = unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err = system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
assert.NoError(err)

packOptions := RepackOptions{TranslateOverlayWhiteouts: true}
Expand Down Expand Up @@ -69,7 +70,7 @@ func TestGenerateLayerTranslateOverlayWhiteouts(t *testing.T) {
}

testNode := path.Join(dir, "test")
err = unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err = system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
assert.NoError(err)

packOptions := RepackOptions{TranslateOverlayWhiteouts: true}
Expand Down
3 changes: 2 additions & 1 deletion oci/layer/tar_extract_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"path/filepath"
"testing"

"github.com/opencontainers/umoci/pkg/system"
"golang.org/x/sys/unix"
)

func canMknod(dir string) (bool, error) {
testNode := filepath.Join(dir, "test")
err := unix.Mknod(testNode, unix.S_IFCHR|0666, int(unix.Mkdev(0, 0)))
err := system.Mknod(testNode, unix.S_IFCHR|0666, unix.Mkdev(0, 0))
if err != nil {
if os.IsPermission(err) {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/fseval/fseval_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (fs osFsEval) RemoveAll(path string) error {

// Mknod is equivalent to unix.Mknod.
func (fs osFsEval) Mknod(path string, mode os.FileMode, dev uint64) error {
return unix.Mknod(path, uint32(mode), int(dev))
return system.Mknod(path, uint32(mode), dev)
}

// MkdirAll is equivalent to os.MkdirAll.
Expand Down
28 changes: 28 additions & 0 deletions pkg/system/mknod_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package system

import (
"golang.org/x/sys/unix"
)

// Mknod creates a filesystem node (file, device special file or named pipe) named path
// with attributes specified by mode and dev.
func Mknod(path string, mode uint32, dev uint64) error {
return unix.Mknod(path, mode, dev)
}
25 changes: 6 additions & 19 deletions pkg/system/mknod_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !freebsd

/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
Expand All @@ -18,26 +20,11 @@
package system

import (
"archive/tar"

"golang.org/x/sys/unix"
)

// Tarmode takes a Typeflag (from a tar.Header for example) and returns the
// corresponding os.Filemode bit. Unknown typeflags are treated like regular
// files.
func Tarmode(typeflag byte) uint32 {
switch typeflag {
case tar.TypeSymlink:
return unix.S_IFLNK
case tar.TypeChar:
return unix.S_IFCHR
case tar.TypeBlock:
return unix.S_IFBLK
case tar.TypeFifo:
return unix.S_IFIFO
case tar.TypeDir:
return unix.S_IFDIR
}
return 0
// Mknod creates a filesystem node (file, device special file or named pipe) named path
// with attributes specified by mode and dev.
func Mknod(path string, mode uint32, dev uint64) error {
return unix.Mknod(path, mode, int(dev))
}
43 changes: 43 additions & 0 deletions pkg/system/tarmode_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package system

import (
"archive/tar"

"golang.org/x/sys/unix"
)

// Tarmode takes a Typeflag (from a tar.Header for example) and returns the
// corresponding os.Filemode bit. Unknown typeflags are treated like regular
// files.
func Tarmode(typeflag byte) uint32 {
switch typeflag {
case tar.TypeSymlink:
return unix.S_IFLNK
case tar.TypeChar:
return unix.S_IFCHR
case tar.TypeBlock:
return unix.S_IFBLK
case tar.TypeFifo:
return unix.S_IFIFO
case tar.TypeDir:
return unix.S_IFDIR
}
return 0
}
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/unpriv/unpriv.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func MkdirAll(path string, perm os.FileMode) error {
// required access bits to modify or resolve the path.
func Mknod(path string, mode os.FileMode, dev uint64) error {
return errors.Wrap(Wrap(path, func(path string) error {
return unix.Mknod(path, uint32(mode), int(dev))
return system.Mknod(path, uint32(mode), dev)
}), "unpriv.mknod")
}

Expand Down

0 comments on commit b158474

Please sign in to comment.