Files v0.1.0
GENERIC_READ
pub const GENERIC_READ: uint32 = 0x80000000;
GENERIC_READ: the handle may read.
GENERIC_WRITE
pub const GENERIC_WRITE: uint32 = 0x40000000;
GENERIC_WRITE: the handle may write.
FILE_APPEND_DATA
pub const FILE_APPEND_DATA: uint32 = 0x00000004;
FILE_APPEND_DATA: the handle may append, and only append.
The access right that makes an append-only handle: every write lands at the end whatever the file pointer
says, which GENERIC_WRITE does not promise.
FILE_SHARE_READ
pub const FILE_SHARE_READ: uint32 = 0x00000001;
FILE_SHARE_READ: other openers may read while this handle is open.
Windows denies sharing by default, which is the opposite of every Unix. A file opened without this cannot be
opened for reading by anything else, including the same process.
FILE_SHARE_WRITE
pub const FILE_SHARE_WRITE: uint32 = 0x00000002;
FILE_SHARE_WRITE: other openers may write while this handle is open.
FILE_SHARE_DELETE
pub const FILE_SHARE_DELETE: uint32 = 0x00000004;
FILE_SHARE_DELETE: the file may be renamed or deleted while this handle is open.
FILE_ATTRIBUTE_NORMAL
pub const FILE_ATTRIBUTE_NORMAL: uint32 = 0x00000080;
FILE_ATTRIBUTE_NORMAL: no attributes beyond being an ordinary file.
FILE_FLAG_BACKUP_SEMANTICS
pub const FILE_FLAG_BACKUP_SEMANTICS: uint32 = 0x02000000;
FILE_FLAG_BACKUP_SEMANTICS: let CreateFileW open a directory.
Without it a directory cannot be opened at all, which makes this the flag every metadata query needs.
FILE_FLAG_OPEN_REPARSE_POINT
pub const FILE_FLAG_OPEN_REPARSE_POINT: uint32 = 0x00200000;
FILE_FLAG_OPEN_REPARSE_POINT: open the symbolic link itself rather than what it points at.
FILE_FLAG_DELETE_ON_CLOSE
pub const FILE_FLAG_DELETE_ON_CLOSE: uint32 = 0x04000000;
FILE_FLAG_DELETE_ON_CLOSE: remove the file when its last handle closes.
FILE_FLAG_WRITE_THROUGH
pub const FILE_FLAG_WRITE_THROUGH: uint32 = 0x80000000;
FILE_FLAG_WRITE_THROUGH: writes reach the device before the call returns.
CreateFileW
pub extern func CreateFileW(
fileName: *char16,
desiredAccess: uint32,
shareMode: uint32,
securityAttributes: *var opaque,
creationDisposition: uint32,
flagsAndAttributes: uint32,
templateFile: *var opaque
) -> *var opaque
pub extern func CreateFileW(
fileName: *char16,
desiredAccess: uint32,
shareMode: uint32,
securityAttributes: *opaque,
creationDisposition: uint32,
flagsAndAttributes: uint32,
templateFile: *opaque
) -> *opaque
Creates or opens a file or device, taking a UTF-16 path. Returns InvalidHandleValue on failure, not null. The share mode is not a default: passing zero denies every other opener, which is Windows' behaviour and not most callers' intent.
| Overload | Summary |
|---|---|
pub extern func CreateFileW(fileName: *char16, desiredAccess: uint32, shareMode: uint32, securityAttributes: *var opaque, creationDisposition: uint32, flagsAndAttributes: uint32, templateFile: *var opaque) -> *var opaque | Creates or opens a file or device, taking a UTF-16 path. |
pub extern func CreateFileW(fileName: *char16, desiredAccess: uint32, shareMode: uint32, securityAttributes: *opaque, creationDisposition: uint32, flagsAndAttributes: uint32, templateFile: *opaque) -> *opaque | Creates or opens a file or I/O device. |
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
desiredAccess | uint32 | the access rights wanted, such as GENERIC_READ |
shareMode | uint32 | what other openers may do meanwhile; zero denies them everything |
securityAttributes | *var opaque / *opaque | a security descriptor, or null for the default |
creationDisposition | uint32 | one of the CreationDisposition values |
flagsAndAttributes | uint32 | the file attributes and flags |
templateFile | *var opaque / *opaque | a template whose attributes to copy, or null |
Returns: the new handle, or InvalidHandleValue — which is not null
GetFileInformationByHandle
pub extern func GetFileInformationByHandle(
file: *var opaque,
fileInformation: *var opaque
) -> int32
Fills a BY_HANDLE_FILE_INFORMATION record for an open handle. The record is 52 bytes: attributes at offset 0 (4 bytes), the creation, last-access and last-write FILETIMEs at 4, 12 and 20 (8 bytes each), the volume serial number at 28, the size's high and low halves at 32 and 36, the link count at 40, and the file index's halves at 44 and 48.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle
Parameters
| Name | Type | Description |
|---|---|---|
file | *var opaque | an open file handle |
fileInformation | *var opaque | receives the file's information record |
Returns: non-zero on success
SetFileTime
pub extern func SetFileTime(
file: *var opaque,
creationTime: *FileTime,
lastAccessTime: *FileTime,
lastWriteTime: *FileTime
) -> int32
Sets the creation, last-access and last-write times of an open handle. Each pointer may be null to leave that time alone.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime
Parameters
| Name | Type | Description |
|---|---|---|
file | *var opaque | an open file handle |
creationTime | *FileTime | the creation time to set, or null to leave it |
lastAccessTime | *FileTime | the access time to set, or null to leave it |
lastWriteTime | *FileTime | the write time to set, or null to leave it |
Returns: non-zero on success
GetFinalPathNameByHandleW
pub extern func GetFinalPathNameByHandleW(
file: *var opaque,
filePath: *var char16,
filePathLength: uint32,
flags: uint32
) -> uint32
Writes the final, resolved path of an open handle: symbolic links followed, short names expanded, case as the filesystem stores it. Returns the length written, without the terminator, or the required length when the buffer is too small, or zero on failure. VOLUME_NAME_DOS (0) spells the answer with a drive letter where the file has one.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
Parameters
| Name | Type | Description |
|---|---|---|
file | *var opaque | an open file handle |
filePath | *var char16 | receives the resolved path |
filePathLength | uint32 | how many units filePath holds |
flags | uint32 | the call's flag bits, combined with | |
Returns: the length written, or zero on failure
FlushFileBuffers
pub extern func FlushFileBuffers(file: *var opaque) -> int32
Flushes a file handle's writes to the device. Returns zero on failure. This is what makes a write durable; FILE_FLAG_WRITE_THROUGH is the alternative that does it on every write instead.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers
Parameters
| Name | Type | Description |
|---|---|---|
file | *var opaque | an open file handle |
Returns: non-zero on success
SetEndOfFile
pub extern func SetEndOfFile(file: *var opaque) -> int32
Sets the size of a file to the handle's current position.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setendoffile
Parameters
| Name | Type | Description |
|---|---|---|
file | *var opaque | an open file handle |
Returns: non-zero on success
CloseHandle
pub extern func CloseHandle(handle: *opaque) -> bool32
Closes an open object handle.
See also: https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
Parameters
| Name | Type | Description |
|---|---|---|
handle | *opaque | the handle to act on |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
CreateFileA
pub extern func CreateFileA(
fileName: *char8,
desiredAccess: uint32,
shareMode: uint32,
securityAttributes: *opaque,
creationDisposition: uint32,
flagsAndAttributes: uint32,
templateFile: *opaque
) -> *opaque
Creates or opens a file or I/O device.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char8 | the path, as a null-terminated string |
desiredAccess | uint32 | the access rights wanted, such as GENERIC_READ |
shareMode | uint32 | what other openers may do meanwhile; zero denies them everything |
securityAttributes | *opaque | a security descriptor, or null for the default |
creationDisposition | uint32 | one of the CreationDisposition values |
flagsAndAttributes | uint32 | the file attributes and flags |
templateFile | *opaque | a template whose attributes to copy, or null |
Returns: the new handle, or InvalidHandleValue — which is not null
GetFileSizeEx
pub extern func GetFileSizeEx(
file: *opaque,
size: *int64
) -> bool32
Retrieves the size of the specified file.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfilesizeex
Parameters
| Name | Type | Description |
|---|---|---|
file | *opaque | an open file handle |
size | *int64 | a size in bytes |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
ReadFile
pub extern func ReadFile(
file: *opaque,
buffer: *opaque,
numberOfBytesToRead: uint32,
numberOfBytesRead: *uint32,
overlapped: *opaque
) -> bool32
Reads data from the specified file or input/output (I/O) device.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile
Parameters
| Name | Type | Description |
|---|---|---|
file | *opaque | an open file handle |
buffer | *opaque | the bytes |
numberOfBytesToRead | uint32 | how many bytes to ask for |
numberOfBytesRead | *uint32 | receives how many were read |
overlapped | *opaque | an overlapped record, or null for a synchronous call |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
SetFilePointerEx
pub extern func SetFilePointerEx(
file: *opaque,
distanceToMov: int64,
newFilePointer: *int64,
moveMethod: uint32
) -> bool32
Moves the file pointer of the specified file.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfilepointerex
Parameters
| Name | Type | Description |
|---|---|---|
file | *opaque | an open file handle |
distanceToMov | int64 | how far to move, interpreted by moveMethod |
newFilePointer | *int64 | receives the resulting offset, or null |
moveMethod | uint32 | where the move is measured from |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
WriteFile
pub extern func WriteFile(
file: *opaque,
buffer: *opaque,
bytesToWrite: uint32,
bytesWritten: *uint32,
overlapped: *opaque
) -> bool32
Writes data to the specified file or input/output (I/O) device.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile
Parameters
| Name | Type | Description |
|---|---|---|
file | *opaque | an open file handle |
buffer | *opaque | the bytes |
bytesToWrite | uint32 | how many bytes to offer |
bytesWritten | *uint32 | receives how many were written |
overlapped | *opaque | an overlapped record, or null for a synchronous call |
Returns: non-zero on success, and zero on failure with the reason in GetLastError