diff options
author | sascha <sascha@nomad.localdomain> | 2007-10-19 08:45:57 +0200 |
---|---|---|
committer | sascha <sascha@nomad.localdomain> | 2007-10-19 08:45:57 +0200 |
commit | 3b6d6a45e705efb64fe522158ed33f640073da12 (patch) | |
tree | a7f25b80f133f7046ad88b6a19ee320281922ffa /commands/partition.c | |
parent | 98839f801049609613a964e0526083b66d236e5a (diff) | |
download | barebox-3b6d6a45e705efb64fe522158ed33f640073da12.tar.gz barebox-3b6d6a45e705efb64fe522158ed33f640073da12.tar.xz |
- Implement tree structure for devices
- Use device tree structure to implement partitions
- Let devinfo print a nice tree
- Introduce 'fixed' partitions which are not removable
- Fix mount: It was not possible to mount on a relative path.
Diffstat (limited to 'commands/partition.c')
-rw-r--r-- | commands/partition.c | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/commands/partition.c b/commands/partition.c index c6130337b7..421f01fc2f 100644 --- a/commands/partition.c +++ b/commands/partition.c @@ -29,25 +29,29 @@ #include <errno.h> #include <xfuncs.h> -static void dev_del_partitions(struct device_d *physdev) +static int dev_del_partitions(struct device_d *physdev) { - struct device_d *dev; - char buf[MAX_DRIVER_NAME]; - int i = 0; + struct device_d *child, *tmp; + int ret; - /* This is lame. Devices should to able to have children */ - while (1) { - sprintf(buf, "%s.%d", physdev->id, i); - dev = device_from_spec_str(buf, NULL); - if (dev) { - struct partition *part = dev->type_data; - printf("unregister %s %s\n", dev->name, dev->id); - unregister_device(dev); - free(part); - } else - break; - i++; + device_for_each_child_safe(physdev, tmp, child) { + struct partition *part = child->type_data; + + debug("delete partition: %s\n", child->id); + + if (part->flags & PARTITION_FIXED) + continue; + + ret = unregister_device(child); + if (ret) { + printf("delete partition `%s' failed: %s\n", child->id, errno_str()); + return errno; + } + + free(part); } + + return 0; } static int mtd_part_do_parse_one(struct partition *part, const char *str, @@ -92,7 +96,7 @@ static int mtd_part_do_parse_one(struct partition *part, const char *str, str = end; if (*str == 'r' && *(str + 1) == 'o') { - part->readonly = 1; + part->flags |= PARTITION_READONLY; end = (char *)(str + 2); } @@ -113,12 +117,12 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[]) int num = 0; unsigned long offset; - if (argc != 2) { + if (argc != 3) { printf("Usage:\n%s\n", cmdtp->usage); return 1; } - dev = device_from_spec_str(argv[1], &endp); + dev = get_device_by_path(argv[1]); if (!dev) { printf("no such device: %s\n", argv[1]); return 1; @@ -128,6 +132,8 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[]) offset = 0; + endp = argv[2]; + while (1) { part = xzalloc(sizeof(struct partition)); @@ -138,28 +144,37 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[]) if (mtd_part_do_parse_one(part, endp, &endp)) { dev_del_partitions(dev); - free(part); - return 1; + goto free_out; } offset += part->device.size; part->device.type_data = part; - sprintf(part->device.id, "%s.%d", dev->id, num); - register_device(&part->device); + sprintf(part->device.id, "%s.%s", dev->id, part->name); + if (register_device(&part->device)) + goto free_out; + + dev_add_child(dev, &part->device); + num++; if (!*endp) break; + if (*endp != ',') { printf("parse error\n"); - return 1; + goto err_out; } endp++; } return 0; + +free_out: + free(part); +err_out: + return 1; } static __maybe_unused char cmd_addpart_help[] = @@ -175,7 +190,7 @@ static __maybe_unused char cmd_addpart_help[] = "Note That this command has to be reworked and will probably change it's API."; U_BOOT_CMD_START(addpart) - .maxargs = 2, + .maxargs = 3, .cmd = do_addpart, .usage = "add a partition table to a device", U_BOOT_CMD_HELP(cmd_addpart_help) @@ -190,7 +205,7 @@ static int do_delpart(cmd_tbl_t * cmdtp, int argc, char *argv[]) return 1; } - dev = device_from_spec_str(argv[1], NULL); + dev = get_device_by_path(argv[1]); if (!dev) { printf("no such device: %s\n", argv[1]); return 1; |