• 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

Finding disk drives programmatically

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am programming in Java 1.6, running on a Fedora 7 Linux system. I need to be able to find the disk drives in the system programmatically. Is there a straightforward way to do this in Java? (Sorry, I'm not sure if this belongs in a Java forum or Linux forum).

Via the Linux command line, I've found that I can run the command "cat /proc/scsi/sg/device_strs", which gives me a list of not only my disk drives, but also my dvd-rom. I can parse that output, looking for the string "ATA" to find the disk drive, that position in the list will relate to the number in the /dev/sg? list (zero-based) - for example I have three entries listed as ATA, ATA, and non-ATA, which relate to /dev/sg0, /dev/sg1, and /dev/sg2 respectively. I know that the /dev/sg0 and /dev/sg1 devices are my disk drives since they are listed as ATA.

That approach is certainly doable by running system commands with Java and parsing the results. Before I go down that path, I want to be sure there isn't an easier way to accomplish the same thing. Or if there is no support with Java itself, perhaps there is a better way using Linux commands to get the same information.

Thanks,
Beth
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beth -

Originally posted by Beth Hechanova:
..... I can parse that output, looking for .....



I would not do it like that. Everything on a Unix system is a file. So:



And read it like a normal file (which it is).

Guy
 
Beth Hechanova
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't know that - thanks... that looks much easier.

Beth
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beth - I am really guessing at what you actually need to accomplish.

What is wrong with reading '/etc/mtab' for the information you need? (What happens if a device has multiple partitions?).

Guy
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about 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