// Need to find 3 values, Total drive size, Root drive used, actual used by path // Need to be aware of UNC paths // Need to be aware of Junctions private static void FindAndAddDisplaySizes(string path, ref UInt64 min, ref UInt64 max) { ulong freeBytesAvailable; ulong pathUsedBytes; ulong rootBytesNotCoveredByPath; DriveSpaceDisplay.FreeBytesAvailable(out freeBytesAvailable, path, out pathUsedBytes, out rootBytesNotCoveredByPath); min += pathUsedBytes; max += pathUsedBytes; max += freeBytesAvailable; }
private void btnFileCount_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtCoverageMin.Text)) { btnCoverage_Click(sender, e); } try { Enabled = false; using (new WaitCursor(true)) { ulong freeBytesAvailable; ulong pathUsedBytes; ulong rootBytesNotCoveredByPath; // e.g. 100,000 files @ 256KB/2 block size = 12GB of "extra" space // So this is alot more tricky. // 1st get the Minimum space that could be used for the Parity (Ignore the existing parity) // For each parity target find min space after ignoring "existing" parity file ulong maxParitySizeAvailable = ulong.MaxValue; foreach (string raidTarget in RaidTargets) { DriveSpaceDisplay.FreeBytesAvailable(out freeBytesAvailable, raidTarget, out pathUsedBytes, out rootBytesNotCoveredByPath); ulong currentTarget = freeBytesAvailable + pathUsedBytes; if (maxParitySizeAvailable > currentTarget) { maxParitySizeAvailable = currentTarget; } } // 2 - Then for each of the sources, get the number of actual files // Set Min value to the actual max of the files // 3 - Then for each source find actual and available coverage // use the actual files, and project to theoretical possible // Set Max value to the max of those ulong minFiles = 0; // 4 - Find the Max covered, ulong maxFiles = 1 << 18; // 5 - Make sure that Parity has enough room times the number of max files, // and add onto the left over space to find the min and max values. ulong maxProjectedSource = 0; foreach (string path in SnapShotSources) { DriveSpaceDisplay.FreeBytesAvailable(out freeBytesAvailable, path, out pathUsedBytes, out rootBytesNotCoveredByPath); ulong currentSource = freeBytesAvailable + pathUsedBytes; if (maxProjectedSource < currentSource) { maxProjectedSource = currentSource; } } ulong minParityNeeded = maxProjectedSource + (minFiles * ulong.Parse(txtCoverageMin.Text)) / 2; ulong maxParityNeeded = maxProjectedSource + (minFiles * ulong.Parse(txtCoverageMax.Text)) / 2; if (maxParityNeeded > maxParitySizeAvailable) { lblBadNews.Text = "Display badnews about theoretical projected value - maxParityNeeded > maxParitySizeAvailable"; } if (minParityNeeded > maxParitySizeAvailable) { // Display badnews about theoretical projected value; lblBadNews.Text = "Display badnews about theoretical projected value - minParityNeeded > maxParitySizeAvailable"; } } } finally { Enabled = true; } }