LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2008, 10:13 AM   #1
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 15
given file, determine device


Given a fully-qualified file name, say /home/judy/test/data.bin, how can I determine which device (/dev/???) this file is located on? You may safely assume that the device containing the file will be mounted when I'm doing this. I'm looking to do this in C / C++.

Thanks!!
Judy
 
Old 02-01-2008, 12:25 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 JudyL View Post
Given a fully-qualified file name, say /home/judy/test/data.bin, how can I determine which device (/dev/???) this file is located on? You may safely assume that the device containing the file will be mounted when I'm doing this. I'm looking to do this in C / C++.

Thanks!!
Judy
The mount table (/etc/mtab) gives you what file systems are mounted and their mount point. So you would compare the directories in your path, /home/judy/test/, against /etc/mtab to see what device data.bin is on.

---------------------
Steve Stites
 
Old 02-01-2008, 12:32 PM   #3
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
That lists volumes not physical devices i.e. /dev/sda1, but I can always strip the volume number from the volume to get back to the physical drive.

I was hoping for something simple like a command or function call, but I'll parse that mtab file if nothing easier turns up.

Thanks!!
Judy
 
Old 02-01-2008, 12:34 PM   #4
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
You are looking for stat.

There is a function in the GNU C library (see man stat.h and man 2 stat and info libc's "Filesystem Interface" section)

There is also a GNU coreutils program called 'stat'(man stat)


--jrtayloriv

Last edited by jrtayloriv; 02-01-2008 at 12:39 PM.
 
Old 02-01-2008, 12:45 PM   #5
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jrtayloriv View Post
You are looking for stat.

There is a function in the GNU C library (see man stat.h and man 2 stat and info libc's "Filesystem Interface" section)

There is also a GNU coreutils program called 'stat'(man stat)


--jrtayloriv
stat is definitely it - it identifies the volume and it is easy to backtrack from the volume to the physical device.

Thanks!!
Judy
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How does my computer determine which wireless device to use? drkstr Slackware 9 09-03-2006 03:53 PM
How to determine your boot device haertig Linux - General 3 04-06-2006 07:24 PM
Can't determine modem as device on list Deke1955 Linux - Hardware 1 09-26-2005 12:04 PM
How to determine which disk device is on which controller? vulture99 Linux - Hardware 3 05-05-2005 10:26 PM
How to determine device names yian Linux - General 2 10-21-2002 07:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:01 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