4

After looking at this question here: Get all DVD drives in Java

It seems to me that with JAVA 7 there is a way to discern between hard drives and dvd/cd drives when there is cd/dvd inside the drive. But that one method fails if the drive is empty.

My question is: Is there now 4 years later a method to discern which of the drives are hard drives and which are cd/dvd/blueray drives even if those drives have no cd/dvd/blueray inside?

Edit: The target OS for this is Linux

Community
  • 1
  • 1
Thomas
  • 2,886
  • 3
  • 34
  • 78
  • @the close voter I would expect at least some comment as to why a close. The only possibility I see is that you see this as a duplicate to the question I mentioned in my question. Although I made it clear I think how this question is different from that one, as I'm asking if the one seeming weakness (at least if I understood the answer to that one correct that it was a weakness) is solved after over 4 years in between (and new editions). So would be interesting for the reason behind the close vote. tnx. – Thomas Nov 25 '15 at 06:43
  • Answer is still operating system specific. Which OS are you targeting? – BalusC Dec 04 '15 at 08:10
  • Ah good point. thought cross plattform is possible there but just reread. will update my question there. Target OS is linux – Thomas Dec 04 '15 at 08:19
  • Have you tried java-avm? http://java-avm.sourceforge.net/ – andrucz Dec 07 '15 at 15:13
  • nope didnt see that one before though – Thomas Dec 07 '15 at 15:38

2 Answers2

2

Can you run system commands, or must this be pure Java? If you can run system commands, try:

Runtime.getRuntime().exec("more /proc/sys/dev/cdrom/info");

This will give you something like:

CD-ROM information, Id: cdrom.c 3.20 2003/12/17

drive name:     sr0
drive speed:        24
drive # of slots:   1
Can close tray:     1
Can open tray:      1
Can lock tray:      1
Can change speed:   1
Can select disk:    0
Can read multisession:  1
Can read MCN:       1
Reports media changed:  1
Can play audio:     1
Can write CD-R:     1
Can write CD-RW:    1
Can read DVD:       1
Can write DVD-R:    1
Can write DVD-RAM:  1
Can read MRW:       1
Can write MRW:      1
Can write RAM:      1

For more comprehensive info, you could run:

Runtime.getRuntime().exec("hwinfo --cdrom");

In there should be a line like:

Feature: CD-R, CD-RW, DVD-R, DVDRAM

If you have a blu-ray drive in the system, I would expect BDROM, BD-ROM, BD-R, BD-RW or something similar

Fallso
  • 1,311
  • 1
  • 9
  • 18
  • Took me a moment to get what the program does. So it only displays cdrom drives (nice!). Does it also work nicely with 2 drives installed? Also as it is dev/cdrom/info does it work also for blue ray drives? (only saw dvd/cd in that output) and is it limited to specific linux builds/versions or is it a general program? – Thomas Dec 04 '15 at 10:52
  • I've amended my answer to include information about blu ray drives. Both commands should be present on every Linux system (I've tested on SLES, CentOS locally, but I know Ubuntu has it too). – Fallso Dec 04 '15 at 11:13
  • Interesting tnx. will +1 this for now and wait a few days if something else comes up (else I will accept this one). – Thomas Dec 04 '15 at 11:20
0

hwinfo --cdrom will provide considerably more complete information than /proc/sys/dev/cdrom/info.

Here is an example from a system with an internal DVD-RW drive, an external compact DVD-RW drive, and an external full-size DVD-RW drive. Note an important parsing detail of /proc/sys/dev/cdrom/info: it adds columns, not blocks, for multiple devices. Also note the top line, which indicates that the code it relies on was written quite a while ago:

CD-ROM information, Id: cdrom.c 3.20 2003/12/17

drive name:         sr2 sr1 sr0
drive speed:        48  8   40
drive # of slots:   1   1   1
Can close tray:     1   1   1
Can open tray:      1   1   1
Can lock tray:      1   1   1
Can change speed:   1   1   1
Can select disk:    0   0   0
Can read multisession:  1   1   1
Can read MCN:       1   1   1
Reports media changed:  1   1   1
Can play audio:     1   1   1
Can write CD-R:     1   1   1
Can write CD-RW:    1   1   1
Can read DVD:       1   1   1
Can write DVD-R:    1   1   1
Can write DVD-RAM:  1   1   1
Can read MRW:       1   0   1
Can write MRW:      1   0   1
Can write RAM:      1   1   1

Note that the compact drive is slower, and does not support Mount Rainier packet writing (MRW). Also note that these drives are listed as supporting DVD-R (read: "DVD dash R"; there is no such thing as "DVD minus R"), but there is no row to indicate whether or not they support DVD+R ("DVD plus R"). It is likely that at least one of these drives does.

Using "hwinfo --cdrom" to get more info, here are its matching feature lines (much more data is available; it is stripped here for brevity and clarity:

Features: CD-R, CD-RW, DVD, DVD-R, DVD-RW, DVD-R DL, DVD+R, DVD+RW, DVD+R DL, DVD-RAM, MRW, MRW-W
Features: CD-R, CD-RW, DVD, DVD-R, DVD-RW, DVD-R DL, DVD+R, DVD+RW, DVD+R DL, DVD-RAM
Features: CD-R, CD-RW, DVD, DVD-R, DVD-RW, DVD-R DL, DVD+R, DVD+RW, DVD+R DL, DVD-RAM, MRW, MRW-W

We now see a number of important points, to which you are probably saying, "Oh, that." Yes, oh that. Oh, that format war between DVD-R and DVD-RW. Oh, dual-layer discs. Oh, DVD-RAM. Oh, CD-changers with multi-disc magazines ("can select disk").

I'll see if I can pull data from a BD-ROM drive later and update this. But the upshot is that you are probably going to have to interrogate the system several different ways to get complete results.

Media checks complicate the matter even further. In particular, trying to tell the difference between a defective disc, a blank disc, a valid disc that isn't going to work in that particular drive, an open tray, and various other conditions can require getting familiar with sending low-level IOCTL commands to the device. This can be done in pretty much any language, but it tends to feel pretty foreign to people who haven't written some systems software in C.

breakpoint
  • 916
  • 9
  • 16