{"record":{"id":"db6a52aa1f3fbe00","repo":"kopia/kopia","slug":"windows-getcapacity","errorCode":null,"errorMessage":"windows GetCapacity","messagePattern":"windows GetCapacity","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/blob/filesystem/filesystem_storage_capacity_windows.go","lineNumber":19,"sourceCode":"//go:build windows\n\npackage filesystem\n\nimport (\n\t\"context\"\n\n\t\"github.com/pkg/errors\"\n\t\"golang.org/x/sys/windows\"\n\n\t\"github.com/kopia/kopia/repo/blob\"\n)\n\nfunc (fs *fsStorage) GetCapacity(_ context.Context) (blob.Capacity, error) {\n\tvar c blob.Capacity\n\n\tpathPtr, err := windows.UTF16PtrFromString(fs.RootPath)\n\tif err != nil {\n\t\treturn blob.Capacity{}, errors.Wrap(err, \"windows GetCapacity\")\n\t}\n\n\terr = windows.GetDiskFreeSpaceEx(pathPtr, nil, &c.SizeB, &c.FreeB)\n\tif err != nil {\n\t\treturn blob.Capacity{}, errors.Wrap(err, \"windows GetCapacity\")\n\t}\n\n\treturn c, nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/blob/filesystem/filesystem_storage_capacity_windows.go#L1-L29","documentation":"On Windows, GetCapacity converts fs.RootPath to a UTF-16 pointer via windows.UTF16PtrFromString and calls windows.GetDiskFreeSpaceEx; failure of either is wrapped as \"windows GetCapacity\". This reports that Windows could not resolve the path or query free disk space for the volume containing the storage root.","triggerScenarios":"Calling GetCapacity when fs.RootPath is an invalid Windows path (illegal characters like : * ?, empty string), points to a non-existent/unmapped drive letter, or the volume is unavailable (disconnected network drive).","commonSituations":"Path using forward slashes or UNC path misformatted; USB/network drive disconnected; drive letter changed after the storage was opened; path exceeding MAX_PATH limitations.","solutions":["Verify the drive letter / UNC path in RootPath is valid and accessible (run dir <path> in cmd)","Check disk connectivity and remap disconnected network drives","Normalize the path to a Windows-style absolute path before configuring storage","Ensure the path string contains only characters valid for windows.UTF16PtrFromString (no embedded NULs, no wildcards)"],"exampleFix":"// before\nst, err := fs.New(ctx, fs Options{Path: \"/mnt/data\"})\n// after\nst, err := fs.New(ctx, fs Options{Path: `D:\\Backups\\kopia`}) // valid Windows path\nif err != nil {\n    log.Fatal(err)\n}","handlingStrategy":"validation","validationCode":"func validWindowsPath(p string) error {\n    if p == \"\" || strings.ContainsAny(p, \"*?\\x00\") {\n        return fmt.Errorf(\"invalid Windows path: %q\", p)\n    }\n    if _, err := os.Stat(p); err != nil {\n        return err\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"cap, err := st.GetCapacity(ctx)\nif err != nil && strings.Contains(err.Error(), \"windows GetCapacity\") {\n    // check drive mapping / path validity before retrying\n}","preventionTips":["Use Windows-native absolute paths or proper UNC paths (\\\\\\\\server\\\\share)","Confirm drives are mapped at process start (logon scripts may not map for services)","Avoid embedded NULs and wildcard characters in configured paths","Verify free-space queries with dir before configuring the storage"],"tags":["windows","filesystem","capacity","path"],"backgroundTag":"file-not-found","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}