diff options
Diffstat (limited to 'fs/partitions')
-rw-r--r-- | fs/partitions/check.c | 12 | ||||
-rw-r--r-- | fs/partitions/efi.c | 30 | ||||
-rw-r--r-- | fs/partitions/efi.h | 8 |
3 files changed, 37 insertions, 13 deletions
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 7b685e10cbad..64bc8998ac9a 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -226,6 +226,13 @@ ssize_t part_alignment_offset_show(struct device *dev, | |||
226 | return sprintf(buf, "%llu\n", (unsigned long long)p->alignment_offset); | 226 | return sprintf(buf, "%llu\n", (unsigned long long)p->alignment_offset); |
227 | } | 227 | } |
228 | 228 | ||
229 | ssize_t part_discard_alignment_show(struct device *dev, | ||
230 | struct device_attribute *attr, char *buf) | ||
231 | { | ||
232 | struct hd_struct *p = dev_to_part(dev); | ||
233 | return sprintf(buf, "%u\n", p->discard_alignment); | ||
234 | } | ||
235 | |||
229 | ssize_t part_stat_show(struct device *dev, | 236 | ssize_t part_stat_show(struct device *dev, |
230 | struct device_attribute *attr, char *buf) | 237 | struct device_attribute *attr, char *buf) |
231 | { | 238 | { |
@@ -288,6 +295,8 @@ static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL); | |||
288 | static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); | 295 | static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); |
289 | static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); | 296 | static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); |
290 | static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); | 297 | static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL); |
298 | static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show, | ||
299 | NULL); | ||
291 | static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); | 300 | static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); |
292 | static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL); | 301 | static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL); |
293 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 302 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
@@ -300,6 +309,7 @@ static struct attribute *part_attrs[] = { | |||
300 | &dev_attr_start.attr, | 309 | &dev_attr_start.attr, |
301 | &dev_attr_size.attr, | 310 | &dev_attr_size.attr, |
302 | &dev_attr_alignment_offset.attr, | 311 | &dev_attr_alignment_offset.attr, |
312 | &dev_attr_discard_alignment.attr, | ||
303 | &dev_attr_stat.attr, | 313 | &dev_attr_stat.attr, |
304 | &dev_attr_inflight.attr, | 314 | &dev_attr_inflight.attr, |
305 | #ifdef CONFIG_FAIL_MAKE_REQUEST | 315 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
@@ -403,6 +413,8 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, | |||
403 | 413 | ||
404 | p->start_sect = start; | 414 | p->start_sect = start; |
405 | p->alignment_offset = queue_sector_alignment_offset(disk->queue, start); | 415 | p->alignment_offset = queue_sector_alignment_offset(disk->queue, start); |
416 | p->discard_alignment = queue_sector_discard_alignment(disk->queue, | ||
417 | start); | ||
406 | p->nr_sects = len; | 418 | p->nr_sects = len; |
407 | p->partno = partno; | 419 | p->partno = partno; |
408 | p->policy = get_disk_ro(disk); | 420 | p->policy = get_disk_ro(disk); |
diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c index 038a6022152f..49cfd5f54238 100644 --- a/fs/partitions/efi.c +++ b/fs/partitions/efi.c | |||
@@ -1,7 +1,9 @@ | |||
1 | /************************************************************ | 1 | /************************************************************ |
2 | * EFI GUID Partition Table handling | 2 | * EFI GUID Partition Table handling |
3 | * Per Intel EFI Specification v1.02 | 3 | * |
4 | * http://developer.intel.com/technology/efi/efi.htm | 4 | * http://www.uefi.org/specs/ |
5 | * http://www.intel.com/technology/efi/ | ||
6 | * | ||
5 | * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com> | 7 | * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com> |
6 | * Copyright 2000,2001,2002,2004 Dell Inc. | 8 | * Copyright 2000,2001,2002,2004 Dell Inc. |
7 | * | 9 | * |
@@ -92,6 +94,7 @@ | |||
92 | * | 94 | * |
93 | ************************************************************/ | 95 | ************************************************************/ |
94 | #include <linux/crc32.h> | 96 | #include <linux/crc32.h> |
97 | #include <linux/math64.h> | ||
95 | #include "check.h" | 98 | #include "check.h" |
96 | #include "efi.h" | 99 | #include "efi.h" |
97 | 100 | ||
@@ -141,7 +144,8 @@ last_lba(struct block_device *bdev) | |||
141 | { | 144 | { |
142 | if (!bdev || !bdev->bd_inode) | 145 | if (!bdev || !bdev->bd_inode) |
143 | return 0; | 146 | return 0; |
144 | return (bdev->bd_inode->i_size >> 9) - 1ULL; | 147 | return div_u64(bdev->bd_inode->i_size, |
148 | bdev_logical_block_size(bdev)) - 1ULL; | ||
145 | } | 149 | } |
146 | 150 | ||
147 | static inline int | 151 | static inline int |
@@ -188,6 +192,7 @@ static size_t | |||
188 | read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count) | 192 | read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count) |
189 | { | 193 | { |
190 | size_t totalreadcount = 0; | 194 | size_t totalreadcount = 0; |
195 | sector_t n = lba * (bdev_logical_block_size(bdev) / 512); | ||
191 | 196 | ||
192 | if (!bdev || !buffer || lba > last_lba(bdev)) | 197 | if (!bdev || !buffer || lba > last_lba(bdev)) |
193 | return 0; | 198 | return 0; |
@@ -195,7 +200,7 @@ read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count) | |||
195 | while (count) { | 200 | while (count) { |
196 | int copied = 512; | 201 | int copied = 512; |
197 | Sector sect; | 202 | Sector sect; |
198 | unsigned char *data = read_dev_sector(bdev, lba++, §); | 203 | unsigned char *data = read_dev_sector(bdev, n++, §); |
199 | if (!data) | 204 | if (!data) |
200 | break; | 205 | break; |
201 | if (copied > count) | 206 | if (copied > count) |
@@ -257,15 +262,16 @@ static gpt_header * | |||
257 | alloc_read_gpt_header(struct block_device *bdev, u64 lba) | 262 | alloc_read_gpt_header(struct block_device *bdev, u64 lba) |
258 | { | 263 | { |
259 | gpt_header *gpt; | 264 | gpt_header *gpt; |
265 | unsigned ssz = bdev_logical_block_size(bdev); | ||
266 | |||
260 | if (!bdev) | 267 | if (!bdev) |
261 | return NULL; | 268 | return NULL; |
262 | 269 | ||
263 | gpt = kzalloc(sizeof (gpt_header), GFP_KERNEL); | 270 | gpt = kzalloc(ssz, GFP_KERNEL); |
264 | if (!gpt) | 271 | if (!gpt) |
265 | return NULL; | 272 | return NULL; |
266 | 273 | ||
267 | if (read_lba(bdev, lba, (u8 *) gpt, | 274 | if (read_lba(bdev, lba, (u8 *) gpt, ssz) < ssz) { |
268 | sizeof (gpt_header)) < sizeof (gpt_header)) { | ||
269 | kfree(gpt); | 275 | kfree(gpt); |
270 | gpt=NULL; | 276 | gpt=NULL; |
271 | return NULL; | 277 | return NULL; |
@@ -601,6 +607,7 @@ efi_partition(struct parsed_partitions *state, struct block_device *bdev) | |||
601 | gpt_header *gpt = NULL; | 607 | gpt_header *gpt = NULL; |
602 | gpt_entry *ptes = NULL; | 608 | gpt_entry *ptes = NULL; |
603 | u32 i; | 609 | u32 i; |
610 | unsigned ssz = bdev_logical_block_size(bdev) / 512; | ||
604 | 611 | ||
605 | if (!find_valid_gpt(bdev, &gpt, &ptes) || !gpt || !ptes) { | 612 | if (!find_valid_gpt(bdev, &gpt, &ptes) || !gpt || !ptes) { |
606 | kfree(gpt); | 613 | kfree(gpt); |
@@ -611,13 +618,14 @@ efi_partition(struct parsed_partitions *state, struct block_device *bdev) | |||
611 | pr_debug("GUID Partition Table is valid! Yea!\n"); | 618 | pr_debug("GUID Partition Table is valid! Yea!\n"); |
612 | 619 | ||
613 | for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { | 620 | for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) { |
621 | u64 start = le64_to_cpu(ptes[i].starting_lba); | ||
622 | u64 size = le64_to_cpu(ptes[i].ending_lba) - | ||
623 | le64_to_cpu(ptes[i].starting_lba) + 1ULL; | ||
624 | |||
614 | if (!is_pte_valid(&ptes[i], last_lba(bdev))) | 625 | if (!is_pte_valid(&ptes[i], last_lba(bdev))) |
615 | continue; | 626 | continue; |
616 | 627 | ||
617 | put_partition(state, i+1, le64_to_cpu(ptes[i].starting_lba), | 628 | put_partition(state, i+1, start * ssz, size * ssz); |
618 | (le64_to_cpu(ptes[i].ending_lba) - | ||
619 | le64_to_cpu(ptes[i].starting_lba) + | ||
620 | 1ULL)); | ||
621 | 629 | ||
622 | /* If this is a RAID volume, tell md */ | 630 | /* If this is a RAID volume, tell md */ |
623 | if (!efi_guidcmp(ptes[i].partition_type_guid, | 631 | if (!efi_guidcmp(ptes[i].partition_type_guid, |
diff --git a/fs/partitions/efi.h b/fs/partitions/efi.h index 2cc89d0475bf..6998b589abf9 100644 --- a/fs/partitions/efi.h +++ b/fs/partitions/efi.h | |||
@@ -37,7 +37,6 @@ | |||
37 | #define EFI_PMBR_OSTYPE_EFI 0xEF | 37 | #define EFI_PMBR_OSTYPE_EFI 0xEF |
38 | #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE | 38 | #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE |
39 | 39 | ||
40 | #define GPT_BLOCK_SIZE 512 | ||
41 | #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL | 40 | #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL |
42 | #define GPT_HEADER_REVISION_V1 0x00010000 | 41 | #define GPT_HEADER_REVISION_V1 0x00010000 |
43 | #define GPT_PRIMARY_PARTITION_TABLE_LBA 1 | 42 | #define GPT_PRIMARY_PARTITION_TABLE_LBA 1 |
@@ -79,7 +78,12 @@ typedef struct _gpt_header { | |||
79 | __le32 num_partition_entries; | 78 | __le32 num_partition_entries; |
80 | __le32 sizeof_partition_entry; | 79 | __le32 sizeof_partition_entry; |
81 | __le32 partition_entry_array_crc32; | 80 | __le32 partition_entry_array_crc32; |
82 | u8 reserved2[GPT_BLOCK_SIZE - 92]; | 81 | |
82 | /* The rest of the logical block is reserved by UEFI and must be zero. | ||
83 | * EFI standard handles this by: | ||
84 | * | ||
85 | * uint8_t reserved2[ BlockSize - 92 ]; | ||
86 | */ | ||
83 | } __attribute__ ((packed)) gpt_header; | 87 | } __attribute__ ((packed)) gpt_header; |
84 | 88 | ||
85 | typedef struct _gpt_entry_attributes { | 89 | typedef struct _gpt_entry_attributes { |