diff options
Diffstat (limited to 'flash.c')
-rw-r--r-- | flash.c | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -308,23 +308,26 @@ hdrlengthok: } -void remount_root_as_writeable () +void remount_root_as_writeable (gboolean start) { gchar *cmd; - cmd = g_strdup_printf ("/usr/bin/mount -o remount,rw %s /", globals.HWDetect.remount_point); - printf ("%s\n",cmd); - system(cmd); - g_free (cmd); -} + static GStaticMutex mutex = G_STATIC_MUTEX_INIT; + + if (start) { + g_static_mutex_lock (&mutex); + cmd = g_strdup_printf ("/usr/bin/mount -o remount,rw %s /", globals.HWDetect.remount_point); + } else { + cmd = g_strdup_printf ("/usr/bin/mount -o remount,ro %s /", globals.HWDetect.remount_point); + } -void remount_root_as_not_writeable () -{ - gchar *cmd; - cmd = g_strdup_printf ("/usr/bin/mount -o remount,ro %s /", globals.HWDetect.remount_point); printf ("%s\n",cmd); system(cmd); g_free (cmd); + + if (!start) { + g_static_mutex_unlock (&mutex); + } } @@ -350,12 +353,14 @@ static int readUserBlock(FlashStruct *mem) // if the backup was good overwrite the main file if (!globals.Sys.shutdown_started) { globals.Sys.flash_write_in_progress = TRUE; - remount_root_as_writeable (); + printf ("start writeable: copy from backup\n"); + remount_root_as_writeable (TRUE); persistence_copyfile(BACKUPFILE, MAINFILE); globals.Sys.flash_write_in_progress = FALSE; - remount_root_as_not_writeable (); + printf ("end writeable: copy from backup\n"); + remount_root_as_writeable (FALSE); } return sizeof(*mem); } @@ -384,17 +389,20 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes) if (!globals.Sys.shutdown_started) { globals.Sys.flash_write_in_progress = TRUE; - remount_root_as_writeable (); + printf ("start writeable: make backup\n"); + remount_root_as_writeable (TRUE); bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE); globals.Sys.flash_write_in_progress = FALSE; - remount_root_as_not_writeable (); + printf ("end writeable: make backup\n"); + remount_root_as_writeable (FALSE); if (backup_ok && !globals.Sys.shutdown_started) { globals.Sys.flash_write_in_progress = TRUE; - remount_root_as_writeable (); + printf ("start writeable: write to main config file\n"); + remount_root_as_writeable (TRUE); if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) { if (errno != PERSIST_ERR_COULDNTWRITE) { @@ -404,7 +412,8 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes) } } globals.Sys.flash_write_in_progress = FALSE; - remount_root_as_not_writeable (); + printf ("end writeable: write to main config file\n"); + remount_root_as_writeable (FALSE); } else { printf("Could not backup current file. **Write did not happen!!!**\n"); } |