mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-11-25 18:31:14 +00:00
Merge pull request #126 from schinkelg/kanjitalk755
Volume creation changes for the Unix GTK prefs editor.
This commit is contained in:
commit
45578ddd45
@ -23,6 +23,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@ -572,15 +573,22 @@ static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
|||||||
static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
||||||
{
|
{
|
||||||
gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
|
gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
|
||||||
|
|
||||||
const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
|
const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
|
||||||
int size = atoi(str);
|
int disk_size = atoi(str);
|
||||||
|
if (disk_size < 1 || disk_size > 2000) {
|
||||||
char cmd[1024];
|
printf("Disk size needs to be between 1 and 2000 MB.\n");
|
||||||
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
|
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
||||||
int ret = system(cmd);
|
delete assoc;
|
||||||
if (ret == 0)
|
return;
|
||||||
|
}
|
||||||
|
int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
if (fd < 0 && errno == EEXIST) {
|
||||||
|
printf("File already exists, refusing to overwrite file.\n");
|
||||||
|
} else {
|
||||||
|
ftruncate(fd, disk_size * 1024 * 1024);
|
||||||
gtk_clist_append(GTK_CLIST(volume_list), &file);
|
gtk_clist_append(GTK_CLIST(volume_list), &file);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
||||||
delete assoc;
|
delete assoc;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/if_arp.h>
|
#include <net/if_arp.h>
|
||||||
|
|
||||||
@ -501,15 +502,22 @@ static void add_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
|||||||
static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc)
|
||||||
{
|
{
|
||||||
gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
|
gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req));
|
||||||
|
|
||||||
const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
|
const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry));
|
||||||
int size = atoi(str);
|
int disk_size = atoi(str);
|
||||||
|
if (disk_size < 1 || disk_size > 2000) {
|
||||||
char cmd[1024];
|
printf("Disk size needs to be between 1 and 2000 MB.\n");
|
||||||
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size);
|
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
||||||
int ret = system(cmd);
|
delete assoc;
|
||||||
if (ret == 0)
|
return;
|
||||||
|
}
|
||||||
|
int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
if (fd < 0 && errno == EEXIST) {
|
||||||
|
printf("File already exists, refusing to overwrite file.\n");
|
||||||
|
} else {
|
||||||
|
ftruncate(fd, disk_size * 1024 * 1024);
|
||||||
gtk_clist_append(GTK_CLIST(volume_list), &file);
|
gtk_clist_append(GTK_CLIST(volume_list), &file);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
gtk_widget_destroy(GTK_WIDGET(assoc->req));
|
||||||
delete assoc;
|
delete assoc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user