diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2014-09-16 20:26:13 +0200 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2014-09-16 20:26:13 +0200 |
commit | 8b0ef106f21c589c216ad30279fb2b958a54c7a0 (patch) | |
tree | 0dadb3bf3ea8a183f67de5a2a904666633a10f96 | |
parent | 05112fb523f465f083a07904008ef7d452b2fac6 (diff) | |
download | persistence-client-library-8b0ef106f21c589c216ad30279fb2b958a54c7a0.tar.gz |
-rw-r--r-- | configure.ac | 36 | ||||
-rw-r--r-- | include/persistence_client_library.h | 2 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/persistence_client_library.c | 33 | ||||
-rw-r--r-- | test/persistence_pfs_test.c | 1041 |
5 files changed, 588 insertions, 528 deletions
diff --git a/configure.ac b/configure.ac index 04ec679..2e40aec 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ # create tag version information m4_define([pers_client_library_tag_version_major], [0]) -m4_define([pers_client_library_tag_version_minor], [9]) +m4_define([pers_client_library_tag_version_minor], [10]) m4_define([pers_client_library_tag_version_micro], [0]) m4_define([pers_client_library_tag_version], [pers_client_library_tag_version_major().pers_client_library_tag_version_minor().pers_client_library_tag_version_micro()]) @@ -17,9 +17,9 @@ AC_GNU_SOURCE() # create library version information -m4_define([pers_client_library_version_current], [7]) -m4_define([pers_client_library_version_revision], [1]) -m4_define([pers_client_library_version_age], [0]) +m4_define([pers_client_library_version_current], [8]) +m4_define([pers_client_library_version_revision], [0]) +m4_define([pers_client_library_version_age], [1]) m4_define([pers_client_library_version], [pers_client_library_version_current():pers_client_library_version_revision():pers_client_library_version_age()]) PERS_CLIENT_LIBRARY_VERSION=pers_client_library_version() @@ -30,7 +30,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # Overwrite the build in defaults -#CFLAGS="-Wall -O2" +CFLAGS="-Wall -O2" # Checks for programs. AC_PROG_CC @@ -91,7 +91,7 @@ if test "x$enable_tests" != "xno" ; then AC_DEFINE_UNQUOTED([TESTS_ENABLED], [1], [tests enabled]) else - AC_DEFINE_UNQUOTED([TESTS_ENABLED], [0], [tests enabled]) + AC_DEFINE_UNQUOTED([TESTS_ENABLED], [0], [tests disabled]) fi AC_MSG_NOTICE([Tests enabled: $enable_tests]) AC_MSG_NOTICE([Local check enabled: $localcheck]) @@ -116,6 +116,7 @@ else fi ###################################################################### + # enable persistence file cache component ########### AC_ARG_ENABLE([filecache], [AS_HELP_STRING([--enable-filecache],[Enable file cache component])], @@ -139,6 +140,29 @@ fi ###################################################################### +# enable tracing ########### +#AC_ARG_ENABLE([xstrace], +# [AS_HELP_STRING([--enable-xstrace],[Enable xstrace])], +# [use_xstrace=$enableval], +# [use_xstrace="no"]) +# +#AM_CONDITIONAL([USE_XSTRACE_PERS], [test x"$use_xstrace" = "no"]) +# +#if test "$use_xstrace" != "yes" -a "$use_xstrace" != "no"; then +# AC_MSG_ERROR([Invalid tracing check mode specified: $use_xstrace. Only "yes" or "no" is valid]) +#else +# AC_MSG_NOTICE([Use tracing: $use_xstrace]) + +# if test "$use_xstrace" = "yes"; then +# AC_CHECK_HEADERS([xsm_user.h]) +# AC_DEFINE_UNQUOTED([USE_XSTRACE_PERS], [1], [tracing enabled]) +# else +# AC_DEFINE_UNQUOTED([USE_XSTRACE_PERS], [0], [tracing disabled]) +# fi +#fi +###################################################################### + + AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable debugging, default: no]), diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h index 21615b1..1d42cbc 100644 --- a/include/persistence_client_library.h +++ b/include/persistence_client_library.h @@ -162,7 +162,7 @@ extern "C" { * @attention This function is currently N O T part of the GENIVI compliance specification * * @param appname application name, the name must be a unique name in the system - * @param shutdownMode shutdown mode ::PCL_SHUTDOWN_TYPE_FAST or ::PCL_SHUTDOWN_TYPE_NORMAL + * @param shutdownMode shutdown mode ::PCL_SHUTDOWN_TYPE_FAST or ::PCL_SHUTDOWN_TYPE_NORMAL ::PCL_SHUTDOWN_TYPE_NONE * * @return positive value: success; * On error a negative value will be returned with the following error codes: diff --git a/src/Makefile.am b/src/Makefile.am index 26248f0..dd52eb1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,10 @@ lib_LTLIBRARIES = libpersistence_client_library.la libpersistence_client_library_la_LIBADD = $(DEPS_LIBS) $(PFC_LIBS) -ldl -lpers_common +#if USE_XSTRACE_PERS +#libpersistence_client_library_la_LIBADD += -lxsm_user +#endif + libpersistence_client_library_la_SOURCES = \ persistence_client_library.c \ persistence_client_library_key.c \ diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 2ee3f23..2b57062 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -32,12 +32,19 @@ #include <persistence_file_cache.h> #endif +#if USE_XSTRACE_PERS + #include <xsm_user.h> +#endif + #include <string.h> #include <errno.h> #include <stdlib.h> #include <dlfcn.h> #include <dbus/dbus.h> + + + /// debug log and trace (DLT) setup DLT_DECLARE_CONTEXT(gPclDLTContext); @@ -60,6 +67,10 @@ int pclInitLibrary(const char* appName, int shutdownMode) { int rval = 1; +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif + if(gPclInitialized == PCLnotInitialized) { gShutdownMode = shutdownMode; @@ -92,12 +103,18 @@ int pclInitLibrary(const char* appName, int shutdownMode) DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary - failed to access blacklist:"), DLT_STRING(blacklistPath)); } +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif if(setup_dbus_mainloop() == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - Failed to setup main loop")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_DBUS_MAINLOOP; } +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) @@ -110,7 +127,7 @@ int pclInitLibrary(const char* appName, int shutdownMode) return EPERS_REGISTER_LIFECYCLE; } } -#if USE_PASINTERFACE == 1 +#if USE_PASINTERFACE DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); if(register_pers_admin_service() == -1) { @@ -150,6 +167,10 @@ int pclInitLibrary(const char* appName, int shutdownMode) DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitialized) ); } +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif + return rval; } @@ -159,6 +180,10 @@ int pclDeinitLibrary(void) { int i = 0, rval = 1; +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif + if(gPclInitialized == PCLinitialized) { int* retval; @@ -230,6 +255,12 @@ int pclDeinitLibrary(void) DLT_STRING("- NOT INITIALIZED: ")); rval = EPERS_NOT_INITIALIZED; } + + +#if USE_XSTRACE_PERS + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); +#endif + return rval; } diff --git a/test/persistence_pfs_test.c b/test/persistence_pfs_test.c index 52a0388..d055968 100644 --- a/test/persistence_pfs_test.c +++ b/test/persistence_pfs_test.c @@ -56,86 +56,85 @@ DLT_DECLARE_CONTEXT(gPFSDLTContext); +static const char* gOrigPostfix = "ORIG"; +static const char* gBackupPostfix = "BACK"; static int gLifecycleCounter = 0; static const char* gTestInProgressFlag = "/Data/mnt-c/persistence_pfst_test_in_progress"; -static const char* gOrigPostfix = "ORIG"; -static const char* gBackupPostfix = "BACK"; - static const char* gDefaultKeyValueResName[] = { - "keyValue_Resource_00", - "keyValue_Resource_01", - "keyValue_Resource_02", - "keyValue_Resource_03", - "keyValue_Resource_04", - "keyValue_Resource_05", - "keyValue_Resource_06", - "keyValue_Resource_07", - "keyValue_Resource_08", - "keyValue_Resource_09", - "keyValue_Resource_10", - "keyValue_Resource_11", - "keyValue_Resource_12", - "keyValue_Resource_13", - "keyValue_Resource_14", - "keyValue_Resource_15", - "keyValue_Resource_16", - "keyValue_Resource_17", - "keyValue_Resource_18", - "keyValue_Resource_19", + "keyValue_Resource_00", + "keyValue_Resource_01", + "keyValue_Resource_02", + "keyValue_Resource_03", + "keyValue_Resource_04", + "keyValue_Resource_05", + "keyValue_Resource_06", + "keyValue_Resource_07", + "keyValue_Resource_08", + "keyValue_Resource_09", + "keyValue_Resource_10", + "keyValue_Resource_11", + "keyValue_Resource_12", + "keyValue_Resource_13", + "keyValue_Resource_14", + "keyValue_Resource_15", + "keyValue_Resource_16", + "keyValue_Resource_17", + "keyValue_Resource_18", + "keyValue_Resource_19", }; static const char* gDefaultKeyValueTestData[] = { - "keyValue pair cache Zero - %s : 000000 000000", - "keyValue pair cache One - %s : 000000 000000", - "keyValue pair cache Two - %s : 000000 000000", - "keyValue pair cache Three - %s : 000000 000000", - "keyValue pair cache Four - %s : 000000 000000", - "keyValue pair cache Five - %s : 000000 000000", - "keyValue pair wt Six - %s : 000000 000000", - "keyValue pair wt Seven - %s : 000000 000000", - "keyValue pair wt eight - %s : 000000 000000", - "keyValue pair wt nine - %s : 000000 000000", - "keyValue pair wt ten - %s : 000000 000000", - "keyValue pair cache eleven - %s : 000000 000000", - "keyValue pair cache twelve - %s : 000000 000000", - "keyValue pair cache thirteen - %s : 000000 000000", - "keyValue pair cache fourteen - %s : 000000 000000", - "keyValue pair cache fifteen - %s : 000000 000000", - "keyValue pair wt sixteen - %s : 000000 000000", - "keyValue pair wt Seventeen - %s : 000000 000000", - "keyValue pair wt eighteen - %s : 000000 000000", - "keyValue pair wt nineteen - %s : 000000 000000", + "keyValue pair cache Zero - %s : 000000 000000", + "keyValue pair cache One - %s : 000000 000000", + "keyValue pair cache Two - %s : 000000 000000", + "keyValue pair cache Three - %s : 000000 000000", + "keyValue pair cache Four - %s : 000000 000000", + "keyValue pair cache Five - %s : 000000 000000", + "keyValue pair wt Six - %s : 000000 000000", + "keyValue pair wt Seven - %s : 000000 000000", + "keyValue pair wt eight - %s : 000000 000000", + "keyValue pair wt nine - %s : 000000 000000", + "keyValue pair wt ten - %s : 000000 000000", + "keyValue pair cache eleven - %s : 000000 000000", + "keyValue pair cache twelve - %s : 000000 000000", + "keyValue pair cache thirteen - %s : 000000 000000", + "keyValue pair cache fourteen - %s : 000000 000000", + "keyValue pair cache fifteen - %s : 000000 000000", + "keyValue pair wt sixteen - %s : 000000 000000", + "keyValue pair wt Seventeen - %s : 000000 000000", + "keyValue pair wt eighteen - %s : 000000 000000", + "keyValue pair wt nineteen - %s : 000000 000000", }; static const char* gDefaultFileAPITestData[] = { - "file API cache One : 000000 000000", - "file API cache Two : 000000 000000", - "file API cache Three : 000000 000000", - "file API cache Four : 000000 000000", - "file API wt One : 000000 000000", - "file API wt Two : 000000 000000", - "file API wt Three : 000000 000000", - "file API wt Four : 000000 000000" + "file API cache One : 000000 000000", + "file API cache Two : 000000 000000", + "file API cache Three : 000000 000000", + "file API cache Four : 000000 000000", + "file API wt One : 000000 000000", + "file API wt Two : 000000 000000", + "file API wt Three : 000000 000000", + "file API wt Four : 000000 000000" }; static const char* gDefaultFileResNames[] = { - "file API_Resource_01", - "file API_Resource_02", - "file API_Resource_03", - "file API_Resource_04", - "file API_Resource_05", - "file API_Resource_06", - "file API_Resource_07", - "file API_Resource_08" + "file API_Resource_01", + "file API_Resource_02", + "file API_Resource_03", + "file API_Resource_04", + "file API_Resource_05", + "file API_Resource_06", + "file API_Resource_07", + "file API_Resource_08" }; @@ -161,118 +160,107 @@ void unmount_persistence(); /// setup initial test data -int setup_test_data() +int setup_test_data(const char* postfix) { - int i = 0, ret = 0; - char databuffer[64] = {0}; - - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - - // key/value data - for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) - { - memset(databuffer, 0, 64); - snprintf(databuffer, 64, gDefaultKeyValueTestData[i], gBackupPostfix); - //printf(" setup_test_data - [%.2d] => %s\n", i, databuffer); - ret = pclKeyWriteData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)databuffer, strlen(databuffer)); - if(ret < 0) - { - printf("setup_test_data => failed to write data: %d\n", ret ); - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); - } - - memset(databuffer, 0, 64); - snprintf(databuffer, 64, gDefaultKeyValueTestData[i], gOrigPostfix); - printf(" setup_test_data - [%.2d] => %s\n", i, databuffer); - ret = pclKeyWriteData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)databuffer, strlen(databuffer)); - if(ret < 0) - { - printf("setup_test_data => failed to write data: %d\n", ret ); - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); - } - } + int i = 0, ret = 0; + char databuffer[64] = {0}; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + + pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library + + // key/value data + for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) + { + memset(databuffer, 0, 64); + snprintf(databuffer, 64, gDefaultKeyValueTestData[i], postfix); + printf(" setup_test_data - [%.2d] => %s\n", i, databuffer); + ret = pclKeyWriteData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)databuffer, strlen(databuffer)); + if(ret < 0) + { + printf("setup_test_data => failed to write data: %d\n", ret ); + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); + } + } #if 0 - // file data - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - printf(" file - data[%d] => %s\n", i, gDefaultFileAPITestData[i]); - } + // file data + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + printf(" file - data[%d] => %s\n", i, gDefaultFileAPITestData[i]); + } #endif - pclDeinitLibrary(); // unregister from persistence client library - sync(); - return 1; + pclDeinitLibrary(); // unregister from persistence client library + sync(); + return 1; } void verify_test_setup() { - int i = 0, ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + int i = 0, ret = 0; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - char buffer[64] = {0}; + char buffer[64] = {0}; - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library + pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) - { - ret = pclKeyReadData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); - if(ret < 0) - { - printf("verify_test_setup - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); - } + for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) + { + ret = pclKeyReadData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); + if(ret < 0) + { + printf("verify_test_setup - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); + } - //printf("verify_test_setup: [%.2d] => %s\n", i, buffer); + printf("verify_test_setup: [%.2d] => %s\n", i, buffer); - memset(buffer, 0, 64); - } + memset(buffer, 0, 64); + } - pclDeinitLibrary(); // unregister from persistence client library + pclDeinitLibrary(); // unregister from persistence client library } int setup_serial_con(const char* ttyConsole) { - struct termios tty; - int rval = -1; - - memset (&tty, 0, sizeof(tty)); - tty.c_iflag = IGNPAR; - tty.c_oflag = 0; - tty.c_cflag = CS8 | CREAD | CLOCAL; // 8n1, see termios.h for more information - tty.c_lflag = 0; - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 5; - - printf("Opening connection to %s\n", ttyConsole); - rval = open(ttyConsole, O_RDWR | O_NOCTTY | O_SYNC); - if(rval != -1) - { - if (cfsetospeed (&tty, B115200) == -1) // 115200 baud - { - printf("Failed to set cfsetospeed\n"); - } - if(cfsetispeed (&tty, B115200)) // 115200 baud - { - printf("Failed to set cfsetispeed\n"); - } - - tcsetattr(rval, TCSANOW, &tty); - - printf("tty fd: %d\n", rval); - } - else - { - printf("Failed to open console: %s - %s\n", ttyConsole, strerror(errno)); - } - - return rval; + struct termios tty; + int rval = -1; + + memset (&tty, 0, sizeof(tty)); + tty.c_iflag = IGNPAR; + tty.c_oflag = 0; + tty.c_cflag = CS8 | CREAD | CLOCAL; // 8n1, see termios.h for more information + tty.c_lflag = 0; + tty.c_cc[VMIN] = 1; + tty.c_cc[VTIME] = 5; + + printf("Opening connection to %s\n", ttyConsole); + rval = open(ttyConsole, O_RDWR | O_NOCTTY | O_SYNC); + if(rval != -1) + { + if (cfsetospeed (&tty, B115200) == -1) // 115200 baud + { + printf("Failed to set cfsetospeed\n"); + } + if(cfsetispeed (&tty, B115200)) // 115200 baud + { + printf("Failed to set cfsetispeed\n"); + } + + tcsetattr(rval, TCSANOW, &tty); + + printf("tty fd: %d\n", rval); + } + else + { + printf("Failed to open console: %s - %s\n", ttyConsole, strerror(errno)); + } + + return rval; } @@ -280,20 +268,20 @@ int setup_serial_con(const char* ttyConsole) /// after this function has been called the system reboots void send_serial_shutdown_cmd(int fd) { - // command for the computer controller power supply to power off and restart after 2.5 second again - static const char data[] = { "USET 12.000; ISET 10.000; OUTPUT OFF; WAIT 0.500; OUTPUT ON\n" }; - - if(write(fd, data, sizeof(data)) != -1) - { - fdatasync(fd); - printf("Data: %s\n", data); - } - else - { - printf("Failed to write to tty - size: %d - error: %s\n", sizeof(data), strerror(errno)); - } - - close(fd); + // command for the computer controller power supply to power off and restart after 2.5 second again + static const char data[] = { "USET 12.000; ISET 10.000; OUTPUT OFF; WAIT 0.500; OUTPUT ON\n" }; + + if(write(fd, data, sizeof(data)) != -1) + { + fdatasync(fd); + printf("Data: %s\n", data); + } + else + { + printf("Failed to write to tty - size: %d - error: %s\n", sizeof(data), strerror(errno)); + } + + close(fd); } @@ -304,53 +292,53 @@ int update_test_progress_flag(const char* filename, int *counter) if(access(filename, F_OK) == 0) { - fd = open(filename, O_RDWR); // file exists, update content - if(fd != -1) - { - int size = 0; - char buffer[12] = {0}; - if((size = read(fd, buffer, 12)) != -1) - { - rval = atoi(buffer); - *counter = rval; - snprintf(buffer, 3, "%d", *counter + 1); - - lseek(fd, 0, SEEK_SET); - if((size = write(fd, buffer, strlen(buffer))) == -1) - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - } - } - else - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - rval = -1; - } - } - else - { - rval = -1; - } + fd = open(filename, O_RDWR); // file exists, update content + if(fd != -1) + { + int size = 0; + char buffer[12] = {0}; + if((size = read(fd, buffer, 12)) != -1) + { + rval = atoi(buffer); + *counter = rval; + snprintf(buffer, 12, "%d", *counter + 1); + + lseek(fd, 0, SEEK_SET); + if((size = write(fd, buffer, strlen(buffer))) == -1) + { + printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); + } + } + else + { + printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); + rval = -1; + } + } + else + { + rval = -1; + } } else { - fd = open(filename, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(fd != -1) - { - int size = 0; - char buffer[3] = {0}; - snprintf(buffer, 3, "%d", 1); - if((size = write(fd, buffer, strlen(buffer))) == -1) - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - rval = -1; - } - *counter = 1; - } - else - { - rval = -1; - } + fd = open(filename, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); + if(fd != -1) + { + int size = 0; + char buffer[12] = {0}; + snprintf(buffer, 12, "%d", 1); + if((size = write(fd, buffer, strlen(buffer))) == -1) + { + printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); + rval = -1; + } + *counter = 1; + } + else + { + rval = -1; + } } syncfs(fd); close(fd); @@ -361,61 +349,69 @@ int update_test_progress_flag(const char* filename, int *counter) void update_test_data(char* buffer, int lc_counter, int write_counter) { - int i = 0; - char lc_cnt_buff[7] = {0}; - char wr_cnt_buff[7] = {0}; - - snprintf(lc_cnt_buff, 7, "%.6d", lc_counter); - snprintf(wr_cnt_buff, 7, "%.6d", write_counter); - - for(i=0; i<6; i++) - { - buffer[LC_CNT_START+i] = lc_cnt_buff[i]; - buffer[WR_CNT_START+i] = wr_cnt_buff[i]; - } + int i = 0; + char lc_cnt_buff[7] = {0}; + char wr_cnt_buff[7] = {0}; + + snprintf(lc_cnt_buff, 7, "%.6d", lc_counter); + snprintf(wr_cnt_buff, 7, "%.6d", write_counter); + + for(i=0; i<6; i++) + { + buffer[LC_CNT_START+i] = lc_cnt_buff[i]; + buffer[WR_CNT_START+i] = wr_cnt_buff[i]; + } } void* power_supply_shutdown(void* dataPtr) { - int fd = (int)(dataPtr); - printf("Shutdown thread started fd: %d\n", fd); + int fd = (int)(dataPtr); + int secs = 100000; + printf("Shutdown thread started fd: %d\n", fd); pthread_cond_wait(&gPowerDownMtxCond, &gPowerDownMtx); pthread_mutex_unlock(&gPowerDownMtx); - printf(" Send power Off command!!!!\n"); - send_serial_shutdown_cmd(fd); - printf(" Cut Power OFF => ByBy\n"); +# if 1 + printf(" Send pwrOff command!\n"); +#else + printf(" Send pwrOff command but sleep first: %d !!!!\n", secs); + usleep(secs); + printf(" ==> no more sleeping!!!!\n"); +#endif + send_serial_shutdown_cmd(fd); + printf(" Cut pwr OFF => ByBy\n"); - return NULL; + return NULL; } int get_lifecycle_count(char* buf) { - return atoi(&buf[LC_CNT_START]); + return atoi(&buf[LC_CNT_START]); } int get_write_count(char* buf) { - return atoi(&buf[WR_CNT_START]); + return atoi(&buf[WR_CNT_START]); } int main(int argc, char *argv[]) { - int rVal = EXIT_SUCCESS; - int ttyfd = -1; - char ttydevice[24] = {0}; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - pthread_t gMainLoopThread; - struct sched_param param; - pthread_attr_t tattr; - - printf("------------------\n"); - printf("P F S - Test start\n"); - printf("------------------\n"); + int rVal = EXIT_SUCCESS; + int ttyfd = -1; + int* retval; + char ttydevice[24] = {0}; + unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; + pthread_t powerShutdownThread; + struct sched_param param; + pthread_attr_t tattr; + + printf("------------------\n"); + printf("P F S - Test start\n"); + printf("------------------\n"); /// debug log and trace (DLT) setup //DLT_REGISTER_APP("PFS","power fail safe test"); @@ -427,7 +423,7 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } - pthread_mutex_lock(&gPowerDownMtx); // lock power down mutex and release when powser should be cut off + pthread_mutex_lock(&gPowerDownMtx); // lock power down mutex and release when powser should be cut off // default serial console @@ -435,230 +431,235 @@ int main(int argc, char *argv[]) #if 0 // mount persistence partitions - if(-1 != mount_persistence("/dev/sdb") ) - { + if(-1 != mount_persistence("/dev/sdb") ) + { #endif - int numLoops = 1000000, opt = 0; - - while ((opt = getopt(argc, argv, "l:s:")) != -1) - { - switch (opt) - { - case 'l': - numLoops = atoi(optarg); - break; - case 's': - memset(ttydevice, 0, 24); - strncpy(ttydevice, optarg, 24); - break; - } - } - - // setup the serial connection to the power supply - ttyfd = setup_serial_con(ttydevice); - if(ttyfd == -1) + int numLoops = 1000000, opt = 0; + + while ((opt = getopt(argc, argv, "l:s:")) != -1) + { + switch (opt) + { + case 'l': + numLoops = atoi(optarg); + break; + case 's': + memset(ttydevice, 0, 24); + strncpy(ttydevice, optarg, 24); + break; + } + } + + // setup the serial connection to the power supply + ttyfd = setup_serial_con(ttydevice); + if(ttyfd == -1) { printf("Failed to setup serial console: \"%s\"\n", ttydevice); return EXIT_SUCCESS; } - if(update_test_progress_flag(gTestInProgressFlag, &gLifecycleCounter) == 0) - { - printf("PFS test - first lifecycle, setup test data\n"); - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - first lifecycle, setup test data")); - - printf("--- setup data --- \n"); - setup_test_data(); + if(update_test_progress_flag(gTestInProgressFlag, &gLifecycleCounter) == 0) + { + printf("PFS test - first lifecycle, setup test data\n"); + //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - first lifecycle, setup test data")); - printf("--- verify data setup --- \n"); - verify_test_setup(); - } + printf("--- setup data --- \n"); + setup_test_data(gBackupPostfix); + setup_test_data(gOrigPostfix); - printf("PFS test - Lifecycle counter: %d - number of test loops: %d\n", gLifecycleCounter, numLoops); - /* - DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - Lifecycle counter:"), DLT_INT(gLifecycleCounter), - DLT_STRING("- number of write loops:"), DLT_INT(numLoops)); - */ - pthread_attr_init(&tattr); - param.sched_priority = 49; - pthread_attr_setschedparam(&tattr, ¶m); + printf("--- verify data setup --- \n"); + verify_test_setup(); + } - // create here the dbus connection and pass to main loop - if(pthread_create(&gMainLoopThread, &tattr, power_supply_shutdown, (void*)ttyfd) == -1) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop )") ); - return -1; - } + printf("PFS test - Lifecycle counter: %d - number of test loops: %d\n", gLifecycleCounter, numLoops); + /* + DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - Lifecycle counter:"), DLT_INT(gLifecycleCounter), + DLT_STRING("- number of write loops:"), DLT_INT(numLoops)); + */ + pthread_attr_init(&tattr); + param.sched_priority = 49; + pthread_attr_setschedparam(&tattr, ¶m); + + // create here the dbus connection and pass to main loop + if(pthread_create(&powerShutdownThread, &tattr, power_supply_shutdown, (void*)ttyfd) == -1) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("pthread_create( DBUS run_mainloop )") ); + return -1; + } - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library + pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - // verify the data form previous lifecycle - printf("--- Verify Data ---!!\n"); - verify_data_key_value(); - //verify_data_file(); + // verify the data form previous lifecycle + printf("--- Verify Data ---!!\n"); + verify_data_key_value(); + //verify_data_file(); - // write data - printf("--- Write Data!! ---\n"); - write_data_key_value(numLoops, gLifecycleCounter); // on odd lifecycle numbers, corrupt db data, otherwise corrupt db header - //write_data_file(numLoops); + // write data + printf("--- Write Data!! ---\n"); + write_data_key_value(numLoops, gLifecycleCounter); // on odd lifecycle numbers, corrupt db data, otherwise corrupt db header + //write_data_file(numLoops); pthread_cond_signal(&gPowerDownMtxCond); pthread_mutex_unlock(&gPowerDownMtx); - printf("Deinit library\n"); - pclDeinitLibrary(); // unregister from persistence client library + printf("Deinit library\n"); + pclDeinitLibrary(); // unregister from persistence client library #if 0 - unmount_persistence(); - - } - else - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("PFS test - failed to mount pers partition:"), DLT_INT(gLifecycleCounter) ); - printf("Mount Failed\n"); - rVal = EXIT_FAILURE; - } + unmount_persistence(); + + } + else + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("PFS test - failed to mount pers partition:"), DLT_INT(gLifecycleCounter) ); + printf("Mount Failed\n"); + rVal = EXIT_FAILURE; + } #endif - printf("End of PFS app\n"); + printf("End of PFS app\n"); // unregister debug log and trace //DLT_UNREGISTER_APP(); //dlt_free(); - return rVal; + printf("Wait until shutdown thread has finished\n"); + // wait until the shutdown thread has ended + pthread_join(powerShutdownThread, (void**)&retval); + + return rVal; } void verify_data_key_value() { - int i=0, ret = 0; - char buffer[64] = {0}; - - // read data from previous lifecycle - key/value - for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) - { - memset(buffer, 0, 64); - ret = pclKeyReadData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_WARN, DLT_STRING("verify - key/value - => failed to read data"), DLT_INT(ret), DLT_STRING(buffer)); - printf("verify - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); - } - else - { - int lc_count = get_lifecycle_count(buffer); - - // first verify base string - if(0 == strncmp(gDefaultKeyValueTestData[i], buffer, BASE_STRING_END) ) - { - char extendedStringOrig[64] = {0}; - char extendedStringBack[64] = {0}; - - snprintf(extendedStringOrig, 64, gDefaultKeyValueTestData[i], gOrigPostfix); - snprintf(extendedStringBack, 64, gDefaultKeyValueTestData[i], gBackupPostfix); - - - /*printf("Reference: %s\n", extendedStringOrig); - printf(" found: %s\n",buffer);*/ - - // check if original or backup will be used - if(0 == strncmp(extendedStringOrig, buffer, LC_CNT_START)) - { - /* - printf("ORIGINAL detected, everything OK:\n"); - printf(" desired: %s\n", extendedStringOrig); - printf(" actual : %s\n", buffer);*/ - } - else if(0 == strncmp(extendedStringBack, buffer, LC_CNT_START)) - { - /* - printf("BACKUP detected, everything OK:\n"); - printf(" desired: %s\n", extendedStringBack); - printf(" actual : %s\n", buffer); */ - } - else - { - - printf("----------------------------------------------------\n"); - printf("!!!! F A I L U R E !!!!! => lifecycle count - current: %d - found: %d\n", gLifecycleCounter, lc_count); - printf(" desired: %s\n", gDefaultKeyValueTestData[i]); - printf(" actual : %s\n", buffer); - printf("----------------------------------------------------\n"); - } + int i=0, ret = 0; + char buffer[64] = {0}; + + // read data from previous lifecycle - key/value + for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) + { + memset(buffer, 0, 64); + ret = pclKeyReadData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); + if(ret < 0) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_WARN, DLT_STRING("verify - key/value - => failed to read data"), DLT_INT(ret), DLT_STRING(buffer)); + printf("verify - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); + } + else + { + int lc_count = get_lifecycle_count(buffer); + + // first verify base string + if(0 == strncmp(gDefaultKeyValueTestData[i], buffer, BASE_STRING_END) ) + { + char extendedStringOrig[64] = {0}; + char extendedStringBack[64] = {0}; + + snprintf(extendedStringOrig, 64, gDefaultKeyValueTestData[i], gOrigPostfix); + snprintf(extendedStringBack, 64, gDefaultKeyValueTestData[i], gBackupPostfix); + + + /*printf("Reference: %s\n", extendedStringOrig); + printf(" found: %s\n",buffer);*/ + + // check if original or backup will be used + if(0 == strncmp(extendedStringOrig, buffer, LC_CNT_START)) + { + /* + printf("ORIGINAL detected, everything OK:\n"); + printf(" desired: %s\n", extendedStringOrig); + printf(" actual : %s\n", buffer);*/ + } + else if(0 == strncmp(extendedStringBack, buffer, LC_CNT_START)) + { + /* + printf("BACKUP detected, everything OK:\n"); + printf(" desired: %s\n", extendedStringBack); + printf(" actual : %s\n", buffer); */ + } + else + { + + printf("----------------------------------------------------\n"); + printf("!!!! F A I L U R E !!!!! => lifecycle count - current: %d - found: %d\n", gLifecycleCounter, lc_count); + printf(" desired: %s\n", gDefaultKeyValueTestData[i]); + printf(" actual : %s\n", buffer); + printf("----------------------------------------------------\n"); + } #if 0 - if(lc_count != (gLifecycleCounter-1) ) - { - printf(" Failure - LC count - current: %d - previous: %d - \"%s\"\n", gLifecycleCounter, lc_count, buffer); - /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - LC count - current:"), DLT_INT(gLifecycleCounter), - DLT_STRING("- previous:"), DLT_INT(lc_count), - DLT_STRING("- buf:"), DLT_STRING(buffer));*/ - } + if(lc_count != (gLifecycleCounter-1) ) + { + printf(" Failure - LC count - current: %d - previous: %d - \"%s\"\n", gLifecycleCounter, lc_count, buffer); + /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - LC count - current:"), DLT_INT(gLifecycleCounter), + DLT_STRING("- previous:"), DLT_INT(lc_count), + DLT_STRING("- buf:"), DLT_STRING(buffer));*/ + } #endif - } - else - { - printf(" Failure - base string does not match - actual: \"%s\" - desired: \"%s\"\n", buffer, gDefaultKeyValueTestData[i]); - /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - base string does not match - actual: "), DLT_STRING(buffer), - DLT_STRING("- desired:"), DLT_STRING(gDefaultKeyValueTestData[i]));*/ - } - - } - } - printf("Persistence pfs test - verification ended!!!!\n"); + } + else + { + printf(" Failure - base string does not match - actual: \"%s\" - desired: \"%s\"\n", buffer, gDefaultKeyValueTestData[i]); + /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - base string does not match - actual: "), DLT_STRING(buffer), + DLT_STRING("- desired:"), DLT_STRING(gDefaultKeyValueTestData[i]));*/ + } + + } + } + printf("Persistence pfs test - verification ended!!!!\n"); } void write_data_key_value(int numLoops, int counter) { - int i=0, k=0, ret = 0; - - if( (counter%2) == 1) - { - printf("Corrupt Data: numLoops: %d!!!!\n", numLoops); - } - else - { - printf("Do N O T corrupt data!!!\n"); - } + int i=0, k=0, ret = 0; + + if( (counter%2) == 1) + { + printf("Corrupt Data: numLoops: %d!!!!\n", numLoops); + } + else + { + printf("Do N O T corrupt data!!!\n"); + } #if 1 - for(k=0; k<numLoops; k++) - { - // write key/value data + for(k=0; k<numLoops; k++) + { + // write key/value data - for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) - { - char buffer[64] = {0}; + for(i=0; i<sizeof(gDefaultKeyValueTestData) / sizeof(char*); i++) + { + char buffer[64] = {0}; - strncpy(buffer, gDefaultKeyValueTestData[i], 64); - update_test_data(buffer, gLifecycleCounter, k); + strncpy(buffer, gDefaultKeyValueTestData[i], 64); + update_test_data(buffer, gLifecycleCounter, k); - if( (k == (int)numLoops/((counter%20)+1)) + if( (k == (int)numLoops/((counter%20)+1)) && (counter%2 == 1)) - { - // unlock mutex - printf("Now POWER OFF => k: %d \n", k); + { + // unlock mutex + printf("Now POWER OFF => k: %d \n", k); pthread_cond_signal(&gPowerDownMtxCond); pthread_mutex_unlock(&gPowerDownMtx); - } - ret = pclKeyWriteData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, strlen(buffer)); - if(ret < 0) - { - printf(" failed to write data: %d\n", ret ); - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); - } - - //printf("write data - key/value - \"%s\"\n", buffer); - } - } //num writes per lifecycle - - printf("End of Test\n"); + } + ret = pclKeyWriteData(0xFF, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, strlen(buffer)); + if(ret < 0) + { + printf(" failed to write data: %d\n", ret ); + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); + } + + //printf("write data - key/value - \"%s\"\n", buffer); + } + } //num writes per lifecycle + + printf("End of Test\n"); #endif } @@ -666,131 +667,131 @@ void write_data_key_value(int numLoops, int counter) void verify_data_file() { - int i=0, ret = 0; - int handles[128] = {0}; - char buffer[64] = {0}; - - // open files - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - handles[i] = pclFileOpen(0xFF, gDefaultFileResNames[i], 1, 0); - } - - // read data from previous lifecycle - file - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - memset(buffer, 0, 64); - ret = pclFileReadData(handles[i], buffer, 64); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("verify data - file - failed to read data"), DLT_INT(ret)); - } - else - { - printf("verify file - file - \"%s\"\n", buffer); - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("verify file: "), DLT_STRING(buffer)); - } - } - - // close fd's - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - ret = pclFileClose(handles[i]); - if(ret != 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); - } - } + int i=0, ret = 0; + int handles[128] = {0}; + char buffer[64] = {0}; + + // open files + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + handles[i] = pclFileOpen(0xFF, gDefaultFileResNames[i], 1, 0); + } + + // read data from previous lifecycle - file + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + memset(buffer, 0, 64); + ret = pclFileReadData(handles[i], buffer, 64); + if(ret < 0) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("verify data - file - failed to read data"), DLT_INT(ret)); + } + else + { + printf("verify file - file - \"%s\"\n", buffer); + //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("verify file: "), DLT_STRING(buffer)); + } + } + + // close fd's + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + ret = pclFileClose(handles[i]); + if(ret != 0) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); + } + } } void write_data_file(int numLoops) { - int i=0, k=0, ret = 0; - int handles[128] = {0}; - - // open files - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - handles[i] = pclFileOpen(0xFF, gDefaultFileResNames[i], 1, 1); - } - - for(k=0; k<numLoops; k++) - { - // write file data - - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - char buffer[64] = {0}; - - strncpy(buffer, gDefaultFileAPITestData[i], 64); - update_test_data(buffer, gLifecycleCounter, k); - - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("- write file:"), DLT_STRING(buffer)); - printf("write data - file - \"%s\"\n", buffer); - - ret = pclFileWriteData(handles[i], buffer, strlen(buffer)); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write file - failed to write data"), DLT_INT(ret)); - } - usleep((int)(rand()/100000)); // sleep a time random period - pclFileSeek(handles[i], 0, SEEK_SET); - } - - } // writes per lifecycle - - // close fd's - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - ret = pclFileClose(handles[i]); - if(ret != 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); - } - } + int i=0, k=0, ret = 0; + int handles[128] = {0}; + + // open files + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + handles[i] = pclFileOpen(0xFF, gDefaultFileResNames[i], 1, 1); + } + + for(k=0; k<numLoops; k++) + { + // write file data + + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + char buffer[64] = {0}; + + strncpy(buffer, gDefaultFileAPITestData[i], 64); + update_test_data(buffer, gLifecycleCounter, k); + + //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("- write file:"), DLT_STRING(buffer)); + printf("write data - file - \"%s\"\n", buffer); + + ret = pclFileWriteData(handles[i], buffer, strlen(buffer)); + if(ret < 0) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write file - failed to write data"), DLT_INT(ret)); + } + usleep((int)(rand()/100000)); // sleep a time random period + pclFileSeek(handles[i], 0, SEEK_SET); + } + + } // writes per lifecycle + + // close fd's + for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) + { + ret = pclFileClose(handles[i]); + if(ret != 0) + { + //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); + } + } } void unmount_persistence() { - if(umount2("/Data/mnt-c", MNT_DETACH) == -1) - { - printf("unmount /Data/mnt-c - FAILED: %s\n", strerror(errno)); - } + if(umount2("/Data/mnt-c", MNT_DETACH) == -1) + { + printf("unmount /Data/mnt-c - FAILED: %s\n", strerror(errno)); + } - if(umount2("/Data/mnt-wt", MNT_DETACH) == -1) - { - printf("unmount /Data/mnt-wt - FAILED: %s\n", strerror(errno)); - } + if(umount2("/Data/mnt-wt", MNT_DETACH) == -1) + { + printf("unmount /Data/mnt-wt - FAILED: %s\n", strerror(errno)); + } } int mount_persistence(const char* deviceName) { - int rval = 0; - - printf("Mount - /Data/mnt-c\n"); - if(-1 != mount(deviceName, "/Data/mnt-c", "ext4", 0, "")) - { - printf("Mount - /Data/mnt-wt\n"); - if(-1 == mount(deviceName, "/Data/mnt-wt", "ext4", 0, "")) - { - printf("Mount - FAILED - mnt-wt: %s\n", strerror(errno)); - rval = -1; - } - else - { - printf("Mount - SUCCESS\n"); - } - } - else - { - printf("Mount - FAILED - mnt-c: %s\n", strerror(errno)); - rval = -1; - } - - return rval; + int rval = 0; + + printf("Mount - /Data/mnt-c\n"); + if(-1 != mount(deviceName, "/Data/mnt-c", "ext4", 0, "")) + { + printf("Mount - /Data/mnt-wt\n"); + if(-1 == mount(deviceName, "/Data/mnt-wt", "ext4", 0, "")) + { + printf("Mount - FAILED - mnt-wt: %s\n", strerror(errno)); + rval = -1; + } + else + { + printf("Mount - SUCCESS\n"); + } + } + else + { + printf("Mount - FAILED - mnt-c: %s\n", strerror(errno)); + rval = -1; + } + + return rval; } |