Read-only file system ,ST_RDONLY not shows up on statvfs ?


I would like to know any api or method to check the status of a file system whether it is readonly protected or not.

On my x86 qnx6.3 PC, I inserted a usb which has been readonly-protected.
Then mounted it on /fs/usb/.
If I try to copy or create any file on the file system(/fs/usb), I only get error message saying “Read-only file system”.

It’s ok. Now I need to be able to check whether the file system is read-only file system or not in my program.

I thought statvfs could work. But it doesn’t!!!

The flag, ‘struct statvfs::f_flag’ retireved by statvfs is only 0x100.
0x100 is not the read-only because other file system like ‘/’ retrieves same value 0x100 and I can copy files on ‘/’.

Now I found statvfs doesn’t work for my case.
Can anyone help me?

Actually statvfs should tell you that for your Filesystem.

Other thing you would have to check is if you have write access to the directory you want to write to:

I just tried it here, and I get 0x100 for “/” and 0x101 for a filesystem I mount as readonly. I suspect that your device contains a corrupt filesystem, and the first time you try to write to it, the filesystem driver detects this, and remounts itself as readonly (that is what the filesystem does to prevent further damage to the filesystem).

To check that your code is correct, you can just:

devb-ram ram capacity=8192 &

mount -r /dev/hdXt77 /ram

testProgram /ram

(testProgram /ram should show 0x101 for the filesystem)

For your info. the filesystem type is “dos(fat32)” and the device is usb memory stick.

It’s quite possible the fat file system component doesn’t fill that info properly.

However if you try the create a file with fopen with the write flag it should fail and set errno to the error that matches READ ONLY filesystem.