Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
random532 authored Aug 8, 2020
1 parent ac1d417 commit 61edf8b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 139 deletions.
4 changes: 2 additions & 2 deletions applyButtonClicked.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ char *gpart_filesystem( char *cmd) {
strncat(cmd, "-C ", 4);
const gchar *glabel = gtk_entry_get_text(GTK_ENTRY (text_label)); /* label */
if( (strlen(glabel) != 0) && (strlen(glabel) <= 20 ) ) {
strncat(cmd, " -l ", 4);
strncat(cmd, " -L ", 4);
strcat(cmd, glabel);
strncat(cmd, " ", 1);
}
Expand All @@ -422,7 +422,7 @@ char *gpart_filesystem( char *cmd) {
}

free((void *) gpartition);
free((void *) gf); //XXX: ???
free((void *) gf);
return cmd;
}

Expand Down
146 changes: 22 additions & 124 deletions mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,41 @@ char *is_mounted(char *part) {

char *is_mounted_fuse(char *partition) {

/*
* This is surely not how things should
* be done.
*/


/*
* Just check whether there is at least one fuse mount.
* If so, return "--", else return NULL.
*/

char buf[150];
int bufsize = 150;
char *empty;
char cmd[]= "mount | awk '/fuse/{print $3}'";
int len=0;
int result = 0;
char *mountpoint = NULL;

char *mountpoint;
int len;

if (partition == NULL)
return NULL;

if(!root() && pw_needed() == 1) {
printf("Note: fuse mountpoints unknown. Need higher privileges for that.\n");
char *empty = malloc(10);
strcpy(empty, "--");
return empty;
}

memset(buf, 0, bufsize);
memset(buf, 0, sizeof buf);
mountpoint = NULL;
len = 0;

/* iterate through all mounted fuse file systems */

FILE *fp = popen(cmd, "r");
if (fp == NULL) {
msg("fopen failed");
return NULL;
}
while( fgets(buf, sizeof buf, fp)) {

len = strlen(buf);
if(len == 0)
break;
buf[len-1] = '\0';

/* compare the volume information with device */
result = volume_cmp(partition, buf);

if(result == 0) {
mountpoint = malloc(len +1);
strncpy(mountpoint, buf, len);
}
else if(result == -1) {
/* abort */
mountpoint = malloc(10);
strcpy(mountpoint, "--");
break;
}
}

fgets(buf, sizeof buf, fp);
pclose(fp);
return mountpoint;

if(strncmp(buf, "/", 1) == 0) {
mountpoint = malloc(10);
strcpy(mountpoint, "--");
return mountpoint;
}
else
return NULL;
}

void mountfs(GtkMenuItem *gmenu, gpointer gp) {
Expand Down Expand Up @@ -302,85 +282,3 @@ int vfs_usermount() {
pclose(fp);
return usermnt;
}

int volume_cmp(char *partition, char *mpoint) {

/*
* Compare Volume information of the mountpoint
* with the information of the device.
* If they match, they are identical.
*/

char *filename;
char *tmpfile1;
char *tmpfile2;
char cmd[CMDSIZE];

int mlen;
int match=1;

if(mpoint == NULL || partition == NULL)
return -1;


/* first read the info from mountpoint */
mlen = strlen(mpoint);
filename = malloc(50+mlen);
if(filename == NULL)
return -1;

/* Check for a volume information file. */
sprintf(filename, "%s/System Volume Information/IndexerVolumeGuid", mpoint);
if(access(filename, R_OK) != 0) {
printf("volume_cmp():fuse:%s: %s\n", filename, strerror(errno));
free(filename);
return -1;
}

free(filename);

/* Write both volume informations to tmp files */
tmpfile1 = random_filename();
tmpfile2 = random_filename();
if(tmpfile1 == NULL || tmpfile2 == NULL) {
printf("volume_cmp(): error in tmp files.\n");
free(filename);
return -1;
}

while(strcmp(tmpfile1, tmpfile2) == 0) {
printf("volume_cmp(): Unlucky. Trying again.\n");
free(tmpfile2);
tmpfile2 = random_filename();
}

snprintf(cmd, CMDSIZE, "sudo -S cat %s/System\\ Volume\\ Information/IndexerVolumeGuid >/tmp/%s", mpoint, tmpfile1);
if(execute_cmd(cmd, 0) != 0) {
printf("No System Volume Information on: %s -- Aborting.\n", mpoint);
free(filename);
return -1;
}

/* second read device */
snprintf(cmd, CMDSIZE, "sudo -S ntfscat -fq /dev/%s System\\ Volume\\ Information/IndexerVolumeGuid | tail -n 1 >/tmp/%s ", partition, tmpfile2);
if(execute_cmd(cmd, 0) != 0) {
printf("No System Volume Information on device: /dev/%s -- Aborting.\n", partition);
free(filename);
return -1;
}

snprintf(cmd, CMDSIZE-1, "diff /tmp/%s /tmp/%s", tmpfile1, tmpfile2);
if(execute_cmd(cmd, 0) == 0)
match = 0;
//else
// printf("/dev/%s is not mounted on: %s\n", partition, mpoint);

snprintf(cmd, CMDSIZE-1, "sudo -S rm /tmp/%s /tmp/%s", tmpfile1, tmpfile2);
if(execute_cmd(cmd, 0) != 0)
printf("vol_cmp(): Cannot remove temporary files:/tmp%s, /tmp/%s\n", tmpfile1, tmpfile2);

free(tmpfile1);
free(tmpfile2);

return match;
}
28 changes: 15 additions & 13 deletions treeviews.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,9 @@ g.fslabel = NULL;
g.fslabel = get_label(g.name_capital, g.filesystem);

/* mountpoint */
if(strncmp(g.type, "ntfs", 4) == 0 || strncmp(g.type, "exfat", 5) == 0)
if(strncmp(g.type, "ntfs", 4) == 0 || strncmp(g.type, "exfat", 5) == 0) {
g.mountpoint = is_mounted_fuse(g.name_capital);
}
else
g.mountpoint = is_mounted(g.name_capital);

Expand Down Expand Up @@ -758,13 +759,12 @@ gboolean right_clicked(GtkWidget *btn, GdkEventButton *event, gpointer userdata)
if( (event->type != GDK_BUTTON_PRESS) || (event->button != 3) )
return FALSE;

/* Where did he click? */
/* find and select the row that was clicked */

GtkTreePath *path;
GtkTreeViewColumn *column;
if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree1), event->x, event->y, &path, &column, NULL, NULL))
return FALSE;

