Publish file mode conversion functions
parent
76071bba22
commit
c02e24f8ce
|
@ -89,7 +89,7 @@ func convertInMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if valid&fusekernel.SetattrMode != 0 {
|
if valid&fusekernel.SetattrMode != 0 {
|
||||||
mode := convertFileMode(in.Mode)
|
mode := ConvertFileMode(in.Mode)
|
||||||
to.Mode = &mode
|
to.Mode = &mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func convertInMessage(
|
||||||
// the fact that this is a directory is implicit in the fact that the
|
// the fact that this is a directory is implicit in the fact that the
|
||||||
// opcode is mkdir. But we want the correct mode to go through, so ensure
|
// opcode is mkdir. But we want the correct mode to go through, so ensure
|
||||||
// that os.ModeDir is set.
|
// that os.ModeDir is set.
|
||||||
Mode: convertFileMode(in.Mode) | os.ModeDir,
|
Mode: ConvertFileMode(in.Mode) | os.ModeDir,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ func convertInMessage(
|
||||||
o = &fuseops.MkNodeOp{
|
o = &fuseops.MkNodeOp{
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Mode: convertFileMode(in.Mode),
|
Mode: ConvertFileMode(in.Mode),
|
||||||
Rdev: in.Rdev,
|
Rdev: in.Rdev,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ func convertInMessage(
|
||||||
o = &fuseops.CreateFileOp{
|
o = &fuseops.CreateFileOp{
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Mode: convertFileMode(in.Mode),
|
Mode: ConvertFileMode(in.Mode),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,34 +898,7 @@ func convertAttributes(
|
||||||
out.Blocks = (in.Size + 512 - 1) / 512
|
out.Blocks = (in.Size + 512 - 1) / 512
|
||||||
|
|
||||||
// Set the mode.
|
// Set the mode.
|
||||||
out.Mode = uint32(in.Mode) & 0777
|
out.Mode = ConvertGolangMode(in.Mode)
|
||||||
switch {
|
|
||||||
default:
|
|
||||||
out.Mode |= syscall.S_IFREG
|
|
||||||
case in.Mode&os.ModeDir != 0:
|
|
||||||
out.Mode |= syscall.S_IFDIR
|
|
||||||
case in.Mode&os.ModeDevice != 0:
|
|
||||||
if in.Mode&os.ModeCharDevice != 0 {
|
|
||||||
out.Mode |= syscall.S_IFCHR
|
|
||||||
} else {
|
|
||||||
out.Mode |= syscall.S_IFBLK
|
|
||||||
}
|
|
||||||
case in.Mode&os.ModeNamedPipe != 0:
|
|
||||||
out.Mode |= syscall.S_IFIFO
|
|
||||||
case in.Mode&os.ModeSymlink != 0:
|
|
||||||
out.Mode |= syscall.S_IFLNK
|
|
||||||
case in.Mode&os.ModeSocket != 0:
|
|
||||||
out.Mode |= syscall.S_IFSOCK
|
|
||||||
}
|
|
||||||
if in.Mode&os.ModeSetuid != 0 {
|
|
||||||
out.Mode |= syscall.S_ISUID
|
|
||||||
}
|
|
||||||
if in.Mode&os.ModeSetgid != 0 {
|
|
||||||
out.Mode |= syscall.S_ISGID
|
|
||||||
}
|
|
||||||
if in.Mode&os.ModeSticky != 0 {
|
|
||||||
out.Mode |= syscall.S_ISVTX
|
|
||||||
}
|
|
||||||
|
|
||||||
if out.Mode & (syscall.S_IFCHR | syscall.S_IFBLK) != 0 {
|
if out.Mode & (syscall.S_IFCHR | syscall.S_IFBLK) != 0 {
|
||||||
out.Rdev = in.Rdev
|
out.Rdev = in.Rdev
|
||||||
|
@ -959,7 +932,7 @@ func convertChildInodeEntry(
|
||||||
convertAttributes(in.Child, &in.Attributes, &out.Attr)
|
convertAttributes(in.Child, &in.Attributes, &out.Attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertFileMode(unixMode uint32) os.FileMode {
|
func ConvertFileMode(unixMode uint32) os.FileMode {
|
||||||
mode := os.FileMode(unixMode & 0777)
|
mode := os.FileMode(unixMode & 0777)
|
||||||
switch unixMode & syscall.S_IFMT {
|
switch unixMode & syscall.S_IFMT {
|
||||||
case syscall.S_IFREG:
|
case syscall.S_IFREG:
|
||||||
|
@ -992,6 +965,38 @@ func convertFileMode(unixMode uint32) os.FileMode {
|
||||||
return mode
|
return mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertGolangMode(inMode os.FileMode) uint32 {
|
||||||
|
outMode := uint32(inMode) & 0777
|
||||||
|
switch {
|
||||||
|
default:
|
||||||
|
outMode |= syscall.S_IFREG
|
||||||
|
case inMode&os.ModeDir != 0:
|
||||||
|
outMode |= syscall.S_IFDIR
|
||||||
|
case inMode&os.ModeDevice != 0:
|
||||||
|
if inMode&os.ModeCharDevice != 0 {
|
||||||
|
outMode |= syscall.S_IFCHR
|
||||||
|
} else {
|
||||||
|
outMode |= syscall.S_IFBLK
|
||||||
|
}
|
||||||
|
case inMode&os.ModeNamedPipe != 0:
|
||||||
|
outMode |= syscall.S_IFIFO
|
||||||
|
case inMode&os.ModeSymlink != 0:
|
||||||
|
outMode |= syscall.S_IFLNK
|
||||||
|
case inMode&os.ModeSocket != 0:
|
||||||
|
outMode |= syscall.S_IFSOCK
|
||||||
|
}
|
||||||
|
if inMode&os.ModeSetuid != 0 {
|
||||||
|
outMode |= syscall.S_ISUID
|
||||||
|
}
|
||||||
|
if inMode&os.ModeSetgid != 0 {
|
||||||
|
outMode |= syscall.S_ISGID
|
||||||
|
}
|
||||||
|
if inMode&os.ModeSticky != 0 {
|
||||||
|
outMode |= syscall.S_ISVTX
|
||||||
|
}
|
||||||
|
return outMode
|
||||||
|
}
|
||||||
|
|
||||||
func writeXattrSize(m *buffer.OutMessage, size uint32) {
|
func writeXattrSize(m *buffer.OutMessage, size uint32) {
|
||||||
out := (*fusekernel.GetxattrOut)(m.Grow(int(unsafe.Sizeof(fusekernel.GetxattrOut{}))))
|
out := (*fusekernel.GetxattrOut)(m.Grow(int(unsafe.Sizeof(fusekernel.GetxattrOut{}))))
|
||||||
out.Size = size
|
out.Size = size
|
||||||
|
|
Loading…
Reference in New Issue