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

Re: Detecting ro Filesystem

Le Dimanche 04 Mai 2003 14:57, John Hasler a écrit :
> > ...the following excerpt (which requires linking against liblkid and
> > libext2fs libraries) should do the trick.
> Thank you.  Unfortunately, I need to do this from a sh script.

You may try this  :

# IsOnROFS( $file )
# Returns 0 if the filesystem onto which specified file
# is located is read-only
	# First argument is a file you know to live on the checked filesystem

	# The df command will give us the related filesystem (or label)
	filesystem=$(df "$file_on_fs" | awk 'NR==2 {print $1}')

	# The mount command will tell us how the FS is mounted over the system
	result=$(mount -l | awk -v fs="$fs" '$1==fs { if($NF~/^\(rw,/) {print 1} else 
{print 0} }')

	return $result

I guess it should work in most cases (but not tried with labeled FSs).

Hope this help ...


BOFH excuse #238:
You did wha... oh _dear_....

Reply to: