Skip to content

Commit

Permalink
Merge pull request containerd#24 from zhsj/fix-mipsle
Browse files Browse the repository at this point in the history
fix slice size overflow on mipsle
  • Loading branch information
fuweid authored Jan 17, 2020
2 parents cbb5fe5 + 6d8cb52 commit 1539353
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 84 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This package may not cover all the use cases for btrfs. If something you need
is missing, please don't hesitate to submit a PR.

Note that due to struct alignment issues, this isn't yet fully native.
Preferrably, this could be resolved, so contributions in this direction are
Preferably, this could be resolved, so contributions in this direction are
greatly appreciated.

## Applying License Header to New Files
Expand Down
32 changes: 10 additions & 22 deletions btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,8 @@
limitations under the License.
*/

/*
Copyright The containerd Authors
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 btrfs

import "sort"

/*
#include <stddef.h>
#include <btrfs/ioctl.h>
Expand All @@ -47,12 +30,17 @@ import "C"
import (
"os"
"path/filepath"
"sort"
"syscall"
"unsafe"

"github.com/pkg/errors"
)

// maxByteSliceSize is the smallest size that Go supports on various platforms.
// On mipsle, 1<<31-1 overflows the address space.
const maxByteSliceSize = 1 << 30

// IsSubvolume returns nil if the path is a valid subvolume. An error is
// returned if the path does not exist or the path is not a valid subvolume.
func IsSubvolume(path string) error {
Expand Down Expand Up @@ -146,7 +134,7 @@ func subvolMap(path string) (map[uint64]*Info, error) {
var (
sh C.struct_btrfs_ioctl_search_header
shSize = unsafe.Sizeof(sh)
buf = (*[1<<31 - 1]byte)(unsafe.Pointer(&args.buf[0]))[:C.BTRFS_SEARCH_ARGS_BUFSIZE]
buf = (*[maxByteSliceSize]byte)(unsafe.Pointer(&args.buf[0]))[:C.BTRFS_SEARCH_ARGS_BUFSIZE]
)

for i := 0; i < int(args.key.nr_items); i++ {
Expand Down Expand Up @@ -287,7 +275,7 @@ func SubvolCreate(path string) error {
if len(name) > C.BTRFS_PATH_NAME_MAX {
return errors.Errorf("%q too long for subvolume", name)
}
nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(&args.name[0]))
nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(&args.name[0]))
copy(nameptr[:C.BTRFS_PATH_NAME_MAX], []byte(name))

if err := ioctl(fp.Fd(), C.BTRFS_IOC_SUBVOL_CREATE, uintptr(unsafe.Pointer(&args))); err != nil {
Expand All @@ -304,7 +292,7 @@ func SubvolSnapshot(dst, src string, readonly bool) error {

dstfp, err := openSubvolDir(dstdir)
if err != nil {
return errors.Wrapf(err, "opening snapshot desination subvolume failed")
return errors.Wrapf(err, "opening snapshot destination subvolume failed")
}
defer dstfp.Close()

Expand All @@ -323,7 +311,7 @@ func SubvolSnapshot(dst, src string, readonly bool) error {
return errors.Errorf("%q too long for subvolume", dstname)
}

nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(name))
nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(name))
copy(nameptr[:C.BTRFS_SUBVOL_NAME_MAX], []byte(dstname))

if readonly {
Expand Down Expand Up @@ -382,7 +370,7 @@ func SubvolDelete(path string) error {
return errors.Errorf("%q too long for subvolume", name)
}

nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(&args.name[0]))
nameptr := (*[maxByteSliceSize]byte)(unsafe.Pointer(&args.name[0]))
copy(nameptr[:C.BTRFS_SUBVOL_NAME_MAX], []byte(name))

if err := ioctl(fp.Fd(), C.BTRFS_IOC_SNAP_DESTROY, uintptr(unsafe.Pointer(&args))); err != nil {
Expand Down
15 changes: 0 additions & 15 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,5 @@
limitations under the License.
*/

/*
Copyright The containerd Authors
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 btrfs provides bindings for working with btrfs partitions from Go.
package btrfs
17 changes: 1 addition & 16 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@
limitations under the License.
*/

/*
Copyright The containerd Authors
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 btrfs

/*
Expand Down Expand Up @@ -66,7 +51,7 @@ var (
)

func uuidString(uuid *[C.BTRFS_UUID_SIZE]C.u8) string {
b := (*[1<<31 - 1]byte)(unsafe.Pointer(uuid))[:C.BTRFS_UUID_SIZE]
b := (*[maxByteSliceSize]byte)(unsafe.Pointer(uuid))[:C.BTRFS_UUID_SIZE]

if bytes.Equal(b, zeros) {
return ""
Expand Down
15 changes: 0 additions & 15 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@
limitations under the License.
*/

/*
Copyright The containerd Authors
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 btrfs

// Info describes metadata about a btrfs subvolume.
Expand Down
15 changes: 0 additions & 15 deletions ioctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@
limitations under the License.
*/

/*
Copyright The containerd Authors
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 btrfs

import "syscall"
Expand Down

0 comments on commit 1539353

Please sign in to comment.