Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Retrieving file system statistics using IFileSystem2

To retrieve file system statistics, an application needs to do the following:

  1. Call ISHELL_CreateInstance() to create an instance of the IFileSystem2 interface.
  2. Call IFileSystem2_StatVFS() to obtain information about the files and directories that are present in the application directory or to determine the amount of free space available in the file system.

The following sample code shows how to obtain free space information:

#include "AEEFileSystem2.bid"
#include "AEEIFileSystem2.h"

   //   Usage:  IFileSystem2_StatVFS

   //   IFileSystem2_StatVFS returns the amount of free space available
   //  in the file system.  Here we use this function to retrieve the
   //  number of free and total file system bytes and echo the values
   //  back to the screen.

   IFileSystem2 * pIFileSystem2=NULL;
   FSStatVFSEx buf;

   if (nRet=ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_FileSystem2,
            (void **)&pIFileSystem2)){
      DBGPRINTF("%d=create(AEECLSID_FileSystem2)", nRet);
      goto bail;
   }

   //  Get file system information.  Note that the amount of free space is the
   //  return value of this function, and the total file system size is passed
   //  back in the function's second parameter.
   if(nRet=IFileSystem2_StatVFS(pIFileSystem2, FS_APP_CLASSID, &buf, 
            sizeof(FSStatVFSEx) )){
      DBGPRINTF("%d=IFileSystem2_StatVFS()", nRet);
      goto bail;
   }

   //  Echo amount of free space
   DBGPRINTF("File Space Avail:%u bytes", buf.dwBlocksAvail * buf.dwBlocks);

   //  Echo total file system size
   DBGPRINTF("Total File Sys Size: %u bytes",buf.qwMaxFSSpace);

bail:
   if (pIFileSystem2){
      IFileSystem2_Release(pIFileSystem2);
   }