Skip to content

Instantly share code, notes, and snippets.

@h-yamamo
Created March 12, 2017 02:30
Show Gist options
  • Save h-yamamo/e0f7e2d0e94337d5c30cf62cc29e9f3e to your computer and use it in GitHub Desktop.
Save h-yamamo/e0f7e2d0e94337d5c30cf62cc29e9f3e to your computer and use it in GitHub Desktop.
Display block count of eMMC/SD card for linux 4.10
; mmc: Display media block count
;
# linux 4.10
--- linux.orig/drivers/mmc/core/block.c
+++ linux.new/drivers/mmc/core/block.c
@@ -2170,6 +2170,7 @@
static int mmc_blk_probe(struct mmc_card *card)
{
struct mmc_blk_data *md, *part_md;
+ sector_t capacity;
char cap_str[10];
/*
@@ -2184,11 +2185,12 @@
if (IS_ERR(md))
return PTR_ERR(md);
- string_get_size((u64)get_capacity(md->disk), 512, STRING_UNITS_2,
+ capacity = get_capacity(md->disk);
+ string_get_size((u64)capacity, 512, STRING_UNITS_2,
cap_str, sizeof(cap_str));
- pr_info("%s: %s %s %s %s\n",
+ pr_info("%s: %s '%s' %llu 512-byte logical blocks: %s %s\n",
md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
- cap_str, md->read_only ? "(ro)" : "");
+ capacity, cap_str, md->read_only ? "(ro)" : "");
if (mmc_blk_alloc_parts(card, md))
goto out;
@h-yamamo
Copy link
Author

Official kernel does not display accurate block count - only GB/MB size.
This patch display block count like HDD or USB storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment