Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=fdfabf20d164f85ce739c6203bd31ffd66a89a3e

commit fdfabf20d164f85ce739c6203bd31ffd66a89a3e
Author: James Buren <[email protected]>
Date:   Tue Aug 14 18:56:02 2012 -0500

add function for removing a partition by its number

diff --git a/fwsetup.h b/fwsetup.h
index be7d576..3e8919f 100644
--- a/fwsetup.h
+++ b/fwsetup.h
@@ -129,6 +129,7 @@ extern void partition_free(void *p);
extern struct device *device_read_data(const char *path);
extern bool device_write_data(const struct device *device);
extern void device_create_partition_table(struct device *device,const char 
*label);
+extern bool device_remove_partition(struct device *device,unsigned long long 
n);
extern void device_free(struct device *device);
extern int main(void);
extern struct module begin_module;
diff --git a/utility.c b/utility.c
index ff1de21..c059988 100644
--- a/utility.c
+++ b/utility.c
@@ -227,19 +227,19 @@ extern void *list_remove(void *list)
{
ASSERT_ARGS(list == 0,0);

-  struct list *a = list->prev;
-  struct list *b = list->next;
-  struct list *c = list;
+  struct list *a = list;
+  struct list *b = a->prev;
+  struct list *c = a->next;

-  if(a != 0)
-    a->next = b;
+  a->prev = 0;

-  if(b != 0)
-    b->prev = a;
+  a->next = 0;

-  c->prev = 0;
+  if(b != 0)
+    b->next = c;

-  c->next = 0;
+  if(c != 0)
+    c->prev = b;

return c;
}
@@ -593,6 +593,29 @@ extern void device_create_partition_table(struct device 
*device,const char *labe
device->partitions = 0;
}

+extern bool device_remove_partition(struct device *device,unsigned long long n)
+{
+  ASSERT_ARGS(device == 0 || device->partitions == 0 || n == 0,false);
+
+  struct partition *part = device->partitions;
+
+  while(part != 0)
+  {
+    if(part->num == n)
+    {
+      list_remove(part);
+
+      partition_free(part);
+
+      break;
+    }
+
+    part = part->next;
+  }
+
+  return (part != 0);
+}
+
extern void device_free(struct device *device)
{
if(device == 0)
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to