MCPcopy Create free account
hub / github.com/axboe/liburing / main

Function main

test/hardlink.c:68–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68int main(int argc, char *argv[])
69{
70 static const char target[] = "io_uring-linkat-test-target";
71 static const char emptyname[] = "io_uring-linkat-test-empty";
72 static const char linkname[] = "io_uring-linkat-test-link";
73 static const char symlinkname[] = "io_uring-linkat-test-symlink";
74 struct io_uring ring;
75 int ret, fd, exit_status = T_EXIT_FAIL;
76
77 if (argc > 1)
78 return T_EXIT_SKIP;
79
80 ret = io_uring_queue_init(8, &ring, 0);
81 if (ret) {
82 fprintf(stderr, "queue init failed: %d\n", ret);
83 return ret;
84 }
85
86 ret = fd = open(target, O_CREAT | O_RDWR | O_EXCL, 0600);
87 if (ret < 0) {
88 perror("open");
89 goto out;
90 }
91 if (write(fd, "linktest", 8) != 8) {
92 close(fd);
93 goto out;
94 }
95 if(geteuid()) {
96 fprintf(stdout, "not root, skipping AT_EMPTY_PATH test\n");
97 } else {
98 ret = do_linkat(&ring, fd, "", emptyname, AT_EMPTY_PATH);
99 if (ret < 0) {
100 if (ret == -EBADF || ret == -EINVAL) {
101 fprintf(stdout, "linkat not supported, skipping\n");
102 exit_status = T_EXIT_SKIP;
103 goto out;
104 }
105 fprintf(stderr, "linkat: %s\n", strerror(-ret));
106 goto out;
107 } else if (ret) {
108 goto out;
109 }
110 if (!files_linked_ok(emptyname, target))
111 goto out;
112 unlinkat(AT_FDCWD, emptyname, 0);
113 }
114 close(fd);
115
116 ret = symlink(target, symlinkname);
117 if (ret < 0) {
118 perror("open");
119 goto out;
120 }
121
122 ret = do_linkat(&ring, AT_FDCWD, target, linkname, 0);
123 if (ret < 0) {
124 if (ret == -EBADF || ret == -EINVAL) {
125 fprintf(stdout, "linkat not supported, skipping\n");

Callers

nothing calls this directly

Calls 4

io_uring_queue_initFunction · 0.85
do_linkatFunction · 0.85
files_linked_okFunction · 0.85
io_uring_queue_exitFunction · 0.85

Tested by

no test coverage detected