xref: /onnv-gate/usr/src/cmd/cdrw/dumpinfo.c (revision 6540:879cbb7a3e3e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6540Szk194757  * Common Development and Distribution License (the "License").
6*6540Szk194757  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6540Szk194757  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <libintl.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include "msgs.h"
330Sstevel@tonic-gate #include "mmc.h"
340Sstevel@tonic-gate #include "misc_scsi.h"
350Sstevel@tonic-gate #include "device.h"
360Sstevel@tonic-gate #include "main.h"
370Sstevel@tonic-gate #include "util.h"
380Sstevel@tonic-gate #include "toshiba.h"
390Sstevel@tonic-gate 
400Sstevel@tonic-gate void
info(void)410Sstevel@tonic-gate info(void)
420Sstevel@tonic-gate {
43*6540Szk194757 	uchar_t *toc, *p, *conf;
440Sstevel@tonic-gate 	int ret, toc_size;
45*6540Szk194757 	uint_t bsize;
46*6540Szk194757 	size_t cap = 0;
470Sstevel@tonic-gate 	char *msg;
480Sstevel@tonic-gate 	struct track_info *ti;
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	msg = gettext("Cannot read Table of contents\n");
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	get_media_type(target->d_fd);
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	(void) printf(gettext("\nDevice : %.8s %.16s\n"),
550Sstevel@tonic-gate 	    &target->d_inq[8], &target->d_inq[16]);
560Sstevel@tonic-gate 	(void) printf(gettext("Firmware : Rev. %.4s (%.12s)\n"),
570Sstevel@tonic-gate 	    &target->d_inq[32], &target->d_inq[36]);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	if (check_device(target, CHECK_DEVICE_NOT_READY)) {
600Sstevel@tonic-gate 		(void) check_device(target, CHECK_NO_MEDIA |
610Sstevel@tonic-gate 		    EXIT_IF_CHECK_FAILED);
620Sstevel@tonic-gate 		(void) check_device(target, CHECK_DEVICE_NOT_READY |
630Sstevel@tonic-gate 		    EXIT_IF_CHECK_FAILED);
640Sstevel@tonic-gate 	}
65*6540Szk194757 
66*6540Szk194757 	if (verbose != 0) {
67*6540Szk194757 		/*
68*6540Szk194757 		 * Determine the media type by reading the active profile
69*6540Szk194757 		 * from the profile list.
70*6540Szk194757 		 */
71*6540Szk194757 		(void) printf(gettext("Media Type : "));
72*6540Szk194757 
73*6540Szk194757 		conf = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN);
74*6540Szk194757 
75*6540Szk194757 		if (get_configuration(target->d_fd, MMC_FTR_PRFL_LIST,
76*6540Szk194757 		    MMC_FTR_HDR_LEN, conf))
77*6540Szk194757 			print_profile_name(read_scsi16(&conf[6]), 0, 1);
78*6540Szk194757 		else
79*6540Szk194757 			(void) printf(gettext("UNKNOWN\n"));
80*6540Szk194757 
81*6540Szk194757 		free(conf);
82*6540Szk194757 
83*6540Szk194757 		/*
84*6540Szk194757 		 * Get the start address of the last possible lead out.
85*6540Szk194757 		 */
86*6540Szk194757 		cap = get_last_possible_lba(target);
87*6540Szk194757 
88*6540Szk194757 		/*
89*6540Szk194757 		 * The start address of the last possible leadout will only
90*6540Szk194757 		 * be zero if the disc is full or this drive does not support
91*6540Szk194757 		 * this method of determining capacity.
92*6540Szk194757 		 */
93*6540Szk194757 		if (cap == 0)
94*6540Szk194757 			cap = read_format_capacity(target->d_fd, &bsize);
95*6540Szk194757 
96*6540Szk194757 		/*
97*6540Szk194757 		 * Since both methods of determining the capacity of the
98*6540Szk194757 		 * media count the correct number of blocks, just multiply
99*6540Szk194757 		 * the capacity by the block size.
100*6540Szk194757 		 */
101*6540Szk194757 		cap *= target->d_blksize;
102*6540Szk194757 
103*6540Szk194757 		if (device_type == CD_RW) {
104*6540Szk194757 			(void) printf(gettext("Media Capacity : %.2f MB "),
105*6540Szk194757 			    ((double)cap/ONE_MB_BASE2));
106*6540Szk194757 		} else {
107*6540Szk194757 			/*
108*6540Szk194757 			 * For DVD's make sure we print out "Formatted Media
109*6540Szk194757 			 * Capacity". Don't do this for CD-RWs as only
110*6540Szk194757 			 * DVDs are formatted.
111*6540Szk194757 			 */
112*6540Szk194757 			(void) printf(gettext("Formatted Media Capacity : "
113*6540Szk194757 			    "%.2f GB "), ((double)cap/ONE_GB_BASE10));
114*6540Szk194757 		}
115*6540Szk194757 
116*6540Szk194757 		cap /= target->d_blksize;
117*6540Szk194757 		(void) printf(gettext("(%u blocks)\n"), (uint_t)cap);
118*6540Szk194757 	}
119*6540Szk194757 
1200Sstevel@tonic-gate 	if (!check_device(target, CHECK_MEDIA_IS_NOT_BLANK)) {
1210Sstevel@tonic-gate 		(void) printf(gettext("Media is blank\n"));
1220Sstevel@tonic-gate 		exit(0);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	/*  Find out the number of entries in the toc */
1260Sstevel@tonic-gate 	toc = (uchar_t *)my_zalloc(12);
1270Sstevel@tonic-gate 	if (!read_toc(target->d_fd, 0, 1, 4, toc)) {
1280Sstevel@tonic-gate 		err_msg(msg);
1290Sstevel@tonic-gate 	} else {
1300Sstevel@tonic-gate 		toc_size = 256*toc[0] + toc[1] + 2;
1310Sstevel@tonic-gate 		free(toc);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 		/* allocate enough space for each track entry */
1340Sstevel@tonic-gate 		toc = (uchar_t *)my_zalloc(toc_size);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 		if (!read_toc(target->d_fd, 0, 1, toc_size, toc)) {
1370Sstevel@tonic-gate 			err_msg(msg);
1380Sstevel@tonic-gate 			exit(1);
1390Sstevel@tonic-gate 		}
1400Sstevel@tonic-gate 		(void) printf("\n");
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 		/* l10n_NOTE : Preserve column numbers of '|' character */
1430Sstevel@tonic-gate 		(void) printf(gettext("Track No. |Type    |Start address\n"));
1440Sstevel@tonic-gate 		(void) printf("----------+--------+-------------\n");
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 		/* look at each track and display it's type. */
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 		for (p = &toc[4]; p < (toc + toc_size); p += 8) {
1500Sstevel@tonic-gate 			if (p[2] != 0xAA)
1510Sstevel@tonic-gate 				(void) printf(" %-3d      |", p[2]);
1520Sstevel@tonic-gate 			else
1530Sstevel@tonic-gate 				(void) printf("Leadout   |");
1540Sstevel@tonic-gate 			(void) printf("%s   |", (p[1] & 4) ? gettext("Data ") :
1550Sstevel@tonic-gate 			    gettext("Audio"));
1560Sstevel@tonic-gate 			(void) printf("%u\n", read_scsi32(&p[4]));
1570Sstevel@tonic-gate 		}
1580Sstevel@tonic-gate 	}
1590Sstevel@tonic-gate 	(void) printf("\n");
1600Sstevel@tonic-gate 	ret = read_toc(target->d_fd, 1, 0, 12, toc);
1610Sstevel@tonic-gate 	if ((ret == 0) || (toc[1] != 0x0a))
1620Sstevel@tonic-gate 		/* For ATAPI drives or old Toshiba drives */
1630Sstevel@tonic-gate 		ret = read_toc_as_per_8020(target->d_fd, 1, 0, 12, toc);
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	if (ret && (toc[1] == 0x0a)) {
1660Sstevel@tonic-gate 		(void) printf(gettext("Last session start address: %u\n"),
1670Sstevel@tonic-gate 		    read_scsi32(&toc[8]));
1680Sstevel@tonic-gate 	}
1690Sstevel@tonic-gate 	free(toc);
1700Sstevel@tonic-gate 	ti = (struct track_info *)my_zalloc(sizeof (struct track_info));
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	if (build_track_info(target, -1, ti) && (ti->ti_flags & TI_NWA_VALID)) {
1730Sstevel@tonic-gate 		(void) printf(gettext("Next writable address: %u\n"),
1740Sstevel@tonic-gate 		    ti->ti_nwa);
1750Sstevel@tonic-gate 	}
1760Sstevel@tonic-gate 	free(ti);
1770Sstevel@tonic-gate 	exit(0);
1780Sstevel@tonic-gate }
179