MCPcopy Create free account
hub / github.com/coreutils/coreutils / iwrite

Function iwrite

src/dd.c:1170–1244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1168 writes. */
1169
1170static idx_t
1171iwrite (int fd, char const *buf, idx_t size)
1172{
1173 idx_t total_written = 0;
1174
1175 if ((output_flags & O_DIRECT) && size < output_blocksize)
1176 {
1177 int old_flags = fcntl (STDOUT_FILENO, F_GETFL);
1178 if (fcntl (STDOUT_FILENO, F_SETFL, old_flags & ~O_DIRECT) != 0
1179 && status_level != STATUS_NONE)
1180 diagnose (errno, _("failed to turn off O_DIRECT: %s"),
1181 quotef (output_file));
1182
1183 /* Since we have just turned off O_DIRECT for the final write,
1184 we try to preserve some of its semantics. */
1185
1186 /* Call invalidate_cache to setup the appropriate offsets
1187 for subsequent calls. */
1188 o_nocache_eof = true;
1189 invalidate_cache (STDOUT_FILENO, 0);
1190
1191 /* Attempt to ensure that the final block is committed
1192 to stable storage as quickly as possible. */
1193 conversions_mask |= C_FSYNC;
1194
1195 /* After the subsequent fsync we'll call invalidate_cache
1196 to attempt to clear all data from the page cache. */
1197 }
1198
1199 while (total_written < size)
1200 {
1201 ssize_t nwritten = 0;
1202 process_signals ();
1203
1204 /* Perform a seek for a NUL block if sparse output is enabled. */
1205 final_op_was_seek = false;
1206 if ((conversions_mask & C_SPARSE) && is_nul (buf, size))
1207 {
1208 if (lseek (fd, size, SEEK_CUR) < 0)
1209 {
1210 conversions_mask &= ~C_SPARSE;
1211 /* Don't warn about the advisory sparse request. */
1212 }
1213 else
1214 {
1215 final_op_was_seek = true;
1216 nwritten = size;
1217 }
1218 }
1219
1220 if (!nwritten)
1221 nwritten = write (fd, buf + total_written, size - total_written);
1222
1223 if (nwritten < 0)
1224 {
1225 if (errno != EINTR)
1226 break;
1227 }

Callers 2

write_outputFunction · 0.85
dd_copyFunction · 0.85

Calls 4

diagnoseFunction · 0.85
invalidate_cacheFunction · 0.85
is_nulFunction · 0.85
process_signalsFunction · 0.70

Tested by

no test coverage detected