SUMMARY - reading label on CD-ROM

From: Kandi Kirk-Wilt (ccrwest!
Date: Wed Aug 14 1991 - 14:32:46 CDT

Original question:
I am in the process of writing a suid program which will allow normal users to mount
cd-roms. I know their are lots of programs available but I have some unique circum-
stances thus, I am working on my own. One of the things I would like to be able to
do is determine what cd is mounted.

Does anyone know if there is a way to read the header of a cd-rom to determine if it
is a Answerbook, SUNOS, etc... cd-rom? I need to be able to read the label from
cd-rom's mounted as 4.2 or hsfs filesystems since the Answerbook is 4.2 and the SUNOS
ones are hsfs.

Any suggestions would be appreciated.

As a result of the above question I received many requests for copies of my
code as well as requests for a summary. I only received two responses with
suggestions and they are as follows:


man cdromio, combined with reading some portion of the HSFS spec will
help. Seriously, there is a table of contents you can grab to see what
is going on. You can also read the first block, and see if it looks
like a UFS superblock by magic number, and decide that the disk is HSFS

Kevin Sheehan
Optimation Software Engineering

I took a quick look at man cdromio and found that I would need to spend a bit
more time looking at it when I get more time. I am not sure how to get a
copy of the HSFS spec. This is probably the way I will go when time allows
since priorities have shifted since I first wrote my request.

If you are using the freely available AMD automounter (which is highly
recommended - it's far better than the Sun automounter) you can avoid insecure
setuid programs and use the "program" filesystem type it supports. Basically,
it allows you to specify the mount and unmount programs - I use the shell
script at the end of this message for the mount program.

As for distinguishing between HSFS and 4.2 filesystems, you can use the df
command. On a 4.2 filesystem it will tell you how many blocks are in use, etc.
- on anything else, it will say:

        $ df /dev/sr0 > /dev/null
        df: /dev/sr0: not a UNIX filesystem

So you can check stderr for any output, or check stdout for the '%' character
to test for a 4.2 filesystem.


#!/bin/sh -
# Mount command for CD-ROM
# invoke from AMD as "mountcdrom /dev/sr0 ${fs}" or similar
exec 2>/dev/console


if [ $# -lt 2 ]; then
  exit $EINVAL

OPTS="${3+-o $3}"

test -b "$DEV" || exit $ENOENT

test -d "$FS" || mkdir -p "$FS" || exit $NOENT

df "$DEV" 2>/dev/null | grep % > /dev/null || HSFS="-t hsfs"

mount -r $HSFS $OPTS "$DEV" "$FS" || exit $ENXIO

exit 0

This looked like something to look into also however, I haven't yet had a
chance to check it out.

Sorry no code to share at this time.

Kandi Kirk-Wilt ccrwest!
Institute for Defense Analyses (619) 455-9400
Center for Communications Research - La Jolla (619) 455-1327 (FAX)
4350 Executive Drive Suite 135
San Diego, Ca. 92121

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:20 CDT