hb_DiskSpace() Shows Incorrect Value

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

melliott42
Posts: 119
Joined: Wed Feb 18, 2009 2:14 pm

hb_DiskSpace() Shows Incorrect Value

Post by melliott42 »

Hello,

In Windows XP and 7 if I issue the function hb_DiskSpace('C:', HB_DISK_FREE) the value returned is not the same found in the Windows GUI interfaces.

Which one is correct?

If it is Windows what can we do to return the right value?

Thanks,

Michael
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by esgici »

melliott42 wrote: Which one is correct?
If it is Windows what can we do to return the right value?
What is right value and where is their source?
Free disk space reported by "Disk Properties"
Free disk space reported by "Disk Properties"
ByDiskProperties.jpg (9.19 KiB) Viewed 5390 times
Free disk space acquired via DOS (dir) command
Free disk space acquired via DOS (dir) command
ViaDOSComand.jpg (4.34 KiB) Viewed 5390 times
Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5481
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by Rathinagiri »

There are two sizes for each file.

The actual file size and the size on disk. Whether that might be the cause of this problem?

Just my two cents...
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
melliott42
Posts: 119
Joined: Wed Feb 18, 2009 2:14 pm

Re: hb_DiskSpace() Shows Incorrect Value

Post by melliott42 »

Thanks for pointing this out guys.
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by swapan »

Really interesting observation!
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by esgici »

rathinagiri wrote: There are two sizes for each file.
The actual file size and the size on disk.
swapan wrote:Really interesting observation!
FSizeTest.jpg
FSizeTest.jpg (28.94 KiB) Viewed 5323 times
If you have a diskette drive on your PC, you can do this test:

Code: Select all

copy con test1.txt   // I'll write someting on console, save it to a file name is : test1.txt
1^Z                  // write only one character ("1") and than press ^Z (EOF) (or press F6)
                     // this terminate writing and save the file
dir                  // show me list of files on this folder ( A:\ )

...                  // some info about disk  
...                   

06.08.2010    14:58       1 test1.txt
                 1 file            1 byte
                 0 folder  1.457.152 bytes free           
And than repete :

Code: Select all

copy con test2.txt
1^Z               
                  
dir               

...                  // some info about disk  
...                   

06.08.2010    14:58       1 test1.txt
06.08.2010    14:58       1 test2.txt
                 2 file            2 byte
                 0 folder  1.456.640 bytes free           
File size values ( 1 byte for each ) is actual file sizes.
1.457.152 - 1.456.640 = 512 is space occupied on disk by each 1 byte file.

This is because OS allocates disk space to file as 512 byte unites per request. FE if file size is 513 byte, allocated space will be 1024 bytes.

This is for FAT16 file system and for relatively small media (diskette in our example). While media grown, this allocation unit size too will be greater.

In NTFS, file allocation system is totally different and more complicated.


Regards

--

Esgici

PS: This little information dedicated to who search always a "tool" for every need. ;)
Last edited by esgici on Fri Aug 06, 2010 1:01 pm, edited 1 time in total.
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5481
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by Rathinagiri »

This is called the cluster size. :)

Thanks Esgici for the efforts.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by esgici »

rathinagiri wrote:This is called the cluster size. :)
Yes, "allocation unit" is called sometime "cluster";

thanks Rathi

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: hb_DiskSpace() Shows Incorrect Value

Post by esgici »

BUT !

"Cluster" concept doesn't reason of difference between DOS command result and "Disk Properties" report of Windows.
DisketteProperties.jpg
DisketteProperties.jpg (10.09 KiB) Viewed 5313 times
Sadly, I don't know this reason :(

Does anyone know ?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: hb_DiskSpace() Shows Incorrect Value

Post by sudip »

Hello,

IMHO, dir command calculates SIZE OF THE FILE and Disk property calculates SIZE OF THE FILE ON THE DISK (ie., amount of disk space being occupied).

So, what's the difference?

Size is the actual size of the file in bytes.
Size on disk is the actual amount of space being take up on the disk.
The disk is broken down into tracks and sectors.
So, if your sector size is 512 bytes and your file is actually 513 bytes, the size on disk will be 1024bytes because it is occupying two sectors.
(taken from http://answers.yahoo.com/question/index ... 416AAzMmNu)
With best regards,
Sudip
Post Reply