core.c (86416916466514e4ae0b7296d20133b6427c4c1f) | core.c (1ebe2e5f9d68e94c524aba876f27b945669a7879) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 1991-1998 Linus Torvalds 4 * Re-organised Feb 1998 Russell King 5 * Copyright (C) 2020 Christoph Hellwig 6 */ 7#include <linux/fs.h> 8#include <linux/major.h> --- 84 unchanged lines hidden (view full) --- 93 i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT); 94 bdev->bd_nr_sectors = sectors; 95 spin_unlock(&bdev->bd_size_lock); 96} 97 98static struct parsed_partitions *allocate_partitions(struct gendisk *hd) 99{ 100 struct parsed_partitions *state; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 1991-1998 Linus Torvalds 4 * Re-organised Feb 1998 Russell King 5 * Copyright (C) 2020 Christoph Hellwig 6 */ 7#include <linux/fs.h> 8#include <linux/major.h> --- 84 unchanged lines hidden (view full) --- 93 i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT); 94 bdev->bd_nr_sectors = sectors; 95 spin_unlock(&bdev->bd_size_lock); 96} 97 98static struct parsed_partitions *allocate_partitions(struct gendisk *hd) 99{ 100 struct parsed_partitions *state; |
101 int nr; | 101 int nr = DISK_MAX_PARTS; |
102 103 state = kzalloc(sizeof(*state), GFP_KERNEL); 104 if (!state) 105 return NULL; 106 | 102 103 state = kzalloc(sizeof(*state), GFP_KERNEL); 104 if (!state) 105 return NULL; 106 |
107 nr = disk_max_parts(hd); | |
108 state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); 109 if (!state->parts) { 110 kfree(state); 111 return NULL; 112 } 113 114 state->limit = nr; 115 --- 205 unchanged lines hidden (view full) --- 321 struct device *ddev = disk_to_dev(disk); 322 struct device *pdev; 323 struct block_device *bdev; 324 const char *dname; 325 int err; 326 327 lockdep_assert_held(&disk->open_mutex); 328 | 107 state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); 108 if (!state->parts) { 109 kfree(state); 110 return NULL; 111 } 112 113 state->limit = nr; 114 --- 205 unchanged lines hidden (view full) --- 320 struct device *ddev = disk_to_dev(disk); 321 struct device *pdev; 322 struct block_device *bdev; 323 const char *dname; 324 int err; 325 326 lockdep_assert_held(&disk->open_mutex); 327 |
329 if (partno >= disk_max_parts(disk)) | 328 if (partno >= DISK_MAX_PARTS) |
330 return ERR_PTR(-EINVAL); 331 332 /* 333 * Partitions are not supported on zoned block devices that are used as 334 * such. 335 */ 336 switch (disk->queue->limits.zoned) { 337 case BLK_ZONED_HM: --- 261 unchanged lines hidden (view full) --- 599 return true; 600} 601 602static int blk_add_partitions(struct gendisk *disk) 603{ 604 struct parsed_partitions *state; 605 int ret = -EAGAIN, p; 606 | 329 return ERR_PTR(-EINVAL); 330 331 /* 332 * Partitions are not supported on zoned block devices that are used as 333 * such. 334 */ 335 switch (disk->queue->limits.zoned) { 336 case BLK_ZONED_HM: --- 261 unchanged lines hidden (view full) --- 598 return true; 599} 600 601static int blk_add_partitions(struct gendisk *disk) 602{ 603 struct parsed_partitions *state; 604 int ret = -EAGAIN, p; 605 |
607 if (!disk_part_scan_enabled(disk)) | 606 if (disk->flags & GENHD_FL_NO_PART) |
608 return 0; 609 610 state = check_partition(disk); 611 if (!state) 612 return 0; 613 if (IS_ERR(state)) { 614 /* 615 * I/O error reading the partition table. If we tried to read --- 66 unchanged lines hidden (view full) --- 682 * Historically we only set the capacity to zero for devices that 683 * support partitions (independ of actually having partitions created). 684 * Doing that is rather inconsistent, but changing it broke legacy 685 * udisks polling for legacy ide-cdrom devices. Use the crude check 686 * below to get the sane behavior for most device while not breaking 687 * userspace for this particular setup. 688 */ 689 if (invalidate) { | 607 return 0; 608 609 state = check_partition(disk); 610 if (!state) 611 return 0; 612 if (IS_ERR(state)) { 613 /* 614 * I/O error reading the partition table. If we tried to read --- 66 unchanged lines hidden (view full) --- 681 * Historically we only set the capacity to zero for devices that 682 * support partitions (independ of actually having partitions created). 683 * Doing that is rather inconsistent, but changing it broke legacy 684 * udisks polling for legacy ide-cdrom devices. Use the crude check 685 * below to get the sane behavior for most device while not breaking 686 * userspace for this particular setup. 687 */ 688 if (invalidate) { |
690 if (disk_part_scan_enabled(disk) || | 689 if (!(disk->flags & GENHD_FL_NO_PART) || |
691 !(disk->flags & GENHD_FL_REMOVABLE)) 692 set_capacity(disk, 0); 693 } 694 695 if (get_capacity(disk)) { 696 ret = blk_add_partitions(disk); 697 if (ret == -EAGAIN) 698 goto rescan; --- 42 unchanged lines hidden --- | 690 !(disk->flags & GENHD_FL_REMOVABLE)) 691 set_capacity(disk, 0); 692 } 693 694 if (get_capacity(disk)) { 695 ret = blk_add_partitions(disk); 696 if (ret == -EAGAIN) 697 goto rescan; --- 42 unchanged lines hidden --- |