xref: /illumos-gate/usr/src/cmd/cdrw/dumpinfo.c (revision aefd6f19)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*aefd6f19Szk  * Common Development and Distribution License (the "License").
6*aefd6f19Szk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*aefd6f19Szk  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <libintl.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include "msgs.h"
337c478bd9Sstevel@tonic-gate #include "mmc.h"
347c478bd9Sstevel@tonic-gate #include "misc_scsi.h"
357c478bd9Sstevel@tonic-gate #include "device.h"
367c478bd9Sstevel@tonic-gate #include "main.h"
377c478bd9Sstevel@tonic-gate #include "util.h"
387c478bd9Sstevel@tonic-gate #include "toshiba.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate void
417c478bd9Sstevel@tonic-gate info(void)
427c478bd9Sstevel@tonic-gate {
43*aefd6f19Szk 	uchar_t *toc, *p, *conf;
447c478bd9Sstevel@tonic-gate 	int ret, toc_size;
45*aefd6f19Szk 	uint_t bsize;
46*aefd6f19Szk 	size_t cap = 0;
477c478bd9Sstevel@tonic-gate 	char *msg;
487c478bd9Sstevel@tonic-gate 	struct track_info *ti;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	msg = gettext("Cannot read Table of contents\n");
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	get_media_type(target->d_fd);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	(void) printf(gettext("\nDevice : %.8s %.16s\n"),
557c478bd9Sstevel@tonic-gate 	    &target->d_inq[8], &target->d_inq[16]);
567c478bd9Sstevel@tonic-gate 	(void) printf(gettext("Firmware : Rev. %.4s (%.12s)\n"),
577c478bd9Sstevel@tonic-gate 	    &target->d_inq[32], &target->d_inq[36]);
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	if (check_device(target, CHECK_DEVICE_NOT_READY)) {
607c478bd9Sstevel@tonic-gate 		(void) check_device(target, CHECK_NO_MEDIA |
617c478bd9Sstevel@tonic-gate 		    EXIT_IF_CHECK_FAILED);
627c478bd9Sstevel@tonic-gate 		(void) check_device(target, CHECK_DEVICE_NOT_READY |
637c478bd9Sstevel@tonic-gate 		    EXIT_IF_CHECK_FAILED);
647c478bd9Sstevel@tonic-gate 	}
65*aefd6f19Szk 
66*aefd6f19Szk 	if (verbose != 0) {
67*aefd6f19Szk 		/*
68*aefd6f19Szk 		 * Determine the media type by reading the active profile
69*aefd6f19Szk 		 * from the profile list.
70*aefd6f19Szk 		 */
71*aefd6f19Szk 		(void) printf(gettext("Media Type : "));
72*aefd6f19Szk 
73*aefd6f19Szk 		conf = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN);
74*aefd6f19Szk 
75*aefd6f19Szk 		if (get_configuration(target->d_fd, MMC_FTR_PRFL_LIST,
76*aefd6f19Szk 		    MMC_FTR_HDR_LEN, conf))
77*aefd6f19Szk 			print_profile_name(read_scsi16(&conf[6]), 0, 1);
78*aefd6f19Szk 		else
79*aefd6f19Szk 			(void) printf(gettext("UNKNOWN\n"));
80*aefd6f19Szk 
81*aefd6f19Szk 		free(conf);
82*aefd6f19Szk 
83*aefd6f19Szk 		/*
84*aefd6f19Szk 		 * Get the start address of the last possible lead out.
85*aefd6f19Szk 		 */
86*aefd6f19Szk 		cap = get_last_possible_lba(target);
87*aefd6f19Szk 
88*aefd6f19Szk 		/*
89*aefd6f19Szk 		 * The start address of the last possible leadout will only
90*aefd6f19Szk 		 * be zero if the disc is full or this drive does not support
91*aefd6f19Szk 		 * this method of determining capacity.
92*aefd6f19Szk 		 */
93*aefd6f19Szk 		if (cap == 0)
94*aefd6f19Szk 			cap = read_format_capacity(target->d_fd, &bsize);
95*aefd6f19Szk 
96*aefd6f19Szk 		/*
97*aefd6f19Szk 		 * Since both methods of determining the capacity of the
98*aefd6f19Szk 		 * media count the correct number of blocks, just multiply
99*aefd6f19Szk 		 * the capacity by the block size.
100*aefd6f19Szk 		 */
101*aefd6f19Szk 		cap *= target->d_blksize;
102*aefd6f19Szk 
103*aefd6f19Szk 		if (device_type == CD_RW) {
104*aefd6f19Szk 			(void) printf(gettext("Media Capacity : %.2f MB "),
105*aefd6f19Szk 			    ((double)cap/ONE_MB_BASE2));
106*aefd6f19Szk 		} else {
107*aefd6f19Szk 			/*
108*aefd6f19Szk 			 * For DVD's make sure we print out "Formatted Media
109*aefd6f19Szk 			 * Capacity". Don't do this for CD-RWs as only
110*aefd6f19Szk 			 * DVDs are formatted.
111*aefd6f19Szk 			 */
112*aefd6f19Szk 			(void) printf(gettext("Formatted Media Capacity : "
113*aefd6f19Szk 			    "%.2f GB "), ((double)cap/ONE_GB_BASE10));
114*aefd6f19Szk 		}
115*aefd6f19Szk 
116*aefd6f19Szk 		cap /= target->d_blksize;
117*aefd6f19Szk 		(void) printf(gettext("(%u blocks)\n"), (uint_t)cap);
118*aefd6f19Szk 	}
119*aefd6f19Szk 
1207c478bd9Sstevel@tonic-gate 	if (!check_device(target, CHECK_MEDIA_IS_NOT_BLANK)) {
1217c478bd9Sstevel@tonic-gate 		(void) printf(gettext("Media is blank\n"));
1227c478bd9Sstevel@tonic-gate 		exit(0);
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/*  Find out the number of entries in the toc */
1267c478bd9Sstevel@tonic-gate 	toc = (uchar_t *)my_zalloc(12);
1277c478bd9Sstevel@tonic-gate 	if (!read_toc(target->d_fd, 0, 1, 4, toc)) {
1287c478bd9Sstevel@tonic-gate 		err_msg(msg);
1297c478bd9Sstevel@tonic-gate 	} else {
1307c478bd9Sstevel@tonic-gate 		toc_size = 256*toc[0] + toc[1] + 2;
1317c478bd9Sstevel@tonic-gate 		free(toc);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 		/* allocate enough space for each track entry */
1347c478bd9Sstevel@tonic-gate 		toc = (uchar_t *)my_zalloc(toc_size);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 		if (!read_toc(target->d_fd, 0, 1, toc_size, toc)) {
1377c478bd9Sstevel@tonic-gate 			err_msg(msg);
1387c478bd9Sstevel@tonic-gate 			exit(1);
1397c478bd9Sstevel@tonic-gate 		}
1407c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 		/* l10n_NOTE : Preserve column numbers of '|' character */
1437c478bd9Sstevel@tonic-gate 		(void) printf(gettext("Track No. |Type    |Start address\n"));
1447c478bd9Sstevel@tonic-gate 		(void) printf("----------+--------+-------------\n");
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 		/* look at each track and display it's type. */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 		for (p = &toc[4]; p < (toc + toc_size); p += 8) {
1507c478bd9Sstevel@tonic-gate 			if (p[2] != 0xAA)
1517c478bd9Sstevel@tonic-gate 				(void) printf(" %-3d      |", p[2]);
1527c478bd9Sstevel@tonic-gate 			else
1537c478bd9Sstevel@tonic-gate 				(void) printf("Leadout   |");
1547c478bd9Sstevel@tonic-gate 			(void) printf("%s   |", (p[1] & 4) ? gettext("Data ") :
1557c478bd9Sstevel@tonic-gate 			    gettext("Audio"));
1567c478bd9Sstevel@tonic-gate 			(void) printf("%u\n", read_scsi32(&p[4]));
1577c478bd9Sstevel@tonic-gate 		}
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate 	(void) printf("\n");
1607c478bd9Sstevel@tonic-gate 	ret = read_toc(target->d_fd, 1, 0, 12, toc);
1617c478bd9Sstevel@tonic-gate 	if ((ret == 0) || (toc[1] != 0x0a))
1627c478bd9Sstevel@tonic-gate 		/* For ATAPI drives or old Toshiba drives */
1637c478bd9Sstevel@tonic-gate 		ret = read_toc_as_per_8020(target->d_fd, 1, 0, 12, toc);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	if (ret && (toc[1] == 0x0a)) {
1667c478bd9Sstevel@tonic-gate 		(void) printf(gettext("Last session start address: %u\n"),
1677c478bd9Sstevel@tonic-gate 		    read_scsi32(&toc[8]));
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 	free(toc);
1707c478bd9Sstevel@tonic-gate 	ti = (struct track_info *)my_zalloc(sizeof (struct track_info));
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	if (build_track_info(target, -1, ti) && (ti->ti_flags & TI_NWA_VALID)) {
1737c478bd9Sstevel@tonic-gate 		(void) printf(gettext("Next writable address: %u\n"),
1747c478bd9Sstevel@tonic-gate 		    ti->ti_nwa);
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 	free(ti);
1777c478bd9Sstevel@tonic-gate 	exit(0);
1787c478bd9Sstevel@tonic-gate }
179