[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Easy DOSFS question



Hello Everyone,

I've been busy over the last couple of months and unfortunately have been unable to contribute.  However, I can offer some snippets
of working code we have used in other projects.  As you can see below, Thomas is quite right, it is simply a walk of the free
cluster list in the FAT.  The total space can be obtained from the boot parameter block.

[Excuse the RDCF-isms, but the code is fairly self-explanatory.  It also suffers from the 2GB limit, sorry.  You probably want to
report back size in logical blocks, and have a way of getting the block size, though it is generally 512 bytes.]

This information should be available to the filesystem driver.  One could add an IOCTL or something.

Hope this can help.

Best Regards,

-bogdan


/*************************************************************************
 Function: rdcf_free_space
 */
//! Return the amount of free space in the file system.
/*! \ingroup rdcf2
This routine Return the amount of free space in the file system, in bytes.

\return The amount of free space.
*************************************************************************/
long int rdcf_free_space(struct rdcf *f      /*!< A pointer to the FCB. */    
                        )
{
  rdcf_cluster_t cluster;
  rdcf_size_t number_of_empty_clusters = 0;
  
  //if ((f->result=setjmp(f->error)) != 0) return (long)(f->result);
  error_init(f,long);

  initialize_fcb(f, NULL);
  
  for (cluster = 2; cluster <= f->maximum_cluster_number; cluster++)
  {
    if (FAT_entry(f, cluster) == EMPTY_CLUSTER) number_of_empty_clusters++;
  }
  
  f->file.size = number_of_empty_clusters * (f->sectors_per_cluster * SECTOR_SIZE);
  
  return (long)(f->file.size);
}


/*************************************************************************
 Function: rdcf_total_space
 */
//! Return the total amount of space in the file system.
/*! \ingroup rdcf2
This routine returns the total amount of space in the file system, in bytes.

\return The bytes in the filesystem.
*************************************************************************/
long int rdcf_total_space(struct rdcf *f      /*!< A pointer to the FCB. */    
                        )
{
//  rdcf_cluster_t cluster;
//  rdcf_size_t number_of_empty_clusters = 0;
  
  //if ((f->result=setjmp(f->error)) != 0) return (long)(f->result);
  error_init(f,long);

  initialize_fcb(f, NULL);
  
  
  return (long)(f->maximum_cluster_number-2) * (f->sectors_per_cluster * SECTOR_SIZE);
}



On Thursday, November 25, 2004 9:24 AM, Thomas Doerfler wrote:

> Hi,
> 
> the basic task seems not so complicated: Any
> unallocated cluster hast the value ZERO in the FAT.
> So to get the number of free clusters, just scan
> through the FAT and count the ZERO clusters.
> 
> The info in FS_Info is not SO reliable, and might
> not be available anyhow.
> 
> wkr,
> Thomas.
> 
> 
>> Hi all,
>> 
>> Actually I'm not sure and unfortunately have no time right now to
>> investigate the issue in more details but whether the free_cls field
>> of the structure fat_vol_s may be usefull to implement the required
>> functionality? 
>> 
>> 
>> Regards,
>> 		Eugeny
>> 
>> Victor V. Vengerov wrote:
>>> Thomas Doerfler wrote:
>>> 
>>>> Hi Etienne,
>>>> 
>>>> 
>>>> 
>>>>> Hi Thomas,
>>>>> Is there a way to get the free space available on a DOSFS mount?
>>>>> 
>>>> 
>>>> 
>>>> Easy answer: no :-(
>>>> 
>>>> Basically, you would have to walk through the FAT to find things
>>>> out. And there is no call to do things like that right now.
>>>> 
>>>> 
>>> At start of day, you may open dummy file and make binary search of
>>> maximum free space available by calling seek(,,SEEK_SET), assuming
>>> that no other file system activity happens. But this is kludge.
>>> 
>>> Victor
>>> 
>>> 
>> 
> 
> --------------------------------------------
> IMD Ingenieurbuero fuer Microcomputertechnik
> Thomas Doerfler           Herbststrasse 8
> D-82178 Puchheim          Germany
> email:    Thomas.Doerfler at imd-systems.de
> PGP public key available at: http://www.imd- systems.de/pgp_keys.htm