Navigation Menu

Skip to content

Commit

Permalink
[usb-moded] Know how to deal with symlinks for working SD card mass-s…
Browse files Browse the repository at this point in the history
…torage support

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Jan 14, 2014
1 parent 8bf0490 commit 0387645
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/usb_moded-modesetting.c
Expand Up @@ -26,6 +26,7 @@
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <limits.h>

#include <glib.h>

Expand Down Expand Up @@ -108,11 +109,10 @@ int write_to_file(const char *path, const char *text)
return err;
}


static int set_mass_storage_mode(struct mode_list_elem *data)
{
gchar *command;
char command2[256];
char command2[256], *real_path = NULL, *mountpath;
const char *mount;
gchar **mounts;
int ret = 0, i = 0, mountpoints = 0, fua = 0, try = 0;
Expand Down Expand Up @@ -150,13 +150,18 @@ static int set_mass_storage_mode(struct mode_list_elem *data)
for(i=0 ; mounts[i] != NULL; i++)
{
/* check if filesystem is mounted or not, if ret = 1 it is already unmounted */
umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
real_path = realpath(mounts[i], NULL);
if(real_path)
mountpath = real_path;
else
mountpath = mounts[i];
umount: command = g_strconcat("mount | grep ", mountpath, NULL);
ret = system(command);
g_free(command);
if(!ret)
{
/* no check for / needed as that will fail to umount anyway */
command = g_strconcat("umount ", mounts[i], NULL);
command = g_strconcat("umount ", mountpath, NULL);
log_debug("unmount command = %s\n", command);
ret = system(command);
g_free(command);
Expand Down Expand Up @@ -214,6 +219,8 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
}
g_strfreev(mounts);
g_free((gpointer *)mount);
if(real_path)
free(real_path);
}

/* only send data in use signal in case we actually succeed */
Expand All @@ -227,7 +234,7 @@ umount: command = g_strconcat("mount | grep ", mounts[i], NULL);
static int unset_mass_storage_mode(struct mode_list_elem *data)
{
gchar *command;
char command2[256];
char command2[256], *real_path = NULL, *mountpath;
const char *mount;
gchar **mounts;
int ret = 1, i = 0;
Expand All @@ -239,12 +246,17 @@ static int unset_mass_storage_mode(struct mode_list_elem *data)
for(i=0 ; mounts[i] != NULL; i++)
{
/* check if it is still or already mounted, if so (ret==0) skip mounting */
command = g_strconcat("mount | grep ", mounts[i], NULL);
real_path = realpath(mounts[i], NULL);
if(real_path)
mountpath = real_path;
else
mountpath = mounts[i];
command = g_strconcat("mount | grep ", mountpath, NULL);
ret = system(command);
g_free(command);
if(ret)
{
command = g_strconcat("mount ", mounts[i], NULL);
command = g_strconcat("mount ", mountpath, NULL);
log_debug("mount command = %s\n",command);
ret = system(command);
g_free(command);
Expand Down Expand Up @@ -285,6 +297,8 @@ static int unset_mass_storage_mode(struct mode_list_elem *data)
}
g_strfreev(mounts);
g_free((gpointer *)mount);
if(real_path)
free(real_path);
}

return(ret);
Expand Down

0 comments on commit 0387645

Please sign in to comment.