'The array's index used ([x]) to get the free blocks and the block size was obtained by studying the ouput of the commands used below
IF sFilesystem = "Ext2" OR sFilesystem = "Ext3" THEN
SHELL "dumpe2fs -h " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[13], RInStr(arrTemp[13], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[16], RInStr(arrTemp[16], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "XFS" THEN
SHELL "xfs_db -c 'sb 0' -c 'print blocksize' -c 'print fdblocks' -r " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[1], RInStr(arrTemp[1], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[0], RInStr(arrTemp[0], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "ReiserFS" THEN
SHELL "debugreiserfs " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(arrTemp[6], RInStr(arrTemp[6], Space$(1))))
sBlockSize = Trim$(Mid$(arrTemp[5], RInStr(arrTemp[5], Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "JFS" THEN
SHELL "echo dm | jfs_debugfs " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
sFreeBlocks = Trim$(Mid$(Left$(arrTemp[8], RInStr(arrTemp[8], "[") - 1), InStr(arrTemp[8], ":") + 1))
sBlockSize = Trim$(Mid$(arrTemp[2], RInStr(arrTemp[2], Space$(1))))
iFreeBytes = HexToLong(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "FAT12" OR sFilesystem = "FAT16" OR sFilesystem = "FAT32" THEN 'Who even uses FAT12 on today's hard-drives anyway?!
SHELL "dosfsck -v " & sDevice TO sTemp 'The "-a" switch should also be used to automaticaly repair a FAT partition, but that can take ages...lets see how well it works without it.
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
'Debug
' FOR i = 0 TO arrTemp.Length - 1
' PRINT arrTemp[i]
' NEXT
'Reuse sTemp, can't get sFreeBlocks in one go
sTemp = Trim$(Mid$(Left$(arrTemp[arrTemp.Length - 1], RInStr(arrTemp[arrTemp.Length - 1], "/") - 1), InStr(arrTemp[arrTemp.Length - 1], ",") + 1))
'PRINT sTemp
sTemp2 = Trim$(Mid$(Left$(arrTemp[arrTemp.Length - 1], RInStr(arrTemp[arrTemp.Length - 1], Space$(1))), RInStr(arrTemp[arrTemp.Length - 1], "/") + 1))
'PRINT sTemp2
sFreeBlocks = Str(CLng(Val(sTemp2) - CLng(Val(sTemp))))
sBlockSize = Trim$(Left$(Trim$(arrTemp[7]), InStr(Trim$(arrTemp[7]), Space$(1))))
iFreeBytes = CLng(sFreeBlocks) * CLng(sBlockSize)
ELSE IF sFilesystem = "NTFS" THEN
SHELL "ntfsresize --info --force --no-progress-bar " & sDevice TO sTemp
sTemp = Trim$(sTemp)
arrTemp = Split(sTemp, Chr$(10))
'It would be a lot easier to use an expression in the output of ntfsresize to identify the number of free bytes, but that is not i18n ready!
'So "chomp" away portions of the string until the first integer is found (this will be the free space value)
'PRINT arrTemp[10]
sTemp = arrTemp[10]
WHILE Len(sTemp) > 0
sTemp2 = Trim$(Left$(sTemp, InStr(sTemp, Space$(1))))
IF IsInteger(Val(sTemp2)) OR IsLong(Val(sTemp2)) THEN
sUsedBlocks = CLng(Val(sTemp2))
BREAK
ELSE
sTemp = Trim$(Mid$(sTemp, InStr(sTemp, Space$(1))))
ENDIF
WEND
'sBlockSize = Trim$(Mid$(Left$(arrTemp[3], RInStr(arrTemp[3], Space$(1))), InStr(arrTemp[3], ":") + 1))
sTemp = Trim$(Mid$(arrTemp[5], InStr(arrTemp[5], ":") + 1)) 'Get total partition size
sTemp2 = Trim$(Left(sTemp, InStr(sTemp, Space$(1))))
iFreeBytes = CLng(sTemp2) - CLng(sUsedBlocks)
ELSE
iFreeBytes = 0
ENDIF
RETURN iFreeBytes
END