authorgravatar for shadeops@gmail.comjim price <shadeops@gmail.com> 2023-03-04 18:03:37-08:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-05 17:56:44+02:00
loga63134a4a56e8683aeee292b641b4e943cbfb999
tree29b1dfb59fa9181676893a2fbfc8d84d2e54e10b
parente7f128c2051b086cdb1c03da041745b560bbaa3e

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.

2 files changed, 6 insertions(+), 0 deletions(-)

lib/std/os.zig+5
......@@ -1036,6 +1036,7 @@ pub const WriteError = error{
10361036 FileTooBig,
10371037 InputOutput,
10381038 NoSpaceLeft,
1039 DeviceBusy,
10391040
10401041 /// In WASI, this error may occur when the file descriptor does
10411042 /// not hold the required rights to write to it.
......@@ -1134,6 +1135,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
11341135 .PERM => return error.AccessDenied,
11351136 .PIPE => return error.BrokenPipe,
11361137 .CONNRESET => return error.ConnectionResetByPeer,
1138 .BUSY => return error.DeviceBusy,
11371139 else => |err| return unexpectedErrno(err),
11381140 }
11391141 }
......@@ -1203,6 +1205,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
12031205 .PERM => return error.AccessDenied,
12041206 .PIPE => return error.BrokenPipe,
12051207 .CONNRESET => return error.ConnectionResetByPeer,
1208 .BUSY => return error.DeviceBusy,
12061209 else => |err| return unexpectedErrno(err),
12071210 }
12081211 }
......@@ -1299,6 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
12991302 .NXIO => return error.Unseekable,
13001303 .SPIPE => return error.Unseekable,
13011304 .OVERFLOW => return error.Unseekable,
1305 .BUSY => return error.DeviceBusy,
13021306 else => |err| return unexpectedErrno(err),
13031307 }
13041308 }
......@@ -1388,6 +1392,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
13881392 .NXIO => return error.Unseekable,
13891393 .SPIPE => return error.Unseekable,
13901394 .OVERFLOW => return error.Unseekable,
1395 .BUSY => return error.DeviceBusy,
13911396 else => |err| return unexpectedErrno(err),
13921397 }
13931398 }
src/link.zig+1
......@@ -460,6 +460,7 @@ pub const File = struct {
460460 CurrentWorkingDirectoryUnlinked,
461461 LockViolation,
462462 NetNameDeleted,
463 DeviceBusy,
463464 };
464465
465466 /// Called from within the CodeGen to lower a local variable instantion as an unnamed