All Forums
 Microsoft Windows CE
 CE Flash, CF and PCMCIA
 Enumerating mount points w/4.2 .NET
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

bincbom

23 Posts

Posted - 01 Oct 2003 :  16:25:19  Show Profile  Email Poster
Hello,

How do you enumerate flash mount points in 4.2 .NET? WINCE 3.0 provided
the FindFirstFlashCard/FindNextFlashCard API's. These seem to be gone in WINCE 4.2. Please help!!

craig vanderborgh
voxware incorporated

ctacke

877 Posts

Posted - 01 Oct 2003 :  17:56:58  Show Profile  Email Poster
Actually FindFirstFlashCard/FindNextFlashCard are Pocket PC specific APIs.

Probably the simplest way to get similar functionality is to enumerate all top-level folders looking for temporary ones. Something like this:


WIN32_FIND_DATA fd;
HANDLE hFile;

hFile = FindFirstFile(_T("*"), &fd);

do
{
if(hFile == INVALID_HANDLE_VALUE)
break;

if((fd.dwFileAttributes & (FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_DIRECTORY))
== (FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_DIRECTORY) )
{
RETAILMSG(TRUE, (_T("Removable media at %s\r\n"), fd.cFileName));
}
} while(FindNextFile(hFile, &fd));


The downside here is that any mountable directories (like the FlashFX Disk folder on ADS devices) will show up.

Also some of the special folders (like \NETWORK) will also show up, though they could be filtered using calls to SHGetSpecialFolderPath().
Go to Top of Page

bincbom

23 Posts

Posted - 01 Oct 2003 :  19:34:44  Show Profile  Email Poster
Chris, thank you so much for the suggestion. This works well, and we now
have a complete "df" implementation that works across wince 3.0/4.x. I have
incorporated the source; hopefully it will be of some use to you or
somebody else.

df.c - a disk utilization utility like the one on linux, for GNUWINCE

#include
#include

#include
#include
#include

#define MAXMOUNTS 10
#define BUFSIZE 128

static void dfpath(char *path);
static void heading();

void
usage()
{
  fprintf(stderr, "Usage: df [path]\n");
  exit(1);
}

int
main(int argc, char **argv)
{
  int c, i, j;
  int res;
  char buf[BUFSIZE];
  wchar_t bufw[BUFSIZE];
  BOOL mntFound;
  int mntCnt;
  HANDLE hnd;

  WIN32_FIND_DATAW fdw;
  char mounts[MAXMOUNTS][BUFSIZE];

  switch (argc) {
  case 1:
    mbstowcs(bufw, "*", BUFSIZE);
    hnd = FindFirstFileW(bufw, &fdw);

    mntCnt = 0;
    do {
      if (hnd == INVALID_HANDLE_VALUE)
      break;

      if ((fdw.dwFileAttributes & (FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_DIRECTORY)) ==
          (FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_DIRECTORY)) {
        wcstombs(buf, fdw.cFileName, BUFSIZE);

        /* Here we must eliminate things returned by the FindFile API
         * that are completely irrelevant to us. */
        if (strcasecmp(buf, "NETWORK") == 0 || strcasecmp(buf, "RELEASE") == 0)
          continue;
        strcpy(mounts[mntCnt], "/");
        strcat(mounts[mntCnt], buf);
        mntCnt++;
      }
    } while(FindNextFileW(hnd, &fdw));

    /* Add the object store in explicitly here */
    strcpy(mounts[mntCnt], "/");
    mntCnt++;

    heading();
    for (i = 0; i < mntCnt; i++) {
      dfpath(mounts[i]);
    }
    break;
  case 2:
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
      usage();
    } else {
      heading();
      dfpath(argv[1]);
    }
    break;
  default:
    usage();
  }
  exit(0);
}

static void
heading()
{
  fprintf(stdout, "Filesystem 1k-blocks Used Available Use%%\n");
}

static void
dfpath(char *path)
{
  QWORD freeBytes;
  QWORD totalBytes;
  QWORD totalFreeBytes;
  int total, used, avail, pct;
  wchar_t wpath[BUFSIZE];
  char fmtbuf[BUFSIZE];
  char *p;

  if (path == NULL)
    usage();

  mbstowcs(wpath, path, 256);

  if (GetDiskFreeSpaceExW(wpath, &freeBytes, &totalBytes, &totalFreeBytes) == 0) {
    fprintf(stderr, "GetDiskFreeSpace: Error %d\n", GetLastError());
    exit(1);
  }

  total = (int)(totalBytes / 1024LL);
  avail = (int)(freeBytes / 1024LL);
  used = total - avail;
  pct = (int) (used/(float)total * 100.);

  fprintf(stdout, "%-16s%14d %9d %9d%4d%%\n", path, total, used, avail, pct);

  fflush(stdout);
}
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000