cdcheck Command

Purpose

Asks cdromd daemon information about a device.

Syntax

cdcheck { -a | -m | -u | -e } [ -q ] [ -h | -? ] DeviceName

Description

The cdcheck command sends an appropriate command to the cdromd daemon to get information on a media or a device depending on the flag used.

The cdcheck command returns a zero (True) exit value and prints a message on stdout if the specified condition is true. Otherwise, the cdcheck command returns a nonzero (False) exit value and prints an error message on stderr.

To check if a device is managed by cdromd daemon, use the cdcheck command with the -a flag. If the cdromd daemon is running and the specified device is in its device list, the cdcheck -a command will return with a zero (True) exit value after printing the following message on stdout:
       cd<x> is managed by cdromd.
Note: An exit value of zero (True) with the -a flag means that a media will be automatically mounted when it is inserted. It does not mean that a media is currently mounted.
To check if a media is present and was mounted by cdromd daemon, use the cdcheck command with the -m flag. When a media is inserted in a drive, it can take several seconds or tens of seconds before it become ready and mounted. The cdcheck -m command waits until the end of the mount operation by the cdromd daemon. If this operation is successfull, the cdcheck -m command returns with a zero (True) exit value after printing the mount point on stdout.
Note: If the media is damaged and can't be mounted by the cdromd daemon, the cdcheck -m command returns a nonzero (False) exit value and prints an error message on stderr.
To check if a media is present but was unmounted by the cdumount command, use the cdcheck command with the -u flag. If the cdromd daemon is running and the specified device is in in unmounted state, the cdcheck -u command will return with a zero (True) exit value after printing the following message on stdout:
       cd<x> is not mounted.
To check that there is no media present in the specified device, use the cdcheck command with the -e flag. If the cdromd daemon is running and there is no media present in the drive, the cdcheck -e command will return with a zero (True) exit value after printing the following message on stdout:
       No media present in cd<x>.

When using cdcheck in shell scripts, the -q flag can be added to the cdcheck command so that no messages are printed on stdout and stderr. The only exception is the cdcheck command with the -m flag, which always prints the mount point on stdout so that the shell script can get this mount point.

Flags

Item Description
-a Checks if a device is managed by cdromd.
-e Checks if a media has been ejected from a device.
-h or -? Displays the command usage message.
-m Checks if a media is mounted on a device.
-q Specifies silent mode: Doesn't print any information or error message.
Note: If -q is used with the -m flag, the mount point will be printed to stdout.
-u Checks if a media is not mounted on a device.
DeviceName Specifies the name of the device.

Exit Status

This command returns the following exit values:

0
answer = yes.
>0
answer = no or error.

Examples

  1. To ask cdromd if cd0 is managed enter:
    cdcheck -a cd0
  2. To ask cdromd if a media is mounted on cd1 without any printed error messages, enter:
    cdcheck -m -q cd1
  3. To ask cdromd if a media is not mounted on cd1 enter:
          cdcheck -u cd1
  4. To ask cdromd if a media is not present on cd0 enter:
    cdcheck -e cd0
  5. Shell script example:
    DEVICE=$1
    
    if [ cdcheck -a -q "$DEVICE" ]; then
        AUTO_MOUNT="ON"
    else
        AUTO_MOUNT="OFF"
    fi
    
    # Other initializations
    # ...
    
    if [ "$AUTO_MOUNT" = "ON" ]; then
        MOUNT_POINT=`cdcheck -m -q $DEVICE`
    else
        MOUNT_POINT="/tmp/MyProg_$$"
        mount -rv cdrfs $DEVICE $MOUNT_POINT
    fi
    if [ $? -ne 0 ]; then
        echo "mount $DEVICE failed"
        exit 1
    fi
    
    # Now extract data from $MOUNT_POINT...
    # ...
    
    
    # End of processing. Umount the media
    if [ "$AUTO_MOUNT" = "ON" ]; then
        cdeject -q $DEVICE
    else
        unmount $DEVICE
    fi
    if [ $? -ne 0 ]; then
        echo "unmount $DEVICE failed"
        exit 1
    fi