From 81ccbfa1e74dfe1a4bac911d95fe68389871ed5f Mon Sep 17 00:00:00 2001 From: Ger Schinkel Date: Mon, 2 May 2022 16:40:55 +0200 Subject: [PATCH 1/3] Volume creation changes. No longer dependent on dd system command. Does not overwrite existing files. Rudimentary file size checks. --- BasiliskII/src/Unix/prefs_editor_gtk.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/BasiliskII/src/Unix/prefs_editor_gtk.cpp b/BasiliskII/src/Unix/prefs_editor_gtk.cpp index d7ceae8c..e9432629 100644 --- a/BasiliskII/src/Unix/prefs_editor_gtk.cpp +++ b/BasiliskII/src/Unix/prefs_editor_gtk.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -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) { gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req)); - const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry)); - int size = atoi(str); - - char cmd[1024]; - sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size); - int ret = system(cmd); - if (ret == 0) + int disk_size = atoi(str); + if (disk_size < 1 || disk_size > 2000) { + printf("Disk size needs to be between 1 and 2000 MB.\n"); + gtk_widget_destroy(GTK_WIDGET(assoc->req)); + delete assoc; + return; + } + int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR); + 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); + } + close(fd); gtk_widget_destroy(GTK_WIDGET(assoc->req)); delete assoc; } From 2666bef882683880bff52553c752bb9d1a2ab0f9 Mon Sep 17 00:00:00 2001 From: Ger Schinkel Date: Mon, 2 May 2022 19:56:22 +0200 Subject: [PATCH 2/3] Forgot Sheepshaver. Same fix. --- SheepShaver/src/Unix/prefs_editor_gtk.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/SheepShaver/src/Unix/prefs_editor_gtk.cpp b/SheepShaver/src/Unix/prefs_editor_gtk.cpp index a3984f34..a26ba7de 100644 --- a/SheepShaver/src/Unix/prefs_editor_gtk.cpp +++ b/SheepShaver/src/Unix/prefs_editor_gtk.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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) { gchar *file = (gchar *)gtk_file_selection_get_filename(GTK_FILE_SELECTION(assoc->req)); - const gchar *str = gtk_entry_get_text(GTK_ENTRY(assoc->entry)); - int size = atoi(str); - - char cmd[1024]; - sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", file, size); - int ret = system(cmd); - if (ret == 0) + int disk_size = atoi(str); + if (disk_size < 1 || disk_size > 2000) { + printf("Disk size needs to be between 1 and 2000 MB.\n"); + gtk_widget_destroy(GTK_WIDGET(assoc->req)); + delete assoc; + return; + } + int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR); + 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); + } + close(fd); gtk_widget_destroy(GTK_WIDGET(assoc->req)); delete assoc; } From e933e7885f3a8bfe50ca38586ced74669731a0e4 Mon Sep 17 00:00:00 2001 From: Ger Schinkel Date: Tue, 3 May 2022 08:08:36 +0200 Subject: [PATCH 3/3] Create files according to the process umask. --- BasiliskII/src/Unix/prefs_editor_gtk.cpp | 2 +- SheepShaver/src/Unix/prefs_editor_gtk.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BasiliskII/src/Unix/prefs_editor_gtk.cpp b/BasiliskII/src/Unix/prefs_editor_gtk.cpp index e9432629..a7a03db5 100644 --- a/BasiliskII/src/Unix/prefs_editor_gtk.cpp +++ b/BasiliskII/src/Unix/prefs_editor_gtk.cpp @@ -581,7 +581,7 @@ static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc) delete assoc; return; } - int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR); + 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 { diff --git a/SheepShaver/src/Unix/prefs_editor_gtk.cpp b/SheepShaver/src/Unix/prefs_editor_gtk.cpp index a26ba7de..a15337d3 100644 --- a/SheepShaver/src/Unix/prefs_editor_gtk.cpp +++ b/SheepShaver/src/Unix/prefs_editor_gtk.cpp @@ -510,7 +510,7 @@ static void create_volume_ok(GtkWidget *button, file_req_assoc *assoc) delete assoc; return; } - int fd = open(file, O_CREAT | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR); + 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 {