• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get physical HDD from path? (Unix)

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic