| 1 | package Win32::VolumeInformation; | ||
| 2 | |||
| 3 | use Win32::API; | ||
| 4 | use File::Spec; | ||
| 5 | |||
| 6 | use Exporter (); | ||
| 7 | our @ISA = qw( Exporter ); | ||
| 8 | our @EXPORT_OK = qw( GetVolumeInformation ); | ||
| 9 | |||
| 10 | our $VERSION = 0.2; | ||
| 11 | |||
| 12 | our $volinfofunc = Win32::API->new('kernel32', 'GetVolumeInformation', ['P','P','N','P','P','P','P','N'], 'N') | ||
| 13 | or die "Win32::API->new GetVolumeInformation: $!"; | ||
| 14 | |||
| 15 | our %flags = ( | ||
| 16 | 0x00000001 => 'FS_CASE_SENSITIVE' | ||
| 17 | ,0x00000002 => 'FS_CASE_IS_PRESERVED' | ||
| 18 | ,0x00000004 => 'FS_UNICODE_STORED_ON_DISK' | ||
| 19 | ,0x00000008 => 'FS_PERSISTENT_ACLS' | ||
| 20 | ,0x00000010 => 'FS_FILE_COMPRESSION' | ||
| 21 | ,0x00000020 => 'FILE_VOLUME_QUOTAS' | ||
| 22 | ,0x00000040 => 'FILE_SUPPORTS_SPARSE_FILES' | ||
| 23 | ,0x00000080 => 'FILE_SUPPORTS_REPARSE_POINTS' | ||
| 24 | ,0x00008000 => 'FS_VOL_IS_COMPRESSED' | ||
| 25 | ,0x00000000 => 'FILE_NAMED_STREAMS' | ||
| 26 | ,0x00020000 => 'FILE_SUPPORTS_ENCRYPTION' | ||
| 27 | ,0x00010000 => 'FILE_SUPPORTS_OBJECT_IDS' | ||
| 28 | ); | ||
| 29 | |||
| 30 | sub get_flags{ | ||
| 31 | my $flags = shift; | ||
| 32 | my %result; | ||
| 33 | for( keys %flags ){ | ||
| 34 | $result{ $flags{$_} } = $flags & $_ ? 1 : 0; | ||
| 35 | } | ||
| 36 | return \%result; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub GetVolumeInformation{ | ||
| 40 | my( $vol,$path,$file) = File::Spec->splitpath(shift); | ||
| 41 | $vol = ( $vol ) ? $vol."\\" : 0; | ||
| 42 | my $name,$serial,$maxlen,$flags,$fstype; | ||
| 43 | $name = $fstype = "\0"x256; | ||
| 44 | $serial = $maxlen = $flags = pack("L", 0); | ||
| 45 | if( $volinfofunc->Call($vol,$name,256,$serial,$maxlen,$flags,$fstype,256) ){ | ||
| 46 | $_ =~ s/\0*$// for ( $name,$fstype ); | ||
| 47 | $_ = unpack("L", $_) for ( $serial,$maxlen,$flags ); | ||
| 48 | my $result = get_flags($flags); | ||
| 49 | $result->{VolumeName} = $name; | ||
| 50 | $result->{VolumeSerialNumber} = $serial; | ||
| 51 | $result->{MaximumComponentLength} = $maxlen; | ||
| 52 | $result->{FileSystemName} = $fsname; | ||
| 53 | $_[1] = $result; | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; |