Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Correct cluster size
Message
 
À
20/08/2001 09:45:37
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00546141
Message ID:
00546248
Vues:
20
>>I know. GetDiskFreeSpace() returns the bytes per sector and the sectors per cluster, in addition to other information.
>
>OK, thank you very much. I am new to Win-API; and I thought: GetDiskFreeSpace() only gives me the free disk space.
>
>>
>>>I wrote a small utility, which I called "Who's gobbling my hard disk", that totals file sizes for each folder. For accurate information, for a specific disk, I need the cluster size. For instance, on my current "C:" drive, a 100-byte batch-file actually uses 4 KB, because that is the cluster size I am using.
>>>
>>>Since sys(2022) isn't trustworthy (see my original message), I gave the user the option of selecting the cluster size.
>>
>>How?
>
>A combobox on the main form. The options are: "Auto" (i.e., autodetect), "512 bytes", "1 KB", "2 KB", ..., "32 KB" (all powers of 2 in between).

But how are you going to actually change the file system? You can't merely specify a cluster size for a single file. It's a disk wide change and cannot be easily controlled.

>>The only reliable way to do it across all Win32 platform and file systems is to write get the amount of free space, write a small temporary file, and get the amount of free space afterwards.
>
>I disagree: this is not reliable. Another user or process may increase or decrease the free disk space in the meantime. Unless I create a thousand small temp files, and round to the nearest power of 2...

You're not going to find anything better. Networked drives are extremely problematical at best, and you've no way of interfacing with the network OS. Each user has an allocation, however, and that's what's reported as free space. As long as there are no pending writes in the cache, you should be OK. However, pending writes do pose a problem, since there's no way to control when the buffers get flushed.

>>FWIW, here's the GetDiskFreeSpace() syntax:
>...
>
>
>OK, I'll check into it. Thanks again.
>
>>On a Win2K box it accurately reports a 4K cluster size. On a Win98SE box, it reports 32K, when in reality the cluster size is 4K.
>
>Perhaps this is the reason VFP reports the wrong cluster size! If that is the case, unfortunately, there is no additional benefit in using the Win-API. BTW, I did get correct information (using the VFP function) on a machine with Windows NT 4. The problem is, precisely, on machines with Windows 98. And the problem seems to appear only on FAT32 partitions.

It could be. However, be aware that VFP 6.0 cannot through its internal functions get the correctly amount of free or total disk space when these values exceed 2 gb. The reason for this is that it's accessing the GetDiskFreeSpace() function. In order to return the correct amount, the programmer has to access GetDiskFreeSpaceEx(). I've an FAQ here that explains how to do this. Additionally, there's no way to accurately return the information prior to Win95 OSR2 since GetDiskFreeSpaceEx() wasn't available prior to that release. Determining whether or not the function is available is shown in the FAQ.

>Is there an API function to report how much space is "really used" (round up to the nearest cluster) by a file? 'Cause I do get correct information when I check a file's properties in the Explorer.
>
No there isn't. If I recall correctly, information regarding the cluster size is stored by the ROM BIOS. Windows probably loads this information on startup. There's no way via the API to interface with the ROM BIOS interrupt functions to retrieve this information.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform