| ... | ... | @@ -650,6 +650,23 @@ pub const IO_Uring = struct { |
| 650 | 650 | return sqe; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | /// Queues (but does not submit) an SQE to perform an `statx(2)`. |
| 654 | /// Returns a pointer to the SQE. |
| 655 | pub fn statx( |
| 656 | self: *IO_Uring, |
| 657 | user_data: u64, |
| 658 | fd: os.fd_t, |
| 659 | path: [:0]const u8, |
| 660 | flags: u32, |
| 661 | mask: u32, |
| 662 | buf: *linux.Statx, |
| 663 | ) !*io_uring_sqe { |
| 664 | const sqe = try self.get_sqe(); |
| 665 | io_uring_prep_statx(sqe, fd, path, flags, mask, buf); |
| 666 | sqe.user_data = user_data; |
| 667 | return sqe; |
| 668 | } |
| 669 | |
| 653 | 670 | /// Registers an array of file descriptors. |
| 654 | 671 | /// Every time a file descriptor is put in an SQE and submitted to the kernel, the kernel must |
| 655 | 672 | /// retrieve a reference to the file, and once I/O has completed the file reference must be |
| ... | ... | @@ -1116,6 +1133,18 @@ pub fn io_uring_prep_fallocate( |
| 1116 | 1133 | }; |
| 1117 | 1134 | } |
| 1118 | 1135 | |
| 1136 | pub fn io_uring_prep_statx( |
| 1137 | sqe: *io_uring_sqe, |
| 1138 | fd: os.fd_t, |
| 1139 | path: [*:0]const u8, |
| 1140 | flags: u32, |
| 1141 | mask: u32, |
| 1142 | buf: *linux.Statx, |
| 1143 | ) void { |
| 1144 | io_uring_prep_rw(.STATX, sqe, fd, @ptrToInt(path), mask, @ptrToInt(buf)); |
| 1145 | sqe.rw_flags = flags; |
| 1146 | } |
| 1147 | |
| 1119 | 1148 | test "structs/offsets/entries" { |
| 1120 | 1149 | if (builtin.os.tag != .linux) return error.SkipZigTest; |
| 1121 | 1150 | |
| ... | ... | @@ -1720,3 +1749,57 @@ test "fallocate" { |
| 1720 | 1749 | |
| 1721 | 1750 | try testing.expectEqual(len, (try file.stat()).size); |
| 1722 | 1751 | } |
| 1752 | |
| 1753 | test "statx" { |
| 1754 | if (builtin.os.tag != .linux) return error.SkipZigTest; |
| 1755 | |
| 1756 | var ring = IO_Uring.init(1, 0) catch |err| switch (err) { |
| 1757 | error.SystemOutdated => return error.SkipZigTest, |
| 1758 | error.PermissionDenied => return error.SkipZigTest, |
| 1759 | else => return err, |
| 1760 | }; |
| 1761 | defer ring.deinit(); |
| 1762 | |
| 1763 | const path = "test_io_uring_statx"; |
| 1764 | const file = try std.fs.cwd().createFile(path, .{ .truncate = true, .mode = 0o666 }); |
| 1765 | defer file.close(); |
| 1766 | defer std.fs.cwd().deleteFile(path) catch {}; |
| 1767 | |
| 1768 | try testing.expectEqual(@as(u64, 0), (try file.stat()).size); |
| 1769 | |
| 1770 | try file.writeAll("foobar"); |
| 1771 | |
| 1772 | var buf: linux.Statx = undefined; |
| 1773 | const sqe = try ring.statx( |
| 1774 | 0xaaaaaaaa, |
| 1775 | linux.AT.FDCWD, |
| 1776 | path, |
| 1777 | 0, |
| 1778 | linux.STATX_SIZE, |
| 1779 | &buf, |
| 1780 | ); |
| 1781 | try testing.expectEqual(linux.IORING_OP.STATX, sqe.opcode); |
| 1782 | try testing.expectEqual(@as(i32, linux.AT.FDCWD), sqe.fd); |
| 1783 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1784 | |
| 1785 | const cqe = try ring.copy_cqe(); |
| 1786 | switch (cqe.err()) { |
| 1787 | .SUCCESS => {}, |
| 1788 | // This kernel's io_uring does not yet implement statx(): |
| 1789 | .INVAL => return error.SkipZigTest, |
| 1790 | // This kernel does not implement statx(): |
| 1791 | .NOSYS => return error.SkipZigTest, |
| 1792 | // The filesystem containing the file referred to by fd does not support this operation; |
| 1793 | // or the mode is not supported by the filesystem containing the file referred to by fd: |
| 1794 | .OPNOTSUPP => return error.SkipZigTest, |
| 1795 | else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), |
| 1796 | } |
| 1797 | try testing.expectEqual(linux.io_uring_cqe{ |
| 1798 | .user_data = 0xaaaaaaaa, |
| 1799 | .res = 0, |
| 1800 | .flags = 0, |
| 1801 | }, cqe); |
| 1802 | |
| 1803 | try testing.expect(buf.mask & os.linux.STATX_SIZE == os.linux.STATX_SIZE); |
| 1804 | try testing.expectEqual(@as(u64, 6), buf.size); |
| 1805 | } |