Commit Graph

98 Commits

Author SHA1 Message Date
Jakub Konka 901bf0a2e2 Convert prefix from u8 to u16 programmatically 2020-08-10 20:44:22 +02:00
Jakub Konka 73b9f65746 Validate DOS path before returning
And some other minor refactors which address more review comments.
2020-08-10 16:39:02 +02:00
Jakub Konka cd8e6b66d0 Address some review comments 2020-08-09 10:47:52 +02:00
Jakub Konka 310aa87198 Fix alignment issue 2020-08-07 23:21:06 +02:00
Jakub Konka bdda8fa7a8 Redo GetFinalPathNameByHandle using DeviceIoControl
This commit reimagines `std.os.windows.GetFinalPathNameByHandle`
using `DeviceIoControl` to query the OS mount manager for the DOS
(symlink) paths for the given NT volume name. In particular,
it uses `IOCTL_MOUNTMGR_QUERY_POINTS` ioctl opcode to query the
manager for the available moount points.
2020-08-07 11:33:05 +02:00
Jakub Konka e8abfef2aa Add docs 2020-08-06 23:56:37 +02:00
Jakub Konka 2628a8846e Use NtQueryInformationFile unless unavailable
Favour newer API which uses `NtQueryInformationFile` with class flags
`FileNormalizedNameInformation` and `FileVolumeNameInformation`
instead of lower-level `NtQueryObject`. `NtQueryObject` is still
used as a fallback in case the former are unavailable.
2020-08-06 23:56:37 +02:00
Jakub Konka 747d46f22c Initial draft of GetFinalPathNameByHandle
This commit proposes an initial draft of `GetPathNameByHandle` function
which wraps NT syscalls and strives to emulate (currently only
partially) the `kernel32.GetFinalPathNameByHandleW` function.
2020-08-06 23:56:37 +02:00
Andrew Kelley d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
Jakub Konka 4d9eff4bdb Add prelim openW and openatW
Added POSIX functions targeting Windows pass `open` and `openat`
smoke tests.
2020-07-31 16:41:25 +02:00
Jakub Konka 390194431e Use NtCreateFile directly in ReadLink
This shaves off one syscall (we use one instead of two if we were to
use `windows.OpenFile` wrapper). Clean up flag generation in `OpenFile`.
Hopefully, we're in a much better place to *almost* support `openW`
and `openatW`.
2020-07-31 16:32:21 +02:00
Jakub Konka 8981b18fee Move delete file logic into windows.DeleteFile fn
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
2020-07-31 16:31:51 +02:00
Jakub Konka 66bbe4ec4c Refactor internal Win routines to reuse OpenFile
This covers mainly `ReadLink` and `CreateSymolicLink` functions.
2020-07-31 16:31:44 +02:00
Jakub Konka a89d5cfc3e Remove CreateDirectoryW and CreateFileW calls
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
2020-07-31 16:31:23 +02:00
Jakub Konka 547e520359 Split DeviceIoControl path into two fn call paths
As discussed in the previous commit, it would be better to avoid
function pointers to syscalls and explicitly split the control
path into two function calls instead. This commit addresses that
for `std.os.windows.DeviceIoControl`.
2020-07-29 14:17:49 +02:00
Jakub Konka 4fdfaf69c8 Add Zig wrapper for kernel32.DeviceIoControl
This commit adds a Zig wrapper for `kernel32.DeviceIoControl` which
applies ReactOS logic for deciding whether to use
`ntdll.NtDeviceIoControlFile` or `ntdll.NtFsControlFile` based on the
value of passed `IO_CONTROL_CODE`. The decision logic is based on the
logic found in ReactOS found in the following [link].

Thanks to Daurnimator for finding this bit in ReactOS!

