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.
This commit is contained in:
jim price 2023-03-04 18:03:37 -08:00 committed by Veikka Tuominen
parent e7f128c205
commit a63134a4a5
2 changed files with 6 additions and 0 deletions

View File

@ -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),
}
}

View File

@ -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