Commit 8cc09240 authored by lch's avatar lch Committed by Han-Wen Nienhuys

fuse: separate const definitions into os specific files and merge common structs and functions

Change-Id: I76715678a305ebe981ba20392965ff5c011b883e
parent 44cba9c3
...@@ -70,8 +70,6 @@ func CurrentOwner() *Owner { ...@@ -70,8 +70,6 @@ func CurrentOwner() *Owner {
} }
} }
const _UTIME_OMIT = ((1 << 30) - 2)
// UtimeToTimespec converts a "Time" pointer as passed to Utimens to a // UtimeToTimespec converts a "Time" pointer as passed to Utimens to a
// "Timespec" that can be passed to the utimensat syscall. // "Timespec" that can be passed to the utimensat syscall.
// A nil pointer is converted to the special UTIME_OMIT value. // A nil pointer is converted to the special UTIME_OMIT value.
......
package fuse
// Ref: https://github.com/apple/darwin-xnu/blob/main/bsd/sys/stat.h#L576
const _UTIME_OMIT = -2
//go:build !darwin
package fuse
import "golang.org/x/sys/unix"
const _UTIME_OMIT = unix.UTIME_OMIT
...@@ -44,9 +44,6 @@ const ( ...@@ -44,9 +44,6 @@ const (
// ENOSYS Function not implemented // ENOSYS Function not implemented
ENOSYS = Status(syscall.ENOSYS) ENOSYS = Status(syscall.ENOSYS)
// ENODATA No data available
ENODATA = Status(syscall.ENODATA)
// ENOTDIR Not a directory // ENOTDIR Not a directory
ENOTDIR = Status(syscall.ENOTDIR) ENOTDIR = Status(syscall.ENOTDIR)
...@@ -693,3 +690,72 @@ func (lk *FileLock) FromFlockT(flockT *syscall.Flock_t) { ...@@ -693,3 +690,72 @@ func (lk *FileLock) FromFlockT(flockT *syscall.Flock_t) {
} }
lk.Pid = uint32(flockT.Pid) lk.Pid = uint32(flockT.Pid)
} }
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
InHeader
Flags_ uint32
Dummy uint32
Fh_ uint64
}
// Flags accesses the flags. This is a method, because OSXFuse does not
// have GetAttrIn flags.
func (g *GetAttrIn) Flags() uint32 {
return g.Flags_
}
// Fh accesses the file handle. This is a method, because OSXFuse does not
// have GetAttrIn flags.
func (g *GetAttrIn) Fh() uint64 {
return g.Fh_
}
type MknodIn struct {
InHeader
// Mode to use, including the Umask value
Mode uint32
Rdev uint32
Umask uint32
Padding uint32
}
type CreateIn struct {
InHeader
Flags uint32
// Mode for the new file; already takes Umask into account.
Mode uint32
// Umask used for this create call.
Umask uint32
Padding uint32
}
type ReadIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
type WriteIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
WriteFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
) )
const ( const (
ENODATA = Status(syscall.ENODATA)
ENOATTR = Status(syscall.ENOATTR) // ENOATTR is not defined for all GOOS. ENOATTR = Status(syscall.ENOATTR) // ENOATTR is not defined for all GOOS.
// EREMOTEIO is not supported on Darwin. // EREMOTEIO is not supported on Darwin.
...@@ -61,73 +62,6 @@ const ( ...@@ -61,73 +62,6 @@ const (
FOPEN_PURGE_UBC = (1 << 31) FOPEN_PURGE_UBC = (1 << 31)
) )
// compat with linux.
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
InHeader
Flags_ uint32
Dummy uint32
Fh_ uint64
}
func (g *GetAttrIn) Flags() uint32 {
return g.Flags_
}
func (g *GetAttrIn) Fh() uint64 {
return g.Fh_
}
// Uses OpenIn struct for create.
type CreateIn struct {
InHeader
Flags uint32
// Mode for the new file; already takes Umask into account.
Mode uint32
// Umask used for this create call.
Umask uint32
Padding uint32
}
type MknodIn struct {
InHeader
// Mode to use, including the Umask value
Mode uint32
Rdev uint32
Umask uint32
Padding uint32
}
type ReadIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
type WriteIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
WriteFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
type SetXAttrIn struct { type SetXAttrIn struct {
InHeader InHeader
Size uint32 Size uint32
......
package fuse
import "syscall"
const (
ENOATTR = Status(syscall.ENOATTR)
ENODATA = Status(syscall.EIO)
)
const (
CAP_NO_OPENDIR_SUPPORT = (1 << 24)
// The higher capabilities are not currently defined by FreeBSD.
// Ref: https://cgit.freebsd.org/src/tree/sys/fs/fuse/fuse_kernel.h
// CAP_RENAME_SWAP only exists on OSX.
CAP_RENAME_SWAP = 0x0
// CAP_EXPLICIT_INVAL_DATA is not supported on FreeBSD.
CAP_EXPLICIT_INVAL_DATA = 0x0
)
func (s *StatfsOut) FromStatfsT(statfs *syscall.Statfs_t) {
s.Blocks = statfs.Blocks
s.Bsize = uint32(statfs.Bsize)
s.Bfree = statfs.Bfree
s.Bavail = uint64(statfs.Bavail)
s.Files = statfs.Files
s.Ffree = uint64(statfs.Ffree)
s.Frsize = uint32(statfs.Bsize)
s.NameLen = uint32(statfs.Namemax)
}
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
) )
const ( const (
ENODATA = Status(syscall.ENODATA)
ENOATTR = Status(syscall.ENODATA) // On Linux, ENOATTR is an alias for ENODATA. ENOATTR = Status(syscall.ENODATA) // On Linux, ENOATTR is an alias for ENODATA.
// EREMOTEIO Remote I/O error // EREMOTEIO Remote I/O error
...@@ -33,113 +34,6 @@ const ( ...@@ -33,113 +34,6 @@ const (
CAP_RENAME_SWAP = 0x0 CAP_RENAME_SWAP = 0x0
) )
type Attr struct {
Ino uint64
Size uint64
// Blocks is the number of 512-byte blocks that the file occupies on disk.
Blocks uint64
Atime uint64
Mtime uint64
Ctime uint64
Atimensec uint32
Mtimensec uint32
Ctimensec uint32
Mode uint32
Nlink uint32
Owner
Rdev uint32
// Blksize is the preferred size for file system operations.
Blksize uint32
Padding uint32
}
type SetAttrIn struct {
SetAttrInCommon
}
const (
// Mask for GetAttrIn.Flags. If set, GetAttrIn has a file handle set.
FUSE_GETATTR_FH = (1 << 0)
)
type GetAttrIn struct {
InHeader
Flags_ uint32
Dummy uint32
Fh_ uint64
}
// Flags accesses the flags. This is a method, because OSXFuse does not
// have GetAttrIn flags.
func (g *GetAttrIn) Flags() uint32 {
return g.Flags_
}
// Fh accesses the file handle. This is a method, because OSXFuse does not
// have GetAttrIn flags.
func (g *GetAttrIn) Fh() uint64 {
return g.Fh_
}
type CreateIn struct {
InHeader
Flags uint32
// Mode for the new file; already takes Umask into account.
Mode uint32
// Umask used for this create call.
Umask uint32
Padding uint32
}
type MknodIn struct {
InHeader
// Mode to use, including the Umask value
Mode uint32
Rdev uint32
Umask uint32
Padding uint32
}
type ReadIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
ReadFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
type WriteIn struct {
InHeader
Fh uint64
Offset uint64
Size uint32
WriteFlags uint32
LockOwner uint64
Flags uint32
Padding uint32
}
type SetXAttrIn struct {
InHeader
Size uint32
Flags uint32
}
type GetXAttrIn struct {
InHeader
Size uint32
Padding uint32
}
func (s *StatfsOut) FromStatfsT(statfs *syscall.Statfs_t) { func (s *StatfsOut) FromStatfsT(statfs *syscall.Statfs_t) {
s.Blocks = statfs.Blocks s.Blocks = statfs.Blocks
s.Bsize = uint32(statfs.Bsize) s.Bsize = uint32(statfs.Bsize)
......
//go:build !darwin
package fuse
type Attr struct {
Ino uint64
Size uint64
// Blocks is the number of 512-byte blocks that the file occupies on disk.
Blocks uint64
Atime uint64
Mtime uint64
Ctime uint64
Atimensec uint32
Mtimensec uint32
Ctimensec uint32
Mode uint32
Nlink uint32
Owner
Rdev uint32
// Blksize is the preferred size for file system operations.
Blksize uint32
Padding uint32
}
type SetAttrIn struct {
SetAttrInCommon
}
type SetXAttrIn struct {
InHeader
Size uint32
Flags uint32
}
type GetXAttrIn struct {
InHeader
Size uint32
Padding uint32
}
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