You could also popen
the command mount
and examine the output looking for your file system and seeing if it held the text " (ro,"
.
But again, that's not necessarily portable.
My option would be to not worry about whether the file system was mounted read only at all. Just try and create your file and, if it fails, tell the user what the error was. And, of course, give them the option of saving it somewhere else.
You really have to do that sort of thing anyway since, in any scenario where there's even a small gap between testing and doing, you may find the situation changes (probably not to the extent of making an entire file system read only but, who knows, maybe there is (or will be in the future) a file system that allows this).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…