3

I'm trying to find out free space information about volumes. Those with letters assigned are fine (GetDiskFreeSpaceEx). I've also connected to VDS (Virtual Disk Service) and retrieved something called AvailableAllocationUnits (A) and AllocationUnitSize (B), where A*B = free size shown by Windows. But B is 4096, so this is not an exact number in bytes.

  1. How is it possible to determine this without VDS?
  2. Is there a more precise way (in bytes)?

regards,
Kate

pnuts
  • 58,317
  • 11
  • 87
  • 139
SmartK8
  • 2,616
  • 1
  • 29
  • 37
  • 1
    http://stackoverflow.com/questions/412632/how-do-i-retrieve-disk-information-in-c and why do you think 4096 is not an exact number of bytes? 4096 bytes is 4KB (using 1024 bytes per KB) – ChrisPatrick Apr 02 '12 at 10:53
  • Hi, DriveInfo just won't do. It doesn't even know about those volumes. I'm talking about volumes without letter access by GUID (such as \\?\GLOBALROOT\Device\HarddiskVolume15). The 4096 rounding would be fine (if more precision is not possible like 1 byte precision), but I need to determine that without VDS if possible. – SmartK8 Apr 02 '12 at 11:06
  • Sorry, I never came back to you. You're right. Thanks. – SmartK8 Jan 10 '15 at 10:49

1 Answers1

1

On Windows, you could execute the following commands and parse the output:

vssadmin list volumes

This gives:

C:\Windows\system32>vssadmin list volumes
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2013 Microsoft Corp.

Volume path: \\?\Volume{66c6160d-60cc-11e3-824b-806e6f6e6963}\
    Volume name: \\?\Volume{66c6160d-60cc-11e3-824b-806e6f6e6963}\
Volume path: D:\
    Volume name: \\?\Volume{66c6160f-60cc-11e3-824b-806e6f6e6963}\
Volume path: C:\
    Volume name: \\?\Volume{66c6160e-60cc-11e3-824b-806e6f6e6963}\

Then Execute

fsutil volume diskfree

Which gives:

C:\Users\MC>fsutil volume diskfree \\?\Volume{66c6160e-60cc-11e3-824b-806e6f6e6963}\
Total # of free bytes        : 47826694144
Total # of bytes             : 255691059200
Total # of avail free bytes  : 47826694144

To read output of a shell process, you can read the standard output

string output = proc.StandardOutput.ReadToEnd();

DISCLAIMER: Yes I know its not exactly the cleanest way, but it is a way. As I'm not aware of an API for accessing such low level info.

Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118
  • 1
    Hi, thanks for the answer I since then found out that VDS actually really returns a correct number. The "rounded" number is actually the correct one. So you can use clean way and not worry. Even in your example the numbers are multiples of 4096 (or AllocationUnitSize to be precise). But I will accept your answer because it is A answer. People can read the comments anyway. – SmartK8 Jan 10 '15 at 10:48