Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

func Partitions(all bool) does not work on FreeBSD ARM64 #543

Open
jsirianni opened this issue Jul 2, 2018 · 7 comments
Open

func Partitions(all bool) does not work on FreeBSD ARM64 #543

jsirianni opened this issue Jul 2, 2018 · 7 comments

Comments

@jsirianni
Copy link

I have a utility that retrieves a list of mountpoints, and checks their disk usage. I can compile on Windows, Linux, FreeBSD (x86). I can even compile linux + arm64, but not FreeBSd. I would like to get FreeBSD + ARM working in order to run my utility on Netgate firewalls. Specifically, 32 bit arm.

My code:

devices, _ := disk.Partitions(true)
for _, device := range devices {
     if checkFileSystem(device.Fstype) == true {
         drives = append(drives, device.Mountpoint)
     }
}

Error:

gopsutil/disk/disk_freebsd.go:153:9: undefined: Bintime

I can get around the issue by simply hardcoding my partitions ("/", "/var/log", etc) for arm, but would prefer to intelligently retrieve a list of mountpoints.

@Lomanic
Copy link
Collaborator

Lomanic commented Jul 2, 2018

Try to generate the missing definitions with GOARCH=arm64 go tool cgo -godefs disk/types_freebsd.go > disk/disk_freebsd_arm64.go on a FreeBSD host and tell us if it succeeds, and if you are then able to compile. If everything goes right (and there is no runtime error when you execute your compiled program on the arm64 host), can you please submit a PR to include this generated file in gopsutil?

@jsirianni
Copy link
Author

Sure thing!

@jsirianni
Copy link
Author

Hi @Lomanic, I get the following error when running the command you suggested:

go/src/github.com/shirou/gopsutil/disk/types_freebsd.go:87:14: unexpected: 8-byte pointer type - *struct devstat

My command is:

GOOS=freebsd GOARCH=arm GOARM=7 go tool cgo -godefs disk/types_freebsd.go > disk/disk_freebsd_arm.go

I misspoke in my issue, and should have stated I need ARM v7, which is 32 bit. Also, I am building on an AMD 64 machine, freebsd 11.2.

@jsirianni
Copy link
Author

jsirianni commented Jul 14, 2018

Note, the original command appears to run fine but I have no way to test it

Click to expand
$ GOOS=freebsd GOARCH=arm64 go tool cgo -godefs disk/types_freebsd.go > disk/disk_freebsd_arm64.go
$ cat disk/disk_freebsd_arm64.go 
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs disk/types_freebsd.go

package disk

const (
	sizeofPtr		= 0x8
	sizeofShort		= 0x2
	sizeofInt		= 0x4
	sizeofLong		= 0x8
	sizeofLongLong		= 0x8
	sizeofLongDouble	= 0x8

	DEVSTAT_NO_DATA	= 0x00
	DEVSTAT_READ	= 0x01
	DEVSTAT_WRITE	= 0x02
	DEVSTAT_FREE	= 0x03

	MNT_RDONLY	= 0x00000001
	MNT_SYNCHRONOUS	= 0x00000002
	MNT_NOEXEC	= 0x00000004
	MNT_NOSUID	= 0x00000008
	MNT_UNION	= 0x00000020
	MNT_ASYNC	= 0x00000040
	MNT_SUIDDIR	= 0x00100000
	MNT_SOFTDEP	= 0x00200000
	MNT_NOSYMFOLLOW	= 0x00400000
	MNT_GJOURNAL	= 0x02000000
	MNT_MULTILABEL	= 0x04000000
	MNT_ACLS	= 0x08000000
	MNT_NOATIME	= 0x10000000
	MNT_NOCLUSTERR	= 0x40000000
	MNT_NOCLUSTERW	= 0x80000000
	MNT_NFS4ACLS	= 0x00000010

	MNT_WAIT	= 1
	MNT_NOWAIT	= 2
	MNT_LAZY	= 3
	MNT_SUSPEND	= 4
)

const (
	sizeOfDevstat = 0x120
)

type (
	_C_short	int16
	_C_int		int32
	_C_long		int64
	_C_long_long	int64
	_C_long_double	int64
)

type Statfs struct {
	Version		uint32
	Type		uint32
	Flags		uint64
	Bsize		uint64
	Iosize		uint64
	Blocks		uint64
	Bfree		uint64
	Bavail		int64
	Files		uint64
	Ffree		int64
	Syncwrites	uint64
	Asyncwrites	uint64
	Syncreads	uint64
	Asyncreads	uint64
	Spare		[10]uint64
	Namemax		uint32
	Owner		uint32
	Fsid		Fsid
	Charspare	[80]int8
	Fstypename	[16]int8
	Mntfromname	[88]int8
	Mntonname	[88]int8
}
type Fsid struct {
	Val [2]int32
}

type Devstat struct {
	Sequence0	uint32
	Allocated	int32
	Start_count	uint32
	End_count	uint32
	Busy_from	Bintime
	Dev_links	_Ctype_struct___0
	Device_number	uint32
	Device_name	[16]int8
	Unit_number	int32
	Bytes		[4]uint64
	Operations	[4]uint64
	Duration	[4]Bintime
	Busy_time	Bintime
	Creation_time	Bintime
	Block_size	uint32
	Pad_cgo_0	[4]byte
	Tag_types	[3]uint64
	Flags		uint32
	Device_type	uint32
	Priority	uint32
	Pad_cgo_1	[4]byte
	Id		*byte
	Sequence1	uint32
	Pad_cgo_2	[4]byte
}
type Bintime struct {
	Sec	int64
	Frac	uint64
}

@Lomanic
Copy link
Collaborator

Lomanic commented Jul 14, 2018

Great news for arm64 ; you should try installing Go on the armv7 host and try the same go tool cgo -godefs … command. I won't be of much help on how to do that as I never used FreeBSD. Keep us updated! 👍

@jsirianni
Copy link
Author

I will see what I can do. The catch is, my arm v7 host is a production firewall (pfsense). It does not have the dependencies required (git, build tools, etc). I may be able to source a spare that can be used, or perhaps an emulator.

@Lomanic
Copy link
Collaborator

Lomanic commented Dec 23, 2019

arm64 support added in #802. Let's keep this open for armv7 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants