You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOOS="darwin"
and
GOARCH="amd64"
GOOS="linux"
What did you do?
I stat-ed a character device and analyzed the returned mode.
The os/stat_linux.go and os/stat_darwin.go implementations map a system stat value of S_IFCHR to ModeDevice | ModeCharDevice. I did not check other platforms.
However, the ModeType mask defined in os/type.go (https://golang.org/pkg/os/#FileMode) doesn't include the ModeCharDevice bit.
Masking a mode with ModeType in order to recover the type from the mode doesn't allow ModeDevice | ModeCharDevice to be recovered.
package main
import (
"fmt"
"os"
)
func main() {
path := "/dev/zero"
info, err := os.Lstat(path)
if err != nil {
fmt.Printf("stat failed; %v\n", err)
return
}
mode := info.Mode()
const charDev = os.ModeDevice | os.ModeCharDevice
if mode & charDev == charDev {
fmt.Printf("%s has character device bits set\n", path)
}
if mode & os.ModeType == charDev {
fmt.Printf("%s type is character device\n", path)
} else if mode & os.ModeType == os.ModeDevice {
fmt.Printf("%s type is other device\n", path)
}
}
os.ModeCharDevice was added by @rsc in https://golang.org/cl/5531052, but nothing indicates why it was omitted from os.ModeType. Maybe just an oversight?
What version of Go are you using (
go version
)?go1.11
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOOS="darwin"
and
GOARCH="amd64"
GOOS="linux"
What did you do?
I stat-ed a character device and analyzed the returned mode.
The
os/stat_linux.go
andos/stat_darwin.go
implementations map a system stat value ofS_IFCHR
toModeDevice | ModeCharDevice
. I did not check other platforms.However, the
ModeType
mask defined inos/type.go
(https://golang.org/pkg/os/#FileMode) doesn't include theModeCharDevice
bit.Masking a mode with
ModeType
in order to recover the type from the mode doesn't allowModeDevice | ModeCharDevice
to be recovered.https://play.golang.org/p/lcciw1JFCtj
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: