3

When I burn a DVD with Brasero, it asks me whether I want to close the DVD after burn or leave it open to add files later.

How do I check whether a DVD is read-only or it's still writable? I am talking of course of DVD-R, not DVD-RW disks.

I am looking for some kind of console command to check whether the disk is closed or not.

ThunderBird
  • 1,915
  • 13
  • 19
  • 31
David
  • 1
  • 1
  • 2

2 Answers2

1

You can use cdrskin to get this information. Here are the two options that might be of use (from man cdrskin, emphasis mine):

-minfo
Print information about the loaded media. This includes media type, writability state, and a quite readable table of content.
-msinfo
Retrieve multi-session info for preparing a follow-up session by option -C of programs mkisofs, genisoimage, or xorriso -as mkisofs. Print result to standard output. This option redirects to stderr all message output except the one of option --tell_media_space and its own result string, which consists of two numbers. The result string shall be used as argument of option -C with said programs. It gives the start address of the most recent session and the predicted start address of the next session to be appended. The string is empty if the most recent session was not written with option -multi. To have a chance for working on overwriteable media, this option has to be accompanied by option --grow_overwriteable_iso.

The manpage also has a list of examples, one of which shows the use of -msinfo:

Get multi-session info for option -C of program mkisofs:

c_values=$(cdrskin dev=/dev/hdc -msinfo 2>/dev/null)
mkisofs ... -C "$c_values" ...

To sum it up, you should be able to test for a CD/DVD to be appendable with the following script:

#!/bin/bash
if [ "$(cdrskin -msinfo 2>/dev/null)" ]; then
  echo "Medium is appendable"
else
  echo "Medium is blank or closed"
fi

Oneliner version:

[ "$(cdrskin -msinfo 2>/dev/null)" ] && echo "appendable" || echo "blank or closed"

cdrskin takes the default drive which should be fine for nearly everyone. If it uses the wrong device, specify it explicitly with the option e.g. dev=/dev/sr1. If in doubt you can display information about a device with the option -checkdrive.

dessert
  • 39,392
  • 12
  • 115
  • 163
  • 1
    The test works for me with all three medium states. But the messages are wrong. Rather: "Medium is appendable" and "Medium is blank or closed". Blank is unused and writable. Appendable is written and still writable. Closed is written and not writable any more. Be aware that wodim happily reads -msinfo from closed DVD-R but not from blank ones. – Thomas Schmitt Feb 08 '18 at 20:22
  • Giving no device address is problematic if there is more than one optical drive. libburn aquires all of them, groping each a little bit, in order to get a list of drives and their names. Then the first one is used and the others get released again. If you give a drive explicitely, then only that one is touched. On GNU/Linux /dev/sr0 is nowadays very surely the first drive. To get a list of drives run: cdrskin --devices – Thomas Schmitt Feb 14 '18 at 08:52
1

dessert's test exactly answers David's question.

But as said im my comment, we have three possible states for DVD-R. To distinguish them all, one may use cdrskin option -minfo. (Note well: -minfo without the "s" of -msinfo.)

cdrskin dev=/dev/sr0 -minfo 2>/dev/null | grep '^disk status:'

This should yield 4 possible text results on standard output.

With a blank medium (unused and writable):

disk status:              empty

With an appendable medium (written and still writable):

disk status:              incomplete/appendable

With a closed medium (written and not writable any more):

disk status:              complete

As fourth possible result, if something goes wrong with accessing the medium, no text at all will appear. In this case you should repeat the run without 2>/dev/null | grep '^disk status:' in order to see all messages.

(I use /dev/sr0 in the example, because /dev/hdc is out of fashion as device name since at least kernel version 3.)

dessert
  • 39,392
  • 12
  • 115
  • 163
Thomas Schmitt
  • 836
  • 4
  • 5
  • I just realized `cdrskin` is sapient enough to work fine without specifying a device at all – I guess it just uses the usual symlink `/dev/cdrom` or the like internally. I adapted my answer, got rid of all the (non-quoted) `/dev/` stuff and added a paragraph for the 1%. – dessert Feb 13 '18 at 08:43