File system v0.1.0

Source
Deleting, copying and moving files, directories, attributes, search and links.

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.

Source

FILE_ATTRIBUTE_DIRECTORY

pub const FILE_ATTRIBUTE_DIRECTORY: uint32 = 0x00000010;

FILE_ATTRIBUTE_DIRECTORY: the name is a directory.

Source

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.

Source

INVALID_FILE_ATTRIBUTES

pub const INVALID_FILE_ATTRIBUTES: uint32 = 0xFFFFFFFF;

INVALID_FILE_ATTRIBUTES: what GetFileAttributesW returns when it could not answer.

Source

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.

Source

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.

Source

MOVEFILE_REPLACE_EXISTING

pub const MOVEFILE_REPLACE_EXISTING: uint32 = 0x00000001;

MOVEFILE_REPLACE_EXISTING: let the move overwrite an existing target.

Source

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.

Source

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

Source

Parameters

NameTypeDescription
fileName*char16the path, as a null-terminated string
findFileData*var opaquereceives 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

Source

Parameters

NameTypeDescription
findFile*var opaquea search handle from the matching FindFirstFile
findFileData*var opaquereceives the entry's record

Returns: non-zero on success, and zero at the end of the enumeration

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

Source

Parameters

NameTypeDescription
fileName*char16the path, as a null-terminated string
existingFileName*char16the path that exists now
securityAttributes*var opaquea security descriptor, or null for the default

Returns: non-zero on success

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

Source

Parameters

NameTypeDescription
symlinkFileName*char16the link to create
targetFileName*char16the path the link will point at
flagsuint32the 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

Source

Parameters

NameTypeDescription
bufferLengthuint32how many units buffer holds
buffer*var char16the 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

Source

Parameters

NameTypeDescription
fileName*char16the 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

Source

Parameters

NameTypeDescription
existingFileName*char16the path that exists now
newFileName*char16the path it should have afterwards
flagsuint32the 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

Source

Parameters

NameTypeDescription
existingFileName*char16the path that exists now
newFileName*char16the path it should have afterwards
failIfExistsint32non-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

Source

Parameters

NameTypeDescription
pathName*char16the directory path, as a null-terminated string
securityAttributes*var opaquea 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

Source

Parameters

NameTypeDescription
pathName*char16the 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

Source

Parameters

NameTypeDescription
fileName*char16the 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

Source

Parameters

NameTypeDescription
fileName*char16the path, as a null-terminated string
fileAttributesuint32the 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

Source

Parameters

NameTypeDescription
bufferLengthuint32how many units buffer holds
buffer*var char16the 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

Source

Parameters

NameTypeDescription
pathName*char16the 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

Source

Parameters

NameTypeDescription
existingFileName*char8the path that exists now
newFileName*char8the path it should have afterwards
failIfExistsbool32non-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

Source

Parameters

NameTypeDescription
pathName*char8the directory path, as a null-terminated string
securityAttributes*opaquea 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

Source

Parameters

NameTypeDescription
fileName*char8the 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

Source

Parameters

NameTypeDescription
findFile*opaquea 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

Source

Parameters

NameTypeDescription
fileName*char8the path, as a null-terminated string
findFileData*Win32FindDataAreceives 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

Source

Parameters

NameTypeDescription
findFile*opaquea search handle from the matching FindFirstFile
findFileData*Win32FindDataAreceives 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

Source

Parameters

NameTypeDescription
bufferLengthuint32how many units buffer holds
buffer*char8the 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

Source

Parameters

NameTypeDescription
fileName*char8the 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

Source

Parameters

NameTypeDescription
existingFileName*char8the path that exists now
newFileName*char8the 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

Source

Parameters

NameTypeDescription
pathName*char8the 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

Source

Parameters

NameTypeDescription
pathName*char8the 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

Source

Parameters

NameTypeDescription
fileName*char8the path, as a null-terminated string
fileAttributesuint32the attribute bits to set

Returns: non-zero on success, and zero on failure with the reason in GetLastError