Description
In ldiskfs_write_ldd():
270 num = fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep); 271 if (num < 1 && ferror(filep)) { 272 fprintf(stderr, "%s: Unable to write to file (%s): %s\n", 273 progname, filepnm, strerror(errno)); 274 fclose(filep); 275 goto out_umnt; 276 } 277 fsync(filep->_fileno); 278 fclose(filep);
Calling fsync() without first calling fflush() is ineffective since there will likely still be unwritten data in the userspace buffer.
Also we should use fileno(filp) instead of accessing filp->_fileno.
We should check the returns of fflush(), fsync(), and fclose() for failure. Since an error is more likely to be reported there than from fwrite().