[Gambas-user] How to determine the order of magnitude of a Long variable
Bruce
adamnt42 at gmail.com
Thu May 13 16:26:46 CEST 2021
I need to determine how many blocks (sectors, writeable chunks,
whatever) are available on a USB "drive" (stick, sdd, whatever).
I can get a reasonably accurate value Shell'ing the lsblk command.
However the value could be anywhere between 0 and the total number of
usable blocks on the device (i.e. the "formatted size").
In order to determine whether the data I am about to write to the device
will fit I need to know the order of magnitude of these free blocks -
kB, mB, gB, TB, etc etc.
This is because the utilities that do the writing wont give the size of
the data in formats other than the so-called "human-readable format" e.g
3.25G or 4GB or any number of other variants, which may by the way be
based on 1024 or 1000 byte scales. (Grrr!)
In that first case, that 3.25G could be any number of bytes between (3.0
gigabytes)+1 and (3.5 gigabytes)-1 but that might not fit onto the drive
if it tries to write into the "last block on the device".
My goal, in case you are wondering, is to keep the maximum number of
daily backups as possible on the drive and the Gambas project will be
run by a cron job (so there is np user interaction).
To be safe I thought I'd take the biggest "about to write" size i.e the
smalllest scale (I think) convert that to a "Required Blocks" value and
compare it to the actual AvailableBlocks. This does not work for various
mathematical reasons. So I need to do it the other way around i.e. is
the number of AvailableBlocks absolutely larger than the needed blocks.
I have searched the internet for something like this with poor results.
So in desparation... does anyone have any idea how to get a reliable
comparison?
tia
bruce
More information about the User
mailing list