Skip to contentSkip to conversation

gpt: fix partition size limit

PATCH New Piotr Wilczek 2 participants 4 messages Jan 28, 2013 – Feb 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpt: fix partition size limit

This patchset fixes partions size limitation in 'gpt' command.

New 'ustrtoll' function is added and used to convert partition size from string to unsigned long long type.

Piotr Wilczek (2):
vsprintf: add ustrtoll function
gpt: fix partion size limit

 common/cmd_gpt.c  |   10 ++++++----
 include/exports.h |    1 +
 lib/vsprintf.c    |   23 +++++++++++++++++++++++
 3 files changed, 30 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 vsprintf: add ustrtoll function

Add 'ustrtoull' function to convert size from string (ex: 1GiB) to unsigned long long type

---
 include/exports.h |    1 +
 lib/vsprintf.c    |   23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)
include/exports.h +1 -0
index 6cf31aa..41d5085 100644
@@ -24,6 +24,7 @@ int setenv (const char *varname, const char *varvalue);
 long simple_strtol(const char *cp,char **endp,unsigned int base);
 int strcmp(const char * cs,const char * ct);
 unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
+unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
 #if defined(CONFIG_CMD_I2C)
 int i2c_write (uchar, uint, int , uchar* , int);
 int i2c_read (uchar, uint, int , uchar* , int);
lib/vsprintf.c +23 -0
index 3c432f8..533a96b 100644
@@ -126,6 +126,29 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base)
 	return result;
 }
 
+unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
+{
+	unsigned long long result = simple_strtoull(cp, endp, base);
+	switch (**endp) {
+	case 'G':
+		result *= 1024;
+		/* fall through */
+	case 'M':
+		result *= 1024;
+		/* fall through */
+	case 'K':
+	case 'k':
+		result *= 1024;
+		if ((*endp)[1] == 'i') {
+			if ((*endp)[2] == 'B')
+				(*endp) += 3;
+			else
+				(*endp) += 2;
+		}
+	}
+	return result;
+}
+
 unsigned long long simple_strtoull(const char *cp, char **endp,
 					unsigned int base)
 {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 1/2 vsprintf: add ustrtoll function

Quoted 5 lines · Piotr Wilczek

Add 'ustrtoull' function to convert size from string (ex: 1GiB) to unsigned long long type

For the series, applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130220/62387d51/attachment.pgp>
#3 lore raw

PATCH 2/2 gpt: fix partion size limit

In reply to Piotr Wilczek

Currently, in gpt command, partion size is converted from string to unsigned long type using 'ustrtol' function. That type limits the partition size to 4GB.

This patch changes the conversion function to 'ustrtoll' to return unsigned long long type.

---
 common/cmd_gpt.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
common/cmd_gpt.c +6 -4
index da7705d..efd7934 100644
@@ -27,6 +27,7 @@
 #include <part_efi.h>
 #include <exports.h>
 #include <linux/ctype.h>
+#include <div64.h>
 
 #ifndef CONFIG_PARTITION_UUIDS
 #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_GPT to be enabled
@@ -131,6 +132,7 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
 	int p_count;
 	disk_partition_t *parts;
 	int errno = 0;
+	uint64_t size_ll, start_ll;
 
 	debug("%s: MMC lba num: 0x%x %d\n", __func__,
 	      (unsigned int)dev_desc->lba, (unsigned int)dev_desc->lba);
@@ -217,8 +219,8 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
 		}
 		if (extract_env(val, &p))
 			p = val;
-		parts[i].size = ustrtoul(p, &p, 0);
-		parts[i].size /= dev_desc->blksz;
+		size_ll = ustrtoull(p, &p, 0);
+		parts[i].size = lldiv(size_ll, dev_desc->blksz);
 		free(val);
 
 		/* start address */
@@ -226,8 +228,8 @@ static int set_gpt_info(block_dev_desc_t *dev_desc,
 		if (val) { /* start address is optional */
 			if (extract_env(val, &p))
 				p = val;
-			parts[i].start = ustrtoul(p, &p, 0);
-			parts[i].start /= dev_desc->blksz;
+			start_ll = ustrtoull(p, &p, 0);
+			parts[i].start = lldiv(start_ll, dev_desc->blksz);
 			free(val);
 		}
 	}
Signature · 1 line
1.7.9.5