Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751338AbWJLXvF (ORCPT ); Thu, 12 Oct 2006 19:51:05 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751339AbWJLXvF (ORCPT ); Thu, 12 Oct 2006 19:51:05 -0400 Received: from ns2.suse.de ([195.135.220.15]:2751 "EHLO mx2.suse.de") by vger.kernel.org with ESMTP id S1751338AbWJLXvC (ORCPT ); Thu, 12 Oct 2006 19:51:02 -0400 From: Neil Brown To: linux-kernel@vger.kernel.org Date: Fri, 13 Oct 2006 09:50:49 +1000 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17710.54489.486265.487078@cse.unsw.edu.au> Cc: aeb@cwi.nl, Jens Axboe Subject: Why aren't partitions limited to fit within the device? X-Mailer: VM 7.19 under Emacs 21.4.1 X-face: [Gw_3E*Gng}4rRrKRYotwlE?.2|**#s9D ### Diffstat output ./block/ioctl.c | 6 ++++++ ./fs/partitions/check.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff .prev/block/ioctl.c ./block/ioctl.c --- .prev/block/ioctl.c 2006-10-09 14:25:11.000000000 +1000 +++ ./block/ioctl.c 2006-10-13 09:45:52.000000000 +1000 @@ -42,6 +42,12 @@ static int blkpg_ioctl(struct block_devi || pstart < 0 || plength < 0) return -EINVAL; } + /* Does partition fit within device */ + if (start + length > get_capacity(disk)) { + if (start >= get_capacity(disk)) + return -EINVAL; + length = get_capacity(disk) - start; + } /* partition number in use? */ mutex_lock(&bdev->bd_mutex); if (disk->part[part - 1]) { diff .prev/fs/partitions/check.c ./fs/partitions/check.c --- .prev/fs/partitions/check.c 2006-10-13 09:28:21.000000000 +1000 +++ ./fs/partitions/check.c 2006-10-13 09:46:12.000000000 +1000 @@ -466,8 +466,16 @@ int rescan_partitions(struct gendisk *di if (!size) continue; if (from + size > get_capacity(disk)) { - printk(" %s: p%d exceeds device capacity\n", - disk->disk_name, p); + if (from >= get_capacity(disk)) { + printk(KERN_INFO + " %s: p%d starts beyond end of device\n", + disk->disk_name, p); + continue; + } + printk(KERN_INFO + " %s: p%d exceeds device capacity - clipping\n", + disk->disk_name, p); + size = get_capacity(disk) - from; } add_partition(disk, p, from, size); #ifdef CONFIG_BLK_DEV_MD - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/