*/
#include <dirent.h>
-#include <time.h>
+#include <glib.h>
#include <storage-internal.h>
#include "app2sd_internals.h"
}
/*
- * 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.
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;
}
{
int ret = 0;
DIR *dp = NULL;
- struct dirent ep;
- struct dirent *er = NULL;
+ struct dirent *ep = NULL;
char abs_filename[FILENAME_MAX] = { 0, };
dp = opendir(dirname);
if (dp != NULL) {
- while (readdir_r(dp, &ep, &er) == 0 && er != NULL) {
+ while ((ep = readdir(dp)) != NULL) {
char mmc_path[PATH_MAX] = {0};
- if (!strcmp(ep.d_name, ".") || !strcmp(ep.d_name, ".."))
+ if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
continue;
/*get realpath find symlink to ".mmc" and unlink it*/
- snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep.d_name);
+ snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep->d_name);
char *path = realpath(abs_filename, mmc_path);
if (!path)
_E("realpath failed");
{
static unsigned long long total = 0;
DIR *dp = NULL;
- struct dirent ep;
- struct dirent *er = NULL;
+ struct dirent *ep = NULL;
char abs_filename[FILENAME_MAX] = { 0, };;
dp = opendir(dirname);
if (dp != NULL) {
- while (readdir_r(dp, &ep, &er) == 0 && er != NULL) {
+ while ((ep = readdir(dp)) != NULL) {
struct stat stFileInfo;
snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
- ep.d_name);
+ ep->d_name);
if (stat(abs_filename, &stFileInfo) < 0)
perror(abs_filename);
total += stFileInfo.st_size;
if (S_ISDIR(stFileInfo.st_mode)) {
- if (strcmp(ep.d_name, ".")
- && strcmp(ep.d_name, "..")) {
+ if (strcmp(ep->d_name, ".")
+ && strcmp(ep->d_name, "..")) {
_app2sd_calculate_dir_size
(abs_filename);
}
* 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