public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pierre Ossman <drzeus-list@drzeus.cx>
To: Russell King <rmk+lkml@arm.linux.org.uk>
Cc: LKML <linux-kernel@vger.kernel.org>, Ian Molton <spyro@f2s.com>,
	Richard Purdie <rpurdie@rpsys.net>
Subject: Re: [PATCH][MMC][3/6] Secure Digital (SD) support : ro
Date: Sun, 06 Mar 2005 02:47:19 +0100	[thread overview]
Message-ID: <422A6127.70906@drzeus.cx> (raw)
In-Reply-To: <422A5E1C.2050107@drzeus.cx>

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

Read-only support.

This patch adds a new callback for the drivers to facilitate reading the 
SD card read-only switch. If the callback is not provided then a warning 
will be printed and it will default to write-enable.

The read-only switch is a host enforced read-only so the MMC block layer 
has been changed to not allow rw mounts of ro cards. It also prints a 
'(ro)' for read-only cards.


[-- Attachment #2: mmc-sd-ro.patch --]
[-- Type: text/x-patch, Size: 3270 bytes --]

Index: linux-sd/include/linux/mmc/card.h
===================================================================
--- linux-sd/include/linux/mmc/card.h	(revision 137)
+++ linux-sd/include/linux/mmc/card.h	(working copy)
@@ -48,6 +48,7 @@
 #define MMC_STATE_DEAD		(1<<1)		/* device no longer in stack */
 #define MMC_STATE_BAD		(1<<2)		/* unrecognised device */
 #define MMC_STATE_SDCARD	(1<<3)		/* is an SD card */
+#define MMC_STATE_READONLY	(1<<4)		/* card is read-only */
 	u32			raw_cid[4];	/* raw card CID */
 	u32			raw_csd[4];	/* raw card CSD */
 	struct mmc_cid		cid;		/* card identification */
@@ -58,11 +59,13 @@
 #define mmc_card_dead(c)	((c)->state & MMC_STATE_DEAD)
 #define mmc_card_bad(c)		((c)->state & MMC_STATE_BAD)
 #define mmc_card_sd(c)		((c)->state & MMC_STATE_SDCARD)
+#define mmc_card_readonly(c)	((c)->state & MMC_STATE_READONLY)
 
 #define mmc_card_set_present(c)	((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_dead(c)	((c)->state |= MMC_STATE_DEAD)
 #define mmc_card_set_bad(c)	((c)->state |= MMC_STATE_BAD)
 #define mmc_card_set_sd(c)	((c)->state |= MMC_STATE_SDCARD)
+#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
 
 #define mmc_card_name(c)	((c)->cid.prod_name)
 #define mmc_card_id(c)		((c)->dev.bus_id)
Index: linux-sd/include/linux/mmc/host.h
===================================================================
--- linux-sd/include/linux/mmc/host.h	(revision 137)
+++ linux-sd/include/linux/mmc/host.h	(working copy)
@@ -56,6 +56,7 @@
 struct mmc_host_ops {
 	void	(*request)(struct mmc_host *host, struct mmc_request *req);
 	void	(*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
+	int	(*get_ro)(struct mmc_host *host);
 };
 
 struct mmc_card;
Index: linux-sd/drivers/mmc/mmc_block.c
===================================================================
--- linux-sd/drivers/mmc/mmc_block.c	(revision 135)
+++ linux-sd/drivers/mmc/mmc_block.c	(working copy)
@@ -95,6 +95,10 @@
 		if (md->usage == 2)
 			check_disk_change(inode->i_bdev);
 		ret = 0;
+		
+		if ((filp->f_mode & FMODE_WRITE) &&
+			mmc_card_readonly(md->queue.card))
+			ret = -EROFS;
 	}
 
 	return ret;
@@ -400,9 +404,10 @@
 	if (err)
 		goto out;
 
-	printk(KERN_INFO "%s: %s %s %dKiB\n",
+	printk(KERN_INFO "%s: %s %s %dKiB %s\n",
 		md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
-		(card->csd.capacity << card->csd.read_blkbits) / 1024);
+		(card->csd.capacity << card->csd.read_blkbits) / 1024,
+		mmc_card_readonly(card)?"(ro)":"");
 
 	mmc_set_drvdata(card, md);
 	add_disk(md->disk);
Index: linux-sd/drivers/mmc/mmc.c
===================================================================
--- linux-sd/drivers/mmc/mmc.c	(revision 137)
+++ linux-sd/drivers/mmc/mmc.c	(working copy)
@@ -726,8 +726,20 @@
 			err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
 			if (err != MMC_ERR_NONE)
 				mmc_card_set_dead(card);
-			else
+			else {			
 				card->rca = cmd.resp[0] >> 16;
+				
+				if (!host->ops->get_ro) {
+					printk(KERN_WARNING "%s: host does not "
+						"support reading read-only "
+						"switch. assuming write-enable.\n",
+						host->host_name);
+				}
+				else {
+					if (host->ops->get_ro(host))
+						mmc_card_set_readonly(card);
+				}
+			}
 		}
 		else {
 			cmd.opcode = MMC_SET_RELATIVE_ADDR;

  parent reply	other threads:[~2005-03-06  1:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-03 12:22 [PATCH][MMC] Secure Digital (SD) support Pierre Ossman
2005-03-04 13:22 ` Pavel Machek
2005-03-04 15:00 ` Marcel Holtmann
2005-03-04 15:12   ` Pierre Ossman
2005-03-04 16:22     ` Marcel Holtmann
2005-03-04 21:04     ` Ian Molton
2005-03-05 11:37 ` Russell King
2005-03-05 12:23   ` Pierre Ossman
2005-03-05 12:44     ` Russell King
2005-03-05 13:46       ` Pierre Ossman
2005-03-05 16:24         ` Richard Purdie
2005-05-06 14:15         ` Pierre Ossman
2005-03-06  1:34       ` [PATCH][MMC][0/6] " Pierre Ossman
2005-03-06  1:37         ` [PATCH][MMC][1/6] Secure Digital (SD) support : protocol Pierre Ossman
2005-03-19 16:35           ` Russell King
2005-03-06  1:44         ` [PATCH][MMC][2/6] Secure Digital (SD) support : init Pierre Ossman
2005-03-06  1:47         ` Pierre Ossman [this message]
2005-03-06  1:50         ` [PATCH][MMC][4/6] Secure Digital (SD) support : SCR Pierre Ossman
2005-03-06  1:52         ` [PATCH][MMC][5/6] Secure Digital (SD) support : sysfs Pierre Ossman
2005-03-06  1:57         ` [PATCH][MMC][6/6] Secure Digital (SD) support : wide bus Pierre Ossman
2005-03-12 17:35         ` [PATCH][MMC][7/6] Secure Digital (SD) support : Copyright Pierre Ossman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=422A6127.70906@drzeus.cx \
    --to=drzeus-list@drzeus.cx \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk+lkml@arm.linux.org.uk \
    --cc=rpurdie@rpsys.net \
    --cc=spyro@f2s.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox