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

os: ModeType is missing os.ModeCharDevice #27640

Closed
somersf opened this issue Sep 12, 2018 · 2 comments
Closed

os: ModeType is missing os.ModeCharDevice #27640

somersf opened this issue Sep 12, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@somersf
Copy link
Contributor

somersf commented Sep 12, 2018

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 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)
    }
}

https://play.golang.org/p/lcciw1JFCtj

What did you expect to see?

/dev/zero has character device bits set
/dev/zero type is character device

What did you see instead?

/dev/zero has character device bits set
/dev/zero type is other device
@ianlancetaylor ianlancetaylor changed the title os.ModeType is missing os.ModeCharDevice os: ModeType is missing os.ModeCharDevice Sep 12, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 12, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Sep 12, 2018
@tklauser
Copy link
Member

FWIW, in archive/zip.fileModeToUnixMode this also leads to the character device bit not represented correctly.

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?

@gopherbot
Copy link

Change https://golang.org/cl/135075 mentions this issue: os: add ModeCharDevice to ModeType

rillig added a commit to rillig/pkglint that referenced this issue Jun 19, 2019
@golang golang locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants