| 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 ( |
| 8 |
"io/fs" |
| 9 |
"syscall" |
| 10 |
) |
| 11 |
|
| 12 |
// Getpagesize returns the underlying system's memory page size. |
| 13 |
func Getpagesize() int { return syscall.Getpagesize() } |
| 14 |
|
| 15 |
// File represents an open file descriptor. |
| 16 |
// |
| 17 |
// The methods of File are safe for concurrent use. |
| 18 |
type File struct { |
| 19 |
*file // os specific |
| 20 |
} |
| 21 |
|
| 22 |
// A FileInfo describes a file and is returned by [Stat] and [Lstat]. |
| 23 |
type FileInfo = fs.FileInfo |
| 24 |
|
| 25 |
// A FileMode represents a file's mode and permission bits. |
| 26 |
// The bits have the same definition on all systems, so that |
| 27 |
// information about files can be moved from one system |
| 28 |
// to another portably. Not all bits apply to all systems. |
| 29 |
// The only required bit is [ModeDir] for directories. |
| 30 |
type FileMode = fs.FileMode |
| 31 |
|
| 32 |
// The defined file mode bits are the most significant bits of the [FileMode]. |
| 33 |
// The nine least-significant bits are the standard Unix rwxrwxrwx permissions. |
| 34 |
// The values of these bits should be considered part of the public API and |
| 35 |
// may be used in wire protocols or disk representations: they must not be |
| 36 |
// changed, although new bits might be added. |
| 37 |
const ( |
| 38 |
// The single letters are the abbreviations |
| 39 |
// used by the String method's formatting. |
| 40 |
ModeDir = fs.ModeDir // d: is a directory |
| 41 |
ModeAppend = fs.ModeAppend // a: append-only |
| 42 |
ModeExclusive = fs.ModeExclusive // l: exclusive use |
| 43 |
ModeTemporary = fs.ModeTemporary // T: temporary file; Plan 9 only |
| 44 |
ModeSymlink = fs.ModeSymlink // L: symbolic link |
| 45 |
ModeDevice = fs.ModeDevice // D: device file |
| 46 |
ModeNamedPipe = fs.ModeNamedPipe // p: named pipe (FIFO) |
| 47 |
ModeSocket = fs.ModeSocket // S: Unix domain socket |
| 48 |
ModeSetuid = fs.ModeSetuid // u: setuid |
| 49 |
ModeSetgid = fs.ModeSetgid // g: setgid |
| 50 |
ModeCharDevice = fs.ModeCharDevice // c: Unix character device, when ModeDevice is set |
| 51 |
ModeSticky = fs.ModeSticky // t: sticky |
| 52 |
ModeIrregular = fs.ModeIrregular // ?: non-regular file; nothing else is known about this file |
| 53 |
|
| 54 |
// Mask for the type bits. For regular files, none will be set. |
| 55 |
ModeType = fs.ModeType |
| 56 |
|
| 57 |
ModePerm = fs.ModePerm // Unix permission bits, 0o777 |
| 58 |
) |
| 59 |
|
| 60 |
func (fs *fileStat) Name() string { return fs.name } |
| 61 |
func (fs *fileStat) IsDir() bool { return fs.Mode().IsDir() } |
| 62 |
|
| 63 |
// SameFile reports whether fi1 and fi2 describe the same file. |
| 64 |
// For example, on Unix this means that the device and inode fields |
| 65 |
// of the two underlying structures are identical; on other systems |
| 66 |
// the decision may be based on the path names. |
| 67 |
// SameFile only applies to results returned by this package's [Stat]. |
| 68 |
// It returns false in other cases. |
| 69 |
func SameFile(fi1, fi2 FileInfo) bool { |
| 70 |
fs1, ok1 := fi1.(*fileStat) |
| 71 |
fs2, ok2 := fi2.(*fileStat) |
| 72 |
if !ok1 || !ok2 { |
| 73 |
return false |
| 74 |
} |
| 75 |
return sameFile(fs1, fs2) |
| 76 |
} |