{"record":{"id":"829713b2daee508a","repo":"astrid-runtime/astrid","slug":"windows-drive-target-is-already-in-use","errorCode":null,"errorMessage":"Windows drive target is already in use: {}","messagePattern":"Windows drive target is already in use: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-provider-winfsp/src/main.rs","lineNumber":348,"sourceCode":"            bail!(\"kernel refused storage unmount authorization: {error}\")\n        },\n        _ => bail!(\"kernel returned an unexpected storage unmount response\"),\n    }\n}\n\n#[cfg(windows)]\nfn prepare_mountpoint(\n    requested: Option<PathBuf>,\n    view: &astrid_core::storage_provider::StorageProviderViewV1,\n) -> Result<(PathBuf, bool)> {\n    let _ = view;\n    let mountpoint = requested.map_or_else(first_free_drive, Ok)?;\n    if !mountpoint.is_absolute() {\n        bail!(\"mountpoint must be absolute\");\n    }\n    if is_drive_target(&mountpoint) {\n        if std::fs::metadata(&mountpoint).is_ok() {\n            bail!(\n                \"Windows drive target is already in use: {}\",\n                mountpoint.display()\n            );\n        }\n        return Ok((mountpoint, false));\n    }\n\n    let parent = mountpoint\n        .parent()\n        .context(\"WinFsp directory mountpoint has no parent\")?;\n    std::fs::create_dir_all(parent)\n        .with_context(|| format!(\"create mountpoint parent {}\", parent.display()))?;\n    astrid_core::platform_fs::verify_no_redirects(parent)\n        .with_context(|| format!(\"reject redirected mountpoint parent {}\", parent.display()))?;\n    if !std::fs::symlink_metadata(parent)?.is_dir() {\n        bail!(\"mountpoint parent is not a directory: {}\", parent.display());\n    }\n    match std::fs::symlink_metadata(&mountpoint) {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-provider-winfsp/src/main.rs#L330-L366","documentation":"When the requested mountpoint is a drive target (a drive root like `F:\\`), `prepare_mountpoint` checks whether that drive already exists via `std::fs::metadata`. If metadata succeeds, the drive letter is occupied (by another volume, subst mapping, or network drive) and WinFsp cannot claim it, so the provider bails with this message including the offending path.","triggerScenarios":"`mount` is called with an explicit drive-root mountpoint (e.g. `E:\\`) that already resolves to an existing volume, or a reserved drive letter collides with an existing device on the machine.","commonSituations":"Hard-coding a drive letter that is already used by a USB stick or mapped network drive on the target machine; re-running a mount without unmounting first; multi-tenant machines where drive letters are contested.","solutions":["Choose a different, unused drive letter for the mountpoint","Unmount or disconnect whatever currently occupies the drive letter, then retry","Omit the mountpoint argument so `first_free_drive` automatically picks a free letter from D: to Z:"],"exampleFix":"// before\nmount(provider, Some(PathBuf::from(\"E:\\\\\"))).await?; // E: already in use\n// after\nmount(provider, None).await?; // auto-picks first free drive","handlingStrategy":"validation","validationCode":"// Check drive availability before requesting it\nfn drive_free(letter: char) -> bool {\n    !std::fs::metadata(format!(\"{letter}:\\\\\")).is_ok()\n}\nif !drive_free('E') { /* pick another letter or pass None for auto-select */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't hard-code drive letters in configs or scripts","Pass `None` as the mountpoint to let first_free_drive auto-select D:–Z:","Clean up previous mounts so drive letters are released"],"tags":["filesystem","windows","mount-conflict","drive-letter"],"backgroundTag":"address-already-in-use","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}