-
Notifications
You must be signed in to change notification settings - Fork 42
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
mountinfo: BSDs no longer need cgo nor reflect #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build freebsd || darwin | ||
// +build freebsd darwin | ||
|
||
package mountinfo | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
func getMountinfo(entry *unix.Statfs_t) *Info { | ||
var mountinfo Info | ||
mountinfo.Mountpoint = unix.ByteSliceToString(entry.Mntonname[:]) | ||
mountinfo.FSType = unix.ByteSliceToString(entry.Fstypename[:]) | ||
mountinfo.Source = unix.ByteSliceToString(entry.Mntfromname[:]) | ||
return &mountinfo | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mountinfo | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
func int8SliceToString(is []int8) string { | ||
var bs []byte | ||
for _, i := range is { | ||
if i == 0 { | ||
break | ||
} | ||
bs = append(bs, byte(i)) | ||
} | ||
return string(bs) | ||
} | ||
|
||
func getMountinfo(entry *unix.Statfs_t) *Info { | ||
var mountinfo Info | ||
mountinfo.Mountpoint = int8SliceToString(entry.F_mntonname[:]) | ||
mountinfo.FSType = int8SliceToString(entry.F_fstypename[:]) | ||
mountinfo.Source = int8SliceToString(entry.F_mntfromname[:]) | ||
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you forgot to switch to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is correct. In But in This is why I chose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, weird. This is probably something that needs to be fixed in x/sys/unix. Something similar to e.g. https://go-review.googlesource.com/c/sys/+/359674 needs to be done. If you have openbsd running, you can prepare a patch to x/sys/unix similar to the above; if not, I can try to do that or we can maybe kindly ask @tklauser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will make a patch to x/sys/unix for OpenBSD. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return &mountinfo | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I overlooked it. This function is probably doing some excessive allocations and copying and should be rewritten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not think of a better way without
unsafe
. If you are sure, then I will rewrite it withunsafe
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrited with
unsafe
.#117