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

Function test_truncate

test/file-verify.c:76–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76static int test_truncate(struct io_uring *ring, const char *fname, int buffered,
77 int vectored, int provide_buf)
78{
79 struct io_uring_cqe *cqe;
80 struct io_uring_sqe *sqe;
81 struct iovec vec;
82 struct stat sb;
83 off_t punch_off, off, file_size;
84 void *buf = NULL;
85 int u_in_buf, i, ret, fd, first_pass = 1;
86 unsigned int *ptr;
87
88 if (buffered)
89 fd = open(fname, O_RDWR);
90 else
91 fd = open(fname, O_DIRECT | O_RDWR);
92 if (fd < 0) {
93 if (!buffered && errno == EINVAL)
94 return T_EXIT_SKIP;
95 perror("open");
96 return 1;
97 }
98
99 if (fstat(fd, &sb) < 0) {
100 perror("stat");
101 close(fd);
102 return 1;
103 }
104
105 if (S_ISREG(sb.st_mode)) {
106 file_size = sb.st_size;
107 } else if (S_ISBLK(sb.st_mode)) {
108 unsigned long long bytes;
109
110 if (ioctl(fd, BLKGETSIZE64, &bytes) < 0) {
111 perror("ioctl");
112 close(fd);
113 return 1;
114 }
115 file_size = bytes;
116 } else {
117 goto out;
118 }
119
120 if (file_size < CHUNK_SIZE)
121 goto out;
122
123 t_posix_memalign(&buf, 4096, CHUNK_SIZE);
124
125 off = file_size - (CHUNK_SIZE / 2);
126 punch_off = off + CHUNK_SIZE / 4;
127
128 u_in_buf = CHUNK_SIZE / sizeof(unsigned int);
129 ptr = buf;
130 for (i = 0; i < u_in_buf; i++) {
131 *ptr = i;
132 ptr++;
133 }

Callers 1

mainFunction · 0.70

Calls 4

t_posix_memalignFunction · 0.85
io_uring_submitFunction · 0.85
verify_bufFunction · 0.70
io_uring_get_sqeFunction · 0.50

Tested by

no test coverage detected