Commit cc02ef02 authored by Russ Cox's avatar Russ Cox

os: add ModeCharDevice

This should make conversion from Unix mode
to os.FileMode and back not lossy.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5531052
parent f9427364
...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { ...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
} }
fs.mode = FileMode(st.Mode & 0777) fs.mode = FileMode(st.Mode & 0777)
switch st.Mode & syscall.S_IFMT { switch st.Mode & syscall.S_IFMT {
case syscall.S_IFBLK, syscall.S_IFCHR, syscall.S_IFWHT: case syscall.S_IFBLK, syscall.S_IFWHT:
fs.mode |= ModeDevice fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR: case syscall.S_IFDIR:
fs.mode |= ModeDir fs.mode |= ModeDir
case syscall.S_IFIFO: case syscall.S_IFIFO:
......
...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { ...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
} }
fs.mode = FileMode(st.Mode & 0777) fs.mode = FileMode(st.Mode & 0777)
switch st.Mode & syscall.S_IFMT { switch st.Mode & syscall.S_IFMT {
case syscall.S_IFBLK, syscall.S_IFCHR: case syscall.S_IFBLK:
fs.mode |= ModeDevice fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR: case syscall.S_IFDIR:
fs.mode |= ModeDir fs.mode |= ModeDir
case syscall.S_IFIFO: case syscall.S_IFIFO:
......
...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { ...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
} }
fs.mode = FileMode(st.Mode & 0777) fs.mode = FileMode(st.Mode & 0777)
switch st.Mode & syscall.S_IFMT { switch st.Mode & syscall.S_IFMT {
case syscall.S_IFBLK, syscall.S_IFCHR: case syscall.S_IFBLK:
fs.mode |= ModeDevice fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR: case syscall.S_IFDIR:
fs.mode |= ModeDir fs.mode |= ModeDir
case syscall.S_IFIFO: case syscall.S_IFIFO:
......
...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { ...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
} }
fs.mode = FileMode(st.Mode & 0777) fs.mode = FileMode(st.Mode & 0777)
switch st.Mode & syscall.S_IFMT { switch st.Mode & syscall.S_IFMT {
case syscall.S_IFBLK, syscall.S_IFCHR: case syscall.S_IFBLK:
fs.mode |= ModeDevice fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR: case syscall.S_IFDIR:
fs.mode |= ModeDir fs.mode |= ModeDir
case syscall.S_IFIFO: case syscall.S_IFIFO:
......
...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo { ...@@ -24,8 +24,10 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
} }
fs.mode = FileMode(st.Mode & 0777) fs.mode = FileMode(st.Mode & 0777)
switch st.Mode & syscall.S_IFMT { switch st.Mode & syscall.S_IFMT {
case syscall.S_IFBLK, syscall.S_IFCHR: case syscall.S_IFBLK:
fs.mode |= ModeDevice fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR: case syscall.S_IFDIR:
fs.mode |= ModeDir fs.mode |= ModeDir
case syscall.S_IFIFO: case syscall.S_IFIFO:
......
...@@ -30,19 +30,23 @@ type FileMode uint32 ...@@ -30,19 +30,23 @@ type FileMode uint32
// The defined file mode bits are the most significant bits of the FileMode. // The defined file mode bits are the most significant bits of the FileMode.
// The nine least-significant bits are the standard Unix rwxrwxrwx permissions. // The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
// The values of these bits should be considered part of the public API and
// may be used in wire protocols or disk representations: they must not be
// changed, although new bits might be added.
const ( const (
// The single letters are the abbreviations // The single letters are the abbreviations
// used by the String method's formatting. // used by the String method's formatting.
ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory
ModeAppend // a: append-only ModeAppend // a: append-only
ModeExclusive // l: exclusive use ModeExclusive // l: exclusive use
ModeTemporary // t: temporary file (not backed up) ModeTemporary // t: temporary file (not backed up)
ModeSymlink // L: symbolic link ModeSymlink // L: symbolic link
ModeDevice // D: device file ModeDevice // D: device file
ModeNamedPipe // p: named pipe (FIFO) ModeNamedPipe // p: named pipe (FIFO)
ModeSocket // S: Unix domain socket ModeSocket // S: Unix domain socket
ModeSetuid // u: setuid ModeSetuid // u: setuid
ModeSetgid // g: setgid ModeSetgid // g: setgid
ModeCharDevice // c: Unix character device, when ModeDevice is set
// Mask for the type bits. For regular files, none will be set. // Mask for the type bits. For regular files, none will be set.
ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice
...@@ -51,7 +55,7 @@ const ( ...@@ -51,7 +55,7 @@ const (
) )
func (m FileMode) String() string { func (m FileMode) String() string {
const str = "daltLDpSug" const str = "daltLDpSugc"
var buf [20]byte var buf [20]byte
w := 0 w := 0
for i, c := range str { for i, c := range str {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment