This is disksize, a tool for determining the sizes of disks and files.
It has been written for learning how to non-sequentially access raw disks
beyond the limit of LONG_MAX (== 2^31-1 == 2147483647 ~ 2047 M).

The usage is:  disksize [options] file(s), as to be expected.


It operates as follows:

1. After opening the file read-only, its offset is tried to set to its end by
size=lseek(fd,0,SEEK_END). If size is zero, the file is a usual one of zero
size OR a special file like a harddisk. If size > 0, we're ready.

2. Unfortunately, for harddisks zero is returned. Thus, if size == 0, the file
is a usual one of zero size OR a special file like a harddisk which is checked
by reading the first byte of the file by nbr=read(fd,buf,1). If nbr == 0, we're
ready: the file is a normal one of zero size.

3. If nbr == 1, the file is a special one. It's size is determined iterative:
size_min= 0;
size_max= SIZE_MAX;	/* run disksize -V for its value */
while( size_max > size_min )
{
  offset= ( size_min + size_max ) /2;
  lseek( fd, offset, SEEK_SET )
  if( read(fd,buf,1) == 0 )  size_max= offset;
  else                       size_min= offset+1;
}
size= size_max;		/* == size_min */
To be compatible with CD-ROMs, since v0.31, if read() returns -1 this is
treated as zero.


When determining the size of a raw disk, one might expect that the result
returned by disksize is just CYL*HDS*SEC*512, where CYL, HDS and SEC stand
for the number of cylinders, heads and sectors per track, respectively. This
is NOT the case! Since modern harddisks only talk about their LOGICAL CHS-
value nobody knows their physical layout (think about 255 heads). Think of
the disksize as a given value and try to fit it into 255 heads and 63 sectors
per track. Obviously, the number of cylinders will most likely not be an
integer number. Thus, as long as disksize returns a value out of larger
or equal to CYL*HDS*SEC*512 but less than (CYL+1)*HDS*SEC*512, you can
believe in its statement. -- And I'm shure that running a
diskerase -o CYL*HDS*SEC*512
will not destroy any (file system) data on your disk, give it a try :-).


Since v0.31, this tool is called disksize. Until v0.30 it was called sizeof.


Disksize is one of a bunch of simple disk utilities (named disk*), which
should be available at the sunsite ftp site (sunsite.unc.edu), probably in
pub/Linux/utils/disk-management.
