aboutsummaryrefslogtreecommitdiff
path: root/src/gpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpt.c')
-rw-r--r--src/gpt.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/gpt.c b/src/gpt.c
index 40ac4a5..9c0c3a5 100644
--- a/src/gpt.c
+++ b/src/gpt.c
@@ -17,15 +17,17 @@
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <ctype.h>
+#include <sys/types.h>
#include "lg-downloader.h"
#include "download.h"
#include "gpt.h"
/* Lookup table for CRC32 with generator polynomial 0x04C11Db7. */
-static const unsigned int gpt_crc_table[] = {
+static const uint32_t gpt_crc_table[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
@@ -80,20 +82,20 @@ static const unsigned int gpt_crc_table[] = {
0x2d02ef8d
};
-static unsigned int gpt_crc_step(unsigned int crc, unsigned char data)
+static uint32_t gpt_crc_step(uint32_t crc, uint8_t data)
{
return ((crc >> 8) ^ gpt_crc_table[(crc ^ data) & 0xff]);
}
-static unsigned int gpt_crc_final(unsigned int crc)
+static uint32_t gpt_crc_final(uint32_t crc)
{
return crc ^ GPT_CRC_SEED;
}
static void gpt_partition_name(struct gpt_partition *partition, char *name)
{
- unsigned int i;
- unsigned int j;
+ size_t i;
+ size_t j;
char c;
if (partition == NULL || name == NULL)
@@ -112,9 +114,9 @@ static void gpt_partition_name(struct gpt_partition *partition, char *name)
int gpt_header_verify(struct gpt_header *header)
{
struct gpt_header header_copy;
- unsigned char *p;
- unsigned int crc;
- unsigned int i;
+ uint8_t *p;
+ uint32_t crc;
+ size_t i;
if (header == NULL)
return -1;
@@ -133,7 +135,7 @@ int gpt_header_verify(struct gpt_header *header)
header_copy.crc = 0;
crc = GPT_CRC_SEED;
- p = (unsigned char *) &header_copy;
+ p = (uint8_t *) &header_copy;
for (i = 0; i < sizeof(struct gpt_header); i++)
crc = gpt_crc_step(crc, *p++);
@@ -159,8 +161,8 @@ int gpt_header_verify(struct gpt_header *header)
int gpt_header_read(struct context *context, struct gpt_header *header)
{
- unsigned int address;
- unsigned int length;
+ off_t address;
+ size_t length;
int rc;
address = GPT_HEADER_LBA;
@@ -183,11 +185,11 @@ int gpt_partition_find(struct context *context)
struct gpt_partition *partition;
void *buffer = NULL;
char name[GPT_PARTITION_NAME_COUNT + 1];
- unsigned int address;
- unsigned int length;
- unsigned int count;
- unsigned int index;
- unsigned int i;
+ off_t address;
+ size_t length;
+ size_t count;
+ size_t index;
+ size_t i;
int rc;
if (context == NULL || context->partition == NULL)
@@ -243,8 +245,8 @@ int gpt_partition_find(struct context *context)
if (strcmp(name, context->partition) == 0) {
printf("Matched GPT partition: %s\n", name);
- context->address = (unsigned int) le64toh(partition->first_lba);
- context->length = (unsigned int) (le64toh(partition->last_lba) - le64toh(partition->first_lba) + 1) * GPT_BLOCK_SIZE;
+ context->address = (uint32_t) le64toh(partition->first_lba);
+ context->length = (uint32_t) (le64toh(partition->last_lba) - le64toh(partition->first_lba) + 1) * GPT_BLOCK_SIZE;
rc = 0;
goto complete;
@@ -271,11 +273,11 @@ int gpt_partitions_print(struct context *context)
struct gpt_partition *partition;
void *buffer = NULL;
char name[GPT_PARTITION_NAME_COUNT + 1];
- unsigned int address;
- unsigned int length;
- unsigned int count;
- unsigned int index;
- unsigned int i;
+ off_t address;
+ size_t length;
+ size_t count;
+ size_t index;
+ size_t i;
int rc;
if (context == NULL)
@@ -325,7 +327,7 @@ int gpt_partitions_print(struct context *context)
gpt_partition_name(partition, (char *) &name);
if (name[0] != '\0')
- printf("Partition name: %s, size: %d bytes\n", name, (unsigned int) (le64toh(partition->last_lba) - le64toh(partition->first_lba) + 1) * GPT_BLOCK_SIZE);
+ printf("Partition name: %s, size: %d bytes\n", name, (int) (le64toh(partition->last_lba) - le64toh(partition->first_lba) + 1) * GPT_BLOCK_SIZE);
}
rc = 0;