This is the next version of a toy I shot together while waiting for a backup to finish. It scans drives from A: to Z:, determines their type and if media is available it determines the storage size and how much if any free space is available.
Output depending on what you have plugged in or loaded looks something like this.
Media type Drv Size Free
========== === ==== ====
Removable media b:\ No Media Present
HDD partition c:\ 232 gb 223 gb
HDD partition d:\ 227 gb 226 gb
HDD partition e:\ 227 gb 217 gb
HDD partition f:\ 243 gb 242 gb
HDD partition g:\ 232 gb 228 gb
HDD partition h:\ 232 gb 221 gb
HDD partition i:\ 232 gb 212 gb
HDD partition j:\ 232 gb 140 gb
HDD partition k:\ 232 gb 232 gb
HDD partition l:\ 232 gb 219 gb
HDD partition m:\ 232 gb 228 gb
HDD partition n:\ 232 gb 202 gb
CD/DVD drive o:\ No Media Present
Removable media p:\ No Media Present
Removable media q:\ 3.62 gb 3.62 gb
The source code.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
comment * ---------------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
DF.EXE Disk Free utility scans drives from A: to Z:
displaying the drive type, drive size and available
drive space.
Run DF.EXE from the command line
Another bloated pig wickedly crafted in Microsoft Assembler
--------------------------------------------------------- *
include \masm32\include\Shlwapi.inc
includelib \masm32\lib\Shlwapi.lib
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
; inkey ; uncoment this line to view from editor
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
LOCAL avl :QWORD ; 64 bit target for available disk space
LOCAL dsk :QWORD ; 64 bit target for drive size
LOCAL cnt :DWORD ; loop counter
LOCAL drv :DWORD ; drive letter variable
LOCAL pbuf :DWORD ; text pointer 1
LOCAL buffer[256]:BYTE ; text buffer 1
LOCAL buf2 :DWORD ; text pointer 2
LOCAL buffer2[256]:BYTE ; text buffer 2
push ebx
push esi
push edi
mov cnt, 0 ; zero the counter
mov drv, "A" ; start at drive A
lea ebx, drv ; load address of variable "drv" into EBX
invoke GetLogicalDrives ; returns bitmask in EAX
mov esi, eax
mov edi, 00000000000000000000000000000001b ; start with bit set to drive A:
; --------------------
; display topic header
; --------------------
print "Media type",9," Drv",9," Size",9," Free",13,10
print "==========",9," ===",9," ====",9," ====",13,10
; -----------------------------------------------------------------------
lp:
test esi, edi ; test if bit set in ESI
jz @F
mov pbuf, ptr$(buffer)
mov pbuf, cat$(pbuf,ebx,":\ ") ; append ":\" to the drive letter
invoke GetDriveType,pbuf
switch eax
case 0 ; The drive type cannot be determined.
print "Unknown type "
case 1 ; The root directory does not exist.
print "No root directory "
case DRIVE_REMOVABLE ; The drive can be removed from the drive.
print "Removable media "
case DRIVE_FIXED ; The disk cannot be removed from the drive.
print "HDD partition "
case DRIVE_REMOTE ; The drive is a remote (network) drive.
print "Network drive "
case DRIVE_CDROM ; The drive is a CD-ROM drive.
print "CD/DVD drive "
case DRIVE_RAMDISK ; The drive is a RAM disk.
print "Ram drive "
endsw
; -----------------------------------------------------
; so Windows does not display an error on missing media
; -----------------------------------------------------
invoke SetErrorMode,SEM_FAILCRITICALERRORS
invoke GetDiskFreeSpaceEx,pbuf,ADDR avl,ADDR dsk,NULL
.if eax != 0
mov buf2, ptr$(buffer2)
lea eax, dsk
invoke StrFormatByteSize64,[eax], [eax+4], buf2, 256 ; format the disk size data
mov pbuf, lcase$(cat$(pbuf," ",buf2," ")) ; construct 1st part of info string
mov buf2, ptr$(buffer2)
lea eax, avl
invoke StrFormatByteSize64,[eax], [eax+4], buf2, 256 ; format the available space data
mov pbuf, lcase$(cat$(pbuf,chr$(9),buf2)) ; append 2nd part of string
print pbuf,13,10 ; display the line of information
.else
print lcase$(pbuf)," No Media Present",13,10
jmp @F
.endif
@@:
rol edi, 1 ; shift bit left to test next drive
add cnt, 1 ; increment counter
add drv, 1 ; increment drive
cmp cnt, 26 ; loop through 26 possible
jne lp
; -----------------------------------------------------------------------
pop edi
pop esi
pop ebx
ret
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
df.exe works fine on my Windows Xp Pro Sp3 system :U
It runs smoothly but it clutters:
Media type Drv Size Free
========== === ==== ====
HDD partition c:\ 141 gb 27.2 gb
HDD partition d:\ 7.08 gb 892 mb
CD/DVD drive e:\ No Media Present
CD/DVD drive f:\ 660 mb 0 bytes
It is OK under Windows7 Ultimate 64bit,
but I can't see my Snow Leopard's partitions... :wink
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
c:\My Documents\asm\df.exe
Media type Drv Size Free
========== === ==== ====
Removable media a:\ No Media Present
HDD partition c:\ 127 gb 94.2 gb
HDD partition d:\ 69.2 gb 15.0 gb
HDD partition e:\ 54.2 gb 19.4 gb
HDD partition f:\ 264 gb 239 gb
HDD partition g:\ 1.36 tb 1.01 tb
CD/DVD drive i:\ 480 kb 0 bytes
c:\My Documents\asm>
Nice one but noticed that is returns "No Media Present" for my UNIX partition (Or maybe I really didnt format it and windows msg is right I forget how far I got with setup - new drive)
(Just FYI I have no need of fix)
It uses GetDiskFreeSpaceEx ,so with some googling I found this :
http://www.winasm.net/forum/index.php?showtopic=2224&st=40
QuoteFAT, FAT32, NTFS, CDFS, UDFS, supports Floppy, ZIP , Fixed disks, USB Memory Storage Devices, Ram Disk, CD-ROM/CDRW/CD-DVD disks, Networked Storage Shares.
I guess that's what is supported, UNIX filesystems ... not so much :bdg
oex,
I did not really expect it to recognise a non-Windows partition as it uses the API that BlackVortex mentioned and while the operating system can recognise if there is a non-Windows partition on one of the disks I doubt that the API is designed to read any of the Linux disk formats that are available.