File system v0.1.0
FILE_ATTRIBUTE_READONLY
pub const FILE_ATTRIBUTE_READONLY: uint32 = 0x00000001;
FILE_ATTRIBUTE_READONLY: the file may not be opened for writing or deleted.
The whole of Windows' permission model as this package uses it: there are ACLs underneath, but nothing in the
portable surface can express them, and this bit is what chmod maps onto.
FILE_ATTRIBUTE_DIRECTORY
pub const FILE_ATTRIBUTE_DIRECTORY: uint32 = 0x00000010;
FILE_ATTRIBUTE_DIRECTORY: the name is a directory.
FILE_ATTRIBUTE_REPARSE_POINT
pub const FILE_ATTRIBUTE_REPARSE_POINT: uint32 = 0x00000400;
FILE_ATTRIBUTE_REPARSE_POINT: the name carries a reparse point, which is what a symbolic link is.
INVALID_FILE_ATTRIBUTES
pub const INVALID_FILE_ATTRIBUTES: uint32 = 0xFFFFFFFF;
INVALID_FILE_ATTRIBUTES: what GetFileAttributesW returns when it could not answer.
SYMBOLIC_LINK_FLAG_DIRECTORY
pub const SYMBOLIC_LINK_FLAG_DIRECTORY: uint32 = 0x00000001;
SYMBOLIC_LINK_FLAG_DIRECTORY: the link's target is a directory.
Windows types its symbolic links: a link made without this flag misbehaves when its target is a directory,
which no Unix symlink ever asked anyone to know in advance.
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
pub const SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: uint32 = 0x00000002;
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: let a Developer Mode machine create the link without the
privilege older systems demand.
Harmless where the privilege is held; without Developer Mode or the privilege the call still fails with
ERROR_PRIVILEGE_NOT_HELD.
MOVEFILE_REPLACE_EXISTING
pub const MOVEFILE_REPLACE_EXISTING: uint32 = 0x00000001;
MOVEFILE_REPLACE_EXISTING: let the move overwrite an existing target.
MOVEFILE_WRITE_THROUGH
pub const MOVEFILE_WRITE_THROUGH: uint32 = 0x00000008;
MOVEFILE_WRITE_THROUGH: do not return until the move has reached the disk.
With MOVEFILE_REPLACE_EXISTING, this is what makes publishing a file under its final name durable.
FindFirstFileW
pub extern func FindFirstFileW(
fileName: *char16,
findFileData: *var opaque
) -> *var opaque
Begins a directory enumeration matching a UTF-16 pattern.
Returns InvalidHandleValue on failure. findFileData receives a WIN32_FIND_DATAW record: attributes at
offset 0 (4 bytes), three FILETIMEs from 4, the size's halves at 28 and 32, and the entry's NUL-terminated
UTF-16 name from offset 44. The record is 592 bytes.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilew
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
findFileData | *var opaque | receives the entry's record |
Returns: a search handle, or InvalidHandleValue
FindNextFileW
pub extern func FindNextFileW(
findFile: *var opaque,
findFileData: *var opaque
) -> int32
Continues a directory enumeration; fails with ERROR_NO_MORE_FILES at its end.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextfilew
Parameters
| Name | Type | Description |
|---|---|---|
findFile | *var opaque | a search handle from the matching FindFirstFile |
findFileData | *var opaque | receives the entry's record |
Returns: non-zero on success, and zero at the end of the enumeration
CreateHardLinkW
pub extern func CreateHardLinkW(
fileName: *char16,
existingFileName: *char16,
securityAttributes: *var opaque
) -> int32
Creates a hard link: a second name for an existing file's contents.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinkw
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
existingFileName | *char16 | the path that exists now |
securityAttributes | *var opaque | a security descriptor, or null for the default |
Returns: non-zero on success
CreateSymbolicLinkW
pub extern func CreateSymbolicLinkW(
symlinkFileName: *char16,
targetFileName: *char16,
flags: uint32
) -> uint8
Creates a symbolic link; returns a BOOLEAN, so only the low byte is meaningful. Creation needs SeCreateSymbolicLinkPrivilege or a Developer Mode machine with the allow-unprivileged flag; without either it fails with ERROR_PRIVILEGE_NOT_HELD.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw
Parameters
| Name | Type | Description |
|---|---|---|
symlinkFileName | *char16 | the link to create |
targetFileName | *char16 | the path the link will point at |
flags | uint32 | the call's flag bits, combined with | |
Returns: non-zero on success; creating one needs a privilege or developer mode
GetTempPathW
pub extern func GetTempPathW(
bufferLength: uint32,
buffer: *var char16
) -> uint32
Writes the path of the directory designated for temporary files. Returns the length written without the terminator, or the required length when the buffer is too small, or zero on failure. The answer always ends in a backslash. Consults TMP, then TEMP, then USERPROFILE, then the Windows directory, so it answers even where none of those are set.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppathw
Parameters
| Name | Type | Description |
|---|---|---|
bufferLength | uint32 | how many units buffer holds |
buffer | *var char16 | the bytes |
Returns: the length written including the separator, or zero on failure
DeleteFileW
pub extern func DeleteFileW(fileName: *char16) -> int32
Deletes a file, taking a UTF-16 path.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilew
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
Returns: non-zero on success
MoveFileExW
pub extern func MoveFileExW(
existingFileName: *char16,
newFileName: *char16,
flags: uint32
) -> int32
Moves or renames a file or directory, taking UTF-16 paths. With MOVEFILE_REPLACE_EXISTING this replaces the target atomically within a volume, which is how a file is published under its final name. Across volumes it copies and deletes instead, which is not atomic.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw
Parameters
| Name | Type | Description |
|---|---|---|
existingFileName | *char16 | the path that exists now |
newFileName | *char16 | the path it should have afterwards |
flags | uint32 | the call's flag bits, combined with | |
Returns: non-zero on success
CopyFileW
pub extern func CopyFileW(
existingFileName: *char16,
newFileName: *char16,
failIfExists: int32
) -> int32
Copies a file, taking UTF-16 paths.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfilew
Parameters
| Name | Type | Description |
|---|---|---|
existingFileName | *char16 | the path that exists now |
newFileName | *char16 | the path it should have afterwards |
failIfExists | int32 | non-zero to refuse rather than overwrite |
Returns: non-zero on success
CreateDirectoryW
pub extern func CreateDirectoryW(
pathName: *char16,
securityAttributes: *var opaque
) -> int32
Creates a directory, taking a UTF-16 path.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createdirectoryw
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char16 | the directory path, as a null-terminated string |
securityAttributes | *var opaque | a security descriptor, or null for the default |
Returns: non-zero on success
RemoveDirectoryW
pub extern func RemoveDirectoryW(pathName: *char16) -> int32
Removes an empty directory, taking a UTF-16 path.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectoryw
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char16 | the directory path, as a null-terminated string |
Returns: non-zero on success
GetFileAttributesW
pub extern func GetFileAttributesW(fileName: *char16) -> uint32
Reads a file's attributes, taking a UTF-16 path. Returns 0xFFFFFFFF on failure, which is INVALID_FILE_ATTRIBUTES and not an attribute value.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesw
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
Returns: the attribute bits, or INVALID_FILE_ATTRIBUTES
SetFileAttributesW
pub extern func SetFileAttributesW(
fileName: *char16,
fileAttributes: uint32
) -> int32
Sets a file's attributes, taking a UTF-16 path.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesw
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char16 | the path, as a null-terminated string |
fileAttributes | uint32 | the attribute bits to set |
Returns: non-zero on success
GetCurrentDirectoryW
pub extern func GetCurrentDirectoryW(
bufferLength: uint32,
buffer: *var char16
) -> uint32
Reads the current directory into a UTF-16 buffer. Returns the length written, or the length required when the buffer is too small — a return larger than the buffer is not a failure but a request to call again.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
Parameters
| Name | Type | Description |
|---|---|---|
bufferLength | uint32 | how many units buffer holds |
buffer | *var char16 | the bytes |
Returns: the length written, the length needed when the buffer is too small, or zero on failure
SetCurrentDirectoryW
pub extern func SetCurrentDirectoryW(pathName: *char16) -> int32
Sets the current directory, taking a UTF-16 path.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcurrentdirectory
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char16 | the directory path, as a null-terminated string |
Returns: non-zero on success
CopyFileA
pub extern func CopyFileA(
existingFileName: *char8,
newFileName: *char8,
failIfExists: bool32
) -> bool32
Copies an existing file to a new file.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-copyfilea
Parameters
| Name | Type | Description |
|---|---|---|
existingFileName | *char8 | the path that exists now |
newFileName | *char8 | the path it should have afterwards |
failIfExists | bool32 | non-zero to refuse rather than overwrite |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
CreateDirectoryA
pub extern func CreateDirectoryA(
pathName: *char8,
securityAttributes: *opaque
) -> bool32
Creates a new directory.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createdirectorya
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char8 | the directory path, as a null-terminated string |
securityAttributes | *opaque | a security descriptor, or null for the default |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
DeleteFileA
pub extern func DeleteFileA(fileName: *char8) -> bool32
Deletes an existing file.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char8 | the path, as a null-terminated string |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
FindClose
pub extern func FindClose(findFile: *opaque) -> bool32
Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW,. FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findclose
Parameters
| Name | Type | Description |
|---|---|---|
findFile | *opaque | a search handle from the matching FindFirstFile |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
FindFirstFileA
pub extern func FindFirstFileA(
fileName: *char8,
findFileData: *Win32FindDataA
) -> *opaque
Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilea
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char8 | the path, as a null-terminated string |
findFileData | *Win32FindDataA | receives the entry's record |
Returns: a search handle, or InvalidHandleValue
FindNextFileA
pub extern func FindNextFileA(
findFile: *opaque,
findFileData: *Win32FindDataA
) -> bool32
Continues a file search from a previous call to the FindFirstFile, FindFirstFileEx, or FindFirstFileTransacted functions.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextfilea
Parameters
| Name | Type | Description |
|---|---|---|
findFile | *opaque | a search handle from the matching FindFirstFile |
findFileData | *Win32FindDataA | receives the entry's record |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
GetCurrentDirectoryA
pub extern func GetCurrentDirectoryA(
bufferLength: uint32,
buffer: *char8
) -> uint32
Retrieves the current directory.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcurrentdirectory
Parameters
| Name | Type | Description |
|---|---|---|
bufferLength | uint32 | how many units buffer holds |
buffer | *char8 | the bytes |
Returns: the length written, the length needed when the buffer is too small, or zero on failure
GetFileAttributesA
pub extern func GetFileAttributesA(fileName: *char8) -> uint32
Retrieves file attributes.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesa
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char8 | the path, as a null-terminated string |
Returns: the attribute bits, or INVALID_FILE_ATTRIBUTES
MoveFileA
pub extern func MoveFileA(
existingFileName: *char8,
newFileName: *char8
) -> bool32
Moves an existing file or directory.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefilea
Parameters
| Name | Type | Description |
|---|---|---|
existingFileName | *char8 | the path that exists now |
newFileName | *char8 | the path it should have afterwards |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
RemoveDirectoryA
pub extern func RemoveDirectoryA(pathName: *char8) -> bool32
Deletes an existing empty directory.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-removedirectorya
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char8 | the directory path, as a null-terminated string |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
SetCurrentDirectoryA
pub extern func SetCurrentDirectoryA(pathName: *char8) -> bool32
Changes the current directory.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcurrentdirectory
Parameters
| Name | Type | Description |
|---|---|---|
pathName | *char8 | the directory path, as a null-terminated string |
Returns: non-zero on success, and zero on failure with the reason in GetLastError
SetFileAttributesA
pub extern func SetFileAttributesA(
fileName: *char8,
fileAttributes: uint32
) -> bool32
Sets file attributes.
See also: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesa
Parameters
| Name | Type | Description |
|---|---|---|
fileName | *char8 | the path, as a null-terminated string |
fileAttributes | uint32 | the attribute bits to set |
Returns: non-zero on success, and zero on failure with the reason in GetLastError