Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=cddc83cfea0b72849025dcc85a4af605c3849729
commit cddc83cfea0b72849025dcc85a4af605c3849729 Author: James Buren <[email protected]> Date: Tue Sep 11 08:45:06 2012 -0500 add function for deleting the last partition entry diff --git a/src/local.h b/src/local.h index 6a92ded..8925017 100644 --- a/src/local.h +++ b/src/local.h @@ -69,6 +69,25 @@ extern bool execute(const char *command,const char *root,pid_t *cpid); extern void *malloc0(size_t size); extern struct parted *parted_open(const char *path); extern bool parted_new_disk_label(struct parted *parted,PedDiskType *type); +static inline bool is_normal_partition(PedPartitionType type) +{ + switch(type) + { + case PED_PARTITION_NORMAL: + case PED_PARTITION_LOGICAL: + case PED_PARTITION_EXTENDED: + return true; + + case PED_PARTITION_FREESPACE: + case PED_PARTITION_METADATA: + case PED_PARTITION_PROTECTED: + return false; + + default: + return false; + } +} +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); extern bool get_text_screen_size(const char *text,int *width,int *height); diff --git a/src/utility.c b/src/utility.c index 06f325b..f78edf0 100644 --- a/src/utility.c +++ b/src/utility.c @@ -244,6 +244,31 @@ extern bool parted_new_disk_label(struct parted *parted,PedDiskType *type) return (parted->disk != 0); } +extern bool parted_delete_last_partition(struct parted *parted) +{ + PedPartition *part = 0; + + if(parted == 0 || parted->device == 0 || parted->disk == 0) + { + errno = EINVAL; + fprintf(logfile,"%s: %s\n",__func__,strerror(errno)); + return false; + } + + for( PedPartition *i = 0 ; (i = ped_disk_next_partition(parted->disk,i)) != 0 ; ) + { + if(i->num > 0 && is_normal_partition(i->type)) + part = i; + } + + if(part == 0) + return true; + + parted->modified = true; + + return (ped_disk_delete_partition(parted->disk,part) != 0); +} + extern void parted_close(struct parted *parted) { if(parted != 0) _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
