apache / apache/nuttx

[HELP] What is the right format should be used in `part_procfs_read`?

Open
#19,424 0 comments 0 reactions 0 assignees View on GitHub
Community: Question
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

### Description

I am testing NAND MTD partition in MIPS32 system, and after I created 4 partitions, I ran `cat /proc/partitions`, and got followings,

```
Name Start Size MTD
(noname) 34359738368 9230062565109792768
(noname) 274877906944 9230062565109792768
(noname) 274877906944 9230062565109792768
(noname) 274877906944 9230062565109792768
```

This is wrong, my partition table should be
```
Name Start Size MTD
(noname) 0 8 tstnand
(noname) 8 64 tstnand
(noname) 72 64 tstnand
(noname) 136 64 tstnand
```
The info is from following codes of `part_procfs_read()`,
```
#ifdef CONFIG_MTD_PARTITION_NAMES
ptr = attr->nextpart->name;
for (x = 0; x < sizeof(partname) - 1; x++)
{
/* Test for end of partition name */

if (*ptr == ',' || *ptr == '\0')
{
/* Perform space fill for alignment */

partname[x] = ' ';
}
else
{
/* Copy next byte of partition name */

partname[x] = *ptr++;
}
}

partname[x] = '\0';

/* Terminate the partition name and add to output buffer */

ret = snprintf(&buffer[total], buflen - total,
"%s%7ju %7ju %s\n",
partname,
(uintmax_t)attr->nextpart->firstblock / blkpererase,
(uintmax_t)attr->nextpart->geo.neraseblocks,
attr->nextpart->parent->name);
#else
ret = snprintf(&buffer[total], buflen - total, "%7ju %7ju %s\n",
(uintmax_t)attr->nextpart->firstblock / blkpererase,
(uintmax_t)attr->nextpart->geo.neraseblocks,
attr->nextpart->parent->name);
#endif
```
What is the right format should be used to print partition info across 32 and 64bit platform?

### Verification

- [x] I have verified before submitting the report.

Contributor guide

Open the contributing guide

Research direction

Start by reading the part_procfs_read() code shown in the issue and trace the types of firstblock, neraseblocks, and the snprintf format arguments on 32- and 64-bit targets. Reproduce the /proc/partitions output on the MIPS32 setup if available, then verify that the reported partition start and size match the expected table on both word sizes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.