Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2492 lines
84 KiB

  1. # File.pm -- Low-level access to Win32 file/dir functions/constants.
  2. package Win32API::File;
  3. use strict;
  4. use Carp;
  5. use Fcntl qw( O_RDONLY O_RDWR O_WRONLY O_APPEND O_BINARY O_TEXT );
  6. use vars qw( $VERSION @ISA );
  7. use vars qw( @EXPORT @EXPORT_OK @EXPORT_FAIL %EXPORT_TAGS );
  8. $VERSION= '0.09';
  9. use base qw( Exporter DynaLoader );
  10. @EXPORT= qw();
  11. %EXPORT_TAGS= (
  12. Func => [qw( attrLetsToBits createFile
  13. fileConstant fileLastError getLogicalDrives
  14. CloseHandle CopyFile CreateFile
  15. DefineDosDevice DeleteFile DeviceIoControl
  16. FdGetOsFHandle GetDriveType GetFileType
  17. GetHandleInformation GetLogicalDrives GetLogicalDriveStrings
  18. GetOsFHandle GetVolumeInformation IsRecognizedPartition
  19. IsContainerPartition MoveFile MoveFileEx
  20. OsFHandleOpen OsFHandleOpenFd QueryDosDevice
  21. ReadFile SetErrorMode SetFilePointer
  22. SetHandleInformation WriteFile )],
  23. FuncA => [qw(
  24. CopyFileA CreateFileA DefineDosDeviceA
  25. DeleteFileA GetDriveTypeA GetLogicalDriveStringsA
  26. GetVolumeInformationA MoveFileA MoveFileExA
  27. QueryDosDeviceA )],
  28. FuncW => [qw(
  29. CopyFileW CreateFileW DefineDosDeviceW
  30. DeleteFileW GetDriveTypeW GetLogicalDriveStringsW
  31. GetVolumeInformationW MoveFileW MoveFileExW
  32. QueryDosDeviceW )],
  33. Misc => [qw(
  34. CREATE_ALWAYS CREATE_NEW FILE_BEGIN
  35. FILE_CURRENT FILE_END INVALID_HANDLE_VALUE
  36. OPEN_ALWAYS OPEN_EXISTING TRUNCATE_EXISTING )],
  37. DDD_ => [qw(
  38. DDD_EXACT_MATCH_ON_REMOVE DDD_RAW_TARGET_PATH
  39. DDD_REMOVE_DEFINITION )],
  40. DRIVE_ => [qw(
  41. DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE
  42. DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM
  43. DRIVE_RAMDISK )],
  44. FILE_ => [qw(
  45. FILE_READ_DATA FILE_LIST_DIRECTORY
  46. FILE_WRITE_DATA FILE_ADD_FILE
  47. FILE_APPEND_DATA FILE_ADD_SUBDIRECTORY
  48. FILE_CREATE_PIPE_INSTANCE FILE_READ_EA
  49. FILE_WRITE_EA FILE_EXECUTE
  50. FILE_TRAVERSE FILE_DELETE_CHILD
  51. FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES
  52. FILE_ALL_ACCESS FILE_GENERIC_READ
  53. FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE )],
  54. FILE_ATTRIBUTE_ => [qw(
  55. FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED
  56. FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL
  57. FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY
  58. FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY )],
  59. FILE_FLAG_ => [qw(
  60. FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_DELETE_ON_CLOSE
  61. FILE_FLAG_NO_BUFFERING FILE_FLAG_OVERLAPPED
  62. FILE_FLAG_POSIX_SEMANTICS FILE_FLAG_RANDOM_ACCESS
  63. FILE_FLAG_SEQUENTIAL_SCAN FILE_FLAG_WRITE_THROUGH )],
  64. FILE_SHARE_ => [qw(
  65. FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE )],
  66. FILE_TYPE_ => [qw(
  67. FILE_TYPE_CHAR FILE_TYPE_DISK FILE_TYPE_PIPE
  68. FILE_TYPE_UNKNOWN )],
  69. FS_ => [qw(
  70. FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE
  71. FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS
  72. FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED )],
  73. HANDLE_FLAG_ => [qw(
  74. HANDLE_FLAG_INHERIT HANDLE_FLAG_PROTECT_FROM_CLOSE )],
  75. IOCTL_STORAGE_ => [qw(
  76. IOCTL_STORAGE_CHECK_VERIFY IOCTL_STORAGE_MEDIA_REMOVAL
  77. IOCTL_STORAGE_EJECT_MEDIA IOCTL_STORAGE_LOAD_MEDIA
  78. IOCTL_STORAGE_RESERVE IOCTL_STORAGE_RELEASE
  79. IOCTL_STORAGE_FIND_NEW_DEVICES IOCTL_STORAGE_GET_MEDIA_TYPES
  80. )],
  81. IOCTL_DISK_ => [qw(
  82. IOCTL_DISK_FORMAT_TRACKS IOCTL_DISK_FORMAT_TRACKS_EX
  83. IOCTL_DISK_GET_DRIVE_GEOMETRY IOCTL_DISK_GET_DRIVE_LAYOUT
  84. IOCTL_DISK_GET_MEDIA_TYPES IOCTL_DISK_GET_PARTITION_INFO
  85. IOCTL_DISK_HISTOGRAM_DATA IOCTL_DISK_HISTOGRAM_RESET
  86. IOCTL_DISK_HISTOGRAM_STRUCTURE IOCTL_DISK_IS_WRITABLE
  87. IOCTL_DISK_LOGGING IOCTL_DISK_PERFORMANCE
  88. IOCTL_DISK_REASSIGN_BLOCKS IOCTL_DISK_REQUEST_DATA
  89. IOCTL_DISK_REQUEST_STRUCTURE IOCTL_DISK_SET_DRIVE_LAYOUT
  90. IOCTL_DISK_SET_PARTITION_INFO IOCTL_DISK_VERIFY )],
  91. GENERIC_ => [qw(
  92. GENERIC_ALL GENERIC_EXECUTE
  93. GENERIC_READ GENERIC_WRITE )],
  94. MEDIA_TYPE => [qw(
  95. Unknown F5_1Pt2_512 F3_1Pt44_512
  96. F3_2Pt88_512 F3_20Pt8_512 F3_720_512
  97. F5_360_512 F5_320_512 F5_320_1024
  98. F5_180_512 F5_160_512 RemovableMedia
  99. FixedMedia F3_120M_512 )],
  100. MOVEFILE_ => [qw(
  101. MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT
  102. MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH )],
  103. SECURITY_ => [qw(
  104. SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING
  105. SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY
  106. SECURITY_IDENTIFICATION SECURITY_IMPERSONATION
  107. SECURITY_SQOS_PRESENT )],
  108. SEM_ => [qw(
  109. SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX
  110. SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX )],
  111. PARTITION_ => [qw(
  112. PARTITION_ENTRY_UNUSED PARTITION_FAT_12
  113. PARTITION_XENIX_1 PARTITION_XENIX_2
  114. PARTITION_FAT_16 PARTITION_EXTENDED
  115. PARTITION_HUGE PARTITION_IFS
  116. PARTITION_FAT32 PARTITION_FAT32_XINT13
  117. PARTITION_XINT13 PARTITION_XINT13_EXTENDED
  118. PARTITION_PREP PARTITION_UNIX
  119. VALID_NTFT PARTITION_NTFT )],
  120. );
  121. @EXPORT_OK= ();
  122. {
  123. my $key;
  124. foreach $key ( keys(%EXPORT_TAGS) ) {
  125. push( @EXPORT_OK, @{$EXPORT_TAGS{$key}} );
  126. #push( @EXPORT_FAIL, @{$EXPORT_TAGS{$key}} ) unless $key =~ /^Func/;
  127. }
  128. }
  129. $EXPORT_TAGS{ALL}= \@EXPORT_OK;
  130. bootstrap Win32API::File $VERSION;
  131. # Preloaded methods go here.
  132. # To convert C constants to Perl code in cFile.pc
  133. # [instead of C or C++ code in cFile.h]:
  134. # * Modify F<Makefile.PL> to add WriteMakeFile() =>
  135. # CONST2PERL/postamble => [[ "Win32API::File" => ]] WRITE_PERL => 1.
  136. # * Either comment out C<#include "cFile.h"> from F<File.xs>
  137. # or make F<cFile.h> an empty file.
  138. # * Make sure the following C<if> block is not commented out.
  139. # * "nmake clean", "perl Makefile.PL", "nmake"
  140. if( ! defined &GENERIC_READ ) {
  141. require "Win32API/File/cFile.pc";
  142. }
  143. sub fileConstant
  144. {
  145. my( $name )= @_;
  146. if( 1 != @_ || ! $name || $name =~ /\W/ ) {
  147. require Carp;
  148. Carp::croak( 'Usage: ',__PACKAGE__,'::fileConstant("CONST_NAME")' );
  149. }
  150. my $proto= prototype $name;
  151. if( defined \&$name
  152. && defined $proto
  153. && "" eq $proto ) {
  154. no strict 'refs';
  155. return &$name;
  156. }
  157. return undef;
  158. }
  159. # We provide this for backwards compatibility:
  160. sub constant
  161. {
  162. my( $name )= @_;
  163. my $value= fileConstant( $name );
  164. if( defined $value ) {
  165. $!= 0;
  166. return $value;
  167. }
  168. $!= 11; # EINVAL
  169. return 0;
  170. }
  171. BEGIN {
  172. my $code= 'return _fileLastError(@_)';
  173. local( $!, $^E )= ( 1, 1 );
  174. if( $! ne $^E ) {
  175. $code= '
  176. local( $^E )= _fileLastError(@_);
  177. my $ret= $^E;
  178. return $ret;
  179. ';
  180. }
  181. eval "sub fileLastError { $code }";
  182. die "$@" if $@;
  183. }
  184. # Since we ISA DynaLoader which ISA AutoLoader, we ISA AutoLoader so we
  185. # need this next chunk to prevent Win32API::File->nonesuch() from
  186. # looking for "nonesuch.al" and producing confusing error messages:
  187. use vars qw($AUTOLOAD);
  188. sub AUTOLOAD {
  189. require Carp;
  190. Carp::croak(
  191. "Can't locate method $AUTOLOAD via package Win32API::File" );
  192. }
  193. # Replace "&rout;" with "goto &rout;" when that is supported on Win32.
  194. # Aliases for non-Unicode functions:
  195. sub CopyFile { &CopyFileA; }
  196. sub CreateFile { &CreateFileA; }
  197. sub DefineDosDevice { &DefineDosDeviceA; }
  198. sub DeleteFile { &DeleteFileA; }
  199. sub GetDriveType { &GetDriveTypeA; }
  200. sub GetLogicalDriveStrings { &GetLogicalDriveStringsA; }
  201. sub GetVolumeInformation { &GetVolumeInformationA; }
  202. sub MoveFile { &MoveFileA; }
  203. sub MoveFileEx { &MoveFileExA; }
  204. sub QueryDosDevice { &QueryDosDeviceA; }
  205. sub OsFHandleOpen {
  206. if( 3 != @_ ) {
  207. croak 'Win32API::File Usage: ',
  208. 'OsFHandleOpen(FILE,$hNativeHandle,"rwatb")';
  209. }
  210. my( $fh, $osfh, $access )= @_;
  211. if( ! ref($fh) ) {
  212. if( $fh !~ /('|::)/ ) {
  213. $fh= caller() . "::" . $fh;
  214. }
  215. no strict "refs";
  216. $fh= \*{$fh};
  217. }
  218. my( $mode, $pref );
  219. if( $access =~ /r/i ) {
  220. if( $access =~ /w/i ) {
  221. $mode= O_RDWR;
  222. $pref= "+<";
  223. } else {
  224. $mode= O_RDONLY;
  225. $pref= "<";
  226. }
  227. } else {
  228. if( $access =~ /w/i ) {
  229. $mode= O_WRONLY;
  230. $pref= ">";
  231. } else {
  232. # croak qq<Win32API::File::OsFHandleOpen(): >,
  233. # qq<Access ($access) missing both "r" and "w">;
  234. $mode= O_RDONLY;
  235. $pref= "<";
  236. }
  237. }
  238. $mode |= O_APPEND if $access =~ /a/i;
  239. #$mode |= O_TEXT if $access =~ /t/i;
  240. # Some versions of the Fcntl module are broken and won't autoload O_TEXT:
  241. if( $access =~ /t/i ) {
  242. my $o_text= eval "O_TEXT";
  243. $o_text= 0x4000 if $@;
  244. $mode |= $o_text;
  245. }
  246. $mode |= O_BINARY if $access =~ /b/i;
  247. my $fd= OsFHandleOpenFd( $osfh, $mode );
  248. return undef if $fd < 0;
  249. return open( $fh, $pref."&=".$fd );
  250. }
  251. sub GetOsFHandle {
  252. if( 1 != @_ ) {
  253. croak 'Win32API::File Usage: $OsFHandle= GetOsFHandle(FILE)';
  254. }
  255. my( $file )= @_;
  256. if( ! ref($file) ) {
  257. if( $file !~ /('|::)/ ) {
  258. $file= caller() . "::" . $file;
  259. }
  260. no strict "refs";
  261. $file= \*{$file};
  262. }
  263. my( $fd )= fileno($file);
  264. if( ! defined( $fd ) ) {
  265. if( $file =~ /^\d+\Z/ ) {
  266. $fd= $file;
  267. } else {
  268. return (); # $! should be set by fileno().
  269. }
  270. }
  271. my $h= FdGetOsFHandle( $fd );
  272. if( INVALID_HANDLE_VALUE() == $h ) {
  273. $h= "";
  274. } elsif( "0" eq $h ) {
  275. $h= "0 but true";
  276. }
  277. return $h;
  278. }
  279. sub attrLetsToBits
  280. {
  281. my( $lets )= @_;
  282. my( %a )= (
  283. "a"=>FILE_ATTRIBUTE_ARCHIVE(), "c"=>FILE_ATTRIBUTE_COMPRESSED(),
  284. "h"=>FILE_ATTRIBUTE_HIDDEN(), "o"=>FILE_ATTRIBUTE_OFFLINE(),
  285. "r"=>FILE_ATTRIBUTE_READONLY(), "s"=>FILE_ATTRIBUTE_SYSTEM(),
  286. "t"=>FILE_ATTRIBUTE_TEMPORARY() );
  287. my( $bits )= 0;
  288. foreach( split(//,$lets) ) {
  289. croak "Win32API::File::attrLetsToBits: Unknown attribute letter ($_)"
  290. unless exists $a{$_};
  291. $bits |= $a{$_};
  292. }
  293. return $bits;
  294. }
  295. use vars qw( @_createFile_Opts %_createFile_Opts );
  296. @_createFile_Opts= qw( Access Create Share Attributes
  297. Flags Security Model );
  298. @_createFile_Opts{@_createFile_Opts}= (1) x @_createFile_Opts;
  299. sub createFile
  300. {
  301. my $opts= "";
  302. if( 2 <= @_ && "HASH" eq ref($_[$#_]) ) {
  303. $opts= pop( @_ );
  304. }
  305. my( $sPath, $svAccess, $svShare )= @_;
  306. if( @_ < 1 || 3 < @_ ) {
  307. croak "Win32API::File::createFile() usage: \$hObject= createFile(\n",
  308. " \$sPath, [\$svAccess_qrw_ktn_ce,[\$svShare_rwd,]]",
  309. " [{Option=>\$Value}] )\n",
  310. " options: @_createFile_Opts\nCalled";
  311. }
  312. my( $create, $flags, $sec, $model )= ( "", 0, [], 0 );
  313. if( ref($opts) ) {
  314. my @err= grep( ! $_createFile_Opts{$_}, keys(%$opts) );
  315. @err and croak "_createFile: Invalid options (@err)";
  316. $flags= $opts->{Flags} if exists( $opts->{Flags} );
  317. $flags |= attrLetsToBits( $opts->{Attributes} )
  318. if exists( $opts->{Attributes} );
  319. $sec= $opts->{Security} if exists( $opts->{Security} );
  320. $model= $opts->{Model} if exists( $opts->{Model} );
  321. $svAccess= $opts->{Access} if exists( $opts->{Access} );
  322. $create= $opts->{Create} if exists( $opts->{Create} );
  323. $svShare= $opts->{Share} if exists( $opts->{Share} );
  324. }
  325. $svAccess= "r" unless defined($svAccess);
  326. $svShare= "rw" unless defined($svShare);
  327. if( $svAccess =~ /^[qrw ktn ce]*$/i ) {
  328. ( my $c= $svAccess ) =~ tr/qrw QRW//d;
  329. $create= $c if "" ne $c && "" eq $create;
  330. local( $_ )= $svAccess;
  331. $svAccess= 0;
  332. $svAccess |= GENERIC_READ() if /r/i;
  333. $svAccess |= GENERIC_WRITE() if /w/i;
  334. } elsif( "?" eq $svAccess ) {
  335. croak
  336. "Win32API::File::createFile: \$svAccess can use the following:\n",
  337. " One or more of the following:\n",
  338. "\tq -- Query access (same as 0)\n",
  339. "\tr -- Read access (GENERIC_READ)\n",
  340. "\tw -- Write access (GENERIC_WRITE)\n",
  341. " At most one of the following:\n",
  342. "\tk -- Keep if exists\n",
  343. "\tt -- Truncate if exists\n",
  344. "\tn -- New file only (fail if file already exists)\n",
  345. " At most one of the following:\n",
  346. "\tc -- Create if doesn't exist\n",
  347. "\te -- Existing file only (fail if doesn't exist)\n",
  348. " '' is the same as 'q k e'\n",
  349. " 'r' is the same as 'r k e'\n",
  350. " 'w' is the same as 'w t c'\n",
  351. " 'rw' is the same as 'rw k c'\n",
  352. " 'rt' or 'rn' implies 'c'.\n",
  353. " Or \$svAccess can be numeric.\n", "Called from";
  354. } elsif( $svAccess == 0 && $svAccess !~ /^[-+.]*0/ ) {
  355. croak "Win32API::File::createFile: Invalid \$svAccess ($svAccess)";
  356. }
  357. if( $create =~ /^[ktn ce]*$/ ) {
  358. local( $_ )= $create;
  359. my( $k, $t, $n, $c, $e )= ( scalar(/k/i), scalar(/t/i),
  360. scalar(/n/i), scalar(/c/i), scalar(/e/i) );
  361. if( 1 < $k + $t + $n ) {
  362. croak "Win32API::File::createFile: \$create must not use ",
  363. qq<more than one of "k", "t", and "n" ($create)>;
  364. }
  365. if( $c && $e ) {
  366. croak "Win32API::File::createFile: \$create must not use ",
  367. qq<both "c" and "e" ($create)>;
  368. }
  369. my $r= ( $svAccess & GENERIC_READ() ) == GENERIC_READ();
  370. my $w= ( $svAccess & GENERIC_WRITE() ) == GENERIC_WRITE();
  371. if( ! $k && ! $t && ! $n ) {
  372. if( $w && ! $r ) { $t= 1;
  373. } else { $k= 1; }
  374. }
  375. if( $k ) {
  376. if( $c || $w && ! $e ) { $create= OPEN_ALWAYS();
  377. } else { $create= OPEN_EXISTING(); }
  378. } elsif( $t ) {
  379. if( $e ) { $create= TRUNCATE_EXISTING();
  380. } else { $create= CREATE_ALWAYS(); }
  381. } else { # $n
  382. if( ! $e ) { $create= CREATE_NEW();
  383. } else {
  384. croak "Win32API::File::createFile: \$create must not use ",
  385. qq<both "n" and "e" ($create)>;
  386. }
  387. }
  388. } elsif( "?" eq $create ) {
  389. croak 'Win32API::File::createFile: $create !~ /^[ktn ce]*$/;',
  390. ' pass $svAccess as "?" for more information.';
  391. } elsif( $create == 0 && $create ne "0" ) {
  392. croak "Win32API::File::createFile: Invalid \$create ($create)";
  393. }
  394. if( $svShare =~ /^[drw]*$/ ) {
  395. my %s= ( "d"=>FILE_SHARE_DELETE(), "r"=>FILE_SHARE_READ(),
  396. "w"=>FILE_SHARE_WRITE() );
  397. my @s= split(//,$svShare);
  398. $svShare= 0;
  399. foreach( @s ) {
  400. $svShare |= $s{$_};
  401. }
  402. } elsif( $svShare == 0 && $svShare !~ /^[-+.]*0/ ) {
  403. croak "Win32API::File::createFile: Invalid \$svShare ($svShare)";
  404. }
  405. return CreateFileA(
  406. $sPath, $svAccess, $svShare, $sec, $create, $flags, $model );
  407. }
  408. sub getLogicalDrives
  409. {
  410. my( $ref )= @_;
  411. my $s= "";
  412. if( ! GetLogicalDriveStringsA( 256, $s ) ) {
  413. return undef;
  414. }
  415. if( ! defined($ref) ) {
  416. return split( /\0/, $s );
  417. } elsif( "ARRAY" ne ref($ref) ) {
  418. croak 'Usage: C<@arr= getLogicalDrives()> ',
  419. 'or C<getLogicalDrives(\\@arr)>', "\n";
  420. }
  421. @$ref= split( /\0/, $s );
  422. return $ref;
  423. }
  424. # Autoload methods go after =cut, and are processed by the autosplit program.
  425. 1;
  426. __END__
  427. =head1 NAME
  428. Win32API::File - Low-level access to Win32 system API calls for files/dirs.
  429. =head1 SYNOPSIS
  430. use Win32API::File 0.08 qw( :ALL );
  431. MoveFile( $Source, $Destination )
  432. or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
  433. MoveFileEx( $Source, $Destination, MOVEFILE_REPLACE_EXISTING() )
  434. or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
  435. [...]
  436. =head1 DESCRIPTION
  437. This provides fairly low-level access to the Win32 System API
  438. calls dealing with files and directories.
  439. To pass in C<NULL> as the pointer to an optional buffer, pass in
  440. an empty list reference, C<[]>.
  441. Beyond raw access to the API calls and related constants, this module
  442. handles smart buffer allocation and translation of return codes.
  443. All functions, unless otherwise noted, return a true value for success
  444. and a false value for failure and set C<$^E> on failure.
  445. =head2 Exports
  446. Nothing is exported by default. The following tags can be used to
  447. have large sets of symbols exported: C<":Func">, C<":FuncA">,
  448. C<":FuncW">, C<":Misc">, C<":DDD_">, C<":DRIVE_">, C<":FILE_">,
  449. C<":FILE_ATTRIBUTE_">, C<":FILE_FLAG_">, C<":FILE_SHARE_">,
  450. C<":FILE_TYPE_">, C<":FS_">, C<":HANDLE_FLAG_">, C<":IOCTL_STORAGE_">,
  451. C<":IOCTL_DISK_">, C<":GENERIC_">, C<":MEDIA_TYPE">, C<":MOVEFILE_">,
  452. C<":SECURITY_">, C<":SEM_">, and C<":PARTITION_">.
  453. =over
  454. =item C<":Func">
  455. The basic function names: C<attrLetsToBits>, C<createFile>,
  456. C<fileConstant>, C<fileLastError>, C<getLogicalDrives>,
  457. C<CloseHandle>, C<CopyFile>, C<CreateFile>,
  458. C<DefineDosDevice>, C<DeleteFile>, C<DeviceIoControl>,
  459. C<FdGetOsFHandle>, C<GetDriveType>, C<GetFileType>,
  460. C<GetHandleInformation>, C<GetLogicalDrives>, C<GetLogicalDriveStrings>,
  461. C<GetOsFHandle>, C<GetVolumeInformation>, C<IsRecognizedPartition>,
  462. C<IsContainerPartition>, C<MoveFile>, C<MoveFileEx>,
  463. C<OsFHandleOpen>, C<OsFHandleOpenFd>, C<QueryDosDevice>,
  464. C<ReadFile>, C<SetErrorMode>, C<SetFilePointer>,
  465. C<SetHandleInformation>, and C<WriteFile>.
  466. =over
  467. =item attrLetsToBits
  468. =item C<$uBits= attrLetsToBits( $sAttributeLetters )>
  469. Converts a string of file attribute letters into an unsigned value with
  470. the corresponding bits set. C<$sAttributeLetters> should contain zero
  471. or more letters from C<"achorst">:
  472. =over
  473. =item C<"a">
  474. C<FILE_ATTRIBUTE_ARCHIVE>
  475. =item C<"c">
  476. C<FILE_ATTRIBUTE_COMPRESSED>
  477. =item C<"h">
  478. C<FILE_ATTRIBUTE_HIDDEN>
  479. =item C<"o">
  480. C<FILE_ATTRIBUTE_OFFLINE>
  481. =item C<"r">
  482. C<FILE_ATTRIBUTE_READONLY>
  483. =item C<"s">
  484. C<FILE_ATTRIBUTE_SYSTEM>
  485. =item C<"t">
  486. C<FILE_ATTRIBUTE_TEMPORARY>
  487. =back
  488. =item createFile
  489. =item C<$hObject= createFile( $sPath )>
  490. =item C<$hObject= createFile( $sPath, $rvhvOptions )>
  491. =item C<$hObject= createFile( $sPath, $svAccess )>
  492. =item C<$hObject= createFile( $sPath, $svAccess, $rvhvOptions )>
  493. =item C<$hObject= createFile( $sPath, $svAccess, $svShare )>
  494. =item C<$hObject= createFile( $sPath, $svAccess, $svShare, $rvhvOptions )>
  495. This is a Perl-friendly wrapper around C<CreateFile>.
  496. On failure, C<$hObject> gets set to a false value and C<regLastError()>
  497. and C<$^E> are set to the reason for the failure. Otherwise,
  498. C<$hObject> gets set to a Win32 native file handle which is alwasy
  499. a true value [returns C<"0 but true"> in the impossible(?) case of
  500. the handle having a value of C<0>].
  501. C<$sPath> is the path to the file [or device, etc.] to be opened. See
  502. C<CreateFile> for more information on possible special values for
  503. C<$sPath>.
  504. C<$svAccess> can be a number containing the bit mask representing
  505. the specific type(s) of access to the file that you desire. See the
  506. C<$uAccess> parameter to C<CreateFile> for more information on these
  507. values.
  508. More likely, C<$svAccess> is a string describing the generic type of
  509. access you desire and possibly the file creation options to use. In
  510. this case, C<$svAccess> should contain zero or more characters from
  511. C<"qrw"> [access desired], zero or one character each from C<"ktn">
  512. and C<"ce">, and optional white space. These letters stand for,
  513. respectively, "Query access", "Read access", "Write access", "Keep if
  514. exists", "Truncate if exists", "New file only", "Create if none", and
  515. "Existing file only". Case is ignored.
  516. You can pass in C<"?"> for C<$svAccess> to have an error message
  517. displayed summarizing its possible values. This is very handy when
  518. doing on-the-fly programming using the Perl debugger:
  519. Win32API::File::createFile: $svAccess can use the following:
  520. One or more of the following:
  521. q -- Query access (same as 0)
  522. r -- Read access (GENERIC_READ)
  523. w -- Write access (GENERIC_WRITE)
  524. At most one of the following:
  525. k -- Keep if exists
  526. t -- Truncate if exists
  527. n -- New file only (fail if file already exists)
  528. At most one of the following:
  529. c -- Create if doesn't exist
  530. e -- Existing file only (fail if doesn't exist)
  531. '' is the same as 'q k e'
  532. 'r' is the same as 'r k e'
  533. 'w' is the same as 'w t c'
  534. 'rw' is the same as 'rw k c'
  535. 'rt' or 'rn' implies 'c'.
  536. Or $access can be numeric.
  537. C<$svAccess> is designed to be "do what I mean", so you can skip
  538. the rest of its explanation unless you are interested in the complex
  539. details. Note that, if you want write access to a device, you need
  540. to specify C<"k"> [and perhaps C<"e">, as in C<"w ke"> or C<"rw ke">]
  541. since Win32 suggests C<OPEN_EXISTING> be used when opening a device.
  542. =over
  543. =item C<"q">
  544. Stands for "Query access". This is really a no-op since you always have
  545. query access when you open a file. You can specify C<"q"> to document
  546. that you plan to query the file [or device, etc.]. This is especially
  547. helpful when you don't want read nor write access since something like
  548. C<"q"> or C<"q ke"> may be easier to understand than just C<""> or C<"ke">.
  549. =item C<"r">
  550. Stands for "Read access". Sets the C<GENERIC_READ> bit(s) in the
  551. C<$uAccess> that is passed to C<CreateFile>. This is the default
  552. access if the C<$svAccess> parameter is missing [or if it is C<undef>
  553. and C<$rvhvOptions> doesn't specify an C<"Access"> option].
  554. =item C<"w">
  555. Stands for "Write access". Sets the C<GENERIC_WRITE> bit(s) in the
  556. C<$uAccess> that is passed to C<CreateFile>.
  557. =item C<"k">
  558. Stands for "Keep if exists". If the requested file exists, then it is
  559. opened. This is the default unless C<GENERIC_WRITE> access has been
  560. requested but C<GENERIC_READ> access has not been requested. Contrast
  561. with C<"t"> and C<"n">.
  562. =item C<"t">
  563. Stands for "Truncate if exists". If the requested file exists, then
  564. it is truncated to zero length and then opened. This is the default if
  565. C<GENERIC_WRITE> access has been requested and C<GENERIC_READ> access
  566. has not been requested. Contrast with C<"k"> and C<"n">.
  567. =item C<"n">
  568. Stands for "New file only". If the requested file exists, then it is
  569. not opened and the C<createFile> call fails. Contrast with C<"k"> and
  570. C<"t">. Can't be used with C<"e">.
  571. =item C<"c">
  572. Stands for "Create if none". If the requested file does not
  573. exist, then it is created and then opened. This is the default
  574. if C<GENERIC_WRITE> access has been requested or if C<"t"> or
  575. C<"n"> was specified. Contrast with C<"e">.
  576. =item C<"e">
  577. Stands for "Existing file only". If the requested file does not
  578. exist, then nothing is opened and the C<createFile> call fails. This
  579. is the default unless C<GENERIC_WRITE> access has been requested or
  580. C<"t"> or C<"n"> was specified. Contrast with C<"c">. Can't be
  581. used with C<"n">.
  582. =back
  583. The characters from C<"ktn"> and C<"ce"> are combined to determine the
  584. what value for C<$uCreate> to pass to C<CreateFile> [unless overridden
  585. by C<$rvhvOptions>]:
  586. =over
  587. =item C<"kc">
  588. C<OPEN_ALWAYS>
  589. =item C<"ke">
  590. C<OPEN_EXISTING>
  591. =item C<"tc">
  592. C<TRUNCATE_EXISTING>
  593. =item C<"te">
  594. C<CREATE_ALWAYS>
  595. =item C<"nc">
  596. C<CREATE_NEW>
  597. =item C<"ne">
  598. Illegal.
  599. =back
  600. C<$svShare> controls how the file is shared, that is, whether other
  601. processes can have read, write, and/or delete access to the file while
  602. we have it opened. C<$svShare> will usually be a string containing zero
  603. or more characters from C<"rwd"> but can also be a numeric bit mask.
  604. C<"r"> sets the C<FILE_SHARE_READ> bit which allows other processes to have
  605. read access to the file. C<"w"> sets the C<FILE_SHARE_WRITE> bit which
  606. allows other processes to have write access to the file. C<"d"> sets the
  607. C<FILE_SHARE_DELETE> bit which allows other processes to have delete access
  608. to the file [ignored under Windows 95].
  609. The default for C<$svShare> is C<"rw"> which provides the same sharing as
  610. using regular perl C<open()>.
  611. If another process currently has read, write, and/or delete access to
  612. the file and you don't allow that level of sharing, then your call to
  613. C<createFile> will fail. If you requested read, write, and/or delete
  614. access and another process already has the file open but doesn't allow
  615. that level of sharing, then your call to C<createFile> will fail. Once
  616. you have the file open, if another process tries to open it with read,
  617. write, and/or delete access and you don't allow that level of sharing,
  618. then that process won't be allowed to open the file.
  619. C<$rvhvOptions> is a reference to a hash where any keys must be from
  620. the list C<qw( Access Create Share Attributes Flags Security Model )>.
  621. The meaning of the value depends on the key name, as described below.
  622. Any option values in C<$rvhvOptions> override the settings from
  623. C<$svAccess> and C<$svShare> if they conflict.
  624. =over
  625. =item Flags => $uFlags
  626. C<$uFlags> is an unsigned value having any of the C<FILE_FLAG_*> or
  627. C<FILE_ATTRIBUTE_*> bits set. Any C<FILE_ATTRIBUTE_*> bits set via the
  628. C<Attributes> option are logically C<or>ed with these bits. Defaults
  629. to C<0>.
  630. If opening the client side of a named pipe, then you can also specify
  631. C<SECURITY_SQOS_PRESENT> along with one of the other C<SECURITY_*>
  632. constants to specify the security quality of service to be used.
  633. =item Attributes => $sAttributes
  634. A string of zero or more characters from C<"achorst"> [see C<attrLetsToBits>
  635. for more information] which are converted to C<FILE_ATTRIBUTE_*> bits to
  636. be set in the C<$uFlags> argument passed to C<CreateFile>.
  637. =item Security => $pSecurityAttributes
  638. C<$pSecurityAttributes> should contain a C<SECURITY_ATTRIBUTES> structure
  639. packed into a string or C<[]> [the default].
  640. =item Model => $hModelFile
  641. C<$hModelFile> should contain a handle opened with C<GENERIC_READ>
  642. access to a model file from which file attributes and extended attributes
  643. are to be copied. Or C<$hModelFile> can be C<0> [the default].
  644. =item Access => $sAccess
  645. =item Access => $uAccess
  646. C<$sAccess> should be a string of zero or more characters from
  647. C<"qrw"> specifying the type of access desired: "query" or C<0>,
  648. "read" or C<GENERIC_READ> [the default], or "write" or
  649. C<GENERIC_WRITE>.
  650. C<$uAccess> should be an unsigned value containing bits set to
  651. indicate the type of access desired. C<GENERIC_READ> is the default.
  652. =item Create => $sCreate
  653. =item Create => $uCreate
  654. C<$sCreate> should be a string constaing zero or one character from
  655. C<"ktn"> and zero or one character from C<"ce">. These stand for
  656. "Keep if exists", "Truncate if exists", "New file only", "Create if
  657. none", and "Existing file only". These are translated into a
  658. C<$uCreate> value.
  659. C<$uCreate> should be one of C<OPEN_ALWAYS>, C<OPEN_EXISTING>,
  660. C<TRUNCATE_EXISTING>, C<CREATE_ALWAYS>, or C<CREATE_NEW>.
  661. =item Share => $sShare
  662. =item Share => $uShare
  663. C<$sShare> should be a string with zero or more characters from
  664. C<"rwd"> that is translated into a C<$uShare> value. C<"rw"> is
  665. the default.
  666. C<$uShare> should be an unsigned value having zero or more of the
  667. following bits set: C<FILE_SHARE_READ>, C<FILE_SHARE_WRITE>, and
  668. C<FILE_SHARE_DELETE>. C<FILE_SHARE_READ|FILE_SHARE_WRITE> is the
  669. default.
  670. =back
  671. Examples:
  672. $hFlop= createFile( "//./A:", "r", "r" )
  673. or die "Can't prevent others from writing to floppy: $^E\n";
  674. $hDisk= createFile( "//./C:", "rw ke", "" )
  675. or die "Can't get exclusive access to C: $^E\n";
  676. $hDisk= createFile( $sFilePath, "ke",
  677. { Access=>FILE_READ_ATTRIBUTES } )
  678. or die "Can't read attributes of $sFilePath: $^E\n";
  679. $hTemp= createFile( "$ENV{Temp}/temp.$$", "wn", "",
  680. { Attributes=>"hst", Flags=>FILE_FLAG_DELETE_ON_CLOSE() } )
  681. or die "Can't create temporary file, temp.$$: $^E\n";
  682. =item getLogicalDrives
  683. =item C<@roots= getLogicalDrives()>
  684. Returns the paths to the root directories of all logical drives
  685. currently defined. This includes all types of drive lettters, such
  686. as floppies, CD-ROMs, hard disks, and network shares. A typical
  687. return value on a poorly equipped computer would be C<("A:\\","C:\\")>.
  688. =item CloseHandle
  689. =item C<CloseHandle( $hObject )>
  690. Closes a Win32 native handle, such as one opened via C<CreateFile>.
  691. Like most routines, returns a true value if successful and a false
  692. value [and sets C<$^E> and C<regLastError()>] on failure.
  693. =item CopyFile
  694. =item C<CopyFile( $sOldFileName, $sNewFileName, $bFailIfExists )>
  695. C<$sOldFileName> is the path to the file to be copied.
  696. C<$sNewFileName> is the path to where the file should be copied.
  697. Note that you can B<NOT> just specify a path to a directory in
  698. C<$sNewFileName> to copy the file to that directory using the
  699. same file name.
  700. If C<$bFailIfExists> is true and C<$sNewFileName> is the path to
  701. a file that already exists, then C<CopyFile> will fail. If
  702. C<$bFailIfExists> is falsea, then the copy of the C<$sOldFileNmae>
  703. file will overwrite the C<$sNewFileName> file if it already exists.
  704. Like most routines, returns a true value if successful and a false
  705. value [and sets C<$^E> and C<regLastError()>] on failure.
  706. =item CreateFile
  707. =item C<$hObject= CreateFile( $sPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel )>
  708. On failure, C<$hObject> gets set to a false value and C<$^E> and
  709. C<fileLastError()> are set to the reason for the failure. Otherwise,
  710. C<$hObject> gets set to a Win32 native file handle which is always a
  711. true value [returns C<"0 but true"> in the impossible(?) case of the
  712. handle having a value of C<0>].
  713. C<$sPath> is the path to the file [or device, etc.] to be opened.
  714. C<$sPath> can use C<"/"> or C<"\\"> as path delimiters and can even
  715. mix the two. We will usually only use C<"/"> in our examples since
  716. using C<"\\"> is usually harder to read.
  717. Under Windows NT, C<$sPath> can start with C<"//?/"> to allow the use
  718. of paths longer than C<MAX_PATH> [for UNC paths, replace the leading
  719. C<"//"> with C<"//?/UNC/">, as in C<"//?/UNC/Server/Share/Dir/File.Ext">].
  720. C<$sPath> can start with C<"//./"> to indicate that the rest of the
  721. path is the name of a "DOS device." You can use C<QueryDosDevice>
  722. to list all current DOS devices and can add or delete them with
  723. C<DefineDosDevice>. If you get the source-code distribution of this
  724. module from CPAN, then it includes an example script, F<ex/ListDevs.plx>
  725. that will list all current DOS devices and their "native" definition.
  726. Again, note that this doesn't work under Win95 nor Win98.
  727. The most common such DOS devices include:
  728. =over
  729. =item C<"//./PhysicalDrive0">
  730. Your entire first hard disk. Doesn't work under Windows 95. This
  731. allows you to read or write raw sectors of your hard disk and to use
  732. C<DeviceIoControl> to perform miscellaneous queries and operations
  733. to the hard disk. Writing raw sectors and certain other operations
  734. can seriously damage your files or the function of your computer.
  735. Locking this for exclusive access [by specifying C<0> for C<$uShare>]
  736. doesn't prevent access to the partitions on the disk nor their file
  737. systems. So other processes can still access any raw sectors within
  738. a partition and can use the file system on the disk as usual.
  739. =item C<"//./C:">
  740. Your F<C:> partition. Doesn't work under Windows 95. This allows
  741. you to read or write raw sectors of that partition and to use
  742. C<DeviceIoControl> to perform miscellaneous queries and operations
  743. to the partition. Writing raw sectors and certain other operations
  744. can seriously damage your files or the function of your computer.
  745. Locking this for exclusive access doesn't prevent access to the
  746. physical drive that the partition is on so other processes can
  747. still access the raw sectors that way. Locking this for exclusive
  748. access B<does> prevent other processes from opening the same raw
  749. partition and B<does> prevent access to the file system on it. It
  750. even prevents the current process from accessing the file system
  751. on that partition.
  752. =item C<"//./A:">
  753. The raw floppy disk. Doesn't work under Windows 95. This allows
  754. you to read or write raw sectors of the floppy disk and to use
  755. C<DeviceIoControl> to perform miscellaneous queries and operations
  756. to the floopy disk or drive.
  757. Locking this for exclusive access prevents all access to the floppy.
  758. =item C<"//./PIPE/PipeName">
  759. A named pipe, created via C<CreateNamedPipe>.
  760. =back
  761. C<$uAccess> is an unsigned value with bits set indicating the
  762. type of access desired. Usually either C<0> ["query" access],
  763. C<GENERIC_READ>, C<GENERIC_WRITE>, C<GENERIC_READ|GENERIC_WRITE>,
  764. or C<GENERIC_ALL>. More specific types of access can be specified,
  765. such as C<FILE_APPEND_DATA> or C<FILE_READ_EA>.
  766. C<$uShare> controls how the file is shared, that is, whether other
  767. processes can have read, write, and/or delete access to the file while
  768. we have it opened. C<$uShare> is an unsigned value with zero or more
  769. of these bits set: C<FILE_SHARE_READ>, C<FILE_SHARE_WRITE>, and
  770. C<FILE_SHARE_DELETE>.
  771. If another process currently has read, write, and/or delete access to
  772. the file and you don't allow that level of sharing, then your call to
  773. C<CreateFile> will fail. If you requested read, write, and/or delete
  774. access and another process already has the file open but doesn't allow
  775. that level of sharing, thenn your call to C<createFile> will fail. Once
  776. you have the file open, if another process tries to open it with read,
  777. write, and/or delete access and you don't allow that level of sharing,
  778. then that process won't be allowed to open the file.
  779. C<$pSecAttr> should either be C<[]> [for C<NULL>] or a
  780. C<SECURITY_ATTRIBUTES> data structure packed into a string.
  781. For example, if C<$pSecDesc> contains a C<SECURITY_DESCRIPTOR>
  782. structure packed into a string, perhaps via:
  783. RegGetKeySecurity( $key, 4, $pSecDesc, 1024 );
  784. then you can set C<$pSecAttr> via:
  785. $pSecAttr= pack( "L P i", 12, $pSecDesc, $bInheritHandle );
  786. C<$uCreate> is one of the following values: C<OPEN_ALWAYS>,
  787. C<OPEN_EXISTING>, C<TRUNCATE_EXISTING>, C<CREATE_ALWAYS>, and
  788. C<CREATE_NEW>.
  789. C<$uFlags> is an unsigned value with zero or more bits set indicating
  790. attributes to associate with the file [C<FILE_ATTRIBUTE_*> values] or
  791. special options [C<FILE_FLAG_*> values].
  792. If opening the client side of a named pipe, then you can also set
  793. C<$uFlags> to include C<SECURITY_SQOS_PRESENT> along with one of the
  794. other C<SECURITY_*> constants to specify the security quality of
  795. service to be used.
  796. C<$hModel> is C<0> [or C<[]>, both of which mean C<NULL>] or a Win32
  797. native handle opened with C<GENERIC_READ> access to a model file from
  798. which file attributes and extended attributes are to be copied if a
  799. new file gets created.
  800. Examples:
  801. $hFlop= CreateFile( "//./A:", GENERIC_READ(),
  802. FILE_SHARE_READ(), [], OPEN_EXISTING(), 0, [] )
  803. or die "Can't prevent others from writing to floppy: $^E\n";
  804. $hDisk= createFile( $sFilePath, FILE_READ_ATTRIBUTES(),
  805. FILE_SHARE_READ()|FILE_SHARE_WRITE(), [], OPEN_EXISTING(), 0, [] )
  806. or die "Can't read attributes of $sFilePath: $^E\n";
  807. $hTemp= createFile( "$ENV{Temp}/temp.$$", GENERIC_WRITE(), 0,
  808. CREATE_NEW(), FILE_FLAG_DELETE_ON_CLOSE()|attrLetsToBits("hst"), [] )
  809. or die "Can't create temporary file, temp.$$: $^E\n";
  810. =item DefineDosDevice
  811. =item C<DefineDosDevice( $uFlags, $sDosDeviceName, $sTargetPath )>
  812. Defines a new DOS device, overrides the current definition of a DOS
  813. device, or deletes a definition of a DOS device. Like most routines,
  814. returns a true value if successful and a false value [and sets C<$^E>
  815. and C<regLastError()>] on failure.
  816. C<$sDosDeviceName> is the name of a DOS device for which we'd like
  817. to add or delete a definition.
  818. C<$uFlags> is an unsigned value with zero or more of the following
  819. bits set:
  820. =over
  821. =item C<DDD_RAW_TARGET_PATH>
  822. Indicates that C<$sTargetPath> will be a raw Windows NT object name.
  823. This usually means that C<$sTargetPath> starts with C<"\\Device\\">.
  824. Note that you cannot use C<"/"> in place of C<"\\"> in raw target path
  825. names.
  826. =item C<DDD_REMOVE_DEFINITION>
  827. Requests that a definition be deleted. If C<$sTargetPath> is
  828. C<[]> [for C<NULL>], then the most recently added definition for
  829. C<$sDosDeviceName> is removed. Otherwise the most recently added
  830. definition matching C<$sTargetPath> is removed.
  831. If the last definition is removed, then the DOS device name is
  832. also deleted.
  833. =item C<DDD_EXACT_MATCH_ON_REMOVE>
  834. When deleting a definition, this bit causes each C<$sTargetPath> to
  835. be compared to the full-length definition when searching for the most
  836. recently added match. If this bit is not set, then C<$sTargetPath>
  837. only needs to match a prefix of the definition.
  838. =back
  839. C<$sTargetPath> is the DOS device's specific definition that you
  840. wish to add or delete. For C<DDD_RAW_TARGET_PATH>, these usually
  841. start with C<"\\Device\\">. If the C<DDD_RAW_TARGET_PATH> bit is
  842. not set, then C<$sTargetPath> is just an ordinary path to some file
  843. or directory, providing the functionality of the B<subst> command.
  844. =item DeleteFile
  845. =item C<DeleteFile( $sFileName )>
  846. Deletes the named file. Compared to Perl's C<unlink>, C<DeleteFile>
  847. has the advantage of not deleting read-only files. For B<some>
  848. versions of Perl, C<unlink> silently calls C<chmod> whether it needs
  849. to or not before deleting the file so that files that you have
  850. protected by marking them as read-only are not always protected from
  851. Perl's C<unlink>.
  852. Like most routines, returns a true value if successful and a false
  853. value [and sets C<$^E> and C<regLastError()>] on failure.
  854. =item DeviceIoControl
  855. =item C<DeviceIoControl( $hDevice, $uIoControlCode, $pInBuf, $lInBuf, $opOutBuf, $lOutBuf, $olRetBytes, $pOverlapped )>
  856. Requests a special operation on an I/O [input/output] device, such
  857. as ejecting a tape or formatting a disk. Like most routines, returns
  858. a true value if successful and a false value [and sets C<$^E> and
  859. C<regLastError()>] on failure.
  860. C<$hDevice> is a Win32 native file handle to a device [return value
  861. from C<CreateFile>].
  862. C<$uIoControlCode> is an unsigned value [a C<IOCTL_*> constant]
  863. indicating the type query or other operation to be performed.
  864. C<$pInBuf> is C<[]> [for C<NULL>] or a data structure packed into a
  865. string. The type of data structure depends on the C<$uIoControlCode>
  866. value. C<$lInBuf> is C<0> or the length of the structure in
  867. C<$pInBuf>. If C<$pInBuf> is not C<[]> and C<$lInBuf> is C<0>, then
  868. C<$lInBuf> will automatically be set to C<length($pInBuf)> for you.
  869. C<$opOutBuf> is C<[]> [for C<NULL>] or will be set to contain a
  870. returned data structure packed into a string. C<$lOutBuf> indicates
  871. how much space to allocate in C<$opOutBuf> for C<DeviceIoControl> to
  872. store the data structure. If C<$lOutBuf> is a number and C<$opOutBuf>
  873. already has a buffer allocated for it that is larger than C<$lOutBuf>
  874. bytes, then this larger buffer size will be passed to C<DeviceIoControl>.
  875. However, you can force a specific buffer size to be passed to
  876. C<DeviceIoControl> by prepending a C<"="> to the front of C<$lOutBuf>.
  877. C<$olRetBytes> is C<[]> or is a scalar to receive the number of bytes
  878. written to C<$opOutBuf>. Even when C<$olRetBytes> is C<[]>, a valid
  879. pointer to a C<DWORD> [and not C<NULL>] is passed to C<DeviceIoControl>.
  880. In this case, C<[]> just means that you don't care about the value
  881. that might be written to C<$olRetBytes>, which is usually the case
  882. since you can usually use C<length($opOutBuf)> instead.
  883. C<$pOverlapped> is C<[]> or is a C<OVERLAPPED> structure packed into
  884. a string. This is only useful if C<$hDevice> was opened with the
  885. C<FILE_FLAG_OVERLAPPED> flag set.
  886. =item FdGetOsFHandle
  887. =item C<$hNativeHandle= FdGetOsFHandle( $ivFd )>
  888. C<FdGetOsFHandle> simply calls C<_get_osfhandle()>. It was renamed
  889. to better fit in with the rest the function names of this module,
  890. in particular to distinguish it from C<GetOsFHandle>. It takes an
  891. integer file descriptor [as from Perl's C<fileno>] and returns the
  892. Win32 native file handle associated with that file descriptor or
  893. C<INVALID_HANDLE_VALUE> if C<$ivFd> is not an open file descriptor.
  894. When you call Perl's C<open> to set a Perl file handle [like C<STDOUT>],
  895. Perl calls C's C<fopen> to set a stdio C<FILE *>. C's C<fopen> calls
  896. something like Unix's C<open>, that is, Win32's C<_sopen>, to get an
  897. integer file descriptor [where 0 is for C<STDIN>, 1 for C<STDOUT>, etc.].
  898. Win32's C<_sopen> calls C<CreateFile> to set a C<HANDLE>, a Win32 native
  899. file handle. So every Perl file handle [like C<STDOUT>] has an integer
  900. file descriptor associated with it that you can get via C<fileno>. And,
  901. under Win32, every file descriptor has a Win32 native file handle
  902. associated with it. C<FdGetOsFHandle> lets you get access to that.
  903. C<$hNativeHandle> is set to C<INVALID_HANDLE_VALUE> [and
  904. C<lastFileError()> and C<$^E> are set] if C<FdGetOsFHandle> fails.
  905. See also C<GetOsFHandle> which provides a friendlier interface.
  906. =item fileConstant
  907. =item C<$value= fileConstant( $sConstantName )>
  908. Fetch the value of a constant. Returns C<undef> if C<$sConstantName>
  909. is not the name of a constant supported by this module. Never sets
  910. C<$!> nor C<$^E>.
  911. This function is rarely used since you will usually get the value of a
  912. constant by having that constant imported into your package by listing
  913. the constant name in the C<use Win32API::File> statement and then
  914. simply using the constant name in your code [perhaps followed by
  915. C<()>]. This function is useful for verifying constant names not in
  916. Perl code, for example, after prompting a user to type in a constant
  917. name.
  918. =item fileLastError
  919. =item C<$svError= fileLastError();>
  920. =item C<fileLastError( $uError );>
  921. Returns the last error encountered by a routine from this module.
  922. It is just like C<$^E> except it isn't changed by anything except
  923. routines from this module. Ideally you could just use C<$^E>, but
  924. current versions of Perl often overwrite C<$^E> before you get a
  925. chance to check it and really old versions of Perl don't really
  926. support C<$^E> under Win32.
  927. Just like C<$^E>, in a numeric context C<fileLastError()> returns
  928. the numeric error value while in a string context it returns a
  929. text description of the error [actually it returns a Perl scalar
  930. that contains both values so C<$x= fileLastError()> causes C<$x>
  931. to give different values in string vs. numeric contexts]. On old
  932. versions of Perl where C<$^E> isn't tied to C<GetLastError()>,
  933. C<fileLastError> simply returns the number of the error and you'll
  934. need to use <Win32::FormatMessage> to get the error string.
  935. The last form sets the error returned by future calls to
  936. C<fileLastError()> and should not be used often. C<$uError> must
  937. be a numeric error code. Also returns the dual-valued version
  938. of C<$uError>.
  939. =item GetDriveType
  940. =item C<$uDriveType= GetDriveType( $sRootPath )>
  941. Takes a string giving the path to the root directory of a file system
  942. [called a "drive" because every file system is assigned a "drive letter"]
  943. and returns an unsigned value indicating the type of drive the file
  944. system is on. The return value should be one of:
  945. =over
  946. =item C<DRIVE_UNKNOWN>
  947. None of the following.
  948. =item C<DRIVE_NO_ROOT_DIR>
  949. A "drive" that does not have a file system. This can be a drive letter
  950. that hasn't been defined or a drive letter assigned to a partition
  951. that hasn't been formatted yet.
  952. =item C<DRIVE_REMOVABLE>
  953. A floppy diskette drive or other removable media drive, but not a CD-ROM
  954. drive.
  955. =item C<DRIVE_FIXED>
  956. An ordinary hard disk partition.
  957. =item C<DRIVE_REMOTE>
  958. A network share.
  959. =item C<DRIVE_CDROM>
  960. A CD-ROM drive.
  961. =item C<DRIVE_RAMDISK>
  962. A "ram disk" or memory-resident virtual file system used for high-speed
  963. access to small amounts of temporary file space.
  964. =back
  965. =item GetFileType
  966. =item C<$uFileType= GetFileType( $hFile )>
  967. Takes a Win32 native file handle and returns a C<FILE_TYPE_*> constant
  968. indicating the type of the file opened on that handle:
  969. =over
  970. =item C<FILE_TYPE_UNKNOWN>
  971. None of the below. Often a special device.
  972. =item C<FILE_TYPE_DISK>
  973. An ordinary disk file.
  974. =item C<FILE_TYPE_CHAR>
  975. What Unix would call a "character special file", that is, a device that
  976. works on character streams such as a printer port or a console.
  977. =item C<FILE_TYPE_PIPE>
  978. Either a named or anonymous pipe.
  979. =back
  980. =item GetLogicalDrives
  981. =item C<$uDriveBits= GetLogicalDrives()>
  982. Returns an unsigned value with one bit set for each drive letter currently
  983. defined. If "A:" is currently a valid drive letter, then the C<1> bit
  984. will be set in C<$uDriveBits>. If "B:" is valid, then the C<2> bit will
  985. be set. If "Z:" is valid, then the C<2**26> [C<0x4000000>] bit will be
  986. set.
  987. =item GetLogicalDriveStrings
  988. =item C<$olOutLength= GetLogicalDriveStrings( $lBufSize, $osBuffer )>
  989. For each currently defined drive letter, a C<'\0'>-terminated string
  990. of the path to the root of its file system is constructed. All of
  991. these strings are concatenated into a single larger string and an
  992. extra terminating C<'\0'> is added. This larger string is returned
  993. in C<$osBuffer>. Note that this includes drive letters that have
  994. been defined but that have no file system, such as drive letters
  995. assigned to unformatted partitions.
  996. C<$lBufSize> is the size of the buffer to allocate to store this
  997. list of strings. C<26*4+1> is always sufficient and should usually
  998. be used.
  999. C<$osBuffer> is a scalar to be set to contain the constructed string.
  1000. C<$olOutLength> is the number of bytes actually written to C<$osBuffer>
  1001. but C<length($osBuffer)> can also be used to determine this.
  1002. For example, on a poorly equipped computer,
  1003. GetLogicalDriveStrings( 4*26+1, $osBuffer );
  1004. might set C<$osBuffer> to the 9-character string, C<"A:\\\0C:\\\0\0">.
  1005. =item GetHandleInformation
  1006. =item C<GetHandleInformation( $hObject, $ouFlags )>
  1007. Retrieves the flags associated with a Win32 native file handle or object
  1008. handle.
  1009. C<$hObject> is an open Win32 native file handle or an open Win32 native
  1010. handle to some other type of object.
  1011. C<$ouFlags> will be set to an unsigned value having zero or more of
  1012. the bits C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE>
  1013. set. See the C<":HANDLE_FLAG_"> export class for the meanings of these
  1014. bits.
  1015. =item GetOsFHandle
  1016. =item C<$hNativeHandle= GetOsFHandle( FILE )>
  1017. Takes a Perl file handle [like C<STDIN>] and returns the Win32 native
  1018. file handle associated with it. See C<FdGetOsFHandle> for more
  1019. information about Win32 native file handles.
  1020. C<$hNativeHandle> is set to a false value [and C<lastFileError()> and
  1021. C<$^E> are set] if C<GetOsFHandle> fails. C<GetOsFHandle> returns
  1022. C<"0 but true"> in the impossible(?) case of the handle having a value
  1023. of C<0>.
  1024. =item GetVolumeInformation
  1025. =item C<GetVolumeInformation( $sRootPath, $osVolName, $lVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType )>
  1026. Gets information about a file system volume, returning a true
  1027. value if successful. On failure, returns a false value and sets
  1028. C<fileLastError()> and C<$^E>.
  1029. C<$sRootPath> is a string specifying the path to the root of the file system,
  1030. for example, C<"C:/">.
  1031. C<$osVolName> is a scalar to be set to the string representing the
  1032. volume name, also called the file system label. C<$lVolName> is the
  1033. number of bytes to allocate for the C<$osVolName> buffer [see
  1034. L<Buffer Sizes> for more information].
  1035. C<$ouSerialNum> is C<[]> [for C<NULL>] or will be set to the numeric
  1036. value of the volume's serial number.
  1037. C<$ouMaxNameLen> is C<[]> [for C<NULL>] or will be set to the maximum
  1038. length allowed for a file name or directory name within the file system.
  1039. C<$osFsType> is a scalar to be set to the string representing the
  1040. file system type, such as C<"FAT"> or C<"NTFS">. C<$lFsType> is the
  1041. number of bytes to allocate for the C<$osFsType> buffer [see
  1042. L<Buffer Sizes> for more information].
  1043. C<$ouFsFlags> is C<[]> [for C<NULL>] or will be set to an unsigned integer
  1044. with bits set indicating properties of the file system:
  1045. =over
  1046. =item C<FS_CASE_IS_PRESERVED>
  1047. The file system preserves the case of file names [usually true].
  1048. That is, it doesn't change the case of file names such as forcing
  1049. them to upper- or lower-case.
  1050. =item C<FS_CASE_SENSITIVE>
  1051. The file system supports the ability to not ignore the case of file
  1052. names [but might ignore case the way you are using it]. That is, the
  1053. file system has the ability to force you to get the letter case of a
  1054. file's name exactly right to be able to open it. This is true for
  1055. "NTFS" file systems, even though case in file names is usually still
  1056. ignored.
  1057. =item C<FS_UNICODE_STORED_ON_DISK>
  1058. The file system preserves Unicode in file names [true for "NTFS"].
  1059. =item C<FS_PERSISTENT_ACLS>
  1060. The file system supports setting Access Control Lists on files [true
  1061. for "NTFS"].
  1062. =item C<FS_FILE_COMPRESSION>
  1063. The file system supports compression on a per-file basis [true for
  1064. "NTFS"].
  1065. =item C<FS_VOL_IS_COMPRESSED>
  1066. The entire file system is compressed such as via "DoubleSpace".
  1067. =back
  1068. =item IsRecognizedPartition
  1069. =item C<IsRecognizedPartition( $ivPartitionType )>
  1070. Takes a partition type and returns whether that partition type is
  1071. supported under Win32. C<$ivPartitonType> is an integer value as from
  1072. the operating system byte of a hard disk's DOS-compatible partition
  1073. table [that is, a partition table for x86-based Win32, not, for
  1074. example, one used with Windows NT for Alpha processors]. For example,
  1075. the C<PartitionType> member of the C<PARTITION_INFORMATION> structure.
  1076. Common values for C<$ivPartitionType> include C<PARTITION_FAT_12==1>,
  1077. C<PARTITION_FAT_16==4>, C<PARTITION_EXTENDED==5>, C<PARTITION_FAT32==0xB>.
  1078. =item IsContainerPartition
  1079. =item C<IsContainerPartition( $ivPartitionType )>
  1080. Takes a partition type and returns whether that partition is a
  1081. "container" partition that is supported under Win32, that is, whether
  1082. it is an "extended" partition that can contain "logical" partitions.
  1083. C<$ivPartitonType> is as for C<IsRecognizedPartition>.
  1084. =item MoveFile
  1085. =item C<MoveFile( $sOldName, $sNewName )>
  1086. Renames a file or directory. C<$sOldName> is the name of the existing
  1087. file or directory that is to be renamed. C<$sNewName> is the new name
  1088. to give the file or directory. Returns a true value if the move
  1089. succeeds. For failure, returns a false value and sets
  1090. C<fileLastErorr()> and C<$^E> to the reason for the failure.
  1091. Files can be "renamed" between file systems and the file contents and
  1092. some attributes will be moved. Directories can only be renamed within
  1093. one file system. If there is already a file or directory named
  1094. C<$sNewName>, then C<MoveFile> will fail.
  1095. =item MoveFileEx
  1096. =item C<MoveFileEx( $sOldName, $sNewName, $uFlags )>
  1097. Renames a file or directory. C<$sOldName> is the name of the existing
  1098. file or directory that is to be renamed. C<$sNewName> is the new name
  1099. to give the file or directory. Returns a true value if the move
  1100. succeeds. For failure, returns a false value and sets
  1101. C<fileLastErorr()> and C<$^E> to the reason for the failure.
  1102. C<$uFlags> is an unsigned value with zero or more of the following bits set:
  1103. =over
  1104. =item C<MOVEFILE_REPLACE_EXISTING>
  1105. If this bit is set and a file [but not a directory] named C<$sNewName>
  1106. already exists, then it will be replaced by C<$sOldName>. If this bit
  1107. is not set then C<MoveFileEx> will fail rather than replace an existing
  1108. C<$sNewName>.
  1109. =item C<MOVEFILE_COPY_ALLOWED>
  1110. Allows files [but not directories] to be moved between file systems
  1111. by copying the C<$sOldName> file data and some attributes to
  1112. C<$sNewName> and then deleting C<$sOldName>. If this bit is not set
  1113. [or if C<$sOldName> denotes a directory] and C<$sNewName> refers to a
  1114. different file system than C<$sOldName>, then C<MoveFileEx> will fail.
  1115. =item C<MOVEFILE_DELAY_UNTIL_REBOOT>
  1116. Preliminary verifications are made and then an entry is added to the
  1117. Registry to cause the rename [or delete] operation to be done the
  1118. next time this copy of the operating system is booted [right after
  1119. any automatic file system checks have completed]. This is not
  1120. supported under Windows 95.
  1121. When this bit is set, C<$sNewName> can be C<[]> [for C<NULL>] to
  1122. indicate that C<$sOldName> should be deleted during the next boot
  1123. rather than renamed.
  1124. Setting both the C<MOVEFILE_COPY_ALLOWED> and
  1125. C<MOVEFILE_DELAY_UNTIL_REBOOT> bits will cause C<MoveFileEx> to fail.
  1126. =item C<MOVEFILE_WRITE_THROUGH>
  1127. Ensures that C<MoveFileEx> won't return until the operation has
  1128. finished and been flushed to disk. This is not supported under
  1129. Windows 95. Only affects file renames to another file system,
  1130. forcing a buffer flush at the end of the copy operation.
  1131. =back
  1132. =item OsFHandleOpen
  1133. =item C<OsFHandleOpen( FILE, $hNativeHandle, $sMode )>
  1134. Opens a Perl file handle based on an already open Win32 native
  1135. file handle [much like C's C<fdopen()> does with a file descriptor].
  1136. Returns a true value if the open operation succeeded. For failure,
  1137. returns a false value and sets C<$!> [and possibly C<fileLastError()>
  1138. and C<$^E>] to the reason for the failure.
  1139. C<FILE> is a Perl file handle [in any of the supported forms, a
  1140. bareword, a string, a typeglob, or a reference to a typeglob] that
  1141. will be opened. If C<FILE> is already open, it will automatically
  1142. be closed before it is reopened.
  1143. C<$hNativeHandle> is an open Win32 native file handle, probably the
  1144. return value from C<CreateFile> or C<createFile>.
  1145. C<$sMode> is string of zero or more letters from C<"rwatb">. These
  1146. are translated into a combination C<O_RDONLY> [C<"r">], C<O_WRONLY>
  1147. [C<"w">], C<O_RDWR> [C<"rw">], C<O_APPEND> [C<"a">], C<O_TEXT>
  1148. [C<"t">], and C<O_BINARY> [C<"b">] flags [see the L<Fcntl> module]
  1149. that is passed to C<OsFHandleOpenFd>. Currently only C<O_APPEND>
  1150. and C<O_TEXT> have any significance.
  1151. Also, a C<"r"> and/or C<"w"> in C<$sMode> is used to decide how the
  1152. file descriptor is converted into a Perl file handle, even though this
  1153. doesn't appear to make a difference. One of the following is used:
  1154. open( FILE, "<&=".$ivFd ) # "r" w/o "w"
  1155. open( FILE, ">&=".$ivFd ) # "w" w/o "r"
  1156. open( FILE, "+<&=".$ivFd ) # both "r" and "w"
  1157. C<OsFHandleOpen> eventually calls the Win32-specific C routine
  1158. C<_open_osfhandle()> or Perl's "improved" version called
  1159. C<win32_open_osfhandle()>. Prior to Perl5.005, C's
  1160. C<_open_osfhandle()> is called which will fail if
  1161. C<GetFileType($hNativeHandle)> would return C<FILE_TYPE_UNKNOWN>. For
  1162. Perl5.005 and later, C<OsFHandleOpen> calls C<win32_open_osfhandle()>
  1163. from the Perl DLL which doesn't have this restriction.
  1164. =item OsFHandleOpenFd
  1165. =item C<$ivFD= OsFHandleOpenFd( $hNativeHandle, $uMode )>
  1166. Opens a file descriptor [C<$ivFD>] based on an already open Win32
  1167. native file handle, C<$hNativeHandle>. This just calls the
  1168. Win32-specific C routine C<_open_osfhandle()> or Perl's "improved"
  1169. version called C<win32_open_osfhandle()>. Prior to Perl5.005, C's
  1170. C<_open_osfhandle()> is called which will fail if
  1171. C<GetFileType($hNativeHandle)> would return C<FILE_TYPE_UNKNOWN>.
  1172. For Perl5.005 and later, C<OsFHandleOpenFd> calls
  1173. C<win32_open_osfhandle()> from the Perl DLL which doesn't have this
  1174. restriction.
  1175. C<$uMode> the logical combination of zero or more C<O_*> constants
  1176. exported by the C<Fcntl> module. Currently only C<O_APPEND> and
  1177. C<O_TEXT> have any significance.
  1178. C<$ivFD> will be non-negative if the open operation was successful.
  1179. For failure, C<-1> is returned and C<$!> [and possibly
  1180. C<fileLastError()> and C<$^E>] is set to the reason for the failure.
  1181. =item QueryDosDevice
  1182. =item C<$olTargetLen= QueryDosDevice( $sDosDeviceName, $osTargetPath, $lTargetBuf )>
  1183. Looks up the definition of a given "DOS" device name, yielding the
  1184. active Windows NT native device name along with any currently dormant
  1185. definitions.
  1186. C<$sDosDeviceName> is the name of the "DOS" device whose definitions
  1187. we want. For example, C<"C:">, C<"COM1">, or C<"PhysicalDrive0">.
  1188. If C<$sDosDeviceName> is C<[]> [for C<NULL>], the list of all DOS
  1189. device names is returned instead.
  1190. C<$osTargetPath> will be assigned a string containing the list of
  1191. definitions. The definitions are each C<'\0'>-terminate and are
  1192. concatenated into the string, most recent first, with an extra C<'\0'>
  1193. at the end of the whole string [see C<GetLogicalDriveStrings> for
  1194. a sample of this format].
  1195. C<$lTargetBuf> is the size [in bytes] of the buffer to allocate for
  1196. C<$osTargetPath>. See L<Buffer Sizes> for more information.
  1197. C<$olTargetLen> is set to the number of bytes written to
  1198. C<$osTargetPath> but you can also use C<length($osTargetPath)>
  1199. to determine this.
  1200. For failure, C<0> is returned and C<fileLastError()> and C<$^E> are
  1201. set to the reason for the failure.
  1202. =item ReadFile
  1203. =item C<ReadFile( $hFile, $opBuffer, $lBytes, $olBytesRead, $pOverlapped )>
  1204. Reads bytes from a file or file-like device. Returns a true value if
  1205. the read operation was successful. For failure, returns a false value
  1206. and sets C<fileLastError()> and C<$^E> for the reason for the failure.
  1207. C<$hFile> is a Win32 native file handle that is already open to the
  1208. file or device to read from.
  1209. C<$opBuffer> will be set to a string containing the bytes read.
  1210. C<$lBytes> is the number of bytes you would like to read.
  1211. C<$opBuffer> is automatically initialized to have a buffer large
  1212. enough to hold that many bytes. Unlike other buffer sizes, C<$lBytes>
  1213. does not need to have a C<"="> prepended to it to prevent a larger
  1214. value to be passed to the underlying Win32 C<ReadFile> API. However,
  1215. a leading C<"="> will be silently ignored, even if Perl warnings are
  1216. enabled.
  1217. If C<$olBytesRead> is not C<[]>, it will be set to the actual number
  1218. of bytes read, though C<length($opBuffer)> can also be used to
  1219. determine this.
  1220. C<$pOverlapped> is C<[]> or is a C<OVERLAPPED> structure packed
  1221. into a string. This is only useful if C<$hFile> was opened with
  1222. the C<FILE_FLAG_OVERLAPPED> flag set.
  1223. =item SetErrorMode
  1224. =item C<$uOldMode= SetErrorMode( $uNewMode )>
  1225. Sets the mode controlling system error handling B<and> returns the
  1226. previous mode value. Both C<$uOldMode> and C<$uNewMode> will have
  1227. zero or more of the following bits set:
  1228. =over
  1229. =item C<SEM_FAILCRITICALERRORS>
  1230. If set, indicates that when a critical error is encountered, the call
  1231. that triggered the error fails immediately. Normally this bit is not
  1232. set, which means that a critical error causes a dialogue box to appear
  1233. notifying the desktop user that some application has triggered a
  1234. critical error. The dialogue box allows the desktop user to decide
  1235. whether the critical error is returned to the process, is ignored, or
  1236. the offending operation is retried.
  1237. This affects the C<CreateFile> and C<GetVolumeInformation> calls.
  1238. Setting this bit is useful for allowing you to check whether a floppy
  1239. diskette is in the floppy drive.
  1240. =item C<SEM_NOALIGNMENTFAULTEXCEPT>
  1241. If set, this causes memory access misalignment faults to be
  1242. automatically fixed in a manner invisible to the process. This flag
  1243. is ignored on x86-based versions of Windows NT. This flag is not
  1244. supported on Windows 95.
  1245. =item C<SEM_NOGPFAULTERRORBOX>
  1246. If set, general protection faults do not generate a dialogue box but
  1247. can instead be handled by the process via an exception handler. This
  1248. bit should not be set by programs that don't know how to handle such
  1249. faults.
  1250. =item C<SEM_NOOPENFILEERRORBOX>
  1251. If set, then when an attempt to continue reading from or writing to
  1252. an already open file [usually on a removable medium like a floppy
  1253. diskette] finds the file no longer available, the call will
  1254. immediately fail. Normally this bit is not set, which means that
  1255. instead a dialogue box will appear notifying the desktop user that
  1256. some application has run into this problem. The dialogue box allows
  1257. the desktop user to decide whether the failure is returned to the
  1258. process, is ignored, or the offending operation is retried.
  1259. This affects the C<ReadFile> and C<WriteFile> calls.
  1260. =back
  1261. =item SetFilePointer
  1262. =item C<$uNewPos= SetFilePointer( $hFile, $ivOffset, $ioivOffsetHigh, $uFromWhere )>
  1263. The native Win32 version of C<seek()>. C<SetFilePointer> sets the
  1264. position within a file where the next read or write operation will
  1265. start from.
  1266. C<$hFile> is a Win32 native file handle.
  1267. C<$uFromWhere> is either C<FILE_BEGIN>, C<FILE_CURRENT>, or
  1268. C<FILE_END>, indicating that the new file position is being specified
  1269. relative to the beginning of the file, the current file pointer, or
  1270. the end of the file, respectively.
  1271. C<$ivOffset> is [if C<$ioivOffsetHigh> is C<[]>] the offset [in bytes]
  1272. to the new file position from the position specified via
  1273. C<$uFromWhere>. If C<$ioivOffsetHigh> is not C<[]>, then C<$ivOffset>
  1274. is converted to an unsigned value to be used as the low-order 4 bytes
  1275. of the offset.
  1276. C<$ioivOffsetHigh> can be C<[]> [for C<NULL>] to indicate that you are
  1277. only specifying a 4-byte offset and the resulting file position will
  1278. be 0xFFFFFFFE or less [just under 4GB]. Otherwise C<$ioivOfffsetHigh>
  1279. starts out with the high-order 4 bytes [signed] of the offset and gets
  1280. set to the [unsigned] high-order 4 bytes of the resulting file position.
  1281. The underlying C<SetFilePointer> returns C<0xFFFFFFFF> to indicate
  1282. failure, but if C<$ioivOffsetHigh> is not C<[]>, you would also have
  1283. to check C<$^E> to determine whether C<0xFFFFFFFF> indicates an error
  1284. or not. C<Win32API::File::SetFilePointer> does this checking for you
  1285. and returns a false value if and only if the underlying
  1286. C<SetFilePointer> failed. For this reason, C<$uNewPos> is set to
  1287. C<"0 but true"> if you set the file pointer to the beginning of the
  1288. file [or any position with 0 for the low-order 4 bytes].
  1289. So the return value will be true if the seek operation was successful.
  1290. For failure, a false value is returned and C<fileLastError()> and
  1291. C<$^E> are set to the reason for the failure.
  1292. =item SetHandleInformation
  1293. =item C<SetHandleInformation( $hObject, $uMask, $uFlags )>
  1294. Sets the flags associated with a Win32 native file handle or object
  1295. handle. Returns a true value if the operation was successful. For
  1296. failure, returns a false value and sets C<fileLastError()> and C<$^E>
  1297. for the reason for the failure.
  1298. C<$hObject> is an open Win32 native file handle or an open Win32 native
  1299. handle to some other type of object.
  1300. C<$uMask> is an unsigned value having one or more of the bits
  1301. C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE> set.
  1302. Only bits set in C<$uMask> will be modified by C<SetHandleInformation>.
  1303. C<$uFlags> is an unsigned value having zero or more of the bits
  1304. C<HANDLE_FLAG_INHERIT> and C<HANDLE_FLAG_PROTECT_FROM_CLOSE> set.
  1305. For each bit set in C<$uMask>, the cooresponding bit in the handle's
  1306. flags is set to the value of the cooresponding bit in C<$uFlags>.
  1307. If C<$uOldFlags> were the value of the handle's flags before the
  1308. call to C<SetHandleInformation>, then the value of the handle's
  1309. flags afterward would be:
  1310. ( $uOldFlags & ~$uMask ) | ( $uFlags & $uMask )
  1311. [at least as far as the C<HANDLE_FLAG_INHERIT> and
  1312. C<HANDLE_FLAG_PROTECT_FROM_CLOSE> bits are concerned.]
  1313. See the C<":HANDLE_FLAG_"> export class for the meanings of these bits.
  1314. =item WriteFile
  1315. =item C<WriteFile( $hFile, $pBuffer, $lBytes, $ouBytesWritten, $pOverlapped )>
  1316. Write bytes to a file or file-like device. Returns a true value if
  1317. the operation was successful. For failure, returns a false value and
  1318. sets C<fileLastError()> and C<$^E> for the reason for the failure.
  1319. C<$hFile> is a Win32 native file handle that is already open to the
  1320. file or device to be written to.
  1321. C<$pBuffer> is a string containing the bytes to be written.
  1322. C<$lBytes> is the number of bytes you would like to write. If
  1323. C<$pBuffer> is not at least C<$lBytes> long, C<WriteFile> croaks. You
  1324. can specify C<0> for C<$lBytes> to write C<length($pBuffer)> bytes.
  1325. A leading C<"="> on C<$lBytes> will be silently ignored, even if Perl
  1326. warnings are enabled.
  1327. C<$ouBytesWritten> will be set to the actual number of bytes written
  1328. unless you specify it as C<[]>.
  1329. C<$pOverlapped> is C<[]> or is an C<OVERLAPPED> structure packed
  1330. into a string. This is only useful if C<$hFile> was opened with
  1331. the C<FILE_FLAG_OVERLAPPED> flag set.
  1332. =back
  1333. =item C<":FuncA">
  1334. The ASCII-specific functions. Each of these is just the same as the
  1335. version without the trailing "A".
  1336. CopyFileA
  1337. CreateFileA
  1338. DefineDosDeviceA
  1339. DeleteFileA
  1340. GetDriveTypeA
  1341. GetLogicalDriveStringsA
  1342. GetVolumeInformationA
  1343. MoveFileA
  1344. MoveFileExA
  1345. QueryDosDeviceA
  1346. =item C<":FuncW">
  1347. The wide-character-specific (Unicode) functions. Each of these is
  1348. just the same as the version without the trailing "W" except that
  1349. strings are expected in Unicode and some lengths are measured as
  1350. number of C<WCHAR>s instead of number of bytes, as indicated below.
  1351. =over
  1352. =item CopyFileW
  1353. =item C<CopyFileW( $swOldFileName, $swNewFileName, $bFailIfExists )>
  1354. C<$swOldFileName> and C<$swNewFileName> are Unicode strings.
  1355. =item CreateFileW
  1356. =item C<$hObject= CreateFileW( $swPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel )>
  1357. C<$swPath> is Unicode.
  1358. =item DefineDosDeviceW
  1359. =item C<DefineDosDeviceW( $uFlags, $swDosDeviceName, $swTargetPath )>
  1360. C<$swDosDeviceName> and C<$swTargetPath> are Unicode.
  1361. =item DeleteFileW
  1362. =item C<DeleteFileW( $swFileName )>
  1363. C<$swFileName> is Unicode.
  1364. =item GetDriveTypeW
  1365. =item C<$uDriveType= GetDriveTypeW( $swRootPath )>
  1366. C<$swRootPath> is Unicode.
  1367. =item GetLogicalDriveStringsW
  1368. =item C<$olwOutLength= GetLogicalDriveStringsW( $lwBufSize, $oswBuffer )>
  1369. Unicode is stored in C<$oswBuffer>. C<$lwBufSize> and C<$olwOutLength>
  1370. are measured as number of C<WCHAR>s.
  1371. =item GetVolumeInformationW
  1372. =item C<GetVolumeInformationW( $swRootPath, $oswVolName, $lwVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $oswFsType, $lwFsType )>
  1373. C<$swRootPath> is Unicode and Unicode is written to C<$oswVolName> and
  1374. C<$oswFsType>. C<$lwVolName> and C<$lwFsType> are measures as number
  1375. of C<WCHAR>s.
  1376. =item MoveFileW
  1377. =item C<MoveFileW( $swOldName, $swNewName )>
  1378. C<$swOldName> and C<$swNewName> are Unicode.
  1379. =item MoveFileExW
  1380. =item C<MoveFileExW( $swOldName, $swNewName, $uFlags )>
  1381. C<$swOldName> and C<$swNewName> are Unicode.
  1382. =item QueryDosDeviceW
  1383. =item C<$olwTargetLen= QueryDosDeviceW( $swDeviceName, $oswTargetPath, $lwTargetBuf )>
  1384. C<$swDeviceName> is Unicode and Unicode is written to
  1385. C<$oswTargetPath>. C<$lwTargetBuf> and C<$olwTargetLen> are measured
  1386. as number of C<WCHAR>s.
  1387. =back
  1388. =item C<":Misc">
  1389. Miscellaneous constants. Used for the C<$uCreate> argument of
  1390. C<CreateFile> or the C<$uFromWhere> argument of C<SetFilePointer>.
  1391. Plus C<INVALID_HANDLE_VALUE>, which you usually won't need to check
  1392. for since most routines translate it into a false value.
  1393. CREATE_ALWAYS CREATE_NEW OPEN_ALWAYS
  1394. OPEN_EXISTING TRUNCATE_EXISTING INVALID_HANDLE_VALUE
  1395. FILE_BEGIN FILE_CURRENT FILE_END
  1396. =item C<":DDD_">
  1397. Constants for the C<$uFlags> argument of C<DefineDosDevice>.
  1398. DDD_EXACT_MATCH_ON_REMOVE
  1399. DDD_RAW_TARGET_PATH
  1400. DDD_REMOVE_DEFINITION
  1401. =item C<":DRIVE_">
  1402. Constants returned by C<GetDriveType>.
  1403. DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE
  1404. DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM
  1405. DRIVE_RAMDISK
  1406. =item C<":FILE_">
  1407. Specific types of access to files that can be requested via the
  1408. C<$uAccess> argument to C<CreateFile>.
  1409. FILE_READ_DATA FILE_LIST_DIRECTORY
  1410. FILE_WRITE_DATA FILE_ADD_FILE
  1411. FILE_APPEND_DATA FILE_ADD_SUBDIRECTORY
  1412. FILE_CREATE_PIPE_INSTANCE FILE_READ_EA
  1413. FILE_WRITE_EA FILE_EXECUTE
  1414. FILE_TRAVERSE FILE_DELETE_CHILD
  1415. FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES
  1416. FILE_ALL_ACCESS FILE_GENERIC_READ
  1417. FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE )],
  1418. =item C<":FILE_ATTRIBUTE_">
  1419. File attribute constants. Returned by C<attrLetsToBits> and used in
  1420. the C<$uFlags> argument to C<CreateFile>.
  1421. FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED
  1422. FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL
  1423. FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY
  1424. FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY
  1425. =item C<":FILE_FLAG_">
  1426. File option flag constants. Used in the C<$uFlags> argument to
  1427. C<CreateFile>.
  1428. FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_DELETE_ON_CLOSE
  1429. FILE_FLAG_NO_BUFFERING FILE_FLAG_OVERLAPPED
  1430. FILE_FLAG_POSIX_SEMANTICS FILE_FLAG_RANDOM_ACCESS
  1431. FILE_FLAG_SEQUENTIAL_SCAN FILE_FLAG_WRITE_THROUGH
  1432. =item C<":FILE_SHARE_">
  1433. File sharing constants. Used in the C<$uShare> argument to
  1434. C<CreateFile>.
  1435. FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE
  1436. =item C<":FILE_TYPE_">
  1437. File type constants. Returned by C<GetFileType>.
  1438. FILE_TYPE_CHAR FILE_TYPE_DISK
  1439. FILE_TYPE_PIPE FILE_TYPE_UNKNOWN
  1440. =item C<":FS_">
  1441. File system characteristics constants. Placed in the C<$ouFsFlags>
  1442. argument to C<GetVolumeInformation>.
  1443. FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE
  1444. FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS
  1445. FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED
  1446. =item C<":HANDLE_FLAG_">
  1447. Flag bits modifying the behavior of an object handle and accessed via
  1448. C<GetHandleInformation> and C<SetHandleInformation>.
  1449. =over
  1450. =item HANDLE_FLAG_INHERIT
  1451. If this bit is set, then children of this process who inherit handles
  1452. [that is, processes created by calls to the Win32 C<CreateProcess> API
  1453. with the C<bInheritHandles> parameter specified as C<TRUE>], will inherit
  1454. this particular object handle.
  1455. =item HANDLE_FLAG_PROTECT_FROM_CLOSE
  1456. If this bit is set, then calls to C<CloseHandle> against this handle
  1457. will be ignored, leaving the handle open and usable.
  1458. =back
  1459. =item C<":IOCTL_STORAGE_">
  1460. I/O control operations for generic storage devices. Used in the
  1461. C<$uIoControlCode> argument to C<DeviceIoControl>. Includes
  1462. C<IOCTL_STORAGE_CHECK_VERIFY>, C<IOCTL_STORAGE_MEDIA_REMOVAL>,
  1463. C<IOCTL_STORAGE_EJECT_MEDIA>, C<IOCTL_STORAGE_LOAD_MEDIA>,
  1464. C<IOCTL_STORAGE_RESERVE>, C<IOCTL_STORAGE_RELEASE>,
  1465. C<IOCTL_STORAGE_FIND_NEW_DEVICES>, and
  1466. C<IOCTL_STORAGE_GET_MEDIA_TYPES>.
  1467. =over
  1468. =item C<IOCTL_STORAGE_CHECK_VERIFY>
  1469. Verify that a device's media is accessible. C<$pInBuf> and C<$opOutBuf>
  1470. should both be C<[]>. If C<DeviceIoControl> returns a true value, then
  1471. the media is currently accessible.
  1472. =item C<IOCTL_STORAGE_MEDIA_REMOVAL>
  1473. Allows the device's media to be locked or unlocked. C<$opOutBuf> should
  1474. be C<[]>. C<$pInBuf> should be a C<PREVENT_MEDIA_REMOVAL> data structure,
  1475. which is simply an interger containing a boolean value:
  1476. $pInBuf= pack( "i", $bPreventMediaRemoval );
  1477. =item C<IOCTL_STORAGE_EJECT_MEDIA>
  1478. Requests that the device eject the media. C<$pInBuf> and C<$opOutBuf>
  1479. should both be C<[]>.
  1480. =item C<IOCTL_STORAGE_LOAD_MEDIA>
  1481. Requests that the device load the media. C<$pInBuf> and C<$opOutBuf>
  1482. should both be C<[]>.
  1483. =item C<IOCTL_STORAGE_RESERVE>
  1484. Requests that the device be reserved. C<$pInBuf> and C<$opOutBuf>
  1485. should both be C<[]>.
  1486. =item C<IOCTL_STORAGE_RELEASE>
  1487. Releases a previous device reservation. C<$pInBuf> and C<$opOutBuf>
  1488. should both be C<[]>.
  1489. =item C<IOCTL_STORAGE_FIND_NEW_DEVICES>
  1490. No documentation on this IOCTL operation was found.
  1491. =item C<IOCTL_STORAGE_GET_MEDIA_TYPES>
  1492. Requests information about the type of media supported by the device.
  1493. C<$pInBuf> should be C<[]>. C<$opOutBuf> will be set to contain a
  1494. vector of C<DISK_GEOMETRY> data structures, which can be decoded via:
  1495. # Calculate the number of DISK_GEOMETRY structures returned:
  1496. my $cStructs= length($opOutBuf)/(4+4+4+4+4+4);
  1497. my @fields= unpack( "L l I L L L" x $cStructs, $opOutBuf )
  1498. my( @ucCylsLow, @ivcCylsHigh, @uMediaType, @uTracksPerCyl,
  1499. @uSectsPerTrack, @uBytesPerSect )= ();
  1500. while( @fields ) {
  1501. push( @ucCylsLow, unshift @fields );
  1502. push( @ivcCylsHigh, unshift @fields );
  1503. push( @uMediaType, unshift @fields );
  1504. push( @uTracksPerCyl, unshift @fields );
  1505. push( @uSectsPerTrack, unshift @fields );
  1506. push( @uBytesPerSect, unshift @fields );
  1507. }
  1508. For the C<$i>th type of supported media, the following variables will
  1509. contain the following data.
  1510. =over
  1511. =item C<$ucCylsLow[$i]>
  1512. The low-order 4 bytes of the total number of cylinders.
  1513. =item C<$ivcCylsHigh[$i]>
  1514. The high-order 4 bytes of the total number of cylinders.
  1515. =item C<$uMediaType[$i]>
  1516. A code for the type of media. See the C<":MEDIA_TYPE"> export class.
  1517. =item C<$uTracksPerCyl[$i]>
  1518. The number of tracks in each cylinder.
  1519. =item C<$uSectsPerTrack[$i]>
  1520. The number of sectors in each track.
  1521. =item C<$uBytesPerSect[$i]>
  1522. The number of bytes in each sector.
  1523. =back
  1524. =back
  1525. =item C<":IOCTL_DISK_">
  1526. I/O control operations for disk devices. Used in the C<$uIoControlCode>
  1527. argument to C<DeviceIoControl>. Most of these are to be used on
  1528. physical drive devices like C<"//./PhysicalDrive0">. However,
  1529. C<IOCTL_DISK_GET_PARTITION_INFO> and C<IOCTL_DISK_SET_PARTITION_INFO>
  1530. should only be used on a single-partition device like C<"//./C:">. Also,
  1531. C<IOCTL_DISK_GET_MEDIA_TYPES> is documented as having been superceded but
  1532. is still useful when used on a floppy device like C<"//./A:">.
  1533. Includes C<IOCTL_DISK_FORMAT_TRACKS>, C<IOCTL_DISK_FORMAT_TRACKS_EX>,
  1534. C<IOCTL_DISK_GET_DRIVE_GEOMETRY>, C<IOCTL_DISK_GET_DRIVE_LAYOUT>,
  1535. C<IOCTL_DISK_GET_MEDIA_TYPES>, C<IOCTL_DISK_GET_PARTITION_INFO>,
  1536. C<IOCTL_DISK_HISTOGRAM_DATA>, C<IOCTL_DISK_HISTOGRAM_RESET>,
  1537. C<IOCTL_DISK_HISTOGRAM_STRUCTURE>, C<IOCTL_DISK_IS_WRITABLE>,
  1538. C<IOCTL_DISK_LOGGING>, C<IOCTL_DISK_PERFORMANCE>,
  1539. C<IOCTL_DISK_REASSIGN_BLOCKS>, C<IOCTL_DISK_REQUEST_DATA>,
  1540. C<IOCTL_DISK_REQUEST_STRUCTURE>, C<IOCTL_DISK_SET_DRIVE_LAYOUT>,
  1541. C<IOCTL_DISK_SET_PARTITION_INFO>, and C<IOCTL_DISK_VERIFY>.
  1542. =over
  1543. =item C<IOCTL_DISK_GET_DRIVE_GEOMETRY>
  1544. Request information about the size and geometry of the disk. C<$pInBuf>
  1545. should be C<[]>. C<$opOutBuf> will be set to a C<DISK_GEOMETRY> data
  1546. structure which can be decode via:
  1547. ( $ucCylsLow, $ivcCylsHigh, $uMediaType, $uTracksPerCyl,
  1548. $uSectsPerTrack, $uBytesPerSect )= unpack( "L l I L L L", $opOutBuf );
  1549. =over
  1550. =item C<$ucCylsLow>
  1551. The low-order 4 bytes of the total number of cylinders.
  1552. =item C<$ivcCylsHigh>
  1553. The high-order 4 bytes of the total number of cylinders.
  1554. =item C<$uMediaType>
  1555. A code for the type of media. See the C<":MEDIA_TYPE"> export class.
  1556. =item C<$uTracksPerCyl>
  1557. The number of tracks in each cylinder.
  1558. =item C<$uSectsPerTrack>
  1559. The number of sectors in each track.
  1560. =item C<$uBytesPerSect>
  1561. The number of bytes in each sector.
  1562. =back
  1563. =item C<IOCTL_DISK_GET_PARTITION_INFO>
  1564. Request information about the size and geometry of the partition.
  1565. C<$pInBuf> should be C<[]>. C<$opOutBuf> will be set to a
  1566. C<PARTITION_INFORMATION> data structure which can be decode via:
  1567. ( $uStartLow, $ivStartHigh, $ucHiddenSects, $uPartitionSeqNumber,
  1568. $uPartitionType, $bActive, $bRecognized, $bToRewrite )=
  1569. unpack( "L l L L C c c c", $opOutBuf );
  1570. =over
  1571. =item C<$uStartLow> and C<$ivStartHigh>
  1572. The low-order and high-order [respectively] 4 bytes of the starting
  1573. offset of the partition, measured in bytes.
  1574. =item C<$ucHiddenSects>
  1575. The number of "hidden" sectors for this partition. Actually this is
  1576. the number of sectors found prior to this partiton, that is, the
  1577. starting offset [as found in C<$uStartLow> and C<$ivStartHigh>]
  1578. divided by the number of bytes per sector.
  1579. =item C<$uPartitionSeqNumber>
  1580. The sequence number of this partition. Partitions are numbered
  1581. starting as C<1> [with "partition 0" meaning the entire disk].
  1582. Sometimes this field may be C<0> and you'll have to infer the
  1583. partition sequence number from how many partitions preceed it on
  1584. the disk.
  1585. =item C<$uPartitionType>
  1586. The type of partition. See the C<":PARTITION_"> export class for a
  1587. list of known types. See also C<IsRecognizedPartition> and
  1588. C<IsContainerPartition>.
  1589. =item C<$bActive>
  1590. C<1> for the active [boot] partition, C<0> otherwise.
  1591. =item C<$bRecognized>
  1592. Whether this type of partition is support under Win32.
  1593. =item C<$bToRewrite>
  1594. Whether to update this partition information. This field is not used
  1595. by C<IOCTL_DISK_GET_PARTITION_INFO>. For
  1596. C<IOCTL_DISK_SET_DRIVE_LAYOUT>, you must set this field to a true
  1597. value for any partitions you wish to have changed, added, or deleted.
  1598. =back
  1599. =item C<IOCTL_DISK_SET_PARTITION_INFO>
  1600. Change the type of the partition. C<$opOutBuf> should be C<[]>.
  1601. C<$pInBuf> should be a C<SET_PARTITION_INFORMATION> data structure
  1602. which is just a single byte containing the new parition type [see
  1603. the C<":PARTITION_"> export class for a list of known types]:
  1604. $pInBuf= pack( "C", $uPartitionType );
  1605. =item C<IOCTL_DISK_GET_DRIVE_LAYOUT>
  1606. Request information about the disk layout. C<$pInBuf> should be C<[]>.
  1607. C<$opOutBuf> will be set to contain C<DRIVE_LAYOUT_INFORMATION>
  1608. structure including several C<PARTITION_INFORMATION> structures:
  1609. my( $cPartitions, $uDiskSignature )= unpack( "L L", $opOutBuf );
  1610. my @fields= unpack( "x8" . ( "L l L L C c c c" x $cPartitions ),
  1611. $opOutBuf );
  1612. my( @uStartLow, @ivStartHigh, @ucHiddenSects,
  1613. @uPartitionSeqNumber, @uPartitionType, @bActive,
  1614. @bRecognized, @bToRewrite )= ();
  1615. for( 1..$cPartition ) {
  1616. push( @uStartLow, unshift @fields );
  1617. push( @ivStartHigh, unshift @fields );
  1618. push( @ucHiddenSects, unshift @fields );
  1619. push( @uPartitionSeqNumber, unshift @fields );
  1620. push( @uPartitionType, unshift @fields );
  1621. push( @bActive, unshift @fields );
  1622. push( @bRecognized, unshift @fields );
  1623. push( @bToRewrite, unshift @fields );
  1624. }
  1625. =over
  1626. =item C<$cPartitions>
  1627. If the number of partitions on the disk.
  1628. =item C<$uDiskSignature>
  1629. Is the disk signature, a unique number assigned by Disk Administrator
  1630. [F<WinDisk.exe>] and used to identify the disk. This allows drive
  1631. letters for partitions on that disk to remain constant even if the
  1632. SCSI Target ID of the disk gets changed.
  1633. =back
  1634. See C<IOCTL_DISK_GET_PARTITION_INFORMATION> for information on the
  1635. remaining these fields.
  1636. =item C<IOCTL_DISK_GET_MEDIA_TYPES>
  1637. Is supposed to be superseded by C<IOCTL_STORAGE_GET_MEDIA_TYPES> but
  1638. is still useful for determining the types of floppy diskette formats
  1639. that can be produced by a given floppy drive. See
  1640. F<ex/FormatFloppy.plx> for an example.
  1641. =item C<IOCTL_DISK_SET_DRIVE_LAYOUT>
  1642. Change the partition layout of the disk. C<$pOutBuf> should be C<[]>.
  1643. C<$pInBuf> should be a C<DISK_LAYOUT_INFORMATION> data structure
  1644. including several C<PARTITION_INFORMATION> data structures.
  1645. # Already set: $cPartitions, $uDiskSignature, @uStartLow, @ivStartHigh,
  1646. # @ucHiddenSects, @uPartitionSeqNumber, @uPartitionType, @bActive,
  1647. # @bRecognized, and @bToRewrite.
  1648. my( @fields, $prtn )= ();
  1649. for $prtn ( 1..$cPartition ) {
  1650. push( @fields, $uStartLow[$prtn-1], $ivStartHigh[$prtn-1],
  1651. $ucHiddenSects[$prtn-1], $uPartitionSeqNumber[$prtn-1],
  1652. $uPartitionType[$prtn-1], $bActive[$prtn-1],
  1653. $bRecognized[$prtn-1], $bToRewrite[$prtn-1] );
  1654. }
  1655. $pInBuf= pack( "L L" . ( "L l L L C c c c" x $cPartitions ),
  1656. $cPartitions, $uDiskSignature, @fields );
  1657. To delete a partition, zero out all fields except for C<$bToRewrite>
  1658. which should be set to C<1>. To add a partition, increment
  1659. C<$cPartitions> and add the information for the new partition
  1660. into the arrays, making sure that you insert C<1> into @bToRewrite.
  1661. See C<IOCTL_DISK_GET_DRIVE_LAYOUT> and
  1662. C<IOCTL_DISK_GET_PARITITON_INFORMATION> for descriptions of the
  1663. fields.
  1664. =item C<IOCTL_DISK_VERIFY>
  1665. Performs a logical format of [part of] the disk. C<$opOutBuf> should
  1666. be C<[]>. C<$pInBuf> should contain a C<VERIFY_INFORMATION> data
  1667. structure:
  1668. $pInBuf= pack( "L l L",
  1669. $uStartOffsetLow, $ivStartOffsetHigh, $uLength );
  1670. =over
  1671. =item C<$uStartOffsetLow> and C<$ivStartOffsetHigh>
  1672. The low-order and high-order [respectively] 4 bytes of the offset [in
  1673. bytes] where the formatting should begin.
  1674. =item C<$uLength>
  1675. The length [in bytes] of the section to be formatted.
  1676. =back
  1677. =item C<IOCTL_DISK_FORMAT_TRACKS>
  1678. Format a range of tracks on the disk. C<$opOutBuf> should be C<[]>.
  1679. C<$pInBuf> should contain a C<FORMAT_PARAMETERS> data structure:
  1680. $pInBuf= pack( "L L L L L", $uMediaType,
  1681. $uStartCyl, $uEndCyl, $uStartHead, $uEndHead );
  1682. C<$uMediaType> if the type of media to be formatted. Mostly used to
  1683. specify the density to use when formatting a floppy diskette. See the
  1684. C<":MEDIA_TYPE"> export class for more information.
  1685. The remaining fields specify the starting and ending cylinder and
  1686. head of the range of tracks to be formatted.
  1687. =item C<IOCTL_DISK_REASSIGN_BLOCKS>
  1688. Reassign a list of disk blocks to the disk's spare-block pool.
  1689. C<$opOutBuf> should be C<[]>. C<$pInBuf> should be a
  1690. C<REASSIGN_BLOCKS> data structure:
  1691. $pInBuf= pack( "S S L*", 0, $cBlocks, @uBlockNumbers );
  1692. =item C<IOCTL_DISK_PERFORMANCE>
  1693. Request information about disk performance. C<$pInBuf> should be C<[]>.
  1694. C<$opOutBuf> will be set to contain a C<DISK_PERFORMANCE> data structure:
  1695. my( $ucBytesReadLow, $ivcBytesReadHigh,
  1696. $ucBytesWrittenLow, $ivcBytesWrittenHigh,
  1697. $uReadTimeLow, $ivReadTimeHigh,
  1698. $uWriteTimeLow, $ivWriteTimeHigh,
  1699. $ucReads, $ucWrites, $uQueueDepth )=
  1700. unpack( "L l L l L l L l L L L", $opOutBuf );
  1701. =item C<IOCTL_DISK_IS_WRITABLE>
  1702. No documentation on this IOCTL operation was found.
  1703. =item C<IOCTL_DISK_LOGGING>
  1704. Control disk logging. Little documentation for this IOCTL operation
  1705. was found. It makes use of a C<DISK_LOGGING> data structure:
  1706. =over
  1707. =item DISK_LOGGING_START
  1708. Start logging each disk request in a buffer internal to the disk device
  1709. driver of size C<$uLogBufferSize>:
  1710. $pInBuf= pack( "C L L", 0, 0, $uLogBufferSize );
  1711. =item DISK_LOGGING_STOP
  1712. Stop loggin each disk request:
  1713. $pInBuf= pack( "C L L", 1, 0, 0 );
  1714. =item DISK_LOGGING_DUMP
  1715. Copy the interal log into the supplied buffer:
  1716. $pLogBuffer= ' ' x $uLogBufferSize
  1717. $pInBuf= pack( "C P L", 2, $pLogBuffer, $uLogBufferSize );
  1718. ( $uByteOffsetLow[$i], $ivByteOffsetHigh[$i],
  1719. $uStartTimeLow[$i], $ivStartTimeHigh[$i],
  1720. $uEndTimeLog[$i], $ivEndTimeHigh[$i],
  1721. $hVirtualAddress[$i], $ucBytes[$i],
  1722. $uDeviceNumber[$i], $bWasReading[$i] )=
  1723. unpack( "x".(8+8+8+4+4+1+1+2)." L l L l L l L L C c x2", $pLogBuffer );
  1724. =item DISK_LOGGING_BINNING
  1725. Keep statics grouped into bins based on request sizes.
  1726. $pInBuf= pack( "C P L", 3, $pUnknown, $uUnknownSize );
  1727. =back
  1728. =item C<IOCTL_DISK_FORMAT_TRACKS_EX>
  1729. No documentation on this IOCTL is included.
  1730. =item C<IOCTL_DISK_HISTOGRAM_STRUCTURE>
  1731. No documentation on this IOCTL is included.
  1732. =item C<IOCTL_DISK_HISTOGRAM_DATA>
  1733. No documentation on this IOCTL is included.
  1734. =item C<IOCTL_DISK_HISTOGRAM_RESET>
  1735. No documentation on this IOCTL is included.
  1736. =item C<IOCTL_DISK_REQUEST_STRUCTURE>
  1737. No documentation on this IOCTL operation was found.
  1738. =item C<IOCTL_DISK_REQUEST_DATA>
  1739. No documentation on this IOCTL operation was found.
  1740. =back
  1741. =item C<":GENERIC_">
  1742. Constants specifying generic access permissions that are not specific
  1743. to one type of object.
  1744. GENERIC_ALL GENERIC_EXECUTE
  1745. GENERIC_READ GENERIC_WRITE
  1746. =item C<":MEDIA_TYPE">
  1747. Different classes of media that a device can support. Used in the
  1748. C<$uMediaType> field of a C<DISK_GEOMETRY> structure.
  1749. =over
  1750. =item C<Unknown>
  1751. Format is unknown.
  1752. =item C<F5_1Pt2_512>
  1753. 5.25" floppy, 1.2MB [really 1,200KB] total space, 512 bytes/sector.
  1754. =item C<F3_1Pt44_512>
  1755. 3.5" floppy, 1.44MB [really 1,440KB] total space, 512 bytes/sector.
  1756. =item C<F3_2Pt88_512>
  1757. 3.5" floppy, 2.88MB [really 2,880KB] total space, 512 bytes/sector.
  1758. =item C<F3_20Pt8_512>
  1759. 3.5" floppy, 20.8MB total space, 512 bytes/sector.
  1760. =item C<F3_720_512>
  1761. 3.5" floppy, 720KB total space, 512 bytes/sector.
  1762. =item C<F5_360_512>
  1763. 5.25" floppy, 360KB total space, 512 bytes/sector.
  1764. =item C<F5_320_512>
  1765. 5.25" floppy, 320KB total space, 512 bytes/sector.
  1766. =item C<F5_320_1024>
  1767. 5.25" floppy, 320KB total space, 1024 bytes/sector.
  1768. =item C<F5_180_512>
  1769. 5.25" floppy, 180KB total space, 512 bytes/sector.
  1770. =item C<F5_160_512>
  1771. 5.25" floppy, 160KB total space, 512 bytes/sector.
  1772. =item C<RemovableMedia>
  1773. Some type of removable media other than a floppy diskette.
  1774. =item C<FixedMedia>
  1775. A fixed hard disk.
  1776. =item C<F3_120M_512>
  1777. 3.5" floppy, 120MB total space.
  1778. =back
  1779. =item C<":MOVEFILE_">
  1780. Constants for use in C<$uFlags> arguments to C<MoveFileEx>.
  1781. MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT
  1782. MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH
  1783. =item C<":SECURITY_">
  1784. Security quality of service values that can be used in the C<$uFlags>
  1785. argument to C<CreateFile> if opening the client side of a named pipe.
  1786. SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING
  1787. SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY
  1788. SECURITY_IDENTIFICATION SECURITY_IMPERSONATION
  1789. SECURITY_SQOS_PRESENT
  1790. =item C<":SEM_">
  1791. Constants to be used with C<SetErrorMode>.
  1792. SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX
  1793. SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX
  1794. =item C<":PARTITION_">
  1795. Constants describing partition types.
  1796. PARTITION_ENTRY_UNUSED PARTITION_FAT_12
  1797. PARTITION_XENIX_1 PARTITION_XENIX_2
  1798. PARTITION_FAT_16 PARTITION_EXTENDED
  1799. PARTITION_HUGE PARTITION_IFS
  1800. PARTITION_FAT32 PARTITION_FAT32_XINT13
  1801. PARTITION_XINT13 PARTITION_XINT13_EXTENDED
  1802. PARTITION_PREP PARTITION_UNIX
  1803. VALID_NTFT PARTITION_NTFT
  1804. =item C<":ALL">
  1805. All of the above.
  1806. =back
  1807. =head1 BUGS
  1808. None known at this time.
  1809. =head1 AUTHOR
  1810. Tye McQueen, tye@metronet.com, http://www.metronet.com/~tye/.
  1811. =head1 SEE ALSO
  1812. The pyramids.
  1813. =cut