You need root access to do this. You can run hdparm -W 0 /dev/sda
command to disable write caching, where you have to replace /dev/sda
with device for your drive:
#include <stdlib.h>
...
system("hdparm -W 0 /dev/sda1");
You can also selectively disable write caching to individual partitions like this: hdparm -W 0 /dev/sda1
.
To reenable caching again just use the -W 1
argument.
man hdparm, man system
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…