Here is a way to get the number of sectors on a disk and thus it's total capacity and last accessible sector.
It requires the bios grub4dos program from the grubutils pack.
echo xxxxxxxxxxxxxxxxxxxxxxxxx > (md)0x300+1 # set buffer to 0 in case bios call fails write 0x60010 0 # get number of sectors from INT 13h AH=48 into memory at DS:SI+10h - edx=80h is hard disk 0, 81h would be hard disk 1 /bios int=0x13 eax=0x4800 edx=0x80 ds=0x6000 esi=0x0 > nul read 0x60010 > nul set /A END=%@retval%-1 > nul if %END%<=0 echo Drive too big! && exit
Note that END will be the last accessible sector (LBA number) - e.g. if the disk had only 1 sector then the last accessible sector would be LBA 0.
If the bios call fails, END will be -1.
If the drive is very large, then although read returns a 64-bit number, set /A only works with signed 32-bit numbers, so with large USB drives of over 7FFFFFFF sectors (=1TB), END will be negative! You need to be careful when doing any maths if that is the case - I just give up if the drive is over 1TB!
DS:EDI = 6000:0 which is 0x60000 in memory. This is equivalent to (md)0x300 and is a safe work area to use within grub4dos.
The BIOS call int13 AH=48h places various values into memory at this address, with the number of sectors at offset 10h.
[Edit: 1st line added as bios call fails without it]
[Edit2: Use write 0x60000 0x42 instead of the echo xxx line would be more correct as the buffer size needs to be specified before the call is made]
Edited by steve6375, 15 March 2016 - 09:53 AM.