[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: prevent writing to unmounted directory



Chris <list.hurschler@gmx.de> writes:

> I want to run a script to rsync local files to a NAS mounted to /mnt/music.  
> Sometimes the NAS is not running, and I want to prevent the script from 
> writing to the mount directory:  is there any easy way to prevent this?

Umount /mnt/music. Run "chattr +i /mnt/music", or, if rsync
doesn't run as root, "chmod o-w /mnt/music".

This doesn't prevent writes to existing files under the
mount directory, or to any file in any existing
subdirectory of the mount directory.

The immutable flag will become unset on /mnt/music when it's
mounted, and the permissions and ownership and so on will
match those of the root of the filesystem being mounted.

Example:

/tmp# dd if=/dev/zero of=loopfs.img count=400
400+0 records in
400+0 records out
204800 bytes (205 kB) copied, 0.00501796 s, 40.8 MB/s
/tmp# mke2fs -Fq loopfs.img
/tmp# mkdir loopdir
/tmp# chattr +i loopdir
/tmp# touch loopdir/foo
touch: cannot touch `loopdir/foo': Permission denied
/tmp# lsattr -d loopdir
----i------------- loopdir
/tmp# mount -o loop loopfs.img loopdir
/tmp# touch loopdir/foo
/tmp# lsattr -d loopdir
------------------ loopdir

-- 
sean
sconnor@spacey.net


Reply to: