1 # File.pm -- Low-level access to Win32 file/dir functions/constants.
2 # This file is http://cpansearch.perl.org/src/CHORNY/Win32API-File-0.1203/File.pm
4 package IPC::Win32APIFile;
9 use Config qw( %Config );
10 use Fcntl qw( O_RDONLY O_RDWR O_WRONLY O_APPEND O_BINARY O_TEXT );
11 use vars qw( $VERSION @ISA );
12 use vars qw( @EXPORT @EXPORT_OK @EXPORT_FAIL %EXPORT_TAGS );
16 use base qw( Exporter DynaLoader Tie::Handle IO::File );
18 # Math::BigInt optimizations courtesy of Tels
21 $_64BITINT = defined($Config{use64bitint}) &&
22 ($Config{use64bitint} eq 'define');
24 require Math::BigInt unless $_64BITINT;
27 my $THIRTY_TWO = $_64BITINT ? 32 : Math::BigInt->new(32);
29 my $FFFFFFFF = $_64BITINT ? 0xFFFFFFFF : Math::BigInt->new(0xFFFFFFFF);
33 Func => [qw( attrLetsToBits createFile
34 fileConstant fileLastError getLogicalDrives
35 CloseHandle CopyFile CreateFile
36 DefineDosDevice DeleteFile DeviceIoControl
37 FdGetOsFHandle GetDriveType GetFileAttributes GetFileType
38 GetHandleInformation GetLogicalDrives GetLogicalDriveStrings
39 GetOsFHandle GetVolumeInformation IsRecognizedPartition
40 IsContainerPartition MoveFile MoveFileEx
41 OsFHandleOpen OsFHandleOpenFd QueryDosDevice
42 ReadFile SetErrorMode SetFilePointer
43 SetHandleInformation WriteFile GetFileSize
44 getFileSize setFilePointer GetOverlappedResult)],
46 CopyFileA CreateFileA DefineDosDeviceA
47 DeleteFileA GetDriveTypeA GetFileAttributesA GetLogicalDriveStringsA
48 GetVolumeInformationA MoveFileA MoveFileExA
51 CopyFileW CreateFileW DefineDosDeviceW
52 DeleteFileW GetDriveTypeW GetFileAttributesW GetLogicalDriveStringsW
53 GetVolumeInformationW MoveFileW MoveFileExW
56 CREATE_ALWAYS CREATE_NEW FILE_BEGIN
57 FILE_CURRENT FILE_END INVALID_HANDLE_VALUE
58 OPEN_ALWAYS OPEN_EXISTING TRUNCATE_EXISTING )],
60 DDD_EXACT_MATCH_ON_REMOVE DDD_RAW_TARGET_PATH
61 DDD_REMOVE_DEFINITION )],
63 DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE
64 DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM
67 FILE_READ_DATA FILE_LIST_DIRECTORY
68 FILE_WRITE_DATA FILE_ADD_FILE
69 FILE_APPEND_DATA FILE_ADD_SUBDIRECTORY
70 FILE_CREATE_PIPE_INSTANCE FILE_READ_EA
71 FILE_WRITE_EA FILE_EXECUTE
72 FILE_TRAVERSE FILE_DELETE_CHILD
73 FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES
74 FILE_ALL_ACCESS FILE_GENERIC_READ
75 FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE )],
76 FILE_ATTRIBUTE_ => [qw(
77 INVALID_FILE_ATTRIBUTES
78 FILE_ATTRIBUTE_DEVICE FILE_ATTRIBUTE_DIRECTORY
79 FILE_ATTRIBUTE_ENCRYPTED FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
80 FILE_ATTRIBUTE_REPARSE_POINT FILE_ATTRIBUTE_SPARSE_FILE
81 FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED
82 FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL
83 FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY
84 FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY )],
86 FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_DELETE_ON_CLOSE
87 FILE_FLAG_NO_BUFFERING FILE_FLAG_OVERLAPPED
88 FILE_FLAG_POSIX_SEMANTICS FILE_FLAG_RANDOM_ACCESS
89 FILE_FLAG_SEQUENTIAL_SCAN FILE_FLAG_WRITE_THROUGH
90 FILE_FLAG_OPEN_REPARSE_POINT )],
92 FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE )],
94 FILE_TYPE_CHAR FILE_TYPE_DISK FILE_TYPE_PIPE
97 FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE
98 FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS
99 FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED )],
101 FSCTL_SET_REPARSE_POINT FSCTL_GET_REPARSE_POINT
102 FSCTL_DELETE_REPARSE_POINT )],
104 HANDLE_FLAG_INHERIT HANDLE_FLAG_PROTECT_FROM_CLOSE )],
105 IOCTL_STORAGE_ => [qw(
106 IOCTL_STORAGE_CHECK_VERIFY IOCTL_STORAGE_MEDIA_REMOVAL
107 IOCTL_STORAGE_EJECT_MEDIA IOCTL_STORAGE_LOAD_MEDIA
108 IOCTL_STORAGE_RESERVE IOCTL_STORAGE_RELEASE
109 IOCTL_STORAGE_FIND_NEW_DEVICES IOCTL_STORAGE_GET_MEDIA_TYPES
112 IOCTL_DISK_FORMAT_TRACKS IOCTL_DISK_FORMAT_TRACKS_EX
113 IOCTL_DISK_GET_DRIVE_GEOMETRY IOCTL_DISK_GET_DRIVE_LAYOUT
114 IOCTL_DISK_GET_MEDIA_TYPES IOCTL_DISK_GET_PARTITION_INFO
115 IOCTL_DISK_HISTOGRAM_DATA IOCTL_DISK_HISTOGRAM_RESET
116 IOCTL_DISK_HISTOGRAM_STRUCTURE IOCTL_DISK_IS_WRITABLE
117 IOCTL_DISK_LOGGING IOCTL_DISK_PERFORMANCE
118 IOCTL_DISK_REASSIGN_BLOCKS IOCTL_DISK_REQUEST_DATA
119 IOCTL_DISK_REQUEST_STRUCTURE IOCTL_DISK_SET_DRIVE_LAYOUT
120 IOCTL_DISK_SET_PARTITION_INFO IOCTL_DISK_VERIFY )],
122 GENERIC_ALL GENERIC_EXECUTE
123 GENERIC_READ GENERIC_WRITE )],
125 Unknown F5_1Pt2_512 F3_1Pt44_512
126 F3_2Pt88_512 F3_20Pt8_512 F3_720_512
127 F5_360_512 F5_320_512 F5_320_1024
128 F5_180_512 F5_160_512 RemovableMedia
129 FixedMedia F3_120M_512 )],
131 MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT
132 MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH )],
134 SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING
135 SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY
136 SECURITY_IDENTIFICATION SECURITY_IMPERSONATION
137 SECURITY_SQOS_PRESENT )],
139 SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX
140 SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX )],
142 PARTITION_ENTRY_UNUSED PARTITION_FAT_12
143 PARTITION_XENIX_1 PARTITION_XENIX_2
144 PARTITION_FAT_16 PARTITION_EXTENDED
145 PARTITION_HUGE PARTITION_IFS
146 PARTITION_FAT32 PARTITION_FAT32_XINT13
147 PARTITION_XINT13 PARTITION_XINT13_EXTENDED
148 PARTITION_PREP PARTITION_UNIX
149 VALID_NTFT PARTITION_NTFT )],
151 STD_INPUT_HANDLE STD_OUTPUT_HANDLE
157 foreach $key ( keys(%EXPORT_TAGS) ) {
158 push( @EXPORT_OK, @{$EXPORT_TAGS{$key}} );
159 #push( @EXPORT_FAIL, @{$EXPORT_TAGS{$key}} ) unless $key =~ /^Func/;
162 $EXPORT_TAGS{ALL}= \@EXPORT_OK;
164 bootstrap Win32API::File $VERSION;
166 # Preloaded methods go here.
168 # To convert C constants to Perl code in cFile.pc
169 # [instead of C or C++ code in cFile.h]:
170 # * Modify F<Makefile.PL> to add WriteMakeFile() =>
171 # CONST2PERL/postamble => [[ "Win32API::File" => ]] WRITE_PERL => 1.
172 # * Either comment out C<#include "cFile.h"> from F<File.xs>
173 # or make F<cFile.h> an empty file.
174 # * Make sure the following C<if> block is not commented out.
175 # * "nmake clean", "perl Makefile.PL", "nmake"
177 if( ! defined &GENERIC_READ ) {
178 require "Win32API/File/cFile.pc";
184 if( 1 != @_ || ! $name || $name =~ /\W/ ) {
186 Carp::croak( 'Usage: ',__PACKAGE__,'::fileConstant("CONST_NAME")' );
188 my $proto= prototype $name;
198 # We provide this for backwards compatibility:
202 my $value= fileConstant( $name );
203 if( defined $value ) {
212 # my $code= 'return _fileLastError(@_)';
213 # local( $!, $^E )= ( 1, 1 );
216 # local( $^E )= _fileLastError(@_);
221 # eval "sub fileLastError { $code }";
225 package Win32API::File::_error;
230 require Win32 unless defined &Win32::FormatMessage;
231 $_ = Win32::FormatMessage(Win32API::File::_fileLastError());
235 '0+' => sub { Win32API::File::_fileLastError() },
238 sub new { return bless {}, shift }
239 sub set { Win32API::File::_fileLastError($_[1]); return $_[0] }
241 package Win32API::File;
243 my $_error = Win32API::File::_error->new();
246 Carp::croak ('Usage: '.__PACKAGE__.'::fileLastError( [$setWin32ErrCode] )') if @_ > 1;
247 $_error->set($_[0]) if defined $_[0];
251 # Since we ISA DynaLoader which ISA AutoLoader, we ISA AutoLoader so we
252 # need this next chunk to prevent Win32API::File->nonesuch() from
253 # looking for "nonesuch.al" and producing confusing error messages:
254 use vars qw($AUTOLOAD);
258 "Can't locate method $AUTOLOAD via package Win32API::File" );
261 # Replace "&rout;" with "goto &rout;" when that is supported on Win32.
263 # Aliases for non-Unicode functions:
264 sub CopyFile { &CopyFileA; }
265 sub CreateFile { &CreateFileA; }
266 sub DefineDosDevice { &DefineDosDeviceA; }
267 sub DeleteFile { &DeleteFileA; }
268 sub GetDriveType { &GetDriveTypeA; }
269 sub GetFileAttributes { &GetFileAttributesA; }
270 sub GetLogicalDriveStrings { &GetLogicalDriveStringsA; }
271 sub GetVolumeInformation { &GetVolumeInformationA; }
272 sub MoveFile { &MoveFileA; }
273 sub MoveFileEx { &MoveFileExA; }
274 sub QueryDosDevice { &QueryDosDeviceA; }
278 Carp::croak ('Win32API::File Usage: '.
279 'OsFHandleOpen(FILE,$hNativeHandle,"rwatb")');
281 my( $fh, $osfh, $access )= @_;
283 if( $fh !~ /('|::)/ ) {
284 $fh= caller() . "::" . $fh;
290 if( $access =~ /r/i ) {
291 if( $access =~ /w/i ) {
299 if( $access =~ /w/i ) {
303 # croak qq<Win32API::File::OsFHandleOpen(): >,
304 # qq<Access ($access) missing both "r" and "w">;
309 $mode |= O_APPEND if $access =~ /a/i;
310 #$mode |= O_TEXT if $access =~ /t/i;
311 # Some versions of the Fcntl module are broken and won't autoload O_TEXT:
312 if( $access =~ /t/i ) {
313 my $o_text= eval "O_TEXT";
314 $o_text= 0x4000 if $@;
317 $mode |= O_BINARY if $access =~ /b/i;
318 my $fd = eval { OsFHandleOpenFd( $osfh, $mode ) };
320 return tie *{$fh}, __PACKAGE__, $osfh;
322 return undef unless $fd;
323 return open( $fh, $pref."&=".(0+$fd) );
328 Carp::croak ('Win32API::File Usage: $OsFHandle= GetOsFHandle(FILE)');
332 if( $file !~ /('|::)/ ) {
333 $file= caller() . "::" . $file;
336 # The eval "" is necessary in Perl 5.6, avoid it otherwise.
337 my $tied = !defined($^]) || $^] < 5.008
338 ? eval "tied *{$file}"
341 if (UNIVERSAL::isa($tied => __PACKAGE__)) {
342 return $tied->win32_handle;
347 my( $fd )= fileno($file);
348 if( ! defined( $fd ) ) {
349 if( $file =~ /^\d+\Z/ ) {
352 return (); # $! should be set by fileno().
355 my $h= FdGetOsFHandle( $fd );
356 if( INVALID_HANDLE_VALUE() == $h ) {
358 } elsif( "0" eq $h ) {
365 Carp::croak ('Win32API::File Usage: $size= getFileSize($hNativeHandle)')
371 my $low_size = GetFileSize($handle, $high_size);
373 my $retval = $_64BITINT ? $high_size : Math::BigInt->new($high_size);
375 $retval <<= $THIRTY_TWO;
376 $retval += $low_size;
382 Carp::croak ('Win32API::File Usage: $pos= setFilePointer($hNativeHandle, $posl, $from_where)')
385 my ($handle, $pos, $from_where) = @_;
387 my ($pos_low, $pos_high) = ($pos, 0);
390 $pos_low = ($pos & $FFFFFFFF);
391 $pos_high = (($pos >> $THIRTY_TWO) & $FFFFFFFF);
393 elsif (UNIVERSAL::isa($pos => 'Math::BigInt')) {
394 $pos_low = ($pos & $FFFFFFFF)->numify();
395 $pos_high = (($pos >> $THIRTY_TWO) & $FFFFFFFF)->numify();
398 my $retval = SetFilePointer($handle, $pos_low, $pos_high, $from_where);
400 if (defined $pos_high && $pos_high != 0) {
402 $retval = Math::BigInt->new($retval);
403 $pos_high = Math::BigInt->new($pos_high);
406 $retval += $pos_high << $THIRTY_TWO;
416 "a"=>FILE_ATTRIBUTE_ARCHIVE(), "c"=>FILE_ATTRIBUTE_COMPRESSED(),
417 "h"=>FILE_ATTRIBUTE_HIDDEN(), "o"=>FILE_ATTRIBUTE_OFFLINE(),
418 "r"=>FILE_ATTRIBUTE_READONLY(), "s"=>FILE_ATTRIBUTE_SYSTEM(),
419 "t"=>FILE_ATTRIBUTE_TEMPORARY() );
421 foreach( split(//,$lets) ) {
422 Carp::croak ("Win32API::File::attrLetsToBits: Unknown attribute letter ($_)")
423 unless exists $a{$_};
429 use vars qw( @_createFile_Opts %_createFile_Opts );
430 @_createFile_Opts= qw( Access Create Share Attributes
431 Flags Security Model );
432 @_createFile_Opts{@_createFile_Opts}= (1) x @_createFile_Opts;
437 if( 2 <= @_ && "HASH" eq ref($_[$#_]) ) {
440 my( $sPath, $svAccess, $svShare )= @_;
441 if( @_ < 1 || 3 < @_ ) {
442 Carp::croak ("Win32API::File::createFile() usage: \$hObject= createFile(\n",
443 " \$sPath, [\$svAccess_qrw_ktn_ce,[\$svShare_rwd,]]",
444 " [{Option=>\$Value}] )\n",
445 " options: @_createFile_Opts\nCalled");
447 my( $create, $flags, $sec, $model )= ( "", 0, [], 0 );
449 my @err= grep( ! $_createFile_Opts{$_}, keys(%$opts) );
450 @err and Carp::croak ("_createFile: Invalid options (@err)");
451 $flags= $opts->{Flags} if exists( $opts->{Flags} );
452 $flags |= attrLetsToBits( $opts->{Attributes} )
453 if exists( $opts->{Attributes} );
454 $sec= $opts->{Security} if exists( $opts->{Security} );
455 $model= $opts->{Model} if exists( $opts->{Model} );
456 $svAccess= $opts->{Access} if exists( $opts->{Access} );
457 $create= $opts->{Create} if exists( $opts->{Create} );
458 $svShare= $opts->{Share} if exists( $opts->{Share} );
460 $svAccess= "r" unless defined($svAccess);
461 $svShare= "rw" unless defined($svShare);
462 if( $svAccess =~ /^[qrw ktn ce]*$/i ) {
463 ( my $c= $svAccess ) =~ tr/qrw QRW//d;
464 $create= $c if "" ne $c && "" eq $create;
465 local( $_ )= $svAccess;
467 $svAccess |= GENERIC_READ() if /r/i;
468 $svAccess |= GENERIC_WRITE() if /w/i;
469 } elsif( "?" eq $svAccess ) {
471 ("Win32API::File::createFile: \$svAccess can use the following:\n",
472 " One or more of the following:\n",
473 "\tq -- Query access (same as 0)\n",
474 "\tr -- Read access (GENERIC_READ)\n",
475 "\tw -- Write access (GENERIC_WRITE)\n",
476 " At most one of the following:\n",
477 "\tk -- Keep if exists\n",
478 "\tt -- Truncate if exists\n",
479 "\tn -- New file only (fail if file already exists)\n",
480 " At most one of the following:\n",
481 "\tc -- Create if doesn't exist\n",
482 "\te -- Existing file only (fail if doesn't exist)\n",
483 " '' is the same as 'q k e'\n",
484 " 'r' is the same as 'r k e'\n",
485 " 'w' is the same as 'w t c'\n",
486 " 'rw' is the same as 'rw k c'\n",
487 " 'rt' or 'rn' implies 'c'.\n",
488 " Or \$svAccess can be numeric.\n", "Called from");
489 } elsif( $svAccess == 0 && $svAccess !~ /^[-+.]*0/ ) {
490 Carp::croak ("Win32API::File::createFile: Invalid \$svAccess ($svAccess)");
492 if( $create =~ /^[ktn ce]*$/ ) {
493 local( $_ )= $create;
494 my( $k, $t, $n, $c, $e )= ( scalar(/k/i), scalar(/t/i),
495 scalar(/n/i), scalar(/c/i), scalar(/e/i) );
496 if( 1 < $k + $t + $n ) {
497 Carp::croak ("Win32API::File::createFile: \$create must not use ",
498 qq<more than one of "k", "t", and "n" ($create)>);
501 Carp::croak ("Win32API::File::createFile: \$create must not use ",
502 qq<both "c" and "e" ($create)>);
504 my $r= ( $svAccess & GENERIC_READ() ) == GENERIC_READ();
505 my $w= ( $svAccess & GENERIC_WRITE() ) == GENERIC_WRITE();
506 if( ! $k && ! $t && ! $n ) {
507 if( $w && ! $r ) { $t= 1;
511 if( $c || $w && ! $e ) { $create= OPEN_ALWAYS();
512 } else { $create= OPEN_EXISTING(); }
514 if( $e ) { $create= TRUNCATE_EXISTING();
515 } else { $create= CREATE_ALWAYS(); }
517 if( ! $e ) { $create= CREATE_NEW();
519 Carp::croak ("Win32API::File::createFile: \$create must not use ",
520 qq<both "n" and "e" ($create)>);
523 } elsif( "?" eq $create ) {
524 Carp::croak ('Win32API::File::createFile: $create !~ /^[ktn ce]*$/;',
525 ' pass $svAccess as "?" for more information.');
526 } elsif( $create == 0 && $create ne "0" ) {
527 Carp::croak ("Win32API::File::createFile: Invalid \$create ($create)");
529 if( $svShare =~ /^[drw]*$/ ) {
530 my %s= ( "d"=>FILE_SHARE_DELETE(), "r"=>FILE_SHARE_READ(),
531 "w"=>FILE_SHARE_WRITE() );
532 my @s= split(//,$svShare);
537 } elsif( $svShare == 0 && $svShare !~ /^[-+.]*0/ ) {
538 Carp::croak ("Win32API::File::createFile: Invalid \$svShare ($svShare)");
541 $sPath, $svAccess, $svShare, $sec, $create, $flags, $model );
549 if( ! GetLogicalDriveStringsA( 256, $s ) ) {
552 if( ! defined($ref) ) {
553 return split( /\0/, $s );
554 } elsif( "ARRAY" ne ref($ref) ) {
555 Carp::croak ('Usage: C<@arr= getLogicalDrives()> ',
556 'or C<getLogicalDrives(\\@arr)>', "\n");
558 @$ref= split( /\0/, $s );
562 ###############################################################################
563 # Experimental Tied Handle and Object Oriented interface. #
564 ###############################################################################
568 $class = ref $class || $class;
570 my $self = IO::File::new($class);
571 tie *$self, __PACKAGE__;
573 $self->open(@_) if @_;
579 my ($class, $win32_handle) = @_;
580 $class = ref $class || $class;
583 _win32_handle => $win32_handle,
594 # This is called for getting the tied object from hard refs to glob refs in
595 # some cases, for reasons I don't quite grok.
597 sub FETCH { return $_[0] }
601 sub win32_handle{ $_[0]->{_win32_handle}||= $_[1] }
603 # Protected accessors
605 sub _buffer { $_[0]->{_buffer} ||= $_[1] }
606 sub _binmode { $_[0]->{_binmode} ||= $_[1] }
607 sub _fileno { $_[0]->{_fileno} ||= $_[1] }
608 sub _access { $_[0]->{_access} ||= $_[1] }
609 sub _append { $_[0]->{_append} ||= $_[1] }
616 Carp::croak ("Only the two argument form of open is supported at this time") if @_;
617 # FIXME: this needs to parse the full Perl open syntax in $expr
619 my ($mixed, $mode, $path) =
620 ($expr =~ /^\s* (\+)? \s* (<|>|>>)? \s* (.*?) \s*$/x);
622 Carp::croak ("Unsupported open mode") if not $path;
625 my $append = $mode eq '>>' ? 1 : 0;
629 } elsif($mode eq '>') {
633 my $w32_handle = createFile($path, $access);
635 $self->win32_handle($w32_handle);
637 $self->seek(1,2) if $append;
639 $self->_access($access);
640 $self->_append($append);
650 my ($self, $buf, $len, $offset, $overlap) = @_;
653 $buf = substr($buf, $offset);
657 $len = length($buf) if not defined $len;
659 $overlap = [] if not defined $overlap;;
661 my $bytes_written = 0;
664 $self->win32_handle, $buf, $len,
665 $bytes_written, $overlap
668 return $bytes_written;
674 my $buf = join defined $, ? $, : "" => @_;
676 $buf =~ s/\012/\015\012/sg unless $self->_binmode();
678 $buf .= $\ if defined $\;
680 $self->WRITE($buf, length($buf), 0);
685 my $into = \$_[0]; shift;
686 my ($len, $offset, $overlap) = @_;
688 my $buffer = defined $self->_buffer ? $self->_buffer : "";
689 my $buf_length = length($buffer);
692 $offset = 0 if not defined $offset;
694 if ($buf_length >= $len) {
695 $data = substr($buffer, 0, $len => "");
697 $self->_buffer($buffer);
699 if ($buf_length > 0) {
701 substr($$into, $offset) = $buffer;
702 $offset += $buf_length;
708 $self->win32_handle, $data, $len,
709 $bytes_read, $overlap
713 $$into = "" if not defined $$into;
715 substr($$into, $offset) = $data;
724 while ((index $line, $/) == -1) { # read until end of line marker
725 my $char = $self->GETC();
727 last if !defined $char || $char eq '';
732 return undef if $line eq '';
741 return $self->_fileno() if defined $self->_fileno();
743 return -1 if $^O eq 'cygwin';
745 # FIXME: We don't always open the handle, better to query the handle or to set
746 # the right access info at TIEHANDLE time.
748 my $access = $self->_access();
749 my $mode = $access eq 'rw' ? O_RDWR :
750 $access eq 'w' ? O_WRONLY : O_RDONLY;
752 $mode |= O_APPEND if $self->_append();
754 $mode |= O_TEXT if not $self->_binmode();
756 return $self->_fileno ( OsfHandleOpenFd (
757 $self->win32_handle, $mode
762 my ($self, $pos, $whence) = @_;
764 $whence = 0 if not defined $whence;
765 my @file_consts = map {
767 } qw(FILE_BEGIN FILE_CURRENT FILE_END);
769 my $from_where = $file_consts[$whence];
771 return setFilePointer($self->win32_handle, $pos, $from_where);
775 # SetFilePointer with position 0 at FILE_CURRENT will return position.
776 return $_[0]->SEEK(0, 1);
782 my $current = $self->TELL() + 0;
783 my $end = getFileSize($self->win32_handle) + 0;
785 return $current == $end;
793 if (defined $self->win32_handle) {
794 $retval = CloseHandle($self->win32_handle);
796 $self->win32_handle(undef);
802 # Only close the handle on explicit close, too many problems otherwise.
807 # End of Tie/OO Interface
809 # Autoload methods go after =cut, and are processed by the autosplit program.
816 Win32API::File - Low-level access to Win32 system API calls for files/dirs.
820 use Win32API::File 0.08 qw( :ALL );
822 MoveFile( $Source, $Destination )
823 or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
824 MoveFileEx( $Source, $Destination, MOVEFILE_REPLACE_EXISTING() )
825 or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
830 This provides fairly low-level access to the Win32 System API
831 calls dealing with files and directories.
833 To pass in C<NULL> as the pointer to an optional buffer, pass in
834 an empty list reference, C<[]>.
836 Beyond raw access to the API calls and related constants, this module
837 handles smart buffer allocation and translation of return codes.
839 All functions, unless otherwise noted, return a true value for success
840 and a false value for failure and set C<$^E> on failure.
842 =head2 Object Oriented/Tied Handle Interface
844 WARNING: this is new code, use at your own risk.
846 This version of C<Win32API::File> can be used like an C<IO::File> object:
848 my $file = Win32API::File->new("+> foo");
850 print $file "hello there\n";
855 It also supports tying via a win32 handle (for example, from C<createFile()>):
857 tie FILE, 'Win32API::File', $win32_handle;
860 It has not been extensively tested yet and buffered I/O is not yet implemented.
864 Nothing is exported by default. The following tags can be used to
865 have large sets of symbols exported: C<":Func">, C<":FuncA">,
866 C<":FuncW">, C<":Misc">, C<":DDD_">, C<":DRIVE_">, C<":FILE_">,
867 C<":FILE_ATTRIBUTE_">, C<":FILE_FLAG_">, C<":FILE_SHARE_">,
868 C<":FILE_TYPE_">, C<":FS_">, C<":FSCTL_">, C<":HANDLE_FLAG_">,
869 C<":IOCTL_STORAGE_">, C<":IOCTL_DISK_">, C<":GENERIC_">,
870 C<":MEDIA_TYPE">, C<":MOVEFILE_">, C<":SECURITY_">, C<":SEM_">,
871 and C<":PARTITION_">.
877 The basic function names: C<attrLetsToBits>, C<createFile>,
878 C<fileConstant>, C<fileLastError>, C<getLogicalDrives>,
879 C<setFilePointer>, C<getFileSize>,
880 C<CloseHandle>, C<CopyFile>, C<CreateFile>,
881 C<DefineDosDevice>, C<DeleteFile>, C<DeviceIoControl>,
882 C<FdGetOsFHandle>, C<GetDriveType>, C<GetFileAttributes>,
883 C<GetFileSize>, C<GetFileType>, C<GetHandleInformation>,
884 C<GetLogicalDrives>, C<GetLogicalDriveStrings>, C<GetOsFHandle>,
885 C<GetOverlappedResult>, C<GetVolumeInformation>, C<IsContainerPartition>,
886 C<IsRecognizedPartition>, C<MoveFile>, C<MoveFileEx>,
887 C<OsFHandleOpen>, C<OsFHandleOpenFd>, C<QueryDosDevice>,
888 C<ReadFile>, C<SetErrorMode>, C<SetFilePointer>,
889 C<SetHandleInformation>, and C<WriteFile>.
895 =item C<$uBits= attrLetsToBits( $sAttributeLetters )>
897 Converts a string of file attribute letters into an unsigned value with
898 the corresponding bits set. C<$sAttributeLetters> should contain zero
899 or more letters from C<"achorst">:
905 C<FILE_ATTRIBUTE_ARCHIVE>
909 C<FILE_ATTRIBUTE_COMPRESSED>
913 C<FILE_ATTRIBUTE_HIDDEN>
917 C<FILE_ATTRIBUTE_OFFLINE>
921 C<FILE_ATTRIBUTE_READONLY>
925 C<FILE_ATTRIBUTE_SYSTEM>
929 C<FILE_ATTRIBUTE_TEMPORARY>
935 =item C<$hObject= createFile( $sPath )>
937 =item C<$hObject= createFile( $sPath, $rvhvOptions )>
939 =item C<$hObject= createFile( $sPath, $svAccess )>
941 =item C<$hObject= createFile( $sPath, $svAccess, $rvhvOptions )>
943 =item C<$hObject= createFile( $sPath, $svAccess, $svShare )>
945 =item C<$hObject= createFile( $sPath, $svAccess, $svShare, $rvhvOptions )>
947 This is a Perl-friendly wrapper around C<CreateFile>.
949 On failure, C<$hObject> gets set to a false value and C<regLastError()>
950 and C<$^E> are set to the reason for the failure. Otherwise,
951 C<$hObject> gets set to a Win32 native file handle which is always
952 a true value [returns C<"0 but true"> in the impossible(?) case of
953 the handle having a value of C<0>].
955 C<$sPath> is the path to the file [or device, etc.] to be opened. See
956 C<CreateFile> for more information on possible special values for
959 C<$svAccess> can be a number containing the bit mask representing
960 the specific type(s) of access to the file that you desire. See the
961 C<$uAccess> parameter to C<CreateFile> for more information on these
964 More likely, C<$svAccess> is a string describing the generic type of
965 access you desire and possibly the file creation options to use. In
966 this case, C<$svAccess> should contain zero or more characters from
967 C<"qrw"> [access desired], zero or one character each from C<"ktn">
968 and C<"ce">, and optional white space. These letters stand for,
969 respectively, "Query access", "Read access", "Write access", "Keep if
970 exists", "Truncate if exists", "New file only", "Create if none", and
971 "Existing file only". Case is ignored.
973 You can pass in C<"?"> for C<$svAccess> to have an error message
974 displayed summarizing its possible values. This is very handy when
975 doing on-the-fly programming using the Perl debugger:
977 Win32API::File::createFile: $svAccess can use the following:
978 One or more of the following:
979 q -- Query access (same as 0)
980 r -- Read access (GENERIC_READ)
981 w -- Write access (GENERIC_WRITE)
982 At most one of the following:
984 t -- Truncate if exists
985 n -- New file only (fail if file already exists)
986 At most one of the following:
987 c -- Create if doesn't exist
988 e -- Existing file only (fail if doesn't exist)
989 '' is the same as 'q k e'
990 'r' is the same as 'r k e'
991 'w' is the same as 'w t c'
992 'rw' is the same as 'rw k c'
993 'rt' or 'rn' implies 'c'.
994 Or $access can be numeric.
996 C<$svAccess> is designed to be "do what I mean", so you can skip
997 the rest of its explanation unless you are interested in the complex
998 details. Note that, if you want write access to a device, you need
999 to specify C<"k"> [and perhaps C<"e">, as in C<"w ke"> or C<"rw ke">]
1000 since Win32 suggests C<OPEN_EXISTING> be used when opening a device.
1006 Stands for "Query access". This is really a no-op since you always have
1007 query access when you open a file. You can specify C<"q"> to document
1008 that you plan to query the file [or device, etc.]. This is especially
1009 helpful when you don't want read nor write access since something like
1010 C<"q"> or C<"q ke"> may be easier to understand than just C<""> or C<"ke">.
1014 Stands for "Read access". Sets the C<GENERIC_READ> bit(s) in the
1015 C<$uAccess> that is passed to C<CreateFile>. This is the default
1016 access if the C<$svAccess> parameter is missing [or if it is C<undef>
1017 and C<$rvhvOptions> doesn't specify an C<"Access"> option].
1021 Stands for "Write access". Sets the C<GENERIC_WRITE> bit(s) in the
1022 C<$uAccess> that is passed to C<CreateFile>.
1026 Stands for "Keep if exists". If the requested file exists, then it is
1027 opened. This is the default unless C<GENERIC_WRITE> access has been
1028 requested but C<GENERIC_READ> access has not been requested. Contrast
1029 with C<"t"> and C<"n">.
1033 Stands for "Truncate if exists". If the requested file exists, then
1034 it is truncated to zero length and then opened. This is the default if
1035 C<GENERIC_WRITE> access has been requested and C<GENERIC_READ> access
1036 has not been requested. Contrast with C<"k"> and C<"n">.
1040 Stands for "New file only". If the requested file exists, then it is
1041 not opened and the C<createFile> call fails. Contrast with C<"k"> and
1042 C<"t">. Can't be used with C<"e">.
1046 Stands for "Create if none". If the requested file does not
1047 exist, then it is created and then opened. This is the default
1048 if C<GENERIC_WRITE> access has been requested or if C<"t"> or
1049 C<"n"> was specified. Contrast with C<"e">.
1053 Stands for "Existing file only". If the requested file does not
1054 exist, then nothing is opened and the C<createFile> call fails. This
1055 is the default unless C<GENERIC_WRITE> access has been requested or
1056 C<"t"> or C<"n"> was specified. Contrast with C<"c">. Can't be
1061 The characters from C<"ktn"> and C<"ce"> are combined to determine the
1062 what value for C<$uCreate> to pass to C<CreateFile> [unless overridden
1063 by C<$rvhvOptions>]:
1077 C<TRUNCATE_EXISTING>
1093 C<$svShare> controls how the file is shared, that is, whether other
1094 processes can have read, write, and/or delete access to the file while
1095 we have it opened. C<$svShare> will usually be a string containing zero
1096 or more characters from C<"rwd"> but can also be a numeric bit mask.
1098 C<"r"> sets the C<FILE_SHARE_READ> bit which allows other processes to have
1099 read access to the file. C<"w"> sets the C<FILE_SHARE_WRITE> bit which
1100 allows other processes to have write access to the file. C<"d"> sets the
1101 C<FILE_SHARE_DELETE> bit which allows other processes to have delete access
1102 to the file [ignored under Windows 95].
1104 The default for C<$svShare> is C<"rw"> which provides the same sharing as
1105 using regular perl C<open()>.
1107 If another process currently has read, write, and/or delete access to
1108 the file and you don't allow that level of sharing, then your call to
1109 C<createFile> will fail. If you requested read, write, and/or delete
1110 access and another process already has the file open but doesn't allow
1111 that level of sharing, then your call to C<createFile> will fail. Once
1112 you have the file open, if another process tries to open it with read,
1113 write, and/or delete access and you don't allow that level of sharing,
1114 then that process won't be allowed to open the file.
1116 C<$rvhvOptions> is a reference to a hash where any keys must be from
1117 the list C<qw( Access Create Share Attributes Flags Security Model )>.
1118 The meaning of the value depends on the key name, as described below.
1119 Any option values in C<$rvhvOptions> override the settings from
1120 C<$svAccess> and C<$svShare> if they conflict.
1124 =item Flags => $uFlags
1126 C<$uFlags> is an unsigned value having any of the C<FILE_FLAG_*> or
1127 C<FILE_ATTRIBUTE_*> bits set. Any C<FILE_ATTRIBUTE_*> bits set via the
1128 C<Attributes> option are logically C<or>ed with these bits. Defaults
1131 If opening the client side of a named pipe, then you can also specify
1132 C<SECURITY_SQOS_PRESENT> along with one of the other C<SECURITY_*>
1133 constants to specify the security quality of service to be used.
1135 =item Attributes => $sAttributes
1137 A string of zero or more characters from C<"achorst"> [see C<attrLetsToBits>
1138 for more information] which are converted to C<FILE_ATTRIBUTE_*> bits to
1139 be set in the C<$uFlags> argument passed to C<CreateFile>.
1141 =item Security => $pSecurityAttributes
1143 C<$pSecurityAttributes> should contain a C<SECURITY_ATTRIBUTES> structure
1144 packed into a string or C<[]> [the default].
1146 =item Model => $hModelFile
1148 C<$hModelFile> should contain a handle opened with C<GENERIC_READ>
1149 access to a model file from which file attributes and extended attributes
1150 are to be copied. Or C<$hModelFile> can be C<0> [the default].
1152 =item Access => $sAccess
1154 =item Access => $uAccess
1156 C<$sAccess> should be a string of zero or more characters from
1157 C<"qrw"> specifying the type of access desired: "query" or C<0>,
1158 "read" or C<GENERIC_READ> [the default], or "write" or
1161 C<$uAccess> should be an unsigned value containing bits set to
1162 indicate the type of access desired. C<GENERIC_READ> is the default.
1164 =item Create => $sCreate
1166 =item Create => $uCreate
1168 C<$sCreate> should be a string containing zero or one character from
1169 C<"ktn"> and zero or one character from C<"ce">. These stand for
1170 "Keep if exists", "Truncate if exists", "New file only", "Create if
1171 none", and "Existing file only". These are translated into a
1174 C<$uCreate> should be one of C<OPEN_ALWAYS>, C<OPEN_EXISTING>,
1175 C<TRUNCATE_EXISTING>, C<CREATE_ALWAYS>, or C<CREATE_NEW>.
1177 =item Share => $sShare
1179 =item Share => $uShare
1181 C<$sShare> should be a string with zero or more characters from
1182 C<"rwd"> that is translated into a C<$uShare> value. C<"rw"> is
1185 C<$uShare> should be an unsigned value having zero or more of the
1186 following bits set: C<FILE_SHARE_READ>, C<FILE_SHARE_WRITE>, and
1187 C<FILE_SHARE_DELETE>. C<FILE_SHARE_READ|FILE_SHARE_WRITE> is the
1194 $hFlop= createFile( "//./A:", "r", "r" )
1195 or die "Can't prevent others from writing to floppy: $^E\n";
1196 $hDisk= createFile( "//./C:", "rw ke", "" )
1197 or die "Can't get exclusive access to C: $^E\n";
1198 $hDisk= createFile( $sFilePath, "ke",
1199 { Access=>FILE_READ_ATTRIBUTES } )
1200 or die "Can't read attributes of $sFilePath: $^E\n";
1201 $hTemp= createFile( "$ENV{Temp}/temp.$$", "wn", "",
1202 { Attributes=>"hst", Flags=>FILE_FLAG_DELETE_ON_CLOSE() } )
1203 or die "Can't create temporary file, temp.$$: $^E\n";
1205 =item getLogicalDrives
1207 =item C<@roots= getLogicalDrives()>
1209 Returns the paths to the root directories of all logical drives
1210 currently defined. This includes all types of drive letters, such
1211 as floppies, CD-ROMs, hard disks, and network shares. A typical
1212 return value on a poorly equipped computer would be C<("A:\\","C:\\")>.
1216 =item C<CloseHandle( $hObject )>
1218 Closes a Win32 native handle, such as one opened via C<CreateFile>.
1219 Like most routines, returns a true value if successful and a false
1220 value [and sets C<$^E> and C<regLastError()>] on failure.
1224 =item C<CopyFile( $sOldFileName, $sNewFileName, $bFailIfExists )>
1226 C<$sOldFileName> is the path to the file to be copied.
1227 C<$sNewFileName> is the path to where the file should be copied.
1228 Note that you can B<NOT> just specify a path to a directory in
1229 C<$sNewFileName> to copy the file to that directory using the
1232 If C<$bFailIfExists> is true and C<$sNewFileName> is the path to
1233 a file that already exists, then C<CopyFile> will fail. If
1234 C<$bFailIfExists> is false, then the copy of the C<$sOldFileNmae>
1235 file will overwrite the C<$sNewFileName> file if it already exists.
1237 Like most routines, returns a true value if successful and a false
1238 value [and sets C<$^E> and C<regLastError()>] on failure.
1242 =item C<$hObject= CreateFile( $sPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel )>
1244 On failure, C<$hObject> gets set to a false value and C<$^E> and
1245 C<fileLastError()> are set to the reason for the failure. Otherwise,
1246 C<$hObject> gets set to a Win32 native file handle which is always a
1247 true value [returns C<"0 but true"> in the impossible(?) case of the
1248 handle having a value of C<0>].
1250 C<$sPath> is the path to the file [or device, etc.] to be opened.
1252 C<$sPath> can use C<"/"> or C<"\\"> as path delimiters and can even
1253 mix the two. We will usually only use C<"/"> in our examples since
1254 using C<"\\"> is usually harder to read.
1256 Under Windows NT, C<$sPath> can start with C<"//?/"> to allow the use
1257 of paths longer than C<MAX_PATH> [for UNC paths, replace the leading
1258 C<"//"> with C<"//?/UNC/">, as in C<"//?/UNC/Server/Share/Dir/File.Ext">].
1260 C<$sPath> can start with C<"//./"> to indicate that the rest of the
1261 path is the name of a "DOS device." You can use C<QueryDosDevice>
1262 to list all current DOS devices and can add or delete them with
1263 C<DefineDosDevice>. If you get the source-code distribution of this
1264 module from CPAN, then it includes an example script, F<ex/ListDevs.plx>
1265 that will list all current DOS devices and their "native" definition.
1266 Again, note that this doesn't work under Win95 nor Win98.
1268 The most common such DOS devices include:
1272 =item C<"//./PhysicalDrive0">
1274 Your entire first hard disk. Doesn't work under Windows 95. This
1275 allows you to read or write raw sectors of your hard disk and to use
1276 C<DeviceIoControl> to perform miscellaneous queries and operations
1277 to the hard disk. Writing raw sectors and certain other operations
1278 can seriously damage your files or the function of your computer.
1280 Locking this for exclusive access [by specifying C<0> for C<$uShare>]
1281 doesn't prevent access to the partitions on the disk nor their file
1282 systems. So other processes can still access any raw sectors within
1283 a partition and can use the file system on the disk as usual.
1287 Your F<C:> partition. Doesn't work under Windows 95. This allows
1288 you to read or write raw sectors of that partition and to use
1289 C<DeviceIoControl> to perform miscellaneous queries and operations
1290 to the partition. Writing raw sectors and certain other operations
1291 can seriously damage your files or the function of your computer.
1293 Locking this for exclusive access doesn't prevent access to the
1294 physical drive that the partition is on so other processes can
1295 still access the raw sectors that way. Locking this for exclusive
1296 access B<does> prevent other processes from opening the same raw
1297 partition and B<does> prevent access to the file system on it. It
1298 even prevents the current process from accessing the file system
1303 The raw floppy disk. Doesn't work under Windows 95. This allows
1304 you to read or write raw sectors of the floppy disk and to use
1305 C<DeviceIoControl> to perform miscellaneous queries and operations
1306 to the floppy disk or drive.
1308 Locking this for exclusive access prevents all access to the floppy.
1310 =item C<"//./PIPE/PipeName">
1312 A named pipe, created via C<CreateNamedPipe>.
1316 C<$uAccess> is an unsigned value with bits set indicating the
1317 type of access desired. Usually either C<0> ["query" access],
1318 C<GENERIC_READ>, C<GENERIC_WRITE>, C<GENERIC_READ|GENERIC_WRITE>,
1319 or C<GENERIC_ALL>. More specific types of access can be specified,
1320 such as C<FILE_APPEND_DATA> or C<FILE_READ_EA>.
1322 C<$uShare> controls how the file is shared, that is, whether other
1323 processes can have read, write, and/or delete access to the file while
1324 we have it opened. C<$uShare> is an unsigned value with zero or more
1325 of these bits set: C<FILE_SHARE_READ>, C<FILE_SHARE_WRITE>, and
1326 C<FILE_SHARE_DELETE>.
1328 If another process currently has read, write, and/or delete access to
1329 the file and you don't allow that level of sharing, then your call to
1330 C<CreateFile> will fail. If you requested read, write, and/or delete
1331 access and another process already has the file open but doesn't allow
1332 that level of sharing, then your call to C<createFile> will fail. Once
1333 you have the file open, if another process tries to open it with read,
1334 write, and/or delete access and you don't allow that level of sharing,
1335 then that process won't be allowed to open the file.
1337 C<$pSecAttr> should either be C<[]> [for C<NULL>] or a
1338 C<SECURITY_ATTRIBUTES> data structure packed into a string.
1339 For example, if C<$pSecDesc> contains a C<SECURITY_DESCRIPTOR>
1340 structure packed into a string, perhaps via:
1342 RegGetKeySecurity( $key, 4, $pSecDesc, 1024 );
1344 then you can set C<$pSecAttr> via:
1346 $pSecAttr= pack( "L P i", 12, $pSecDesc, $bInheritHandle );
1348 C<$uCreate> is one of the following values: C<OPEN_ALWAYS>,
1349 C<OPEN_EXISTING>, C<TRUNCATE_EXISTING>, C<CREATE_ALWAYS>, and
1352 C<$uFlags> is an unsigned value with zero or more bits set indicating
1353 attributes to associate with the file [C<FILE_ATTRIBUTE_*> values] or
1354 special options [C<FILE_FLAG_*> values].
1356 If opening the client side of a named pipe, then you can also set
1357 C<$uFlags> to include C<SECURITY_SQOS_PRESENT> along with one of the
1358 other C<SECURITY_*> constants to specify the security quality of
1361 C<$hModel> is C<0> [or C<[]>, both of which mean C<NULL>] or a Win32
1362 native handle opened with C<GENERIC_READ> access to a model file from
1363 which file attributes and extended attributes are to be copied if a
1364 new file gets created.
1368 $hFlop= CreateFile( "//./A:", GENERIC_READ(),
1369 FILE_SHARE_READ(), [], OPEN_EXISTING(), 0, [] )
1370 or die "Can't prevent others from writing to floppy: $^E\n";
1371 $hDisk= CreateFile( $sFilePath, FILE_READ_ATTRIBUTES(),
1372 FILE_SHARE_READ()|FILE_SHARE_WRITE(), [], OPEN_EXISTING(), 0, [] )
1373 or die "Can't read attributes of $sFilePath: $^E\n";
1374 $hTemp= CreateFile( "$ENV{Temp}/temp.$$", GENERIC_WRITE(), 0,
1375 CREATE_NEW(), FILE_FLAG_DELETE_ON_CLOSE()|attrLetsToBits("hst"), [] )
1376 or die "Can't create temporary file, temp.$$: $^E\n";
1378 =item DefineDosDevice
1380 =item C<DefineDosDevice( $uFlags, $sDosDeviceName, $sTargetPath )>
1382 Defines a new DOS device, overrides the current definition of a DOS
1383 device, or deletes a definition of a DOS device. Like most routines,
1384 returns a true value if successful and a false value [and sets C<$^E>
1385 and C<regLastError()>] on failure.
1387 C<$sDosDeviceName> is the name of a DOS device for which we'd like
1388 to add or delete a definition.
1390 C<$uFlags> is an unsigned value with zero or more of the following
1395 =item C<DDD_RAW_TARGET_PATH>
1397 Indicates that C<$sTargetPath> will be a raw Windows NT object name.
1398 This usually means that C<$sTargetPath> starts with C<"\\Device\\">.
1399 Note that you cannot use C<"/"> in place of C<"\\"> in raw target path
1402 =item C<DDD_REMOVE_DEFINITION>
1404 Requests that a definition be deleted. If C<$sTargetPath> is
1405 C<[]> [for C<NULL>], then the most recently added definition for
1406 C<$sDosDeviceName> is removed. Otherwise the most recently added
1407 definition matching C<$sTargetPath> is removed.
1409 If the last definition is removed, then the DOS device name is
1412 =item C<DDD_EXACT_MATCH_ON_REMOVE>
1414 When deleting a definition, this bit causes each C<$sTargetPath> to
1415 be compared to the full-length definition when searching for the most
1416 recently added match. If this bit is not set, then C<$sTargetPath>
1417 only needs to match a prefix of the definition.
1421 C<$sTargetPath> is the DOS device's specific definition that you
1422 wish to add or delete. For C<DDD_RAW_TARGET_PATH>, these usually
1423 start with C<"\\Device\\">. If the C<DDD_RAW_TARGET_PATH> bit is
1424 not set, then C<$sTargetPath> is just an ordinary path to some file
1425 or directory, providing the functionality of the B<subst> command.
1429 =item C<DeleteFile( $sFileName )>
1431 Deletes the named file. Compared to Perl's C<unlink>, C<DeleteFile>
1432 has the advantage of not deleting read-only files. For B<some>
1433 versions of Perl, C<unlink> silently calls C<chmod> whether it needs
1434 to or not before deleting the file so that files that you have
1435 protected by marking them as read-only are not always protected from
1438 Like most routines, returns a true value if successful and a false
1439 value [and sets C<$^E> and C<regLastError()>] on failure.
1441 =item DeviceIoControl
1443 =item C<DeviceIoControl( $hDevice, $uIoControlCode, $pInBuf, $lInBuf, $opOutBuf, $lOutBuf, $olRetBytes, $pOverlapped )>
1445 Requests a special operation on an I/O [input/output] device, such
1446 as ejecting a tape or formatting a disk. Like most routines, returns
1447 a true value if successful and a false value [and sets C<$^E> and
1448 C<regLastError()>] on failure.
1450 C<$hDevice> is a Win32 native file handle to a device [return value
1451 from C<CreateFile>].
1453 C<$uIoControlCode> is an unsigned value [a C<IOCTL_*> or C<FSCTL_*>
1454 constant] indicating the type query or other operation to be performed.
1456 C<$pInBuf> is C<[]> [for C<NULL>] or a data structure packed into a
1457 string. The type of data structure depends on the C<$uIoControlCode>
1458 value. C<$lInBuf> is C<0> or the length of the structure in
1459 C<$pInBuf>. If C<$pInBuf> is not C<[]> and C<$lInBuf> is C<0>, then
1460 C<$lInBuf> will automatically be set to C<length($pInBuf)> for you.
1462 C<$opOutBuf> is C<[]> [for C<NULL>] or will be set to contain a
1463 returned data structure packed into a string. C<$lOutBuf> indicates
1464 how much space to allocate in C<$opOutBuf> for C<DeviceIoControl> to
1465 store the data structure. If C<$lOutBuf> is a number and C<$opOutBuf>
1466 already has a buffer allocated for it that is larger than C<$lOutBuf>
1467 bytes, then this larger buffer size will be passed to C<DeviceIoControl>.
1468 However, you can force a specific buffer size to be passed to
1469 C<DeviceIoControl> by prepending a C<"="> to the front of C<$lOutBuf>.
1471 C<$olRetBytes> is C<[]> or is a scalar to receive the number of bytes
1472 written to C<$opOutBuf>. Even when C<$olRetBytes> is C<[]>, a valid
1473 pointer to a C<DWORD> [and not C<NULL>] is passed to C<DeviceIoControl>.
1474 In this case, C<[]> just means that you don't care about the value
1475 that might be written to C<$olRetBytes>, which is usually the case
1476 since you can usually use C<length($opOutBuf)> instead.
1478 C<$pOverlapped> is C<[]> or is a C<OVERLAPPED> structure packed into
1479 a string. This is only useful if C<$hDevice> was opened with the
1480 C<FILE_FLAG_OVERLAPPED> flag set.
1482 =item FdGetOsFHandle
1484 =item C<$hNativeHandle= FdGetOsFHandle( $ivFd )>
1486 C<FdGetOsFHandle> simply calls C<_get_osfhandle()>. It was renamed
1487 to better fit in with the rest the function names of this module,
1488 in particular to distinguish it from C<GetOsFHandle>. It takes an
1489 integer file descriptor [as from Perl's C<fileno>] and returns the
1490 Win32 native file handle associated with that file descriptor or
1491 C<INVALID_HANDLE_VALUE> if C<$ivFd> is not an open file descriptor.
1493 When you call Perl's C<open> to set a Perl file handle [like C<STDOUT>],
1494 Perl calls C's C<fopen> to set a stdio C<FILE *>. C's C<fopen> calls
1495 something like Unix's C<open>, that is, Win32's C<_sopen>, to get an
1496 integer file descriptor [where 0 is for C<STDIN>, 1 for C<STDOUT>, etc.].
1497 Win32's C<_sopen> calls C<CreateFile> to set a C<HANDLE>, a Win32 native
1498 file handle. So every Perl file handle [like C<STDOUT>] has an integer
1499 file descriptor associated with it that you can get via C<fileno>. And,
1500 under Win32, every file descriptor has a Win32 native file handle
1501 associated with it. C<FdGetOsFHandle> lets you get access to that.
1503 C<$hNativeHandle> is set to C<INVALID_HANDLE_VALUE> [and
1504 C<lastFileError()> and C<$^E> are set] if C<FdGetOsFHandle> fails.
1505 See also C<GetOsFHandle> which provides a friendlier interface.
1509 =item C<$value= fileConstant( $sConstantName )>
1511 Fetch the value of a constant. Returns C<undef> if C<$sConstantName>
1512 is not the name of a constant supported by this module. Never sets
1515 This function is rarely used since you will usually get the value of a
1516 constant by having that constant imported into your package by listing
1517 the constant name in the C<use Win32API::File> statement and then
1518 simply using the constant name in your code [perhaps followed by
1519 C<()>]. This function is useful for verifying constant names not in
1520 Perl code, for example, after prompting a user to type in a constant
1525 =item C<$svError= fileLastError();>
1527 =item C<fileLastError( $uError );>
1529 Returns the last error encountered by a routine from this module.
1530 It is just like C<$^E> except it isn't changed by anything except
1531 routines from this module. Ideally you could just use C<$^E>, but
1532 current versions of Perl often overwrite C<$^E> before you get a
1533 chance to check it and really old versions of Perl don't really
1534 support C<$^E> under Win32.
1536 Just like C<$^E>, in a numeric context C<fileLastError()> returns
1537 the numeric error value while in a string context it returns a
1538 text description of the error [actually it returns a Perl scalar
1539 that contains both values so C<$x= fileLastError()> causes C<$x>
1540 to give different values in string vs. numeric contexts].
1542 The last form sets the error returned by future calls to
1543 C<fileLastError()> and should not be used often. C<$uError> must
1544 be a numeric error code. Also returns the dual-valued version
1549 =item C<$uDriveType= GetDriveType( $sRootPath )>
1551 Takes a string giving the path to the root directory of a file system
1552 [called a "drive" because every file system is assigned a "drive letter"]
1553 and returns an unsigned value indicating the type of drive the file
1554 system is on. The return value should be one of:
1558 =item C<DRIVE_UNKNOWN>
1560 None of the following.
1562 =item C<DRIVE_NO_ROOT_DIR>
1564 A "drive" that does not have a file system. This can be a drive letter
1565 that hasn't been defined or a drive letter assigned to a partition
1566 that hasn't been formatted yet.
1568 =item C<DRIVE_REMOVABLE>
1570 A floppy diskette drive or other removable media drive, but not a CD-ROM
1573 =item C<DRIVE_FIXED>
1575 An ordinary hard disk partition.
1577 =item C<DRIVE_REMOTE>
1581 =item C<DRIVE_CDROM>
1585 =item C<DRIVE_RAMDISK>
1587 A "ram disk" or memory-resident virtual file system used for high-speed
1588 access to small amounts of temporary file space.
1592 =item GetFileAttributes
1594 =item C<$uAttrs = GetFileAttributes( $sPath )>
1596 Takes a path string and returns an unsigned value with attribute flags.
1597 If it fails, it returns INVALID_FILE_ATTRIBUTES, otherwise it can be
1598 one or more of the following values:
1602 =item C<FILE_ATTRIBUTE_ARCHIVE>
1604 The file or directory is an archive file or directory. Applications use
1605 this attribute to mark files for backup or removal.
1607 =item C<FILE_ATTRIBUTE_COMPRESSED>
1609 The file or directory is compressed. For a file, this means that all of
1610 the data in the file is compressed. For a directory, this means that
1611 compression is the default for newly created files and subdirectories.
1613 =item C<FILE_ATTRIBUTE_DEVICE>
1615 Reserved; do not use.
1617 =item C<FILE_ATTRIBUTE_DIRECTORY>
1619 The handle identifies a directory.
1621 =item C<FILE_ATTRIBUTE_ENCRYPTED>
1623 The file or directory is encrypted. For a file, this means that all data
1624 streams in the file are encrypted. For a directory, this means that
1625 encryption is the default for newly created files and subdirectories.
1627 =item C<FILE_ATTRIBUTE_HIDDEN>
1629 The file or directory is hidden. It is not included in an ordinary directory
1632 =item C<FILE_ATTRIBUTE_NORMAL>
1634 The file or directory has no other attributes set. This attribute is valid
1637 =item C<FILE_ATTRIBUTE_NOT_CONTENT_INDEXED>
1639 The file will not be indexed by the content indexing service.
1641 =item C<FILE_ATTRIBUTE_OFFLINE>
1643 The data of the file is not immediately available. This attribute indicates
1644 that the file data has been physically moved to offline storage. This
1645 attribute is used by Remote Storage, the hierarchical storage management
1646 software. Applications should not arbitrarily change this attribute.
1648 =item C<FILE_ATTRIBUTE_READONLY>
1650 The file or directory is read-only. Applications can read the file but cannot
1651 write to it or delete it. In the case of a directory, applications cannot
1654 =item C<FILE_ATTRIBUTE_REPARSE_POINT>
1656 The file or directory has an associated reparse point.
1658 =item C<FILE_ATTRIBUTE_SPARSE_FILE>
1660 The file is a sparse file.
1662 =item C<FILE_ATTRIBUTE_SYSTEM>
1664 The file or directory is part of, or is used exclusively by, the operating
1667 =item C<FILE_ATTRIBUTE_TEMPORARY>
1669 The file is being used for temporary storage. File systems avoid writing
1670 data back to mass storage if sufficient cache memory is available, because
1671 often the application deletes the temporary file shortly after the handle is
1672 closed. In that case, the system can entirely avoid writing the data.
1673 Otherwise, the data will be written after the handle is closed.
1679 =item C<$uFileType= GetFileType( $hFile )>
1681 Takes a Win32 native file handle and returns a C<FILE_TYPE_*> constant
1682 indicating the type of the file opened on that handle:
1686 =item C<FILE_TYPE_UNKNOWN>
1688 None of the below. Often a special device.
1690 =item C<FILE_TYPE_DISK>
1692 An ordinary disk file.
1694 =item C<FILE_TYPE_CHAR>
1696 What Unix would call a "character special file", that is, a device that
1697 works on character streams such as a printer port or a console.
1699 =item C<FILE_TYPE_PIPE>
1701 Either a named or anonymous pipe.
1707 =item C<$size= getFileSize( $hFile )>
1709 This is a Perl-friendly wrapper for the C<GetFileSize> (below) API call.
1711 It takes a Win32 native file handle and returns the size in bytes. Since the
1712 size can be a 64 bit value, on non 64 bit integer Perls the value returned will
1713 be an object of type C<Math::BigInt>.
1717 =item C<$iSizeLow= GetFileSize($win32Handle, $iSizeHigh)>
1719 Returns the size of a file pointed to by C<$win32Handle>, optionally storing
1720 the high order 32 bits into C<$iSizeHigh> if it is not C<[]>. If $iSizeHigh is
1721 C<[]>, a non-zero value indicates success. Otherwise, on failure the return
1722 value will be C<0xffffffff> and C<fileLastError()> will not be C<NO_ERROR>.
1724 =item GetOverlappedResult
1726 =item C<$bRetval= GetOverlappedResult( $win32Handle, $pOverlapped,
1727 $numBytesTransferred, $bWait )>
1729 Used for asynchronous IO in Win32 to get the result of a pending IO operation,
1730 such as when a file operation returns C<ERROR_IO_PENDING>. Returns a false
1731 value on failure. The C<$overlapped> structure and C<$numBytesTransferred>
1732 will be modified with the results of the operation.
1734 As far as creating the C<$pOverlapped> structure, you are currently on your own.
1736 See L<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getoverlappedresult.asp> for more information.
1738 =item GetLogicalDrives
1740 =item C<$uDriveBits= GetLogicalDrives()>
1742 Returns an unsigned value with one bit set for each drive letter currently
1743 defined. If "A:" is currently a valid drive letter, then the C<1> bit
1744 will be set in C<$uDriveBits>. If "B:" is valid, then the C<2> bit will
1745 be set. If "Z:" is valid, then the C<2**26> [C<0x4000000>] bit will be
1748 =item GetLogicalDriveStrings
1750 =item C<$olOutLength= GetLogicalDriveStrings( $lBufSize, $osBuffer )>
1752 For each currently defined drive letter, a C<'\0'>-terminated string
1753 of the path to the root of its file system is constructed. All of
1754 these strings are concatenated into a single larger string and an
1755 extra terminating C<'\0'> is added. This larger string is returned
1756 in C<$osBuffer>. Note that this includes drive letters that have
1757 been defined but that have no file system, such as drive letters
1758 assigned to unformatted partitions.
1760 C<$lBufSize> is the size of the buffer to allocate to store this
1761 list of strings. C<26*4+1> is always sufficient and should usually
1764 C<$osBuffer> is a scalar to be set to contain the constructed string.
1766 C<$olOutLength> is the number of bytes actually written to C<$osBuffer>
1767 but C<length($osBuffer)> can also be used to determine this.
1769 For example, on a poorly equipped computer,
1771 GetLogicalDriveStrings( 4*26+1, $osBuffer );
1773 might set C<$osBuffer> to the 9-character string, C<"A:\\\0C:\\\0\0">.
1775 =item GetHandleInformation
1777 =item C<GetHandleInformation( $hObject, $ouFlags )>
1779 Retrieves the flags associated with a Win32 native file handle or object
1782 C<$hObject> is an open Win32 native file handle or an open Win32 native
1783 handle to some other type of object.
1785 C<$ouFlags> will be set to an unsigned value having zero or more of
1786 the bits C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE>
1787 set. See the C<":HANDLE_FLAG_"> export class for the meanings of these
1792 =item C<$hNativeHandle= GetOsFHandle( FILE )>
1794 Takes a Perl file handle [like C<STDIN>] and returns the Win32 native
1795 file handle associated with it. See C<FdGetOsFHandle> for more
1796 information about Win32 native file handles.
1798 C<$hNativeHandle> is set to a false value [and C<lastFileError()> and
1799 C<$^E> are set] if C<GetOsFHandle> fails. C<GetOsFHandle> returns
1800 C<"0 but true"> in the impossible(?) case of the handle having a value
1803 =item GetVolumeInformation
1805 =item C<GetVolumeInformation( $sRootPath, $osVolName, $lVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType )>
1807 Gets information about a file system volume, returning a true
1808 value if successful. On failure, returns a false value and sets
1809 C<fileLastError()> and C<$^E>.
1811 C<$sRootPath> is a string specifying the path to the root of the file system,
1812 for example, C<"C:/">.
1814 C<$osVolName> is a scalar to be set to the string representing the
1815 volume name, also called the file system label. C<$lVolName> is the
1816 number of bytes to allocate for the C<$osVolName> buffer [see
1817 L<Buffer Sizes> for more information].
1819 C<$ouSerialNum> is C<[]> [for C<NULL>] or will be set to the numeric
1820 value of the volume's serial number.
1822 C<$ouMaxNameLen> is C<[]> [for C<NULL>] or will be set to the maximum
1823 length allowed for a file name or directory name within the file system.
1825 C<$osFsType> is a scalar to be set to the string representing the
1826 file system type, such as C<"FAT"> or C<"NTFS">. C<$lFsType> is the
1827 number of bytes to allocate for the C<$osFsType> buffer [see
1828 L<Buffer Sizes> for more information].
1830 C<$ouFsFlags> is C<[]> [for C<NULL>] or will be set to an unsigned integer
1831 with bits set indicating properties of the file system:
1835 =item C<FS_CASE_IS_PRESERVED>
1837 The file system preserves the case of file names [usually true].
1838 That is, it doesn't change the case of file names such as forcing
1839 them to upper- or lower-case.
1841 =item C<FS_CASE_SENSITIVE>
1843 The file system supports the ability to not ignore the case of file
1844 names [but might ignore case the way you are using it]. That is, the
1845 file system has the ability to force you to get the letter case of a
1846 file's name exactly right to be able to open it. This is true for
1847 "NTFS" file systems, even though case in file names is usually still
1850 =item C<FS_UNICODE_STORED_ON_DISK>
1852 The file system preserves Unicode in file names [true for "NTFS"].
1854 =item C<FS_PERSISTENT_ACLS>
1856 The file system supports setting Access Control Lists on files [true
1859 =item C<FS_FILE_COMPRESSION>
1861 The file system supports compression on a per-file basis [true for
1864 =item C<FS_VOL_IS_COMPRESSED>
1866 The entire file system is compressed such as via "DoubleSpace".
1870 =item IsRecognizedPartition
1872 =item C<IsRecognizedPartition( $ivPartitionType )>
1874 Takes a partition type and returns whether that partition type is
1875 supported under Win32. C<$ivPartitonType> is an integer value as from
1876 the operating system byte of a hard disk's DOS-compatible partition
1877 table [that is, a partition table for x86-based Win32, not, for
1878 example, one used with Windows NT for Alpha processors]. For example,
1879 the C<PartitionType> member of the C<PARTITION_INFORMATION> structure.
1881 Common values for C<$ivPartitionType> include C<PARTITION_FAT_12==1>,
1882 C<PARTITION_FAT_16==4>, C<PARTITION_EXTENDED==5>, C<PARTITION_FAT32==0xB>.
1884 =item IsContainerPartition
1886 =item C<IsContainerPartition( $ivPartitionType )>
1888 Takes a partition type and returns whether that partition is a
1889 "container" partition that is supported under Win32, that is, whether
1890 it is an "extended" partition that can contain "logical" partitions.
1891 C<$ivPartitonType> is as for C<IsRecognizedPartition>.
1895 =item C<MoveFile( $sOldName, $sNewName )>
1897 Renames a file or directory. C<$sOldName> is the name of the existing
1898 file or directory that is to be renamed. C<$sNewName> is the new name
1899 to give the file or directory. Returns a true value if the move
1900 succeeds. For failure, returns a false value and sets
1901 C<fileLastErorr()> and C<$^E> to the reason for the failure.
1903 Files can be "renamed" between file systems and the file contents and
1904 some attributes will be moved. Directories can only be renamed within
1905 one file system. If there is already a file or directory named
1906 C<$sNewName>, then C<MoveFile> will fail.
1910 =item C<MoveFileEx( $sOldName, $sNewName, $uFlags )>
1912 Renames a file or directory. C<$sOldName> is the name of the existing
1913 file or directory that is to be renamed. C<$sNewName> is the new name
1914 to give the file or directory. Returns a true value if the move
1915 succeeds. For failure, returns a false value and sets
1916 C<fileLastErorr()> and C<$^E> to the reason for the failure.
1918 C<$uFlags> is an unsigned value with zero or more of the following bits set:
1922 =item C<MOVEFILE_REPLACE_EXISTING>
1924 If this bit is set and a file [but not a directory] named C<$sNewName>
1925 already exists, then it will be replaced by C<$sOldName>. If this bit
1926 is not set then C<MoveFileEx> will fail rather than replace an existing
1929 =item C<MOVEFILE_COPY_ALLOWED>
1931 Allows files [but not directories] to be moved between file systems
1932 by copying the C<$sOldName> file data and some attributes to
1933 C<$sNewName> and then deleting C<$sOldName>. If this bit is not set
1934 [or if C<$sOldName> denotes a directory] and C<$sNewName> refers to a
1935 different file system than C<$sOldName>, then C<MoveFileEx> will fail.
1937 =item C<MOVEFILE_DELAY_UNTIL_REBOOT>
1939 Preliminary verifications are made and then an entry is added to the
1940 Registry to cause the rename [or delete] operation to be done the
1941 next time this copy of the operating system is booted [right after
1942 any automatic file system checks have completed]. This is not
1943 supported under Windows 95.
1945 When this bit is set, C<$sNewName> can be C<[]> [for C<NULL>] to
1946 indicate that C<$sOldName> should be deleted during the next boot
1947 rather than renamed.
1949 Setting both the C<MOVEFILE_COPY_ALLOWED> and
1950 C<MOVEFILE_DELAY_UNTIL_REBOOT> bits will cause C<MoveFileEx> to fail.
1952 =item C<MOVEFILE_WRITE_THROUGH>
1954 Ensures that C<MoveFileEx> won't return until the operation has
1955 finished and been flushed to disk. This is not supported under
1956 Windows 95. Only affects file renames to another file system,
1957 forcing a buffer flush at the end of the copy operation.
1963 =item C<OsFHandleOpen( FILE, $hNativeHandle, $sMode )>
1965 Opens a Perl file handle based on an already open Win32 native
1966 file handle [much like C's C<fdopen()> does with a file descriptor].
1967 Returns a true value if the open operation succeeded. For failure,
1968 returns a false value and sets C<$!> [and possibly C<fileLastError()>
1969 and C<$^E>] to the reason for the failure.
1971 C<FILE> is a Perl file handle [in any of the supported forms, a
1972 bareword, a string, a typeglob, or a reference to a typeglob] that
1973 will be opened. If C<FILE> is already open, it will automatically
1974 be closed before it is reopened.
1976 C<$hNativeHandle> is an open Win32 native file handle, probably the
1977 return value from C<CreateFile> or C<createFile>.
1979 C<$sMode> is string of zero or more letters from C<"rwatb">. These
1980 are translated into a combination C<O_RDONLY> [C<"r">], C<O_WRONLY>
1981 [C<"w">], C<O_RDWR> [C<"rw">], C<O_APPEND> [C<"a">], C<O_TEXT>
1982 [C<"t">], and C<O_BINARY> [C<"b">] flags [see the L<Fcntl> module]
1983 that is passed to C<OsFHandleOpenFd>. Currently only C<O_APPEND>
1984 and C<O_TEXT> have any significance.
1986 Also, a C<"r"> and/or C<"w"> in C<$sMode> is used to decide how the
1987 file descriptor is converted into a Perl file handle, even though this
1988 doesn't appear to make a difference. One of the following is used:
1990 open( FILE, "<&=".$ivFd ) # "r" w/o "w"
1991 open( FILE, ">&=".$ivFd ) # "w" w/o "r"
1992 open( FILE, "+<&=".$ivFd ) # both "r" and "w"
1994 C<OsFHandleOpen> eventually calls the Win32-specific C routine
1995 C<_open_osfhandle()> or Perl's "improved" version called
1996 C<win32_open_osfhandle()>. Prior to Perl5.005, C's
1997 C<_open_osfhandle()> is called which will fail if
1998 C<GetFileType($hNativeHandle)> would return C<FILE_TYPE_UNKNOWN>. For
1999 Perl5.005 and later, C<OsFHandleOpen> calls C<win32_open_osfhandle()>
2000 from the Perl DLL which doesn't have this restriction.
2002 =item OsFHandleOpenFd
2004 =item C<$ivFD= OsFHandleOpenFd( $hNativeHandle, $uMode )>
2006 Opens a file descriptor [C<$ivFD>] based on an already open Win32
2007 native file handle, C<$hNativeHandle>. This just calls the
2008 Win32-specific C routine C<_open_osfhandle()> or Perl's "improved"
2009 version called C<win32_open_osfhandle()>. Prior to Perl5.005 and in Cygwin
2010 Perl, C's C<_open_osfhandle()> is called which will fail if
2011 C<GetFileType($hNativeHandle)> would return C<FILE_TYPE_UNKNOWN>. For
2012 Perl5.005 and later, C<OsFHandleOpenFd> calls C<win32_open_osfhandle()> from
2013 the Perl DLL which doesn't have this restriction.
2015 C<$uMode> the logical combination of zero or more C<O_*> constants
2016 exported by the C<Fcntl> module. Currently only C<O_APPEND> and
2017 C<O_TEXT> have any significance.
2019 C<$ivFD> will be non-negative if the open operation was successful.
2020 For failure, C<-1> is returned and C<$!> [and possibly
2021 C<fileLastError()> and C<$^E>] is set to the reason for the failure.
2023 =item QueryDosDevice
2025 =item C<$olTargetLen= QueryDosDevice( $sDosDeviceName, $osTargetPath, $lTargetBuf )>
2027 Looks up the definition of a given "DOS" device name, yielding the
2028 active Windows NT native device name along with any currently dormant
2031 C<$sDosDeviceName> is the name of the "DOS" device whose definitions
2032 we want. For example, C<"C:">, C<"COM1">, or C<"PhysicalDrive0">.
2033 If C<$sDosDeviceName> is C<[]> [for C<NULL>], the list of all DOS
2034 device names is returned instead.
2036 C<$osTargetPath> will be assigned a string containing the list of
2037 definitions. The definitions are each C<'\0'>-terminate and are
2038 concatenated into the string, most recent first, with an extra C<'\0'>
2039 at the end of the whole string [see C<GetLogicalDriveStrings> for
2040 a sample of this format].
2042 C<$lTargetBuf> is the size [in bytes] of the buffer to allocate for
2043 C<$osTargetPath>. See L<Buffer Sizes> for more information.
2045 C<$olTargetLen> is set to the number of bytes written to
2046 C<$osTargetPath> but you can also use C<length($osTargetPath)>
2049 For failure, C<0> is returned and C<fileLastError()> and C<$^E> are
2050 set to the reason for the failure.
2054 =item C<ReadFile( $hFile, $opBuffer, $lBytes, $olBytesRead, $pOverlapped )>
2056 Reads bytes from a file or file-like device. Returns a true value if
2057 the read operation was successful. For failure, returns a false value
2058 and sets C<fileLastError()> and C<$^E> for the reason for the failure.
2060 C<$hFile> is a Win32 native file handle that is already open to the
2061 file or device to read from.
2063 C<$opBuffer> will be set to a string containing the bytes read.
2065 C<$lBytes> is the number of bytes you would like to read.
2066 C<$opBuffer> is automatically initialized to have a buffer large
2067 enough to hold that many bytes. Unlike other buffer sizes, C<$lBytes>
2068 does not need to have a C<"="> prepended to it to prevent a larger
2069 value to be passed to the underlying Win32 C<ReadFile> API. However,
2070 a leading C<"="> will be silently ignored, even if Perl warnings are
2073 If C<$olBytesRead> is not C<[]>, it will be set to the actual number
2074 of bytes read, though C<length($opBuffer)> can also be used to
2077 C<$pOverlapped> is C<[]> or is a C<OVERLAPPED> structure packed
2078 into a string. This is only useful if C<$hFile> was opened with
2079 the C<FILE_FLAG_OVERLAPPED> flag set.
2083 =item C<$uOldMode= SetErrorMode( $uNewMode )>
2085 Sets the mode controlling system error handling B<and> returns the
2086 previous mode value. Both C<$uOldMode> and C<$uNewMode> will have
2087 zero or more of the following bits set:
2091 =item C<SEM_FAILCRITICALERRORS>
2093 If set, indicates that when a critical error is encountered, the call
2094 that triggered the error fails immediately. Normally this bit is not
2095 set, which means that a critical error causes a dialogue box to appear
2096 notifying the desktop user that some application has triggered a
2097 critical error. The dialogue box allows the desktop user to decide
2098 whether the critical error is returned to the process, is ignored, or
2099 the offending operation is retried.
2101 This affects the C<CreateFile> and C<GetVolumeInformation> calls.
2103 Setting this bit is useful for allowing you to check whether a floppy
2104 diskette is in the floppy drive.
2106 =item C<SEM_NOALIGNMENTFAULTEXCEPT>
2108 If set, this causes memory access misalignment faults to be
2109 automatically fixed in a manner invisible to the process. This flag
2110 is ignored on x86-based versions of Windows NT. This flag is not
2111 supported on Windows 95.
2113 =item C<SEM_NOGPFAULTERRORBOX>
2115 If set, general protection faults do not generate a dialogue box but
2116 can instead be handled by the process via an exception handler. This
2117 bit should not be set by programs that don't know how to handle such
2120 =item C<SEM_NOOPENFILEERRORBOX>
2122 If set, then when an attempt to continue reading from or writing to
2123 an already open file [usually on a removable medium like a floppy
2124 diskette] finds the file no longer available, the call will
2125 immediately fail. Normally this bit is not set, which means that
2126 instead a dialogue box will appear notifying the desktop user that
2127 some application has run into this problem. The dialogue box allows
2128 the desktop user to decide whether the failure is returned to the
2129 process, is ignored, or the offending operation is retried.
2131 This affects the C<ReadFile> and C<WriteFile> calls.
2135 =item setFilePointer
2137 =item C<$uNewPos = setFilePointer( $hFile, $ivOffset, $uFromWhere )>
2139 This is a perl-friendly wrapper for the SetFilePointer API (below).
2140 C<$ivOffset> can be a 64 bit integer or C<Math::BigInt> object if your Perl
2141 doesn't have 64 bit integers. The return value is the new offset and will
2142 likewise be a 64 bit integer or a C<Math::BigInt> object.
2144 =item SetFilePointer
2146 =item C<$uNewPos = SetFilePointer( $hFile, $ivOffset, $ioivOffsetHigh, $uFromWhere )>
2148 The native Win32 version of C<seek()>. C<SetFilePointer> sets the
2149 position within a file where the next read or write operation will
2152 C<$hFile> is a Win32 native file handle.
2154 C<$uFromWhere> is either C<FILE_BEGIN>, C<FILE_CURRENT>, or
2155 C<FILE_END>, indicating that the new file position is being specified
2156 relative to the beginning of the file, the current file pointer, or
2157 the end of the file, respectively.
2159 C<$ivOffset> is [if C<$ioivOffsetHigh> is C<[]>] the offset [in bytes]
2160 to the new file position from the position specified via
2161 C<$uFromWhere>. If C<$ioivOffsetHigh> is not C<[]>, then C<$ivOffset>
2162 is converted to an unsigned value to be used as the low-order 4 bytes
2165 C<$ioivOffsetHigh> can be C<[]> [for C<NULL>] to indicate that you are
2166 only specifying a 4-byte offset and the resulting file position will
2167 be 0xFFFFFFFE or less [just under 4GB]. Otherwise C<$ioivOfffsetHigh>
2168 starts out with the high-order 4 bytes [signed] of the offset and gets
2169 set to the [unsigned] high-order 4 bytes of the resulting file position.
2171 The underlying C<SetFilePointer> returns C<0xFFFFFFFF> to indicate
2172 failure, but if C<$ioivOffsetHigh> is not C<[]>, you would also have
2173 to check C<$^E> to determine whether C<0xFFFFFFFF> indicates an error
2174 or not. C<Win32API::File::SetFilePointer> does this checking for you
2175 and returns a false value if and only if the underlying
2176 C<SetFilePointer> failed. For this reason, C<$uNewPos> is set to
2177 C<"0 but true"> if you set the file pointer to the beginning of the
2178 file [or any position with 0 for the low-order 4 bytes].
2180 So the return value will be true if the seek operation was successful.
2181 For failure, a false value is returned and C<fileLastError()> and
2182 C<$^E> are set to the reason for the failure.
2184 =item SetHandleInformation
2186 =item C<SetHandleInformation( $hObject, $uMask, $uFlags )>
2188 Sets the flags associated with a Win32 native file handle or object
2189 handle. Returns a true value if the operation was successful. For
2190 failure, returns a false value and sets C<fileLastError()> and C<$^E>
2191 for the reason for the failure.
2193 C<$hObject> is an open Win32 native file handle or an open Win32 native
2194 handle to some other type of object.
2196 C<$uMask> is an unsigned value having one or more of the bits
2197 C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE> set.
2198 Only bits set in C<$uMask> will be modified by C<SetHandleInformation>.
2200 C<$uFlags> is an unsigned value having zero or more of the bits
2201 C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE> set.
2202 For each bit set in C<$uMask>, the corresponding bit in the handle's
2203 flags is set to the value of the corresponding bit in C<$uFlags>.
2205 If C<$uOldFlags> were the value of the handle's flags before the
2206 call to C<SetHandleInformation>, then the value of the handle's
2207 flags afterward would be:
2209 ( $uOldFlags & ~$uMask ) | ( $uFlags & $uMask )
2211 [at least as far as the C<HANDLE_FLAG_INHERIT> and
2212 C<HANDLE_FLAG_PROTECT_FROM_CLOSE> bits are concerned.]
2214 See the C<":HANDLE_FLAG_"> export class for the meanings of these bits.
2218 =item C<WriteFile( $hFile, $pBuffer, $lBytes, $ouBytesWritten, $pOverlapped )>
2220 Write bytes to a file or file-like device. Returns a true value if
2221 the operation was successful. For failure, returns a false value and
2222 sets C<fileLastError()> and C<$^E> for the reason for the failure.
2224 C<$hFile> is a Win32 native file handle that is already open to the
2225 file or device to be written to.
2227 C<$pBuffer> is a string containing the bytes to be written.
2229 C<$lBytes> is the number of bytes you would like to write. If
2230 C<$pBuffer> is not at least C<$lBytes> long, C<WriteFile> croaks. You
2231 can specify C<0> for C<$lBytes> to write C<length($pBuffer)> bytes.
2232 A leading C<"="> on C<$lBytes> will be silently ignored, even if Perl
2233 warnings are enabled.
2235 C<$ouBytesWritten> will be set to the actual number of bytes written
2236 unless you specify it as C<[]>.
2238 C<$pOverlapped> is C<[]> or is an C<OVERLAPPED> structure packed
2239 into a string. This is only useful if C<$hFile> was opened with
2240 the C<FILE_FLAG_OVERLAPPED> flag set.
2246 The ASCII-specific functions. Each of these is just the same as the
2247 version without the trailing "A".
2255 GetLogicalDriveStringsA
2256 GetVolumeInformationA
2263 The wide-character-specific (Unicode) functions. Each of these is
2264 just the same as the version without the trailing "W" except that
2265 strings are expected in Unicode and some lengths are measured as
2266 number of C<WCHAR>s instead of number of bytes, as indicated below.
2272 =item C<CopyFileW( $swOldFileName, $swNewFileName, $bFailIfExists )>
2274 C<$swOldFileName> and C<$swNewFileName> are Unicode strings.
2278 =item C<$hObject= CreateFileW( $swPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel )>
2280 C<$swPath> is Unicode.
2282 =item DefineDosDeviceW
2284 =item C<DefineDosDeviceW( $uFlags, $swDosDeviceName, $swTargetPath )>
2286 C<$swDosDeviceName> and C<$swTargetPath> are Unicode.
2290 =item C<DeleteFileW( $swFileName )>
2292 C<$swFileName> is Unicode.
2296 =item C<$uDriveType= GetDriveTypeW( $swRootPath )>
2298 C<$swRootPath> is Unicode.
2300 =item GetFileAttributesW
2302 =item C<$uAttrs= GetFileAttributesW( $swPath )>
2304 C<$swPath> is Unicode.
2306 =item GetLogicalDriveStringsW
2308 =item C<$olwOutLength= GetLogicalDriveStringsW( $lwBufSize, $oswBuffer )>
2310 Unicode is stored in C<$oswBuffer>. C<$lwBufSize> and C<$olwOutLength>
2311 are measured as number of C<WCHAR>s.
2313 =item GetVolumeInformationW
2315 =item C<GetVolumeInformationW( $swRootPath, $oswVolName, $lwVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $oswFsType, $lwFsType )>
2317 C<$swRootPath> is Unicode and Unicode is written to C<$oswVolName> and
2318 C<$oswFsType>. C<$lwVolName> and C<$lwFsType> are measures as number
2323 =item C<MoveFileW( $swOldName, $swNewName )>
2325 C<$swOldName> and C<$swNewName> are Unicode.
2329 =item C<MoveFileExW( $swOldName, $swNewName, $uFlags )>
2331 C<$swOldName> and C<$swNewName> are Unicode.
2333 =item QueryDosDeviceW
2335 =item C<$olwTargetLen= QueryDosDeviceW( $swDeviceName, $oswTargetPath, $lwTargetBuf )>
2337 C<$swDeviceName> is Unicode and Unicode is written to
2338 C<$oswTargetPath>. C<$lwTargetBuf> and C<$olwTargetLen> are measured
2339 as number of C<WCHAR>s.
2345 Miscellaneous constants. Used for the C<$uCreate> argument of
2346 C<CreateFile> or the C<$uFromWhere> argument of C<SetFilePointer>.
2347 Plus C<INVALID_HANDLE_VALUE>, which you usually won't need to check
2348 for since most routines translate it into a false value.
2350 CREATE_ALWAYS CREATE_NEW OPEN_ALWAYS
2351 OPEN_EXISTING TRUNCATE_EXISTING INVALID_HANDLE_VALUE
2352 FILE_BEGIN FILE_CURRENT FILE_END
2356 Constants for the C<$uFlags> argument of C<DefineDosDevice>.
2358 DDD_EXACT_MATCH_ON_REMOVE
2360 DDD_REMOVE_DEFINITION
2364 Constants returned by C<GetDriveType>.
2366 DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE
2367 DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM
2372 Specific types of access to files that can be requested via the
2373 C<$uAccess> argument to C<CreateFile>.
2375 FILE_READ_DATA FILE_LIST_DIRECTORY
2376 FILE_WRITE_DATA FILE_ADD_FILE
2377 FILE_APPEND_DATA FILE_ADD_SUBDIRECTORY
2378 FILE_CREATE_PIPE_INSTANCE FILE_READ_EA
2379 FILE_WRITE_EA FILE_EXECUTE
2380 FILE_TRAVERSE FILE_DELETE_CHILD
2381 FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES
2382 FILE_ALL_ACCESS FILE_GENERIC_READ
2383 FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE )],
2385 =item C<":FILE_ATTRIBUTE_">
2387 File attribute constants. Returned by C<attrLetsToBits> and used in
2388 the C<$uFlags> argument to C<CreateFile>.
2390 FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED
2391 FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL
2392 FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY
2393 FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY
2395 In addition, C<GetFileAttributes> can return these constants (or
2396 INVALID_FILE_ATTRIBUTES in case of an error).
2398 FILE_ATTRIBUTE_DEVICE FILE_ATTRIBUTE_DIRECTORY
2399 FILE_ATTRIBUTE_ENCRYPTED FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
2400 FILE_ATTRIBUTE_REPARSE_POINT FILE_ATTRIBUTE_SPARSE_FILE
2402 =item C<":FILE_FLAG_">
2404 File option flag constants. Used in the C<$uFlags> argument to
2407 FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_DELETE_ON_CLOSE
2408 FILE_FLAG_NO_BUFFERING FILE_FLAG_OVERLAPPED
2409 FILE_FLAG_POSIX_SEMANTICS FILE_FLAG_RANDOM_ACCESS
2410 FILE_FLAG_SEQUENTIAL_SCAN FILE_FLAG_WRITE_THROUGH
2411 FILE_FLAG_OPEN_REPARSE_POINT
2413 =item C<":FILE_SHARE_">
2415 File sharing constants. Used in the C<$uShare> argument to
2418 FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE
2420 =item C<":FILE_TYPE_">
2422 File type constants. Returned by C<GetFileType>.
2424 FILE_TYPE_CHAR FILE_TYPE_DISK
2425 FILE_TYPE_PIPE FILE_TYPE_UNKNOWN
2429 File system characteristics constants. Placed in the C<$ouFsFlags>
2430 argument to C<GetVolumeInformation>.
2432 FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE
2433 FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS
2434 FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED
2436 =item C<":HANDLE_FLAG_">
2438 Flag bits modifying the behavior of an object handle and accessed via
2439 C<GetHandleInformation> and C<SetHandleInformation>.
2443 =item HANDLE_FLAG_INHERIT
2445 If this bit is set, then children of this process who inherit handles
2446 [that is, processes created by calls to the Win32 C<CreateProcess> API
2447 with the C<bInheritHandles> parameter specified as C<TRUE>], will inherit
2448 this particular object handle.
2450 =item HANDLE_FLAG_PROTECT_FROM_CLOSE
2452 If this bit is set, then calls to C<CloseHandle> against this handle
2453 will be ignored, leaving the handle open and usable.
2457 =item C<":IOCTL_STORAGE_">
2459 I/O control operations for generic storage devices. Used in the
2460 C<$uIoControlCode> argument to C<DeviceIoControl>. Includes
2461 C<IOCTL_STORAGE_CHECK_VERIFY>, C<IOCTL_STORAGE_MEDIA_REMOVAL>,
2462 C<IOCTL_STORAGE_EJECT_MEDIA>, C<IOCTL_STORAGE_LOAD_MEDIA>,
2463 C<IOCTL_STORAGE_RESERVE>, C<IOCTL_STORAGE_RELEASE>,
2464 C<IOCTL_STORAGE_FIND_NEW_DEVICES>, and
2465 C<IOCTL_STORAGE_GET_MEDIA_TYPES>.
2469 =item C<IOCTL_STORAGE_CHECK_VERIFY>
2471 Verify that a device's media is accessible. C<$pInBuf> and C<$opOutBuf>
2472 should both be C<[]>. If C<DeviceIoControl> returns a true value, then
2473 the media is currently accessible.
2475 =item C<IOCTL_STORAGE_MEDIA_REMOVAL>
2477 Allows the device's media to be locked or unlocked. C<$opOutBuf> should
2478 be C<[]>. C<$pInBuf> should be a C<PREVENT_MEDIA_REMOVAL> data structure,
2479 which is simply an integer containing a boolean value:
2481 $pInBuf= pack( "i", $bPreventMediaRemoval );
2483 =item C<IOCTL_STORAGE_EJECT_MEDIA>
2485 Requests that the device eject the media. C<$pInBuf> and C<$opOutBuf>
2486 should both be C<[]>.
2488 =item C<IOCTL_STORAGE_LOAD_MEDIA>
2490 Requests that the device load the media. C<$pInBuf> and C<$opOutBuf>
2491 should both be C<[]>.
2493 =item C<IOCTL_STORAGE_RESERVE>
2495 Requests that the device be reserved. C<$pInBuf> and C<$opOutBuf>
2496 should both be C<[]>.
2498 =item C<IOCTL_STORAGE_RELEASE>
2500 Releases a previous device reservation. C<$pInBuf> and C<$opOutBuf>
2501 should both be C<[]>.
2503 =item C<IOCTL_STORAGE_FIND_NEW_DEVICES>
2505 No documentation on this IOCTL operation was found.
2507 =item C<IOCTL_STORAGE_GET_MEDIA_TYPES>
2509 Requests information about the type of media supported by the device.
2510 C<$pInBuf> should be C<[]>. C<$opOutBuf> will be set to contain a
2511 vector of C<DISK_GEOMETRY> data structures, which can be decoded via:
2513 # Calculate the number of DISK_GEOMETRY structures returned:
2514 my $cStructs= length($opOutBuf)/(4+4+4+4+4+4);
2515 my @fields= unpack( "L l I L L L" x $cStructs, $opOutBuf )
2516 my( @ucCylsLow, @ivcCylsHigh, @uMediaType, @uTracksPerCyl,
2517 @uSectsPerTrack, @uBytesPerSect )= ();
2519 push( @ucCylsLow, unshift @fields );
2520 push( @ivcCylsHigh, unshift @fields );
2521 push( @uMediaType, unshift @fields );
2522 push( @uTracksPerCyl, unshift @fields );
2523 push( @uSectsPerTrack, unshift @fields );
2524 push( @uBytesPerSect, unshift @fields );
2527 For the C<$i>th type of supported media, the following variables will
2528 contain the following data.
2532 =item C<$ucCylsLow[$i]>
2534 The low-order 4 bytes of the total number of cylinders.
2536 =item C<$ivcCylsHigh[$i]>
2538 The high-order 4 bytes of the total number of cylinders.
2540 =item C<$uMediaType[$i]>
2542 A code for the type of media. See the C<":MEDIA_TYPE"> export class.
2544 =item C<$uTracksPerCyl[$i]>
2546 The number of tracks in each cylinder.
2548 =item C<$uSectsPerTrack[$i]>
2550 The number of sectors in each track.
2552 =item C<$uBytesPerSect[$i]>
2554 The number of bytes in each sector.
2560 =item C<":IOCTL_DISK_">
2562 I/O control operations for disk devices. Used in the C<$uIoControlCode>
2563 argument to C<DeviceIoControl>. Most of these are to be used on
2564 physical drive devices like C<"//./PhysicalDrive0">. However,
2565 C<IOCTL_DISK_GET_PARTITION_INFO> and C<IOCTL_DISK_SET_PARTITION_INFO>
2566 should only be used on a single-partition device like C<"//./C:">. Also,
2567 C<IOCTL_DISK_GET_MEDIA_TYPES> is documented as having been superseded but
2568 is still useful when used on a floppy device like C<"//./A:">.
2570 Includes C<IOCTL_DISK_FORMAT_TRACKS>, C<IOCTL_DISK_FORMAT_TRACKS_EX>,
2571 C<IOCTL_DISK_GET_DRIVE_GEOMETRY>, C<IOCTL_DISK_GET_DRIVE_LAYOUT>,
2572 C<IOCTL_DISK_GET_MEDIA_TYPES>, C<IOCTL_DISK_GET_PARTITION_INFO>,
2573 C<IOCTL_DISK_HISTOGRAM_DATA>, C<IOCTL_DISK_HISTOGRAM_RESET>,
2574 C<IOCTL_DISK_HISTOGRAM_STRUCTURE>, C<IOCTL_DISK_IS_WRITABLE>,
2575 C<IOCTL_DISK_LOGGING>, C<IOCTL_DISK_PERFORMANCE>,
2576 C<IOCTL_DISK_REASSIGN_BLOCKS>, C<IOCTL_DISK_REQUEST_DATA>,
2577 C<IOCTL_DISK_REQUEST_STRUCTURE>, C<IOCTL_DISK_SET_DRIVE_LAYOUT>,
2578 C<IOCTL_DISK_SET_PARTITION_INFO>, and C<IOCTL_DISK_VERIFY>.
2582 =item C<IOCTL_DISK_GET_DRIVE_GEOMETRY>
2584 Request information about the size and geometry of the disk. C<$pInBuf>
2585 should be C<[]>. C<$opOutBuf> will be set to a C<DISK_GEOMETRY> data
2586 structure which can be decode via:
2588 ( $ucCylsLow, $ivcCylsHigh, $uMediaType, $uTracksPerCyl,
2589 $uSectsPerTrack, $uBytesPerSect )= unpack( "L l I L L L", $opOutBuf );
2595 The low-order 4 bytes of the total number of cylinders.
2597 =item C<$ivcCylsHigh>
2599 The high-order 4 bytes of the total number of cylinders.
2601 =item C<$uMediaType>
2603 A code for the type of media. See the C<":MEDIA_TYPE"> export class.
2605 =item C<$uTracksPerCyl>
2607 The number of tracks in each cylinder.
2609 =item C<$uSectsPerTrack>
2611 The number of sectors in each track.
2613 =item C<$uBytesPerSect>
2615 The number of bytes in each sector.
2619 =item C<IOCTL_DISK_GET_PARTITION_INFO>
2621 Request information about the size and geometry of the partition.
2622 C<$pInBuf> should be C<[]>. C<$opOutBuf> will be set to a
2623 C<PARTITION_INFORMATION> data structure which can be decode via:
2625 ( $uStartLow, $ivStartHigh, $ucHiddenSects, $uPartitionSeqNumber,
2626 $uPartitionType, $bActive, $bRecognized, $bToRewrite )=
2627 unpack( "L l L L C c c c", $opOutBuf );
2631 =item C<$uStartLow> and C<$ivStartHigh>
2633 The low-order and high-order [respectively] 4 bytes of the starting
2634 offset of the partition, measured in bytes.
2636 =item C<$ucHiddenSects>
2638 The number of "hidden" sectors for this partition. Actually this is
2639 the number of sectors found prior to this partition, that is, the
2640 starting offset [as found in C<$uStartLow> and C<$ivStartHigh>]
2641 divided by the number of bytes per sector.
2643 =item C<$uPartitionSeqNumber>
2645 The sequence number of this partition. Partitions are numbered
2646 starting as C<1> [with "partition 0" meaning the entire disk].
2647 Sometimes this field may be C<0> and you'll have to infer the
2648 partition sequence number from how many partitions precede it on
2651 =item C<$uPartitionType>
2653 The type of partition. See the C<":PARTITION_"> export class for a
2654 list of known types. See also C<IsRecognizedPartition> and
2655 C<IsContainerPartition>.
2659 C<1> for the active [boot] partition, C<0> otherwise.
2661 =item C<$bRecognized>
2663 Whether this type of partition is support under Win32.
2665 =item C<$bToRewrite>
2667 Whether to update this partition information. This field is not used
2668 by C<IOCTL_DISK_GET_PARTITION_INFO>. For
2669 C<IOCTL_DISK_SET_DRIVE_LAYOUT>, you must set this field to a true
2670 value for any partitions you wish to have changed, added, or deleted.
2674 =item C<IOCTL_DISK_SET_PARTITION_INFO>
2676 Change the type of the partition. C<$opOutBuf> should be C<[]>.
2677 C<$pInBuf> should be a C<SET_PARTITION_INFORMATION> data structure
2678 which is just a single byte containing the new partition type [see
2679 the C<":PARTITION_"> export class for a list of known types]:
2681 $pInBuf= pack( "C", $uPartitionType );
2683 =item C<IOCTL_DISK_GET_DRIVE_LAYOUT>
2685 Request information about the disk layout. C<$pInBuf> should be C<[]>.
2686 C<$opOutBuf> will be set to contain C<DRIVE_LAYOUT_INFORMATION>
2687 structure including several C<PARTITION_INFORMATION> structures:
2689 my( $cPartitions, $uDiskSignature )= unpack( "L L", $opOutBuf );
2690 my @fields= unpack( "x8" . ( "L l L L C c c c" x $cPartitions ),
2692 my( @uStartLow, @ivStartHigh, @ucHiddenSects,
2693 @uPartitionSeqNumber, @uPartitionType, @bActive,
2694 @bRecognized, @bToRewrite )= ();
2695 for( 1..$cPartition ) {
2696 push( @uStartLow, unshift @fields );
2697 push( @ivStartHigh, unshift @fields );
2698 push( @ucHiddenSects, unshift @fields );
2699 push( @uPartitionSeqNumber, unshift @fields );
2700 push( @uPartitionType, unshift @fields );
2701 push( @bActive, unshift @fields );
2702 push( @bRecognized, unshift @fields );
2703 push( @bToRewrite, unshift @fields );
2708 =item C<$cPartitions>
2710 If the number of partitions on the disk.
2712 =item C<$uDiskSignature>
2714 Is the disk signature, a unique number assigned by Disk Administrator
2715 [F<WinDisk.exe>] and used to identify the disk. This allows drive
2716 letters for partitions on that disk to remain constant even if the
2717 SCSI Target ID of the disk gets changed.
2721 See C<IOCTL_DISK_GET_PARTITION_INFORMATION> for information on the
2722 remaining these fields.
2724 =item C<IOCTL_DISK_GET_MEDIA_TYPES>
2726 Is supposed to be superseded by C<IOCTL_STORAGE_GET_MEDIA_TYPES> but
2727 is still useful for determining the types of floppy diskette formats
2728 that can be produced by a given floppy drive. See
2729 F<ex/FormatFloppy.plx> for an example.
2731 =item C<IOCTL_DISK_SET_DRIVE_LAYOUT>
2733 Change the partition layout of the disk. C<$pOutBuf> should be C<[]>.
2734 C<$pInBuf> should be a C<DISK_LAYOUT_INFORMATION> data structure
2735 including several C<PARTITION_INFORMATION> data structures.
2737 # Already set: $cPartitions, $uDiskSignature, @uStartLow, @ivStartHigh,
2738 # @ucHiddenSects, @uPartitionSeqNumber, @uPartitionType, @bActive,
2739 # @bRecognized, and @bToRewrite.
2740 my( @fields, $prtn )= ();
2741 for $prtn ( 1..$cPartition ) {
2742 push( @fields, $uStartLow[$prtn-1], $ivStartHigh[$prtn-1],
2743 $ucHiddenSects[$prtn-1], $uPartitionSeqNumber[$prtn-1],
2744 $uPartitionType[$prtn-1], $bActive[$prtn-1],
2745 $bRecognized[$prtn-1], $bToRewrite[$prtn-1] );
2747 $pInBuf= pack( "L L" . ( "L l L L C c c c" x $cPartitions ),
2748 $cPartitions, $uDiskSignature, @fields );
2750 To delete a partition, zero out all fields except for C<$bToRewrite>
2751 which should be set to C<1>. To add a partition, increment
2752 C<$cPartitions> and add the information for the new partition
2753 into the arrays, making sure that you insert C<1> into @bToRewrite.
2755 See C<IOCTL_DISK_GET_DRIVE_LAYOUT> and
2756 C<IOCTL_DISK_GET_PARITITON_INFORMATION> for descriptions of the
2759 =item C<IOCTL_DISK_VERIFY>
2761 Performs a logical format of [part of] the disk. C<$opOutBuf> should
2762 be C<[]>. C<$pInBuf> should contain a C<VERIFY_INFORMATION> data
2765 $pInBuf= pack( "L l L",
2766 $uStartOffsetLow, $ivStartOffsetHigh, $uLength );
2770 =item C<$uStartOffsetLow> and C<$ivStartOffsetHigh>
2772 The low-order and high-order [respectively] 4 bytes of the offset [in
2773 bytes] where the formatting should begin.
2777 The length [in bytes] of the section to be formatted.
2781 =item C<IOCTL_DISK_FORMAT_TRACKS>
2783 Format a range of tracks on the disk. C<$opOutBuf> should be C<[]>.
2784 C<$pInBuf> should contain a C<FORMAT_PARAMETERS> data structure:
2786 $pInBuf= pack( "L L L L L", $uMediaType,
2787 $uStartCyl, $uEndCyl, $uStartHead, $uEndHead );
2789 C<$uMediaType> if the type of media to be formatted. Mostly used to
2790 specify the density to use when formatting a floppy diskette. See the
2791 C<":MEDIA_TYPE"> export class for more information.
2793 The remaining fields specify the starting and ending cylinder and
2794 head of the range of tracks to be formatted.
2796 =item C<IOCTL_DISK_REASSIGN_BLOCKS>
2798 Reassign a list of disk blocks to the disk's spare-block pool.
2799 C<$opOutBuf> should be C<[]>. C<$pInBuf> should be a
2800 C<REASSIGN_BLOCKS> data structure:
2802 $pInBuf= pack( "S S L*", 0, $cBlocks, @uBlockNumbers );
2804 =item C<IOCTL_DISK_PERFORMANCE>
2806 Request information about disk performance. C<$pInBuf> should be C<[]>.
2807 C<$opOutBuf> will be set to contain a C<DISK_PERFORMANCE> data structure:
2809 my( $ucBytesReadLow, $ivcBytesReadHigh,
2810 $ucBytesWrittenLow, $ivcBytesWrittenHigh,
2811 $uReadTimeLow, $ivReadTimeHigh,
2812 $uWriteTimeLow, $ivWriteTimeHigh,
2813 $ucReads, $ucWrites, $uQueueDepth )=
2814 unpack( "L l L l L l L l L L L", $opOutBuf );
2816 =item C<IOCTL_DISK_IS_WRITABLE>
2818 No documentation on this IOCTL operation was found.
2820 =item C<IOCTL_DISK_LOGGING>
2822 Control disk logging. Little documentation for this IOCTL operation
2823 was found. It makes use of a C<DISK_LOGGING> data structure:
2827 =item DISK_LOGGING_START
2829 Start logging each disk request in a buffer internal to the disk device
2830 driver of size C<$uLogBufferSize>:
2832 $pInBuf= pack( "C L L", 0, 0, $uLogBufferSize );
2834 =item DISK_LOGGING_STOP
2836 Stop logging each disk request:
2838 $pInBuf= pack( "C L L", 1, 0, 0 );
2840 =item DISK_LOGGING_DUMP
2842 Copy the internal log into the supplied buffer:
2844 $pLogBuffer= ' ' x $uLogBufferSize
2845 $pInBuf= pack( "C P L", 2, $pLogBuffer, $uLogBufferSize );
2847 ( $uByteOffsetLow[$i], $ivByteOffsetHigh[$i],
2848 $uStartTimeLow[$i], $ivStartTimeHigh[$i],
2849 $uEndTimeLog[$i], $ivEndTimeHigh[$i],
2850 $hVirtualAddress[$i], $ucBytes[$i],
2851 $uDeviceNumber[$i], $bWasReading[$i] )=
2852 unpack( "x".(8+8+8+4+4+1+1+2)." L l L l L l L L C c x2", $pLogBuffer );
2854 =item DISK_LOGGING_BINNING
2856 Keep statics grouped into bins based on request sizes.
2858 $pInBuf= pack( "C P L", 3, $pUnknown, $uUnknownSize );
2862 =item C<IOCTL_DISK_FORMAT_TRACKS_EX>
2864 No documentation on this IOCTL is included.
2866 =item C<IOCTL_DISK_HISTOGRAM_STRUCTURE>
2868 No documentation on this IOCTL is included.
2870 =item C<IOCTL_DISK_HISTOGRAM_DATA>
2872 No documentation on this IOCTL is included.
2874 =item C<IOCTL_DISK_HISTOGRAM_RESET>
2876 No documentation on this IOCTL is included.
2878 =item C<IOCTL_DISK_REQUEST_STRUCTURE>
2880 No documentation on this IOCTL operation was found.
2882 =item C<IOCTL_DISK_REQUEST_DATA>
2884 No documentation on this IOCTL operation was found.
2890 File system control operations. Used in the C<$uIoControlCode>
2891 argument to C<DeviceIoControl>.
2893 Includes C<FSCTL_SET_REPARSE_POINT>, C<FSCTL_GET_REPARSE_POINT>,
2894 C<FSCTL_DELETE_REPARSE_POINT>.
2898 =item C<FSCTL_SET_REPARSE_POINT>
2900 Sets reparse point data to be associated with $hDevice.
2902 =item C<FSCTL_GET_REPARSE_POINT>
2904 Retrieves the reparse point data associated with $hDevice.
2906 =item C<FSCTL_DELETE_REPARSE_POINT>
2908 Deletes the reparse point data associated with $hDevice.
2912 =item C<":GENERIC_">
2914 Constants specifying generic access permissions that are not specific
2915 to one type of object.
2917 GENERIC_ALL GENERIC_EXECUTE
2918 GENERIC_READ GENERIC_WRITE
2920 =item C<":MEDIA_TYPE">
2922 Different classes of media that a device can support. Used in the
2923 C<$uMediaType> field of a C<DISK_GEOMETRY> structure.
2931 =item C<F5_1Pt2_512>
2933 5.25" floppy, 1.2MB [really 1,200KB] total space, 512 bytes/sector.
2935 =item C<F3_1Pt44_512>
2937 3.5" floppy, 1.44MB [really 1,440KB] total space, 512 bytes/sector.
2939 =item C<F3_2Pt88_512>
2941 3.5" floppy, 2.88MB [really 2,880KB] total space, 512 bytes/sector.
2943 =item C<F3_20Pt8_512>
2945 3.5" floppy, 20.8MB total space, 512 bytes/sector.
2949 3.5" floppy, 720KB total space, 512 bytes/sector.
2953 5.25" floppy, 360KB total space, 512 bytes/sector.
2957 5.25" floppy, 320KB total space, 512 bytes/sector.
2959 =item C<F5_320_1024>
2961 5.25" floppy, 320KB total space, 1024 bytes/sector.
2965 5.25" floppy, 180KB total space, 512 bytes/sector.
2969 5.25" floppy, 160KB total space, 512 bytes/sector.
2971 =item C<RemovableMedia>
2973 Some type of removable media other than a floppy diskette.
2979 =item C<F3_120M_512>
2981 3.5" floppy, 120MB total space.
2985 =item C<":MOVEFILE_">
2987 Constants for use in C<$uFlags> arguments to C<MoveFileEx>.
2989 MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT
2990 MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH
2992 =item C<":SECURITY_">
2994 Security quality of service values that can be used in the C<$uFlags>
2995 argument to C<CreateFile> if opening the client side of a named pipe.
2997 SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING
2998 SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY
2999 SECURITY_IDENTIFICATION SECURITY_IMPERSONATION
3000 SECURITY_SQOS_PRESENT
3004 Constants to be used with C<SetErrorMode>.
3006 SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX
3007 SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX
3009 =item C<":PARTITION_">
3011 Constants describing partition types.
3013 PARTITION_ENTRY_UNUSED PARTITION_FAT_12
3014 PARTITION_XENIX_1 PARTITION_XENIX_2
3015 PARTITION_FAT_16 PARTITION_EXTENDED
3016 PARTITION_HUGE PARTITION_IFS
3017 PARTITION_FAT32 PARTITION_FAT32_XINT13
3018 PARTITION_XINT13 PARTITION_XINT13_EXTENDED
3019 PARTITION_PREP PARTITION_UNIX
3020 VALID_NTFT PARTITION_NTFT
3022 =item C<":STD_HANDLE_">
3024 Constants for GetStdHandle and SetStdHandle
3038 None known at this time.
3042 Tye McQueen, tye@metronet.com, http://perlmonks.org/?node=tye.