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.
12 // Getpagesize returns the underlying system's memory page size.
13 func Getpagesize() int { return syscall.Getpagesize() }
15 // A FileInfo describes a file and is returned by Stat and Lstat
16 type FileInfo interface {
17 Name() string // base name of the file
18 Size() int64 // length in bytes
19 Mode() FileMode // file mode bits
20 ModTime() time.Time // modification time
21 IsDir() bool // abbreviation for Mode().IsDir()
24 // A FileMode represents a file's mode and permission bits.
25 // The bits have the same definition on all systems, so that
26 // information about files can be moved from one system
27 // to another portably. Not all bits apply to all systems.
28 // The only required bit is ModeDir for directories.
31 // The defined file mode bits are the most significant bits of the FileMode.
32 // The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
33 // The values of these bits should be considered part of the public API and
34 // may be used in wire protocols or disk representations: they must not be
35 // changed, although new bits might be added.
37 // The single letters are the abbreviations
38 // used by the String method's formatting.
39 ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory
40 ModeAppend // a: append-only
41 ModeExclusive // l: exclusive use
42 ModeTemporary // t: temporary file (not backed up)
43 ModeSymlink // L: symbolic link
44 ModeDevice // D: device file
45 ModeNamedPipe // p: named pipe (FIFO)
46 ModeSocket // S: Unix domain socket
47 ModeSetuid // u: setuid
48 ModeSetgid // g: setgid
49 ModeCharDevice // c: Unix character device, when ModeDevice is set
51 // Mask for the type bits. For regular files, none will be set.
52 ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice
54 ModePerm FileMode = 0777 // permission bits
57 func (m FileMode) String() string {
58 const str = "daltLDpSugc"
61 for i, c := range str {
62 if m&(1<<uint(32-1-i)) != 0 {
71 const rwx = "rwxrwxrwx"
72 for i, c := range rwx {
73 if m&(1<<uint(9-1-i)) != 0 {
80 return string(buf[:w])
83 // IsDir reports whether m describes a directory.
84 // That is, it tests for the ModeDir bit being set in m.
85 func (m FileMode) IsDir() bool {
89 // Perm returns the Unix permission bits in m.
90 func (m FileMode) Perm() FileMode {
94 // A FileStat is the implementation of FileInfo returned by Stat and Lstat.
95 // Clients that need access to the underlying system-specific stat information
96 // can test for *os.FileStat and then consult the Sys field.
97 type FileStat struct {
106 func (fs *FileStat) Name() string { return fs.name }
107 func (fs *FileStat) Size() int64 { return fs.size }
108 func (fs *FileStat) Mode() FileMode { return fs.mode }
109 func (fs *FileStat) ModTime() time.Time { return fs.modTime }
110 func (fs *FileStat) IsDir() bool { return fs.mode.IsDir() }
112 // SameFile reports whether fs and other describe the same file.
113 // For example, on Unix this means that the device and inode fields
114 // of the two underlying structures are identical; on other systems
115 // the decision may be based on the path names.
116 func (fs *FileStat) SameFile(other *FileStat) bool {
117 return sameFile(fs, other)