From a63134a4a56e8683aeee292b641b4e943cbfb999 Mon Sep 17 00:00:00 2001 From: jim price Date: Sat, 4 Mar 2023 18:03:37 -0800 Subject: [PATCH] std.os: Add DeviceBusy as a possible write error In Linux when writing to various files in the virtual file system, for example /sys/fs/cgroup, if you write an invalid value to a file you'll get errno 16. This change allows for these specific cases to be caught instead of being lumped together in UnexpectedError. --- lib/std/os.zig | 5 +++++ src/link.zig | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index fe664302a7..3a3433d819 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -1036,6 +1036,7 @@ pub const WriteError = error{ FileTooBig, InputOutput, NoSpaceLeft, + DeviceBusy, /// In WASI, this error may occur when the file descriptor does /// not hold the required rights to write to it. @@ -1134,6 +1135,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { .PERM => return error.AccessDenied, .PIPE => return error.BrokenPipe, .CONNRESET => return error.ConnectionResetByPeer, + .BUSY => return error.DeviceBusy, else => |err| return unexpectedErrno(err), } } @@ -1203,6 +1205,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { .PERM => return error.AccessDenied, .PIPE => return error.BrokenPipe, .CONNRESET => return error.ConnectionResetByPeer, + .BUSY => return error.DeviceBusy, else => |err| return unexpectedErrno(err), } } @@ -1299,6 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { .NXIO => return error.Unseekable, .SPIPE => return error.Unseekable, .OVERFLOW => return error.Unseekable, + .BUSY => return error.DeviceBusy, else => |err| return unexpectedErrno(err), } } @@ -1388,6 +1392,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz .NXIO => return error.Unseekable, .SPIPE => return error.Unseekable, .OVERFLOW => return error.Unseekable, + .BUSY => return error.DeviceBusy, else => |err| return unexpectedErrno(err), } } diff --git a/src/link.zig b/src/link.zig index 4c4915441d..24cc0a3861 100644 --- a/src/link.zig +++ b/src/link.zig @@ -460,6 +460,7 @@ pub const File = struct { CurrentWorkingDirectoryUnlinked, LockViolation, NetNameDeleted, + DeviceBusy, }; /// Called from within the CodeGen to lower a local variable instantion as an unnamed