1 /*
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
468 /**
469 * GetDiskFreeSpaceEx(
470 * LPCTSTR lpDirectoryName,
471 * PULARGE_INTEGER lpFreeBytesAvailableToCaller,
472 * PULARGE_INTEGER lpTotalNumberOfBytes,
473 * PULARGE_INTEGER lpTotalNumberOfFreeBytes
474 * )
475 */
476 static DiskFreeSpace GetDiskFreeSpaceEx(String path)
477 throws WindowsException
478 {
479 NativeBuffer buffer = asNativeBuffer(path);
480 try {
481 DiskFreeSpace space = new DiskFreeSpace();
482 GetDiskFreeSpaceEx0(buffer.address(), space);
483 return space;
484 } finally {
485 buffer.release();
486 }
487 }
488 static class DiskFreeSpace {
489 private long freeBytesAvailable;
490 private long totalNumberOfBytes;
491 private long totalNumberOfFreeBytes;
492 private DiskFreeSpace() { }
493
494 public long freeBytesAvailable() { return freeBytesAvailable; }
495 public long totalNumberOfBytes() { return totalNumberOfBytes; }
496 public long totalNumberOfFreeBytes() { return totalNumberOfFreeBytes; }
497 }
498 private static native void GetDiskFreeSpaceEx0(long lpDirectoryName,
499 DiskFreeSpace obj)
500 throws WindowsException;
501
502
503 /**
504 * GetVolumePathName(
505 * LPCTSTR lpszFileName,
506 * LPTSTR lpszVolumePathName,
507 * DWORD cchBufferLength
508 * )
509 *
510 * @return lpFileName
511 */
512 static String GetVolumePathName(String path) throws WindowsException {
513 NativeBuffer buffer = asNativeBuffer(path);
514 try {
515 return GetVolumePathName0(buffer.address());
516 } finally {
517 buffer.release();
518 }
519 }
520 private static native String GetVolumePathName0(long lpFileName)
521 throws WindowsException;
522
|
1 /*
2 * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
468 /**
469 * GetDiskFreeSpaceEx(
470 * LPCTSTR lpDirectoryName,
471 * PULARGE_INTEGER lpFreeBytesAvailableToCaller,
472 * PULARGE_INTEGER lpTotalNumberOfBytes,
473 * PULARGE_INTEGER lpTotalNumberOfFreeBytes
474 * )
475 */
476 static DiskFreeSpace GetDiskFreeSpaceEx(String path)
477 throws WindowsException
478 {
479 NativeBuffer buffer = asNativeBuffer(path);
480 try {
481 DiskFreeSpace space = new DiskFreeSpace();
482 GetDiskFreeSpaceEx0(buffer.address(), space);
483 return space;
484 } finally {
485 buffer.release();
486 }
487 }
488
489 /**
490 * GetDiskFreeSpace(
491 * LPCTSTR lpRootPathName,
492 * LPDWORD lpSectorsPerCluster,
493 * LPDWORD lpBytesPerSector,
494 * LPDWORD lpNumberOfFreeClusters,
495 * LPDWORD lpTotalNumberOfClusters
496 * )
497 */
498 static DiskFreeSpace GetDiskFreeSpace(String path)
499 throws WindowsException
500 {
501 NativeBuffer buffer = asNativeBuffer(path);
502 try {
503 DiskFreeSpace space = new DiskFreeSpace();
504 GetDiskFreeSpace0(buffer.address(), space);
505 return space;
506 } finally {
507 buffer.release();
508 }
509 }
510
511 static class DiskFreeSpace {
512 private long freeBytesAvailable;
513 private long totalNumberOfBytes;
514 private long totalNumberOfFreeBytes;
515 private long bytesPerSector;
516 private DiskFreeSpace() { }
517
518 public long freeBytesAvailable() { return freeBytesAvailable; }
519 public long totalNumberOfBytes() { return totalNumberOfBytes; }
520 public long totalNumberOfFreeBytes() { return totalNumberOfFreeBytes; }
521 public long bytesPerSector() { return bytesPerSector; }
522 }
523 private static native void GetDiskFreeSpaceEx0(long lpDirectoryName,
524 DiskFreeSpace obj)
525 throws WindowsException;
526
527
528 private static native void GetDiskFreeSpace0(long lpRootPathName,
529 DiskFreeSpace obj)
530 throws WindowsException;
531
532 /**
533 * GetVolumePathName(
534 * LPCTSTR lpszFileName,
535 * LPTSTR lpszVolumePathName,
536 * DWORD cchBufferLength
537 * )
538 *
539 * @return lpFileName
540 */
541 static String GetVolumePathName(String path) throws WindowsException {
542 NativeBuffer buffer = asNativeBuffer(path);
543 try {
544 return GetVolumePathName0(buffer.address());
545 } finally {
546 buffer.release();
547 }
548 }
549 private static native String GetVolumePathName0(long lpFileName)
550 throws WindowsException;
551
|