NAME
Win32API::File - Low-level access to Win32 system API calls for files/dirs.
SYNOPSIS
use Win32API::File 0.02 qw( :ALL );
MoveFile( $Source, $Destination )
or die "Can't move $Source to $Destination: $^E\n";
MoveFileEx( $Source, $Destination, MOVEFILE_REPLACE_EXISTING() )
or die "Can't move $Source to $Destination: $^E\n";
DESCRIPTION
This provides fairly low-level access to the Win32 System API calls dealing with files and directories.
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.
Exports
Nothing is exported by default. The following tags can be used to have large sets of symbols exported: ":Func", ":FuncA", ":FuncW", ":Misc", ":DDD_", ":DRIVE_", ":FILE_", ":FILE_ATTRIBUTE_", ":FILE_FLAG_", ":FILE_SHARE_", ":FILE_TYPE_", ":FS_", ":IOCTL_STORAGE_", ":IOCTL_DISK_", ":GENERIC_", ":MEDIA_TYPE", ":MOVEFILE_", ":SECURITY_", ":SEM_", and ":PARTITION_".
":Func"-
The basic function names:
attrLetsToBits,createFile,getLogicalDrives,CloseHandle,CopyFile,CreateFile,DeleteFile,DefineDosDevice,DeviceIoControl,FdGetOsFHandle,GetDriveType,GetFileType,GetLogicalDrives,GetLogicalDriveStrings,GetOsFHandle,GetVolumeInformation,IsRecognizedPartition,IsContainerPartition,MoveFile,MoveFileEx,OsFHandleOpen,OsFHandleOpenFd,QueryDosDevice,ReadFile,SetFilePointer,SetErrorMode, andWriteFile.- attrLetsToBits
$uBits= attrLetsToBits( $sAttributeLetters )-
Converts a string of file attribute letters into an unsigned value with the corresponding bits set.
$sAttributeLettersshould contain zero or more letters from"achorst": - createFile
$hObject= createFile( $sPath )$hObject= createFile( $sPath, $rvhvOptions )$hObject= createFile( $sPath, $svAccess )$hObject= createFile( $sPath, $svAccess, $rvhvOptions )-
This is a Perl-friendly wrapper around
CreateFile.On failure,
$hObjectgets set to a false value and$^Eis set to the reason for the failure. Otherwise,$hObjectgets 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 of0].$sPathis the path to the file [or device, etc.] to be opened. SeeCreateFilefor more information on possible special values for$sPath.$svAccesscan be a number containing the bit mask representing the specific type(s) of access to the file that you desire. See the$uAccessparameter toCreateFilefor more information on these values.More likely,
$svAccessis a string describing the generic type of access you desire and possibly the file creation options to use. In this case,$svAccessshould 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$svAccessto 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.$svAccessis 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"e"[as in"w ke"or"rw ke"] since Win32 requiresOPEN_EXISTINGbe used when opening a device."q"-
Stands for "Query access". This is really a no-op since you always have query access when you open a file. You can specify
"q"to document that you plan to query the file [or device, etc.]. This is especially helpful when you don't want read nor write access since something like"q"or"q ke"may be easier to understand than just""or"ke". "r"-
Stands for "Read access". Sets the
GENERIC_READbit(s) in the$uAccessthat is passed toCreateFile. This is the default access if the$svAccessparameter is missing or isundefand if not overridden by$rvhvOptions. "w"-
Stands for "Write access". Sets the
GENERIC_WRITEbit(s) in the$uAccessthat is passed toCreateFile. "k"-
Stands for "Keep if exists". If the requested file exists, then it is opened. This is the default unless
GENERIC_WRITEaccess has been requested butGENERIC_READaccess has not been requested. Contrast with"t"and"n". "t"-
Stands for "Truncate if exists". If the requested file exists, then it is truncated to zero length and then opened. This is the default if
GENERIC_WRITEaccess has been requested andGENERIC_READaccess has not been requested. Contrast with"k"and"n". "n"-
Stands for "New file only". If the requested file exists, then it is not opened and the
createFilecall fails. Contrast with"k"and"t". Can't be used with"e". "c"-
Stands for "Create if none". If the requested file does not exist, then it is created and then opened. This is the default if
GENERIC_WRITEaccess has been requested or if"t"or"n"was specified. Contrast with"e". "e"-
Stands for "Existing file only". If the requested file does not exist, then nothing is opened and the
createFilecall fails. This is the default unlessGENERIC_WRITEaccess has been requested or"t"or"n"was specified. Contrast with"c". Can't be used with"n".
The characters from
"ktn"and"ce"are combined to determine the what value for$uCreateto pass toCreateFile[unless overridden by$rvhvOptions]:"kc"-
OPEN_ALWAYS "ke"-
OPEN_EXISTING "tc"-
TRUNCATE_EXISTING "te"-
CREATE_ALWAYS "nc"-
CREATE_NEW "ne"-
Illegal.
$svSharecontrols 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.$svSharewill usually be a string containing zero or more characters from"rwd"but can also be a numeric bit mask."r"sets theFILE_SHARE_READbit which allows other processes to have read access to the file."w"sets theFILE_SHARE_WRITEbit which allows other processes to have write access to the file."d"sets theFILE_SHARE_DELETEbit which allows other processes to have delete access to the file [ignored under Windows 95].The default for
$svShareis"rw"which provides the same sharing as using regular perlopen().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
createFilewill 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 tocreateFilewill 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.$rvhvOptionsis a reference to a hash where any keys must be from the listqw( Access Create Share Attributes Flags Security Model ). The meaning of the value depends on the key name, as described below. Any option values in$rvhvOptionsoverride the settings from$svAccessand$svShareif they conflict.- Flags => $uFlags
-
$uFlagsis an unsigned value having any of theFILE_FLAG_*orFILE_ATTRIBUTE_*bits set. AnyFILE_ATTRIBUTE_*bits set via theAttributesoption are logicallyored with these bits. Defaults to0.If opening the client side of a named pipe, then you can also specify
SECURITY_SQOS_PRESENTalong with one of the otherSECURITY_*constants to specify the security quality of service to be used. - Attributes => $sAttributes
-
A string of zero or more characters from
"achorst"[seeattrLetsToBitsfor more information] which are converted toFILE_ATTRIBUTE_*bits to be set in the$uFlagsargument passed toCreateFile. - Security => $pSecurityAttributes
-
$pSecurityAttributesshould contain aSECURITY_ATTRIBUTESstructure packed into a string or[][the default]. - Model => $hModelFile
-
$hModelFileshould contain a handle opened withGENERIC_READaccess to a model file from which file attributes and extended attributes are to be copied. Or$hModelFilecan be0[the default]. - Access => $sAccess
- Access => $uAccess
-
$sAccessshould be a string of zero or more characters from"qrw"specifying the type of access desired: "query" or0, "read" orGENERIC_READ[the default], or "write" orGENERIC_WRITE.$uAccessshould be an unsigned value containing bits set to indicate the type of access desired.GENERIC_READis the default. - Create => $sCreate
- Create => $uCreate
-
$sCreateshould be a string constaing zero or one character from"ktn"and zero or one character from"ce". These stand for "keep if exists", "truncate if exists", "new file only", "create if none", and "existing file only". These are translated into a$uCreatevalue.$uCreateshould be one ofOPEN_ALWAYS,OPEN_EXISTING,TRUNCATE_EXISTING,CREATE_ALWAYS, orCREATE_NEW. -
$sShareshould be a string with zero or more characters from"rwd"that is translated into a$uSharevalue."rw"is the default.$uShareshould be an unsigned value having zero or more of the following bits set:FILE_SHARE_READ,FILE_SHARE_WRITE, andFILE_SHARE_DELETE.FILE_SHARE_READ|FILE_SHARE_WRITEis 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"; - getLogicalDrives
@roots= getLogicalDrives()-
Returns the paths to the root directories of all logical drives currently defined. This includes all types of drive lettters, such as floppies, CD-ROMs, hard disks, and network shares. A typical return value on a poorly equipped computer would be
("A:\\","C:\\"). - CloseHandle
CloseHandle( $hObject )-
Closes a Win32 native handle, such as one opened via
CreateFile. Like most routines, if it fails then it returns a false value and sets$^Eto indicate the reason for the failure. Returns a true value for success. - CopyFile
CopyFile( $sOldFileName, $sNewFileName, $bFailIfExists )-
$sOldFileNameis the path to the file to be copied.$sNewFileNameis the path to where the file should be copied. Note that you can E<NOT> just specify a path to a directory in$sNewFileNameto copy the file to that directory using the same file name.If
$bFailIfExistsis true and$sNewFileNameis the path to a file that already exists, thenCopyFilewill fail. If$bFailIfExistsis falsea, then the copy of the$sOldFileNmaefile will overwrite the$sNewFileNamefile if it already exists. - CreateFile
-
On failure,
$hObjectgets set to a false value and$^Eis set to the reason for the failure. Otherwise,$hObjectgets 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 of0].$sPathis the path to the file [or device, etc.] to be opened.$sPathcan 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,
$sPathcan start with"//?/"to allow the use of paths longer thanMAX_PATH[for UNC paths, replace the leading"//"with"//?/UNC/", as in"//?/UNC/Server/Share/Dir/File.Ext"].$sPathcan start with"//./"to indicate that the rest of the path is the name of a "DOS device." You can useQueryDosDeviceto list all current DOS devices and can add or delete them withDefineDosDevice.The most common such DOS devices include:
"//./PhysicalDrive0"-
Your entire first hard disk. Doesn't work under Windows 95. This allows you to read or write raw sectors of your hard disk and to use
DeviceIoControlto perform miscellaneous queries and operations to the hard disk. Writing raw sectors and certain other operations can seriously damage your files or the function of your computer.Locking this for exclusive access [by specifying
0for$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. "//./C:"-
Your C: partition. Doesn't work under Windows 95. This allows you to read or write raw sectors of that partition and to use
DeviceIoControlto perform miscellaneous queries and operations to the sector. Writing raw sectors and certain other operations can seriously damage your files or the function of your computer.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 E<does> prevent other processes from opening the same raw partition and E<does> prevent access to the file system on it. It even prevents the current process from accessing the file system on that partition.
"//./A:"-
The raw floppy disk. Doesn't work under Windows 95. This allows you to read or write raw sectors of the floppy disk and to use
DeviceIoControlto perform miscellaneous queries and operations to the floopy disk or drive.Locking this for exclusive access prevents all access to the floppy.
"//./PIPE/PipeName"-
A named pipe, created via
CreateNamedPipe.
$uAccessis an unsigned value with bits set indicating the type of access desired. Usually either0["query" access],GENERIC_READ,GENERIC_WRITE,GENERIC_READ|GENERIC_WRITE, orGENERIC_ALL. More specific types of access can be specified, such asFILE_APPEND_DATAorFILE_READ_EA.$uSharecontrols 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.$uShareis an unsigned value with zero or more of these bits set:FILE_SHARE_READ,FILE_SHARE_WRITE, andFILE_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
CreateFilewill 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 tocreateFilewill 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.$pSecAttrshould either be[][forNULL] or aSECURITY_ATTRIBUTESdata structure packed into a string. For example, if$pSecDesccontains aSECURITY_DESCRIPTORstructure packed into a string, perhaps via:RegGetKeySecurity( $key, 4, $pSecDesc, 1024 );then you can set
$pSecAttrvia:$pSecAttr= pack( "L P i", 12, $pSecDesc, $bInheritHandle );$uCreateis one of the following values:OPEN_ALWAYS,OPEN_EXISTING,TRUNCATE_EXISTING,CREATE_ALWAYS, andCREATE_NEW.$uFlagsis 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
$uFlagsto includeSECURITY_SQOS_PRESENTalong with one of the otherSECURITY_*constants to specify the security quality of service to be used.$hModelis0[or[], both of which meanNULL] or a Win32 native handle opened withGENERIC_READaccess 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"; - DefineDosDevice
DefineDosDevice( $uFlags, $sDosDeviceName, $sTargetPath )-
$sDosDeviceNameis the name of a DOS device for which we'd like to add or delete a definition.$uFlagsis an unsigned value with zero or more of the following bits set:DDD_RAW_TARGET_PATH-
Indicates that
$sTargetPathwill be a raw Windows NT object name. This usually means that$sTargetPathstarts with"\\Devices\\". Note that you cannot use"/"in place of"\\"in raw target path names. DDD_REMOVE_DEFINITION-
Requests that a definition be deleted. If
$sTargetPathis[][forNULL], then the most recently added definition for$sDosDeviceNameis removed. Otherwise the most recently added definition matching$sTargetPathis removed.If the last definition is removed, then the DOS device name is also deleted.
DDD_EXACT_MATCH_ON_REMOVE-
When deleting a definition, this bit causes each
$sTargetPathto be compared to the full-length definition when searching for the most recently added match. If this bit is not set, then$sTargetPathonly needs to match a prefix of the definition.
$sTargetPathis the DOS device's specific definition that you wish to add or delete. ForDDD_RAW_TARGET_PATH, these usually start with"\\Devices\\". If theDDD_RAW_TARGET_PATHbit is not set, then$sTargetPathis just an ordinary path to some file or directory, providing the functionality of the subst command. - DeleteFile
DeleteFile( $sFileName )-
Deletes the named file. Compared to Perl's
unlink,DeleteFilehas the advantage of not deleting read-only files. For E<some> versions of Perl,unlinksilently callschmodwhether it needs to or not before deleting the file so that files that you have protected by marking them as read-only are not always protected from Perl'sunlink. - DeviceIoControl
DeviceIoControl( $hDevice, $uIoControlCode, $pInBuf, $lInBuf, $opOutBuf, $lOutBuf, $olRetBytes, $pOverlapped )-
$hDeviceis a Win32 native file handle to a device [return value fromCreateFile].$uIoControlCodeis an unsigned value [aIOCTL_*constant] indicating the type query or other operation to be performed.$pInBufis[][forNULL] or a data structure packed into a string. The type of data structure depends on the$uIoControlCodevalue.$lInBufis0or the length of the structure in$pInBuf. If$pInBufis not[]and$lInBufis0, then$lInBufwill automatically be set tolength($pInBuf)for you.$opOutBufis[][forNULL] or will be set to contain a returned data structure packed into a string.$lOutBufindicates how much space to allocate in$opOutBufforDeviceIoControlto store the data structure. If$lOutBufis a number and$opOutBufalready has a buffer allocated for it that is larger than$lOutBufbytes, then this larger buffer size will be passed toDeviceIoControl. To force a specific buffer size to be passed toDeviceIoControl, prepend a"="to the front of$lOutBuf.$olRetBytesis[]or is a scalar to receive the number of bytes written to$opOutBuf. Even when$olRetBytesis[], a valid pointer to aDWORD[and notNULL] is passed toDeviceIoControl. 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 uselength($opOutBuf)instead.$pOverlappedis[]or is aOVERLAPPEDstructure packed into a string. This is only useful if$hDevicewas opened with theFILE_FLAG_OVERLAPPEDflag set. - FdGetOsFHandle
$hNativeHandle= FdGetOsFHandle( $ivFd )-
FdGetOsFHandlesimply calls_get_osfhandle(). It was renamed to better fit in with the rest the function names of this module, in particular to distinguish it fromGetOsFHandle. It takes an integer file descriptor [as fromfileno] and return the Win32 native file handle assocatiated with that file descriptor.When you call Perl's
opento set a Perl file handle [likeSTDOUT], Perl calls C'sfopento set a stdioFILE *. C'sfopencalls something like Unix'sopen, that is, Win32's_sopen, to get an integer file descriptor [where 0 is forSTDIN, 1 forSTDOUT, etc.]. Win32's_sopencallsCreateFileto set aHANDLE, a Win32 native file handle. So every Perl file handle [likeSTDOUT] has an integer file descriptor associated with it that you can get viafileno. And, under Win32, every file descriptor has a Win32 native file handle associated with it.FdGetOsFHandlelets you get access to that. - GetDriveType
$uDriveType= GetDriveType( $sRootPath )-
Takes a string giving the path to the root directory of a file system [called a "drive" because every file system is assigned a "drive letter"] and returns an unsigned value indicating the type of drive the file system is on. The return value should be one of:
DRIVE_UNKNOWN-
None of the following.
DRIVE_NO_ROOT_DIR-
A "drive" that does not have a file system. This can be a drive letter that hasn't been defined or a drive letter assigned to a partition that hasn't been formatted yet.
DRIVE_REMOVABLE-
A floppy diskette drive or other removable media drive, but not a CD-ROM drive.
DRIVE_FIXED-
An ordinary hard disk partition.
DRIVE_REMOTE-
A network share.
DRIVE_CDROM-
A CD-ROM drive.
DRIVE_RAMDISK-
A "ram disk" or memory-resident virtual file system used for high-speed access to small amounts of temporary file space.
- GetFileType
$uFileType= GetFileType( $hFile )-
Takes a Win32 native file handle and returns a
FILE_TYPE_*constant indicating the type of the file opened on that handle:FILE_TYPE_UNKNOWN-
None of the below. Often a special device.
FILE_TYPE_DISK-
An ordinary disk file.
FILE_TYPE_CHAR-
What Unix would call a "character special file", that is, a device that works on characters streams such as a printer port or a console.
FILE_TYPE_PIPE-
Either a named or anonymous pipe.
- GetLogicalDrives
$uDriveBits= GetLogicalDrives()-
Returns an unsigned value with one bit set for each drive letter currently defined. If "A:" is currently a valid drive letter, then the
1bit will be set in$uDriveBits. If "B:" is valid, then the2bit will be set. If "Z:" is valid, then the2**26[0x4000000] bit will be set. - GetLogicalDriveStrings
$olOutLength= GetLogicalDriveStrings( $lBufSize, $osBuffer )-
For each currently defined drive letter, a
'\0'-terminated string of the path to the root of its file system is constructed. All of these strings are concatenated into single larger string and an extra terminating'\0'is added. This larger string is returned in$osBuffer. Note that this includes drive letters that have been defined but that have not file system, such as drive letters assigned to unformatted partitions.$lBufSizeis the size of the buffer to allocate to store this list of strings.26*4+1is always sufficient and should usually be used.$osBufferis a scalar to be set to contain the constructed string.$olOutLengthis the number of bytes actually written to$osBufferbutlength($osBuffer)can also be used to determine this.For example, on a poorly equipped computer,
GetLogicalDriveStrings( 4*26+1, $osBuffer );might set
$osBufferto"A:\\\0C:\\\0\0"[which is the same asjoin "", 'A',':','\\','\0', 'C',':','\\','\0', '\0']. - GetOsFHandle
$hNativeHandle= GetOsFHandle( FILE )-
Takes a Perl file handle [like
STDIN] and returns the Win32 native file handle associated with it. SeeFdGetOsFHandlefor more information. - GetVolumeInformation
GetVolumeInformation( $sRootPath, $osVolName, $lVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $osFsType, $lFsType )-
Gets information about a file system volume.
$sRootPathis a string specifying the path to the root of the file system, for example,"C:/".$osVolNameis a scalar to be set to the string representing the volume name, also called the file system label.$lVolNameis the number of bytes to allocate for the$osVolNamebuffer [see "Buffer Sizes" for more information].$ouSerialNumis[][forNULL] or will be set to the numeric value of the volume's serial number.$ouMaxNameLenis[][forNULL] or will be set to the maximum length allowed for a file name or directory name within the file system.$osFsTypeis a scalar to be set to the string representing the file system type, such as"FAT"or"NTFS".$lFsTypeis the number of bytes to allocate for the$osFsTypebuffer [see "Buffer Sizes" for more information].$ouFsFlagsis[][forNULL] or will be set to an unsigned integer with bits set indicating properties of the file system:FS_CASE_IS_PRESERVED-
The file system preserves the case of file names [usually true]. That is, it doesn't change the case of file names such as forcing them to upper- or lower-case.
FS_CASE_SENSITIVE-
The file system supports the ability to not ignore the case of file names [but might ignore case the way you are using it]. That is, the file system has the ability to force you to get the letter case of a file's name exactly right to be able to open it. This is true for "NTFS" file systems, even though case in file names is usually still ignored.
FS_UNICODE_STORED_ON_DISK-
The file system perserves Unicode in file names [true for "NTFS"].
FS_PERSISTENT_ACLS-
The file system supports setting Access Control Lists on files [true for "NTFS"].
FS_FILE_COMPRESSION-
The file system supports compression on a per-file basis [true for "NTFS"].
FS_VOL_IS_COMPRESSED-
The entire file system is compressed such as via "DoubleSpace".
- IsRecognizedPartition
IsRecognizedPartition( $ivPartitionType )-
Takes a partition type and returns whether that partition type is supported under Win32.
$ivPartitonTypeis an integer value as from the operating system byte of a hard disk's DOS-compatible partition table [that is, a partition table for x86-based Win32, not, for example, one used with Windows NT for Alpha processors]. For example, thePartitionTypemember of thePARTITION_INFORMATIONstructure.Common values for
$ivPartitionTypeincludePARTITION_FAT_12==1,PARTITION_FAT_16==4,PARTITION_EXTENDED==5,PARTITION_FAT32==0xB. - IsContainerPartition
IsContainerPartition( $ivPartitionType )-
Takes a partition type and returns whether that partition is a "container" partition that is supported under Win32, that is, whether it is an "extended" partition that can contain "logical" partitions.
$ivPartitonTypeis as forIsRecognizedPartition. - MoveFile
MoveFile( $sOldName, $sNewName )-
Renames a file or directory.
$sOldNameis the name of the existing file or directory that is to be renamed.$sNewNameis the new name to give the file or directory.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, thenMoveFilewill fail. - MoveFileEx
MoveFileEx( $sOldName, $sNewName, $uFlags )-
Renames a file or directory.
$sOldNameis the name of the existing file or directory that is to be renamed.$sNewNameis the new name to give the file or directory.$uFlagsis an unsigned value with zero or more of the following bits set:MOVEFILE_REPLACE_EXISTING-
If this bit is set and a file or directory named
$sNewNamealready exists, then it will be replaced by$sOldName. If this bit is not set thenMoveFileExwill fail rather than replace an existing$sNewName. MOVEFILE_COPY_ALLOWED-
Allows files [but not directories] to be moved between file systems by copying the
$sOldNamefile data and some attributes to$sNewNameand then deleting$sOldName. If this bit is not set [or if$sOldNamedenotes a directory] and$sNewNamerefers to a different file system than$sOldName, thenMoveFileExwill fail. MOVEFILE_DELAY_UNTIL_REBOOT-
Preliminary verifications are made and then an entry is added to the Registry to cause the rename [or delete] operation to be done the next time this copy of the operating system is booted [right after any automatic file system checks have completed]. This is not supported under Windows 95.
When this bit is set,
$sNewNamecan be[][forNULL] to indicate that$sOldNameshould be deleted during the next boot rather than renamed.Setting both the
MOVEFILE_COPY_ALLOWEDandMOVEFILE_DELAY_UNTIL_REBOOTbits will causeMoveFileExto fail. MOVEFILE_WRITE_THROUGH-
Ensures that
MoveFileExwon't return until the operation has finished and been flushed to disk. This is not supported under Windows 95. Only affects file renames to another file system, forcing a buffer flush at the end of the copy operation.
- OsFHandleOpen
OsFHandleOpen( FILE, $hNativeHandle, $sMode )-
Opens a Perl file handle based on an already open Win32 native file handle [much like C's
fdopen()does with a file descriptor].FILEis 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. IfFILEis already open, it will automatically be closed before it is reopened.$hNativeHandleis an open Win32 native file handle, probably the return value fromCreateFile.$sModeis string of zero or more letters from"rwatb". These are translated into a combinationO_RDONLY["r"],O_WRONLY["w"],O_RDWR["rw"],O_APPEND["a"],O_TEXT["t"], andO_BINARY["b"] flags [see the Fcntl module] that is passed toOsFHandleOpenFd. Currently onlyO_APPENDandO_TEXThave any significance.Also, a
"r"and/or"w"in$sModeis 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 ) open( FILE, ">&=".$ivFd ) open( FILE, "+<&=".$ivFd )OsFHandleOpeneventually calls the Win32-specific C routine_open_osfhandle()or Perl's "improved" version calledwin32_open_osfhandle(). Prior to Perl5.005, C's_open_osfhandle()is called which will fail ifGetFileType($hNativeHandle)would returnFILE_TYPE_UNKNOWN. For Perl5.005 and later,OsFHandleOpencallswin32_open_osfhandle()from the Perl DLL which doesn't have this restriction. - OsFHandleOpenFd
$ivFD= OsFHandleOpenFd( $hNativeHandle, $uMode )-
Opens a file descriptor [
$ivFD] based on an already open Win32 native file handle,$hNativeHandle. This just calls the Win32-specific C routine_open_osfhandle()or Perl's "improved" version calledwin32_open_osfhandle(). Prior to Perl5.005, C's_open_osfhandle()is called which will fail ifGetFileType($hNativeHandle)would returnFILE_TYPE_UNKNOWN. For Perl5.005 and later,OsFHandleOpenFdcallswin32_open_osfhandle()from the Perl DLL which doesn't have this restriction.$uModethe logical combination of zero or moreO_*constants exported by theFcntlmodule. Currently onlyO_APPENDandO_TEXThave any significance. - QueryDosDevice
$olTargetLen= QueryDosDevice( $sDosDeviceName, $osTargetPath, $lTargetBuf )-
Looks up the definition of a given "DOS" device name, yielding the active Windows NT native device name along with any currently dormant definitions.
$sDosDeviceNameis the name of the "DOS" device whose definitions we want. For example,"C:","COM1", or"PhysicalDrive0". If$sDosDeviceNameis[][forNULL], the list of all DOS device names is returned instead.$osTargetPathwill 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 [seeGetLogicalDriveStringsfor a sample of this format].$lTargetBufis the size [in bytes] of the buffer to allocate for$osTargetPath. See "Buffers Sizes" for more information.$olTargetLenis set to the number of bytes written to$osTargetPathbut you can also uselength($osTargetPath)to determine this.For failure,
0is returned and$^Eis set to the reason for the failure. - ReadFile
ReadFile( $hFile, $opBuffer, $lBytes, $olBytesRead, $pOverlapped )-
Reads bytes from a file or file-like device.
$hFileis a Win32 native file handle open to the file or device to read from.$opBufferwill be set to a string containing the bytes read.$lBytesis the number of bytes you would like to read.$opBufferis automatically initialized to have a buffer large enough to hold that many bytes. Unlike other buffer sizes,$lBytesdoes not need to have a"="prepended to it to prevent a larger value to be passed to the underlying Win32ReadFileAPI. However, a leading"="will be silently ignored, even if Perl warnings are enabled.if
$olBytesReadis not[], it will be set to the actual number of bytes read, thoughlength($opBuffer)can also be used to determine this.$pOverlappedis[]or is aOVERLAPPEDstructure packed into a string. This is only useful if$hFilewas opened with theFILE_FLAG_OVERLAPPEDflag set. - SetErrorMode
$uOldMode= SetErrorMode( $uNewMode )-
Sets the mode controlling system error handling ∧ returns the previous mode value. Both
$uOldModeand$uNewModewill have zero or more of the following bits set:SEM_FAILCRITICALERRORS-
If set, indicates that when a critical error is encountered, the call that triggered the error fails immediately. Normally this bit is not set, which means that a critical error causes a dialogue box to appear notifying the desktop user that some application has triggered a critical error. The dialogue box allows the desktop user to decide whether the critical error is returned to the process, is ignored, or the offending operation is retried.
This affects the
CreateFileandGetVolumeInformationcalls. SEM_NOALIGNMENTFAULTEXCEPT-
If set, this causes memory access misalignment faults to be automatically fixed in a manner invisible to the process. This flag is ignored on x86-based versions of Windows NT. This flag is not supported on Windows 95.
SEM_NOGPFAULTERRORBOX-
If set, general protection faults do not generate a dialogue box but can instead be handled by the process via an exception handler. This bit should not be set by programs that don't know how to handle such faults.
SEM_NOOPENFILEERRORBOX-
If set, then when an attempt to continue reading from or writing to an already open file [usually on a removable medium like a floppy diskette] finds the file no longer available, the call will immediately fail. Normally this bit is not set, which means that instead a dialogue box will appear notifying the desktop user that some application has run into this problem. The dialogue box allows the desktop user to decide whether the failure is returned to the process, is ignored, or the offending operation is retried.
This affects the
ReadFileandWriteFilecalls.
- SetFilePointer
$uNewPos= SetFilePointer( $hFile, $ivOffset, $ioivOffsetHigh, $uFromWhere )-
The native Win32 version of
seek().SetFilePointersets the position within a file where the next read or write operation will start from.$hFileis a Win32 native file handle.$uFromWhereis eitherFILE_BEGIN,FILE_CURRENT, orFILE_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.$ivOffsetis [if$ioivOffsetHighis[]] the offset [in bytes] to the new file position from the position specified via$uFromWhere. If$ioivOffsetHighis not[], then$ivOffsetis treated is converted to an unsigned value to be used as the low-order 4 bytes of the offset.$ioivOffsetHighcan be[][forNULL] 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$ioivOfffsetHighstarts 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
SetFilePointerreturns0xFFFFFFFFto indicate failure, but if$ioivOffsetHighis not[], you would also have to check$^Eto determine whether0xFFFFFFFFindicates an error or not.Win32API::File::SetFilePointerdoes this checking for you and returns a false value if and only if the underlyingSetFilePointerfailed. For this reason,$uNewPosis 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]. - WriteFile
WriteFile( $hFile, $pBuffer, $lBytes, $ouBytesWritten, $pOverlapped )-
Write bytes to a file or file-like device.
$hFileis a Win32 native file handle open to the file or device to write to.$pBufferis a string containing the bytes to be written.$lBytesis the number of bytes you would like to write. If$pBufferis not at least$lByteslong,WriteFilecroaks. You can specify0for$lBytesto writelength($pBuffer)bytes. A leading"="on$lByteswill be silently ignored, even if Perl warnings are enabled.$ouBytesWrittenwill be set to the actual number of bytes written unless you specify it as[].$pOverlappedis[]or is aOVERLAPPEDstructure packed into a string. This is only useful if$hFilewas opened with theFILE_FLAG_OVERLAPPEDflag set.
":FuncA"-
The ASCII-specific functions. Each of these is just the same as the version without the trailing "A".
CopyFileA CreateFileA DefineDosDeviceA DeleteFileA GetDriveTypeA GetLogicalDriveStringsA GetVolumeInformationA MoveFileA MoveFileExA QueryDosDeviceA ":FuncW"-
The wide-character-specific (Unicode) functions. Each of these is just the same as the version without the trailing "W" except that strings are expected in Unicode and some lengths are measured as number of
WCHARs instead of number of bytes, as indicated below.- CopyFileW
CopyFileW( $swOldFileName, $swNewFileName, $bFailIfExists )-
$swOldFileNameand$swNewFileNameare Unicode strings. - CreateFileW
-
$swPathis Unicode. - DefineDosDeviceW
DefineDosDeviceW( $uFlags, $swDosDeviceName, $swTargetPath )-
$swDosDeviceNameand$swTargetPathare Unicode. - DeleteFileW
DeleteFileW( $swFileName )-
$swFileNameis Unicode. - GetDriveTypeW
$uDriveType= GetDriveTypeW( $swRootPath )-
$swRootPathis Unicode. - GetLogicalDriveStringsW
$olwOutLength= GetLogicalDriveStringsW( $lwBufSize, $oswBuffer )-
Unicode is stored in
$oswBuffer.$lwBufSizeand$olwOutLengthare measured as number ofWCHARs. - GetVolumeInformationW
GetVolumeInformationW( $swRootPath, $oswVolName, $lwVolName, $ouSerialNum, $ouMaxNameLen, $ouFsFlags, $oswFsType, $lwFsType )-
$swRootPathis Unicode and Unicode is written to$oswVolNameand$oswFsType.$lwVolNameand$lwFsTypeare measures as number ofWCHARs. - MoveFileW
MoveFileW( $swOldName, $swNewName )-
$swOldNameand$swNewNameare Unicode. - MoveFileExW
MoveFileExW( $swOldName, $swNewName, $uFlags )-
$swOldNameand$swNewNameare Unicode. - QueryDosDeviceW
$olwTargetLen= QueryDosDeviceW( $swDeviceName, $oswTargetPath, $lwTargetBuf )-
$swDeviceNameis Unicode and Unicode is written to$oswTargetPath.$lwTargetBufand$olwTargetLenare measured as number ofWCHARs.
":Misc"-
Miscellaneous constants. Used for the
$uCreateargument ofCreateFileor the$uFromWhereargument ofSetFilePointer. PlusINVALID_HANDLE_VALUE, which you usually won't need to check for sinceCreateFiletranslates it into a false value.CREATE_ALWAYS CREATE_NEW OPEN_ALWAYS OPEN_EXISTING TRUNCATE_EXISTING INVALID_HANDLE_VALUE FILE_BEGIN FILE_CURRENT FILE_END ":DDD_"-
Constants for the
$uFlagsargument ofDefineDosDevice.DDD_EXACT_MATCH_ON_REMOVE DDD_RAW_TARGET_PATH DDD_REMOVE_DEFINITION ":DRIVE_"-
Constants returned by
GetDriveType.DRIVE_UNKNOWN DRIVE_NO_ROOT_DIR DRIVE_REMOVABLE DRIVE_FIXED DRIVE_REMOTE DRIVE_CDROM DRIVE_RAMDISK ":FILE_"-
Specific types of access to files that can be requested via the
$uAccessargument toCreateFile.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_"-
File attribute constants. Returned by
attrLetsToBitsand used in the$uFlagsargument toCreateFile.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_"-
File option flag constants. Used in the
$uFlagsargument toCreateFile.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_"-
File sharing constants. Used in the
$uShareargument toCreateFile.FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE ":FILE_TYPE_"-
File type constants. Returned by
GetFileType.FILE_TYPE_CHAR FILE_TYPE_DISK FILE_TYPE_PIPE FILE_TYPE_UNKNOWN ":FS_"-
File system characteristics constants. Placed in the
$ouFsFlagsargument toGetVolumeInformation.FS_CASE_IS_PRESERVED FS_CASE_SENSITIVE FS_UNICODE_STORED_ON_DISK FS_PERSISTENT_ACLS FS_FILE_COMPRESSION FS_VOL_IS_COMPRESSED ":IOCTL_STORAGE_"-
I/O control operations for generic storage devices. Used in the
$uIoControlCodeargument toDeviceIoControl. IncludesIOCTL_STORAGE_CHECK_VERIFY,IOCTL_STORAGE_MEDIA_REMOVAL,IOCTL_STORAGE_EJECT_MEDIA,IOCTL_STORAGE_LOAD_MEDIA,IOCTL_STORAGE_RESERVE,IOCTL_STORAGE_RELEASE,IOCTL_STORAGE_FIND_NEW_DEVICES, andIOCTL_STORAGE_GET_MEDIA_TYPES.IOCTL_STORAGE_CHECK_VERIFY-
Verify that a device's media is accessible.
$pInBufand$opOutBufshould both be[]. IfDeviceIoControlreturns a true value, then the media is currently accessible. IOCTL_STORAGE_MEDIA_REMOVAL-
Allows the device's media to be locked or unlocked.
$opOutBufshould be[].$pInBufshould be aPREVENT_MEDIA_REMOVALdata structure, which is simply an interger containing a boolean value:$pInBuf= pack( "i", $bPreventMediaRemoval ); IOCTL_STORAGE_EJECT_MEDIA-
Requests that the device eject the media.
$pInBufand$opOutBufshould both be[]. IOCTL_STORAGE_LOAD_MEDIA-
Requests that the device load the media.
$pInBufand$opOutBufshould both be[]. IOCTL_STORAGE_RESERVE-
Requests that the device be reserved.
$pInBufand$opOutBufshould both be[]. IOCTL_STORAGE_RELEASE-
Releases a previous device reservation.
$pInBufand$opOutBufshould both be[]. IOCTL_STORAGE_FIND_NEW_DEVICES-
No documentation on this IOCTL operation was found.
IOCTL_STORAGE_GET_MEDIA_TYPES-
Requests information about the type of media supported by the device.
$pInBufshould be[].$opOutBufwill be set to contain a vector ofDISK_GEOMETRYdata structures, which can be decoded via:# 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.$ucCylsLow[$i]-
The low-order 4 bytes of the total number of cylinders.
$ivcCylsHigh[$i]-
The high-order 4 bytes of the total number of cylinders.
$uMediaType[$i]-
A code for the type of media. See the
":MEDIA_TYPE"export class. $uTracksPerCyl[$i]-
The number of tracks in each cylinder.
$uSectsPerTrack[$i]-
The number of sectors in each track.
$uBytesPerSect[$i]-
The number of bytes in each sector.
":IOCTL_DISK_"-
I/O control operations for disk devices. Used in the
$uIoControlCodeargument toDeviceIoControl. Most of these are to be used on physical drive devices like"//./PhysicalDrive0". However,IOCTL_DISK_GET_PARTITION_INFOandIOCTL_DISK_SET_PARTITION_INFOshould only be used on a single-partition device like"//./C:".Includes
IOCTL_DISK_GET_DRIVE_GEOMETRY,IOCTL_DISK_GET_PARTITION_INFO,IOCTL_DISK_SET_PARTITION_INFO,IOCTL_DISK_GET_DRIVE_LAYOUT,IOCTL_DISK_SET_DRIVE_LAYOUT,IOCTL_DISK_VERIFY,IOCTL_DISK_FORMAT_TRACKS,IOCTL_DISK_REASSIGN_BLOCKS,IOCTL_DISK_PERFORMANCE,IOCTL_DISK_IS_WRITABLE,IOCTL_DISK_LOGGING,IOCTL_DISK_FORMAT_TRACKS_EX,IOCTL_DISK_HISTOGRAM_STRUCTURE,IOCTL_DISK_HISTOGRAM_DATA,IOCTL_DISK_HISTOGRAM_RESET,IOCTL_DISK_REQUEST_STRUCTURE, andIOCTL_DISK_REQUEST_DATA.IOCTL_DISK_GET_DRIVE_GEOMETRY-
Request information about the size and geometry of the disk.
$pInBufshould be[].$opOutBufwill be set to aDISK_GEOMETRYdata structure which can be decode via:( $ucCylsLow, $ivcCylsHigh, $uMediaType, $uTracksPerCyl, $uSectsPerTrack, $uBytesPerSect )= unpack( "L l I L L L", $opOutBuf );$ucCylsLow-
The low-order 4 bytes of the total number of cylinders.
$ivcCylsHigh-
The high-order 4 bytes of the total number of cylinders.
$uMediaType-
A code for the type of media. See the
":MEDIA_TYPE"export class. $uTracksPerCyl-
The number of tracks in each cylinder.
$uSectsPerTrack-
The number of sectors in each track.
$uBytesPerSect-
The number of bytes in each sector.
IOCTL_DISK_GET_PARTITION_INFO-
Request information about the size and geometry of the partition.
$pInBufshould be[].$opOutBufwill be set to aPARTITION_INFORMATIONdata structure which can be decode via:( $uStartLow, $ivStartHigh, $ucHiddenSects, $uPartitionSeqNumber, $uPartitionType, $bActive, $bRecognized, $bToRewrite )= unpack( "L l L L C c c c", $opOutBuf );$uStartLowand$ivStartHigh-
The low-order and high-order [respectively] 4 bytes of the starting offset of the partition, measured in bytes.
$ucHiddenSects-
The number of "hidden" sectors for this partition. Actually this is the number of sectors found prior to this partiton, that is, the starting offset [as found in
$uStartLowand$ivStartHigh] divided by the number of bytes per sector. $uPartitionSeqNumber-
The sequence number of this partition. Partitions are numbered starting as
1[with "partition 0" meaning the entire disk]. Sometimes this field may be0and you'll have to infer the partition sequence number from how many partitions preceed it on the disk. $uPartitionType-
The type of partition. See the
":PARTITION_"export class for a list of known types. See alsoIsRecognizedPartitionandIsContainerPartition. $bActive-
1for the active [boot] partition,0otherwise. $bRecognized-
Whether this type of partition is support under Win32.
$bToRewrite-
Whether to update this partition information. This field is not used by
IOCTL_DISK_GET_PARTITION_INFO. ForIOCTL_DISK_SET_DRIVE_LAYOUT, you must set this field to a true value for any partitions you wish to have changed, added, or deleted.
IOCTL_DISK_SET_PARTITION_INFO-
Change the type of the partition.
$opOutBufshould be[].$pInBufshould be aSET_PARTITION_INFORMATIONdata structure which is just a single byte containing the new parition type [see the":PARTITION_"export class for a list of known types]:$pInBuf= pack( "C", $uPartitionType ); IOCTL_DISK_GET_DRIVE_LAYOUT-
Request information about the disk layout.
$pInBufshould be[].$opOutBufwill be set to containDRIVE_LAYOUT_INFORMATIONstructure including severalPARTITION_INFORMATIONstructures: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 ); }$cPartitions-
If the number of partitions on the disk.
$uDiskSignature-
Is the disk signature, a unique number assigned by Disk Administrator [WinDisk.exe] and used to identify the disk. This allows drive letters for partitions on that disk to remain constant even if the SCSI Target ID of the disk gets changed.
See
IOCTL_DISK_GET_PARTITION_INFORMATIONfor information on the remaining these fields. IOCTL_DISK_SET_DRIVE_LAYOUT-
Change the partition layout of the disk.
$pOutBufshould be[].$pInBufshould be aDISK_LAYOUT_INFORMATIONdata structure including severalPARTITION_INFORMATIONdata structures.# 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
$bToRewritewhich should be set to1. To add a partition, increment$cPartitionsand add the information for the new partition into the arrays, making sure that you insert1into @bToRewrite.See
IOCTL_DISK_GET_DRIVE_LAYOUTandIOCTL_DISK_GET_PARITITON_INFORMATIONfor descriptions of the fields. IOCTL_DISK_VERIFY-
Performs a logical format of [part of] the disk.
$opOutBufshould be[].$pInBufshould contain aVERIFY_INFORMATIONdata structure:$pInBuf= pack( "L l L", $uStartOffsetLow, $ivStartOffsetHigh, $uLength ); IOCTL_DISK_FORMAT_TRACKS-
Format a range of tracks on the disk.
$opOutBufshould be[].$pInBufshould contain aFORMAT_PARAMETERSdata structure:$pInBuf= pack( "L L L L L", $uMediaType, $uStartCyl, $uEndCyl, $uStartHead, $uEndHead );$uMediaTypeif 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.
IOCTL_DISK_REASSIGN_BLOCKS-
Reassign a list of disk blocks to the disk's spare-block pool.
$opOutBufshould be[].$pInBufshould be aREASSIGN_BLOCKSdata structure:$pInBuf= pack( "S S L*", 0, $cBlocks, @uBlockNumbers ); IOCTL_DISK_PERFORMANCE-
Request information about disk performance.
$pInBufshould be[].$opOutBufwill be set to contain aDISK_PERFORMANCEdata structure: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 ); IOCTL_DISK_IS_WRITABLE-
No documentation on this IOCTL operation was found.
IOCTL_DISK_LOGGING-
Control disk logging. Little documentation for this IOCTL operation was found. It makes use of a
DISK_LOGGINGdata structure:- DISK_LOGGING_START
-
Start logging each disk request in a buffer internal to the disk device driver of size
$uLogBufferSize:$pInBuf= pack( "C L L", 0, 0, $uLogBufferSize ); - DISK_LOGGING_STOP
-
Stop loggin each disk request:
$pInBuf= pack( "C L L", 1, 0, 0 ); - DISK_LOGGING_DUMP
-
Copy the interal log into the supplied buffer:
$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 ); - DISK_LOGGING_BINNING
-
Keep statics grouped into bins based on request sizes.
$pInBuf= pack( "C P L", 3, $pUnknown, $uUnknownSize );
IOCTL_DISK_FORMAT_TRACKS_EX-
No documentation on this IOCTL is included.
IOCTL_DISK_HISTOGRAM_STRUCTURE-
No documentation on this IOCTL is included.
IOCTL_DISK_HISTOGRAM_DATA-
No documentation on this IOCTL is included.
IOCTL_DISK_HISTOGRAM_RESET-
No documentation on this IOCTL is included.
IOCTL_DISK_REQUEST_STRUCTURE-
No documentation on this IOCTL operation was found.
IOCTL_DISK_REQUEST_DATA-
No documentation on this IOCTL operation was found.
":GENERIC_"-
Constants specifying generic access permissions that are not specific to one type of object.
GENERIC_ALL GENERIC_EXECUTE GENERIC_READ GENERIC_WRITE ":MEDIA_TYPE"-
Different classes of media that a device can support. Used in the
$uMediaTypefield of aDISK_GEOMETRYstructure.Unknown-
Format is unknown.
F5_1Pt2_512-
5.25" floppy, 1.2MB total space, 512 bytes/sector.
F3_1Pt44_512-
3.5" floppy, 1.44MB total space, 512 bytes/sector.
F3_2Pt88_512-
3.5" floppy, 2.88MB total space, 512 bytes/sector.
F3_20Pt8_512-
3.5" floppy, 20.8MB total space, 512 bytes/sector.
F3_720_512-
3.5" floppy, 720KB total space, 512 bytes/sector.
F5_360_512-
5.25" floppy, 360KB total space, 512 bytes/sector.
F5_320_512-
5.25" floppy, 320KB total space, 512 bytes/sector.
F5_320_1024-
5.25" floppy, 320KB total space, 1024 bytes/sector.
F5_180_512-
5.25" floppy, 180KB total space, 512 bytes/sector.
F5_160_512-
5.25" floppy, 160KB total space, 512 bytes/sector.
RemovableMedia-
Some type of removable media other than a floppy diskette.
FixedMedia-
A fixed hard disk.
F3_120M_512-
3.5" floppy, 120MB total space.
":MOVEFILE_"-
Constants for use in
$uFlagsarguments toMoveFileEx.MOVEFILE_COPY_ALLOWED MOVEFILE_DELAY_UNTIL_REBOOT MOVEFILE_REPLACE_EXISTING MOVEFILE_WRITE_THROUGH ":SECURITY_"-
Security quality of service values that can be used in the
$uFlagsargument toCreateFileif opening the client side of a named pipe.SECURITY_ANONYMOUS SECURITY_CONTEXT_TRACKING SECURITY_DELEGATION SECURITY_EFFECTIVE_ONLY SECURITY_IDENTIFICATION SECURITY_IMPERSONATION SECURITY_SQOS_PRESENT ":SEM_"-
Constants to be used with
SetErrorMode.SEM_FAILCRITICALERRORS SEM_NOGPFAULTERRORBOX SEM_NOALIGNMENTFAULTEXCEPT SEM_NOOPENFILEERRORBOX ":PARTITION_"-
Constants describing partition types.
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 ":ALL"-
All of the above.
BUGS
None known at this time.
AUTHOR
Tye McQueen, tye@metronet.com, http://www.metronet.com/~tye/.
SEE ALSO
The pyramids.
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 806:
Unknown E content in E<NOT>
- Around line 865:
Unknown E content in E<does>
Unknown E content in E<does>
- Around line 998:
Unknown E content in E<some>