[link]: https://doxygen.reactos.org/d3/d74/deviceio_8c.html
2020-07-29 01:19:10 +00:00
Jakub Konka f0ed2ed67f Replace DeviceIoControl with FsControlFile
This commit replaces `windows.DeviceIoControl` with
`windows.FsControlFile` which is a wrapper around the NT-based
syscall `ntdll.NtFsControlFile`.
2020-07-27 19:45:23 +00:00
Jakub Konka 3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka 4887350bf4 Finish drafting CreateSymolicLink using NT calls 2020-07-22 08:51:23 +02:00
Jakub Konka 99f0e64fa0 Draft out dir symlinks branch 2020-07-22 08:51:23 +02:00
Jakub Konka c53bcd027f Start drafting CreateSymbolicLink using ntdll syscalls 2020-07-22 08:51:23 +02:00
Jakub Konka e0b77a6b77 Ensure Dir.deleteTree does not dereference symlinks
Otherwise, the behaviour can lead to unexpected results, resulting
in removing an entire tree that's not necessarily under the root.
Furthermore, this change is needed if are to properly handle dir
symlinks on Windows. Without explicitly requiring that a directory
or file is opened with `FILE_OPEN_REPARSE_POINT`, Windows automatically
dereferences all symlinks along the way. This commit adds another
option to `OpenDirOptions`, namely `.no_follow`, which defaults to
`false` and can be used to specifically open a directory symlink on
Windows or call `openat` with `O_NOFOLLOW` flag in POSIX.
2020-07-22 08:51:22 +02:00
Jakub Konka 3c8ceb674e Fix Windows build 2020-07-22 08:51:22 +02:00
Jakub Konka fc7d87fef1 Move symlink to fs.symlinkAbsolute with SymlinkFlags
This way `std.fs.symlinkAbsolute` becomes cross-platform and we can
legally include `SymlinkFlags` as an argument that's only used on
Windows. Also, now `std.os.symlink` generates a compile error on
Windows with a message to instead use `std.os.windows.CreateSymbolicLink`.
Finally, this PR also reshuffles the tests between `std.os.test` and
`std.fs.test`.
2020-07-22 08:51:22 +02:00
Jakub Konka 22362568cf Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka 3ab5e6b1a9 Ensure we use Win32 prefix in Win32 calls 2020-07-22 08:51:22 +02:00
Jakub Konka 99e3e29e2e Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka ae8abedbed Use NtCreateFile to get handle to reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka 9b00dc941b Use windows.CreateFileW to open the reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka 49b5815364 Add windows.ReadLink similar to OpenFile but for reparse points only 2020-07-22 08:51:22 +02:00
Jakub Konka 92d11fd4e9 Debug readlinkW using OpenFile 2020-07-22 08:51:22 +02:00
Jakub Konka 791795a63a Finish symlink implementation on Windows 2020-07-22 08:51:22 +02:00
Nameless 56220449ab Add errors to windows.WSAStartup and WSACleanup 2020-06-21 00:13:06 -04:00
Ryan Liptak f839d34baa std.os.windows.OpenFile: Handle FILE_IS_A_DIRECTORY status
Fixes #5533
2020-06-04 22:53:23 -04:00
Ryan Liptak 95a5f6bf2d Windows: Handle ERROR_DIRECTORY in std.fs.deleteDirAbsolute when called on a file path
ERROR_DIRECTORY (267) is returned from kernel32.RemoveDirectoryW if the path is not a directory. Note also that os.DirectDirError already includes NotDir

Before: error.Unexpected: GetLastError(267): The directory name is invalid.
After: error: NotDir
2020-06-04 22:52:53 -04:00
Alexandros Naskos 215a0d61ab Fix evented builds on windows with runtime safety on 2020-06-01 14:22:45 -04:00
Andrew Kelley 3052fd84c8 fix regression in std.os.windows.fromSysTime 2020-05-25 00:37:47 -04:00
Andrew Kelley 53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
Andrew Kelley 43f7856bac fix regressions in windows std lib tests 2020-05-02 01:25:22 -04:00
Andrew Kelley 2272a07ca0 std.event.Loop: promote the fs thread to be available for all OS's 2020-05-02 00:41:19 -04:00
Andrew Kelley 45bce27b8f cleanup and fixes. behavior tests passing with evented I/O 2020-05-01 23:17:28 -04:00
Andrew Kelley 988031c07c Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into FireFox317-windows-evented-io 2020-05-01 19:02:16 -04:00
Andrew Kelley 1e04e85200 std: support / in Windows paths 2020-04-27 13:39:06 -04:00
Jakub 1e23a3cd91 Added gdi32.zig and More user32 definitions 2020-04-14 16:20:48 -04:00
daurnimator 8e9e126d41 std: add some basic windows user32 definitions 2020-04-12 02:28:52 -04:00
LeRoyce Pearson 317f06dc77 Add lock_nonblocking flag for creating or opening files
Also, make windows share delete access. Rationale: this is how it works
on Unix systems, mostly because locks are (usually) advisory on Unix.
2020-04-07 18:00:12 -06:00
LeRoyce Pearson 117d15ed7a Fix file locking on windows
The share_access bitfield was being ORed with what was supposed to be
parts of the default value, meaning that the share_access would be
more permissive than expected.
2020-04-07 16:49:37 -06:00
LeRoyce Pearson 35c462caf0 Merge branch 'master' into feature-file-locks 2020-04-02 21:46:48 -06:00
Andrew Kelley 9e7ae06249 std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
daurnimator 8cad453495 std: fix compile error since WinsockError was changed 2020-03-30 11:02:06 -04:00