From ec347f96fd6ab6610c0b46aa505aa017423d2b11 Mon Sep 17 00:00:00 2001 From: Nate Rosenblum Date: Mon, 13 Jul 2015 08:26:40 -0700 Subject: [PATCH] Fix OS X build - Explicitly cast statfs_t members to int64 (this structure is platform-specific) - Add pass-through New methods to Darwin SHA package - Move scsi pkg types to common translation unit (package was empty) - Add stub implementations mount/disk ops for OS X --- pkg/crypto/sha256/sha256_darwin.go | 6 ++++++ pkg/crypto/sha512/sha512_darwin.go | 6 ++++++ pkg/donut/disk/disk.go | 12 ++++++------ pkg/utils/scsi/mountinfo.go | 10 ---------- pkg/utils/scsi/mountinfo_darwin.go | 23 +++++++++++++++++++++++ pkg/utils/scsi/scsi-common.go | 18 ++++++++++++++++-- pkg/utils/scsi/scsi.go | 6 ------ pkg/utils/scsi/scsi_darwin.go | 23 +++++++++++++++++++++++ pkg/utils/scsi/scsi_test.go | 2 -- 9 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 pkg/utils/scsi/mountinfo_darwin.go create mode 100644 pkg/utils/scsi/scsi_darwin.go diff --git a/pkg/crypto/sha256/sha256_darwin.go b/pkg/crypto/sha256/sha256_darwin.go index ddb06ec61..e44b42522 100644 --- a/pkg/crypto/sha256/sha256_darwin.go +++ b/pkg/crypto/sha256/sha256_darwin.go @@ -17,6 +17,7 @@ package sha256 import ( + "hash" "io" "crypto/sha256" @@ -45,3 +46,8 @@ func Sum(reader io.Reader) ([]byte, error) { } return d.Sum(nil), nil } + +// New returns a new hash.Hash computing SHA256. +func New() hash.Hash { + return sha256.New() +} diff --git a/pkg/crypto/sha512/sha512_darwin.go b/pkg/crypto/sha512/sha512_darwin.go index 751c7adff..4a85211aa 100644 --- a/pkg/crypto/sha512/sha512_darwin.go +++ b/pkg/crypto/sha512/sha512_darwin.go @@ -17,6 +17,7 @@ package sha512 import ( + "hash" "io" "crypto/sha512" @@ -61,3 +62,8 @@ func SumStream(reader io.Reader) ([sha512.Size]byte, error) { copy(returnValue[:], sumSlice) return returnValue, err } + +// New returns a new hash.Hash computing SHA512. +func New() hash.Hash { + return sha512.New() +} diff --git a/pkg/donut/disk/disk.go b/pkg/donut/disk/disk.go index 24fa729dc..0af53b83b 100644 --- a/pkg/donut/disk/disk.go +++ b/pkg/donut/disk/disk.go @@ -63,8 +63,8 @@ func New(diskPath string) (Disk, error) { disk.fsInfo["MountPoint"] = disk.path return disk, nil } - return Disk{}, iodine.New(UnsupportedFilesystem{Type: strconv.FormatInt(s.Type, 10)}, - map[string]string{"Type": strconv.FormatInt(s.Type, 10)}) + return Disk{}, iodine.New(UnsupportedFilesystem{Type: strconv.FormatInt(int64(s.Type), 10)}, + map[string]string{"Type": strconv.FormatInt(int64(s.Type), 10)}) } // GetPath - get root disk path @@ -82,10 +82,10 @@ func (disk Disk) GetFSInfo() map[string]string { if err != nil { return nil } - disk.fsInfo["Total"] = formatBytes(s.Bsize * int64(s.Blocks)) - disk.fsInfo["Free"] = formatBytes(s.Bsize * int64(s.Bfree)) - disk.fsInfo["TotalB"] = strconv.FormatInt(s.Bsize*int64(s.Blocks), 10) - disk.fsInfo["FreeB"] = strconv.FormatInt(s.Bsize*int64(s.Bfree), 10) + disk.fsInfo["Total"] = formatBytes(int64(s.Bsize) * int64(s.Blocks)) + disk.fsInfo["Free"] = formatBytes(int64(s.Bsize) * int64(s.Bfree)) + disk.fsInfo["TotalB"] = strconv.FormatInt(int64(s.Bsize)*int64(s.Blocks), 10) + disk.fsInfo["FreeB"] = strconv.FormatInt(int64(s.Bsize)*int64(s.Bfree), 10) return disk.fsInfo } diff --git a/pkg/utils/scsi/mountinfo.go b/pkg/utils/scsi/mountinfo.go index 2dcc457f7..4b74679d7 100644 --- a/pkg/utils/scsi/mountinfo.go +++ b/pkg/utils/scsi/mountinfo.go @@ -31,16 +31,6 @@ import ( "github.com/minio/minio/pkg/iodine" ) -// Mountinfo container to capture /etc/mtab mount structure -type Mountinfo struct { - FSName string /* name of mounted filesystem */ - Dir string /* filesystem path prefix */ - Type string /* mount type (see mntent.h) */ - Opts string /* mount options (see mntent.h) */ - Freq int /* dump frequency in days */ - Passno int /* pass number on parallel fsck */ -} - var supportedFSType = map[string]bool{ "ext4": true, "xfs": true, diff --git a/pkg/utils/scsi/mountinfo_darwin.go b/pkg/utils/scsi/mountinfo_darwin.go new file mode 100644 index 000000000..962525d40 --- /dev/null +++ b/pkg/utils/scsi/mountinfo_darwin.go @@ -0,0 +1,23 @@ +/* + * Mini Object Storage, (C) 2014 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 scsi + +// GetMountInfo - get mount info map +func GetMountInfo() (map[string]Mountinfo, error) { + // Stub implementation; returns an empty map + return make(map[string]Mountinfo), nil +} diff --git a/pkg/utils/scsi/scsi-common.go b/pkg/utils/scsi/scsi-common.go index 816844513..086432a6c 100644 --- a/pkg/utils/scsi/scsi-common.go +++ b/pkg/utils/scsi/scsi-common.go @@ -1,5 +1,3 @@ -// +build linux,amd64 - /* * Mini Object Storage, (C) 2014 Minio, Inc. * @@ -25,6 +23,22 @@ import ( "strings" ) +// Attributes Scsi device attributes +type Attributes map[string]string + +// Disks is a list of scsis disks and attributes +type Disks map[string]Attributes + +// Mountinfo container to capture /etc/mtab mount structure +type Mountinfo struct { + FSName string /* name of mounted filesystem */ + Dir string /* filesystem path prefix */ + Type string /* mount type (see mntent.h) */ + Opts string /* mount options (see mntent.h) */ + Freq int /* dump frequency in days */ + Passno int /* pass number on parallel fsck */ +} + func getattrs(scsiAttrPath string, scsiAttrList []string) map[string]string { attrMap := make(map[string]string) for _, attr := range scsiAttrList { diff --git a/pkg/utils/scsi/scsi.go b/pkg/utils/scsi/scsi.go index 8f5ba277f..ee6c56fd5 100644 --- a/pkg/utils/scsi/scsi.go +++ b/pkg/utils/scsi/scsi.go @@ -28,12 +28,6 @@ import ( // NOTE : supporting virtio based scsi devices is out of scope for this implementation -// Attributes Scsi device attributes -type Attributes map[string]string - -// Disks is a list of scsis disks and attributes -type Disks map[string]Attributes - // Get get disk scsi params func (d Disks) Get(disk string) Attributes { return d[disk] diff --git a/pkg/utils/scsi/scsi_darwin.go b/pkg/utils/scsi/scsi_darwin.go new file mode 100644 index 000000000..153f2b78c --- /dev/null +++ b/pkg/utils/scsi/scsi_darwin.go @@ -0,0 +1,23 @@ +/* + * Minimalist Object Storage, (C) 2015 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 scsi + +// GetDisks - get system devices list +func GetDisks() (Disks, error) { + // Stub implementation; returns empty disk information + return Disks{}, nil +} diff --git a/pkg/utils/scsi/scsi_test.go b/pkg/utils/scsi/scsi_test.go index 997e8fb8d..8c0141497 100644 --- a/pkg/utils/scsi/scsi_test.go +++ b/pkg/utils/scsi/scsi_test.go @@ -1,5 +1,3 @@ -// +build linux,amd64 - /* * Minimalist Object Storage, (C) 2015 Minio, Inc. *