Skip to content

Commit 1805252

Browse files
authored
Merge pull request #173 from samuelkarp/freebsd
Support FreeBSD
2 parents b0f312d + 654421a commit 1805252

13 files changed

+218
-17
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ jobs:
7676
run: make build binaries
7777
working-directory: src/github.com/containerd/continuity
7878

79+
- name: Cross-compile
80+
if: startsWith(matrix.os, 'ubuntu')
81+
shell: bash
82+
run: |
83+
GOOS=freebsd make build binaries
84+
working-directory: src/github.com/containerd/continuity
85+
7986
- name: Linux Tests
8087
if: startsWith(matrix.os, 'ubuntu')
8188
run: |

AUTHORS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ Justin Cummins <[email protected]>
1919
Kasper Fabæch Brandt <[email protected]>
2020
Kir Kolyshkin <[email protected]>
2121
Michael Crosby <[email protected]>
22+
Michael Crosby <[email protected]>
2223
Michael Wan <[email protected]>
24+
Mike Brown <[email protected]>
2325
Niels de Vos <[email protected]>
2426
Phil Estes <[email protected]>
2527
Phil Estes <[email protected]>
28+
Samuel Karp <[email protected]>
2629
Sam Whited <[email protected]>
30+
Sebastiaan van Stijn <[email protected]>
2731
Shengjing Zhu <[email protected]>
2832
Stephen J Day <[email protected]>
2933
Tibor Vass <[email protected]>

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ $ stat -c %a Makefile
6363
$ ./bin/continuity verify . /tmp/a.pb
6464
```
6565

66+
## Platforms
67+
68+
continuity primarily targets Linux. continuity may compile for and work on
69+
other operating systems, but those platforms are not tested.
6670

6771
## Contribution Guide
6872
### Building Proto Package

devices/devices_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Mknod(p string, mode os.FileMode, maj, min int) error {
5656
m |= unix.S_IFIFO
5757
}
5858

59-
return unix.Mknod(p, m, int(dev))
59+
return mknod(p, m, dev)
6060
}
6161

6262
// syscallMode returns the syscall-specific mode bits from Go's portable mode bits.

devices/mknod_freebsd.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// +build freebsd
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package devices
20+
21+
import "golang.org/x/sys/unix"
22+
23+
func mknod(path string, mode uint32, dev uint64) (err error) {
24+
return unix.Mknod(path, mode, dev)
25+
}

devices/mknod_unix.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// +build linux darwin solaris
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package devices
20+
21+
import "golang.org/x/sys/unix"
22+
23+
func mknod(path string, mode uint32, dev uint64) (err error) {
24+
return unix.Mknod(path, mode, int(dev))
25+
}

fs/copy_darwinopenbsdsolaris.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// +build darwin openbsd solaris
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package fs
20+
21+
import (
22+
"os"
23+
"syscall"
24+
25+
"github.com/pkg/errors"
26+
"golang.org/x/sys/unix"
27+
)
28+
29+
func copyDevice(dst string, fi os.FileInfo) error {
30+
st, ok := fi.Sys().(*syscall.Stat_t)
31+
if !ok {
32+
return errors.New("unsupported stat type")
33+
}
34+
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
35+
}
36+
37+
func utimesNano(name string, atime, mtime syscall.Timespec) error {
38+
timespec := []syscall.Timespec{atime, mtime}
39+
return syscall.UtimesNano(name, timespec)
40+
}

fs/copy_freebsd.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// +build freebsd
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package fs
20+
21+
import (
22+
"os"
23+
"syscall"
24+
25+
"github.com/pkg/errors"
26+
"golang.org/x/sys/unix"
27+
)
28+
29+
func copyDevice(dst string, fi os.FileInfo) error {
30+
st, ok := fi.Sys().(*syscall.Stat_t)
31+
if !ok {
32+
return errors.New("unsupported stat type")
33+
}
34+
return unix.Mknod(dst, uint32(fi.Mode()), st.Rdev)
35+
}
36+
37+
func utimesNano(name string, atime, mtime syscall.Timespec) error {
38+
at := unix.NsecToTimespec(atime.Nano())
39+
mt := unix.NsecToTimespec(mtime.Nano())
40+
utimes := [2]unix.Timespec{at, mt}
41+
return unix.UtimesNanoAt(unix.AT_FDCWD, name, utimes[0:], unix.AT_SYMLINK_NOFOLLOW)
42+
}

fs/copy_unix.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/containerd/continuity/sysx"
2727
"github.com/pkg/errors"
28-
"golang.org/x/sys/unix"
2928
)
3029

3130
func copyFileInfo(fi os.FileInfo, name string) error {
@@ -53,8 +52,7 @@ func copyFileInfo(fi os.FileInfo, name string) error {
5352
}
5453
}
5554

56-
timespec := []syscall.Timespec{StatAtime(st), StatMtime(st)}
57-
if err := syscall.UtimesNano(name, timespec); err != nil {
55+
if err := utimesNano(name, StatAtime(st), StatMtime(st)); err != nil {
5856
return errors.Wrapf(err, "failed to utime %s", name)
5957
}
6058

@@ -102,11 +100,3 @@ func copyXAttrs(dst, src string, xeh XAttrErrorHandler) error {
102100

103101
return nil
104102
}
105-
106-
func copyDevice(dst string, fi os.FileInfo) error {
107-
st, ok := fi.Sys().(*syscall.Stat_t)
108-
if !ok {
109-
return errors.New("unsupported stat type")
110-
}
111-
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
112-
}

fs/du_cmd_freebsd_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// +build freebsd
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package fs
20+
21+
import (
22+
"fmt"
23+
"os/exec"
24+
)
25+
26+
func duCmd(root string) *exec.Cmd {
27+
cmd := exec.Command("du", "-s", root)
28+
/*
29+
From du(1):
30+
BLOCKSIZE If the environment variable BLOCKSIZE is set, and the -h, -k,
31+
-m or --si options are not specified, the block counts will be
32+
displayed in units of that block size. If BLOCKSIZE is not
33+
set, and the -h, -k, -m or --si options are not specified, the
34+
block counts will be displayed in 512-byte blocks.
35+
*/
36+
cmd.Env = []string{fmt.Sprintf("BLOCKSIZE=%d", blocksUnitSize)}
37+
return cmd
38+
}

0 commit comments

Comments
 (0)