LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-16-2015, 11:59 AM   #1
danielhilst
LQ Newbie
 
Registered: Apr 2010
Location: Brazil
Distribution: Gentoo,Archlinux
Posts: 24

Rep: Reputation: 1
Avoiding creation of files at some mount point.


I have some embedded environment, on which there is a mount point called /media/card. This mount point receives the SDCard filesystem, where our application runs. We have some problems of card not being inserted, and people wrongly copying data to this mount point - via SFTP. The safe-lock implemented by me was put some check on application's startup script to do not execute if /media/card isn't mounted. I do this by greping /proc/mounts.

I want to know if there is a way to put all tree below /media/card, while umounted, in read-only and when SDCard got mounted, overwrite permissions setted that tree. I've tryied to setup permissions, but even with chmod 000 /media/card, I still can create files, I mean, touch /media/card/foo works.

Since I'm running from a flash disk, the filesystem used is jffs2. Running applications that logs to filesystem can harm whole environment after some time, so I would like to have something more secure.

Best regards,
Daniel
 
Old 03-16-2015, 03:54 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by danielhilst View Post
The safe-lock implemented by me was put some check on application's startup script to do not execute if /media/card isn't mounted. I do this by greping /proc/mounts.
Could you do the mount in the application startup script? If so, then you could check the mount command for successful completion. The command would look someting like this:

# Mount the flash drive
if ! (mount -L charlie /media/card);
then
echo "mount failed for flash card"
exit
fi
 
Old 03-16-2015, 04:25 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Could you just remove the directory if the mount is unsuccessful? What is this "tree" you're speaking of? If the card is not mounted, the mount point should just be an empty directory.
 
Old 03-17-2015, 11:27 AM   #4
danielhilst
LQ Newbie
 
Registered: Apr 2010
Location: Brazil
Distribution: Gentoo,Archlinux
Posts: 24

Original Poster
Rep: Reputation: 1
With tree I mean all directories below /media/card, like /media/card/app/foo/bar/etc... I wan't to prohibit the user from writing on /media/card when no filesystem is mounted on it. Something like this

touch /media/card/foo # Error, pohibited. /media/card on same filesystem as /
mount /dev/sdb1 /media/card
touch /media/card/foo # Ok!

The ideia is to pohibit user to write data below /media/card on root filesystem, and permit on other filesystem (usually vfat)

I think about removing the card directory at all, and create on auto-mount.sh script (udev stuff), and remove on umount. This way no mount point exists when no filesystem is mounted on it. But I don't know if this script will run if the machine boots with SDCard inserted already. I'm gonna test it..

Regards,
Daniel
 
Old 03-17-2015, 11:32 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Is it root you're trying to stop from writing to this directory, or another user? You can't stop root from doing anything, root can do whatever it wants, but it would be pretty easy to block a regular user from writing to that directory when the card is not mounted.
 
Old 03-18-2015, 05:07 AM   #6
danielhilst
LQ Newbie
 
Registered: Apr 2010
Location: Brazil
Distribution: Gentoo,Archlinux
Posts: 24

Original Poster
Rep: Reputation: 1
I see, it's root user. So this would be fixed if I use proper users, true. I'll try this! Thanks for suggestion!!
 
Old 03-18-2015, 11:52 AM   #7
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
You can test if something is mounted on a folder with the 'mountpoint' command eg
Code:
keithhedger@LFSStarBug:/tmp-> mountpoint /etc
/etc is not a mountpoint
keithhedger@LFSStarBug:/tmp-> mountpoint /dev
/dev is a mountpoint
keithhedger@LFSStarBug:/tmp->
 
Old 03-18-2015, 12:06 PM   #8
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
Mount another filesystem there with options=ro.
 
  


Reply

Tags
mount, permissions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
total number of files in mount point from all directories rookie11 Linux - Newbie 2 06-14-2013 04:51 PM
Can browse files via Windows mount point but not through the server/share njmurvin Linux - Newbie 2 08-21-2009 12:43 PM
puppy+grub saves ram installed mount point as HD install mount point agualust Linux - Newbie 0 04-10-2009 11:23 AM
Avoiding automatic creation of tar.gz in /var/archives? frenchn00b Linux - Newbie 2 07-18-2007 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration