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{...@@ -1036,6 +1036,7 @@ pub const WriteError = error{
1036 FileTooBig,1036 FileTooBig,
1037 InputOutput,1037 InputOutput,
1038 NoSpaceLeft,1038 NoSpaceLeft,
1039 DeviceBusy,
10391040
1040 /// In WASI, this error may occur when the file descriptor does1041 /// In WASI, this error may occur when the file descriptor does
1041 /// not hold the required rights to write to it.1042 /// not hold the required rights to write to it.
...@@ -1134,6 +1135,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -1134,6 +1135,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
1134 .PERM => return error.AccessDenied,1135 .PERM => return error.AccessDenied,
1135 .PIPE => return error.BrokenPipe,1136 .PIPE => return error.BrokenPipe,
1136 .CONNRESET => return error.ConnectionResetByPeer,1137 .CONNRESET => return error.ConnectionResetByPeer,
1138 .BUSY => return error.DeviceBusy,
1137 else => |err| return unexpectedErrno(err),1139 else => |err| return unexpectedErrno(err),
1138 }1140 }
1139 }1141 }
...@@ -1203,6 +1205,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {...@@ -1203,6 +1205,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
1203 .PERM => return error.AccessDenied,1205 .PERM => return error.AccessDenied,
1204 .PIPE => return error.BrokenPipe,1206 .PIPE => return error.BrokenPipe,
1205 .CONNRESET => return error.ConnectionResetByPeer,1207 .CONNRESET => return error.ConnectionResetByPeer,
1208 .BUSY => return error.DeviceBusy,
1206 else => |err| return unexpectedErrno(err),1209 else => |err| return unexpectedErrno(err),
1207 }1210 }
1208 }1211 }
...@@ -1299,6 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {...@@ -1299,6 +1302,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
1299 .NXIO => return error.Unseekable,1302 .NXIO => return error.Unseekable,
1300 .SPIPE => return error.Unseekable,1303 .SPIPE => return error.Unseekable,
1301 .OVERFLOW => return error.Unseekable,1304 .OVERFLOW => return error.Unseekable,
1305 .BUSY => return error.DeviceBusy,
1302 else => |err| return unexpectedErrno(err),1306 else => |err| return unexpectedErrno(err),
1303 }1307 }
1304 }1308 }
...@@ -1388,6 +1392,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz...@@ -1388,6 +1392,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
1388 .NXIO => return error.Unseekable,1392 .NXIO => return error.Unseekable,
1389 .SPIPE => return error.Unseekable,1393 .SPIPE => return error.Unseekable,
1390 .OVERFLOW => return error.Unseekable,1394 .OVERFLOW => return error.Unseekable,
1395 .BUSY => return error.DeviceBusy,
1391 else => |err| return unexpectedErrno(err),1396 else => |err| return unexpectedErrno(err),
1392 }1397 }
1393 }1398 }
src/link.zig+1
...@@ -460,6 +460,7 @@ pub const File = struct {...@@ -460,6 +460,7 @@ pub const File = struct {
460 CurrentWorkingDirectoryUnlinked,460 CurrentWorkingDirectoryUnlinked,
461 LockViolation,461 LockViolation,
462 NetNameDeleted,462 NetNameDeleted,
463 DeviceBusy,
463 };464 };
464465
465 /// Called from within the CodeGen to lower a local variable instantion as an unnamed466 /// Called from within the CodeGen to lower a local variable instantion as an unnamed