Documentation
¶
Overview ¶
Package osfs determines filesystem capabilities based on os.FileInfo.
On Linux, it parses /proc/self/mountinfo. Then it can find the mount point based on the st_dev field of the stat result (os.FileInfo.Sys()), and determine filesystem capabilities from the filesystem type.
Index ¶
Constants ¶
const MOUNTINFO_PATH = "/proc/self/mountinfo"
MOUNTINFO_PATH is the common path for the mountinfo file on Linux.
Variables ¶
var Default = defaultFilesystem()
Default has the filesystem capabilities of the common filesystem(s) on the current OS.
Functions ¶
This section is empty.
Types ¶
type Filesystem ¶
type Filesystem struct { Permissions os.FileMode // supported permissions are set (e.g. 0777 on Linux) Symlink bool Hardlink bool Inode bool Memory bool // true if this is an in-memory filesystem (tmpfs) Special bool // true if this is a filesystem like /proc }
Filesystem contains capabilities of one filesystem. The zero value means it has no special features (and is not a typical POSIX filesystem).
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info lists all filesystems on the current system. A specific filesystem can be fetched using Get().
func Read ¶
Read retuns a list of all mountpoints and their filesystem types. It always returns a valid Info object, but may also return an error on failures. Errors are worked around as much as possible. Thus, you can safely ignore Read() errors while still having reasonable defaults.
func (*Info) Get ¶
Get returns the mount point based on a path and stat result. The path does not have to be absolute and may contain symlinks.
func (*Info) GetPath ¶
func (info *Info) GetPath(path string) (*MountPoint, error)
GetPath returns the mount point based on a path. It does a os.Stat and Info.Get on the file. It is a shorthand for Get(path, stat).
func (*Info) GetReal ¶
func (info *Info) GetReal(filePath string, fileInfo os.FileInfo) *MountPoint
MountPoint returns the mountpoint associated with the FileInfo, or nil if the mount point wasn't found. When nil is returned, you can still safely call Filesystem() on the returned pointer (it will return the default filesystem). Calling GetReal() on a nil *Info is not allowed.
The filePath must be absolute (pass filepath.IsAbs), otherwise this function will panic. If you aren't sure that the path is absolute, use filepath.Abs().
type MountPoint ¶
type MountPoint struct { FSRoot string // root of the mount within the filesystem Root string // mount point relative to the process's root Type string // filesystem type, e.g. "ext4" // contains filtered or unexported fields }
MountPoint contains information on one mount point, for example one line of /proc/self/mountinfo.
All fields have the zero value if they are unknown (e.g. ints are 0). Only Root is required to be set (when Type is empty, it is the default filesystem).
func (*MountPoint) DevNumber ¶
func (p *MountPoint) DevNumber() (uint64, bool)
Return the device number for this mount point (the st_dev field for files on it).
func (*MountPoint) Filesystem ¶
func (p *MountPoint) Filesystem() Filesystem
Filesystem returns capabilities of the filesystem for this mount point. The results are more like an educated guess, but should give correct results for the vast majority of detected filesystems. It has a reasonable default (e.g. on Linux a standard POSIX filesystem with hardlinks and inodes).