authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-20 12:18:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-20 12:18:25-07:00
loga9e5c72aa885c67348277ca982fb964fd686254e
treeda6bc0a19f43d2010107e9f2c6566d7267952eb7
parent2054a257c288c44df52510ac2e7646a08df8a4bb

Io.Uring: simplify openat error handling


1 files changed, 10 insertions(+), 32 deletions(-)

lib/std/Io/Uring.zig+10-32
...@@ -594,7 +594,7 @@ const CachedFd = struct {...@@ -594,7 +594,7 @@ const CachedFd = struct {
594 futexWake(ev, @ptrCast(&cached_fd.once), 1);594 futexWake(ev, @ptrCast(&cached_fd.once), 1);
595 }595 }
596 const fd = ev.openat(cancel_region, linux.AT.FDCWD, path, flags, 0) catch |err| switch (err) {596 const fd = ev.openat(cancel_region, linux.AT.FDCWD, path, flags, 0) catch |err| switch (err) {
597 error.OperationUnsupported => return error.Unexpected, // Not expecting O_TMPFILE flag597 error.OperationUnsupported => return error.Unexpected, // TMPFILE unset.
598 else => |e| return e,598 else => |e| return e,
599 };599 };
600 @atomicStore(Once, &cached_fd.once, .fromFd(fd), .monotonic);600 @atomicStore(Once, &cached_fd.once, .fromFd(fd), .monotonic);
...@@ -2725,11 +2725,10 @@ fn dirOpenDir(...@@ -2725,11 +2725,10 @@ fn dirOpenDir(
2725 error.WouldBlock => return errnoBug(.AGAIN),2725 error.WouldBlock => return errnoBug(.AGAIN),
2726 error.FileTooBig => return errnoBug(.FBIG),2726 error.FileTooBig => return errnoBug(.FBIG),
2727 error.NoSpaceLeft => return errnoBug(.NOSPC),2727 error.NoSpaceLeft => return errnoBug(.NOSPC),
2728 error.DeviceBusy => return errnoBug(.BUSY), // O_EXCL not passed2728 error.DeviceBusy => return errnoBug(.BUSY), // EXCL unset.
2729 error.FileBusy => return errnoBug(.TXTBSY),2729 error.FileBusy => return errnoBug(.TXTBSY),
2730 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.2730 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.
2731 error.FileLocksUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.2731 error.OperationUnsupported => return errnoBug(.OPNOTSUPP), // No TMPFILE, no locks.
2732 error.OperationUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for O_TMPFILE.
2733 else => |e| return e,2732 else => |e| return e,
2734 },2733 },
2735 };2734 };
...@@ -2819,7 +2818,7 @@ fn dirCreateFile(...@@ -2819,7 +2818,7 @@ fn dirCreateFile(
2819 .EXCL = flags.exclusive,2818 .EXCL = flags.exclusive,
2820 .CLOEXEC = true,2819 .CLOEXEC = true,
2821 }, flags.permissions.toMode()) catch |err| switch (err) {2820 }, flags.permissions.toMode()) catch |err| switch (err) {
2822 error.OperationUnsupported => return error.Unexpected, // TMPFILE bit not set.2821 error.OperationUnsupported => return error.Unexpected, // TMPFILE unset.
2823 else => |e| return e,2822 else => |e| return e,
2824 };2823 };
2825 errdefer ev.closeAsync(fd);2824 errdefer ev.closeAsync(fd);
...@@ -2906,7 +2905,6 @@ fn dirCreateFileAtomic(...@@ -2906,7 +2905,6 @@ fn dirCreateFileAtomic(
2906 error.FileTooBig => return errnoBug(.FBIG),2905 error.FileTooBig => return errnoBug(.FBIG),
2907 error.DeviceBusy => return errnoBug(.BUSY), // O_EXCL not passed2906 error.DeviceBusy => return errnoBug(.BUSY), // O_EXCL not passed
2908 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.2907 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.
2909 error.FileLocksUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.
2910 else => |e| return e,2908 else => |e| return e,
2911 },2909 },
2912 .flags = .{ .nonblocking = false },2910 .flags = .{ .nonblocking = false },
...@@ -3008,7 +3006,7 @@ fn dirOpenFile(...@@ -3008,7 +3006,7 @@ fn dirOpenFile(
3008 .CLOEXEC = true,3006 .CLOEXEC = true,
3009 .PATH = flags.path_only,3007 .PATH = flags.path_only,
3010 }, 0) catch |err| switch (err) {3008 }, 0) catch |err| switch (err) {
3011 error.OperationUnsupported => return error.Unexpected, // TMPFILE bit not set.3009 error.OperationUnsupported => return error.Unexpected, // TMPFILE unset.
3012 else => |e| return e,3010 else => |e| return e,
3013 };3011 };
3014 errdefer ev.closeAsync(fd);3012 errdefer ev.closeAsync(fd);
...@@ -3155,7 +3153,7 @@ fn dirRealPathFile(...@@ -3155,7 +3153,7 @@ fn dirRealPathFile(
3155 .PATH = true,3153 .PATH = true,
3156 }, 0) catch |err| switch (err) {3154 }, 0) catch |err| switch (err) {
3157 error.WouldBlock => return errnoBug(.AGAIN),3155 error.WouldBlock => return errnoBug(.AGAIN),
3158 error.FileLocksUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.3156 error.OperationUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.
3159 else => |e| return e,3157 else => |e| return e,
3160 };3158 };
3161 defer ev.closeAsync(fd);3159 defer ev.closeAsync(fd);
...@@ -5615,27 +5613,6 @@ fn lseek(...@@ -5615,27 +5613,6 @@ fn lseek(
5615 }5613 }
5616}5614}
56175615
5618const OpenError = error{
5619 AccessDenied,
5620 FileTooBig,
5621 IsDir,
5622 SymLinkLoop,
5623 ProcessFdQuotaExceeded,
5624 SystemFdQuotaExceeded,
5625 NoDevice,
5626 FileNotFound,
5627 SystemResources,
5628 NoSpaceLeft,
5629 NotDir,
5630 PermissionDenied,
5631 PathAlreadyExists,
5632 DeviceBusy,
5633 OperationUnsupported,
5634 FileLocksUnsupported,
5635 WouldBlock,
5636 FileBusy,
5637} || Dir.PathNameError || Io.Cancelable || Io.UnexpectedError;
5638
5639fn openat(5616fn openat(
5640 ev: *Evented,5617 ev: *Evented,
5641 cancel_region: *CancelRegion,5618 cancel_region: *CancelRegion,
...@@ -5643,7 +5620,7 @@ fn openat(...@@ -5643,7 +5620,7 @@ fn openat(
5643 path: [*:0]const u8,5620 path: [*:0]const u8,
5644 flags: linux.O,5621 flags: linux.O,
5645 mode: linux.mode_t,5622 mode: linux.mode_t,
5646) OpenError!fd_t {5623) !fd_t {
5647 var mut_flags = flags;5624 var mut_flags = flags;
5648 if (@hasField(linux.O, "LARGEFILE")) mut_flags.LARGEFILE = true;5625 if (@hasField(linux.O, "LARGEFILE")) mut_flags.LARGEFILE = true;
5649 while (true) {5626 while (true) {
...@@ -5689,8 +5666,9 @@ fn openat(...@@ -5689,8 +5666,9 @@ fn openat(
5689 .PERM => return error.PermissionDenied,5666 .PERM => return error.PermissionDenied,
5690 .EXIST => return error.PathAlreadyExists,5667 .EXIST => return error.PathAlreadyExists,
5691 .BUSY => return error.DeviceBusy,5668 .BUSY => return error.DeviceBusy,
5692 // File locking and TMPFILE are mutually exclusive5669 // This can be triggered by file locking and TMPFILE, but those
5693 .OPNOTSUPP => return if (flags.TMPFILE) error.OperationUnsupported else error.FileLocksUnsupported,5670 // flags are mutually exclusive.
5671 .OPNOTSUPP => return error.OperationUnsupported,
5694 .AGAIN => return error.WouldBlock,5672 .AGAIN => return error.WouldBlock,
5695 .TXTBSY => return error.FileBusy,5673 .TXTBSY => return error.FileBusy,
5696 .NXIO => return error.NoDevice,5674 .NXIO => return error.NoDevice,