< prev index next >

src/java.base/windows/native/libjava/WinNTFileSystem_md.c

Print this page

 394                                    &lpf);
 395     if ((retLen == BUFSIZE - 1 || retLen == BUFSIZE - 2) &&
 396         buf[0] == L'\\' && buf[1] == L'\\' &&
 397         buf[2] == L'.' && buf[3] == L'\\') {
 398         WCHAR* dname = _wcsupr(buf + 4);
 399         if (wcscmp(dname, L"CON") == 0 ||
 400             wcscmp(dname, L"PRN") == 0 ||
 401             wcscmp(dname, L"AUX") == 0 ||
 402             wcscmp(dname, L"NUL") == 0)
 403             return TRUE;
 404         if ((wcsncmp(dname, L"COM", 3) == 0 ||
 405              wcsncmp(dname, L"LPT", 3) == 0) &&
 406             dname[3] - L'0' > 0 &&
 407             dname[3] - L'0' <= 9)
 408             return TRUE;
 409     }
 410     return FALSE;
 411 }
 412 
 413 JNIEXPORT jint JNICALL
 414 Java_java_io_WinNTFileSystem_getBooleanAttributes(JNIEnv *env, jobject this,
 415                                                   jobject file)
 416 {
 417     jint rv = 0;
 418 
 419     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 420     if (pathbuf == NULL)
 421         return rv;
 422     if (!isReservedDeviceNameW(pathbuf)) {
 423         DWORD a = getFinalAttributes(pathbuf);
 424         if (a != INVALID_FILE_ATTRIBUTES) {
 425             rv = (java_io_FileSystem_BA_EXISTS
 426                 | ((a & FILE_ATTRIBUTE_DIRECTORY)
 427                     ? java_io_FileSystem_BA_DIRECTORY
 428                     : java_io_FileSystem_BA_REGULAR)
 429                 | ((a & FILE_ATTRIBUTE_HIDDEN)
 430                     ? java_io_FileSystem_BA_HIDDEN : 0));
 431         }
 432     }
 433     free(pathbuf);
 434     return rv;
 435 }
 436 
 437 
 438 JNIEXPORT jboolean
 439 JNICALL Java_java_io_WinNTFileSystem_checkAccess(JNIEnv *env, jobject this,
 440                                                  jobject file, jint access)
 441 {
 442     DWORD attr;
 443     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 444     if (pathbuf == NULL)
 445         return JNI_FALSE;
 446     attr = GetFileAttributesW(pathbuf);
 447     attr = getFinalAttributesIfReparsePoint(pathbuf, attr);
 448     free(pathbuf);
 449     if (attr == INVALID_FILE_ATTRIBUTES)
 450         return JNI_FALSE;
 451     switch (access) {
 452     case java_io_FileSystem_ACCESS_READ:
 453     case java_io_FileSystem_ACCESS_EXECUTE:
 454         return JNI_TRUE;
 455     case java_io_FileSystem_ACCESS_WRITE:
 456         /* Read-only attribute ignored on directories */
 457         if ((attr & FILE_ATTRIBUTE_DIRECTORY) ||
 458             (attr & FILE_ATTRIBUTE_READONLY) == 0)
 459             return JNI_TRUE;
 460         else
 461             return JNI_FALSE;
 462     default:
 463         assert(0);
 464         return JNI_FALSE;
 465     }
 466 }
 467 
 468 JNIEXPORT jboolean JNICALL
 469 Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
 470                                            jobject file,
 471                                            jint access,
 472                                            jboolean enable,
 473                                            jboolean owneronly)
 474 {
 475     jboolean rv = JNI_FALSE;
 476     WCHAR *pathbuf;
 477     DWORD a;
 478     if (access == java_io_FileSystem_ACCESS_READ ||
 479         access == java_io_FileSystem_ACCESS_EXECUTE) {
 480         return enable;
 481     }
 482     pathbuf = fileToNTPath(env, file, ids.path);
 483     if (pathbuf == NULL)
 484         return JNI_FALSE;
 485     a = GetFileAttributesW(pathbuf);
 486 
 487     /* if reparse point, get final target */
 488     if ((a != INVALID_FILE_ATTRIBUTES) &&
 489         ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
 490     {
 491         WCHAR *fp = getFinalPath(env, pathbuf);
 492         if (fp == NULL) {
 493             a = INVALID_FILE_ATTRIBUTES;

 495             free(pathbuf);
 496             pathbuf = fp;
 497             a = GetFileAttributesW(pathbuf);
 498         }
 499     }
 500     if ((a != INVALID_FILE_ATTRIBUTES) &&
 501         ((a & FILE_ATTRIBUTE_DIRECTORY) == 0))
 502     {
 503         if (enable)
 504             a =  a & ~FILE_ATTRIBUTE_READONLY;
 505         else
 506             a =  a | FILE_ATTRIBUTE_READONLY;
 507         if (SetFileAttributesW(pathbuf, a))
 508             rv = JNI_TRUE;
 509     }
 510     free(pathbuf);
 511     return rv;
 512 }
 513 
 514 JNIEXPORT jlong JNICALL
 515 Java_java_io_WinNTFileSystem_getLastModifiedTime(JNIEnv *env, jobject this,
 516                                                  jobject file)
 517 {
 518     jlong rv = 0;
 519     ULARGE_INTEGER modTime;
 520     FILETIME t;
 521     HANDLE h;
 522     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 523     if (pathbuf == NULL)
 524         return rv;
 525     h = CreateFileW(pathbuf,
 526                     /* Device query access */
 527                     0,
 528                     /* Share it */
 529                     FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
 530                     /* No security attributes */
 531                     NULL,
 532                     /* Open existing or fail */
 533                     OPEN_EXISTING,
 534                     /* Backup semantics for directories */
 535                     FILE_FLAG_BACKUP_SEMANTICS,
 536                     /* No template file */
 537                     NULL);
 538     if (h != INVALID_HANDLE_VALUE) {
 539         if (GetFileTime(h, NULL, NULL, &t)) {
 540             modTime.LowPart = (DWORD) t.dwLowDateTime;
 541             modTime.HighPart = (LONG) t.dwHighDateTime;
 542             rv = modTime.QuadPart / 10000;
 543             rv -= 11644473600000;
 544         }
 545         CloseHandle(h);
 546     }
 547     free(pathbuf);
 548     return rv;
 549 }
 550 
 551 JNIEXPORT jlong JNICALL
 552 Java_java_io_WinNTFileSystem_getLength(JNIEnv *env, jobject this, jobject file)
 553 {
 554     jlong rv = 0;
 555     WIN32_FILE_ATTRIBUTE_DATA wfad;
 556     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 557     if (pathbuf == NULL)
 558         return rv;
 559     if (GetFileAttributesExW(pathbuf,
 560                              GetFileExInfoStandard,
 561                              &wfad)) {
 562         if ((wfad.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
 563             rv = wfad.nFileSizeHigh * ((jlong)MAXDWORD + 1) + wfad.nFileSizeLow;
 564         } else {
 565             /* file is a reparse point so read attributes of final target */
 566             BY_HANDLE_FILE_INFORMATION finfo;
 567             if (getFileInformation(pathbuf, &finfo)) {
 568                 rv = finfo.nFileSizeHigh * ((jlong)MAXDWORD + 1) +
 569                     finfo.nFileSizeLow;
 570             }
 571         }
 572     } else {

 598                     if (wcscmp(pslash, fslash) == 0) {
 599                         ULARGE_INTEGER length;
 600                         length.LowPart = fileData.nFileSizeLow;
 601                         length.HighPart = fileData.nFileSizeHigh;
 602                         if (length.QuadPart <= _I64_MAX) {
 603                             rv = (jlong)length.QuadPart;
 604                         }
 605                     }
 606                 }
 607                 FindClose(h);
 608             }
 609         }
 610     }
 611     free(pathbuf);
 612     return rv;
 613 }
 614 
 615 /* -- File operations -- */
 616 
 617 JNIEXPORT jboolean JNICALL
 618 Java_java_io_WinNTFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
 619                                                    jstring path)
 620 {
 621     HANDLE h = NULL;
 622     WCHAR *pathbuf = pathToNTPath(env, path, JNI_FALSE);
 623     if (pathbuf == NULL)
 624         return JNI_FALSE;
 625     if (isReservedDeviceNameW(pathbuf)) {
 626         free(pathbuf);
 627         return JNI_FALSE;
 628     }
 629     h = CreateFileW(
 630         pathbuf,                              /* Wide char path name */
 631         GENERIC_READ | GENERIC_WRITE,         /* Read and write permission */
 632         FILE_SHARE_READ | FILE_SHARE_WRITE,   /* File sharing flags */
 633         NULL,                                 /* Security attributes */
 634         CREATE_NEW,                           /* creation disposition */
 635         FILE_ATTRIBUTE_NORMAL |
 636             FILE_FLAG_OPEN_REPARSE_POINT,     /* flags and attributes */
 637         NULL);
 638 
 639     if (h == INVALID_HANDLE_VALUE) {

 671         return !DeleteFileW(path);
 672     }
 673 }
 674 
 675 JNIEXPORT jboolean JNICALL
 676 Java_java_io_WinNTFileSystem_delete0(JNIEnv *env, jobject this, jobject file)
 677 {
 678     jboolean rv = JNI_FALSE;
 679     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 680     if (pathbuf == NULL) {
 681         return JNI_FALSE;
 682     }
 683     if (removeFileOrDirectory(pathbuf) == 0) {
 684         rv = JNI_TRUE;
 685     }
 686     free(pathbuf);
 687     return rv;
 688 }
 689 
 690 JNIEXPORT jobjectArray JNICALL
 691 Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
 692 {
 693     WCHAR *search_path;
 694     HANDLE handle;
 695     WIN32_FIND_DATAW find_data;
 696     int len, maxlen;
 697     jobjectArray rv, old;
 698     DWORD fattr;
 699     jstring name;
 700     jclass str_class;
 701     WCHAR *pathbuf;
 702     DWORD err;
 703 
 704     str_class = JNU_ClassString(env);
 705     CHECK_NULL_RETURN(str_class, NULL);
 706 
 707     pathbuf = fileToNTPath(env, file, ids.path);
 708     if (pathbuf == NULL)
 709         return NULL;
 710     search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6);
 711     if (search_path == 0) {

 793     err = GetLastError();
 794     FindClose(handle);
 795     if (err != ERROR_NO_MORE_FILES) {
 796         return NULL; // error
 797     }
 798 
 799     if (len < maxlen) {
 800         /* Copy the final results into an appropriately-sized array */
 801         old = rv;
 802         rv = (*env)->NewObjectArray(env, len, str_class, NULL);
 803         if (rv == NULL)
 804             return NULL; /* error */
 805         if (JNU_CopyObjectArray(env, rv, old, len) < 0)
 806             return NULL; /* error */
 807     }
 808     return rv;
 809 }
 810 
 811 
 812 JNIEXPORT jboolean JNICALL
 813 Java_java_io_WinNTFileSystem_createDirectory(JNIEnv *env, jobject this,
 814                                              jobject file)
 815 {
 816     BOOL h = FALSE;
 817     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 818     if (pathbuf == NULL) {
 819         /* Exception is pending */
 820         return JNI_FALSE;
 821     }
 822     h = CreateDirectoryW(pathbuf, NULL);
 823     free(pathbuf);
 824 
 825     if (h == 0) {
 826         return JNI_FALSE;
 827     }
 828 
 829     return JNI_TRUE;
 830 }
 831 
 832 
 833 JNIEXPORT jboolean JNICALL
 834 Java_java_io_WinNTFileSystem_rename0(JNIEnv *env, jobject this, jobject from,
 835                                      jobject to)
 836 {
 837 
 838     jboolean rv = JNI_FALSE;
 839     WCHAR *frompath = fileToNTPath(env, from, ids.path);
 840     WCHAR *topath = fileToNTPath(env, to, ids.path);
 841     if (frompath != NULL && topath != NULL && _wrename(frompath, topath) == 0) {
 842         rv = JNI_TRUE;
 843     }
 844     free(frompath);
 845     free(topath);
 846     return rv;
 847 }
 848 
 849 
 850 JNIEXPORT jboolean JNICALL
 851 Java_java_io_WinNTFileSystem_setLastModifiedTime(JNIEnv *env, jobject this,
 852                                                  jobject file, jlong time)
 853 {
 854     jboolean rv = JNI_FALSE;
 855     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 856     HANDLE h;
 857     if (pathbuf == NULL)
 858         return JNI_FALSE;
 859     h = CreateFileW(pathbuf,
 860                     FILE_WRITE_ATTRIBUTES,
 861                     FILE_SHARE_READ | FILE_SHARE_WRITE,
 862                     NULL,
 863                     OPEN_EXISTING,
 864                     FILE_FLAG_BACKUP_SEMANTICS,
 865                     0);
 866     if (h != INVALID_HANDLE_VALUE) {
 867         ULARGE_INTEGER modTime;
 868         FILETIME t;
 869         modTime.QuadPart = (time + 11644473600000L) * 10000L;
 870         t.dwLowDateTime = (DWORD)modTime.LowPart;
 871         t.dwHighDateTime = (DWORD)modTime.HighPart;
 872         if (SetFileTime(h, NULL, NULL, &t)) {
 873             rv = JNI_TRUE;
 874         }
 875         CloseHandle(h);
 876     }
 877     free(pathbuf);
 878 
 879     return rv;
 880 }
 881 
 882 
 883 JNIEXPORT jboolean JNICALL
 884 Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this,
 885                                          jobject file)
 886 {
 887     jboolean rv = JNI_FALSE;
 888     DWORD a;
 889     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 890     if (pathbuf == NULL)
 891         return JNI_FALSE;
 892     a = GetFileAttributesW(pathbuf);
 893 
 894     /* if reparse point, get final target */
 895     if ((a != INVALID_FILE_ATTRIBUTES) &&
 896         ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
 897     {
 898         WCHAR *fp = getFinalPath(env, pathbuf);
 899         if (fp == NULL) {
 900             a = INVALID_FILE_ATTRIBUTES;
 901         } else {
 902             free(pathbuf);
 903             pathbuf = fp;
 904             a = GetFileAttributesW(pathbuf);
 905         }

 394                                    &lpf);
 395     if ((retLen == BUFSIZE - 1 || retLen == BUFSIZE - 2) &&
 396         buf[0] == L'\\' && buf[1] == L'\\' &&
 397         buf[2] == L'.' && buf[3] == L'\\') {
 398         WCHAR* dname = _wcsupr(buf + 4);
 399         if (wcscmp(dname, L"CON") == 0 ||
 400             wcscmp(dname, L"PRN") == 0 ||
 401             wcscmp(dname, L"AUX") == 0 ||
 402             wcscmp(dname, L"NUL") == 0)
 403             return TRUE;
 404         if ((wcsncmp(dname, L"COM", 3) == 0 ||
 405              wcsncmp(dname, L"LPT", 3) == 0) &&
 406             dname[3] - L'0' > 0 &&
 407             dname[3] - L'0' <= 9)
 408             return TRUE;
 409     }
 410     return FALSE;
 411 }
 412 
 413 JNIEXPORT jint JNICALL
 414 Java_java_io_WinNTFileSystem_getBooleanAttributes0(JNIEnv *env, jobject this,
 415                                                    jobject file)
 416 {
 417     jint rv = 0;
 418 
 419     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 420     if (pathbuf == NULL)
 421         return rv;
 422     if (!isReservedDeviceNameW(pathbuf)) {
 423         DWORD a = getFinalAttributes(pathbuf);
 424         if (a != INVALID_FILE_ATTRIBUTES) {
 425             rv = (java_io_FileSystem_BA_EXISTS
 426                 | ((a & FILE_ATTRIBUTE_DIRECTORY)
 427                     ? java_io_FileSystem_BA_DIRECTORY
 428                     : java_io_FileSystem_BA_REGULAR)
 429                 | ((a & FILE_ATTRIBUTE_HIDDEN)
 430                     ? java_io_FileSystem_BA_HIDDEN : 0));
 431         }
 432     }
 433     free(pathbuf);
 434     return rv;
 435 }
 436 
 437 
 438 JNIEXPORT jboolean
 439 JNICALL Java_java_io_WinNTFileSystem_checkAccess0(JNIEnv *env, jobject this,
 440                                                   jobject file, jint access)
 441 {
 442     DWORD attr;
 443     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 444     if (pathbuf == NULL)
 445         return JNI_FALSE;
 446     attr = GetFileAttributesW(pathbuf);
 447     attr = getFinalAttributesIfReparsePoint(pathbuf, attr);
 448     free(pathbuf);
 449     if (attr == INVALID_FILE_ATTRIBUTES)
 450         return JNI_FALSE;
 451     switch (access) {
 452     case java_io_FileSystem_ACCESS_READ:
 453     case java_io_FileSystem_ACCESS_EXECUTE:
 454         return JNI_TRUE;
 455     case java_io_FileSystem_ACCESS_WRITE:
 456         /* Read-only attribute ignored on directories */
 457         if ((attr & FILE_ATTRIBUTE_DIRECTORY) ||
 458             (attr & FILE_ATTRIBUTE_READONLY) == 0)
 459             return JNI_TRUE;
 460         else
 461             return JNI_FALSE;
 462     default:
 463         assert(0);
 464         return JNI_FALSE;
 465     }
 466 }
 467 
 468 JNIEXPORT jboolean JNICALL
 469 Java_java_io_WinNTFileSystem_setPermission0(JNIEnv *env, jobject this,
 470                                             jobject file,
 471                                             jint access,
 472                                             jboolean enable,
 473                                             jboolean owneronly)
 474 {
 475     jboolean rv = JNI_FALSE;
 476     WCHAR *pathbuf;
 477     DWORD a;
 478     if (access == java_io_FileSystem_ACCESS_READ ||
 479         access == java_io_FileSystem_ACCESS_EXECUTE) {
 480         return enable;
 481     }
 482     pathbuf = fileToNTPath(env, file, ids.path);
 483     if (pathbuf == NULL)
 484         return JNI_FALSE;
 485     a = GetFileAttributesW(pathbuf);
 486 
 487     /* if reparse point, get final target */
 488     if ((a != INVALID_FILE_ATTRIBUTES) &&
 489         ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
 490     {
 491         WCHAR *fp = getFinalPath(env, pathbuf);
 492         if (fp == NULL) {
 493             a = INVALID_FILE_ATTRIBUTES;

 495             free(pathbuf);
 496             pathbuf = fp;
 497             a = GetFileAttributesW(pathbuf);
 498         }
 499     }
 500     if ((a != INVALID_FILE_ATTRIBUTES) &&
 501         ((a & FILE_ATTRIBUTE_DIRECTORY) == 0))
 502     {
 503         if (enable)
 504             a =  a & ~FILE_ATTRIBUTE_READONLY;
 505         else
 506             a =  a | FILE_ATTRIBUTE_READONLY;
 507         if (SetFileAttributesW(pathbuf, a))
 508             rv = JNI_TRUE;
 509     }
 510     free(pathbuf);
 511     return rv;
 512 }
 513 
 514 JNIEXPORT jlong JNICALL
 515 Java_java_io_WinNTFileSystem_getLastModifiedTime0(JNIEnv *env, jobject this,
 516                                                   jobject file)
 517 {
 518     jlong rv = 0;
 519     ULARGE_INTEGER modTime;
 520     FILETIME t;
 521     HANDLE h;
 522     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 523     if (pathbuf == NULL)
 524         return rv;
 525     h = CreateFileW(pathbuf,
 526                     /* Device query access */
 527                     0,
 528                     /* Share it */
 529                     FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
 530                     /* No security attributes */
 531                     NULL,
 532                     /* Open existing or fail */
 533                     OPEN_EXISTING,
 534                     /* Backup semantics for directories */
 535                     FILE_FLAG_BACKUP_SEMANTICS,
 536                     /* No template file */
 537                     NULL);
 538     if (h != INVALID_HANDLE_VALUE) {
 539         if (GetFileTime(h, NULL, NULL, &t)) {
 540             modTime.LowPart = (DWORD) t.dwLowDateTime;
 541             modTime.HighPart = (LONG) t.dwHighDateTime;
 542             rv = modTime.QuadPart / 10000;
 543             rv -= 11644473600000;
 544         }
 545         CloseHandle(h);
 546     }
 547     free(pathbuf);
 548     return rv;
 549 }
 550 
 551 JNIEXPORT jlong JNICALL
 552 Java_java_io_WinNTFileSystem_getLength0(JNIEnv *env, jobject this, jobject file)
 553 {
 554     jlong rv = 0;
 555     WIN32_FILE_ATTRIBUTE_DATA wfad;
 556     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 557     if (pathbuf == NULL)
 558         return rv;
 559     if (GetFileAttributesExW(pathbuf,
 560                              GetFileExInfoStandard,
 561                              &wfad)) {
 562         if ((wfad.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
 563             rv = wfad.nFileSizeHigh * ((jlong)MAXDWORD + 1) + wfad.nFileSizeLow;
 564         } else {
 565             /* file is a reparse point so read attributes of final target */
 566             BY_HANDLE_FILE_INFORMATION finfo;
 567             if (getFileInformation(pathbuf, &finfo)) {
 568                 rv = finfo.nFileSizeHigh * ((jlong)MAXDWORD + 1) +
 569                     finfo.nFileSizeLow;
 570             }
 571         }
 572     } else {

 598                     if (wcscmp(pslash, fslash) == 0) {
 599                         ULARGE_INTEGER length;
 600                         length.LowPart = fileData.nFileSizeLow;
 601                         length.HighPart = fileData.nFileSizeHigh;
 602                         if (length.QuadPart <= _I64_MAX) {
 603                             rv = (jlong)length.QuadPart;
 604                         }
 605                     }
 606                 }
 607                 FindClose(h);
 608             }
 609         }
 610     }
 611     free(pathbuf);
 612     return rv;
 613 }
 614 
 615 /* -- File operations -- */
 616 
 617 JNIEXPORT jboolean JNICALL
 618 Java_java_io_WinNTFileSystem_createFileExclusively0(JNIEnv *env, jclass cls,
 619                                                     jstring path)
 620 {
 621     HANDLE h = NULL;
 622     WCHAR *pathbuf = pathToNTPath(env, path, JNI_FALSE);
 623     if (pathbuf == NULL)
 624         return JNI_FALSE;
 625     if (isReservedDeviceNameW(pathbuf)) {
 626         free(pathbuf);
 627         return JNI_FALSE;
 628     }
 629     h = CreateFileW(
 630         pathbuf,                              /* Wide char path name */
 631         GENERIC_READ | GENERIC_WRITE,         /* Read and write permission */
 632         FILE_SHARE_READ | FILE_SHARE_WRITE,   /* File sharing flags */
 633         NULL,                                 /* Security attributes */
 634         CREATE_NEW,                           /* creation disposition */
 635         FILE_ATTRIBUTE_NORMAL |
 636             FILE_FLAG_OPEN_REPARSE_POINT,     /* flags and attributes */
 637         NULL);
 638 
 639     if (h == INVALID_HANDLE_VALUE) {

 671         return !DeleteFileW(path);
 672     }
 673 }
 674 
 675 JNIEXPORT jboolean JNICALL
 676 Java_java_io_WinNTFileSystem_delete0(JNIEnv *env, jobject this, jobject file)
 677 {
 678     jboolean rv = JNI_FALSE;
 679     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 680     if (pathbuf == NULL) {
 681         return JNI_FALSE;
 682     }
 683     if (removeFileOrDirectory(pathbuf) == 0) {
 684         rv = JNI_TRUE;
 685     }
 686     free(pathbuf);
 687     return rv;
 688 }
 689 
 690 JNIEXPORT jobjectArray JNICALL
 691 Java_java_io_WinNTFileSystem_list0(JNIEnv *env, jobject this, jobject file)
 692 {
 693     WCHAR *search_path;
 694     HANDLE handle;
 695     WIN32_FIND_DATAW find_data;
 696     int len, maxlen;
 697     jobjectArray rv, old;
 698     DWORD fattr;
 699     jstring name;
 700     jclass str_class;
 701     WCHAR *pathbuf;
 702     DWORD err;
 703 
 704     str_class = JNU_ClassString(env);
 705     CHECK_NULL_RETURN(str_class, NULL);
 706 
 707     pathbuf = fileToNTPath(env, file, ids.path);
 708     if (pathbuf == NULL)
 709         return NULL;
 710     search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6);
 711     if (search_path == 0) {

 793     err = GetLastError();
 794     FindClose(handle);
 795     if (err != ERROR_NO_MORE_FILES) {
 796         return NULL; // error
 797     }
 798 
 799     if (len < maxlen) {
 800         /* Copy the final results into an appropriately-sized array */
 801         old = rv;
 802         rv = (*env)->NewObjectArray(env, len, str_class, NULL);
 803         if (rv == NULL)
 804             return NULL; /* error */
 805         if (JNU_CopyObjectArray(env, rv, old, len) < 0)
 806             return NULL; /* error */
 807     }
 808     return rv;
 809 }
 810 
 811 
 812 JNIEXPORT jboolean JNICALL
 813 Java_java_io_WinNTFileSystem_createDirectory0(JNIEnv *env, jobject this,
 814                                               jobject file)
 815 {
 816     BOOL h = FALSE;
 817     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 818     if (pathbuf == NULL) {
 819         /* Exception is pending */
 820         return JNI_FALSE;
 821     }
 822     h = CreateDirectoryW(pathbuf, NULL);
 823     free(pathbuf);
 824 
 825     if (h == 0) {
 826         return JNI_FALSE;
 827     }
 828 
 829     return JNI_TRUE;
 830 }
 831 
 832 
 833 JNIEXPORT jboolean JNICALL
 834 Java_java_io_WinNTFileSystem_rename0(JNIEnv *env, jobject this, jobject from,
 835                                      jobject to)
 836 {
 837 
 838     jboolean rv = JNI_FALSE;
 839     WCHAR *frompath = fileToNTPath(env, from, ids.path);
 840     WCHAR *topath = fileToNTPath(env, to, ids.path);
 841     if (frompath != NULL && topath != NULL && _wrename(frompath, topath) == 0) {
 842         rv = JNI_TRUE;
 843     }
 844     free(frompath);
 845     free(topath);
 846     return rv;
 847 }
 848 
 849 
 850 JNIEXPORT jboolean JNICALL
 851 Java_java_io_WinNTFileSystem_setLastModifiedTime0(JNIEnv *env, jobject this,
 852                                                   jobject file, jlong time)
 853 {
 854     jboolean rv = JNI_FALSE;
 855     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 856     HANDLE h;
 857     if (pathbuf == NULL)
 858         return JNI_FALSE;
 859     h = CreateFileW(pathbuf,
 860                     FILE_WRITE_ATTRIBUTES,
 861                     FILE_SHARE_READ | FILE_SHARE_WRITE,
 862                     NULL,
 863                     OPEN_EXISTING,
 864                     FILE_FLAG_BACKUP_SEMANTICS,
 865                     0);
 866     if (h != INVALID_HANDLE_VALUE) {
 867         ULARGE_INTEGER modTime;
 868         FILETIME t;
 869         modTime.QuadPart = (time + 11644473600000L) * 10000L;
 870         t.dwLowDateTime = (DWORD)modTime.LowPart;
 871         t.dwHighDateTime = (DWORD)modTime.HighPart;
 872         if (SetFileTime(h, NULL, NULL, &t)) {
 873             rv = JNI_TRUE;
 874         }
 875         CloseHandle(h);
 876     }
 877     free(pathbuf);
 878 
 879     return rv;
 880 }
 881 
 882 
 883 JNIEXPORT jboolean JNICALL
 884 Java_java_io_WinNTFileSystem_setReadOnly0(JNIEnv *env, jobject this,
 885                                           jobject file)
 886 {
 887     jboolean rv = JNI_FALSE;
 888     DWORD a;
 889     WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
 890     if (pathbuf == NULL)
 891         return JNI_FALSE;
 892     a = GetFileAttributesW(pathbuf);
 893 
 894     /* if reparse point, get final target */
 895     if ((a != INVALID_FILE_ATTRIBUTES) &&
 896         ((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
 897     {
 898         WCHAR *fp = getFinalPath(env, pathbuf);
 899         if (fp == NULL) {
 900             a = INVALID_FILE_ATTRIBUTES;
 901         } else {
 902             free(pathbuf);
 903             pathbuf = fp;
 904             a = GetFileAttributesW(pathbuf);
 905         }
< prev index next >