Fix wrong available mem calculation of internal storage
[platform/core/appfw/app2sd.git] / plugin / app2sd / server / app2sd_internals_utils.c
index 970db56..705d52f 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #include <dirent.h>
-#include <time.h>
+#include <glib.h>
 #include <storage-internal.h>
 
 #include "app2sd_internals.h"
@@ -106,8 +106,8 @@ int _app2sd_check_mmc_status(char **sdpath)
 }
 
 /*
- * This function returns the available free memory in the SD Card.
- * param [in]: sd_path: This is sd card access path.
+ * This function returns the available free memory in the storage.
+ * param [in]: mmc_path: This is storage access path.
  * param [out]: free_mem: Result will be available in this.
  * User has to pass valid memory address.
  * return: On success, it will return 0.
@@ -128,7 +128,7 @@ int _app2sd_get_available_free_memory(char *mmc_path, int *free_mem)
 
        ret = statvfs(mmc_path, &buf);
        if (ret) {
-               _E("unable to get SD Card memory information");
+               _E("unable to get memory information");
                return APP2EXT_ERROR_MMC_INFORMATION;
        }
 
@@ -570,44 +570,26 @@ char *_app2sd_find_free_device(void)
 * This is a simple password generator
 * return: On success, it will return the password, else NULL.
 */
-char *_app2sd_generate_password(const char *pkgid)
+char *_app2sd_generate_password(void)
 {
-       char passwd[PASSWD_LEN + 1] = { 0, };
-       char *ret_result = NULL;
-       char set[ASCII_PASSWD_CHAR + 1] =
+       char *passwd;
+       static const char charset[ASCII_PASSWD_CHAR + 1] =
                "!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
                "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
-       unsigned char char_1;
-       unsigned char char_2;
-       int i = 0;
-       int appname_len = strlen(pkgid);
-       int j = appname_len;
-       unsigned int seed;
-
-       /* length of the password */
-       ret_result = (char *)malloc(PASSWD_LEN + 1);
-       if (NULL == ret_result) {
+       int i;
+
+       /* include null byte */
+       passwd = (char *)malloc(sizeof(char) * (PASSWD_LEN + 1));
+       if (passwd == NULL) {
                _E("unable to allocate memory");
                return NULL;
        }
-       memset((void *)ret_result, '\0', PASSWD_LEN + 1);
-
-       while (i < PASSWD_LEN) {
-               seed = time(NULL);
-               if (j > 0) j--;
-               char_1 = (rand_r(&seed) + pkgid[j]) % ASCII_PASSWD_CHAR;
-               char_2 = rand_r(&seed) % ASCII_PASSWD_CHAR;
-               passwd[i] = set[char_1];
-               if (j > 0) j--;
-               passwd[i + 1] = set[((pkgid[j]) * 2) % ASCII_PASSWD_CHAR];
-               if (i < PASSWD_LEN - 3)
-                       passwd[i + 2] = set[char_2];
-               i++;
-       }
 
-       memcpy(ret_result, passwd, PASSWD_LEN + 1);
+       for (i = 0; i < PASSWD_LEN; i++)
+               passwd[i] = charset[g_random_int() % ASCII_PASSWD_CHAR];
+       passwd[i] = '\0';
 
-       return ret_result;
+       return passwd;
 }
 
 #ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION