driveinfo.java
/*
* Copyright (c) 2001-2005 Servertec. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* THIS NOTICE MUST NOT BE ALTERED NOR REMOVED.
*
* CopyrightVersion 1.0
*/
import stec.sfc.Win32.Drive;
import stec.sfc.Win32.DriveType;
import stec.sfc.Win32.FileSystem;
import stec.sfc.Win32.FileSystemFlag;
import stec.sfc.Win32.Win32Exception;
public class driveinfo
{
public static void main(String[] args) throws Exception
{
if(args == null)
{
syntax("drive was not specified.");
return;
}
if(args.length < 1)
{
syntax("drive was not specified.");
return;
}
if(args[0].equalsIgnoreCase("all"))
{
String[] drives = FileSystem.drives();
for(int i = 0; i < drives.length; i++)
{
driveinfo(drives[i]);
}
if(drives == null)
{
System.out.println("0 drives found.");
}
else if(drives.length == 1)
{
System.out.println("1 drive found.");
}
else
{
System.out.println(drives.length + " drives found.");
}
}
else
{
driveinfo(args[0]);
}
}
static void driveinfo(String name) throws Exception
{
System.out.println("Drive: " + name);
Drive drive;
try
{
drive = new Drive(name);
}
catch(Win32Exception ex)
{
System.out.println("Drive is not available: " + ex.getErrorCode());
System.out.println();
return;
}
System.out.println("Volume Label: " + drive.getVolumeLabel());
System.out.println("Serial Number: " + drive.getVolumeSerialNumber());
System.out.print("Drive Type: ");
int type = drive.getType();
if(type == DriveType.UNKNOWN)
{
System.out.println("Unknown");
}
else if(type == DriveType.NO_ROOT_DIR)
{
System.out.println("Invalid");
}
else if(type == DriveType.REMOVABLE)
{
System.out.println("Removable");
}
else if(type == DriveType.FIXED)
{
System.out.println("Fixed");
}
else if(type == DriveType.REMOTE)
{
System.out.println("Remote");
}
else if(type == DriveType.CDROM)
{
System.out.println("CD-ROM");
}
else if(type == DriveType.RAMDISK)
{
System.out.println("RAM Disk");
}
else
{
System.out.println(type);
}
System.out.println("Sectors / Cluster: " + drive.getSectorsPerCluster());
System.out.println("Bytes / Sector: " + drive.getBytesPerSector());
System.out.println("Total Number of Clusters: " + drive.getTotalNumberOfClusters());
System.out.println("Number of Free Clusters: " + drive.getNumberOfFreeClusters());
System.out.println("Total Number of Bytes: " + drive.getTotalNumberOfBytes());
System.out.println("Total Number of Free Clusters: " + drive.getTotalNumberOfFreeBytes());
System.out.println("Maximum Path Component Length: " + drive.getMaximumPathComponentLength());
System.out.println("File System Name: " + drive.getFileSystemName());
StringBuffer sb = new StringBuffer();
int flags = drive.getFileSystemFlags();
if((flags & FileSystemFlag.CASE_IS_PRESERVED) != 0)
{
sb.append(" Case Preserved,");
}
if((flags & FileSystemFlag.CASE_SENSITIVE) != 0)
{
sb.append(" Case Sensitive,");
}
if((flags & FileSystemFlag.UNICODE_STORED_ON_DISK) != 0)
{
sb.append(" Unicode,");
}
if((flags & FileSystemFlag.PERSISTENT_ACLS) != 0)
{
sb.append(" Persistent ACLs,");
}
if((flags & FileSystemFlag.FILE_COMPRESSION) != 0)
{
sb.append(" File Compression,");
}
if((flags & FileSystemFlag.VOL_IS_COMPRESSED) != 0)
{
sb.append(" Volume Compression,");
}
if((flags & FileSystemFlag.NAMED_STREAMS) != 0)
{
sb.append(" Named Streams,");
}
if((flags & FileSystemFlag.READ_ONLY_VOLUME) != 0)
{
sb.append(" Read-Only,");
}
if((flags & FileSystemFlag.SUPPORTS_ENCRYPTION) != 0)
{
sb.append(" Encryption,");
}
if((flags & FileSystemFlag.SUPPORTS_OBJECT_IDS) != 0)
{
sb.append(" Object IDs,");
}
if((flags & FileSystemFlag.SUPPORTS_REPARSE_POINTS) != 0)
{
sb.append(" Reparse Points,");
}
if((flags & FileSystemFlag.SUPPORTS_SPARSE_FILES) != 0)
{
sb.append(" Sparse Files,");
}
if((flags & FileSystemFlag.VOLUME_QUOTAS) != 0)
{
sb.append(" Volume Quotas,");
}
if(sb.length() > 0)
{
sb.setLength(sb.length() - 1);
}
System.out.println("File System Flags:" + sb.toString());
System.out.println();
}
static void syntax()
{
System.out.println("usage: driveinfo [|all]");
System.out.println();
}
static void syntax(String message)
{
syntax();
if(message != null)
{
System.out.println(message);
}
System.out.println();
}
}