block/partitions/core.c
Source file repositories/reference/linux-study-clean/block/partitions/core.c
File Facts
- System
- Linux kernel
- Corpus path
block/partitions/core.c- Extension
.c- Size
- 17653 bytes
- Lines
- 734
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/major.hlinux/slab.hlinux/string.hlinux/sysfs.hlinux/ctype.hlinux/vmalloc.hlinux/raid/detect.hcheck.h
Detected Declarations
function free_partitionsfunction part_partition_showfunction part_start_showfunction part_ro_showfunction part_alignment_offset_showfunction part_discard_alignment_showfunction part_releasefunction part_ueventfunction drop_partitionfunction whole_disk_showfunction partition_overlapsfunction bdev_add_partitionfunction bdev_del_partitionfunction bdev_resize_partitionfunction disk_unlock_native_capacityfunction blk_add_partitionfunction blk_add_partitionsfunction bdev_disk_changedfunction xa_for_each_startfunction partitionsexport bdev_disk_changed
Annotated Snippet
err = device_add(pdev);
if (err)
goto out_put;
err = -ENOMEM;
bdev->bd_holder_dir = kobject_create_and_add("holders", &pdev->kobj);
if (!bdev->bd_holder_dir)
goto out_del;
dev_set_uevent_suppress(pdev, 0);
if (flags & ADDPART_FLAG_WHOLEDISK) {
err = device_create_file(pdev, &dev_attr_whole_disk);
if (err)
goto out_del;
}
if (flags & ADDPART_FLAG_READONLY)
bdev_set_flag(bdev, BD_READ_ONLY);
/* everything is up and running, commence */
err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL);
if (err)
goto out_del;
bdev_add(bdev, devt);
/* suppress uevent if the disk suppresses it */
if (!dev_get_uevent_suppress(ddev))
kobject_uevent(&pdev->kobj, KOBJ_ADD);
return bdev;
out_del:
kobject_put(bdev->bd_holder_dir);
device_del(pdev);
out_put:
put_device(pdev);
return ERR_PTR(err);
out_put_disk:
put_disk(disk);
return ERR_PTR(err);
}
static bool partition_overlaps(struct gendisk *disk, sector_t start,
sector_t length, int skip_partno)
{
struct block_device *part;
bool overlap = false;
unsigned long idx;
rcu_read_lock();
xa_for_each_start(&disk->part_tbl, idx, part, 1) {
if (bdev_partno(part) != skip_partno &&
start < part->bd_start_sect + bdev_nr_sectors(part) &&
start + length > part->bd_start_sect) {
overlap = true;
break;
}
}
rcu_read_unlock();
return overlap;
}
int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
sector_t length)
{
struct block_device *part;
int ret;
mutex_lock(&disk->open_mutex);
if (!disk_live(disk)) {
ret = -ENXIO;
goto out;
}
if (disk->flags & GENHD_FL_NO_PART) {
ret = -EINVAL;
goto out;
}
if (partition_overlaps(disk, start, length, -1)) {
ret = -EBUSY;
goto out;
}
part = add_partition(disk, partno, start, length,
ADDPART_FLAG_NONE, NULL);
ret = PTR_ERR_OR_ZERO(part);
out:
mutex_unlock(&disk->open_mutex);
return ret;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/major.h`, `linux/slab.h`, `linux/string.h`, `linux/sysfs.h`, `linux/ctype.h`, `linux/vmalloc.h`, `linux/raid/detect.h`.
- Detected declarations: `function free_partitions`, `function part_partition_show`, `function part_start_show`, `function part_ro_show`, `function part_alignment_offset_show`, `function part_discard_alignment_show`, `function part_release`, `function part_uevent`, `function drop_partition`, `function whole_disk_show`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.