Commit Graph

215 Commits (83b0e52079298244912f2d2f28b256457c8dc3a5)

Author SHA1 Message Date
Andrew Kelley b1c7334355
Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04:00
Andrew Kelley ae2c88754d std: signalfd: fix the types of things; add test 2020-08-17 16:19:57 -07:00
Luna 2deb07a001 rename signalfd4 to signalfd 2020-08-17 16:05:35 -07:00
Jakub Konka 3e2e6baee5 Add std.os.getFdPath and std.fs.Dir.realpath
`std.os.getFdPath` is very platform-specific and can be used to query
the OS for a canonical path to a file handle. Currently supported hosts
are Linux, macOS and Windows.

`std.fs.Dir.realpath` (and null-terminated, plus WTF16 versions) are
similar to `std.os.realpath`, however, they resolve a path wrt to this
`Dir` instance.

If the input pathname argument turns out to be an absolute path, this
function reverts to calling `realpath` on that pathname completely
ignoring this `Dir`.
2020-08-13 07:08:39 +02:00
Maciej Walczak 6febe7e977
copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04: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 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
Jakub Konka 4b0ab0c186
Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-02 19:36:49 +02: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 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
luna a6626802f9
Add signalfd support (#5322)
* add signalfd_siginfo to linux bits

* Cast sigaddset's shift value to u5

* linux: add signalfd4

* os: add signalfd
2020-07-22 17:26:27 -04:00
Jakub Konka aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka 3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka 2c9c13f624 Add various build fixes
Fix WASI build, fix atomicSymlink by using `cwd().symLink`, add
`Dir.symLink` on supported targets.
2020-07-22 08:51:22 +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 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 cc9c5c5b0e Handle relative/absolute symlinks; add more tests 2020-07-22 08:51:22 +02:00
Jakub Konka 30f1176a54 Add SymlinkFlags needed to create symlinks to dirs on Win 2020-07-22 08:51:22 +02:00
Jakub Konka 99e3e29e2e Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka c47cb8d09f Fix unlinkatW to allow file symlink deletion on Windows 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 d17c9b3591 Fix incorrect byte format of REPARSE_DATA_BUFFER struct 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
Jakub Konka 515c663cd6 Add readlink smoke test 2020-07-22 08:51:22 +02:00
Jakub Konka cc83d92b0b Start drafting out os.readlink on Windows 2020-07-22 08:51:22 +02:00
Vexu e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
luna e2cfc65909
Merge branch 'master' into ebadf-error 2020-07-02 00:49:56 -03:00
Jakub Konka 8306826d53 Map ENOTCAPABLE into error.AccessDenied instead of error.NotCapable
This is direct result of review comments left by andrewrk and
daurnimator. It makes sense to map `ENOTCAPABLE` into a more generic
`error.AccessDenied`.
2020-06-30 18:21:38 +02:00
Jakub Konka 5bc99dd7e8 Fix more compilation errors 2020-06-29 21:42:11 +02:00
Luna 3f5b2d6c51 std.os: map EBADF to errors on WASI read/write syscalls 2020-06-29 16:23:58 -03:00
Jakub Konka b96882c57a Fix compilation errors 2020-06-29 18:09:22 +02:00
Jakub Konka bf8bf528c6 Handle ENOTCAPABLE in WASI
This commit adds `error.NotCapable` enum value and makes sure that
every applicable WASI syscall that can return `ENOTCAPABLE` errno
remaps it to `error.NotCapable.
2020-06-29 17:10:01 +02:00
Luna f47c6d3c6b std.os: make EBADF return error for read and write 2020-06-28 18:40:43 -03:00
Jakub Konka d40e367b73 Reformat using if-else where appropriate 2020-06-24 21:00:21 +02:00
Jakub Konka be78b7b648 Implement fstatat targeting WASI
Also, add more informative `@compileError` in a few `std.os` functions
that would otherwise yield a cryptic compile error when targeting
WASI. Finally, enhance docs in a few places and add test case for
`fstatat`.
2020-06-24 21:00:21 +02:00
Jakub Konka c950f0c6c3 Enhance std.os.readlinkat coverage
Adds Windows stub (still needs to be implemented on Windows),
adds WASI implementation, adds unit test testing basic chain of
ops: create file -> symlink -> readlink.
2020-06-22 09:40:06 +02:00
Jakub Konka 64078ca924 Enhance std.os.symlinkat coverage
Fixes `std.os.symlinkat` compile errors, adds Windows stub (still
needs to be implemented), adds WASI implementation.
2020-06-22 09:14:51 +02:00
Ryan Liptak f7b6957fb4 Windows: Fix std.fs.Dir.deleteDir() deleting files
Would previously delete files, now correctly returns error.NotDir. Fixes #5536
2020-06-04 22:51:58 -04:00
Andrew Kelley 7fd937fef4 cleanups
* improve docs
 * add TODO comments for things that don't have open issues
 * remove redundant namespacing of struct fields
 * guard against ioctl returning EINTR
 * remove the general std.os.ioctl function in favor of the specific
   ioctl_SIOCGIFINDEX function. This allows us to have a more precise
   error set, and more type-safe API.
2020-06-02 15:28:46 -04:00
Luna 6623efd7d4 Change ioctl's request type to i32 2020-06-02 14:56:19 -04:00
Luna 7c71054286 Replace syscall3 to os.ioctl 2020-06-02 14:56:19 -04:00
Luna c8468bed42 Add std.os.ioctl 2020-06-02 14:56:19 -04:00
Andrew Kelley c6764fd254
Merge pull request #5475 from marler8997/windowsDns
support name resolution on windows
2020-06-01 15:33:05 -04:00