UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 16th, 2008, 07:56 PM
cydonio cydonio is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 4 cydonio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Advanced file system question

The df command has the option "df filename" which shows information for the file system on which the file resides. Does anyone know how df in this case finds out on which file system the specified file exists?. I'm writing a tool which needs to do that, given a file name, find out its file system (without using df).
Any help will be greatly appreciated.
Thanks in advance

Reply With Quote
  #2  
Old March 18th, 2008, 01:34 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
Short verion of what GNU df does:
lstat for the file in the current directory, see if it is a link, use the link directory to find the mount point

otherwise it attempts several things
getcwd to find a filename a directory name
Then it searches for mount points, going upward from the current directory
To do this is needs a list of mounted filesystems as well.

When it finds a mount point, it then knows which filesystem applies.

You can also work against a device list using the device number in struct stat - st_dev You can relate that to mounted filesystems list as well.

IMO, you'd be better off getting code for df.c and mountpoint.c in the coreutils:
http://linux.softpedia.com/progDown...nload-6964.html

Last edited by jim mcnamara : March 18th, 2008 at 01:38 PM.

Reply With Quote
  #3  
Old March 19th, 2008, 07:45 PM
cydonio cydonio is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 4 cydonio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 13 sec
Reputation Power: 0
Thanks for that Jim.
That's what I call a good answer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Advanced file system question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway