drivers/mtd/mtd_partition.c: Copy the partition name to internal buffer so that the caller can free the name argument
This commit is contained in:
parent
159b88c871
commit
41a1e76735
@ -93,7 +93,7 @@ struct mtd_partition_s
|
||||
struct mtd_partition_s *pnext; /* Pointer to next partition struct */
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_PARTITION_NAMES
|
||||
FAR const char *name; /* Name of the partition */
|
||||
char name[11]; /* Name of the partition */
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -604,34 +604,27 @@ static ssize_t part_procfs_read(FAR struct file *filep, FAR char *buffer,
|
||||
/* Copy data from the next known partition */
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITION_NAMES
|
||||
if (attr->nextpart->name == NULL)
|
||||
ptr = attr->nextpart->name;
|
||||
for (x = 0; x < sizeof(partname) - 1; x++)
|
||||
{
|
||||
strcpy(partname, "(noname) ");
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = attr->nextpart->name;
|
||||
for (x = 0; x < sizeof(partname) - 1; x++)
|
||||
/* Test for end of partition name */
|
||||
|
||||
if (*ptr == ',' || *ptr == '\0')
|
||||
{
|
||||
/* Test for end of partition name */
|
||||
/* Perform space fill for alignment */
|
||||
|
||||
if (*ptr == ',' || *ptr == '\0')
|
||||
{
|
||||
/* Perform space fill for alignment */
|
||||
|
||||
partname[x] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy next byte of partition name */
|
||||
|
||||
partname[x] = *ptr++;
|
||||
}
|
||||
partname[x] = ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy next byte of partition name */
|
||||
|
||||
partname[x] = '\0';
|
||||
partname[x] = *ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
partname[x] = '\0';
|
||||
|
||||
/* Terminate the partition name and add to output buffer */
|
||||
|
||||
ret = snprintf(&buffer[total], buflen - total, "%s%7d %7d",
|
||||
@ -860,7 +853,7 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t firstblock,
|
||||
part->blkpererase = blkpererase;
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITION_NAMES
|
||||
part->name = NULL;
|
||||
strcpy(part->name, "(noname)");
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_PROCFS_EXCLUDE_PARTITIONS)
|
||||
@ -906,11 +899,14 @@ int mtd_setpartitionname(FAR struct mtd_dev_s *mtd, FAR const char *name)
|
||||
{
|
||||
FAR struct mtd_partition_s *priv = (FAR struct mtd_partition_s *)mtd;
|
||||
|
||||
DEBUGASSERT(mtd);
|
||||
DEBUGASSERT(name);
|
||||
if (priv == NULL || name == NULL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Allocate space for the name */
|
||||
priv->name = name;
|
||||
|
||||
strncpy(priv->name, name, sizeof(priv->name));
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user