/* find and select the row that was clicked */
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree1));
gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_path(selection, path);
Expand All @@ -777,17 +777,21 @@ gboolean right_clicked(GtkWidget *btn, GdkEventButton *event, gpointer userdata)
return TRUE;
if(part == NULL)
return TRUE;

todo = MOUNT;
GtkWidget *pop_menu = gtk_menu_new();

if(strncmp(fs, "ntfs", 4) == 0 || strncmp(fs, "exfat", 5) == 0)
mountpoint = is_mounted_fuse(part);
/* fuse is difficult to mount */
if(strncmp(fs, "ntfs", 4) == 0 || strncmp(fs, "exfat", 5) == 0) {
printf("mount/unmount of fuse based file systems is not supported.\n");
return TRUE;
}
else
mountpoint = is_mounted(part);

if (mountpoint != NULL) { /* "unmount" */

/* Create the popup menu */
todo = MOUNT;
GtkWidget *pop_menu = gtk_menu_new();

if (mountpoint != NULL) {

free(mountpoint);
unmount = gtk_menu_item_new_with_label ("unmount");
gtk_menu_shell_append (GTK_MENU_SHELL (pop_menu), unmount);
Expand All @@ -796,8 +800,6 @@ gboolean right_clicked(GtkWidget *btn, GdkEventButton *event, gpointer userdata)

else if (mountpoint == NULL) {

/* XXX: NULL could be an error too! */

if(strncmp(fs, "n/a", 3) == 0) {
/* "show file system" */
rescan = gtk_menu_item_new_with_label(l.mrescan);
Expand Down

0 comments on commit 61edf8b

Please sign in to comment.