int _app2sd_delete_directory(const char *dirname);
+void _app2sd_set_application_path(const char *pkgid, uid_t uid, char path[],
+ int size);
+
#ifdef __cplusplus
}
#endif
char source_name[FILENAME_MAX] = { 0, };
GChecksum *checksum;
- snprintf(source_name, FILENAME_MAX - 1, "%s_%d", pkgid, uid);
+ snprintf(source_name, sizeof(source_name), "%s_%d", pkgid, uid);
checksum = g_checksum_new(G_CHECKSUM_MD5);
- g_checksum_update(checksum, (const guchar *)source_name, strlen(source_name));
+ g_checksum_update(checksum, (const guchar *)source_name,
+ strlen(source_name));
temp_string = (char *)g_checksum_get_string(checksum);
new_name = strdup(temp_string);
g_checksum_free(checksum);
return new_name;
}
+void _app2sd_set_application_path(const char *pkgid, uid_t uid,
+ char path[], int size)
+{
+ if (_is_global(uid)) {
+ snprintf(path, size, "%s/%s",
+ tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
+ } else {
+ tzplatform_set_user(uid);
+ snprintf(path, size, "%s/%s",
+ tzplatform_getenv(TZ_USER_APP), pkgid);
+ tzplatform_reset_user();
+ }
+}
+
int _app2sd_delete_directory(const char *dirname)
{
DIR *dp = NULL;
int ret = 0;
dp = opendir(dirname);
- if (dp != NULL) {
- while ((ep = readdir(dp)) != NULL) {
- struct stat stFileInfo;
+ if (dp == NULL) {
+ _W("couldn't open the directory[%s], errno[%d]",
+ dirname, errno);
+ return 0;
+ }
- snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
- ep->d_name);
+ while ((ep = readdir(dp)) != NULL) {
+ struct stat stFileInfo;
- if (lstat(abs_filename, &stFileInfo) < 0) {
- perror(abs_filename);
- (void)closedir(dp);
- return -1;
- }
+ snprintf(abs_filename, sizeof(abs_filename), "%s/%s",
+ dirname, ep->d_name);
- if (S_ISDIR(stFileInfo.st_mode)) {
- if (strcmp(ep->d_name, ".")
- && strcmp(ep->d_name, "..")) {
- ret = _app2sd_delete_directory(abs_filename);
- if (ret < 0) {
- (void)closedir(dp);
- return -1;
- }
- }
- } else {
- ret = remove(abs_filename);
+ if (lstat(abs_filename, &stFileInfo) < 0) {
+ perror(abs_filename);
+ (void)closedir(dp);
+ return -1;
+ }
+
+ if (S_ISDIR(stFileInfo.st_mode)) {
+ if (strcmp(ep->d_name, ".")
+ && strcmp(ep->d_name, "..")) {
+ ret = _app2sd_delete_directory(abs_filename);
if (ret < 0) {
(void)closedir(dp);
return -1;
}
}
+ } else {
+ ret = remove(abs_filename);
+ if (ret < 0) {
+ (void)closedir(dp);
+ return -1;
+ }
}
- (void)closedir(dp);
- ret = remove(dirname);
- if (ret < 0)
- return -1;
- } else {
- _W("couldn't open the directory[%s]", dirname);
}
+ (void)closedir(dp);
+ ret = remove(dirname);
+ if (ret < 0)
+ return -1;
+
return 0;
}
app2sd_cmd cmd, uid_t uid)
{
int ret = 0;
+ char app_path[FILENAME_MAX] = { 0, };
char temp_path[FILENAME_MAX] = { 0, };
if (cmd != APP2SD_PRE_UPGRADE)
return APP2EXT_SUCCESS;
- if (_is_global(uid)) {
- snprintf(temp_path, FILENAME_MAX - 1, "%s/%s.new",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- } else {
- tzplatform_set_user(uid);
- snprintf(temp_path, FILENAME_MAX - 1, "%s/%s.new",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- tzplatform_reset_user();
- }
+ _app2sd_set_application_path(pkgid, uid, app_path, sizeof(app_path));
+ snprintf(temp_path, sizeof(temp_path), "%s.new", app_path);
/* this will delete all files under temp_path */
ret = _app2sd_delete_directory(temp_path);
int ret = 0;
mode_t mode = DIR_PERMS;
char application_path[FILENAME_MAX] = { 0, };
- char application_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
char temp_path[FILENAME_MAX] = { 0, };
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- tzplatform_reset_user();
- }
-
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
ret = mkdir(application_path, mode);
if (ret) {
if (errno != EEXIST) {
}
}
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
application_path);
-
- ret = mkdir(application_mmc_path, mode);
+ ret = mkdir(app_mmc_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("create directory failed," \
if (cmd == APP2SD_PRE_UPGRADE) {
/* application_path for {pkgid}.new */
- snprintf(temp_path, FILENAME_MAX - 1, "%s.new",
+ snprintf(temp_path, sizeof(temp_path), "%s.new",
application_path);
ret = mkdir(temp_path, mode);
if (ret) {
return APP2EXT_ERROR_CREATE_DIRECTORY;
}
}
- /* application_mmc_path for {pkgid}.new */
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ /* app_mmc_path for {pkgid}.new */
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
temp_path);
- ret = mkdir(application_mmc_path, mode);
+ ret = mkdir(app_mmc_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("create directory failed," \
char app2sd_path[FILENAME_MAX] = { 0, };
mode_t mode = DIR_PERMS;
- snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
- mmc_path, EXTIMG_DIR);
+ snprintf(app2sd_path, sizeof(app2sd_path), "%s/%s",
+ mmc_path, EXTIMG_DIR);
ret = mkdir(app2sd_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
+
ret = __app2sd_create_app2sd_directories(uid, mmc_path);
if (ret) {
_E("failed to create app2sd dirs");
char *sdpath = NULL;
char mmc_path[FILENAME_MAX] = { 0, };
char application_path[FILENAME_MAX] = { 0, };
- char application_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
char loopback_device[FILENAME_MAX] = { 0, };
char *encoded_id = NULL;
int ret = APP2EXT_SUCCESS;
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
+ application_path);
+
ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
application_path, uid);
if (ret) {
if (ret)
_E("unable to delete info");
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
- application_path);
- ret = _app2sd_delete_directory(application_mmc_path);
+ ret = _app2sd_delete_directory(app_mmc_path);
if (ret)
_E("unable to delete the directory (%s)", application_path);
} else {
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- /* check app entry is there in sd card or not. */
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
fp = fopen(loopback_device, "r+");
if (fp == NULL) {
_W("MMC not present OR Not ready (%d)", ret);
mmc_present = 0;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- /* check app entry is there in sd card or not. */
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
if (mmc_present) {
fp = fopen(loopback_device, "r+");
ret = APP2EXT_ERROR_MMC_STATUS;
goto END;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
/* check app entry is there in sd card or not. */
fp = fopen(loopback_device, "r+");
{
char mmc_path[FILENAME_MAX] = { 0, };
char application_path[FILENAME_MAX] = { 0, };
- char application_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
char loopback_device[FILENAME_MAX] = { 0, };
char *sdpath = NULL;
char *encoded_id = NULL;
ret = APP2EXT_ERROR_MMC_STATUS;
goto END;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
+ application_path);
+
ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
application_path, uid);
if (ret) {
goto END;
}
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
- application_path);
- ret = _app2sd_delete_directory(application_mmc_path);
+ ret = _app2sd_delete_directory(app_mmc_path);
if (ret) {
_E("unable to delete the directory (%s)",
application_path);
_E("MMC not present OR Not ready(%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
_E("MMC not present OR Not ready(%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- tzplatform_reset_user();
- }
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
application_path, uid);
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
- sdpath, EXTIMG_DIR);
+ snprintf(app2sd_path, sizeof(app2sd_path), "%s/%s",
+ sdpath, EXTIMG_DIR);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
- app2sd_path, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
- app2sd_path, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s",
+ app2sd_path, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
/* check app entry is there in sd card or not. */
fp = fopen(loopback_device, "r+");
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
ret = __app2sd_finalize_device_setup(pkgid, loopback_device,
application_path, uid);
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+ snprintf(mmc_path, sizeof(mmc_path), "%s", sdpath);
free(sdpath);
sync();
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
-
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
- mmc_path, EXTIMG_DIR, encoded_id);
- tzplatform_reset_user();
- }
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
+ mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
ret = _app2sd_force_clean(pkgid, application_path, loopback_device, uid);
_E("MMC not present OR Not ready (%d)", ret);
return APP2EXT_ERROR_MMC_STATUS;
}
- snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
- sdpath, EXTIMG_DIR);
+ snprintf(app2sd_path, sizeof(app2sd_path), "%s/%s",
+ sdpath, EXTIMG_DIR);
free(sdpath);
dir = opendir(app2sd_path);
if (strcmp(entry->d_name, ".") == 0 ||
strcmp(entry->d_name, "..") == 0)
continue;
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s",
app2sd_path, entry->d_name);
ret = _app2sd_get_info_from_db(loopback_device,
&pkgid, &uid);
}
encoded_id = _app2sd_get_encoded_name(pkgid, uid);
- if (encoded_id == NULL) {
+ if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
- }
+
snprintf(loopback_device, sizeof(loopback_device), "%s/%s",
mmc_path, encoded_id);
free(encoded_id);
}
/* process the string*/
- snprintf(dev, FILENAME_MAX - 1, "%s", result);
+ snprintf(dev, sizeof(dev), "%s", result);
if (strstr(dev, "dev") == NULL) {
_E("unable to find the associated file");
}
count = 0;
char dev_path[BUF_SIZE] = { 0, };
- snprintf(dev_path, BUF_SIZE, "/dev/loop%d", count);
+ snprintf(dev_path, sizeof(dev_path), "/dev/loop%d", count);
while ((fp = fopen(dev_path, "r+")) != NULL) {
count = count + 1;
- snprintf(dev_path, BUF_SIZE, "/dev/loop%d", count);
+ snprintf(dev_path, sizeof(dev_path), "/dev/loop%d", count);
_D("next dev path for checking is (%s)",
dev_path);
fclose(fp);
}
}
- snprintf(dmcrypt_setup_cmd, BUF_SIZE, "/bin/echo '%s' | /sbin/cryptsetup -q -i %d " \
+ snprintf(dmcrypt_setup_cmd, sizeof(dmcrypt_setup_cmd),
+ "/bin/echo '%s' | /sbin/cryptsetup -q -i %d " \
"-c aes-cbc-lmk -s %d --align-payload=8 luksFormat %s",
passwd, DMCRYPT_ITER_TIME, DMCRYPT_KEY_LEN, loopback_device);
}
if (is_dup)
- snprintf(dev_name, BUF_SIZE, "%s.new_%d", pkgid, uid);
+ snprintf(dev_name, sizeof(dev_name), "%s.new_%d", pkgid, uid);
else
- snprintf(dev_name, BUF_SIZE, "%s_%d", pkgid, uid);
+ snprintf(dev_name, sizeof(dev_name), "%s_%d", pkgid, uid);
/* get password for dmcrypt encryption */
ret = _app2sd_initialize_db();
return APP2EXT_ERROR_OPEN_DMCRYPT_DEVICE;
}
- snprintf(buf, BUF_SIZE, "/dev/mapper/%s", dev_name);
+ snprintf(buf, sizeof(buf), "/dev/mapper/%s", dev_name);
len = strlen(buf);
*dev_node = (char *)calloc(len + 1, sizeof(char));
if (*dev_node == NULL) {
free(t_dev_node);
t_dev_node = NULL;
- snprintf(dev_node, BUF_SIZE, "/dev/mapper/%s_%d", pkgid, uid);
- snprintf(dmcrypt_close_cmd, BUF_SIZE, "/sbin/cryptsetup -q luksClose %s", dev_node);
+ snprintf(dev_node, sizeof(dev_node), "/dev/mapper/%s_%d", pkgid, uid);
+ snprintf(dmcrypt_close_cmd, sizeof(dmcrypt_close_cmd),
+ "/sbin/cryptsetup -q luksClose %s", dev_node);
ret = system(dmcrypt_close_cmd);
if (ret) {
strerror_r(errno, err_buf, sizeof(err_buf));
char buf[BUF_SIZE] = { 0, };
int len = 0;
- snprintf(buf, BUF_SIZE, "/dev/mapper/%s_%d", pkgid, uid);
+ snprintf(buf, sizeof(buf), "/dev/mapper/%s_%d", pkgid, uid);
len = strlen(buf);
dev_node = (char *)calloc(len + 1, sizeof(char));
if (dev_node == NULL) {
_E("invalid argument");
return APP2EXT_ERROR_INVALID_ARGUMENTS;
}
- snprintf(command, FILENAME_MAX - 1, "of=%s", loopback_device);
- snprintf(buff, BUF_SIZE - 1, "count=%d", size);
+ snprintf(command, sizeof(command), "of=%s", loopback_device);
+ snprintf(buff, sizeof(buff), "count=%d", size);
const char *argv1[] = { "/bin/dd", "if=/dev/zero",
command, "bs=1M", buff, NULL };
const char *pkgid, const char *dir_name, uid_t uid)
{
int ret = APP2EXT_SUCCESS;
- char application_dir_mmc_path[FILENAME_MAX] = { 0, };
- char application_dir_path[FILENAME_MAX] = { 0, };
+ char app_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char app_dir_path[FILENAME_MAX] = { 0, };
- snprintf(application_dir_mmc_path, FILENAME_MAX - 1, "%s/.mmc/%s",
+ snprintf(app_dir_mmc_path, sizeof(app_dir_mmc_path), "%s/.mmc/%s",
application_path, dir_name);
- snprintf(application_dir_path, FILENAME_MAX, "%s/%s",
+ snprintf(app_dir_path, sizeof(app_dir_path), "%s/%s",
application_path, dir_name);
- ret = _app2sd_make_directory(application_dir_mmc_path, uid);
+ ret = _app2sd_make_directory(app_dir_mmc_path, uid);
if (ret) {
_E("create directory failed");
return APP2EXT_ERROR_CREATE_DIRECTORY;
}
- if ((ret = symlink(application_dir_mmc_path,
- application_dir_path)) < 0) {
+ if ((ret = symlink(app_dir_mmc_path,
+ app_dir_path)) < 0) {
if (errno == EEXIST) {
_D("file with symlink name present (%s)",
- application_dir_path);
+ app_dir_path);
} else {
_E("symbolic link creation "
"failed, error no is (%d)", errno);
{
int ret = APP2EXT_SUCCESS;
int fd = -1;
- char application_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
char temp_path[FILENAME_MAX] = { 0, };
char err_buf[1024] = {0,};
struct timespec time = {
}
close(fd);
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
application_path);
- fd = open(application_mmc_path, O_RDONLY|O_DIRECTORY);
+ fd = open(app_mmc_path, O_RDONLY|O_DIRECTORY);
if (fd < 0) {
- _E("path(%s) error(%d)", application_mmc_path, errno);
+ _E("path(%s) error(%d)", app_mmc_path, errno);
return APP2EXT_ERROR_OPEN_DIR;
}
close(fd);
switch (mount_type) {
case MOUNT_TYPE_RD:
- if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ if ((ret = mount(dev, app_mmc_path, FS_TYPE,
MS_MGC_VAL | MS_RDONLY | MS_NOSUID, NULL)) < 0) {
_E("read only mount failed, " \
"errono is (%d), " \
"dev is (%s) path is (%s)",
- errno, dev, application_mmc_path);
+ errno, dev, app_mmc_path);
ret = APP2EXT_ERROR_MOUNT;
}
break;
case MOUNT_TYPE_RW:
- if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ if ((ret = mount(dev, app_mmc_path, FS_TYPE,
MS_MGC_VAL | MS_NOSUID, NULL)) < 0) {
_E("read write mount failed, " \
"errono is (%d)", errno);
}
break;
case MOUNT_TYPE_RW_NOEXEC:
- if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ if ((ret = mount(dev, app_mmc_path, FS_TYPE,
MS_MGC_VAL | MS_NOEXEC | MS_NOSUID, NULL)) < 0) {
_E("rwnx mount failed " \
"errono is (%d)", errno);
}
break;
case MOUNT_TYPE_RD_REMOUNT:
- if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ if ((ret = mount(dev, app_mmc_path, FS_TYPE,
MS_MGC_VAL | MS_RDONLY | MS_REMOUNT | MS_NOSUID,
NULL)) < 0) {
_E("read remount failed "
}
break;
case MOUNT_TYPE_RW_REMOUNT:
- if ((ret = mount(dev, application_mmc_path, FS_TYPE,
+ if ((ret = mount(dev, app_mmc_path, FS_TYPE,
MS_MGC_VAL | MS_REMOUNT | MS_NOSUID, NULL)) < 0) {
_E("read write remount failed "
"errono(%d), errstr(%s)", errno,
if (mount_type != MOUNT_TYPE_RD &&
mount_type != MOUNT_TYPE_RD_REMOUNT) {
/* change lost+found permission */
- snprintf(temp_path, FILENAME_MAX - 1, "%s/lost+found",
- application_mmc_path);
+ snprintf(temp_path, sizeof(temp_path), "%s/lost+found",
+ app_mmc_path);
ret = _app2sd_make_directory(temp_path, uid);
if (ret) {
_E("create directory(%s) failed", temp_path);
int _app2sd_unmount_app_content(const char *application_path)
{
int ret = APP2EXT_SUCCESS;
- char application_dir_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
char err_buf[1024] = {0,};
- snprintf(application_dir_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
application_path);
- if ((ret = umount(application_dir_mmc_path)) < 0) {
+ if ((ret = umount(app_mmc_path)) < 0) {
strerror_r(errno, err_buf, sizeof(err_buf));
_D("unable to umount the dir, ret(%d) error(%d, %s)",
ret, errno, err_buf);
int ret = APP2EXT_SUCCESS;
mode_t mode = DIR_PERMS;
char temp_dir_path[FILENAME_MAX] = { 0, };
- char application_mmc_path[FILENAME_MAX] = { 0, };
- char application_archive_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
+ char app_archive_path[FILENAME_MAX] = { 0, };
char application_path[FILENAME_MAX] = { 0, };
char loopback_device[FILENAME_MAX] = { 0, };
unsigned long long total_size = 0;
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- tzplatform_reset_user();
- }
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
/* check whether application is in external memory or not */
fp = fopen(loopback_device, "r+");
_app2sd_force_clean(pkgid, application_path, loopback_device, uid);
}
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
application_path);
- snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive",
+ snprintf(app_archive_path, sizeof(app_archive_path), "%s/.archive",
application_path);
- ret = mkdir(application_mmc_path, mode);
+ ret = mkdir(app_mmc_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("unable to create directory for archiving," \
}
}
- ret = mkdir(application_archive_path, mode);
+ ret = mkdir(app_archive_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("unable to create directory for archiving," \
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
+ memset(temp_dir_path, '\0', sizeof(temp_dir_path));
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
"%s/%s", application_path,
dir_detail->name);
_D("cal size of app dirs, temp_dir_path(%s)",
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
"%s/%s", application_path,
dir_detail->name);
_D("app2archive, temp_dir_path(%s)",
temp_dir_path);
ret = _app2sd_move_to_archive(temp_dir_path,
- application_archive_path);
+ app_archive_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
_E("unable to access (%s)",
} else {
_E("unable to copy from (%s) to (%s)",
temp_dir_path,
- application_archive_path);
+ app_archive_path);
}
goto ERR;
}
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
- "%s/%s", application_archive_path,
+ memset(temp_dir_path, '\0', sizeof(temp_dir_path));
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
+ "%s/%s", app_archive_path,
dir_detail->name);
_D("archive2mmc, temp_dir_path(%s)",
temp_dir_path);
ret = _app2sd_copy_dir(temp_dir_path,
- application_mmc_path);
+ app_mmc_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
_E("unable to access (%s)",
_E("unable to copy from (%s) to (%s)," \
" error is (%s)",
temp_dir_path,
- application_mmc_path, err_buf);
+ app_mmc_path, err_buf);
}
goto ERR;
}
list = g_list_next(list);
}
- ret = _app2sd_delete_directory(application_archive_path);
+ ret = _app2sd_delete_directory(app_archive_path);
if (ret) {
- _E("unable to delete (%s)", application_archive_path);
+ _E("unable to delete (%s)", app_archive_path);
ret = APP2EXT_ERROR_DELETE_DIRECTORY;
goto ERR;
}
int ret = APP2EXT_SUCCESS;
mode_t mode = DIR_PERMS;
char temp_dir_path[FILENAME_MAX] = { 0, };
- char application_mmc_path[FILENAME_MAX] = { 0, };
- char application_archive_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
+ char app_archive_path[FILENAME_MAX] = { 0, };
char application_path[FILENAME_MAX] = { 0, };
char loopback_device[FILENAME_MAX] = { 0, };
char *device_node = NULL;
if (encoded_id == NULL)
return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
- snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+ snprintf(loopback_device, sizeof(loopback_device), "%s/%s/%s",
mmc_path, EXTIMG_DIR, encoded_id);
free(encoded_id);
- if (_is_global(uid)) {
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
- } else {
- tzplatform_set_user(uid);
- snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
- tzplatform_getenv(TZ_USER_APP), pkgid);
- tzplatform_reset_user();
- }
+ _app2sd_set_application_path(pkgid, uid, application_path,
+ sizeof(application_path));
/* check whether application is in external memory or not */
fp = fopen(loopback_device, "r+");
}
}
- snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc",
+ snprintf(app_mmc_path, sizeof(app_mmc_path), "%s/.mmc",
application_path);
- snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive",
+ snprintf(app_archive_path, sizeof(app_archive_path), "%s/.archive",
application_path);
- ret = mkdir(application_archive_path, mode);
+ ret = mkdir(app_archive_path, mode);
if (ret) {
if (errno != EEXIST) {
_E("unable to create directory for archiving," \
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
/* archiving code */
- memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
- "%s/%s", application_mmc_path,
+ memset(temp_dir_path, '\0', sizeof(temp_dir_path));
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
+ "%s/%s", app_mmc_path,
dir_detail->name);
_D("mmc2archive, temp_dir_path(%s)", temp_dir_path);
ret = _app2sd_copy_dir(temp_dir_path,
- application_archive_path);
+ app_archive_path);
if (ret) {
if (ret == APP2EXT_ERROR_ACCESS_FILE) {
_E("unable to access (%s)",
_E("unable to copy from (%s) to (%s),"
" error is (%s)",
temp_dir_path,
- application_archive_path, err_buf);
+ app_archive_path, err_buf);
}
goto ERR;
}
/* delete the symbolic link files [bin, lib, res]*/
- memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
+ memset(temp_dir_path, '\0', sizeof(temp_dir_path));
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
"%s/%s", application_path,
dir_detail->name);
_D("unlink, temp_dir_path(%s)", temp_dir_path);
}
/* Copy content to destination */
- memset(temp_dir_path, '\0', FILENAME_MAX);
- snprintf(temp_dir_path, FILENAME_MAX,
- "%s/%s", application_archive_path,
+ memset(temp_dir_path, '\0', sizeof(temp_dir_path));
+ snprintf(temp_dir_path, sizeof(temp_dir_path),
+ "%s/%s", app_archive_path,
dir_detail->name);
_D("archive2app, temp_dir_path(%s)", temp_dir_path);
ret = _app2sd_copy_dir(temp_dir_path, application_path);
_E("unable to delete the loopback device for (%s)",
pkgid);
- ret = _app2sd_delete_directory(application_mmc_path);
+ ret = _app2sd_delete_directory(app_mmc_path);
if (ret)
- _E("unable to delete (%s)", application_mmc_path);
+ _E("unable to delete (%s)", app_mmc_path);
- ret = _app2sd_delete_directory(application_archive_path);
+ ret = _app2sd_delete_directory(app_archive_path);
if (ret)
- _E("unable to delete (%s)", application_archive_path);
+ _E("unable to delete (%s)", app_archive_path);
/* remove passwrd from DB */
ret = _app2sd_initialize_db();
dir_detail = (app2ext_dir_details *)list->data;
if (dir_detail && dir_detail->name
&& dir_detail->type == APP2EXT_DIR_RO) {
- memset((void *)&path, '\0', FILENAME_MAX);
- snprintf(path, FILENAME_MAX - 1, "%s/%s", src,
+ memset((void *)&path, '\0', sizeof(path));
+ snprintf(path, sizeof(path), "%s/%s", src,
dir_detail->name);
ret = _app2sd_copy_dir(path, dest);
if (ret) {
char *device_node = NULL;
char *old_device_node = NULL;
int err_res = 0;
- char application_mmc_path[FILENAME_MAX] = { 0, };
- char temp_application_mmc_path[FILENAME_MAX] = { 0, };
+ char app_mmc_path[FILENAME_MAX] = { 0, };
+ char temp_app_mmc_path[FILENAME_MAX] = { 0, };
ret = _app2sd_duplicate_device(pkgid, loopback_device,
temp_pkgid, temp_application_path, temp_loopback_device,
}
}
- snprintf(application_mmc_path, FILENAME_MAX - 1,
+ snprintf(app_mmc_path, sizeof(app_mmc_path),
"%s/.mmc", application_path);
- snprintf(temp_application_mmc_path, FILENAME_MAX - 1,
+ snprintf(temp_app_mmc_path, sizeof(temp_app_mmc_path),
"%s/.mmc", temp_application_path);
- ret = _app2sd_copy_ro_content(application_mmc_path,
- temp_application_mmc_path, dir_list);
+ ret = _app2sd_copy_ro_content(app_mmc_path,
+ temp_app_mmc_path, dir_list);
if (ret) {
_E("copy ro content failed");
err_res = ret;
continue;
/*get realpath find symlink to ".mmc" and unlink it*/
- snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep->d_name);
+ snprintf(abs_filename, sizeof(abs_filename), "%s/%s", dirname, ep->d_name);
char *path = realpath(abs_filename, mmc_path);
if (!path)
_E("realpath failed");
(void)closedir(dp);
/*delete ".mmc" folder*/
- snprintf(abs_filename, FILENAME_MAX, "%s/.mmc", dirname);
+ snprintf(abs_filename, sizeof(abs_filename), "%s/.mmc", dirname);
ret = remove(abs_filename);
if (ret == -1)
return;
while ((ep = readdir(dp)) != NULL) {
struct stat stFileInfo;
- snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+ snprintf(abs_filename, sizeof(abs_filename), "%s/%s", dirname,
ep->d_name);
if (stat(abs_filename, &stFileInfo) < 0)