summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2025-11-18 12:51:22 -0600
committerTom Rini <[email protected]>2025-11-18 12:51:22 -0600
commitb8872deb4450b09586e28550c23d33a71084d94f (patch)
tree8dd5e2c78ed30bd1c0983f5e134ac2a77b85ddf0 /disk
parentabf15eb60c8a87f833f7e75e5e8a51a7eb115e0b (diff)
parent30890051ab23a0293f6404c9a49e86f33e45df66 (diff)
Merge patch series "'part name' subcommand and some robustification"
Rasmus Villemoes <[email protected]> says: Implement a "part name" subcommand, mirroring the existing "part number" subcommand. In the discussion for v1 of that, it came up that there's a bit of inconsistency in how much and what one can assume to be initialized in 'struct disk_partition' after a successful call of one of the get_info* family of functions. Patch 1/2 tries to consolidate that by making sure all ->get_info invocations go through a common helper that at least always initializes the string members. Quentin, I've taken the liberty of including your Acks, as the incremental diff in patch 1 is quite minor, but do speak up if I should not have done that. Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c63
1 files changed, 37 insertions, 26 deletions
diff --git a/disk/part.c b/disk/part.c
index be2b45d5a29..49a0fca6b89 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -72,6 +72,28 @@ struct part_driver *part_driver_lookup_type(struct blk_desc *desc)
return NULL;
}
+static void disk_partition_clr(struct disk_partition *info)
+{
+ /* The common case is no UUID support */
+ disk_partition_clr_uuid(info);
+ disk_partition_clr_type_guid(info);
+ info->name[0] = '\0';
+ info->type[0] = '\0';
+}
+
+int part_driver_get_info(struct part_driver *drv, struct blk_desc *desc, int part,
+ struct disk_partition *info)
+{
+ if (!drv->get_info) {
+ log_debug("## Driver %s does not have the get_info() method\n",
+ drv->name);
+ return -ENOSYS;
+ }
+
+ disk_partition_clr(info);
+ return drv->get_info(desc, part, info);
+}
+
int part_get_type_by_name(const char *name)
{
struct part_driver *drv =
@@ -322,12 +344,9 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
struct disk_partition *info)
{
struct part_driver *drv;
+ int ret = -ENOENT;
if (blk_enabled()) {
- /* The common case is no UUID support */
- disk_partition_clr_uuid(info);
- disk_partition_clr_type_guid(info);
-
if (part_type == PART_TYPE_UNKNOWN) {
drv = part_driver_lookup_type(desc);
} else {
@@ -339,18 +358,16 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
desc->part_type);
return -EPROTONOSUPPORT;
}
- if (!drv->get_info) {
- PRINTF("## Driver %s does not have the get_info() method\n",
- drv->name);
- return -ENOSYS;
- }
- if (drv->get_info(desc, part, info) == 0) {
+
+ ret = part_driver_get_info(drv, desc, part, info);
+ if (ret && ret != -ENOSYS) {
+ ret = -ENOENT;
+ } else {
PRINTF("## Valid %s partition found ##\n", drv->name);
- return 0;
}
}
- return -ENOENT;
+ return ret;
}
int part_get_info(struct blk_desc *desc, int part,
@@ -657,15 +674,12 @@ int part_get_info_by_name(struct blk_desc *desc, const char *name,
if (!part_drv)
return -1;
- if (!part_drv->get_info) {
- log_debug("## Driver %s does not have the get_info() method\n",
- part_drv->name);
- return -ENOSYS;
- }
-
for (i = 1; i < part_drv->max_entries; i++) {
- ret = part_drv->get_info(desc, i, info);
+ ret = part_driver_get_info(part_drv, desc, i, info);
if (ret != 0) {
+ /* -ENOSYS means no ->get_info method. */
+ if (ret == -ENOSYS)
+ return ret;
/*
* Partition with this index can't be obtained, but
* further partitions might be, so keep checking.
@@ -695,15 +709,12 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
if (!part_drv)
return -1;
- if (!part_drv->get_info) {
- log_debug("## Driver %s does not have the get_info() method\n",
- part_drv->name);
- return -ENOSYS;
- }
-
for (i = 1; i < part_drv->max_entries; i++) {
- ret = part_drv->get_info(desc, i, info);
+ ret = part_driver_get_info(part_drv, desc, i, info);
if (ret != 0) {
+ /* -ENOSYS means no ->get_info method. */
+ if (ret == -ENOSYS)
+ return ret;
/*
* Partition with this index can't be obtained, but
* further partitions might be, so keep checking.