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*aefd6f19Szk194757 * Common Development and Distribution License (the "License").
6*aefd6f19Szk194757 * 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*aefd6f19Szk194757 * 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 #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <libintl.h>
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include "msgs.h"
317c478bd9Sstevel@tonic-gate #include "mmc.h"
327c478bd9Sstevel@tonic-gate #include "misc_scsi.h"
337c478bd9Sstevel@tonic-gate #include "device.h"
347c478bd9Sstevel@tonic-gate #include "main.h"
357c478bd9Sstevel@tonic-gate #include "util.h"
367c478bd9Sstevel@tonic-gate #include "toshiba.h"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate void
info(void)397c478bd9Sstevel@tonic-gate info(void)
407c478bd9Sstevel@tonic-gate {
41*aefd6f19Szk194757 uchar_t *toc, *p, *conf;
427c478bd9Sstevel@tonic-gate int ret, toc_size;
43*aefd6f19Szk194757 uint_t bsize;
44*aefd6f19Szk194757 size_t cap = 0;
457c478bd9Sstevel@tonic-gate char *msg;
467c478bd9Sstevel@tonic-gate struct track_info *ti;
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate msg = gettext("Cannot read Table of contents\n");
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate get_media_type(target->d_fd);
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate (void) printf(gettext("\nDevice : %.8s %.16s\n"),
537c478bd9Sstevel@tonic-gate &target->d_inq[8], &target->d_inq[16]);
547c478bd9Sstevel@tonic-gate (void) printf(gettext("Firmware : Rev. %.4s (%.12s)\n"),
557c478bd9Sstevel@tonic-gate &target->d_inq[32], &target->d_inq[36]);
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate if (check_device(target, CHECK_DEVICE_NOT_READY)) {
587c478bd9Sstevel@tonic-gate (void) check_device(target, CHECK_NO_MEDIA |
597c478bd9Sstevel@tonic-gate EXIT_IF_CHECK_FAILED);
607c478bd9Sstevel@tonic-gate (void) check_device(target, CHECK_DEVICE_NOT_READY |
617c478bd9Sstevel@tonic-gate EXIT_IF_CHECK_FAILED);
627c478bd9Sstevel@tonic-gate }
63*aefd6f19Szk194757
64*aefd6f19Szk194757 if (verbose != 0) {
65*aefd6f19Szk194757 /*
66*aefd6f19Szk194757 * Determine the media type by reading the active profile
67*aefd6f19Szk194757 * from the profile list.
68*aefd6f19Szk194757 */
69*aefd6f19Szk194757 (void) printf(gettext("Media Type : "));
70*aefd6f19Szk194757
71*aefd6f19Szk194757 conf = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN);
72*aefd6f19Szk194757
73*aefd6f19Szk194757 if (get_configuration(target->d_fd, MMC_FTR_PRFL_LIST,
74*aefd6f19Szk194757 MMC_FTR_HDR_LEN, conf))
75*aefd6f19Szk194757 print_profile_name(read_scsi16(&conf[6]), 0, 1);
76*aefd6f19Szk194757 else
77*aefd6f19Szk194757 (void) printf(gettext("UNKNOWN\n"));
78*aefd6f19Szk194757
79*aefd6f19Szk194757 free(conf);
80*aefd6f19Szk194757
81*aefd6f19Szk194757 /*
82*aefd6f19Szk194757 * Get the start address of the last possible lead out.
83*aefd6f19Szk194757 */
84*aefd6f19Szk194757 cap = get_last_possible_lba(target);
85*aefd6f19Szk194757
86*aefd6f19Szk194757 /*
87*aefd6f19Szk194757 * The start address of the last possible leadout will only
88*aefd6f19Szk194757 * be zero if the disc is full or this drive does not support
89*aefd6f19Szk194757 * this method of determining capacity.
90*aefd6f19Szk194757 */
91*aefd6f19Szk194757 if (cap == 0)
92*aefd6f19Szk194757 cap = read_format_capacity(target->d_fd, &bsize);
93*aefd6f19Szk194757
94*aefd6f19Szk194757 /*
95*aefd6f19Szk194757 * Since both methods of determining the capacity of the
96*aefd6f19Szk194757 * media count the correct number of blocks, just multiply
97*aefd6f19Szk194757 * the capacity by the block size.
98*aefd6f19Szk194757 */
99*aefd6f19Szk194757 cap *= target->d_blksize;
100*aefd6f19Szk194757
101*aefd6f19Szk194757 if (device_type == CD_RW) {
102*aefd6f19Szk194757 (void) printf(gettext("Media Capacity : %.2f MB "),
103*aefd6f19Szk194757 ((double)cap/ONE_MB_BASE2));
104*aefd6f19Szk194757 } else {
105*aefd6f19Szk194757 /*
106*aefd6f19Szk194757 * For DVD's make sure we print out "Formatted Media
107*aefd6f19Szk194757 * Capacity". Don't do this for CD-RWs as only
108*aefd6f19Szk194757 * DVDs are formatted.
109*aefd6f19Szk194757 */
110*aefd6f19Szk194757 (void) printf(gettext("Formatted Media Capacity : "
111*aefd6f19Szk194757 "%.2f GB "), ((double)cap/ONE_GB_BASE10));
112*aefd6f19Szk194757 }
113*aefd6f19Szk194757
114*aefd6f19Szk194757 cap /= target->d_blksize;
115*aefd6f19Szk194757 (void) printf(gettext("(%u blocks)\n"), (uint_t)cap);
116*aefd6f19Szk194757 }
117*aefd6f19Szk194757
1187c478bd9Sstevel@tonic-gate if (!check_device(target, CHECK_MEDIA_IS_NOT_BLANK)) {
1197c478bd9Sstevel@tonic-gate (void) printf(gettext("Media is blank\n"));
1207c478bd9Sstevel@tonic-gate exit(0);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /* Find out the number of entries in the toc */
1247c478bd9Sstevel@tonic-gate toc = (uchar_t *)my_zalloc(12);
1257c478bd9Sstevel@tonic-gate if (!read_toc(target->d_fd, 0, 1, 4, toc)) {
1267c478bd9Sstevel@tonic-gate err_msg(msg);
1277c478bd9Sstevel@tonic-gate } else {
1287c478bd9Sstevel@tonic-gate toc_size = 256*toc[0] + toc[1] + 2;
1297c478bd9Sstevel@tonic-gate free(toc);
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /* allocate enough space for each track entry */
1327c478bd9Sstevel@tonic-gate toc = (uchar_t *)my_zalloc(toc_size);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate if (!read_toc(target->d_fd, 0, 1, toc_size, toc)) {
1357c478bd9Sstevel@tonic-gate err_msg(msg);
1367c478bd9Sstevel@tonic-gate exit(1);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate (void) printf("\n");
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /* l10n_NOTE : Preserve column numbers of '|' character */
1417c478bd9Sstevel@tonic-gate (void) printf(gettext("Track No. |Type |Start address\n"));
1427c478bd9Sstevel@tonic-gate (void) printf("----------+--------+-------------\n");
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate /* look at each track and display it's type. */
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate for (p = &toc[4]; p < (toc + toc_size); p += 8) {
1487c478bd9Sstevel@tonic-gate if (p[2] != 0xAA)
1497c478bd9Sstevel@tonic-gate (void) printf(" %-3d |", p[2]);
1507c478bd9Sstevel@tonic-gate else
1517c478bd9Sstevel@tonic-gate (void) printf("Leadout |");
1527c478bd9Sstevel@tonic-gate (void) printf("%s |", (p[1] & 4) ? gettext("Data ") :
1537c478bd9Sstevel@tonic-gate gettext("Audio"));
1547c478bd9Sstevel@tonic-gate (void) printf("%u\n", read_scsi32(&p[4]));
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate (void) printf("\n");
1587c478bd9Sstevel@tonic-gate ret = read_toc(target->d_fd, 1, 0, 12, toc);
1597c478bd9Sstevel@tonic-gate if ((ret == 0) || (toc[1] != 0x0a))
1607c478bd9Sstevel@tonic-gate /* For ATAPI drives or old Toshiba drives */
1617c478bd9Sstevel@tonic-gate ret = read_toc_as_per_8020(target->d_fd, 1, 0, 12, toc);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate if (ret && (toc[1] == 0x0a)) {
1647c478bd9Sstevel@tonic-gate (void) printf(gettext("Last session start address: %u\n"),
1657c478bd9Sstevel@tonic-gate read_scsi32(&toc[8]));
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate free(toc);
1687c478bd9Sstevel@tonic-gate ti = (struct track_info *)my_zalloc(sizeof (struct track_info));
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate if (build_track_info(target, -1, ti) && (ti->ti_flags & TI_NWA_VALID)) {
1717c478bd9Sstevel@tonic-gate (void) printf(gettext("Next writable address: %u\n"),
1727c478bd9Sstevel@tonic-gate ti->ti_nwa);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate free(ti);
1757c478bd9Sstevel@tonic-gate exit(0);
1767c478bd9Sstevel@tonic-gate }
177