| ... | ... | @@ -300,6 +300,10 @@ pub const ReadError = error{ |
| 300 | 300 | /// This error occurs when no global event loop is configured, |
| 301 | 301 | /// and reading from the file descriptor would block. |
| 302 | 302 | WouldBlock, |
| 303 | |
| 304 | /// In WASI, this error occurs when the file descriptor does |
| 305 | /// not hold the required rights to read from it. |
| 306 | AccessDenied, |
| 303 | 307 | } || UnexpectedError; |
| 304 | 308 | |
| 305 | 309 | /// Returns the number of bytes that were read, which can be less than |
| ... | ... | @@ -335,6 +339,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 335 | 339 | wasi.ENOMEM => return error.SystemResources, |
| 336 | 340 | wasi.ECONNRESET => return error.ConnectionResetByPeer, |
| 337 | 341 | wasi.ETIMEDOUT => return error.ConnectionTimedOut, |
| 342 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 338 | 343 | else => |err| return unexpectedErrno(err), |
| 339 | 344 | } |
| 340 | 345 | } |
| ... | ... | @@ -402,6 +407,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { |
| 402 | 407 | wasi.EISDIR => return error.IsDir, |
| 403 | 408 | wasi.ENOBUFS => return error.SystemResources, |
| 404 | 409 | wasi.ENOMEM => return error.SystemResources, |
| 410 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 405 | 411 | else => |err| return unexpectedErrno(err), |
| 406 | 412 | } |
| 407 | 413 | } |
| ... | ... | @@ -466,6 +472,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { |
| 466 | 472 | wasi.ENXIO => return error.Unseekable, |
| 467 | 473 | wasi.ESPIPE => return error.Unseekable, |
| 468 | 474 | wasi.EOVERFLOW => return error.Unseekable, |
| 475 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 469 | 476 | else => |err| return unexpectedErrno(err), |
| 470 | 477 | } |
| 471 | 478 | } |
| ... | ... | @@ -500,8 +507,11 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { |
| 500 | 507 | pub const TruncateError = error{ |
| 501 | 508 | FileTooBig, |
| 502 | 509 | InputOutput, |
| 503 | | CannotTruncate, |
| 504 | 510 | FileBusy, |
| 511 | |
| 512 | /// In WASI, this error occurs when the file descriptor does |
| 513 | /// not hold the required rights to call `ftruncate` on it. |
| 514 | AccessDenied, |
| 505 | 515 | } || UnexpectedError; |
| 506 | 516 | |
| 507 | 517 | pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { |
| ... | ... | @@ -522,7 +532,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { |
| 522 | 532 | switch (rc) { |
| 523 | 533 | .SUCCESS => return, |
| 524 | 534 | .INVALID_HANDLE => unreachable, // Handle not open for writing |
| 525 | | .ACCESS_DENIED => return error.CannotTruncate, |
| 535 | .ACCESS_DENIED => return error.AccessDenied, |
| 526 | 536 | else => return windows.unexpectedStatus(rc), |
| 527 | 537 | } |
| 528 | 538 | } |
| ... | ... | @@ -532,10 +542,11 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { |
| 532 | 542 | wasi.EINTR => unreachable, |
| 533 | 543 | wasi.EFBIG => return error.FileTooBig, |
| 534 | 544 | wasi.EIO => return error.InputOutput, |
| 535 | | wasi.EPERM => return error.CannotTruncate, |
| 545 | wasi.EPERM => return error.AccessDenied, |
| 536 | 546 | wasi.ETXTBSY => return error.FileBusy, |
| 537 | 547 | wasi.EBADF => unreachable, // Handle not open for writing |
| 538 | 548 | wasi.EINVAL => unreachable, // Handle not open for writing |
| 549 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 539 | 550 | else => |err| return unexpectedErrno(err), |
| 540 | 551 | } |
| 541 | 552 | } |
| ... | ... | @@ -554,7 +565,7 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { |
| 554 | 565 | EINTR => continue, |
| 555 | 566 | EFBIG => return error.FileTooBig, |
| 556 | 567 | EIO => return error.InputOutput, |
| 557 | | EPERM => return error.CannotTruncate, |
| 568 | EPERM => return error.AccessDenied, |
| 558 | 569 | ETXTBSY => return error.FileBusy, |
| 559 | 570 | EBADF => unreachable, // Handle not open for writing |
| 560 | 571 | EINVAL => unreachable, // Handle not open for writing |
| ... | ... | @@ -604,6 +615,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { |
| 604 | 615 | wasi.ENXIO => return error.Unseekable, |
| 605 | 616 | wasi.ESPIPE => return error.Unseekable, |
| 606 | 617 | wasi.EOVERFLOW => return error.Unseekable, |
| 618 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 607 | 619 | else => |err| return unexpectedErrno(err), |
| 608 | 620 | } |
| 609 | 621 | } |
| ... | ... | @@ -641,6 +653,9 @@ pub const WriteError = error{ |
| 641 | 653 | FileTooBig, |
| 642 | 654 | InputOutput, |
| 643 | 655 | NoSpaceLeft, |
| 656 | |
| 657 | /// In WASI, this error may occur when the file descriptor does |
| 658 | /// not hold the required rights to write to it. |
| 644 | 659 | AccessDenied, |
| 645 | 660 | BrokenPipe, |
| 646 | 661 | SystemResources, |
| ... | ... | @@ -697,6 +712,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { |
| 697 | 712 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 698 | 713 | wasi.EPERM => return error.AccessDenied, |
| 699 | 714 | wasi.EPIPE => return error.BrokenPipe, |
| 715 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 700 | 716 | else => |err| return unexpectedErrno(err), |
| 701 | 717 | } |
| 702 | 718 | } |
| ... | ... | @@ -774,6 +790,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { |
| 774 | 790 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 775 | 791 | wasi.EPERM => return error.AccessDenied, |
| 776 | 792 | wasi.EPIPE => return error.BrokenPipe, |
| 793 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 777 | 794 | else => |err| return unexpectedErrno(err), |
| 778 | 795 | } |
| 779 | 796 | } |
| ... | ... | @@ -856,6 +873,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { |
| 856 | 873 | wasi.ENXIO => return error.Unseekable, |
| 857 | 874 | wasi.ESPIPE => return error.Unseekable, |
| 858 | 875 | wasi.EOVERFLOW => return error.Unseekable, |
| 876 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 859 | 877 | else => |err| return unexpectedErrno(err), |
| 860 | 878 | } |
| 861 | 879 | } |
| ... | ... | @@ -949,6 +967,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz |
| 949 | 967 | wasi.ENXIO => return error.Unseekable, |
| 950 | 968 | wasi.ESPIPE => return error.Unseekable, |
| 951 | 969 | wasi.EOVERFLOW => return error.Unseekable, |
| 970 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 952 | 971 | else => |err| return unexpectedErrno(err), |
| 953 | 972 | } |
| 954 | 973 | } |
| ... | ... | @@ -984,6 +1003,8 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz |
| 984 | 1003 | } |
| 985 | 1004 | |
| 986 | 1005 | pub const OpenError = error{ |
| 1006 | /// In WASI, this error may occur when the file descriptor does |
| 1007 | /// not hold the required rights to open a new resource relative to it. |
| 987 | 1008 | AccessDenied, |
| 988 | 1009 | SymLinkLoop, |
| 989 | 1010 | ProcessFdQuotaExceeded, |
| ... | ... | @@ -1113,6 +1134,7 @@ pub fn openatWasi(dir_fd: fd_t, file_path: []const u8, oflags: oflags_t, fdflags |
| 1113 | 1134 | wasi.EPERM => return error.AccessDenied, |
| 1114 | 1135 | wasi.EEXIST => return error.PathAlreadyExists, |
| 1115 | 1136 | wasi.EBUSY => return error.DeviceBusy, |
| 1137 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1116 | 1138 | else => |err| return unexpectedErrno(err), |
| 1117 | 1139 | } |
| 1118 | 1140 | } |
| ... | ... | @@ -1499,6 +1521,8 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1499 | 1521 | } |
| 1500 | 1522 | |
| 1501 | 1523 | pub const SymLinkError = error{ |
| 1524 | /// In WASI, this error may occur when the file descriptor does |
| 1525 | /// not hold the required rights to create a new symbolic link relative to it. |
| 1502 | 1526 | AccessDenied, |
| 1503 | 1527 | DiskQuota, |
| 1504 | 1528 | PathAlreadyExists, |
| ... | ... | @@ -1604,13 +1628,14 @@ pub fn symlinkatWasi(target_path: []const u8, newdirfd: fd_t, sym_link_path: []c |
| 1604 | 1628 | wasi.ENOMEM => return error.SystemResources, |
| 1605 | 1629 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 1606 | 1630 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 1631 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1607 | 1632 | else => |err| return unexpectedErrno(err), |
| 1608 | 1633 | } |
| 1609 | 1634 | } |
| 1610 | 1635 | |
| 1611 | 1636 | /// Windows-only. The same as `symlinkat` except the paths are null-terminated, WTF-16 encoded. |
| 1612 | 1637 | /// See also `symlinkat`. |
| 1613 | | pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymlinkError!void { |
| 1638 | pub fn symlinkatW(target_path: [*:0]const u16, newdirfd: fd_t, sym_link_path: [*:0]const u16) SymLinkError!void { |
| 1614 | 1639 | @compileError("TODO implement on Windows"); |
| 1615 | 1640 | } |
| 1616 | 1641 | |
| ... | ... | @@ -1644,6 +1669,9 @@ pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*: |
| 1644 | 1669 | |
| 1645 | 1670 | pub const UnlinkError = error{ |
| 1646 | 1671 | FileNotFound, |
| 1672 | |
| 1673 | /// In WASI, this error may occur when the file descriptor does |
| 1674 | /// not hold the required rights to unlink a resource by path relative to it. |
| 1647 | 1675 | AccessDenied, |
| 1648 | 1676 | FileBusy, |
| 1649 | 1677 | FileSystem, |
| ... | ... | @@ -1747,6 +1775,7 @@ pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatErro |
| 1747 | 1775 | wasi.ENOMEM => return error.SystemResources, |
| 1748 | 1776 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 1749 | 1777 | wasi.ENOTEMPTY => return error.DirNotEmpty, |
| 1778 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1750 | 1779 | |
| 1751 | 1780 | wasi.EINVAL => unreachable, // invalid flags, or pathname has . as last component |
| 1752 | 1781 | wasi.EBADF => unreachable, // always a race condition |
| ... | ... | @@ -1849,6 +1878,8 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr |
| 1849 | 1878 | } |
| 1850 | 1879 | |
| 1851 | 1880 | const RenameError = error{ |
| 1881 | /// In WASI, this error may occur when the file descriptor does |
| 1882 | /// not hold the required rights to rename a resource by path relative to it. |
| 1852 | 1883 | AccessDenied, |
| 1853 | 1884 | FileBusy, |
| 1854 | 1885 | DiskQuota, |
| ... | ... | @@ -1968,6 +1999,7 @@ pub fn renameatWasi(old_dir_fd: fd_t, old_path: []const u8, new_dir_fd: fd_t, ne |
| 1968 | 1999 | wasi.ENOTEMPTY => return error.PathAlreadyExists, |
| 1969 | 2000 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 1970 | 2001 | wasi.EXDEV => return error.RenameAcrossMountPoints, |
| 2002 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 1971 | 2003 | else => |err| return unexpectedErrno(err), |
| 1972 | 2004 | } |
| 1973 | 2005 | } |
| ... | ... | @@ -2066,23 +2098,6 @@ pub fn renameatW( |
| 2066 | 2098 | } |
| 2067 | 2099 | } |
| 2068 | 2100 | |
| 2069 | | pub const MakeDirError = error{ |
| 2070 | | AccessDenied, |
| 2071 | | DiskQuota, |
| 2072 | | PathAlreadyExists, |
| 2073 | | SymLinkLoop, |
| 2074 | | LinkQuotaExceeded, |
| 2075 | | NameTooLong, |
| 2076 | | FileNotFound, |
| 2077 | | SystemResources, |
| 2078 | | NoSpaceLeft, |
| 2079 | | NotDir, |
| 2080 | | ReadOnlyFileSystem, |
| 2081 | | InvalidUtf8, |
| 2082 | | BadPathName, |
| 2083 | | NoDevice, |
| 2084 | | } || UnexpectedError; |
| 2085 | | |
| 2086 | 2101 | pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void { |
| 2087 | 2102 | if (builtin.os.tag == .windows) { |
| 2088 | 2103 | const sub_dir_path_w = try windows.sliceToPrefixedFileW(sub_dir_path); |
| ... | ... | @@ -2114,6 +2129,7 @@ pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirErr |
| 2114 | 2129 | wasi.ENOSPC => return error.NoSpaceLeft, |
| 2115 | 2130 | wasi.ENOTDIR => return error.NotDir, |
| 2116 | 2131 | wasi.EROFS => return error.ReadOnlyFileSystem, |
| 2132 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 2117 | 2133 | else => |err| return unexpectedErrno(err), |
| 2118 | 2134 | } |
| 2119 | 2135 | } |
| ... | ... | @@ -2148,6 +2164,25 @@ pub fn mkdiratW(dir_fd: fd_t, sub_path_w: [*:0]const u16, mode: u32) MakeDirErro |
| 2148 | 2164 | windows.CloseHandle(sub_dir_handle); |
| 2149 | 2165 | } |
| 2150 | 2166 | |
| 2167 | pub const MakeDirError = error{ |
| 2168 | /// In WASI, this error may occur when the file descriptor does |
| 2169 | /// not hold the required rights to create a new directory relative to it. |
| 2170 | AccessDenied, |
| 2171 | DiskQuota, |
| 2172 | PathAlreadyExists, |
| 2173 | SymLinkLoop, |
| 2174 | LinkQuotaExceeded, |
| 2175 | NameTooLong, |
| 2176 | FileNotFound, |
| 2177 | SystemResources, |
| 2178 | NoSpaceLeft, |
| 2179 | NotDir, |
| 2180 | ReadOnlyFileSystem, |
| 2181 | InvalidUtf8, |
| 2182 | BadPathName, |
| 2183 | NoDevice, |
| 2184 | } || UnexpectedError; |
| 2185 | |
| 2151 | 2186 | /// Create a directory. |
| 2152 | 2187 | /// `mode` is ignored on Windows. |
| 2153 | 2188 | pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void { |
| ... | ... | @@ -2311,6 +2346,8 @@ pub fn fchdir(dirfd: fd_t) FchdirError!void { |
| 2311 | 2346 | } |
| 2312 | 2347 | |
| 2313 | 2348 | pub const ReadLinkError = error{ |
| 2349 | /// In WASI, this error may occur when the file descriptor does |
| 2350 | /// not hold the required rights to read value of a symbolic link relative to it. |
| 2314 | 2351 | AccessDenied, |
| 2315 | 2352 | FileSystem, |
| 2316 | 2353 | SymLinkLoop, |
| ... | ... | @@ -2396,6 +2433,7 @@ pub fn readlinkatWasi(dirfd: fd_t, file_path: []const u8, out_buffer: []u8) Read |
| 2396 | 2433 | wasi.ENOENT => return error.FileNotFound, |
| 2397 | 2434 | wasi.ENOMEM => return error.SystemResources, |
| 2398 | 2435 | wasi.ENOTDIR => return error.NotDir, |
| 2436 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 2399 | 2437 | else => |err| return unexpectedErrno(err), |
| 2400 | 2438 | } |
| 2401 | 2439 | } |
| ... | ... | @@ -3073,6 +3111,9 @@ pub fn waitpid(pid: i32, flags: u32) u32 { |
| 3073 | 3111 | |
| 3074 | 3112 | pub const FStatError = error{ |
| 3075 | 3113 | SystemResources, |
| 3114 | |
| 3115 | /// In WASI, this error may occur when the file descriptor does |
| 3116 | /// not hold the required rights to get its filestat information. |
| 3076 | 3117 | AccessDenied, |
| 3077 | 3118 | } || UnexpectedError; |
| 3078 | 3119 | |
| ... | ... | @@ -3086,6 +3127,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat { |
| 3086 | 3127 | wasi.EBADF => unreachable, // Always a race condition. |
| 3087 | 3128 | wasi.ENOMEM => return error.SystemResources, |
| 3088 | 3129 | wasi.EACCES => return error.AccessDenied, |
| 3130 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3089 | 3131 | else => |err| return unexpectedErrno(err), |
| 3090 | 3132 | } |
| 3091 | 3133 | } |
| ... | ... | @@ -3136,6 +3178,7 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S |
| 3136 | 3178 | wasi.ENAMETOOLONG => return error.NameTooLong, |
| 3137 | 3179 | wasi.ENOENT => return error.FileNotFound, |
| 3138 | 3180 | wasi.ENOTDIR => return error.FileNotFound, |
| 3181 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3139 | 3182 | else => |err| return unexpectedErrno(err), |
| 3140 | 3183 | } |
| 3141 | 3184 | } |
| ... | ... | @@ -3641,7 +3684,13 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void { |
| 3641 | 3684 | } |
| 3642 | 3685 | } |
| 3643 | 3686 | |
| 3644 | | pub const SeekError = error{Unseekable} || UnexpectedError; |
| 3687 | pub const SeekError = error{ |
| 3688 | Unseekable, |
| 3689 | |
| 3690 | /// In WASI, this error may occur when the file descriptor does |
| 3691 | /// not hold the required rights to seek on it. |
| 3692 | AccessDenied, |
| 3693 | } || UnexpectedError; |
| 3645 | 3694 | |
| 3646 | 3695 | /// Repositions read/write file offset relative to the beginning. |
| 3647 | 3696 | pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| ... | ... | @@ -3669,6 +3718,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| 3669 | 3718 | wasi.EOVERFLOW => return error.Unseekable, |
| 3670 | 3719 | wasi.ESPIPE => return error.Unseekable, |
| 3671 | 3720 | wasi.ENXIO => return error.Unseekable, |
| 3721 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3672 | 3722 | else => |err| return unexpectedErrno(err), |
| 3673 | 3723 | } |
| 3674 | 3724 | } |
| ... | ... | @@ -3710,6 +3760,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { |
| 3710 | 3760 | wasi.EOVERFLOW => return error.Unseekable, |
| 3711 | 3761 | wasi.ESPIPE => return error.Unseekable, |
| 3712 | 3762 | wasi.ENXIO => return error.Unseekable, |
| 3763 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3713 | 3764 | else => |err| return unexpectedErrno(err), |
| 3714 | 3765 | } |
| 3715 | 3766 | } |
| ... | ... | @@ -3750,6 +3801,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { |
| 3750 | 3801 | wasi.EOVERFLOW => return error.Unseekable, |
| 3751 | 3802 | wasi.ESPIPE => return error.Unseekable, |
| 3752 | 3803 | wasi.ENXIO => return error.Unseekable, |
| 3804 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3753 | 3805 | else => |err| return unexpectedErrno(err), |
| 3754 | 3806 | } |
| 3755 | 3807 | } |
| ... | ... | @@ -3790,6 +3842,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { |
| 3790 | 3842 | wasi.EOVERFLOW => return error.Unseekable, |
| 3791 | 3843 | wasi.ESPIPE => return error.Unseekable, |
| 3792 | 3844 | wasi.ENXIO => return error.Unseekable, |
| 3845 | wasi.ENOTCAPABLE => return error.AccessDenied, |
| 3793 | 3846 | else => |err| return unexpectedErrno(err), |
| 3794 | 3847 | } |
| 3795 | 3848 | } |