1

Context

I am using UBIFS filesystem with on-the-fly data compression enabled. I need to get correct filesystem metrics (total, used, free space) in a C code.

What was tried

I used statvfs call to retrieve the metrics successfully but noticed that values returned were as if data was never compressed. After doing sync(8) call from command line and calling the C code again, correct values were returned so in C code I included call to sync(2) right before statvfs. Calling modified C code again still returned metrics with values as if data was not compressed. Then I tried to make a system call system("sync") before statvfs but still incorrect metric values were returned. Only after waiting like 10 seconds or by explicit sync(8) call the returned filesystem metrics were correct.

Questions

1) Why there is this difference between call to sync(2) or system("sync") in C code right before statvfs and sync(8) call from command line?

2) How to commit pending/cached data to disk in C code so that consequent statvfs call would return correct filesystem metrics?

Richard II
  • 853
  • 9
  • 31

0 Answers0