sprintf(buf, "%lu", size);
}
+/**
+ * This routine does global indexing of all partitions. Resulting index for
+ * current partition is saved in 'mtddevnum'. Current partition name in
+ * 'mtddevname'.
+ */
+static void index_partitions(void)
+{
+ char buf[16];
+ u16 mtddevnum;
+ struct part_info *part;
+ struct list_head *dentry;
+ struct mtd_device *dev;
+
+ DEBUGF("--- index partitions ---\n");
+
+ if (current_dev) {
+ mtddevnum = 0;
+ list_for_each(dentry, &devices) {
+ dev = list_entry(dentry, struct mtd_device, link);
+ if (dev == current_dev) {
+ mtddevnum += current_partnum;
+ sprintf(buf, "%d", mtddevnum);
+ setenv("mtddevnum", buf);
+ break;
+ }
+ mtddevnum += dev->num_parts;
+ }
+
+ part = jffs2_part_info(current_dev, current_partnum);
+ setenv("mtddevname", part->name);
+
+ DEBUGF("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
+ } else {
+ setenv("mtddevnum", NULL);
+ setenv("mtddevname", NULL);
+
+ DEBUGF("=> mtddevnum NULL\n=> mtddevname NULL\n");
+ }
+}
+
/**
* Save current device and partition in environment variable 'partition'.
*/
DEBUGF("=> partition NULL\n");
}
+ index_partitions();
}
/**
*/
static int part_del(struct mtd_device *dev, struct part_info *part)
{
+ u8 current_save_needed = 0;
+
/* if there is only one partition, remove whole device */
if (dev->num_parts == 1)
return device_del(dev);
if (curr_pi == part) {
printf("current partition deleted, resetting current to 0\n");
current_partnum = 0;
- current_save();
} else if (part->offset <= curr_pi->offset) {
current_partnum--;
- current_save();
}
+ current_save_needed = 1;
}
}
-
jffs2_free_cache(part);
list_del(&part->link);
free(part);
dev->num_parts--;
+ if (current_save_needed > 0)
+ current_save();
+ else
+ index_partitions();
+
return 0;
}
if (list_empty(&dev->parts)) {
DEBUGF("part_sort_add: list empty\n");
list_add(&part->link, &dev->parts);
+ dev->num_parts++;
+ index_partitions();
return 0;
}
if (new_pi->offset <= pi->offset) {
list_add_tail(&part->link, entry);
+ dev->num_parts++;
if (curr_pi && (pi->offset <= curr_pi->offset)) {
/* we are modyfing partitions for the current
* device, update current */
current_partnum++;
current_save();
+ } else {
+ index_partitions();
}
-
return 0;
}
}
+
list_add_tail(&part->link, &dev->parts);
+ dev->num_parts++;
+ index_partitions();
return 0;
}
if (part_sort_add(dev, part) != 0)
return 1;
- dev->num_parts++;
return 0;
}
current_partnum = 0;
}
current_save();
+ return 0;
}
-
+ index_partitions();
return 0;
}
*/
static void device_add(struct mtd_device *dev)
{
+ u8 current_save_needed = 0;
+
if (list_empty(&devices)) {
current_dev = dev;
current_partnum = 0;
- current_save();
+ current_save_needed = 1;
}
list_add_tail(&dev->link, &devices);
+
+ if (current_save_needed > 0)
+ current_save();
+ else
+ index_partitions();
}
/**
}
memset(dev, 0, sizeof(struct mtd_device));
dev->id = id;
- dev->num_parts = num_parts;
+ dev->num_parts = 0; /* part_sort_add increments num_parts */
INIT_LIST_HEAD(&dev->parts);
INIT_LIST_HEAD(&dev->link);
ids_changed = 1;
if (parse_mtdids(ids) != 0) {
- device_delall(&devices);
+ devices_init();
return 1;
}