mmccam: fix mmcsd disk aliases

For EXT_CSD_PART_CONFIG_ACC_BOOT<n> and possibly others with suffixes
we fail to create proper disk aliases (symlinks), which shows up as
g_dev_taste: make_dev_alias_p() failed (name=mmcsd0, error=17)

In this case we ended up with the followng two:
  /dev/mmcsd0 -> sdda0
  /dev/mmcsd1 -> sdda0boot1
Note that (i) it should be mmcsd0boot1 and not mmcsd1 and that
(ii) there is no mmcsd0boot0 (failed above as it tried to create a
second mmcsd0).

Adjust the code (using a highly simplified version--compared to my
original approach--suggested by imp) using an extended format string
with (sdda/mmcsd) prefix as first argument to create proper names.

Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D43538

(cherry picked from commit a84d91d81a6f3eeb4949c4fb3440e0634f2b953a)
This commit is contained in:
Bjoern A. Zeeb 2024-01-21 19:56:27 +00:00
parent d60a0ffecf
commit 6f58191b30

View file

@ -89,9 +89,11 @@ typedef enum {
SDDA_STATE_PART_SWITCH,
} sdda_state;
#define SDDA_FMT_BOOT "sdda%dboot"
#define SDDA_FMT_GP "sdda%dgp"
#define SDDA_FMT_RPMB "sdda%drpmb"
/* Purposefully ignore a '%d' argument to snprintf in SDDA_FMT! */
#define SDDA_FMT "%s"
#define SDDA_FMT_BOOT "%s%dboot"
#define SDDA_FMT_GP "%s%dgp"
#define SDDA_FMT_RPMB "%s%drpmb"
#define SDDA_LABEL_ENH "enh"
#define SDDA_PART_NAMELEN (16 + 1)
@ -1481,7 +1483,7 @@ finish_hs_tests:
sdda_process_mmc_partitions(periph, start_ccb);
} else if (mmcp->card_features & CARD_FEATURE_MEMORY) {
/* For SD[HC] cards, just add one partition that is the whole card */
if (sdda_add_part(periph, 0, "sdda",
if (sdda_add_part(periph, 0, SDDA_FMT,
periph->unit_number,
mmc_get_media_size(periph),
sdda_get_read_only(periph, start_ccb)) == false)
@ -1526,7 +1528,7 @@ sdda_add_part(struct cam_periph *periph, u_int type, const char *name,
part->type = type;
part->ro = ro;
part->sc = sc;
snprintf(part->name, sizeof(part->name), name, periph->unit_number);
snprintf(part->name, sizeof(part->name), name, "sdda", periph->unit_number);
/*
* Due to the nature of RPMB partition it doesn't make much sense
@ -1593,8 +1595,11 @@ sdda_add_part(struct cam_periph *periph, u_int type, const char *name,
part->disk->d_fwsectors = 0;
part->disk->d_fwheads = 0;
if (sdda_mmcsd_compat)
disk_add_alias(part->disk, "mmcsd");
if (sdda_mmcsd_compat) {
char cname[SDDA_PART_NAMELEN]; /* This equals the mmcsd namelen. */
snprintf(cname, sizeof(cname), name, "mmcsd", periph->unit_number);
disk_add_alias(part->disk, cname);
}
/*
* Acquire a reference to the periph before we register with GEOM.
@ -1683,7 +1688,7 @@ sdda_process_mmc_partitions(struct cam_periph *periph, union ccb *ccb)
* data area in case partitions are supported.
*/
ro = sdda_get_read_only(periph, ccb);
sdda_add_part(periph, EXT_CSD_PART_CONFIG_ACC_DEFAULT, "sdda",
sdda_add_part(periph, EXT_CSD_PART_CONFIG_ACC_DEFAULT, SDDA_FMT,
periph->unit_number, mmc_get_media_size(periph), ro);
sc->part_curr = EXT_CSD_PART_CONFIG_ACC_DEFAULT;