- if (ctx->cfd != -1)
- close(ctx->cfd);
- asprintf(&bandName, "%s/bands/%x", ctx->pathname, bandNum);
- fd = open(bandName, O_WRONLY | O_CREAT, 0666);
- if (fd == -1) {
- warn("Cannot open band file %s for offset %llu", bandName, offset + written);
- retval = -1;
- goto done;
- }
- free(bandName);
- bandName = NULL;
- ctx->cfd = fd;
- ctx->cBandNum = bandNum;
+ if (ctx->cfd != -1) {
+ close(ctx->cfd);
+ }
+ asprintf(&bandName, "%s/bands/%x", ctx->pathname, bandNum);
+ fd = open(bandName, O_WRONLY | O_CREAT, 0666);
+ if (fd == -1) {
+ warn("Cannot open band file %s for offset %llu", bandName, offset + written);
+ retval = -1;
+ goto done;
+ }
+ /*
+ * When we create a new band file, we sync the volume
+ * it's on, so that we can ensure that the band file is present
+ * on disk. (Otherwise, with a crash, we can end up with the
+ * data not where we expected.) In this case, however, we probably
+ * don't need to wait for it -- just start the sync.
+ */
+ fsync_volume_np(fd, 0);
+ fcntl(fd, F_NOCACHE, 1);
+ free(bandName);
+ bandName = NULL;
+ ctx->cfd = fd;
+ ctx->cBandNum = bandNum;