Manpage of APIFile::File
use Win32API::File 0.08 qw( :ALL );
MoveFile( $Source, $Destination )
or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
MoveFileEx( $Source, $Destination, MOVEFILE_REPLACE_EXISTING() )
or die "Can't move $Source to $Destination: ",fileLastError(),"\n";
[...]
To pass in "NULL" as the pointer to an optional buffer, pass in an empty list reference, "[]".
Beyond raw access to the API calls and related constants, this module handles smart buffer allocation and translation of return codes.
All functions, unless otherwise noted, return a true value for success and a false value for failure and set $^E on failure.
This version of "Win32API::File" can be used like an "IO::File" object. Ie:
my $file = new Win32API::File "+> foo"; binmode $file; print $file "hello there\n"; seek $file, 0, 0; my $line = <$file>; $file->close;
It also supports tying via a win32 handle (for example, from "createFile()"):
tie FILE, 'Win32API::File', $win32_handle; print FILE "...";
It has not been extensively tested yet and buffered I/O is not yet implemented.
On failure, $hObject gets set to a false value and "regLastError()" and $^E are set to the reason for the failure. Otherwise, $hObject gets set to a Win32 native file handle which is alwasy a true value [returns "0 but true" in the impossible(?) case of the handle having a value of 0].
$sPath is the path to the file [or device, etc.] to be opened. See "CreateFile" for more information on possible special values for $sPath.
$svAccess can be a number containing the bit mask representing the specific type(s) of access to the file that you desire. See the $uAccess parameter to "CreateFile" for more information on these values.
More likely, $svAccess is a string describing the generic type of access you desire and possibly the file creation options to use. In this case, $svAccess should contain zero or more characters from "qrw" [access desired], zero or one character each from "ktn" and "ce", and optional white space. These letters stand for, respectively, ``Query access'', ``Read access'', ``Write access'', ``Keep if exists'', ``Truncate if exists'', ``New file only'', ``Create if none'', and ``Existing file only''. Case is ignored.
You can pass in "?" for $svAccess to have an error message displayed summarizing its possible values. This is very handy when doing on-the-fly programming using the Perl debugger:
Win32API::File::createFile: $svAccess can use the following:
One or more of the following:
q -- Query access (same as 0)
r -- Read access (GENERIC_READ)
w -- Write access (GENERIC_WRITE)
At most one of the following:
k -- Keep if exists
t -- Truncate if exists
n -- New file only (fail if file already exists)
At most one of the following:
c -- Create if doesn't exist
e -- Existing file only (fail if doesn't exist)
'' is the same as 'q k e'
'r' is the same as 'r k e'
'w' is the same as 'w t c'
'rw' is the same as 'rw k c'
'rt' or 'rn' implies 'c'.
Or $access can be numeric.
$svAccess is designed to be ``do what I mean'', so you can skip the rest of its explanation unless you are interested in the complex details. Note that, if you want write access to a device, you need to specify "k" [and perhaps "e", as in "w ke" or "rw ke"] since Win32 suggests "OPEN_EXISTING" be used when opening a device.
The characters from "ktn" and "ce" are combined to determine the what value for $uCreate to pass to "CreateFile" [unless overridden by $rvhvOptions]:
$svShare controls how the file is shared, that is, whether other processes can have read, write, and/or delete access to the file while we have it opened. $svShare will usually be a string containing zero or more characters from "rwd" but can also be a numeric bit mask.
"r" sets the "FILE_SHARE_READ" bit which allows other processes to have read access to the file. "w" sets the "FILE_SHARE_WRITE" bit which allows other processes to have write access to the file. "d" sets the "FILE_SHARE_DELETE" bit which allows other processes to have delete access to the file [ignored under Windows 95].
The default for $svShare is "rw" which provides the same sharing as using regular perl "open()".
If another process currently has read, write, and/or delete access to the file and you don't allow that level of sharing, then your call to "createFile" will fail. If you requested read, write, and/or delete access and another process already has the file open but doesn't allow that level of sharing, then your call to "createFile" will fail. Once you have the file open, if another process tries to open it with read, write, and/or delete access and you don't allow that level of sharing, then that process won't be allowed to open the file.
$rvhvOptions is a reference to a hash where any keys must be from the list "qw( Access Create Share Attributes Flags Security Model )". The meaning of the value depends on the key name, as described below. Any option values in $rvhvOptions override the settings from $svAccess and $svShare if they conflict.
If opening the client side of a named pipe, then you can also specify "SECURITY_SQOS_PRESENT" along with one of the other "SECURITY_*" constants to specify the security quality of service to be used.
$uAccess should be an unsigned value containing bits set to indicate the type of access desired. "GENERIC_READ" is the default.
$uCreate should be one of "OPEN_ALWAYS", "OPEN_EXISTING", "TRUNCATE_EXISTING", "CREATE_ALWAYS", or "CREATE_NEW".
$uShare should be an unsigned value having zero or more of the following bits set: "FILE_SHARE_READ", "FILE_SHARE_WRITE", and "FILE_SHARE_DELETE". "FILE_SHARE_READ|FILE_SHARE_WRITE" is the default.
Examples:
$hFlop= createFile( "//./A:", "r", "r" )
or die "Can't prevent others from writing to floppy: $^E\n";
$hDisk= createFile( "//./C:", "rw ke", "" )
or die "Can't get exclusive access to C: $^E\n";
$hDisk= createFile( $sFilePath, "ke",
{ Access=>FILE_READ_ATTRIBUTES } )
or die "Can't read attributes of $sFilePath: $^E\n";
$hTemp= createFile( "$ENV{Temp}/temp.$$", "wn", "",
{ Attributes=>"hst", Flags=>FILE_FLAG_DELETE_ON_CLOSE() } )
or die "Can't create temporary file, temp.$$: $^E\n";
If $bFailIfExists is true and $sNewFileName is the path to a file that already exists, then "CopyFile" will fail. If $bFailIfExists is falsea, then the copy of the $sOldFileNmae file will overwrite the $sNewFileName file if it already exists.
Like most routines, returns a true value if successful and a false value [and sets $^E and "regLastError()"] on failure.
$sPath is the path to the file [or device, etc.] to be opened.
$sPath can use "/" or "\\" as path delimiters and can even mix the two. We will usually only use "/" in our examples since using "\\" is usually harder to read.
Under Windows NT, $sPath can start with "//?/" to allow the use of paths longer than "MAX_PATH" [for UNC paths, replace the leading "//" with "//?/UNC/", as in "//?/UNC/Server/Share/Dir/File.Ext"].
$sPath can start with "//./" to indicate that the rest of the path is the name of a ``DOS device.'' You can use "QueryDosDevice" to list all current DOS devices and can add or delete them with "DefineDosDevice". If you get the source-code distribution of this module from CPAN, then it includes an example script, ex/ListDevs.plx that will list all current DOS devices and their ``native'' definition. Again, note that this doesn't work under Win95 nor Win98.
The most common such DOS devices include:
Locking this for exclusive access [by specifying 0 for $uShare] doesn't prevent access to the partitions on the disk nor their file systems. So other processes can still access any raw sectors within a partition and can use the file system on the disk as usual.
Locking this for exclusive access doesn't prevent access to the physical drive that the partition is on so other processes can still access the raw sectors that way. Locking this for exclusive access does prevent other processes from opening the same raw partition and does prevent access to the file system on it. It even prevents the current process from accessing the file system on that partition.
Locking this for exclusive access prevents all access to the floppy.
$uAccess is an unsigned value with bits set indicating the type of access desired. Usually either 0 [``query'' access], "GENERIC_READ", "GENERIC_WRITE", "GENERIC_READ|GENERIC_WRITE", or "GENERIC_ALL". More specific types of access can be specified, such as "FILE_APPEND_DATA" or "FILE_READ_EA".
$uShare controls how the file is shared, that is, whether other processes can have read, write, and/or delete access to the file while we have it opened. $uShare is an unsigned value with zero or more of these bits set: "FILE_SHARE_READ", "FILE_SHARE_WRITE", and "FILE_SHARE_DELETE".
If another process currently has read, write, and/or delete access to the file and you don't allow that level of sharing, then your call to "CreateFile" will fail. If you requested read, write, and/or delete access and another process already has the file open but doesn't allow that level of sharing, thenn your call to "createFile" will fail. Once you have the file open, if another process tries to open it with read, write, and/or delete access and you don't allow that level of sharing, then that process won't be allowed to open the file.
$pSecAttr should either be "[]" [for "NULL"] or a "SECURITY_ATTRIBUTES" data structure packed into a string. For example, if $pSecDesc contains a "SECURITY_DESCRIPTOR" structure packed into a string, perhaps via:
RegGetKeySecurity( $key, 4, $pSecDesc, 1024 );
then you can set $pSecAttr via:
$pSecAttr= pack( "L P i", 12, $pSecDesc, $bInheritHandle );
$uCreate is one of the following values: "OPEN_ALWAYS", "OPEN_EXISTING", "TRUNCATE_EXISTING", "CREATE_ALWAYS", and "CREATE_NEW".
$uFlags is an unsigned value with zero or more bits set indicating attributes to associate with the file ["FILE_ATTRIBUTE_*" values] or special options ["FILE_FLAG_*" values].
If opening the client side of a named pipe, then you can also set $uFlags to include "SECURITY_SQOS_PRESENT" along with one of the other "SECURITY_*" constants to specify the security quality of service to be used.
$hModel is 0 [or "[]", both of which mean "NULL"] or a Win32 native handle opened with "GENERIC_READ" access to a model file from which file attributes and extended attributes are to be copied if a new file gets created.
Examples:
$hFlop= CreateFile( "//./A:", GENERIC_READ(),
FILE_SHARE_READ(), [], OPEN_EXISTING(), 0, [] )
or die "Can't prevent others from writing to floppy: $^E\n";
$hDisk= createFile( $sFilePath, FILE_READ_ATTRIBUTES(),
FILE_SHARE_READ()|FILE_SHARE_WRITE(), [], OPEN_EXISTING(), 0, [] )
or die "Can't read attributes of $sFilePath: $^E\n";
$hTemp= createFile( "$ENV{Temp}/temp.$$", GENERIC_WRITE(), 0,
CREATE_NEW(), FILE_FLAG_DELETE_ON_CLOSE()|attrLetsToBits("hst"), [] )
or die "Can't create temporary file, temp.$$: $^E\n";
$sDosDeviceName is the name of a DOS device for which we'd like to add or delete a definition.
$uFlags is an unsigned value with zero or more of the following bits set:
If the last definition is removed, then the DOS device name is also deleted.
$sTargetPath is the DOS device's specific definition that you wish to add or delete. For "DDD_RAW_TARGET_PATH", these usually start with "\\Device\\". If the "DDD_RAW_TARGET_PATH" bit is not set, then $sTargetPath is just an ordinary path to some file or directory, providing the functionality of the subst command.
Like most routines, returns a true value if successful and a false value [and sets $^E and "regLastError()"] on failure.
$hDevice is a Win32 native file handle to a device [return value from "CreateFile"].
$uIoControlCode is an unsigned value [a "IOCTL_*" constant] indicating the type query or other operation to be performed.
$pInBuf is "[]" [for "NULL"] or a data structure packed into a string. The type of data structure depends on the $uIoControlCode value. $lInBuf is 0 or the length of the structure in $pInBuf. If $pInBuf is not "[]" and $lInBuf is 0, then $lInBuf will automatically be set to "length($pInBuf)" for you.
$opOutBuf is "[]" [for "NULL"] or will be set to contain a returned data structure packed into a string. $lOutBuf indicates how much space to allocate in $opOutBuf for "DeviceIoControl" to store the data structure. If $lOutBuf is a number and $opOutBuf already has a buffer allocated for it that is larger than $lOutBuf bytes, then this larger buffer size will be passed to "DeviceIoControl". However, you can force a specific buffer size to be passed to "DeviceIoControl" by prepending a "=" to the front of $lOutBuf.
$olRetBytes is "[]" or is a scalar to receive the number of bytes written to $opOutBuf. Even when $olRetBytes is "[]", a valid pointer to a "DWORD" [and not "NULL"] is passed to "DeviceIoControl". In this case, "[]" just means that you don't care about the value that might be written to $olRetBytes, which is usually the case since you can usually use "length($opOutBuf)" instead.
$pOverlapped is "[]" or is a "OVERLAPPED" structure packed into a string. This is only useful if $hDevice was opened with the "FILE_FLAG_OVERLAPPED" flag set.
When you call Perl's "open" to set a Perl file handle [like "STDOUT"], Perl calls C's "fopen" to set a stdio "FILE *". C's "fopen" calls something like Unix's "open", that is, Win32's "_sopen", to get an integer file descriptor [where 0 is for "STDIN", 1 for "STDOUT", etc.]. Win32's "_sopen" calls "CreateFile" to set a "HANDLE", a Win32 native file handle. So every Perl file handle [like "STDOUT"] has an integer file descriptor associated with it that you can get via "fileno". And, under Win32, every file descriptor has a Win32 native file handle associated with it. "FdGetOsFHandle" lets you get access to that.
$hNativeHandle is set to "INVALID_HANDLE_VALUE" [and "lastFileError()" and $^E are set] if "FdGetOsFHandle" fails. See also "GetOsFHandle" which provides a friendlier interface.
This function is rarely used since you will usually get the value of a constant by having that constant imported into your package by listing the constant name in the "use Win32API::File" statement and then simply using the constant name in your code [perhaps followed by "()"]. This function is useful for verifying constant names not in Perl code, for example, after prompting a user to type in a constant name.
Just like $^E, in a numeric context "fileLastError()" returns the numeric error value while in a string context it returns a text description of the error [actually it returns a Perl scalar that contains both values so "$x= fileLastError()" causes $x to give different values in string vs. numeric contexts]. On old versions of Perl where $^E isn't tied to "GetLastError()", "fileLastError" simply returns the number of the error and you'll need to use <Win32::FormatMessage> to get the error string.
The last form sets the error returned by future calls to "fileLastError()" and should not be used often. $uError must be a numeric error code. Also returns the dual-valued version of $uError.
It takes a Win32 native file handle and returns the size in bytes. Since the size can be a 64 bit value, on non 64 bit integer Perls the value returned will be an object of type "Math::BigInt".
As far as creating the $pOverlapped structure, you are currently on your own.
See <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getoverlappedresult.asp> for more information.
$lBufSize is the size of the buffer to allocate to store this list of strings. "26*4+1" is always sufficient and should usually be used.
$osBuffer is a scalar to be set to contain the constructed string.
$olOutLength is the number of bytes actually written to $osBuffer but "length($osBuffer)" can also be used to determine this.
For example, on a poorly equipped computer,
GetLogicalDriveStrings( 4*26+1, $osBuffer );
might set $osBuffer to the 9-character string, "A:\\\0C:\\\0\0".
$hObject is an open Win32 native file handle or an open Win32 native handle to some other type of object.
$ouFlags will be set to an unsigned value having zero or more of the bits "HANDLE_FLAG_INHERIT" and "HANDLE_FLAG_PROTECT_FROM_CLOSE" set. See the ":HANDLE_FLAG_" export class for the meanings of these bits.
$hNativeHandle is set to a false value [and "lastFileError()" and $^E are set] if "GetOsFHandle" fails. "GetOsFHandle" returns "0 but true" in the impossible(?) case of the handle having a value of 0.
$sRootPath is a string specifying the path to the root of the file system, for example, "C:/".
$osVolName is a scalar to be set to the string representing the volume name, also called the file system label. $lVolName is the number of bytes to allocate for the $osVolName buffer [see ``Buffer Sizes'' for more information].
$ouSerialNum is "[]" [for "NULL"] or will be set to the numeric value of the volume's serial number.
$ouMaxNameLen is "[]" [for "NULL"] or will be set to the maximum length allowed for a file name or directory name within the file system.
$osFsType is a scalar to be set to the string representing the file system type, such as "FAT" or "NTFS". $lFsType is the number of bytes to allocate for the $osFsType buffer [see ``Buffer Sizes'' for more information].
$ouFsFlags is "[]" [for "NULL"] or will be set to an unsigned integer with bits set indicating properties of the file system:
Common values for $ivPartitionType include "PARTITION_FAT_12==1", "PARTITION_FAT_16==4", "PARTITION_EXTENDED==5", "PARTITION_FAT32==0xB".
Files can be ``renamed'' between file systems and the file contents and some attributes will be moved. Directories can only be renamed within one file system. If there is already a file or directory named $sNewName, then "MoveFile" will fail.
$uFlags is an unsigned value with zero or more of the following bits set:
When this bit is set, $sNewName can be "[]" [for "NULL"] to indicate that $sOldName should be deleted during the next boot rather than renamed.
Setting both the "MOVEFILE_COPY_ALLOWED" and "MOVEFILE_DELAY_UNTIL_REBOOT" bits will cause "MoveFileEx" to fail.
"FILE" is a Perl file handle [in any of the supported forms, a bareword, a string, a typeglob, or a reference to a typeglob] that will be opened. If "FILE" is already open, it will automatically be closed before it is reopened.
$hNativeHandle is an open Win32 native file handle, probably the return value from "CreateFile" or "createFile".
$sMode is string of zero or more letters from "rwatb". These are translated into a combination "O_RDONLY" ["r"], "O_WRONLY" ["w"], "O_RDWR" ["rw"], "O_APPEND" ["a"], "O_TEXT" ["t"], and "O_BINARY" ["b"] flags [see the Fcntl module] that is passed to "OsFHandleOpenFd". Currently only "O_APPEND" and "O_TEXT" have any significance.
Also, a "r" and/or "w" in $sMode is used to decide how the file descriptor is converted into a Perl file handle, even though this doesn't appear to make a difference. One of the following is used:
open( FILE, "<&=".$ivFd ) # "r" w/o "w"
open( FILE, ">&=".$ivFd ) # "w" w/o "r"
open( FILE, "+<&=".$ivFd ) # both "r" and "w"
"OsFHandleOpen" eventually calls the Win32-specific C routine "_open_osfhandle()" or Perl's ``improved'' version called "win32_open_osfhandle()". Prior to Perl5.005, C's "_open_osfhandle()" is called which will fail if "GetFileType($hNativeHandle)" would return "FILE_TYPE_UNKNOWN". For Perl5.005 and later, "OsFHandleOpen" calls "win32_open_osfhandle()" from the Perl DLL which doesn't have this restriction.
$uMode the logical combination of zero or more "O_*" constants exported by the "Fcntl" module. Currently only "O_APPEND" and "O_TEXT" have any significance.
$ivFD will be non-negative if the open operation was successful. For failure, "-1" is returned and $! [and possibly "fileLastError()" and $^E] is set to the reason for the failure.
$sDosDeviceName is the name of the ``DOS'' device whose definitions we want. For example, "C:", "COM1", or "PhysicalDrive0". If $sDosDeviceName is "[]" [for "NULL"], the list of all DOS device names is returned instead.
$osTargetPath will be assigned a string containing the list of definitions. The definitions are each '\0'-terminate and are concatenated into the string, most recent first, with an extra '\0' at the end of the whole string [see "GetLogicalDriveStrings" for a sample of this format].
$lTargetBuf is the size [in bytes] of the buffer to allocate for $osTargetPath. See ``Buffer Sizes'' for more information.
$olTargetLen is set to the number of bytes written to $osTargetPath but you can also use "length($osTargetPath)" to determine this.
For failure, 0 is returned and "fileLastError()" and $^E are set to the reason for the failure.
$hFile is a Win32 native file handle that is already open to the file or device to read from.
$opBuffer will be set to a string containing the bytes read.
$lBytes is the number of bytes you would like to read. $opBuffer is automatically initialized to have a buffer large enough to hold that many bytes. Unlike other buffer sizes, $lBytes does not need to have a "=" prepended to it to prevent a larger value to be passed to the underlying Win32 "ReadFile" API. However, a leading "=" will be silently ignored, even if Perl warnings are enabled.
If $olBytesRead is not "[]", it will be set to the actual number of bytes read, though "length($opBuffer)" can also be used to determine this.
$pOverlapped is "[]" or is a "OVERLAPPED" structure packed into a string. This is only useful if $hFile was opened with the "FILE_FLAG_OVERLAPPED" flag set.
This affects the "CreateFile" and "GetVolumeInformation" calls.
Setting this bit is useful for allowing you to check whether a floppy diskette is in the floppy drive.
This affects the "ReadFile" and "WriteFile" calls.
$hFile is a Win32 native file handle.
$uFromWhere is either "FILE_BEGIN", "FILE_CURRENT", or "FILE_END", indicating that the new file position is being specified relative to the beginning of the file, the current file pointer, or the end of the file, respectively.
$ivOffset is [if $ioivOffsetHigh is "[]"] the offset [in bytes] to the new file position from the position specified via $uFromWhere. If $ioivOffsetHigh is not "[]", then $ivOffset is converted to an unsigned value to be used as the low-order 4 bytes of the offset.
$ioivOffsetHigh can be "[]" [for "NULL"] to indicate that you are only specifying a 4-byte offset and the resulting file position will be 0xFFFFFFFE or less [just under 4GB]. Otherwise $ioivOfffsetHigh starts out with the high-order 4 bytes [signed] of the offset and gets set to the [unsigned] high-order 4 bytes of the resulting file position.
The underlying "SetFilePointer" returns 0xFFFFFFFF to indicate failure, but if $ioivOffsetHigh is not "[]", you would also have to check $^E to determine whether 0xFFFFFFFF indicates an error or not. "Win32API::File::SetFilePointer" does this checking for you and returns a false value if and only if the underlying "SetFilePointer" failed. For this reason, $uNewPos is set to "0 but true" if you set the file pointer to the beginning of the file [or any position with 0 for the low-order 4 bytes].
So the return value will be true if the seek operation was successful. For failure, a false value is returned and "fileLastError()" and $^E are set to the reason for the failure.
$hObject is an open Win32 native file handle or an open Win32 native handle to some other type of object.
$uMask is an unsigned value having one or more of the bits "HANDLE_FLAG_INHERIT" and "HANDLE_FLAG_PROTECT_FROM_CLOSE" set. Only bits set in $uMask will be modified by "SetHandleInformation".
$uFlags is an unsigned value having zero or more of the bits "HANDLE_FLAG_INHERIT" and "HANDLE_FLAG_PROTECT_FROM_CLOSE" set. For each bit set in $uMask, the cooresponding bit in the handle's flags is set to the value of the cooresponding bit in $uFlags.
If $uOldFlags were the value of the handle's flags before the call to "SetHandleInformation", then the value of the handle's flags afterward would be:
( $uOldFlags & ~$uMask ) | ( $uFlags & $uMask )
[at least as far as the "HANDLE_FLAG_INHERIT" and "HANDLE_FLAG_PROTECT_FROM_CLOSE" bits are concerned.]
See the ":HANDLE_FLAG_" export class for the meanings of these bits.
$hFile is a Win32 native file handle that is already open to the file or device to be written to.
$pBuffer is a string containing the bytes to be written.
$lBytes is the number of bytes you would like to write. If $pBuffer is not at least $lBytes long, "WriteFile" croaks. You can specify 0 for $lBytes to write "length($pBuffer)" bytes. A leading "=" on $lBytes will be silently ignored, even if Perl warnings are enabled.
$ouBytesWritten will be set to the actual number of bytes written unless you specify it as "[]".
$pOverlapped is "[]" or is an "OVERLAPPED" structure packed into a string. This is only useful if $hFile was opened with the "FILE_FLAG_OVERLAPPED" flag set.
CopyFileA
CreateFileA
DefineDosDeviceA
DeleteFileA
GetDriveTypeA
GetLogicalDriveStringsA
GetVolumeInformationA
MoveFileA
MoveFileExA
QueryDosDeviceA
CREATE_ALWAYS CREATE_NEW OPEN_ALWAYS
OPEN_EXISTING TRUNCATE_EXISTING INVALID_HANDLE_VALUE
FILE_BEGIN FILE_CURRENT FILE_END
DDD_EXACT_MATCH_ON_REMOVE
DDD_RAW_TARGET_PATH
DDD_REMOVE_DEFINITION
DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE
DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM
DRIVE_RAMDISK
FILE_READ_DATA FILE_LIST_DIRECTORY
FILE_WRITE_DATA FILE_ADD_FILE
FILE_APPEND_DATA FILE_ADD_SUBDIRECTORY
FILE_CREATE_PIPE_INSTANCE FILE_READ_EA
FILE_WRITE_EA FILE_EXECUTE
FILE_TRAVERSE FILE_DELETE_CHILD
FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES
FILE_ALL_ACCESS FILE_GENERIC_READ
FILE_GENERIC_WRITE FILE_GENERIC_EXECUTE )],
FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED
FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL
FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY
FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY
FILE_FLAG_BACKUP_SEMANTICS FILE_FLAG_DELETE_ON_CLOSE
FILE_FLAG_NO_BUFFERING FILE_FLAG_OVERLAPPED
FILE_FLAG_POSIX_SEMANTICS FILE_FLAG_RANDOM_ACCESS
FILE_FLAG_SEQUENTIAL_SCAN FILE_FLAG_WRITE_THROUGH
FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE
FILE_TYPE_CHAR FILE_TYPE_DISK
FILE_TYPE_PIPE FILE_TYPE_UNKNOWN
FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE
FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS
FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED
$pInBuf= pack( "i", $bPreventMediaRemoval );
# Calculate the number of DISK_GEOMETRY structures returned:
my $cStructs= length($opOutBuf)/(4+4+4+4+4+4);
my @fields= unpack( "L l I L L L" x $cStructs, $opOutBuf )
my( @ucCylsLow, @ivcCylsHigh, @uMediaType, @uTracksPerCyl,
@uSectsPerTrack, @uBytesPerSect )= ();
while( @fields ) {
push( @ucCylsLow, unshift @fields );
push( @ivcCylsHigh, unshift @fields );
push( @uMediaType, unshift @fields );
push( @uTracksPerCyl, unshift @fields );
push( @uSectsPerTrack, unshift @fields );
push( @uBytesPerSect, unshift @fields );
}
For the $ith type of supported media, the following variables will contain the following data.
Includes "IOCTL_DISK_FORMAT_TRACKS", "IOCTL_DISK_FORMAT_TRACKS_EX", "IOCTL_DISK_GET_DRIVE_GEOMETRY", "IOCTL_DISK_GET_DRIVE_LAYOUT", "IOCTL_DISK_GET_MEDIA_TYPES", "IOCTL_DISK_GET_PARTITION_INFO", "IOCTL_DISK_HISTOGRAM_DATA", "IOCTL_DISK_HISTOGRAM_RESET", "IOCTL_DISK_HISTOGRAM_STRUCTURE", "IOCTL_DISK_IS_WRITABLE", "IOCTL_DISK_LOGGING", "IOCTL_DISK_PERFORMANCE", "IOCTL_DISK_REASSIGN_BLOCKS", "IOCTL_DISK_REQUEST_DATA", "IOCTL_DISK_REQUEST_STRUCTURE", "IOCTL_DISK_SET_DRIVE_LAYOUT", "IOCTL_DISK_SET_PARTITION_INFO", and "IOCTL_DISK_VERIFY".
( $ucCylsLow, $ivcCylsHigh, $uMediaType, $uTracksPerCyl,
$uSectsPerTrack, $uBytesPerSect )= unpack( "L l I L L L", $opOutBuf );
( $uStartLow, $ivStartHigh, $ucHiddenSects, $uPartitionSeqNumber,
$uPartitionType, $bActive, $bRecognized, $bToRewrite )=
unpack( "L l L L C c c c", $opOutBuf );
$pInBuf= pack( "C", $uPartitionType );
my( $cPartitions, $uDiskSignature )= unpack( "L L", $opOutBuf );
my @fields= unpack( "x8" . ( "L l L L C c c c" x $cPartitions ),
$opOutBuf );
my( @uStartLow, @ivStartHigh, @ucHiddenSects,
@uPartitionSeqNumber, @uPartitionType, @bActive,
@bRecognized, @bToRewrite )= ();
for( 1..$cPartition ) {
push( @uStartLow, unshift @fields );
push( @ivStartHigh, unshift @fields );
push( @ucHiddenSects, unshift @fields );
push( @uPartitionSeqNumber, unshift @fields );
push( @uPartitionType, unshift @fields );
push( @bActive, unshift @fields );
push( @bRecognized, unshift @fields );
push( @bToRewrite, unshift @fields );
}
See "IOCTL_DISK_GET_PARTITION_INFORMATION" for information on the remaining these fields.
# Already set: $cPartitions, $uDiskSignature, @uStartLow, @ivStartHigh,
# @ucHiddenSects, @uPartitionSeqNumber, @uPartitionType, @bActive,
# @bRecognized, and @bToRewrite.
my( @fields, $prtn )= ();
for $prtn ( 1..$cPartition ) {
push( @fields, $uStartLow[$prtn-1], $ivStartHigh[$prtn-1],
$ucHiddenSects[$prtn-1], $uPartitionSeqNumber[$prtn-1],
$uPartitionType[$prtn-1], $bActive[$prtn-1],
$bRecognized[$prtn-1], $bToRewrite[$prtn-1] );
}
$pInBuf= pack( "L L" . ( "L l L L C c c c" x $cPartitions ),
$cPartitions, $uDiskSignature, @fields );
To delete a partition, zero out all fields except for $bToRewrite which should be set to 1. To add a partition, increment $cPartitions and add the information for the new partition into the arrays, making sure that you insert 1 into @bToRewrite.
See "IOCTL_DISK_GET_DRIVE_LAYOUT" and "IOCTL_DISK_GET_PARITITON_INFORMATION" for descriptions of the fields.
$pInBuf= pack( "L l L",
$uStartOffsetLow, $ivStartOffsetHigh, $uLength );
$pInBuf= pack( "L L L L L", $uMediaType,
$uStartCyl, $uEndCyl, $uStartHead, $uEndHead );
$uMediaType if the type of media to be formatted. Mostly used to specify the density to use when formatting a floppy diskette. See the ":MEDIA_TYPE" export class for more information.
The remaining fields specify the starting and ending cylinder and head of the range of tracks to be formatted.
$pInBuf= pack( "S S L*", 0, $cBlocks, @uBlockNumbers );
my( $ucBytesReadLow, $ivcBytesReadHigh,
$ucBytesWrittenLow, $ivcBytesWrittenHigh,
$uReadTimeLow, $ivReadTimeHigh,
$uWriteTimeLow, $ivWriteTimeHigh,
$ucReads, $ucWrites, $uQueueDepth )=
unpack( "L l L l L l L l L L L", $opOutBuf );
$pInBuf= pack( "C L L", 0, 0, $uLogBufferSize );
$pInBuf= pack( "C L L", 1, 0, 0 );
$pLogBuffer= ' ' x $uLogBufferSize
$pInBuf= pack( "C P L", 2, $pLogBuffer, $uLogBufferSize );
( $uByteOffsetLow[$i], $ivByteOffsetHigh[$i],
$uStartTimeLow[$i], $ivStartTimeHigh[$i],
$uEndTimeLog[$i], $ivEndTimeHigh[$i],
$hVirtualAddress[$i], $ucBytes[$i],
$uDeviceNumber[$i], $bWasReading[$i] )=
unpack( "x".(8+8+8+4+4+1+1+2)." L l L l L l L L C c x2", $pLogBuffer );
$pInBuf= pack( "C P L", 3, $pUnknown, $uUnknownSize );
GENERIC_ALL GENERIC_EXECUTE
GENERIC_READ GENERIC_WRITE
MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT
MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH
SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING
SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY
SECURITY_IDENTIFICATION SECURITY_IMPERSONATION
SECURITY_SQOS_PRESENT
SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX
SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX
PARTITION_ENTRY_UNUSED PARTITION_FAT_12
PARTITION_XENIX_1 PARTITION_XENIX_2
PARTITION_FAT_16 PARTITION_EXTENDED
PARTITION_HUGE PARTITION_IFS
PARTITION_FAT32 PARTITION_FAT32_XINT13
PARTITION_XINT13 PARTITION_XINT13_EXTENDED
PARTITION_PREP PARTITION_UNIX
VALID_NTFT PARTITION_NTFT