9
0
Fork 0

disk: introduce partition name

so we can register partion with name as present in EFI GPT

Cc: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2013-02-16 14:47:08 +01:00 committed by Sascha Hauer
parent 263bb23ed2
commit 86b3577a72
3 changed files with 45 additions and 13 deletions

View File

@ -44,15 +44,43 @@ static LIST_HEAD(partition_parser_list);
static int register_one_partition(struct block_device *blk, static int register_one_partition(struct block_device *blk,
struct partition *part, int no) struct partition *part, int no)
{ {
char partition_name[19]; char *partition_name;
int ret;
uint64_t start = part->first_sec * SECTOR_SIZE;
uint64_t size = part->size * SECTOR_SIZE;
sprintf(partition_name, "%s.%d", blk->cdev.name, no); partition_name = asprintf("%s.%d", blk->cdev.name, no);
if (!partition_name)
return -ENOMEM;
dev_dbg(blk->dev, "Registering partition %s on drive %s\n", dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
partition_name, blk->cdev.name); partition_name, blk->cdev.name);
return devfs_add_partition(blk->cdev.name, ret = devfs_add_partition(blk->cdev.name,
part->first_sec * SECTOR_SIZE, start, size, 0, partition_name);
part->size * SECTOR_SIZE, if (ret)
0, partition_name); goto out;
free(partition_name);
if (!part->name[0])
return 0;
partition_name = asprintf("%s.%s", blk->cdev.name, part->name);
if (!partition_name)
return -ENOMEM;
dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
partition_name, blk->cdev.name);
ret = devfs_add_partition(blk->cdev.name,
start, size, 0, partition_name);
if (ret)
dev_warn(blk->dev, "Registering partition %s on drive %s failed\n",
partition_name, blk->cdev.name);
ret = 0;
out:
free(partition_name);
return 0;
} }
static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf) static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
@ -91,12 +119,13 @@ static struct partition_parser *partition_parser_get_by_filetype(uint8_t *buf)
*/ */
int parse_partition_table(struct block_device *blk) int parse_partition_table(struct block_device *blk)
{ {
struct partition_desc pdesc = { .used_entries = 0, }; struct partition_desc *pdesc;
int i; int i;
int rc = 0; int rc = 0;
struct partition_parser *parser; struct partition_parser *parser;
uint8_t *buf; uint8_t *buf;
pdesc = xzalloc(sizeof(*pdesc));
buf = dma_alloc(SECTOR_SIZE * 2); buf = dma_alloc(SECTOR_SIZE * 2);
rc = blk->ops->read(blk, buf, 0, 2); rc = blk->ops->read(blk, buf, 0, 2);
@ -109,14 +138,14 @@ int parse_partition_table(struct block_device *blk)
if (!parser) if (!parser)
goto on_error; goto on_error;
parser->parse(buf, blk, &pdesc); parser->parse(buf, blk, pdesc);
if (!pdesc.used_entries) if (!pdesc->used_entries)
return 0; goto on_error;
/* at least one partition description found */ /* at least one partition description found */
for (i = 0; i < pdesc.used_entries; i++) { for (i = 0; i < pdesc->used_entries; i++) {
rc = register_one_partition(blk, &pdesc.parts[i], i); rc = register_one_partition(blk, &pdesc->parts[i], i);
if (rc != 0) if (rc != 0)
dev_err(blk->dev, dev_err(blk->dev,
"Failed to register partition %d on %s (%d)\n", "Failed to register partition %d on %s (%d)\n",
@ -127,6 +156,7 @@ int parse_partition_table(struct block_device *blk)
on_error: on_error:
dma_free(buf); dma_free(buf);
free(pdesc);
return rc; return rc;
} }

View File

@ -76,7 +76,7 @@ static void dos_partition(void *buf, struct block_device *blk,
} }
} }
struct partition_parser dos = { static struct partition_parser dos = {
.parse = dos_partition, .parse = dos_partition,
.type = filetype_mbr, .type = filetype_mbr,
}; };

View File

@ -12,8 +12,10 @@
#include <linux/list.h> #include <linux/list.h>
#define MAX_PARTITION 8 #define MAX_PARTITION 8
#define MAX_PARTITION_NAME 38
struct partition { struct partition {
char name[MAX_PARTITION_NAME];
uint64_t first_sec; uint64_t first_sec;
uint64_t size; uint64_t size;
}; };