#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <gtk/gtk.h>
#include <libermanifest/ermanifest.h>
#include <liberregxml/erregapi.h>
#include "erConnect.h"
#include "system.h"
#include "gtkPincodeScreen.h"
#include "control.h"
#include "erMSDisk.h"
#include "contentListerLog.h"
Go to the source code of this file.
Functions | |
static int | erMSDiskDisconnectFlash (void) |
static int | erMSDiskReconnectFlash (void) |
static gboolean | is_device_mounted (const char *dev) |
expMemType_e | get_exported_memory_type (void) |
expMemType_e | get_memory_type_used (void) |
expMemType_e | read_exported_memory_type (void) |
void | erMSDiskInit () |
void | erStartMSDiskApp () |
void | erStopMSDiskApp () |
int | erMSDiskSetConnected (int connected) |
void | erMSDisk_storage_changed (st_ContentType_e storageType, gboolean storagePresent) |
void | erMSDisk_handle_reread_settings () |
Variables | |
static expMemType_e | g_export_memory_type = expMain |
static expMemType_e | g_memory_type_used = expUndefined |
static const char * | dev [expUndefined] |
void erMSDisk_handle_reread_settings | ( | ) |
Definition at line 334 of file erMSDisk.c.
00335 { 00336 // Re-read export settings from registry 00337 g_export_memory_type = read_exported_memory_type(); 00338 }
void erMSDisk_storage_changed | ( | st_ContentType_e | storageType, | |
gboolean | storagePresent | |||
) |
Definition at line 285 of file erMSDisk.c.
00286 { 00287 CL_LOGPRINTF("storageType = %d, storagePresent = %d", storageType, storagePresent); 00288 00289 // Convert st_ContentType_e to expMemType_e 00290 expMemType_e storage_type = expUndefined; 00291 switch (storageType) 00292 { 00293 case st_StorageTypeCF: 00294 storage_type = expCF; 00295 break; 00296 case st_StorageTypeSD: 00297 storage_type = expMMC; 00298 break; 00299 case st_StorageTypeUSB: 00300 storage_type = expUSB; 00301 break; 00302 default: 00303 break; 00304 } 00305 00306 if (getListerState() == STATE_USB_CONNECTED) 00307 { 00308 // Connected to PC 00309 if (storagePresent == FALSE) 00310 { 00311 // Card plug out event 00312 if (storage_type == g_memory_type_used) 00313 { 00314 // The memory type we are using is plugged out 00315 CL_WARNPRINTF("WARNING! Card is plugged out when connected to PC."); 00316 00317 // Stop msdisk application 00318 erStopMSDiskApp(); 00319 listerHideUSBScreen(); 00320 setListerState(STATE_NORMAL); 00321 } 00322 else 00323 { 00324 // Another type of memory is plugged out, don't care 00325 } 00326 } 00327 } 00328 else if (storage_type == g_export_memory_type) 00329 { 00330 erStartMSDiskApp(); 00331 } 00332 }
static int erMSDiskDisconnectFlash | ( | void | ) | [static] |
Definition at line 231 of file erMSDisk.c.
00232 { 00233 // stop background connect, if any 00234 ctrl_disconnect_wait(); 00235 00236 // unmount filesystem(s) exported over USB 00237 system("sync; sync; sync"); 00238 00239 char cmd[CMD_LEN]; 00240 snprintf(cmd, CMD_LEN, "umount %s", dev[g_memory_type_used]); 00241 00242 int ret = system(cmd); 00243 if (ret == 0) 00244 { 00245 return 0; 00246 } 00247 else 00248 { 00249 CL_ERRORPRINTF("Mount process returned error %d", ret); 00250 return -1; 00251 } 00252 }
void erMSDiskInit | ( | ) |
Definition at line 106 of file erMSDisk.c.
00107 { 00108 g_export_memory_type = read_exported_memory_type(); 00109 }
static int erMSDiskReconnectFlash | ( | void | ) | [static] |
Definition at line 254 of file erMSDisk.c.
00255 { 00256 int rc; 00257 int ret = -1; // return code: 0 = ok 00258 char cmd[CMD_LEN]; 00259 00260 // Determine mount command, 00261 // note that erStopMSDiskApp() sets g_memory_type_used to "not used" 00262 snprintf(cmd, CMD_LEN, "mount %s", dev[g_memory_type_used]); 00263 00264 // stop msdisk application, to free any locks on g_memory_type_used device 00265 erStopMSDiskApp(); 00266 00267 // mount the filesystem so iLiad can access it 00268 CL_WARNPRINTF("remounting memory, command [%s]", cmd); 00269 rc = system(cmd); 00270 if (rc == 0) 00271 { 00272 rc = 0; 00273 } 00274 else 00275 { 00276 CL_ERRORPRINTF("Mount process returned error %d", rc); 00277 } 00278 00279 // start msdisk application again 00280 erStartMSDiskApp(); 00281 00282 return ret; 00283 }
int erMSDiskSetConnected | ( | int | connected | ) |
Definition at line 181 of file erMSDisk.c.
00182 { 00183 CL_WARNPRINTF("connected = %d", connected); 00184 00185 if (connected == 1) 00186 { 00187 listerShowUSBScreen(); 00188 setListerState(STATE_USB_CONNECTED); 00189 00190 #ifdef ENABLE_CONFIG_EXPORT_IMPORT 00191 ctrl_export_config(); 00192 #endif 00193 00194 // For USB stick, if we umount USB memory before exporting it, it fails. 00195 // So just handle USB memory as an exeception, still don't know why. 00196 if (g_export_memory_type != expUSB) 00197 { 00198 erMSDiskDisconnectFlash(); 00199 } 00200 00201 return 0; 00202 } 00203 else if (connected == 0) 00204 { 00205 // Again, it can't work for USB stick... 00206 if (g_export_memory_type != expUSB) 00207 { 00208 erMSDiskReconnectFlash(); 00209 } 00210 00211 listerHideUSBScreen(); 00212 setListerState(STATE_NORMAL); 00213 00214 #ifdef ENABLE_CONFIG_EXPORT_IMPORT 00215 ctrl_handle_import_config(); 00216 #endif 00217 00218 mdsRecreateArchives(st_StorageTypeMain); 00219 mdsRecreateArchives(st_StorageTypeCF); 00220 mdsRecreateArchives(st_StorageTypeSD); 00221 mdsRecreateArchives(st_StorageTypeUSB); 00222 00223 return 0; 00224 } 00225 else 00226 { 00227 return -1; 00228 } 00229 }
void erStartMSDiskApp | ( | ) |
Definition at line 139 of file erMSDisk.c.
00140 { 00141 char cmd[CMD_LEN]; 00142 expMemType_e memory_type_new = expMain; // memory to be exported, default is internal memory 00143 00144 CL_WARNPRINTF("entry: g_export_memory_type [%d] g_memory_type_used [%d]", g_export_memory_type, g_memory_type_used); 00145 00146 // Use export type only when mounted 00147 if ( is_device_mounted(dev[g_export_memory_type]) ) 00148 { 00149 memory_type_new = g_export_memory_type; 00150 } 00151 00152 if (g_memory_type_used == memory_type_new) 00153 { 00154 ; // msdisk application already running on required memory type: do nothing 00155 } 00156 else 00157 { 00158 // Stop msdisk application if running 00159 if (g_memory_type_used != expUndefined) 00160 { 00161 erStopMSDiskApp(); 00162 } 00163 00164 // Start msdisk application 00165 g_memory_type_used = memory_type_new; 00166 snprintf(cmd, sizeof(cmd), "sync ; msdisk %s &", dev[g_memory_type_used]); 00167 CL_WARNPRINTF("-- starting msdisk [%s]", cmd); 00168 system(cmd); 00169 } 00170 }
void erStopMSDiskApp | ( | ) |
Definition at line 172 of file erMSDisk.c.
00173 { 00174 // TODO: The better solution is using fork/exec and then sending SIGTERM signal 00175 CL_WARNPRINTF("-- stopping msdisk"); 00176 system("killall msdisk; sync; sync;"); 00177 00178 g_memory_type_used = expUndefined; 00179 }
expMemType_e get_exported_memory_type | ( | void | ) |
expMemType_e get_memory_type_used | ( | void | ) | [inline] |
static gboolean is_device_mounted | ( | const char * | dev | ) | [static] |
Definition at line 112 of file erMSDisk.c.
00113 { 00114 FILE* fp = fopen(PROCFS_MOUNT_FILE, "r"); 00115 if (NULL == fp) 00116 { 00117 printf("Can NOT open %s\n", PROCFS_MOUNT_FILE); 00118 return -1; 00119 } 00120 00121 char buf[128]; 00122 int len = strlen(dev); 00123 gboolean bFound = FALSE; 00124 while (!feof(fp)) 00125 { 00126 fgets(buf, 128, fp); 00127 if (strncmp(buf, dev, len) == 0) 00128 { 00129 // Mount point found 00130 bFound = TRUE; 00131 break; 00132 } 00133 } 00134 00135 fclose(fp); 00136 return bFound; 00137 }
expMemType_e read_exported_memory_type | ( | void | ) |
Definition at line 64 of file erMSDisk.c.
00065 { 00066 regExportMemType_t* theExportMemType = NULL; 00067 expMemType_e theExpMemType = expMain; 00068 00069 // Get settings from registry 00070 theExportMemType = erRegGetExportMemType(); 00071 if (theExportMemType) 00072 { 00073 // Remember settings 00074 if (strcmp(theExportMemType->location, MAIN_CATEGORY) == 0) 00075 { 00076 theExpMemType = expMain; 00077 } 00078 else if (strcmp(theExportMemType->location, SD_CATEGORY) == 0) 00079 { 00080 theExpMemType = expMMC; 00081 } 00082 else if (strcmp(theExportMemType->location, USB_CATEGORY) == 0) 00083 { 00084 theExpMemType = expUSB; 00085 } 00086 else if (strcmp(theExportMemType->location, CF_CATEGORY) == 0) 00087 { 00088 theExpMemType = expCF; 00089 } 00090 else 00091 { 00092 CL_ERRORPRINTF("Invalid exporting memory type: %s", theExportMemType->location); 00093 } 00094 00095 erRegFreeExportMemType(theExportMemType); 00096 } 00097 else 00098 { 00099 CL_ERRORPRINTF("erRegGetExportMemType returns NULL"); 00100 } 00101 00102 CL_LOGPRINTF("leave, return [%d]", theExpMemType); 00103 return theExpMemType; 00104 }
const char* dev[expUndefined] [static] |
Initial value:
{ "/dev/tffsa6", "/dev/mmc1", "/dev/sda1", "/dev/hda1" }
Definition at line 46 of file erMSDisk.c.
expMemType_e g_export_memory_type = expMain [static] |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 39 of file erMSDisk.c.
expMemType_e g_memory_type_used = expUndefined [static] |
Definition at line 40 of file erMSDisk.c.