MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / convert_size

Function convert_size

components/drivers/block/blk.c:474–499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472
473#if defined(RT_USING_CONSOLE) && defined(RT_USING_MSH)
474const char *convert_size(struct rt_device_blk_geometry *geome,
475 rt_size_t sector_count, rt_size_t *out_cap, rt_size_t *out_minor)
476{
477 rt_size_t cap, minor = 0;
478 int size_index = 0;
479 const char *size_name[] = { "B", "K", "M", "G", "T", "P", "E" };
480
481 cap = geome->bytes_per_sector * sector_count;
482
483 for (size_index = 0; size_index < RT_ARRAY_SIZE(size_name) - 1; ++size_index)
484 {
485 if (cap < 1024)
486 {
487 break;
488 }
489
490 /* Only one decimal point */
491 minor = (cap % 1024) * 10 / 1024;
492 cap = cap / 1024;
493 }
494
495 *out_cap = cap;
496 *out_minor = minor;
497
498 return size_name[size_index];
499}
500
501static int list_blk(int argc, char**argv)
502{

Callers 1

list_blkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected