I don't know how to get the total used.
To get the total size, use the G-P command and check bytes 27-29 returned. These are number of 512-byte sectors. Also, I believe this is unformatted size. The formatted size (available to user for storing data) will be less.
Also, SD2IEC devices like uIEC also support G-P command, but because they can be larger than 16MB, they report the total in bytes 22-25. Same as before, it is the number of 512-byte sectors, and it is the unformatted (raw) size.
The G-P command is issued like:
Where is n is the partition number. I don't own a CMD-HD, but I believe n should be 1 to X (where X is total number of partitions). For SD2IEC device, n is 0 to X-1.
Device will return 31 bytes of data:
Byte 0: Partition type (1=native, 2~5=15x1 disk)
Byte 1: 0 (you probably got disk error if this is not 0)
Byte 2: Partition number
Byte 3~18: Partition name
Byte 19~21: Starting sector (high byte first)
Byte 22~25: Total size (SD2IEC) high byte first
Byte 26: Reserved
Byte 27~29: Total size (CMD-HD) high byte first
Byte 30: 13 (return)
I've attached a simple program I wrote and tested with SD2IEC device, uIEC. It is a BASIC program. I tested in C128 mode, but it should work on other Commodore computers with a little change (remove BANK command, and maybe change RAM address used).