Want make a script (called getmpoint
) what will return the mountpoint from ANY filename.
The 1st idea, like: parsing output form the df
or parsing fstab
is not as easy as seems, because for example:
getmpoint ../../../some/path/tmp/somefile
getmpoint /tmp/somesymlink #and want get the mountpoint where the real file is
getmpoint /
I have some idea by using stat
(getting the device) - but i'm lost. Need some pointers how to solve this.
Another question is than the stat
command is different on Freebsd-stat and Linux-stat. Is here any portable way?
Similarly, what about:
getmpoint /some/real/path/up/to/here/but/nonexistent_file
would be nice to get a mountpoint only from the path - without the file existence - so without stat
.
Any advices? (I'm probably able make a script myself - but need some guide how to do ...)