Update of /cvsroot/morphix/partitionmorpher/src In directory sc8-pr-cvs1:/tmp/cvs-serv21416/src Modified Files: Makefile.am callbacks.c interface.c main.c main.h pm_libparted.c pm_libparted.h Added Files: pm_fswrap.c pm_fswrap.h ui.c ui.h Log Message: added resizing, added wrapper for ntfsresize (untested), heaps of fixes --- NEW FILE: pm_fswrap.c --- /* insert more GPL license BS inspired by qp_fswrap in qtparted */ #include <stdio.h> #include <stdlib.h> #include <gtk/gtk.h> #include <parted/parted.h> #include "pm_libparted.h" #define MKNTFS_PATH "/usr/bin/mkntfs" #define NTFSRESIZE_PATH "/usr/bin/ntfsresize" gboolean ExecuteCommand(gchar *command) { gchar *outbuffer; gchar cmdline[256]; gint exitstatus; debug("Exec: %s\n",command); if (g_spawn_command_line_sync(command,&outbuffer,NULL,&exitstatus,NULL) == FALSE) { debug("Error occured executing command\n"); return FALSE; } free(outbuffer); return TRUE; } gboolean pm_wrap_mkntfs_available() { FILE *fp; fp = fopen(MKNTFS_PATH,"r"); if (fp != NULL) { fclose(fp); return TRUE; } return FALSE; } gboolean pm_wrap_ntfsresize_available() { FILE *fp; fp = fopen(NTFSRESIZE_PATH,"r"); if (fp != NULL) { fclose(fp); return TRUE; } return FALSE; } gboolean do_ntfsresize(PedDevice **dev, int part_nr, PedSector old_end, gchar *path, PedSector old_start, PedSector end) { PedDisk *disk; PedPartition *part; if(!pm_wrap_ntfsresize_available()) { debug("ntfsresize not available, aborting"); return FALSE; } disk = ped_disk_new(*dev); if (!disk) return FALSE; part = ped_disk_get_partition(disk,part_nr); if (!part) { ped_disk_destroy (disk); return FALSE; } if (!partition_warn_busy(part,path)) { ped_disk_destroy (disk); return FALSE; } if (!old_start || !end) { ped_disk_destroy (disk); return FALSE; } if (end < old_end) { // shrinking if (!pm_wrap_ntfsresize(dev,part_nr,path,old_start,end)) { debug("ntfsresizing failed, aborting!\n"); ped_disk_destroy(disk); return FALSE; } do_resize(dev,part_nr,path,old_start,end); } if (end > old_end) { // expanding do_resize(dev,part_nr,path,old_start,end); if (!pm_wrap_ntfsresize(dev,part_nr,path,old_start,end)) { debug("ntfsresizing failed, aborting!\n"); ped_disk_destroy(disk); return FALSE; } } return TRUE; } gboolean pm_wrap_ntfsresize(PedDevice **dev, int part_nr, gchar *path, PedSector start, PedSector end) { PedDisk *disk; PedFileSystem *fs; PedPartition *part; gchar *cmdline; disk = ped_disk_new(*dev); if (!disk) return FALSE; part = ped_disk_get_partition(disk,part_nr); if (!part) { ped_disk_destroy (disk); return FALSE; } if (!partition_warn_busy(part,path)) { ped_disk_destroy (disk); return FALSE; } if (!start || !end) { ped_disk_destroy (disk); return FALSE; } sprintf(cmdline,"%s -ff -s %lld",NTFSRESIZE_PATH,start); // -ff? hope i won't have to use this... gboolean ret = ExecuteCommand(cmdline); free(cmdline); return ret; } --- NEW FILE: pm_fswrap.h --- #ifndef PM_FSWRAP_H #define PM_FSWRAP_H #include <stdio.h> #include <stdlib.h> #include <gtk/gtk.h> #include <parted/parted.h> gboolean do_ntfsresize(PedDevice **dev, int part_nr, PedSector old_end, gchar *path, PedSector start, PedSector end); #endif // PM_FSWRAP_H --- NEW FILE: ui.c --- #include <gtk/gtk.h> #include <parted/parted.h> #include <errno.h> #include <fcntl.h> #include "ui.h" #include "main.h" #include "callbacks.h" #include "interface.h" #include "support.h" #include "pm_libparted.h" /* Note: read the parted-doc API first! this can be found in /usr/share/doc/parted-doc You'll need it to understand certain sections, and pm_lib Some guidelines for the source: when everything is set up using scan_partitions and scan_devices in pm_lib, the partitions- and devices arrays are filled with the current partitiontable information The current selected device can be retrieved with devices[selected_device], The current selected partition can be retrieved with partitions[selected_partition] An Extended partition contains Logical partitions or free space. Do use initialise_partinfo to clean out the partinfo array */ extern GtkWidget *MainWindow; extern GtkWidget *CreateWindow; extern GtkWidget *ResizeWindow; extern GtkWidget *ApplyWindow; extern GtkWidget *RevertWindow; extern GtkWidget *DialogWindow; extern GtkWidget *HelpWindow; extern GtkWidget *DeleteWindow; extern GtkWidget *ConvertWindow; extern GtkWidget *MoveWindow; extern GtkWidget *TableWindow; extern GtkWidget *ErrorWindow; extern GtkWidget *ProgressWindow; #define MEGABYTE_SIZE (1024*1024) #define MEGABYTE_SECTORS 512 enum { PART_NUMBER, PART_PATH, PART_TYPE, PART_FS, PART_SIZE, PART_START, PART_END, PART_FLAGS, N_COLUMNS }; void redirect_stderr_to_pipe(int * saved_fd, int * readable_pipe) { int stderr_fd; int pipe_fd[2]; /* Make a copy of the stderr file-descriptor so we can restore it later */ stderr_fd = fileno(stderr); *saved_fd = dup(stderr_fd); /* Open up a pipe */ if (pipe(pipe_fd) == -1) { fprintf(stderr, "Could not create pipe; errno=%d!\n", errno); exit(-1); } /* Redirect stderr to the writable end of the pipe */ if ( dup2(pipe_fd[1], stderr_fd) == -1 ) { fprintf(stderr, "Could not redirect stderr to the pipe!\n"); exit(-1); } /* Since stderr & pipe_fd[1] point to the same thing, close pipe_fd[1] */ /* NOTE: Do I really need this? */ close(pipe_fd[1]); /* Make sure stderr output is non-blocking (don't hang waiting for EOF) */ int oldflags; oldflags = fcntl(pipe_fd[0], F_GETFL, 0); fcntl(pipe_fd[0], F_SETFL, oldflags|O_NONBLOCK); *readable_pipe = pipe_fd[0]; } void unredirect_stderr(int saved_fd, int readable_pipe) { /* Close the input (readable) end of the pipe*/ close(readable_pipe); /* Now undo the effects of redirecting output */ dup2(saved_fd, fileno(stderr)); /* Now that we no longer need the saved_fd, we can close it */ close(saved_fd); } void show_error_message(gchar * message) { int length = strlen(message)-1; while (message[length] == '\n') length--; message[++length] = '\0'; GtkWidget *error_label = lookup_widget(ErrorWindow,"ErrorLabel"); gtk_label_set_text(GTK_LABEL(error_label), message); gtk_widget_show(ErrorWindow); } void untoggle_create_types() { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreatePrimaryRadiobutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateExtendedRadiobutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateLogicalRadiobutton")),FALSE); }; void untoggle_create_flags() { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateRootFlagCheckbutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")),FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")),FALSE); } void show_create_fstype() { gtk_widget_show(lookup_widget(CreateWindow,"optionmenu4")); gtk_widget_show(lookup_widget(CreateWindow,"label27")); } void hide_create_fstype() { gtk_widget_hide(lookup_widget(CreateWindow,"optionmenu4")); gtk_widget_hide(lookup_widget(CreateWindow,"label27")); } void show_create_flags() { gtk_widget_show(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")); gtk_widget_show(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")); gtk_widget_show(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")); gtk_widget_show(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")); gtk_widget_show(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")); gtk_widget_show(lookup_widget(CreateWindow,"label65")); } void hide_create_flags() { gtk_widget_hide(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")); gtk_widget_hide(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")); gtk_widget_hide(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")); gtk_widget_hide(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")); gtk_widget_hide(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")); gtk_widget_hide(lookup_widget(CreateWindow,"label65")); } void show_busy_cursor( GdkWindow * window ) { static GdkCursor * busy_cursor = NULL; if (!busy_cursor) busy_cursor = gdk_cursor_new(GDK_WATCH); /* Make the specified window show the busy cursor */ gdk_window_set_cursor( window, busy_cursor ); /* Also make the MainWindow show the busy cursor */ gdk_window_set_cursor( MainWindow->window, busy_cursor ); while (gtk_events_pending()) gtk_main_iteration(); } void show_normal_cursor( GdkWindow * window ) { gdk_window_set_cursor( window, NULL ); gdk_window_set_cursor( MainWindow->window, NULL ); } /* initialise list of filesystem types stores this in fsinfo-array, contains name, color and bool's for cr/re/cp */ void get_filesystem_list() { PedFileSystemType *walk = ped_file_system_type_get_next(NULL); gint i = 0; while (walk) { fsinfo[i].name = malloc(strlen(walk->name) + 1); strcpy(fsinfo[i].name,walk->name); fsinfo[i].creatable = (gboolean) walk->ops->create; fsinfo[i].resizeable = (gboolean) walk->ops->resize; fsinfo[i].copyable = (gboolean) walk->ops->copy; fsinfo[i].color = i; walk = ped_file_system_type_get_next(walk); } fs_count = i; } gint get_arraynumber_from_partinfo_num(gint num) { gint i; for (i = 1; i < part_count; i++) { if (partinfo[i].num == num) { return i; } } return -1; } struct partinfo_struct *get_partition_from_partinfo_num(gint num) { gint i; for (i = 1; i < part_count; i++) { if (partinfo[i].num == num) { return &partinfo[i]; } } return NULL; } /* List item selection callback */ void tree_selection_changed (GtkTreeSelection *selection, gpointer data) { GtkWidget *create_widget = lookup_widget(MainWindow,"CreateButton"); GtkWidget *resize_widget = lookup_widget(MainWindow,"ResizeButton"); GtkWidget *delete_widget = lookup_widget(MainWindow,"DeleteButton"); GtkWidget *move_widget = lookup_widget(MainWindow,"MoveButton"); GtkWidget *convert_widget = lookup_widget(MainWindow,"ConvertButton"); GtkWidget *refresh_widget = lookup_widget(MainWindow,"RefreshButton"); GtkTreeIter iter; GtkTreeModel *model; gint num; struct partinfo_struct *partition; if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gtk_tree_model_get(model, &iter,PART_NUMBER, &num,-1); partition = get_partition_from_partinfo_num(num); selected_partition = get_arraynumber_from_partinfo_num(num); if (selected_partition < 0) { debug("Error: selected partition has invalid arraynumber: %d\n",selected_partition); } else if (partition != NULL && partition->num > -2) { if (partition->part_widget != NULL) { gtk_button_clicked(GTK_BUTTON(partition->part_widget)); } if (partition->type == FREE_SPACE) { if (has_max_primary_partitions(&devices[selected_device]) && (selected_partition < part_extended_nr || part_extended_nr == 0)) { gtk_widget_set_sensitive(create_widget,FALSE); } else { gtk_widget_set_sensitive(create_widget,TRUE); } gtk_widget_set_sensitive(resize_widget,FALSE); gtk_widget_set_sensitive(delete_widget,FALSE); gtk_widget_set_sensitive(move_widget,FALSE); gtk_widget_set_sensitive(convert_widget,FALSE); } else { gtk_widget_set_sensitive(create_widget,FALSE); if (partition->type == EXTENDED) { /* if the partition is extended, extra restraints are necessary. You can't delete the extended partition if logical partitions exist in it. Thankfully for me, you can only have one extended partition... */ if (part_logical_count > 0) { gtk_widget_set_sensitive(resize_widget,FALSE); gtk_widget_set_sensitive(delete_widget,FALSE); gtk_widget_set_sensitive(move_widget,FALSE); gtk_widget_set_sensitive(convert_widget,FALSE); } else { gtk_widget_set_sensitive(resize_widget,FALSE); gtk_widget_set_sensitive(delete_widget,TRUE); gtk_widget_set_sensitive(move_widget,FALSE); gtk_widget_set_sensitive(convert_widget,FALSE); } } else { if (partition->max_size == 0 && partition->min_size == 0) { gtk_widget_set_sensitive(resize_widget,FALSE); gtk_widget_set_sensitive(move_widget,FALSE); } else { gtk_widget_set_sensitive(resize_widget,TRUE); gtk_widget_set_sensitive(move_widget,TRUE); } gtk_widget_set_sensitive(convert_widget,TRUE); gtk_widget_set_sensitive(delete_widget,TRUE); } } } } } /* Partition button callback */ gboolean click_part_item(GtkWidget *widget, gpointer data) { struct partinfo_struct *partition = (struct partinfo_struct *)data; GtkWidget *treeview = lookup_widget(MainWindow,"treeview1"); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); gchar path_string[4]; sprintf(path_string,"%d",partition->row_number); GtkTreePath *path = gtk_tree_path_new_from_string(path_string); if (path != NULL) { gtk_tree_selection_select_path(GTK_TREE_SELECTION(selection), (path)); } } /* updates partinfo-array with all partitions for the current selected_device skips the METADATA partition that seems to be before the first partition modifies the GtkList of partitions */ void update_partition_widget() { GtkWidget *partition_widget = lookup_widget(MainWindow,"hbox4"); GtkWidget *part_box = gtk_hbox_new(FALSE,5); gint i; gint win_x; gint win_y; gint height = 30; gint rows = 0; if (G_IS_OBJECT(part_widget)) gtk_container_remove(GTK_CONTAINER(partition_widget),part_widget); gtk_window_get_size(GTK_WINDOW(MainWindow),&win_x,&win_y); win_x -= 10; // border for (i = 1; i < part_count; i++) { if (partinfo[i].num < 0 && partinfo[i].type != FREE_SPACE) { debug("Debug: Skipping partition, partition num invalid\n"); continue; } GtkWidget *part_item = gtk_button_new(); gfloat perc = (float)partinfo[i].size / device_total_size; gint width = (win_x / 100) * 100 * perc; GdkColor color; /* Default color */ color.red = 32768; color.blue = 32768; color.green = 32768; if (width <= 20) width = 20; if (partinfo[i].type == EXTENDED) width = 1; if (partinfo[i].type == FREE_SPACE) COLOR_FREE(color) if (strncmp(partinfo[i].temp_fs_name,"ext2",4) == 0) COLOR_EXT2(color) if (strncmp(partinfo[i].temp_fs_name,"ext3",4) == 0) COLOR_EXT3(color) if (strncmp(partinfo[i].temp_fs_name,"reiserfs",8) == 0) COLOR_REIS(color) if (strncmp(partinfo[i].temp_fs_name,"xfs",3) == 0) COLOR_XFS(color) if (strncmp(partinfo[i].temp_fs_name,"jfs",3) == 0) COLOR_JFS(color) if (strncmp(partinfo[i].temp_fs_name,"vfat",4) == 0) COLOR_32FAT(color) if (strncmp(partinfo[i].temp_fs_name,"ntfs",4) == 0) COLOR_NTFS(color) if (strncmp(partinfo[i].temp_fs_name,"linux-swap",4) == 0) COLOR_SWAP(color) if (partinfo[i].flags[4] == PED_PARTITION_RAID) COLOR_RAID(color) if (partinfo[i].flags[5] == PED_PARTITION_LVM) COLOR_LVM(color) debug("Debug: Color: %d, %d, %d\n",color.red,color.green,color.blue); if (width >= 100) { if (strcmp(partinfo[i].partname,"") != 0) gtk_button_set_label(GTK_BUTTON(part_item),partinfo[i].partname); else gtk_button_set_label(GTK_BUTTON(part_item),"Free Space"); } debug("Debug: Color: %d, %d, %d\n",color.red,color.green,color.blue); gtk_widget_modify_bg(part_item,GTK_STATE_NORMAL,&color); gtk_widget_modify_bg(part_item,GTK_STATE_ACTIVE,&color); gtk_widget_modify_bg(part_item,GTK_STATE_PRELIGHT,&color); gtk_widget_set_size_request(GTK_WIDGET(part_item),width,height); partinfo[i].part_widget = part_item; partinfo[i].row_number = rows++; g_signal_connect(GTK_OBJECT(part_item),"clicked", GTK_SIGNAL_FUNC(click_part_item),(gpointer) &partinfo[i]); debug("Debug: Adding partition, number %d:%d width %d type %d name %s size %ld\n",partinfo[i].num, i, width, partinfo[i].type, partinfo[i].partname, partinfo[i].size); gtk_box_pack_start(GTK_BOX(part_box),part_item,TRUE,TRUE,2); } gtk_container_add(GTK_CONTAINER(partition_widget),part_box); part_widget = part_box; gtk_widget_show_all(part_box); gtk_widget_set_size_request(GTK_WIDGET(MainWindow),win_x,win_y); } /* an attempt to clean out the array before adding other crap to it */ void initialise_partinfo(gint i) { gint j; partinfo[i].type = 0; //partinfo[i].part = NULL; for (j = 0; j < MAX_FLAGS; j++) { partinfo[i].flags[j] = 0; } partinfo[i].flag_count = 0; partinfo[i].t_start = 0; partinfo[i].t_end = 0; partinfo[i].start = 0; partinfo[i].end = 0; partinfo[i].max_size = 0; partinfo[i].min_size = 0; partinfo[i].part_widget = NULL; partinfo[i].row_number = 0; partinfo[i].fs = NULL; strcpy(partinfo[i].temp_fs_name,""); strcpy(partinfo[i].temp_flags_list,""); partinfo[i].num = -1; partinfo[i].size = 0; partinfo[i].mb_t_start = 0; partinfo[i].mb_t_end = 0; partinfo[i].mb_start = 0; partinfo[i].mb_end = 0; partinfo[i].mb_min_size = 0; partinfo[i].mb_max_size = 0; strcpy(partinfo[i].partname,""); partinfo[i].label = NULL; partinfo[i].free = FALSE; partinfo[i].unknown = FALSE; partinfo[i].width = 0; } /* This function updates the partinfo array, and fills each struct in it with current info. Also checks for freespace, and changes the used, free labels of the harddisk, updates the progressbar used for showing the percentage of free space. Creates a new store for info selected from the array and displays it in the GtkTreeView in MainWindow. */ gboolean update_partition_list() { GtkWidget *tree = lookup_widget(MainWindow,"treeview1"); GtkWidget *used_widget = lookup_widget(MainWindow,"UsedLabel"); GtkWidget *free_widget = lookup_widget(MainWindow,"FreeLabel"); GtkWidget *size_bar = lookup_widget (MainWindow,"TotalSizeProgressBar"); gint i; GtkTreeIter iter; PedDisk *disk = NULL; PedPartition *part = NULL; PedPartitionFlag flag; gint flags; gint first_flag; glong free_space = 0; gchar buffer[64]; gchar used_label[64]; gchar free_label[64]; gchar percentage[5]; const char *label = NULL; GtkListStore *store = gtk_list_store_new(N_COLUMNS, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING); disk = ped_disk_new (devices[selected_device]); if (!disk) { debug("Debug: No partitions!\n"); return FALSE; } device_freespace = 0; set_timer(); part_extended_nr = part_primary_count = part_extended_count = part_logical_count = part_freespace_count = 0; for (i = 0; i < part_count; i++) { initialise_partinfo(i); part = ped_disk_next_partition(disk,part); if (part == NULL) { /* Non-partition */ continue; } if (G_IS_OBJECT(partinfo[i].part_widget)) gtk_container_remove(GTK_CONTAINER(part_widget),partinfo[i].part_widget); if (part->type & PED_PARTITION_METADATA) { /* metadata, probably partition table */ continue; } if (part->type != 0 && part->type != PED_PARTITION_EXTENDED && part->type != PED_PARTITION_LOGICAL) { /* Error in parted? */ i--; debug("Error: reading partition! Type: %d\n",part->type); } PedConstraint *constraint = NULL; if (!part && !disk) { debug("Error: reading partition!\n"); return TRUE; } //sdebug(minor,"%d",partition_get_minor(part)); partinfo[i].start = (int)part->geom.start; partinfo[i].mb_start = (int)(part->geom.start * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); partinfo[i].end = (int)part->geom.end; partinfo[i].mb_end = (int)(part->geom.end * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); partinfo[i].num = part->num; partinfo[i].size = (int)((partinfo[i].end - partinfo[i].start) * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); partinfo[i].label = ""; if (!(part->type & PED_PARTITION_FREESPACE)) { debug("Debug: Adding partition\n"); strcpy(partinfo[i].partname,ped_partition_get_path(part)); if (part->type & PED_PARTITION_LOGICAL) { partinfo[i].type = LOGICAL; part_logical_count++; } else if (part->type & PED_PARTITION_EXTENDED) { partinfo[i].type = EXTENDED; part_extended_count++; part_extended_nr = i; } else { partinfo[i].type = PRIMARY; part_primary_count++; } flag = ped_partition_flag_next((PedPartitionFlag)0); flags = 0; strcpy(partinfo[i].temp_flags_list,""); while (flag) { if (ped_partition_get_flag(part,flag)) { partinfo[i].flags[flags] = flag; strncpy(buffer,ped_partition_flag_get_name(flag),63); strcpy(buffer,strcat(buffer," ")); strcpy(partinfo[i].temp_flags_list,strcat(partinfo[i].temp_flags_list,buffer)); } flag = ped_partition_flag_next(flag); flags++; } partinfo[i].free = FALSE; constraint = ped_constraint_any(devices[selected_device]); PedGeometry *geometry = NULL; if (constraint != NULL) geometry = ped_disk_get_max_partition_geometry(disk,part,constraint); if (geometry != NULL) { partinfo[i].t_start = (int)geometry->start; partinfo[i].mb_t_start = (int)(geometry->start * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); partinfo[i].t_end = (int)geometry->end; partinfo[i].mb_t_end = (int)(geometry->end * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); } else { partinfo[i].t_start = -1; partinfo[i].mb_t_start = -1; partinfo[i].t_end = -1; partinfo[i].mb_t_end = -1; } PedFileSystem *fs = ped_file_system_open(&part->geom); if (fs) { debug("Debug: Checking if partition %s is resizable...\n", partinfo[i].partname); PedConstraint *resize_con = ped_file_system_get_resize_constraint(fs); if (resize_con) { debug("Debug: constraint accepted: mb_min: %ld mb_max: %ld\n",(int)(resize_con->min_size * 1.0/ MEGABYTE_SIZE * MEGABYTE_SECTORS),(int)(resize_con->max_size * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS)); partinfo[i].min_size = (int)resize_con->min_size; partinfo[i].mb_min_size = (int)(resize_con->min_size * 1.0/ MEGABYTE_SIZE * MEGABYTE_SECTORS); partinfo[i].max_size = (int)resize_con->max_size; partinfo[i].mb_max_size = (int)(resize_con->max_size * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); ped_constraint_destroy(resize_con); } else { debug("Debug: constraint failed! Can'tresize %dth partition\n",i); } ped_file_system_close(fs); // The following two lines shouldn't be necessary since we initialize partinfo[i].label to "" //if (partinfo[i].label != NULL) //g_free(partinfo[i].label); label = ped_partition_get_name(part); if (label != NULL) partinfo[i].label = label; } else { debug("Debug: filesystem couldn't be opened\n"); } } else { /* FREESPACE */ debug("Debug: Adding freespace\n"); device_freespace += partinfo[i].size; partinfo[i].t_start = -1; partinfo[i].mb_t_start = -1; partinfo[i].t_end = -1; partinfo[i].mb_t_end = -1; partinfo[i].free = TRUE; partinfo[i].type = FREE_SPACE; /* Unfortunately, ped_disk_next_partition sets part->num to -1 for all partitions corresponding to free space. This causes a small bug: whenever the user highlights some free space and clicks on "Create", they are forced to create a partition corresponding to the first set of free space on the drive regardless of which set of free space they clicked on. This is a simple workaround for this problem. */ partinfo[i].num -= part_freespace_count++; } strcpy(partinfo[i].temp_fs_name,part->fs_type ? part->fs_type->name : ""); strncpy(buffer,ped_partition_type_get_name(part->type),63); gtk_list_store_append(store,&iter); gtk_list_store_set(store,&iter, PART_NUMBER,partinfo[i].num, PART_PATH,partinfo[i].partname, PART_TYPE,buffer, PART_FS,partinfo[i].temp_fs_name, PART_SIZE,(int)(partinfo[i].size), PART_START,(int)partinfo[i].start, PART_END,(int)partinfo[i].end, PART_FLAGS,partinfo[i].temp_flags_list, -1); } /* Time to set up the TreeView widget*/ GtkTreeSelection *select; select = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); gtk_tree_selection_set_mode(select,GTK_SELECTION_SINGLE); g_signal_connect(G_OBJECT(select),"changed", G_CALLBACK(tree_selection_changed),NULL); gtk_tree_view_set_model(GTK_TREE_VIEW(tree),GTK_TREE_MODEL(store)); sprintf(free_label,"Free: %ld MB",device_freespace); gtk_label_set_text(GTK_LABEL(free_widget),free_label); sprintf(used_label,"Used: %ld MB",device_total_size - device_freespace); gtk_label_set_text(GTK_LABEL(used_widget),used_label); /* Progress bar, pretty useless, but it's in there for some reason */ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(size_bar),(device_total_size - device_freespace) / (gfloat) device_total_size); sprintf(percentage,"Used: %d%%",(gint) (100*((device_total_size - device_freespace) / (gfloat) device_total_size))); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(size_bar),percentage); ped_disk_destroy(disk); return TRUE; } /* executes all changes for when a new device has been selected calls update_partition_list to modifiy the partinfo array */ void update_interface(gint device) { GtkWidget *sizelabel = lookup_widget(MainWindow,"SizeLabel"); gchar string[256]; gint size_drive = (int) devices[device]->length * 1.0 / MEGABYTE_SIZE * devices[device]->sector_size; debug("Debug: device %d is: length %d sector %d MB\n", device,(int)devices[device]->length,size_drive); sprintf(string,"Total size: %d MB",size_drive); device_total_size = size_drive; gtk_label_set_text(GTK_LABEL(sizelabel),string); } /* Function to completly refresh the partition list, meta-function */ void refresh_devices_and_partitions() { GtkWidget *optionmenu = lookup_widget(MainWindow,"MainHarddiskOptionMenu"); //ped_device_close(devices[selected_device]); selected_device = gtk_option_menu_get_history(GTK_OPTION_MENU(optionmenu)); //ped_device_open(devices[selected_device]); scan_partitions(&devices[selected_device]); update_interface(selected_device); if (update_partition_list() == FALSE) { gtk_widget_show(TableWindow); } else { update_partition_widget(); click_part_item(NULL,&partinfo[selected_partition]); } } --- NEW FILE: ui.h --- #ifndef PM_UI_H #define PM_UI_H void redirect_stderr_to_pipe(int * saved_fd, int * readable_pipe); void unredirect_stderr(int saved_fd, int readable_pipe); void show_error_message(gchar * message); void untoggle_create_types(); void untoggle_create_flags(); void show_create_fstype(); void hide_create_fstype(); void show_create_flags(); void hide_create_flags(); void show_busy_cursor( GdkWindow * window); void show_normal_cursor( GdkWindow * window ); void get_filesystem_list(); gint get_arraynumber_from_partinfo_num(gint num); struct partinfo_struct *get_partition_from_partinfo_num(gint num); void tree_selection_changed (GtkTreeSelection *selection, gpointer data); gboolean click_part_item(GtkWidget *widget, gpointer data); void update_partition_widget(); void initialise_partinfo(gint i); gboolean update_partition_list(); void update_interface(gint device); void refresh_devices_and_partitions(); #endif // PM_UI_H Index: Makefile.am =================================================================== RCS file: /cvsroot/morphix/partitionmorpher/src/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile.am 7 Apr 2003 23:43:54 -0000 1.1.1.1 --- Makefile.am 2 Jan 2004 15:17:31 -0000 1.2 *************** *** 13,17 **** interface.c interface.h \ callbacks.c callbacks.h \ ! pm_libparted.c pm_libparted.h partitionmorpher_LDADD = @PACKAGE_LIBS@ $(INTLLIBS) -lparted --- 13,18 ---- interface.c interface.h \ callbacks.c callbacks.h \ ! pm_libparted.c pm_libparted.h \ ! ui.c ui.h pm_fswrap.c pm_fswrap.h partitionmorpher_LDADD = @PACKAGE_LIBS@ $(INTLLIBS) -lparted Index: callbacks.c =================================================================== RCS file: /cvsroot/morphix/partitionmorpher/src/callbacks.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** callbacks.c 11 Dec 2003 13:30:24 -0000 1.11 --- callbacks.c 2 Jan 2004 15:17:31 -0000 1.12 *************** *** 14,17 **** --- 14,19 ---- #include "support.h" #include "pm_libparted.h" + #include "pm_fswrap.h" + #include "ui.h" /* *************** *** 64,125 **** void - redirect_stderr_to_pipe(int * saved_fd, int * readable_pipe) - { - int stderr_fd; - int pipe_fd[2]; - - /* Make a copy of the stderr file-descriptor so we can restore it later */ - stderr_fd = fileno(stderr); - *saved_fd = dup(stderr_fd); - - /* Open up a pipe */ - if (pipe(pipe_fd) == -1) { - fprintf(stderr, "Could not create pipe; errno=%d!\n", errno); - exit(-1); - } - - /* Redirect stderr to the writable end of the pipe */ - if ( dup2(pipe_fd[1], stderr_fd) == -1 ) { - fprintf(stderr, "Could not redirect stderr to the pipe!\n"); - exit(-1); - } - - /* Since stderr & pipe_fd[1] point to the same thing, close pipe_fd[1] */ - /* NOTE: Do I really need this? */ - close(pipe_fd[1]); - - /* Make sure stderr output is non-blocking (don't hang waiting for EOF) */ - int oldflags; - oldflags = fcntl(pipe_fd[0], F_GETFL, 0); - fcntl(pipe_fd[0], F_SETFL, oldflags|O_NONBLOCK); - *readable_pipe = pipe_fd[0]; - } - - void - unredirect_stderr(int saved_fd, int readable_pipe) - { - /* Close the input (readable) end of the pipe*/ - close(readable_pipe); - - /* Now undo the effects of redirecting output */ - dup2(saved_fd, fileno(stderr)); - - /* Now that we no longer need the saved_fd, we can close it */ - close(saved_fd); - } - - void - show_error_message(gchar * message) - { - int length = strlen(message)-1; - while (message[length] == '\n') - length--; - message[++length] = '\0'; - GtkWidget *error_label = lookup_widget(ErrorWindow,"ErrorLabel"); - gtk_label_set_text(GTK_LABEL(error_label), message); - gtk_widget_show(ErrorWindow); - } - - void on_ErrorOkButton_clicked (GtkButton *button, gpointer user_data) --- 66,69 ---- *************** *** 129,676 **** void - show_busy_cursor( GdkWindow * window ) - { - static GdkCursor * busy_cursor = NULL; - - if (!busy_cursor) - busy_cursor = gdk_cursor_new(GDK_WATCH); - - /* Make the specified window show the busy cursor */ - gdk_window_set_cursor( window, busy_cursor ); - - /* Also make the MainWindow show the busy cursor */ - gdk_window_set_cursor( MainWindow->window, busy_cursor ); - - while (gtk_events_pending()) - gtk_main_iteration(); - } - - void - show_normal_cursor( GdkWindow * window ) - { - gdk_window_set_cursor( window, NULL ); - gdk_window_set_cursor( MainWindow->window, NULL ); - } - - /* - initialise list of filesystem types - stores this in fsinfo-array, contains name, color and bool's for cr/re/cp - */ - - void get_filesystem_list() { - PedFileSystemType *walk = ped_file_system_type_get_next(NULL); - gint i = 0; - while (walk) { - fsinfo[i].name = malloc(strlen(walk->name) + 1); - strcpy(fsinfo[i].name,walk->name); - fsinfo[i].creatable = (gboolean) walk->ops->create; - fsinfo[i].resizeable = (gboolean) walk->ops->resize; - fsinfo[i].copyable = (gboolean) walk->ops->copy; - fsinfo[i].color = i; - walk = ped_file_system_type_get_next(walk); - } - fs_count = i; - } - - gint get_arraynumber_from_partinfo_num(gint num) { - gint i; - for (i = 1; i < part_count; i++) { - if (partinfo[i].num == num) { - return i; - } - } - return -1; - } - - struct partinfo_struct *get_partition_from_partinfo_num(gint num) { - gint i; - for (i = 1; i < part_count; i++) { - if (partinfo[i].num == num) { - return &partinfo[i]; - } - } - return NULL; - } - - /* List item selection callback */ - - void tree_selection_changed (GtkTreeSelection *selection, gpointer data) { - GtkWidget *create_widget = lookup_widget(MainWindow,"CreateButton"); - GtkWidget *resize_widget = lookup_widget(MainWindow,"ResizeButton"); - GtkWidget *delete_widget = lookup_widget(MainWindow,"DeleteButton"); - GtkWidget *move_widget = lookup_widget(MainWindow,"MoveButton"); - GtkWidget *convert_widget = lookup_widget(MainWindow,"ConvertButton"); - GtkWidget *refresh_widget = lookup_widget(MainWindow,"RefreshButton"); - - GtkTreeIter iter; - GtkTreeModel *model; - gint num; - struct partinfo_struct *partition; - - if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - gtk_tree_model_get(model, &iter,PART_NUMBER, &num,-1); - partition = get_partition_from_partinfo_num(num); - selected_partition = get_arraynumber_from_partinfo_num(num); - if (selected_partition < 0) { - debug("Error: selected partition has invalid arraynumber: %d\n",selected_partition); - } - else if (partition != NULL) { - - if (partition->type == FREE_SPACE) { - if (has_max_primary_partitions(&devices[selected_device]) && (selected_partition < part_extended_nr || part_extended_nr == 0)) { gtk_widget_set_sensitive(create_widget,FALSE); - } - else { - gtk_widget_set_sensitive(create_widget,TRUE); - } - gtk_widget_set_sensitive(resize_widget,FALSE); - - gtk_widget_set_sensitive(delete_widget,FALSE); - gtk_widget_set_sensitive(move_widget,FALSE); - gtk_widget_set_sensitive(convert_widget,FALSE); - } - else { - gtk_widget_set_sensitive(create_widget,FALSE); - if (partition->type == EXTENDED) { - /* - if the partition is extended, - extra restraints are necessary. - You can't delete the extended partition - if logical partitions exist in it. - Thankfully for me, you can only have - one extended partition... - */ - if (part_logical_count > 0) { - gtk_widget_set_sensitive(resize_widget,FALSE); - gtk_widget_set_sensitive(delete_widget,FALSE); - gtk_widget_set_sensitive(move_widget,FALSE); - gtk_widget_set_sensitive(convert_widget,FALSE); - } - else { - gtk_widget_set_sensitive(resize_widget,FALSE); - gtk_widget_set_sensitive(delete_widget,TRUE); - gtk_widget_set_sensitive(move_widget,FALSE); - gtk_widget_set_sensitive(convert_widget,FALSE); - } - } - else { - gtk_widget_set_sensitive(resize_widget,TRUE); - gtk_widget_set_sensitive(delete_widget,TRUE); - gtk_widget_set_sensitive(move_widget,TRUE); - gtk_widget_set_sensitive(convert_widget,TRUE); - } - } - } - } - } - - /* Partition button callback */ - - gboolean click_part_item(GtkWidget *widget, gpointer data) { - struct partinfo_struct *partition = (struct partinfo_struct *)data; - GtkWidget *treeview = lookup_widget(MainWindow,"treeview1"); - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - gchar path_string[4]; - sprintf(path_string,"%d",partition->row_number); - GtkTreePath *path = gtk_tree_path_new_from_string(path_string); - if (path != NULL) { - gtk_tree_selection_select_path(GTK_TREE_SELECTION(selection), - (path)); - } - } - /* - updates partinfo-array with all partitions for the current selected_device - skips the METADATA partition that seems to be before the first partition - modifies the GtkList of partitions - */ - - void update_partition_widget() { - GtkWidget *partition_widget = lookup_widget(MainWindow,"hbox4"); - GtkWidget *part_box = gtk_hbox_new(FALSE,5); - gint i; - gint win_x; - gint win_y; - gint height = 30; - gint rows = 0; - - if (G_IS_OBJECT(part_widget)) - gtk_container_remove(GTK_CONTAINER(partition_widget),part_widget); - gtk_window_get_size(GTK_WINDOW(MainWindow),&win_x,&win_y); - - win_x -= 10; // border - - for (i = 1; i < part_count; i++) { - if (partinfo[i].part == NULL && partinfo[i].free != TRUE) { - debug("Debug: Skipping partition. Free: %d\n",partinfo[i].free); - continue; - } - - GtkWidget *part_item = gtk_button_new(); - gfloat perc = (float)partinfo[i].size / device_total_size; - gint width = (win_x / 100) * 100 * perc; - GdkColor color; - /* Default color */ - color.red = 32768; color.blue = 32768; color.green = 32768; - - if (width <= 20) - width = 20; - if (partinfo[i].type == EXTENDED) - width = 1; - if (partinfo[i].type == FREE_SPACE) - COLOR_FREE(color) - if (strncmp(partinfo[i].temp_fs_name,"ext2",4) == 0) - COLOR_EXT2(color) - if (strncmp(partinfo[i].temp_fs_name,"ext3",4) == 0) - COLOR_EXT3(color) - if (strncmp(partinfo[i].temp_fs_name,"reiserfs",8) == 0) - COLOR_REIS(color) - if (strncmp(partinfo[i].temp_fs_name,"xfs",3) == 0) - COLOR_XFS(color) - if (strncmp(partinfo[i].temp_fs_name,"jfs",3) == 0) - COLOR_JFS(color) - if (strncmp(partinfo[i].temp_fs_name,"vfat",4) == 0) - COLOR_32FAT(color) - if (strncmp(partinfo[i].temp_fs_name,"ntfs",4) == 0) - COLOR_NTFS(color) - if (strncmp(partinfo[i].temp_fs_name,"linux-swap",4) == 0) - COLOR_SWAP(color) - if (partinfo[i].flags[4] == PED_PARTITION_RAID) - COLOR_RAID(color) - if (partinfo[i].flags[5] == PED_PARTITION_LVM) - COLOR_LVM(color) - debug("Debug: Color: %d, %d, %d\n",color.red,color.green,color.blue); - if (width >= 100) { - if (strcmp(partinfo[i].partname,"") != 0) - gtk_button_set_label(GTK_BUTTON(part_item),partinfo[i].partname); - else - gtk_button_set_label(GTK_BUTTON(part_item),"Free Space"); - } - - debug("Debug: Color: %d, %d, %d\n",color.red,color.green,color.blue); - - gtk_widget_modify_bg(part_item,GTK_STATE_NORMAL,&color); - gtk_widget_modify_bg(part_item,GTK_STATE_ACTIVE,&color); - gtk_widget_modify_bg(part_item,GTK_STATE_PRELIGHT,&color); - - gtk_widget_set_size_request(GTK_WIDGET(part_item),width,height); - partinfo[i].part_widget = part_item; - partinfo[i].row_number = rows++; - g_signal_connect(GTK_OBJECT(part_item),"clicked", - GTK_SIGNAL_FUNC(click_part_item),(gpointer) &partinfo[i]); - debug("Debug: Adding partition, number %d:%d width %d type %d name %s size %ld\n",partinfo[i].num, i, width, partinfo[i].type, partinfo[i].partname, partinfo[i].size); - - gtk_box_pack_start(GTK_BOX(part_box),part_item,TRUE,TRUE,2); - } - gtk_container_add(GTK_CONTAINER(partition_widget),part_box); - part_widget = part_box; - gtk_widget_show_all(part_box); - gtk_widget_set_size_request(GTK_WIDGET(MainWindow),win_x,win_y); - } - - /* - an attempt to clean out the array before adding other crap to it - */ - - void initialise_partinfo(gint i) { - gint j; - - partinfo[i].type = 0; - partinfo[i].part = NULL; - for (j = 0; j < MAX_FLAGS; j++) { - partinfo[i].flags[j] = 0; - } - partinfo[i].flag_count = 0; - partinfo[i].t_start = 0; - partinfo[i].t_end = 0; - partinfo[i].start = 0; - partinfo[i].end = 0; - partinfo[i].max_size = 0; - partinfo[i].min_size = 0; - - partinfo[i].part_widget = NULL; - partinfo[i].row_number = 0; - - partinfo[i].fs = NULL; - strcpy(partinfo[i].temp_fs_name,""); - strcpy(partinfo[i].temp_flags_list,""); - partinfo[i].num = 0; - - partinfo[i].size = 0; - partinfo[i].mb_t_start = 0; - partinfo[i].mb_t_end = 0; - partinfo[i].mb_start = 0; - partinfo[i].mb_end = 0; - partinfo[i].mb_min_size = 0; - partinfo[i].mb_max_size = 0; - strcpy(partinfo[i].partname,""); - partinfo[i].label = NULL; - partinfo[i].free = FALSE; - partinfo[i].unknown = FALSE; - partinfo[i].width = 0; - } - - - /* - This function updates the partinfo array, and fills each struct in it with - current info. Also checks for freespace, and changes the used, free labels - of the harddisk, updates the progressbar used for showing the percentage - of free space. Creates a new store for info selected from the array and - displays it in the GtkTreeView in MainWindow. - */ - - gboolean update_partition_list() { - GtkWidget *tree = lookup_widget(MainWindow,"treeview1"); - GtkWidget *used_widget = lookup_widget(MainWindow,"UsedLabel"); - GtkWidget *free_widget = lookup_widget(MainWindow,"FreeLabel"); - GtkWidget *size_bar = lookup_widget (MainWindow,"TotalSizeProgressBar"); - gint i; - GtkTreeIter iter; - PedDisk *disk = NULL; - PedPartition *part = NULL; - PedPartitionFlag flag; - gint flags; - gint first_flag; - glong free_space = 0; - gchar buffer[64]; - gchar used_label[64]; - gchar free_label[64]; - gchar percentage[5]; - const char *label = NULL; - GtkListStore *store = gtk_list_store_new(N_COLUMNS, - G_TYPE_INT, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_STRING); - disk = ped_disk_new (devices[selected_device]); - if (!disk) { - debug("Debug: No partitions!\n"); - - return FALSE; - } - device_freespace = 0; - - set_timer(); - - part_extended_nr = part_primary_count = part_extended_count = part_logical_count = part_freespace_count = 0; - - - for (i = 0; i < part_count; i++) { - initialise_partinfo(i); - part = ped_disk_next_partition(disk,part); - if (part == NULL) { - /* Non-partition */ - continue; - } - if (G_IS_OBJECT(partinfo[i].part_widget)) - gtk_container_remove(GTK_CONTAINER(part_widget),partinfo[i].part_widget); - if (part->type & PED_PARTITION_METADATA) { - /* metadata, probably partition table */ - continue; - } - if (part->type != 0 && - part->type != PED_PARTITION_EXTENDED && - part->type != PED_PARTITION_LOGICAL) { - /* Error in parted? */ - debug("Error: reading partition! Type: %d\n",part->type); - } - PedConstraint *constraint = NULL; - if (!part && !disk) { - debug("Error: reading partition!\n"); - return TRUE; - } - - //sdebug(minor,"%d",partition_get_minor(part)); - - partinfo[i].part = part; - partinfo[i].start = (int)part->geom.start; - partinfo[i].mb_start = (int)(part->geom.start * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - partinfo[i].end = (int)part->geom.end; - partinfo[i].mb_end = (int)(part->geom.end * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - partinfo[i].num = part->num; - partinfo[i].size = (int)((partinfo[i].end - partinfo[i].start) * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - partinfo[i].label = ""; - if (!(part->type & PED_PARTITION_FREESPACE)) { - debug("Debug: Adding partition\n"); - strcpy(partinfo[i].partname,ped_partition_get_path(part)); - if (part->type & PED_PARTITION_LOGICAL) { - partinfo[i].type = LOGICAL; - part_logical_count++; - } - else if (part->type & PED_PARTITION_EXTENDED) { - partinfo[i].type = EXTENDED; - part_extended_count++; - part_extended_nr = i; - } - else { - partinfo[i].type = PRIMARY; - part_primary_count++; - } - - flag = ped_partition_flag_next((PedPartitionFlag)0); - flags = 0; - strcpy(partinfo[i].temp_flags_list,""); - while (flag) { - if (ped_partition_get_flag(part,flag)) { - partinfo[i].flags[flags] = flag; - strncpy(buffer,ped_partition_flag_get_name(flag),63); - strcpy(buffer,strcat(buffer," ")); - strcpy(partinfo[i].temp_flags_list,strcat(partinfo[i].temp_flags_list,buffer)); - - } - flag = ped_partition_flag_next(flag); - - flags++; - } - partinfo[i].free = FALSE; - constraint = ped_constraint_any(devices[selected_device]); - PedGeometry *geometry = NULL; - if (constraint != NULL) - geometry = ped_disk_get_max_partition_geometry(disk,part,constraint); - if (geometry != NULL) { - partinfo[i].t_start = (int)geometry->start; - partinfo[i].mb_t_start = (int)(geometry->start * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - partinfo[i].t_end = (int)geometry->end; - partinfo[i].mb_t_end = (int)(geometry->end * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - } else { - partinfo[i].t_start = -1; - partinfo[i].mb_t_start = -1; - partinfo[i].t_end = -1; - partinfo[i].mb_t_end = -1; - } - PedFileSystem *fs = ped_file_system_open(&part->geom); - if (fs) { - debug("Debug: Checking if partition %s is resizable...\n", partinfo[i].partname); - - PedConstraint *resize_con = - ped_file_system_get_resize_constraint(fs); - if (resize_con) { - debug("Debug: constraint accepted: mb_min: %ld mb_max: %ld\n",(int)(resize_con->min_size * 1.0/ MEGABYTE_SIZE * MEGABYTE_SECTORS),(int)(resize_con->max_size * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS)); - partinfo[i].min_size = (int)resize_con->min_size; - partinfo[i].mb_min_size = (int)(resize_con->min_size * 1.0/ MEGABYTE_SIZE * MEGABYTE_SECTORS); - partinfo[i].max_size = (int)resize_con->max_size; - partinfo[i].mb_max_size = (int)(resize_con->max_size * 1.0 / MEGABYTE_SIZE * MEGABYTE_SECTORS); - ped_constraint_destroy(resize_con); - } - else { - debug("Debug: constraint failed! Can'tresize %dth partition\n",i); - } - ped_file_system_close(fs); - // The following two lines shouldn't be necessary since we initialize partinfo[i].label to "" - //if (partinfo[i].label != NULL) - //g_free(partinfo[i].label); - label = ped_partition_get_name(part); - if (label != NULL) - partinfo[i].label = label; - } - else { - debug("Debug: filesystem couldn't be opened\n"); - } - } - else { - /* FREESPACE */ - debug("Debug: Adding freespace\n"); - device_freespace += partinfo[i].size; - partinfo[i].t_start = -1; - partinfo[i].mb_t_start = -1; - partinfo[i].t_end = -1; - partinfo[i].mb_t_end = -1; - partinfo[i].free = TRUE; - partinfo[i].type = FREE_SPACE; - - /* Unfortunately, ped_disk_next_partition sets part->num to -1 - for all partitions corresponding to free space. This - causes a small bug: whenever the user highlights some free - space and clicks on "Create", they are forced to create a - partition corresponding to the first set of free space on - the drive regardless of which set of free space they - clicked on. This is a simple workaround for this problem. */ - partinfo[i].num -= part_freespace_count++; - } - - strcpy(partinfo[i].temp_fs_name,part->fs_type ? part->fs_type->name : ""); - strncpy(buffer,ped_partition_type_get_name(part->type),63); - - gtk_list_store_append(store,&iter); - gtk_list_store_set(store,&iter, - PART_NUMBER,partinfo[i].num, - PART_PATH,partinfo[i].partname, - PART_TYPE,buffer, - PART_FS,partinfo[i].temp_fs_name, - PART_SIZE,(int)(partinfo[i].size), - PART_START,(int)partinfo[i].start, - PART_END,(int)partinfo[i].end, - PART_FLAGS,partinfo[i].temp_flags_list, - -1); - } - /* Time to set up the TreeView widget*/ - - GtkTreeSelection *select; - - select = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); - gtk_tree_selection_set_mode(select,GTK_SELECTION_SINGLE); - g_signal_connect(G_OBJECT(select),"changed", - G_CALLBACK(tree_selection_changed),NULL); - - gtk_tree_view_set_model(GTK_TREE_VIEW(tree),GTK_TREE_MODEL(store)); - - sprintf(free_label,"Free: %ld MB",device_freespace); - gtk_label_set_text(GTK_LABEL(free_widget),free_label); - - sprintf(used_label,"Used: %ld MB",device_total_size - device_freespace); - gtk_label_set_text(GTK_LABEL(used_widget),used_label); - - /* Progress bar, pretty useless, but it's in there for some reason */ - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(size_bar),(device_total_size - device_freespace) / (gfloat) device_total_size); - sprintf(percentage,"Used: %d%%",(gint) (100*((device_total_size - device_freespace) / (gfloat) device_total_size))); - gtk_progress_bar_set_text(GTK_PROGRESS_BAR(size_bar),percentage); - - ped_disk_destroy(disk); - return TRUE; - } - - - - - /* - executes all changes for when a new device has been selected - calls update_partition_list to modifiy the partinfo array - */ - - void update_interface(gint device) { - GtkWidget *sizelabel = lookup_widget(MainWindow,"SizeLabel"); - gchar string[256]; - gint size_drive = (int) devices[device]->length * 1.0 / MEGABYTE_SIZE * devices[device]->sector_size; - debug("Debug: device %d is: length %d sector %d MB\n", - device,(int)devices[device]->length,size_drive); - sprintf(string,"Total size: %d MB",size_drive); - device_total_size = size_drive; - gtk_label_set_text(GTK_LABEL(sizelabel),string); - } - - /* - Function to completly refresh the partition list, meta-function - */ - - void refresh_devices_and_partitions() { - GtkWidget *optionmenu = lookup_widget(MainWindow,"MainHarddiskOptionMenu"); - //ped_device_close(devices[selected_device]); - - selected_device = gtk_option_menu_get_history(GTK_OPTION_MENU(optionmenu)); - //ped_device_open(devices[selected_device]); - scan_partitions(&devices[selected_device]); - update_interface(selected_device); - if (update_partition_list() == FALSE) { - gtk_widget_show(TableWindow); - } - else { - update_partition_widget(); - click_part_item(NULL,&partinfo[selected_partition]); - } - } - - void on_CreateButton_clicked (GtkButton *button, gpointer user_data) --- 73,76 ---- *************** *** 693,696 **** --- 93,97 ---- gtk_range_set_adjustment(GTK_RANGE(range),GTK_ADJUSTMENT(adjustment));*/ gtk_widget_show (CreateWindow); + untoggle_create_types(); } *************** *** 702,706 **** gchar buffer[64]; GtkObject *adjustment; - GtkWidget *range = lookup_widget(ResizeWindow,"hscale2"); GtkWidget *device_label = lookup_widget(ResizeWindow,"ResizeDeviceLabel"); GtkWidget *fs_label = lookup_widget(ResizeWindow,"ResizeFsLabel"); --- 103,106 ---- *************** *** 716,727 **** sprintf(buffer,"%ld MB",partinfo[selected_partition].size); gtk_label_set_text(GTK_LABEL(size_label),buffer); - - adjustment = gtk_adjustment_new((gdouble)partinfo[selected_partition].size, - (gdouble)partinfo[selected_partition].mb_min_size, - (gdouble)partinfo[selected_partition].mb_max_size, - 1.0, - 100.0, - (gdouble)0); - gtk_range_set_adjustment(GTK_RANGE(range),GTK_ADJUSTMENT(adjustment)); gtk_widget_show (ResizeWindow); } --- 116,119 ---- *************** *** 737,741 **** GtkWidget *size_label = lookup_widget(DeleteWindow,"DeleteSizeLabel"); gtk_label_set_text(GTK_LABEL(path_label),partinfo[selected_partition].partname); ! gtk_label_set_text(GTK_LABEL(fs_label),partinfo[selected_partition].temp_fs_name); sprintf(buffer,"%ld MB",partinfo[selected_partition].size); gtk_label_set_text(GTK_LABEL(size_label),buffer); --- 129,139 ---- GtkWidget *size_label = lookup_widget(DeleteWindow,"DeleteSizeLabel"); gtk_label_set_text(GTK_LABEL(path_label),partinfo[selected_partition].partname); ! if (strcmp(partinfo[selected_partition].temp_fs_name,"") != 0) { ! gtk_widget_show(fs_label); ! gtk_label_set_text(GTK_LABEL(fs_label),partinfo[selected_partition].temp_fs_name); ! } ! else { ! gtk_widget_hide(fs_label); ! } sprintf(buffer,"%ld MB",partinfo[selected_partition].size); gtk_label_set_text(GTK_LABEL(size_label),buffer); *************** *** 1117,1121 **** debug("Debug: Move not yet implemented!\n"); /* ! do_move(&devices[selected_device],partinfo[selected_partition].part,partinfo[selected_partition].partname,(PedSector) start, (PedSector) end); */ gtk_widget_hide(MoveWindow); --- 515,519 ---- debug("Debug: Move not yet implemented!\n"); /* ! do_move(&devices[selected_device],partinfo[selected_partition].nr,partinfo[selected_partition].partname,(PedSector) start, (PedSector) end); */ gtk_widget_hide(MoveWindow); *************** *** 1242,1256 **** unredirect_stderr(saved_fd, stderr_pipe); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_boot_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_BOOT,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_root_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_ROOT,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_hidden_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_HIDDEN,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_raid_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_RAID,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_lvm_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_LVM,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_lba_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].part,PED_PARTITION_LBA,1); } else { index = read(stderr_pipe, error_message_buffer, 1000); --- 640,654 ---- unredirect_stderr(saved_fd, stderr_pipe); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_boot_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_BOOT,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_root_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_ROOT,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_hidden_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_HIDDEN,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_raid_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_RAID,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_lvm_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_LVM,1); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_lba_flag))) ! set_part_flag_state(&devices[selected_device],partinfo[selected_partition].num,PED_PARTITION_LBA,1); } else { index = read(stderr_pipe, error_message_buffer, 1000); *************** *** 1272,1277 **** { PedSector end_sector; ! GtkWidget *range = lookup_widget(ResizeWindow,"hscale2"); ! long long mb_size = (long long)gtk_range_get_value(GTK_RANGE(range)); long long sector_num = ((mb_size * 1024*1024) / 512); --- 670,676 ---- { PedSector end_sector; ! GtkWidget *entry = lookup_widget(ResizeWindow,"entry2"); ! ! long long mb_size = (long long)atol(gtk_entry_get_text(GTK_ENTRY(entry))); long long sector_num = ((mb_size * 1024*1024) / 512); *************** *** 1280,1286 **** debug("Debug: mbsize: %lld, end: %lld\n",mb_size,end_sector); ! do_resize(&devices[selected_device],partinfo[selected_partition].part, ! partinfo[selected_partition].partname, ! (PedSector) partinfo[selected_partition].start,(PedSector) end_sector); gtk_widget_hide(ResizeWindow); refresh_devices_and_partitions(); --- 679,693 ---- debug("Debug: mbsize: %lld, end: %lld\n",mb_size,end_sector); ! if (strcmp(partinfo[selected_partition].temp_fs_name,"ntfs") == 0) { ! do_ntfsresize(&devices[selected_device],partinfo[selected_partition].num,(PedSector)partinfo[selected_partition].end, ! partinfo[selected_partition].partname, ! (PedSector) partinfo[selected_partition].start,(PedSector) end_sector); ! } ! else { ! ! do_resize(&devices[selected_device],partinfo[selected_partition].num, ! partinfo[selected_partition].partname, ! (PedSector) partinfo[selected_partition].start,(PedSector) end_sector); ! } gtk_widget_hide(ResizeWindow); refresh_devices_and_partitions(); *************** *** 1524,1535 **** } - void untoggle_create_flags() { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")),FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateRootFlagCheckbutton")),FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")),FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")),FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")),FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")),FALSE); - } --- 931,934 ---- *************** *** 1583,1615 **** } - void show_create_fstype() { - gtk_widget_show(lookup_widget(CreateWindow,"optionmenu4")); - gtk_widget_show(lookup_widget(CreateWindow,"label27")); - } - - void hide_create_fstype() { - gtk_widget_hide(lookup_widget(CreateWindow,"optionmenu4")); - gtk_widget_hide(lookup_widget(CreateWindow,"label27")); - } - - void show_create_flags() { - gtk_widget_show(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"CreateRootFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")); - gtk_widget_show(lookup_widget(CreateWindow,"label65")); - } - - void hide_create_flags() { - gtk_widget_hide(lookup_widget(CreateWindow,"CreateBootFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"CreateRootFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"CreateHiddenFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"CreateRaidFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"CreateLVMFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"CreateLBAFlagCheckbutton")); - gtk_widget_hide(lookup_widget(CreateWindow,"label65")); - } void --- 982,985 ---- *************** *** 1641,1645 **** { if (gtk_toggle_button_get_active(togglebutton)) { ! hide_create_flags(); /* afaik logical partitions can't have flags set... */ show_create_fstype(); gtk_window_resize(GTK_WINDOW(CreateWindow),1,1); --- 1011,1015 ---- { if (gtk_toggle_button_get_active(togglebutton)) { ! show_create_flags(); show_create_fstype(); gtk_window_resize(GTK_WINDOW(CreateWindow),1,1); *************** *** 1651,1656 **** gpointer user_data) { - fprintf(stderr, "on_CreateTypeRadiobutton_clicked called.\n"); - GtkWidget *radio_primary_type = lookup_widget(CreateWindow,"CreatePrimaryRadiobutton"); GtkWidget *radio_extended_type = lookup_widget(CreateWindow,"CreateExtendedRadiobutton"); --- 1021,1024 ---- Index: interface.c =================================================================== RCS file: /cvsroot/morphix/partitionmorpher/src/interface.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** interface.c 11 Dec 2003 13:30:24 -0000 1.8 --- interface.c 2 Jan 2004 15:17:31 -0000 1.9 *************** *** 39,44 **** GtkWidget *MoveButton; GtkWidget *ConvertButton; GtkWidget *RefreshButton; - GtkWidget *RevertButton; GtkWidget *HelpButton; GtkWidget *QuitButton; --- 39,44 ---- GtkWidget *MoveButton; GtkWidget *ConvertButton; + GtkWidget *button1; GtkWidget *RefreshButton; GtkWidget *HelpButton; GtkWidget *QuitButton; *************** *** 125,128 **** --- 125,129 ---- gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (toolbar1)->children)->data))->label), TRUE); gtk_widget_show (MoveButton); + gtk_widget_set_sensitive (MoveButton, FALSE); tmp_toolbar_icon = gtk_image_new_from_stock ("gtk-convert", gtk_toolbar_get_icon... [truncated message content] |