linux - Given the directory name, how to find the Filesystem on which it resides in C? -


for example, sample df command output

filesystem    mb blocks      free %used    iused %iused mounted on /dev/hd4         512.00    322.96   37%     4842     7% / /dev/hd2        4096.00    717.96   83%    68173    29% /usr /dev/hd9var     1024.00    670.96   35%     6385     4% /var /dev/hd3        5120.00      0.39  100%      158    10% /tmp 

now if specify /tmp/dummy.txt should able /dev/hd3 or hd3.

edit : torek answer. probing /proc become tedious. can suggest me system calls can same internally?

df `pwd` 

...super simple, works, , tells how space there...

[stackuser@rhel62 ~]$ pwd /home/stackuser [stackuser@rhel62 ~]$ df `pwd` filesystem           1k-blocks      used available use% mounted on /dev/sda7            250056240 196130640  41223408  83% / [stackuser@rhel62 ~]$ cd isos [stackuser@rhel62 isos]$ pwd /home/stackuser/isos [stackuser@rhel62 isos]$ df `pwd` filesystem           1k-blocks      used available use% mounted on /dev/sda5            103216920  90417960  11750704  89% /mnt/sda5 [stackuser@rhel62 isos]$ df $(pwd) filesystem           1k-blocks      used available use% mounted on /dev/sda5            103216920  90417960  11750704  89% /mnt/sda5 

...which cause of mount point query in first place.

note backticks, , alternate (modern) method, providing further control on slashes , expansion df $(pwd). tested , traverses symlinks correctly on bash, dash, busybox, zsh. note tcsh won't $(...), stick older backtick style in csh-variants.

there switches in pwd , df further enjoyment.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

delphi - How to convert bitmaps to video? -