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.
13
// A fileStat is the implementation of FileInfo returned by Stat and Lstat.
14
type fileStat struct {
16
sys syscall.Win32FileAttributeData
18
// used to implement SameFile
26
func (fs *fileStat) Size() int64 {
27
return int64(fs.sys.FileSizeHigh)<<32 + int64(fs.sys.FileSizeLow)
30
func (fs *fileStat) Mode() (m FileMode) {
31
if fs == &devNullStat {
32
return ModeDevice | ModeCharDevice | 0666
34
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
37
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_READONLY != 0 {
45
func (fs *fileStat) ModTime() time.Time {
46
return time.Unix(0, fs.sys.LastWriteTime.Nanoseconds())
49
// Sys returns syscall.Win32FileAttributeData for file fs.
50
func (fs *fileStat) Sys() interface{} { return &fs.sys }
52
func (fs *fileStat) loadFileId() error {
59
pathp, err := syscall.UTF16PtrFromString(fs.path)
63
h, err := syscall.CreateFile(pathp, 0, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
67
defer syscall.CloseHandle(h)
68
var i syscall.ByHandleFileInformation
69
err = syscall.GetFileInformationByHandle(syscall.Handle(h), &i)
74
fs.vol = i.VolumeSerialNumber
75
fs.idxhi = i.FileIndexHigh
76
fs.idxlo = i.FileIndexLow
80
// devNullStat is fileStat structure describing DevNull file ("NUL").
81
var devNullStat = fileStat{
83
// hopefully this will work for SameFile
89
func sameFile(fs1, fs2 *fileStat) bool {
98
return fs1.vol == fs2.vol && fs1.idxhi == fs2.idxhi && fs1.idxlo == fs2.idxlo
102
func atime(fi FileInfo) time.Time {
103
return time.Unix(0, fi.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds())