It's not a secret anymore!*
The moose likes Beginning Java and the fly likes How to get physical HDD from path? (Unix) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get physical HDD from path? (Unix)" Watch "How to get physical HDD from path? (Unix)" New topic
Author

How to get physical HDD from path? (Unix)

Justin Thomas
Ranch Hand

Joined: Mar 08, 2012
Posts: 62
How to get physical HDD from path? (Unix)

There is a java program that executes external programms on various physical disks. What I want to do is to queue tasks (so only 1 task is being done on 1 physical disk). I have a String path to the executable. How to learn to which HDD that executable belongs? (We're talking Ubuntu here).

Thank you very much in advance for any help with this.

---
ps: I am not looking for any internal hdd serial number, I'm just looking for some simple solution

--
edit: I found this: http://www.cyberciti.biz/faq/linux-unix-command-findout-on-which-partition-file-directory-exits and this: http://tuxtweaks.com/2010/03/command-line-basics-list-hard-drives-by-uuid/
However, is there a way to do it without OS dependent functions (purely in java)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

First, read the mtab file (usually stored in /etc/) to find all the current mount points and their devices. Then create a File object, and get its parent until you've found a match. The resulting device tells you which hard drive it is, but it can also be a virtual device such as proc or udev.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Justin Thomas wrote:
edit: I found this: http://www.cyberciti.biz/faq/linux-unix-command-findout-on-which-partition-file-directory-exits and this: http://tuxtweaks.com/2010/03/command-line-basics-list-hard-drives-by-uuid/
However, is there a way to do it without OS dependent functions (purely in java)


Unfortunately, I don't think you can. The unix filesystem shows up as a single filesystem, starting from the root directory.... and there doesn't seem to be a way to get the mounts from the core libs.

For Windows, you can get all the roots with the listRoots() method call -- in which case, it returns a root file for each drive letter.

Henry
Justin Thomas
Ranch Hand

Joined: Mar 08, 2012
Posts: 62
Thank you for your replies. I already coded the part to get UUID. Now I need to figure out how to synchronize the access... I'll think about it; maybe I will be able to do it alone, without bothering you again for help.

--
for ppl who use "Search" and find this, the code is this:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get physical HDD from path? (Unix)
 
Similar Threads
Old hard disk not visible
How can I run this program?
SnowLeopard+NTFS
How to get drives info
Physical Path of a file