From 34de876298c5177ddeb98f3af7e4e3012f16e2a7 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 16 Dec 2009 08:31:24 -0800 Subject: [PATCH] PSARC 2009/656 DKIOCREADONLY 6820128 Can't mount locked SD card on Toshiba R600 --- usr/src/cmd/hal/probing/storage/probe-storage.c | 13 +++++++++---- usr/src/cmd/truss/codes.c | 2 ++ usr/src/uts/common/io/scsi/targets/sd.c | 14 ++++++++++++++ usr/src/uts/common/sys/dkio.h | 5 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/usr/src/cmd/hal/probing/storage/probe-storage.c b/usr/src/cmd/hal/probing/storage/probe-storage.c index 6fa8fead0a..d274aa9366 100644 --- a/usr/src/cmd/hal/probing/storage/probe-storage.c +++ b/usr/src/cmd/hal/probing/storage/probe-storage.c @@ -2,7 +2,7 @@ * * probe-storage.c : Probe for storage devices * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * Licensed under the Academic Free License version 2.1 @@ -336,6 +336,7 @@ main (int argc, char *argv[]) dbus_bool_t is_cdrom; dbus_bool_t is_floppy; struct dk_minfo minfo; + int rdonly; unsigned int block_size = 512; dbus_bool_t only_check_for_media; int got_media = FALSE; @@ -416,9 +417,13 @@ main (int argc, char *argv[]) /* don't look for partitions on floppy */ goto out_cs; } else { - got_media = TRUE; - if (get_media_info(rfd, &minfo)) { - block_size = minfo.dki_lbsize; + got_media = get_media_info(rfd, &minfo); + if (!got_media) { + goto out_cs; + } + block_size = minfo.dki_lbsize; + if ((ioctl(rfd, DKIOCREADONLY, &rdonly) == 0) && rdonly) { + is_write_protected = TRUE; } } diff --git a/usr/src/cmd/truss/codes.c b/usr/src/cmd/truss/codes.c index a9246870af..68d78f826e 100644 --- a/usr/src/cmd/truss/codes.c +++ b/usr/src/cmd/truss/codes.c @@ -1327,6 +1327,8 @@ const struct ioc { NULL}, { (uint_t)DKIOCDUMPFINI, "DKIOCDUMPFINI", NULL}, + { (uint_t)DKIOCREADONLY, "DKIOCREADONLY", + NULL}, /* disk ioctls - (0x04 << 8) - fdio.h */ { (uint_t)FDIOGCHAR, "FDIOGCHAR", diff --git a/usr/src/uts/common/io/scsi/targets/sd.c b/usr/src/uts/common/io/scsi/targets/sd.c index e5d35025fe..eb57ec143b 100644 --- a/usr/src/uts/common/io/scsi/targets/sd.c +++ b/usr/src/uts/common/io/scsi/targets/sd.c @@ -22347,6 +22347,20 @@ skip_ready_valid: } break; + case DKIOCREADONLY: + SD_TRACE(SD_LOG_IOCTL, un, "DKIOCREADONLY\n"); + i = 0; + if ((ISCD(un) && !un->un_f_mmc_writable_media) || + (sr_check_wp(dev) != 0)) { + i = 1; + } + if (ddi_copyout(&i, (void *)arg, sizeof (int), flag) != 0) { + err = EFAULT; + } else { + err = 0; + } + break; + case DKIOCGTEMPERATURE: SD_TRACE(SD_LOG_IOCTL, un, "DKIOCGTEMPERATURE\n"); err = sd_dkio_get_temp(dev, (caddr_t)arg, flag); diff --git a/usr/src/uts/common/sys/dkio.h b/usr/src/uts/common/sys/dkio.h index 277397bdbd..b6833db391 100644 --- a/usr/src/uts/common/sys/dkio.h +++ b/usr/src/uts/common/sys/dkio.h @@ -311,6 +311,11 @@ enum dkio_state { DKIO_NONE, DKIO_EJECTED, DKIO_INSERTED, DKIO_DEV_GONE }; #define DKIOCGMEDIAINFOEXT (DKIOC|48) /* + * ioctl to determine whether media is write-protected + */ +#define DKIOCREADONLY (DKIOC|49) + +/* * Used for providing the temperature. */ -- 2.11.4.GIT