Author |
Topic |
|
bincbom
23 Posts |
Posted - 01 Oct 2003 : 16:25:19
|
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
|
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(). |
|
|
bincbom
23 Posts |
Posted - 01 Oct 2003 : 19:34:44
|
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); }
|
|
|
|
Topic |
|
|
|