Make minio server compile on OpenBSD, NetBSD, Solaris (#3719)

This commit is contained in:
Krishnan Parthasarathi
2017-02-09 11:57:35 +05:30
committed by Harshavardhana
parent 0c7694894b
commit e5773e11c6
24 changed files with 545 additions and 141 deletions

View File

@@ -27,3 +27,11 @@ type Info struct {
Ffree int64
FSType string
}
func b2s(bs []int8) string {
b := make([]byte, len(bs))
for i, v := range bs {
b[i] = byte(v)
}
return string(b)
}

View File

@@ -1,5 +1,7 @@
// +build !netbsd,!solaris
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,7 +1,7 @@
// +build darwin dragonfly freebsd linux netbsd openbsd
// +build darwin freebsd dragonfly
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,9 +34,6 @@ func GetInfo(path string) (info Info, err error) {
info.Free = int64(s.Bsize) * int64(s.Bavail)
info.Files = int64(s.Files)
info.Ffree = int64(s.Ffree)
info.FSType, err = getFSType(path)
if err != nil {
return Info{}, err
}
info.FSType = getFSType(s.Fstypename)
return info, nil
}

24
pkg/disk/stat_fallback.go Normal file
View File

@@ -0,0 +1,24 @@
// +build netbsd solaris
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* 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 disk
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
func GetInfo(path string) (info Info, err error) {
return Info{}, nil
}

39
pkg/disk/stat_linux.go Normal file
View File

@@ -0,0 +1,39 @@
// +build linux
/*
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* 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 disk
import (
"syscall"
)
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
func GetInfo(path string) (info Info, err error) {
s := syscall.Statfs_t{}
err = syscall.Statfs(path, &s)
if err != nil {
return Info{}, err
}
info = Info{}
info.Total = int64(s.Bsize) * int64(s.Blocks)
info.Free = int64(s.Bsize) * int64(s.Bavail)
info.Files = int64(s.Files)
info.Ffree = int64(s.Ffree)
info.FSType = getFSType(int64(s.Type))
return info, nil
}

39
pkg/disk/stat_openbsd.go Normal file
View File

@@ -0,0 +1,39 @@
// +build openbsd
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* 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 disk
import (
"syscall"
)
// GetInfo returns total and free bytes available in a directory, e.g. `/`.
func GetInfo(path string) (info Info, err error) {
s := syscall.Statfs_t{}
err = syscall.Statfs(path, &s)
if err != nil {
return Info{}, err
}
info = Info{}
info.Total = int64(s.F_bsize) * int64(s.F_blocks)
info.Free = int64(s.F_bsize) * int64(s.F_bavail)
info.Files = int64(s.F_files)
info.Ffree = int64(s.F_ffree)
info.FSType = getFSType(s.F_fstypename)
return info, nil
}

View File

@@ -1,7 +1,7 @@
// +build freebsd
// +build darwin freebsd dragonfly openbsd
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,27 +18,7 @@
package disk
import (
"strconv"
"syscall"
)
// fsType2StringMap - list of filesystems supported by donut on linux
var fsType2StringMap = map[string]string{
"35": "UFS",
}
// getFSType returns the filesystem type of the underlying mounted filesystem
func getFSType(path string) (string, error) {
s := syscall.Statfs_t{}
err := syscall.Statfs(path, &s)
if err != nil {
return "", err
}
fsTypeHex := strconv.FormatInt(int64(s.Type), 16)
fsTypeString, ok := fsType2StringMap[fsTypeHex]
if ok == false {
return "UNKNOWN", nil
}
return fsTypeString, nil
func getFSType(fstype [16]int8) string {
return b2s(fstype[:])
}

View File

@@ -18,10 +18,7 @@
package disk
import (
"strconv"
"syscall"
)
import "strconv"
// fsType2StrinMap - list of filesystems supported by donut
var fsType2StringMap = map[string]string{
@@ -29,16 +26,11 @@ var fsType2StringMap = map[string]string{
}
// getFSType returns the filesystem type of the underlying mounted filesystem
func getFSType(path string) (string, error) {
s := syscall.Statfs_t{}
err := syscall.Statfs(path, &s)
if err != nil {
return "", err
}
fsTypeHex := strconv.FormatUint(uint64(s.Type), 16)
func getFSType(ftype int64) string {
fsTypeHex := strconv.FormatInt(ftype, 16)
fsTypeString, ok := fsType2StringMap[fsTypeHex]
if !ok {
return "UNKNOWN", nil
return "UNKNOWN"
}
return fsTypeString, nil
return fsTypeString
}

View File

@@ -1,7 +1,7 @@
// +build linux
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
* Minio Cloud Storage, (C) 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,7 @@
package disk
import (
"strconv"
"syscall"
)
import "strconv"
// fsType2StringMap - list of filesystems supported by donut on linux
var fsType2StringMap = map[string]string{
@@ -40,16 +37,11 @@ var fsType2StringMap = map[string]string{
}
// getFSType returns the filesystem type of the underlying mounted filesystem
func getFSType(path string) (string, error) {
s := syscall.Statfs_t{}
err := syscall.Statfs(path, &s)
if err != nil {
return "", err
}
fsTypeHex := strconv.FormatInt(int64(s.Type), 16)
func getFSType(ftype int64) string {
fsTypeHex := strconv.FormatInt(ftype, 16)
fsTypeString, ok := fsType2StringMap[fsTypeHex]
if ok == false {
return "UNKNOWN", nil
return "UNKNOWN"
}
return fsTypeString, nil
return fsTypeString
}