summaryrefslogtreecommitdiff
path: root/usr/src/cmd/cdrw
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/cdrw')
-rw-r--r--usr/src/cmd/cdrw/device.c42
-rw-r--r--usr/src/cmd/cdrw/device.h4
-rw-r--r--usr/src/cmd/cdrw/misc_scsi.c12
-rw-r--r--usr/src/cmd/cdrw/mmc.c204
-rw-r--r--usr/src/cmd/cdrw/mmc.h29
5 files changed, 249 insertions, 42 deletions
diff --git a/usr/src/cmd/cdrw/device.c b/usr/src/cmd/cdrw/device.c
index f1a582b08f..1f0cba7a54 100644
--- a/usr/src/cmd/cdrw/device.c
+++ b/usr/src/cmd/cdrw/device.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -206,11 +206,11 @@ get_device(char *user_supplied, char *node)
dev->d_speed_ctrl = cd_speed_ctrl;
} else {
/*
- * If feature 8 (see GET CONF MMC command) is supported,
- * READ CD will work and will return jitter free audio data.
- * Otherwise look at page code 2A for this info.
+ * If the CD Read Feature is supported, READ CD will work
+ * and will return jitter free audio data. Otherwise, look
+ * at Page Code 2A for this information.
*/
- if (get_configuration(fd, 0x1E, 8, cap)) {
+ if (ftr_supported(fd, MMC_FTR_CD_READ) == 1) {
dev->d_read_audio = read_audio_through_read_cd;
dev->d_cap |= DEV_CAP_ACCURATE_CDDA;
} else if (get_mode_page(fd, 0x2A, 0, 8, cap)) {
@@ -221,11 +221,11 @@ get_device(char *user_supplied, char *node)
}
}
/*
- * If feature 0x0107 is suported then Real-time streaming
- * commands can be used for speed control. Otherwise try
- * SET CD SPEED.
+ * If the Real Time Streaming Feature is supported then
+ * Real-time streaming commands can be used for speed control.
+ * Otherwise try SET CD SPEED.
*/
- if (get_configuration(fd, 0x0107, 8, cap)) {
+ if (ftr_supported(fd, MMC_FTR_RT_STREAM) == 1) {
dev->d_speed_ctrl = rt_streaming_ctrl;
if (debug)
(void) printf("using rt speed ctrl\n");
@@ -246,15 +246,12 @@ get_device(char *user_supplied, char *node)
*/
if (ioctl(fd, DKIOCGMEDIAINFO, &mediainfo) < 0) {
-
/*
* If DKIOCGMEDIAINFO fails we'll try to get
* the blocksize from the device itself.
*/
-
if (debug)
(void) printf("DKIOCGMEDIAINFO failed\n");
-
if (read_capacity(fd, cap))
dev->d_blksize = read_scsi32(cap + 4);
} else {
@@ -768,21 +765,13 @@ list(void)
void
get_media_type(int fd)
{
- uchar_t cap[DVD_CONFIG_SIZE];
- uint_t i;
-
-
- (void) memset(cap, 0, DVD_CONFIG_SIZE);
- if (get_configuration(fd, 0, DVD_CONFIG_SIZE, cap)) {
- if (debug && verbose) {
- (void) printf("\nprofile = ");
+ uchar_t *cap = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN);
- for (i = 7; i < 0x20; i += 4)
- (void) printf(" 0x%x", cap[i]);
- (void) printf("\n");
- }
-
- switch (cap[7]) {
+ if (get_configuration(fd, MMC_FTR_PRFL_LIST,
+ MMC_FTR_HDR_LEN, cap)) {
+ if (debug)
+ (void) print_profile_list(fd);
+ switch (read_scsi16(&cap[6])) {
case 0x8: /* CD-ROM */
if (debug)
(void) printf("CD-ROM found\n");
@@ -863,6 +852,7 @@ get_media_type(int fd)
device_type = CD_RW;
}
}
+ free(cap);
}
/* Translate a transfer rate (eg, KB/s) into a Speed (eg, "2X") */
diff --git a/usr/src/cmd/cdrw/device.h b/usr/src/cmd/cdrw/device.h
index 851d67dd53..fd08be1be8 100644
--- a/usr/src/cmd/cdrw/device.h
+++ b/usr/src/cmd/cdrw/device.h
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -78,6 +78,8 @@ int scan_for_cd_device(int mode, cd_device **found);
void write_next_track(int mode, bstreamhandle h);
int check_device(cd_device *dev, int cond);
void get_media_type(int fd);
+void print_profile_list(int fd);
+int ftr_supported(int fd, uint16_t feature);
uint_t cdrw_bandwidth_to_x(uint_t rate);
uint_t cdrw_x_to_bandwidth(uint_t x);
diff --git a/usr/src/cmd/cdrw/misc_scsi.c b/usr/src/cmd/cdrw/misc_scsi.c
index cab78db4d2..120a67e950 100644
--- a/usr/src/cmd/cdrw/misc_scsi.c
+++ b/usr/src/cmd/cdrw/misc_scsi.c
@@ -859,18 +859,6 @@ write_init(int mode)
write_mode = DAO_MODE;
}
- /* For debug, print out device config information */
- if (debug) {
- int i;
- uchar_t cap[80];
-
- if (get_configuration(target->d_fd, 0, 80, cap))
- (void) printf("Drive profile = ");
- for (i = 10; i < 70; i += 8)
- (void) printf(" 0x%x", cap[i]);
- (void) printf("\n");
- }
-
/* DVD+ and DVD- have no support for AUDIO, bail out */
if ((mode == TRACK_MODE_AUDIO) && (device_type != CD_RW)) {
err_msg(gettext("Audio mode is only supported for CD media\n"));
diff --git a/usr/src/cmd/cdrw/mmc.c b/usr/src/cmd/cdrw/mmc.c
index 9c051ee619..a130662311 100644
--- a/usr/src/cmd/cdrw/mmc.c
+++ b/usr/src/cmd/cdrw/mmc.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -671,3 +671,205 @@ read_format_capacity(int fd, uint_t *bsize)
return (filesize);
}
+
+/*
+ * Function: ftr_supported
+ *
+ * Description: Check to see if a device supports a Feature
+ *
+ * Arguments: fd - file descriptor
+ * feature - the MMC Feature for which we'd like to know
+ * if there's support
+ *
+ * Return Code: 1 - Feature is supported
+ * 0 - Feature is not supported
+ *
+ */
+int
+ftr_supported(int fd, uint16_t feature)
+{
+ size_t response_len;
+ uchar_t *bufp;
+ int ret;
+
+ response_len = MMC_FTR_HDR_LEN + MMC_FTR_DSCRPTR_BASE_LEN;
+ bufp = (uchar_t *)my_zalloc(response_len);
+
+ /*
+ * If a Feature is supported, a device will return a Feature Descriptor
+ * for that Feature, and its Current Bit will be set.
+ */
+ if (get_configuration(fd, feature, response_len, bufp) == 1) {
+ /*
+ * To check that a Feature Descriptor was returned, we
+ * check to see if the Data Length field of the Feature
+ * Header holds a value greater than four. To check if
+ * the Current Bit is set, we check bit 1 of byte 10.
+ */
+ if (read_scsi32(bufp) > 4 && bufp[10] & 1)
+ ret = 1;
+ else
+ ret = 0;
+ } else {
+ /* get_configuration failed */
+ ret = 0;
+ }
+ free(bufp);
+ return (ret);
+}
+
+/*
+ * Function: print_profile_name
+ *
+ * Description: Prints a list of the Profiles the device supports
+ *
+ * Parameters: num - hexadecimal representation of Profile
+ * current - 1 if the Profile is Current, otherwise 0
+ */
+static void
+print_profile_name(uint16_t num, uchar_t current)
+{
+ (void) printf(" 0x%04x: ", num);
+ switch (num) {
+ case 0x0000:
+ (void) printf("No Current Profile");
+ break;
+ case 0x0001:
+ (void) printf("Non-Removable Disk");
+ break;
+ case 0x0002:
+ (void) printf("Removable Disk");
+ break;
+ case 0x0003:
+ (void) printf("Magneto-Optical Erasable");
+ break;
+ case 0x0004:
+ (void) printf("Optical Write Once");
+ break;
+ case 0x0005:
+ (void) printf("AS-MO");
+ break;
+ case 0x0008:
+ (void) printf("CD-ROM");
+ break;
+ case 0x0009:
+ (void) printf("CD-R");
+ break;
+ case 0x000A:
+ (void) printf("CD-RW");
+ break;
+ case 0x0010:
+ (void) printf("DVD-ROM");
+ break;
+ case 0x0011:
+ (void) printf("DVD-R Sequential Recording");
+ break;
+ case 0x0012:
+ (void) printf("DVD-RAM");
+ break;
+ case 0x0013:
+ (void) printf("DVD-RW Restricted Overwrite");
+ break;
+ case 0x0014:
+ (void) printf("DVD-RW Sequential Recording");
+ break;
+ case 0x001A:
+ (void) printf("DVD+RW");
+ break;
+ case 0x001B:
+ (void) printf("DVD+R");
+ break;
+ case 0x0020:
+ (void) printf("DDCD-ROM");
+ break;
+ case 0x0021:
+ (void) printf("DDCD-R");
+ break;
+ case 0x0022:
+ (void) printf("DDCD-RW");
+ break;
+ case 0x002B:
+ (void) printf("DVD+R Double Layer");
+ break;
+ case 0x0040:
+ (void) printf("BD-ROM");
+ break;
+ case 0x0041:
+ (void) printf("BD-R Sequential Recording (SRM) Profile");
+ break;
+ case 0x0042:
+ (void) printf("BD-R Random Recording (RRM) Profile");
+ break;
+ case 0x0043:
+ (void) printf("BD-RE");
+ break;
+ case 0xFFFF:
+ (void) printf("Nonstandard Profile");
+ break;
+ default:
+ break;
+ }
+ if (current == 1)
+ (void) printf(" (Current Profile)");
+ (void) printf("\n");
+}
+
+/*
+ * Function: print_profile_list
+ *
+ * Description: Print a list of Profiles supported by the Logical Unit.
+ *
+ * Parameters: fd - file descriptor for device whose list of
+ * profiles we wish to print
+ */
+void
+print_profile_list(int fd)
+{
+ size_t i;
+ size_t buflen;
+ uint16_t current;
+ uint16_t other;
+ uchar_t *bufp = (uchar_t *)my_zalloc(MMC_FTR_HDR_LEN);
+
+ /*
+ * First get_configuration call is used to determine amount of memory
+ * needed to hold all the Profiles. The first four bytes of bufp
+ * concatenated tell us the number of bytes of memory we need but do
+ * not take themselves into account. Therefore, add four, and
+ * allocate that number of bytes.
+ */
+ if (get_configuration(fd, MMC_FTR_PRFL_LIST, MMC_FTR_HDR_LEN,
+ bufp)) {
+ buflen = read_scsi32(bufp) + 4;
+ free(bufp);
+ bufp = (uchar_t *)my_zalloc(buflen);
+
+ /*
+ * Now get all the Profiles
+ */
+ if (get_configuration(fd, MMC_FTR_PRFL_LIST, buflen, bufp)) {
+ (void) printf("\nProfile List\n");
+ (void) printf("---------------------------------\n");
+
+ /*
+ * Find out the Logical Unit's Current Profile
+ */
+ current = read_scsi16(&bufp[6]);
+
+ /*
+ * Print out the Profile List and indicate which
+ * Profile is Current
+ */
+ for (i = MMC_FTR_HDR_LEN + MMC_FTR_DSCRPTR_BASE_LEN;
+ i < buflen; i += MMC_PRFL_DSCRPTR_LEN) {
+ other = read_scsi16(&bufp[i]);
+ if (other == current)
+ print_profile_name(other, 1);
+ else
+ print_profile_name(other, 0);
+ }
+ (void) printf("\n");
+ }
+ }
+ free(bufp);
+}
diff --git a/usr/src/cmd/cdrw/mmc.h b/usr/src/cmd/cdrw/mmc.h
index 34a9fffd83..d96a851c65 100644
--- a/usr/src/cmd/cdrw/mmc.h
+++ b/usr/src/cmd/cdrw/mmc.h
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -41,7 +41,32 @@ extern "C" {
#define GET_PERF_DATA_LEN 24
#define SET_STREAM_DATA_LEN 28
-#define DEFAULT_SCSI_TIMEOUT 60
+#define DEFAULT_SCSI_TIMEOUT 60
+
+#define MMC_FTR_HDR_LEN 8 /* byte len of Feature Header */
+/*
+ * byte length of the static part of a Feature Descriptor
+ */
+#define MMC_FTR_DSCRPTR_BASE_LEN 4
+#define MMC_PRFL_DSCRPTR_LEN 4 /* byte len of Profile Descriptor */
+/*
+ * MMC Features; can be added to over time
+ */
+#define MMC_FTR_PRFL_LIST 0x0000 /* Profile List Feature */
+#define MMC_FTR_CORE 0x0001 /* Core Feature */
+#define MMC_FTR_MORPHING 0x0002 /* Morphing Feature */
+#define MMC_FTR_REM_MED 0x0003 /* Removable Medium Feature */
+#define MMC_FTR_WR_PROTECT 0x0004 /* Write Protect Feature */
+#define MMC_FTR_RAND_READ 0x0010 /* Random Readable Feature */
+#define MMC_FTR_MULTI_READ 0x001D /* Multi-Read Feature */
+#define MMC_FTR_CD_READ 0x001E /* CD Read Feature */
+#define MMC_FTR_DVD_READ 0x001F /* DVD Read Feature */
+#define MMC_FTR_RAND_WR 0x0020 /* Random Writable Feature */
+#define MMC_FTR_INC_STR_WR 0x0021 /* Incremental Streaming Writable */
+#define MMC_FTR_SCTR_ERSBL 0x0022 /* Sector Erasable Feature */
+#define MMC_FTR_FORMATTABLE 0x0023 /* Formattable Feature */
+#define MMC_FTR_DFCT_MNGMNT 0x0024 /* Hardware Defect Management Feature */
+#define MMC_FTR_RT_STREAM 0x0107 /* Real Time Streaming Feature */
int test_unit_ready(int fd);
int inquiry(int fd, uchar_t *inq);