Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a program which writes some files to a directory. My problem is that if the directory isn't mounted for some reason, the program writes to the directory anyway, but the files end up in the system's filesystem, not on the normally mounted filesystem. I would like writes to the directory to fail if that directory isn't mounted. How do I do this in Linux?

share|improve this question
    
So, which program is it? –  slhck Oct 20 '11 at 22:01
    
It is a program you can edit? –  Canadian Luke Oct 20 '11 at 22:04
    
Not a program I can edit. –  Nick Oct 20 '11 at 22:45
    
Is it a program you could wrap with a shell script? –  ott-- Oct 20 '11 at 22:51

2 Answers 2

Make the underlying mount point read-only.

When the additional filesystem is mounted, it's permissions take precedence IIRC.

share|improve this answer

I stumbled across this problen once also.

In my case the scripts accessing the directory in question as root, so the readonly option would have been no solution.

But there are two other possible workarounds:

1st: Check the with the mount command, if the directory is mounted:

 if mount | grep /that/mountpoint
  then
    ...

2nd: Create manually a flag file once the FS is mounted and check that in your script. If the flag-file is not there, the FS may not be mounted

 mount /that/mountpoint
 touch /that/mountpoint/.is_mounted

 if test -e /that/mountpoint/.is_mounted
  then
    ...

The first solution is more reliable if suitable for your system whereas the second one is more portable.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.