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 {
594594 futexWake(ev, @ptrCast(&cached_fd.once), 1);
595595 }
596596 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 flag
597 error.OperationUnsupported => return error.Unexpected, // TMPFILE unset.
598598 else => |e| return e,
599599 };
600600 @atomicStore(Once, &cached_fd.once, .fromFd(fd), .monotonic);
......@@ -2725,11 +2725,10 @@ fn dirOpenDir(
27252725 error.WouldBlock => return errnoBug(.AGAIN),
27262726 error.FileTooBig => return errnoBug(.FBIG),
27272727 error.NoSpaceLeft => return errnoBug(.NOSPC),
2728 error.DeviceBusy => return errnoBug(.BUSY), // O_EXCL not passed
2728 error.DeviceBusy => return errnoBug(.BUSY), // EXCL unset.
27292729 error.FileBusy => return errnoBug(.TXTBSY),
27302730 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.
2731 error.FileLocksUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.
2732 error.OperationUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for O_TMPFILE.
2731 error.OperationUnsupported => return errnoBug(.OPNOTSUPP), // No TMPFILE, no locks.
27332732 else => |e| return e,
27342733 },
27352734 };
......@@ -2819,7 +2818,7 @@ fn dirCreateFile(
28192818 .EXCL = flags.exclusive,
28202819 .CLOEXEC = true,
28212820 }, 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.
28232822 else => |e| return e,
28242823 };
28252824 errdefer ev.closeAsync(fd);
......@@ -2906,7 +2905,6 @@ fn dirCreateFileAtomic(
29062905 error.FileTooBig => return errnoBug(.FBIG),
29072906 error.DeviceBusy => return errnoBug(.BUSY), // O_EXCL not passed
29082907 error.PathAlreadyExists => return errnoBug(.EXIST), // Not creating.
2909 error.FileLocksUnsupported => return errnoBug(.OPNOTSUPP), // Not asking for locks.
29102908 else => |e| return e,
29112909 },
29122910 .flags = .{ .nonblocking = false },
......@@ -3008,7 +3006,7 @@ fn dirOpenFile(
30083006 .CLOEXEC = true,
30093007 .PATH = flags.path_only,
30103008 }, 0) catch |err| switch (err) {
3011 error.OperationUnsupported => return error.Unexpected, // TMPFILE bit not set.
3009 error.OperationUnsupported => return error.Unexpected, // TMPFILE unset.
30123010 else => |e| return e,
30133011 };
30143012 errdefer ev.closeAsync(fd);
......@@ -3155,7 +3153,7 @@ fn dirRealPathFile(
31553153 .PATH = true,
31563154 }, 0) catch |err| switch (err) {
31573155 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.
31593157 else => |e| return e,
31603158 };
31613159 defer ev.closeAsync(fd);
......@@ -5615,27 +5613,6 @@ fn lseek(
56155613 }
56165614}
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
56395616fn openat(
56405617 ev: *Evented,
56415618 cancel_region: *CancelRegion,
......@@ -5643,7 +5620,7 @@ fn openat(
56435620 path: [*:0]const u8,
56445621 flags: linux.O,
56455622 mode: linux.mode_t,
5646) OpenError!fd_t {
5623) !fd_t {
56475624 var mut_flags = flags;
56485625 if (@hasField(linux.O, "LARGEFILE")) mut_flags.LARGEFILE = true;
56495626 while (true) {
......@@ -5689,8 +5666,9 @@ fn openat(
56895666 .PERM => return error.PermissionDenied,
56905667 .EXIST => return error.PathAlreadyExists,
56915668 .BUSY => return error.DeviceBusy,
5692 // File locking and TMPFILE are mutually exclusive
5693 .OPNOTSUPP => return if (flags.TMPFILE) error.OperationUnsupported else error.FileLocksUnsupported,
5669 // This can be triggered by file locking and TMPFILE, but those
5670 // flags are mutually exclusive.
5671 .OPNOTSUPP => return error.OperationUnsupported,
56945672 .AGAIN => return error.WouldBlock,
56955673 .TXTBSY => return error.FileBusy,
56965674 .NXIO => return error.NoDevice,