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,963
  • 13
  • 22
  • 31
David
  • 1

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
  • 40,956
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
  • 40,956