diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-14 09:28:10 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-14 09:28:10 +0200 |
commit | 65778b63d2f0b6d5b3405010eedc72271bce20e0 (patch) | |
tree | c4c3e859387a3dce7da811edff04a3b79cb9f5fd | |
parent | 59f72431f42753e1f61bd19176eb67029e2ef77c (diff) | |
download | barebox-65778b63d2f0b6d5b3405010eedc72271bce20e0.tar.gz barebox-65778b63d2f0b6d5b3405010eedc72271bce20e0.tar.xz |
Partition: Add an own device id for partitions
Add an own device id for partitions. This is necessary to allow
the partition layer to check if the given device is really a partition.
Also, check for readonly flag in erase.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rwxr-xr-x | commands/partition.c | 9 | ||||
-rw-r--r-- | common/partition.c | 6 | ||||
-rw-r--r-- | include/driver.h | 3 |
3 files changed, 16 insertions, 2 deletions
diff --git a/commands/partition.c b/commands/partition.c index dfc4e0d1aa..9148725522 100755 --- a/commands/partition.c +++ b/commands/partition.c @@ -41,10 +41,16 @@ static int dev_del_partitions(struct device_d *physdev) { struct device_d *child, *tmp; + struct partition *part; int ret; device_for_each_child_safe(physdev, tmp, child) { - struct partition *part = child->type_data; + if (child->type != DEVICE_TYPE_PARTITION) { + printf("not a partition: %s\n", child->id); + continue; + } + + part = child->type_data; if (part->flags & PARTITION_FIXED) { debug("Skip fixed partition: %s\n", child->id); @@ -191,6 +197,7 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[]) part->num = num; part->device.map_base = dev->map_base + offset; part->device.type_data = part; + part->device.type = DEVICE_TYPE_PARTITION; if (mtd_part_do_parse_one(part, endp, &endp)) goto free_out; diff --git a/common/partition.c b/common/partition.c index 8804fdb7c3..bb946383d3 100644 --- a/common/partition.c +++ b/common/partition.c @@ -59,6 +59,7 @@ struct device_d *dev_add_partition(struct device_d *dev, unsigned long offset, part->device.map_base = dev->map_base + offset; part->device.size = size; part->device.type_data = part; + part->device.type = DEVICE_TYPE_PARTITION; get_free_deviceid(part->device.id, name); part->offset = offset; @@ -71,6 +72,7 @@ struct device_d *dev_add_partition(struct device_d *dev, unsigned long offset, if (part->device.driver) return &part->device; + unregister_device(&part->device); free(part); return 0; } @@ -87,6 +89,9 @@ static int part_erase(struct device_d *dev, size_t count, unsigned long offset) { struct partition *part = dev->type_data; + if (part->flags & PARTITION_READONLY) + return -EROFS; + return dev_erase(part->physdev, count, offset + part->offset); } @@ -246,6 +251,7 @@ struct driver_d part_driver = { .erase = part_erase, .protect= part_protect, .memmap = part_memmap, + .type = DEVICE_TYPE_PARTITION, }; static int partition_init(void) diff --git a/include/driver.h b/include/driver.h index fb31ada610..e2b6d669dc 100644 --- a/include/driver.h +++ b/include/driver.h @@ -36,7 +36,8 @@ #define DEVICE_TYPE_MIIPHY 6 #define DEVICE_TYPE_NAND 7 #define DEVICE_TYPE_NAND_BB 8 -#define MAX_DEVICE_TYPE 8 +#define DEVICE_TYPE_PARTITION 9 +#define MAX_DEVICE_TYPE 9 #include <param.h> |