vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Build the tree for Windows and name the platform seams
215f8aebc38e69e621eb6f739e0cfea2ba07fd9a · Keenan Nemetz · 2d ago · parent 416739b1
Build the tree for Windows and name the platform seams `go build` for windows/amd64 failed on five unix syscall uses, and the tree had nowhere to say what a platform can and cannot do. Each unix-only site now lives in a `_unix.go` file with a Windows counterpart: disk capacity through GetDiskFreeSpaceEx, allocated bytes through GetCompressedFileSize, hard-link identity through GetFileInformationByHandle, the runner's cache lock through LockFileEx, a liveness probe through OpenProcess, and a command's process group through a helper that has no group to signal yet. Two sites cannot be ported without weakening them, so they refuse rather than pretend. File modes are a unix control and Windows needs ACLs instead, so `internal/secure` will not create or accept a secret there, and `internal/audit` will not verify a log it cannot check. The front door says the same about exec, which Windows does not have: sshd gets an explanation instead of a process that returns EWINDOWS. A CI step cross-compiles windows/amd64 and vets it, and `go vet` is what type-checks the test files that `go build` skips, so a unix-only call fails a push instead of a port nobody can start. Part of 01M8S9B86B36PE0MY8MMCRCMYA.
internal/storage/stat_windows.go +81
| @@ -0,0 +1,81 @@ | |||
| 1 | //go:build windows | ||
| 2 | |||
| 3 | package storage | ||
| 4 | |||
| 5 | import ( | ||
| 6 | "io/fs" | ||
| 7 | "os" | ||
| 8 | "unsafe" | ||
| 9 | |||
| 10 | "golang.org/x/sys/windows" | ||
| 11 | ) | ||
| 12 | |||
| 13 | // fileKey identifies a file by the volume it lives on and the index the | ||
| 14 | // filesystem gave it, which is how a hard link is measured once per inode rather | ||
| 15 | // than once per name. Windows reports both through an open handle rather than | ||
| 16 | // os.FileInfo, so the file is opened here; one that cannot be opened is counted | ||
| 17 | // under every name it has, which over-reports disk use rather than losing bytes. | ||
| 18 | func fileKeyFor(path string, _ fs.FileInfo) (fileKey, bool) { | ||
| 19 | f, err := os.Open(path) | ||
| 20 | if err != nil { | ||
| 21 | return fileKey{}, false | ||
| 22 | } | ||
| 23 | defer f.Close() | ||
| 24 | var info windows.ByHandleFileInformation | ||
| 25 | if err := windows.GetFileInformationByHandle(windows.Handle(f.Fd()), &info); err != nil { | ||
| 26 | return fileKey{}, false | ||
| 27 | } | ||
| 28 | return fileKey{ | ||
| 29 | dev: uint64(info.VolumeSerialNumber), | ||
| 30 | ino: uint64(info.FileIndexHigh)<<32 | uint64(info.FileIndexLow), | ||
| 31 | }, true | ||
| 32 | } | ||
| 33 | |||
| 34 | var ( | ||
| 35 | kernel32 = windows.NewLazySystemDLL("kernel32.dll") | ||
| 36 | procGetCompressedFileSizeW = kernel32.NewProc("GetCompressedFileSizeW") | ||
| 37 | ) | ||
| 38 | |||
| 39 | // allocatedBytes is the space the file actually costs. GetCompressedFileSize is | ||
| 40 | // how Windows answers that question: it reports the clusters allocated to the | ||
| 41 | // file, so a sparse or compressed file does not claim its apparent size. When the | ||
| 42 | // call fails, the apparent size is the answer that cannot under-report. | ||
| 43 | func allocatedBytes(path string, info fs.FileInfo) int64 { | ||
| 44 | p, err := windows.UTF16PtrFromString(path) | ||
| 45 | if err != nil { | ||
| 46 | return info.Size() | ||
| 47 | } | ||
| 48 | var high uint32 | ||
| 49 | low, _, callErr := procGetCompressedFileSizeW.Call( | ||
| 50 | uintptr(unsafe.Pointer(p)), | ||
| 51 | uintptr(unsafe.Pointer(&high)), | ||
| 52 | ) | ||
| 53 | // The API signals failure with INVALID_FILE_SIZE, so a real 0xFFFFFFFF-byte | ||
| 54 | // result is distinguished by a zero last-error, not by the value. | ||
| 55 | if uint32(low) == 0xffffffff && callErr != nil && callErr != windows.ERROR_SUCCESS { | ||
| 56 | return info.Size() | ||
| 57 | } | ||
| 58 | if n := int64(high)<<32 | int64(uint32(low)); n > 0 { | ||
| 59 | return n | ||
| 60 | } | ||
| 61 | return info.Size() | ||
| 62 | } | ||
| 63 | |||
| 64 | // diskUsage is the capacity of the volume holding root. Available is what this | ||
| 65 | // account can still write, which is the number an operator cares about; Used is | ||
| 66 | // the whole volume's usage, not just Vole's. | ||
| 67 | func diskUsage(root string) (Disk, error) { | ||
| 68 | p, err := windows.UTF16PtrFromString(root) | ||
| 69 | if err != nil { | ||
| 70 | return Disk{}, err | ||
| 71 | } | ||
| 72 | var available, total, free uint64 | ||
| 73 | if err := windows.GetDiskFreeSpaceEx(p, &available, &total, &free); err != nil { | ||
| 74 | return Disk{}, err | ||
| 75 | } | ||
| 76 | return Disk{ | ||
| 77 | Total: int64(total), | ||
| 78 | Used: int64(total - free), | ||
| 79 | Available: int64(available), | ||
| 80 | }, nil | ||
| 81 | } | ||