setcd-1.5/0040755000175000001440000000000007735646316011514 5ustar daviduserssetcd-1.5/Makefile0100644000175000001440000000152706760570101013137 0ustar davidusers# Makefile for setcd # rely on default rules of GNU make prefix=/usr/local source=$(HOME)/cdrom revision=1.4 CC=gcc CFLAGS=-g -Wall INSTALL=install default: setcd cdrom-standard.ps install: setcd cdrom-standard.ps $(INSTALL) -s -m 0755 setcd $(prefix)/bin/setcd $(INSTALL) -m 0644 setcd.1 $(prefix)/man/man1 $(INSTALL) -m 0644 cdrom-standard.ps $(prefix)/doc/setcd cdrom-standard.ps: /usr/src/linux/Documentation/cdrom/cdrom-standard.tex ln -sf /usr/src/linux/Documentation/cdrom/cdrom-standard.tex . latex cdrom-standard.tex latex cdrom-standard.tex dvips cdrom-standard -r0 -o distclean: rm -f cdrom-standard.{tex,log,ps,aux,dvi} rm -f setcd sources: co -p$(revision) $(source)/setcd.c > setcd.c co -p$(revision) $(source)/setcd.1 > setcd.1 rcs2log $(source)/setcd.c | \ sed 's/davidav.our.home/ElseWare.cistron.nl/' > ChangeLog setcd-1.5/README0100644000175000001440000000076207735634210012364 0ustar davidusersSetcd is a utility to control cdrom device behaviour for the new style unfirm cdrom interface. This README for setcd is for non-Debian distributions. Consider moving to Debian. It's great. However, you can compile things from here as well. Just say make setcd make install assuming you have GNU make, gcc, install, TeX, latex, dvips and the Linux kernel under /usr/src/linux. I didn't test it, but it should work all right. Good luck, ---david David van Leeuwen setcd-1.5/setcd.10100644000175000001440000002522706760570107012674 0ustar davidusers.\" Process this file with .\" groff -man -Tascii foo.1 .\" $Id: setcd.1,v 1.1 1997/02/23 17:11:34 david Exp $ .\" " .TH SETCD 1 "February 1997" Linux "User Manuals" .SH NAME setcd \- set various flags to control the behaviour of your cdrom device. .SH SYNOPSIS .B setcd [-hirs] [-ceflot .IB 0|1 "] [-dx" .IB arg "]" .BI [ device .IB ... ] .SH DESCRIPTION .B Setcd is a program that allows you to control the behaviour of your Linux cdrom device. There are a number of ways you can control the behaviour of your cdrom drive: should it try to close the tray upon mounting a cdrom when your happened to have left the tray open, or should it eject the tray upon unmounting the cdrom? Should it lock the door when some process uses the cdrom or not? Should the kernel try to ensure that there actually is a cd in the drive, and that it is of the right type (i.e., a data cd in case of a mount, or an audio cd in case of a play operation)? .B Setcd can also inform you on the current configuration of the drive, and can give information on the status of the drive; whether or not a cd is loaded, what the type is (audio/data), and some basic information of the disc (total playing time for audio / volume name for data). .B Setcd can list/probe/configure several cdrom devices at once, independent of their low-level implementation. Finally, .B setcd can select a disc in a multi-disc cdrom player (juke-box), and set the operating speed of the player. .SH OPTIONS Options come in three flavours: without arguments, with one boolean type argument and with a numeric argument. For boolean type arguments, .I 0 means `clear option,' and .I 1 means `set option.' Several options may be given at the same time. Following the options, a list of cdrom device names can be given, for which the operations will take place. If no device is given, the default value .I /dev/cdrom will be used. .IP "-c 0|1" Clear/set auto-close flag. If the cdrom device is opened for data access (e.g., using .BR mount (1) ) and the tray is found open, an attempt is made to close the tray. This is considered `desired' behaviour but people with old cd player programs may disagree. A cd player that opens the device at regular intervals would have problems leaving the tray ejected, if there were no special arrangements taken to support cd player programs. In the new interface they can specify in their .BR open (2) call that they wish to open the device just for issuing .BR ioctl (2) calls. Instead of clearing this option, consider upgrading your cd player program. .IP "-d drive" Selects the cd in slot number .I drive in case the cdrom player is a juke-box model. .IP "-e 0|1" Clear/set .SM EJECT_SW flag. This is basically identical to controlling the auto-close and auto-open flags simultaneously. The EJECT_SW flag enables closing the tray upon mounting a cdrom, and opening the tray upon unmounting it again. The option is included to support the old-style cdrom behaviour (many low-level driver have implemented the ioctl-command connected to this flag). .IP "-f 0|1" Clear/set use-fflags flag. The new cdrom interface specifies a special interpretation of the O_NONBLOCK option in the .BR open (2) call for cdrom devices. When this option is used, and the use-fflags option is set, the cdrom driver will not attempt to do anything to make the open() call more successful; the tray is not closed upon opening, no cd type checking is performed, in fact the open() call will .I always succeed. This allows user-level programs to issue ioctl() commands regardless of the state in which the drive is. Setting this option is the preferred state. Users may wish to clear this option in case they have an old cd player program that does not support the O_NONBLOCK option, but have a new style cdrom driver (i.e., IDE, SCSI or cm206). .IP "-h" Print copyright information and terse help. .IP "-i" Give information on the cdrom drive. The status of the drive is checked, possible outcome is (a) no disc inserted, (b) tray is open, (c) drive is not ready, (d) disc is found. In the last case, an attempt is made to determine the type of disc (audio or one of 4 types of data disc), and for both "audio" and "data disc type 1|2" some additional information is given. Currently for data discs this is the volume name, publisher and data preparer. For audio discs the extra information is very terse, you may enjoy a full-fledged audio cd player program better. .IP "-l 0|1" Clear/set locking flag. When this flag is set, the drive door is locked while the cdrom devices is opened, e.g., when a cdrom is mounted. Not locking the door is undesired behaviour, because this may lead to file system corruption if a cdrom is removed while being mounted. .IP "-o 0|1" Clear/set auto-open flag. When this flag is set, and the last process that uses the cdrom device closes the device, an attempt is made to eject the tray. Care is taken, that processes that used the O_NONBLOCK option in opening the device, will not cause such an auto-eject. Yet, we consider this auto-eject behaviour undesired. In most cases, this behaviour is combined with the auto-close behaviour, in which case the option "-e" is the preferred usage. .IP "-r" Resets all options to a default behaviour. Using this option is equivalent to "-c1 -f1 -l1 -o0 -t1", i.e., all options set in a way we consider `desired.' For the current development kernel, this is identical to the default settings apart from the type-checking flag, because this flag relies on a very modern kernel, libc and cdrom players. .IP "-s" Gives the current status of the option flags. Information on the following flag settings is giver, one per line: (a) auto-close, (b) auto-open, (c) use-fflags, (d) tray-locking, (e) type-checking. .IP "-t 0|1" Clear/set cd type checking flag. When this option is set, the kernel will check the type of cd upon various operations. A system error "Wrong medium type" is given if the generic cdrom driver receives an open-for-data call while an audio cd is inside the drive, or a playing command is received while a data disc is in the drive. This behaviour is considered superior over kernel time-outs and other implementation-dependent behaviour found on the old-style cdrom interface. However, this feature is relatively new, and requires kernel version 2.1.27 or later, and libc-5.4.24 or later. Moreover, if you use an audio cd player program, it .I must use the O_NONBLOCK open flag (see option "-f"). These stringent constraints made the current kernels to have this option turned off, while people using .B setcd are considered modern and progressive enough to have this option selected by default using the "-r" option. .IP "-x speed" Sets the head-rate of the cdrom player to .I speed times 150 KB/sec, or .I speed times real-time audio playback. The special value .I 0 is interpreted as auto-selection: data cd's are read at maximum head-rate, while audio cd's are played at normal speed. There are a few reasons for having the speed to be selectable. Badly pressed cdroms may benefit from less-than-maximum head rate. Modern cdrom drives can obtain very high head rates (up to 16 times audio speed is common), but these drives tend to make an annoyingly loud noise. A lower speed may reduce this. Finally, although the audio low-pass filters probably aren't designed for it, more than real-time playback of audio might be used for high-speed copying of audio tracks. .SH HISTORY Traditionally, up to the 2.0 Linux kernel line, the behaviour of the cdrom access was determined by the low-level driver implementation, which varied between different brands of drives. Since kernel 1.3.late, an extra interface layer has been defined between the kernel and user level programs, .i /usr/src/linux/Documentation/cdrom/cdrom-standard.tex, that makes the behaviour of the cdrom drive independent of the low-level driver. The first driver to respect the new interface was, surprisingly, the outdated Philips/LMS cm206 in kernel 2.0. Nowadays, all new cdrom drives are either IDE or SCSI, and these drivers support the new cdrom interface in the kernel 2.1 line. We hope that the other `old' cdrom divers will eventually support the new interface, so that the behaviour of Linux cdrom drives is truly uniform. The new cdrom interface level was actually inspired after writing a volume daemon that automatically mounts a cdrom at the location .RI /cdrom/ volume upon insertion of the disc. I then found out that there was a need for finding out the status of the drive without trying to read data, and that the uniformity of cdrom drivers was a mess. The volume daemon has not been finished yet, but progress has been made in convincing the Linux cdrom driver community to comply to the proposed standard. .SH DIGNOSTICS Setting or clearing an option will result in a message indicating the new status of that option. Operations not supported by the underlying hardware, e.g., disc selection, will result in an error condition. Several other ioctls may result an error condition if the low-level drivers don't support that particular ioctl. .SH FILES .I /dev/cdrom .RS The default cdrom device. In most installations, this is a symbolic link to the only cdrom device on the system. In multi cdrom systems, the cdrom devices have to be explicitly named on the command line. .RE .I /usr/include/linux/ucdrom.h .RS The header file for the new cdrom interface. Please consult this file first if you want to use ioctl calls in your program to control the cdrom drives. Maybe you can get want you want by controlling the behaviour of the cdrom, instead of issuing direct commands. At any rate, use the O_NONBLOCK option if you open the device for ioctl-commanding. .RE .I /usr/include/fcntl.h .RS Location where O_NONBLOCK is defined. .RE .I /usr/src/linux/Documentation/cdrom/cdrom-standard.tex .RS A piece of proza originally written for cdrom driver developers. However, cd player program developers may benefit from the explanation of new ioctls defined in the new cdrom interface. You can view the documentation by issuing .RS latex cdrom-standard.tex .br xdvi cdrom-standard .RE I am sorry that you'll have to install TeX, latex and xdvi first, but you may have success in reading the plain latex source; after all, it is .SM ASCII. .SH BUGS Long-style options are not supported. .SH "TO DO" CD medium catalog number could be given for audio cd's. However, not many cd's bare that kind of information. Somehow convince the `old-style' cdrom driver developers to adapt their drivers to the new interface, it shouldn't be that much work. Write texinfo documentation. .SH AUTHOR .B Setcd is written by David A. van Leeuwen , the author of the earlier mentioned new cdrom interface and the cm206 cdrom driver. .SH "SEE ALSO" .BR mount (1), .BR open (2), .BR ioctl (2). setcd-1.5/setcd.c0100644000175000001440000002066306760570107012755 0ustar davidusers/* Setcd.c: Set various flags to control the behaviour of your cdrom device. (c) 1997 David A. van Leeuwen $Id: setcd.c,v 1.4 1999/08/24 19:07:34 david Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include /* tolower */ #include /* lseek, read */ #include /* strncmp */ #include /* ioctl */ #include #ifndef CDC_CLOSE_TRAY /* moved into cdrom.h... */ #include #endif #include #define REVISION "$Revision: 1.4 $" void usage(FILE * f, char * s) { fprintf(f, "Usage: %s [-hirs] [-ceflot 0|1] [-dx arg] [device] ...\n\n\t" "-h print this message and copyright\n\t" "-i print information about cdrom device\n\t" "-s print status of cdrom device options\n\t" "-r reset option flags to preferred default\n\t" "-c * set auto-close flag: close tray if cdrom device is opened\n\t" "-e * set auto-eject/auto-close behaviour\n\t" "-f * use file flag O_NONBLOCK in open() call\n\t" "-l * lock door if cdrom device is opened\n\t" "-o * set auto_open flag: open tray if cdrom device is released\n\t" "-t * enable cdrom type checking (audio/data)\n\t" "-d n select disc number n in jukebox\n\t" "-x n set speed of cdrom n times 150 KB/s (normal audio)\n", s); } #define SHOW(bit, text) if(bit & mask) \ printf(" %-20s %s\n", text ":", (bit & flags) ? "set" : "cleared"); void print_options(int flags, int mask) { SHOW(CDO_AUTO_CLOSE, "Auto close tray"); SHOW(CDO_AUTO_EJECT, "Auto open tray"); SHOW(CDO_USE_FFLAGS, "Use O_NONBLOCK flag"); SHOW(CDO_LOCK, "Lock tray"); SHOW(CDO_CHECK_TYPE, "Check CD type"); } #undef SHOW void print_audio_info(int fd) { struct cdrom_tochdr head; struct cdrom_tocentry entry; int last, first; if (ioctl(fd, CDROMREADTOCHDR, &head)<0) { perror("Can't read Table of Contents header"); return; } last = head.cdth_trk1; first = head.cdth_trk0; printf(" %d Track%s, %d--%d\n", last-first+1, (last==first) ? "" : "s", first, last); entry.cdte_format=CDROM_MSF; entry.cdte_track = 0xAA; if (ioctl(fd, CDROMREADTOCENTRY, &entry)<0) { perror("can't read last track entry"); return; } printf(" Total playing time %d minutes and %d seconds\n", entry.cdte_addr.msf.minute, entry.cdte_addr.msf.second); } char * stripped(char * s, int size, int lower) { char *i, * end = s+size-1; while (*end == ' ') --end; if (end == s+size-1) *end='\0'; else *++end = '\0'; if (lower) for (i=s+1; iid, ISO_STANDARD_ID, sizeof vdp->id)) { /* found an iso-cdrom */ printf(" Volume name: %s\n", stripped(vdp->volume_id, 32, 1)); printf(" Publisher: %s\n", stripped(vdp->publisher_id, 128, 0)); printf(" Data preparer: %s\n", stripped(vdp->preparer_id, 128, 0)); break; } } } void print_info(int fd) { int status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); if (status<0) { perror("can't read drive status"); fprintf(stderr, "%d\n", status); exit (-8); } switch(status) { case CDS_NO_INFO: printf(" No information on drive status is available\n"); break; case CDS_NO_DISC: printf(" No disc is inserted\n"); break; case CDS_TRAY_OPEN: printf(" CD tray is open\n"); break; case CDS_DRIVE_NOT_READY: printf(" Drive is not ready\n"); break; case CDS_DISC_OK: printf(" Disc found in drive:"); status=ioctl(fd, CDROM_DISC_STATUS); if (status < 0) { fprintf(stderr, "%d\n", status); break; } switch (status) { #ifdef CDS_MIXED case CDS_MIXED: printf(" mixed type CD (data/audio)\n"); print_audio_info(fd); print_data_info(fd); break; #endif case CDS_AUDIO: printf(" audio disc\n"); print_audio_info(fd); break; case CDS_DATA_1: case CDS_DATA_2: printf(" data disc type %d\n", status-CDS_DATA_1+1); print_data_info(fd); break; case CDS_XA_2_1: case CDS_XA_2_2: printf(" XA data disc type %d\n", status-CDS_XA_2_1+1); print_data_info(fd); break; default: printf("Unknown status %d\n", status); } break; default: printf(" Unknow drive status return value %d\n", status); } } int main(int ac, char ** av) { char * device = "/dev/cdrom"; int fd, c; int status=0, reset=0, info=0, typecheck=-1, speed=-1, auto_close=-1, auto_open=-1, fflags=-1, lock=-1, disc=-1; int set=0, clear=0, flags=0; extern int optind, optopt; extern char * optarg; if (ac == 1) { usage(stderr, av[0]); exit(-1); } while((c=getopt(ac, av, "c:d:e:f:hil:o:rst:x:"))!=EOF) { switch(c) { case 'c': auto_close=atoi(optarg); break; case 'd': disc=atoi(optarg); break; case 'f': fflags=atoi(optarg); break; case 'e': auto_close=auto_open=atoi(optarg); break; case 'i': info=1; break; case 'l': lock=atoi(optarg); break; case 'o': auto_open=atoi(optarg); break; case 'r': reset=1; /* fall into next line */ case 's': status=1; break; case 't': typecheck=atoi(optarg); break; case 'x': speed=atoi(optarg); break; case 'h': printf("Setcd. Control the behaviour of a cdrom device.\n" "(c) 1997 David A. van Leeuwen\n" REVISION "\n\n"); usage(stdout, av[0]); exit(0); default: usage(stderr, av[0]); exit(-1); } } do { if (ac > optind) device = av[optind]; fd = open(device, O_RDONLY | O_NONBLOCK); if (fd < 0) { perror("Can't open device"); exit(-2); } printf("%s:\n", device); #define FLAG(i,opt) if (i>=0) { set += opt*(i>0); clear += opt*!i; } if (reset) { set = CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK | CDO_CHECK_TYPE; clear = CDO_AUTO_EJECT; /* nasty behaviour */ } FLAG(auto_close, CDO_AUTO_CLOSE); FLAG(auto_open, CDO_AUTO_EJECT); FLAG(fflags, CDO_USE_FFLAGS); FLAG(lock, CDO_LOCK); FLAG(typecheck, CDO_CHECK_TYPE); #undef FLAG if (set && (flags=ioctl(fd, CDROM_SET_OPTIONS, set))<0) { perror("can't set options"); exit(-3); } if (clear && (flags=ioctl(fd, CDROM_CLEAR_OPTIONS, clear))<0) { perror("can't clear options"); exit(-4); } if (!flags && status && (flags=ioctl(fd, CDROM_SET_OPTIONS, 0))<0) { perror("can't get options"); exit(-5); } if (set || clear || status) print_options(flags, set | clear | ~0 * status); if (speed>=0) { if (ioctl(fd, CDROM_SELECT_SPEED, speed)<0) { perror("can't set speed"); exit(-6); } else { printf(" Speed set at "); if (!speed) printf("maximum rate / normal audio rate\n"); else printf("%d KB/s (%dx)\n", 150*speed, speed); } } if (disc >= 0) { if ((disc=ioctl(fd, CDROM_SELECT_DISC, disc)) < 0) { perror("can't select disc"); exit(-7); } else printf(" Disc in slot %d selected\n", disc); } if (info) print_info(fd); close(fd); } while (ac > ++optind); return 0; } /* It was not easy to find variable `c-file-style' in emacs info. In fact, I found it in some other .c file. * Local variables: * c-file-style: "K&R" * compile-command: "gcc -Wall setcd.c -o setcd" * End: */ setcd-1.5/setcd.lsm0100644000175000001440000000076607735635046013337 0ustar davidusersBegin3 Title: setcd Version: 1.4 Entered-date: 7 April 1997 Description: Control the behaviour of your cdrom device Keywords: cdrom control generic Author: David A. van Leeuwen Maintained-by: David A. van Leeuwen Primary-site: ftp://ftp.debian.org/debian/pool/main/s/setcd/ Alternate-site: http://www.elseware.nl/linux/setcd/ 10 kB setcd_1.4.tar.gz Original-site: Platform: i386/Linux Copying-policy: GPL End setcd-1.5/ChangeLog0100644000175000001440000000162007735635456013265 0ustar davidusers28 september 2003: * New release. Fix some stray email addresses etc. Tue Aug 24 19:07:34 1999 David A. van Leeuwen * /home/davidav/david/cdrom/setcd.c: Changed ioctl(fd, CDROM_DRIVE_STATUS, 0) into CDSL_CURRENT. (Andreas Degert ) Mon Nov 16 22:27:21 1998 David A. van Leeuwen * /home/davidav/david/cdrom/setcd.c: Changed ucdrom.h dependency Allow for mixed cd-type. Tue Nov 18 21:12:48 1997 David A. van Leeuwen * /home/davidav/david/cdrom/setcd.c: Added some #includes to prevent warnings. Sat Feb 22 18:14:33 1997 David A. van Leeuwen * /home/davidav/david/cdrom/setcd.c: Added select_disc. Allow multiple devices. Use R&R indentation style. Thu Feb 20 21:33:49 1997 David A. van Leeuwen * /home/davidav/david/cdrom/setcd.c: Initial revision setcd-1.5/COPYRIGHT0100644000175000001440000000201707735646316013004 0ustar davidusersSetcd. Set various flags to control the behaviour of your Linux cdrom device. (c) 1997--2003 David A. van Leeuwen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA You should have a copy of the GPL somewhere on your Linux system. On Debian GNU/Linux you can find it in /usr/share/common-licenses/GPL. ---David van Leeuwen