• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get physical HDD from path? (Unix)

 
Justin Thomas
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic