fix handling of mmcblkN SD disk partition numbers

Partition numbers for mmcblkN disks have partition numbers with
a leading 'p' and a bug caused these partitions to be considered full disks.
This commit is contained in:
Bill Wilson 2016-02-02 17:35:12 -06:00
parent eff1865a4b
commit 7f9617d817
3 changed files with 18 additions and 2 deletions

View File

@ -537,6 +537,8 @@ gkrellm_disk_subdisk_assign_data_by_name(gchar *subdisk_name, gchar *disk_name,
| appended. Eg. "hda1" is a subdisk_name of disk_name "hda"
*/
s = subdisk_name + strlen(disk_name);
if (*s == 'p') /* except mmcblkN SD disks have "pN" partition numbers */
++s;
subdisk = strtol(s, &endptr, 0);
if (!*s || *endptr)
return;

View File

@ -366,6 +366,8 @@ gkrellm_disk_subdisk_assign_data_by_name(gchar *subdisk_name, gchar *disk_name,
| appended. Eg. "hda1" is a subdisk_name of disk_name "hda"
*/
s = subdisk_name + strlen(disk_name);
if (*s == 'p') /* except mmcblkN SD disks have "pN" partition numbers */
++s;
subdisk = strtol(s, &endptr, 0);
if (!*s || *endptr)
return;

View File

@ -412,6 +412,7 @@ static struct _disk_name_map
{"cc5d", COMPAQ_CISS_MAJOR + 5, 16, '0' }, /* 109: c5d0-c5d15 */
{"cc6d", COMPAQ_CISS_MAJOR + 6, 16, '0' }, /* 110: c6d0-c6d15 */
{"cc7d", COMPAQ_CISS_MAJOR + 7, 16, '0' }, /* 111: c7d0-c7d15 */
{"dm-", DM_MAJOR, 256, '0' }, /* 254: dm-0 - dm-255 */
{"fd", FLOPPY_MAJOR, 0, '0' } /* 2: fd0-fd3 */
@ -499,7 +500,8 @@ disk_get_device_name(gint major, gint minor, gchar *disk, gchar *partition)
struct _disk_name_map *dm = NULL;
gint i, unit = 0;
gchar *p, *d;
gboolean valid_partition_number = FALSE;
for (p = partition; *p; ++p)
if (*p == '/')
break;
@ -509,7 +511,16 @@ disk_get_device_name(gint major, gint minor, gchar *disk, gchar *partition)
p = partition;
while (*d && *p && *d++ == *p++)
;
if (d == disk || *d || *p < '0' || *p > '9')
/* Check that p points to valid partition number. Should be a digit
| unless disk is mmcblkN where the partition number has a leading 'p'
*/
if (*p == 'p' && !strncmp(partition, "mmcblk", 6))
++p;
if (*p >= '0' && *p <= '9')
valid_partition_number = TRUE;
if (d == disk || *d || !valid_partition_number)
{
strcpy(disk, partition);
partition[0] = '\0';
@ -596,6 +607,7 @@ linux_read_proc_diskstats(void)
)
continue;
is_MD = (major == MD_MAJOR);
if (part[0] == '\0')
gkrellm_disk_assign_data_by_name(disk, 512 * rd, 512 * wr, is_MD);
else