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

commit b56a85e4e7c74e516e6d9416be6a374b97309bda
Author: James Buren <[email protected]>
Date:   Tue Sep 11 09:23:34 2012 -0500

add function for adding a new partition
cache the device's alignment

diff --git a/src/local.h b/src/local.h
index 8925017..9d35b4e 100644
--- a/src/local.h
+++ b/src/local.h
@@ -34,6 +34,7 @@ struct global
struct parted
{
PedDevice *device;
+  PedConstraint *constraint;
PedDisk *disk;
bool modified;
};
@@ -87,6 +88,7 @@ static inline bool is_normal_partition(PedPartitionType type)
return false;
}
}
+extern bool parted_new_partition(struct parted *parted,const char *size);
extern bool parted_delete_last_partition(struct parted *parted);
extern void parted_close(struct parted *parted);
extern int get_text_screen_width(const char *s);
diff --git a/src/utility.c b/src/utility.c
index f78edf0..e3786c8 100644
--- a/src/utility.c
+++ b/src/utility.c
@@ -197,6 +197,7 @@ extern void *malloc0(size_t size)
extern struct parted *parted_open(const char *path)
{
PedDevice *device = 0;
+  PedConstraint *constraint = 0;
PedDiskType *disktype = 0;
PedDisk *disk = 0;
struct parted *parted = 0;
@@ -211,6 +212,12 @@ extern struct parted *parted_open(const char *path)
if((device = ped_device_get(path)) == 0)
return 0;

+  if((constraint = ped_device_get_optimal_aligned_constraint(device)) == 0)
+  {
+    ped_device_destroy(device);
+    return 0;
+  }
+
if((disktype = ped_disk_probe(device)) != 0 && (disktype == g->doslabel || 
disktype == g->gptlabel))
disk = ped_disk_new(device);

@@ -218,6 +225,8 @@ extern struct parted *parted_open(const char *path)

parted->device = device;

+  parted->constraint = constraint;
+
parted->disk = disk;

parted->modified = false;
@@ -244,6 +253,43 @@ extern bool parted_new_disk_label(struct parted 
*parted,PedDiskType *type)
return (parted->disk != 0);
}

+extern bool parted_new_partition(struct parted *parted,const char *size)
+{
+  PedSector sector = 0;
+  PedGeometry *range = 0;
+  PedPartition *part = 0;
+  bool result = false;
+
+  if(parted == 0 || parted->device == 0 || parted->disk == 0 || size == 0)
+  {
+    errno = EINVAL;
+    fprintf(logfile,"%s: %s\n",__func__,strerror(errno));
+    return false;
+  }
+
+  if(ped_unit_parse(size,parted->device,&sector,&range) == 0)
+    return false;
+
+  if((part = 
ped_partition_new(parted->disk,PED_PARTITION_NORMAL,0,range->start,range->end)) 
== 0)
+  {
+    ped_geometry_destroy(range);
+    return false;
+  }
+
+  if(ped_disk_add_partition(parted->disk,part,parted->constraint) == 0)
+  {
+    ped_geometry_destroy(range);
+    ped_partition_destroy(part);
+    return false;
+  }
+
+  parted->modified = true;
+
+  ped_geometry_destroy(range);
+
+  return true;
+}
+
extern bool parted_delete_last_partition(struct parted *parted)
{
PedPartition *part = 0;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to