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
19 // used to implement SameFile
27 func (fs
*fileStat
) Size() int64 {
28 return int64(fs
.sys
.FileSizeHigh
)<<32 + int64(fs
.sys
.FileSizeLow
)
31 func (fs
*fileStat
) Mode() (m FileMode
) {
32 if fs
== &devNullStat
{
33 return ModeDevice | ModeCharDevice |
0666
35 if fs
.sys
.FileAttributes
&syscall
.FILE_ATTRIBUTE_DIRECTORY
!= 0 {
38 if fs
.sys
.FileAttributes
&syscall
.FILE_ATTRIBUTE_READONLY
!= 0 {
43 if fs
.sys
.FileAttributes
&syscall
.FILE_ATTRIBUTE_REPARSE_POINT
!= 0 {
52 func (fs
*fileStat
) ModTime() time
.Time
{
53 return time
.Unix(0, fs
.sys
.LastWriteTime
.Nanoseconds())
56 // Sys returns syscall.Win32FileAttributeData for file fs.
57 func (fs
*fileStat
) Sys() interface{} { return &fs
.sys
}
59 func (fs
*fileStat
) loadFileId() error
{
66 pathp
, err
:= syscall
.UTF16PtrFromString(fs
.path
)
70 h
, err
:= syscall
.CreateFile(pathp
, 0, 0, nil, syscall
.OPEN_EXISTING
, syscall
.FILE_FLAG_BACKUP_SEMANTICS
, 0)
74 defer syscall
.CloseHandle(h
)
75 var i syscall
.ByHandleFileInformation
76 err
= syscall
.GetFileInformationByHandle(h
, &i
)
81 fs
.vol
= i
.VolumeSerialNumber
82 fs
.idxhi
= i
.FileIndexHigh
83 fs
.idxlo
= i
.FileIndexLow
87 // devNullStat is fileStat structure describing DevNull file ("NUL").
88 var devNullStat
= fileStat
{
90 // hopefully this will work for SameFile
96 func sameFile(fs1
, fs2
*fileStat
) bool {
105 return fs1
.vol
== fs2
.vol
&& fs1
.idxhi
== fs2
.idxhi
&& fs1
.idxlo
== fs2
.idxlo
109 func atime(fi FileInfo
) time
.Time
{
110 return time
.Unix(0, fi
.Sys().(*syscall
.Win32FileAttributeData
).LastAccessTime
.Nanoseconds())