Anyhow, I want to make the filesystem generator program as fool-resistant as I can, which includes preventing the user from entering combinations of parameters that can’t work. In the process, I’m stumbling over what would seem to be a simple math problem. So I am looking for some help.
I'm trying to work out how to apportion storage space between data objects (“objects”) and a bitmap that tracks them. Both objects and bitmap are stored in 1024 byte fixed-size blocks. The objects are 128 bytes each, hence 8 can fit in a block. There is a one-for-one correspondence between a bit in the bitmap and an object.
The number of blocks required to store a given number of objects would be:
Code: Select all
OB = OJ ÷ 8 + ((OJ % 8) > 0)...in which...
- OJ = number of objects
OB = number of object blocks
% = modulus operator
Given that there are 8192 bits in a 1024-byte block, the required number of bitmap blocks for a given number of objects would be:
Code: Select all
BB = OJ ÷ r + ((OJ % r) > 0)...in which...
- BB = number of bitmap blocks
r = 8192 (bits in a block)
Therefore, storage requirements for a given number of objects would be:
Code: Select all
S = OB + BBin which:
- S = required blocks
All arithmetic operations are on unsigned integers. Division behaves as INT(OJ / r) would in BASIC. My division function also reports if the remainder is non-zero, which makes it easy to determine if the result of an expression such as (OJ % r) > 0 is true or false.
The puzzle is this: I already know the value of S—it is indirectly determine by the filesystem size entered by the user—and ultimately wish to solve for OJ. Given that an immutable relationship between OJ and BB is defined in the second equation, you'd think this would be straightforward. It isn't...at least for me. Any suggestions?
Thanks!