From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
To: linux-ide@vger.kernel.org
Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
"Andries E. Brouwer" <Andries.Brouwer@cwi.nl>,
linux-kernel@vger.kernel.org,
Robert Hancock <hancockrwd@gmail.com>,
Al Viro <viro@zeniv.linux.org.uk>, Frans Pop <elendil@planet.nl>
Subject: [PATCH 3/4] ide-gd: implement block device ->set_capacity method
Date: Sun, 31 May 2009 16:39:31 +0200 [thread overview]
Message-ID: <20090531143931.7164.96956.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20090531143911.7164.26834.sendpatchset@localhost.localdomain>
From: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Subject: [PATCH] ide-gd: implement block device ->set_capacity method
* Use ->probed_capacity to store native device capacity for ATA disks.
* Add ->set_capacity method to struct ide_disk_ops.
* Implement disk device ->set_capacity method for ATA disks.
* Implement block device ->set_capacity method.
Together with the previous patch adding ->set_capacity block device
method this allows automatic disabling of Host Protected Area (HPA)
if any partitions overlapping HPA are detected.
Cc: Robert Hancock <hancockrwd@gmail.com>
Cc: Frans Pop <elendil@planet.nl>
Cc: "Andries E. Brouwer" <Andries.Brouwer@cwi.nl>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
drivers/ide/ide-disk.c | 19 ++++++++++++++++++-
drivers/ide/ide-gd.c | 14 ++++++++++++++
include/linux/ide.h | 4 ++--
3 files changed, 34 insertions(+), 3 deletions(-)
Index: b/drivers/ide/ide-disk.c
===================================================================
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -323,6 +323,8 @@ static void idedisk_check_hpa(ide_drive_
if (set_max <= capacity)
return;
+ drive->probed_capacity = set_max;
+
printk(KERN_INFO "%s: Host Protected Area detected.\n"
"\tcurrent capacity is %llu sectors (%llu MB)\n"
"\tnative capacity is %llu sectors (%llu MB)\n",
@@ -358,6 +360,8 @@ static int ide_disk_get_capacity(ide_dri
drive->capacity64 = drive->cyl * drive->head * drive->sect;
}
+ drive->probed_capacity = drive->capacity64;
+
if (lba) {
drive->dev_flags |= IDE_DFLAG_LBA;
@@ -376,7 +380,7 @@ static int ide_disk_get_capacity(ide_dri
"%llu sectors (%llu MB)\n",
drive->name, (unsigned long long)drive->capacity64,
sectors_to_MB(drive->capacity64));
- drive->capacity64 = 1ULL << 28;
+ drive->probed_capacity = drive->capacity64 = 1ULL << 28;
}
if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
@@ -392,6 +396,18 @@ static int ide_disk_get_capacity(ide_dri
return 0;
}
+static u64 ide_disk_set_capacity(ide_drive_t *drive, u64 capacity)
+{
+ u64 set = min(capacity, drive->probed_capacity);
+ int lba48 = ata_id_lba48_enabled(drive->id);
+
+ capacity = idedisk_set_max_address(drive, set, lba48);
+ if (capacity)
+ drive->capacity64 = capacity;
+
+ return drive->capacity64;
+}
+
static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
{
ide_drive_t *drive = q->queuedata;
@@ -740,6 +756,7 @@ static int ide_disk_set_doorlock(ide_dri
const struct ide_disk_ops ide_ata_disk_ops = {
.check = ide_disk_check,
+ .set_capacity = ide_disk_set_capacity,
.get_capacity = ide_disk_get_capacity,
.setup = ide_disk_setup,
.flush = ide_disk_flush,
Index: b/drivers/ide/ide-gd.c
===================================================================
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -287,6 +287,19 @@ static int ide_gd_media_changed(struct g
return ret;
}
+static unsigned long long ide_gd_set_capacity(struct gendisk *disk,
+ unsigned long long capacity)
+{
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
+ ide_drive_t *drive = idkp->drive;
+ const struct ide_disk_ops *disk_ops = drive->disk_ops;
+
+ if (disk_ops->set_capacity)
+ return disk_ops->set_capacity(drive, capacity);
+
+ return drive->capacity64;
+}
+
static int ide_gd_revalidate_disk(struct gendisk *disk)
{
struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
@@ -315,6 +328,7 @@ static struct block_device_operations id
.locked_ioctl = ide_gd_ioctl,
.getgeo = ide_gd_getgeo,
.media_changed = ide_gd_media_changed,
+ .set_capacity = ide_gd_set_capacity,
.revalidate_disk = ide_gd_revalidate_disk
};
Index: b/include/linux/ide.h
===================================================================
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -381,6 +381,7 @@ struct ide_drive_s;
struct ide_disk_ops {
int (*check)(struct ide_drive_s *, const char *);
int (*get_capacity)(struct ide_drive_s *);
+ u64 (*set_capacity)(struct ide_drive_s *, u64);
void (*setup)(struct ide_drive_s *);
void (*flush)(struct ide_drive_s *);
int (*init_media)(struct ide_drive_s *, struct gendisk *);
@@ -552,8 +553,7 @@ struct ide_drive_s {
unsigned int drive_data; /* used by set_pio_mode/dev_select() */
unsigned int failures; /* current failure count */
unsigned int max_failures; /* maximum allowed failure count */
- u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */
-
+ u64 probed_capacity;/* initial/native media capacity */
u64 capacity64; /* total number of sectors */
int lun; /* logical unit */
next prev parent reply other threads:[~2009-05-31 14:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-31 14:39 [PATCH 0/4] partitions/ide: improve Host Protected Area handling Bartlomiej Zolnierkiewicz
2009-05-31 14:39 ` [PATCH 1/4] partitions: warn about the partition exceeding device capacity Bartlomiej Zolnierkiewicz
2009-05-31 14:39 ` [PATCH 2/4] partitions: add ->set_capacity block device method Bartlomiej Zolnierkiewicz
2009-06-06 8:42 ` Al Viro
2009-05-31 14:39 ` Bartlomiej Zolnierkiewicz [this message]
2009-06-01 21:32 ` [PATCH 3/4] ide-gd: implement block device ->set_capacity method Bartlomiej Zolnierkiewicz
2009-06-02 18:55 ` Sergei Shtylyov
2009-06-05 18:38 ` Bartlomiej Zolnierkiewicz
2009-05-31 14:39 ` [PATCH 4/4] ide: preserve Host Protected Area by default Bartlomiej Zolnierkiewicz
2009-06-01 21:33 ` Bartlomiej Zolnierkiewicz
2009-06-02 19:12 ` Sergei Shtylyov
2009-05-31 15:24 ` [PATCH 0/4] partitions/ide: improve Host Protected Area handling Andries E. Brouwer
2009-05-31 15:34 ` Bartlomiej Zolnierkiewicz
2009-06-01 13:02 ` Greg Freemyer
2009-05-31 16:36 ` Alan Cox
2009-05-31 20:04 ` Frans Pop
2009-05-31 22:50 ` Andries E. Brouwer
2009-06-01 12:59 ` Greg Freemyer
2009-06-01 13:06 ` Alan Cox
2009-06-01 22:00 ` Bartlomiej Zolnierkiewicz
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=20090531143931.7164.96956.sendpatchset@localhost.localdomain \
--to=bzolnier@gmail.com \
--cc=Andries.Brouwer@cwi.nl \
--cc=elendil@planet.nl \
--cc=hancockrwd@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).