/** * Returns the mounted root file systems (UNICODE format). Each root must end * with '/' character * @param roots buffer to store the UNICODE string containing * currently mounted roots separated by '\n' character * @param rootsLen available buffer size (maximum number of javacall_utf16 * symbols to be stored) * @return <tt>JAVACALL_OK</tt> on success, * <tt>JAVACALL_FAIL</tt> otherwise */ javacall_result javacall_fileconnection_get_mounted_roots(javacall_utf16* /* OUT */ roots, int rootsLen) { unsigned long driveMask; unsigned short ch = 'A'; int index = 0; for(driveMask = _getdrives(); driveMask; driveMask >>= 1) { if(driveMask & 1) { if(index > 0 && index > rootsLen - PREFIX_CHARS - 5 || rootsLen < PREFIX_CHARS + 4) { javacall_print("Error: javacall_fileconnection_get_mounted_roots(), buffer is too small\n"); return JAVACALL_FAIL; } if(index > 0) { roots[index++] = '\n'; } memcpy(roots + index, DRIVE_PREFIX, PREFIX_SIZE); index += PREFIX_CHARS; roots[index++] = ch; roots[index++] = ':'; /* roots must be in URL format, so '/' separator is used */ roots[index++] = '/'; } ch++; } roots[index] = 0; return JAVACALL_OK; }
/** * Returns the localized names for mounted root file systems (UNICODE format) * @param roots buffer to store the UNICODE string containing localized names * of currently mounted roots separated by ';' character * @param rootsLen available buffer size (maximum number of javacall_utf16 * symbols to be stored) * @return <tt>JAVACALL_OK</tt> on success, * <tt>JAVACALL_FAIL</tt> otherwise */ javacall_result javacall_fileconnection_get_localized_mounted_roots(javacall_utf16* /* OUT */ roots, int rootsLen) { unsigned long driveMask; unsigned short ch = 'A'; int index = 0; for(driveMask = _getdrives(); driveMask; driveMask >>= 1) { if(driveMask & 1) { if(index > 0 && index > rootsLen - 5 - (int)(sizeof(localized_root_prefix) / sizeof(javacall_utf16) - 1) || rootsLen < 4 + (sizeof(localized_root_prefix) / sizeof(javacall_utf16) - 1)) { javacall_print("Error: javacall_fileconnection_get_localized_mounted_roots(), buffer is too small\n"); return JAVACALL_FAIL; } if(index > 0) { roots[index++] = ';'; } memcpy(roots + index, localized_root_prefix, sizeof(localized_root_prefix)); index += sizeof(localized_root_prefix) / sizeof(javacall_utf16) - 1; roots[index++] = ch; roots[index++] = ':'; roots[index++] = javacall_get_file_separator(); } ch++; } roots[index] = 0; return JAVACALL_OK; }
/** * Callback function for mount_timer event. Checks if any drives were * mounted or unmounted, calls javanotify_file_root_changed() if it occured. */ static void mount_timer_callback(javacall_handle handle) { unsigned long newRoots = _getdrives(); if(newRoots != oldRoots) { oldRoots = newRoots; javanotify_fileconnection_root_changed(); } }
int main() { // get the drives bit masks...1 is available, 0 is not available A = least significant bit... ULONG DriveMask = _getdrives(); // if something wrong if(DriveMask == 0) printf("_getdrives() failed with failure code: %d\n", GetLastError()); else { printf("This machine has the following logical drives:\n"); while (DriveMask) { // list all the drives... if(DriveMask & 1) printf(mydrives); else printf("_ "); // go to the next drive strings with one space //++mydrives[1]; // ++(*(mydrives+1)) ++(*(mydrives+1)); // shift the bit masks binary to the right and repeat DriveMask >>= 1; } printf("\n"); } return 0; }
/** * Makes all the required initializations for JSR 75 FileConnection * @return <tt>JAVACALL_OK</tt> if operation completed successfully * <tt>JAVACALL_FAIL</tt> if an error occured or feature is not supported */ javacall_result javacall_fileconnection_init(void) { javacall_result res; oldRoots = _getdrives(); res = javacall_time_initialize_timer(1000, JAVACALL_TRUE, mount_timer_callback, &mount_timer); return res; }
int main(int argc, char* argv[]) { ULONG uDriveMask = _getdrives(); if (uDriveMask == 0) { printf( "_getdrives() failed with failure code: %d\n", GetLastError()); } else { printf("The following logical drives are being used:\n"); while (uDriveMask) { if (uDriveMask & 1) printf(g_szDrvMsg); ++g_szDrvMsg[0]; uDriveMask >>= 1; } } }
static int AccessFile ( char* path, char* pathbuf, int len_pathbuf, char** pathret) { unsigned long drives; int i, len; char* drive; char buf[MAX_PATH]; char* bufp; /* just try the "raw" name first and see if it works */ if (access_file (path, pathbuf, len_pathbuf, pathret)) return 1; #if defined(WIN32) && defined(__MINGW32__) /* don't try others */ return 0; #endif /* try the places set in the environment */ drive = getenv ("_XBASEDRIVE"); #ifdef __UNIXOS2__ if (!drive) drive = getenv ("X11ROOT"); #endif if (!drive) drive = "C:"; len = strlen (drive) + strlen (path); bufp = XtStackAlloc (len + 1, buf); strcpy (bufp, drive); strcat (bufp, path); if (access_file (bufp, pathbuf, len_pathbuf, pathret)) { XtStackFree (bufp, buf); return 1; } #ifndef __UNIXOS2__ /* one last place to look */ drive = getenv ("HOMEDRIVE"); if (drive) { len = strlen (drive) + strlen (path); bufp = XtStackAlloc (len + 1, buf); strcpy (bufp, drive); strcat (bufp, path); if (access_file (bufp, pathbuf, len_pathbuf, pathret)) { XtStackFree (bufp, buf); return 1; } } /* does OS/2 (with or with gcc-emx) have getdrives()? */ /* tried everywhere else, go fishing */ drives = _getdrives (); #define C_DRIVE ('C' - 'A') #define Z_DRIVE ('Z' - 'A') for (i = C_DRIVE; i <= Z_DRIVE; i++) { /* don't check on A: or B: */ if ((1 << i) & drives) { len = 2 + strlen (path); bufp = XtStackAlloc (len + 1, buf); *bufp = 'A' + i; *(bufp + 1) = ':'; *(bufp + 2) = '\0'; strcat (bufp, path); if (access_file (bufp, pathbuf, len_pathbuf, pathret)) { XtStackFree (bufp, buf); return 1; } } } #endif return 0; }
unsigned long ossgetdisks(void) { return _getdrives(); }