Source file src/pkg/os/types.go
1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package os 6 7 import "syscall" 8 9 // An operating-system independent representation of Unix data structures. 10 // OS-specific routines in this directory convert the OS-local versions to these. 11 12 // Getpagesize returns the underlying system's memory page size. 13 func Getpagesize() int { return syscall.Getpagesize() } 14 15 // A FileInfo describes a file and is returned by Stat, Fstat, and Lstat 16 type FileInfo struct { 17 Dev uint64 // device number of file system holding file. 18 Ino uint64 // inode number. 19 Nlink uint64 // number of hard links. 20 Mode uint32 // permission and mode bits. 21 Uid int // user id of owner. 22 Gid int // group id of owner. 23 Rdev uint64 // device type for special file. 24 Size int64 // length in bytes. 25 Blksize int64 // size of blocks, in bytes. 26 Blocks int64 // number of blocks allocated for file. 27 Atime_ns int64 // access time; nanoseconds since epoch. 28 Mtime_ns int64 // modified time; nanoseconds since epoch. 29 Ctime_ns int64 // status change time; nanoseconds since epoch. 30 Name string // base name of the file name provided in Open, Stat, etc. 31 FollowedSymlink bool // followed a symlink to get this information 32 } 33 34 // IsFifo reports whether the FileInfo describes a FIFO file. 35 func (f *FileInfo) IsFifo() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFIFO } 36 37 // IsChar reports whether the FileInfo describes a character special file. 38 func (f *FileInfo) IsChar() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFCHR } 39 40 // IsDirectory reports whether the FileInfo describes a directory. 41 func (f *FileInfo) IsDirectory() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFDIR } 42 43 // IsBlock reports whether the FileInfo describes a block special file. 44 func (f *FileInfo) IsBlock() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFBLK } 45 46 // IsRegular reports whether the FileInfo describes a regular file. 47 func (f *FileInfo) IsRegular() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFREG } 48 49 // IsSymlink reports whether the FileInfo describes a symbolic link. 50 func (f *FileInfo) IsSymlink() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFLNK } 51 52 // IsSocket reports whether the FileInfo describes a socket. 53 func (f *FileInfo) IsSocket() bool { return (f.Mode & syscall.S_IFMT) == syscall.S_IFSOCK } 54 55 // Permission returns the file permission bits. 56 func (f *FileInfo) Permission() uint32 { return f.Mode & 0777 }