SET(SRCS ${SRCS} ${TOUCHSCREEN_SRCS})
ENDIF()
-IF(TZIP_MODULE STREQUAL on)
- ADD_SOURCE(src/tzip TZIP_SRCS)
- SET(SRCS ${SRCS} ${TZIP_SRCS})
-ENDIF()
-
IF(POWER_MODULE STREQUAL on)
ADD_SOURCE(src/power POWER_SRCS)
SET(SRCS ${SRCS} ${POWER_SRCS})
IF(BLOCK_MODULE STREQUAL on)
SET(PKG_MODULES ${PKG_MODULES} storage app2sd capi-system-info)
ENDIF()
-IF(TZIP_MODULE STREQUAL on)
- SET(PKG_MODULES ${PKG_MODULES} minizip fuse)
-ENDIF()
IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on)
SET(PKG_MODULES ${PKG_MODULES} libkmod libusbg)
ENDIF()
%define display_module on
%define extcon_module on
%define haptic_module off
-%define led_module off
%define power_module on
%define touchscreen_module off
-%define tzip_module off
%define usb_module on
%define usbhost_module off
%define TIZEN_FEATURE_USBHOST_TEST off
%if "%{?profile}" == "mobile"
%define haptic_module on
-%define led_module on
%define touchscreen_module on
-%define tzip_module on
%define usbhost_module on
%define TIZEN_FEATURE_USBHOST_TEST on
%endif
%if "%{?profile}" == "wearable"
%define haptic_module on
%define touchscreen_module on
-%define tzip_module on
%endif
%if "%{?profile}" == "tv"
%define block_tmpfs on
BuildRequires: pkgconfig(app2sd)
BuildRequires: pkgconfig(capi-system-info)
%endif
-%if %{?tzip_module} == on
-BuildRequires: pkgconfig(fuse)
-BuildRequires: pkgconfig(minizip)
-%endif
%if %{?TIZEN_FEATURE_USBHOST_TEST} == on
BuildRequires: pkgconfig(libkmod)
BuildRequires: pkgconfig(libusbg)
-DEXTCON_MODULE=%{extcon_module} \
-DHAPTIC_MODULE=%{haptic_module} \
-DSTANDARD_MIX=%{standard_mix} \
- -DLED_MODULE=%{led_module} \
-DPOWER_MODULE=%{power_module} \
-DSDB_PRESTART=%{sdb_prestart} \
-DTOUCHSCREEN_MODULE=%{touchscreen_module} \
- -DTZIP_MODULE=%{tzip_module} \
-DUSB_MODULE=%{usb_module} \
-DUSBHOST_MODULE=%{usbhost_module} \
-DTIZEN_FEATURE_USBHOST_TEST=%{TIZEN_FEATURE_USBHOST_TEST} \
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <unzip.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <stdarg.h>
-#include "core/log.h"
-
-#include "tzip-utility.h"
-
-static sem_t tzip_sem;
-
-static GHashTable *hashmap;
-
-struct tzip_mount_entry *get_mount_entry(const char *mount_path)
-{
- struct tzip_mount_entry *entry;
- entry = (struct tzip_mount_entry *)g_hash_table_lookup(
- hashmap, mount_path);
- return entry;
-}
-
-struct tzip_mount_entry *find_mount_entry(
- const char *mount_path, int *dir_status)
-{
- int len, mlen;
- GHashTableIter iter;
- gpointer key, value;
- char *path;
-
- *dir_status = -1;
- len = strlen(mount_path);
-
- g_hash_table_iter_init(&iter, hashmap);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- path = (char *)key;
- /*
- * FUSE checks directory status in recursive passion.
- * For example if mount path = "/tmp/d1",
- * FUSE first checks status of "/tmp" and proceeds to check
- * "/tmp/d1" only if status "/tmp" is success.
- *
- * This function takes care of this scenario by setting dir_status = 1
- * to indicate parent directory of mount path is found
- */
- mlen = strlen(path);
- if (len < mlen) {
- if (strncmp(mount_path, path, len) == 0) {
- /*
- * Dont break, till exact match is found for node->path.
- * Just mark *dir_status = 1 to indicate
- * parent directory match is found
- */
- *dir_status = 1;
- }
- } else if (mlen == len &&
- strncmp(mount_path, path, mlen) == 0) {
- /* Break, exact match is found for node->path */
- *dir_status = 1;
- return get_mount_entry(path);
- } else if (strncmp(mount_path, path, mlen) == 0 &&
- mount_path[mlen] == DIR_DELIMETER) {
- /* Break, mount directory found for a given file or directory */
- *dir_status = 1;
- return get_mount_entry(path);
- }
- }
-
- return NULL;
-}
-
-struct tzip_dir_info *get_dir_list(
- struct tzip_mount_entry *entry, const char *dir_name)
-{
- struct tzip_dir_info *dinfo;
-
- dinfo = (struct tzip_dir_info *)g_hash_table_lookup(
- entry->dir_hash, dir_name);
-
- if (!dinfo)
- _D("Empty Folder %s", dir_name);
-
- return dinfo;
-}
-
-void fileinfo_to_stat(unz_file_info *file_info, struct stat *file_stat, mode_t mode)
-{
- struct tm newdate;
- time_t file_time;
- struct timeval tv;
-
- if (file_info) {
- newdate.tm_sec = file_info->tmu_date.tm_sec;
- newdate.tm_min = file_info->tmu_date.tm_min;
- newdate.tm_hour = file_info->tmu_date.tm_hour;
- newdate.tm_mday = file_info->tmu_date.tm_mday;
- newdate.tm_mon = file_info->tmu_date.tm_mon;
- if (file_info->tmu_date.tm_year > 1900)
- newdate.tm_year = file_info->tmu_date.tm_year - 1900;
- else
- newdate.tm_year = file_info->tmu_date.tm_year ;
- newdate.tm_isdst = -1;
-
- file_time = mktime(&newdate);
- } else {
- /* add current time for mount directory */
- gettimeofday(&tv, NULL);
- file_time = tv.tv_sec;
- }
-
- file_stat->st_mode = mode;
- file_stat->st_atime = file_time;
- file_stat->st_mtime = file_time;
- file_stat->st_ctime = file_time;
-
- if (mode & S_IFDIR || !file_info)
- file_stat->st_size = 4096;
- else
- file_stat->st_size = file_info->uncompressed_size;
-}
-
-int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path,
- unz_file_info *file_info, mode_t mode)
-{
- char *dir;
- char *cpy_path;
- char *next_dir;
- char *parent_dir;
- char *save_ptr;
- int ret = 0;
-
- if (!strchr(path, '/')) {
- /* file or directory in root directory */
- ret = add_dir_info(entry, ".", path, file_info, mode);
- return ret;
- }
- /* add info about each directory in path */
- parent_dir = malloc(strlen(path) + 1);
- if (!parent_dir) {
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- /* needed copy, because of strtok_r modify cstring */
- cpy_path = strndup(path, strlen(path) + 1);
- if (!cpy_path) {
- free(parent_dir);
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- dir = strtok_r(cpy_path, "/", &save_ptr);
- ret = add_dir_info(entry, ".", dir, file_info, S_IFDIR);
-
- strncpy(parent_dir, dir, strlen(dir) + 1);
- dir = strtok_r(NULL, "/", &save_ptr);
- next_dir = strtok_r(NULL, "/", &save_ptr);
-
- while (next_dir && !ret) {
- ret = add_dir_info(entry, parent_dir, dir, file_info, S_IFDIR);
- strncat(parent_dir, "/", 2);
- strncat(parent_dir, dir, strlen(dir) + 1);
- dir = next_dir;
- next_dir = strtok_r(NULL, "/", &save_ptr);
- }
-
- if (ret) {
- free(cpy_path);
- free(parent_dir);
- return ret;
- }
-
- ret = add_dir_info(entry, parent_dir, dir, file_info, mode);
- free(cpy_path);
- free(parent_dir);
-
- return ret;
-}
-
-int add_dir_info(struct tzip_mount_entry *entry, const char *parent_dir,
- const char *filename, unz_file_info *file_info, mode_t mode)
-{
- struct tzip_file_info *finfo = NULL;
- struct tzip_dir_info *dinfo = NULL;
- int len;
-
- /* create parent directory if does not exist */
- if (!entry->dir_hash) {
- /* first entry, initialize dir_hash table */
- entry->dir_hash = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, NULL);
- }
-
- dinfo = (struct tzip_dir_info *)g_hash_table_lookup(
- entry->dir_hash, parent_dir);
- if (!dinfo) {
- /* new parent directory node, add */
- dinfo = (struct tzip_dir_info *)malloc(
- sizeof(struct tzip_dir_info));
- if (!dinfo) {
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- dinfo->file_hash = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, NULL);
- if (!dinfo->file_hash) {
- _E("Malloc failed");
- free(dinfo);
- return -ENOMEM;
- }
-
- len = strlen(parent_dir) + 1;
- dinfo->name = (char *)malloc(len);
- if (!dinfo->name) {
- _E("Malloc failed");
- free(dinfo);
- return -ENOMEM;
- }
- snprintf(dinfo->name, len, "%s", parent_dir);
- g_hash_table_insert(entry->dir_hash, dinfo->name, dinfo);
- fileinfo_to_stat(NULL, &dinfo->stat, S_IFDIR);
- }
-
- finfo = (struct tzip_file_info *)g_hash_table_lookup(
- dinfo->file_hash, filename);
-
- if (!finfo) {
- /* add dir info in parent dir node */
- finfo = (struct tzip_file_info *)malloc(sizeof(struct tzip_file_info));
- if (!finfo) {
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- len = strlen(filename) + 1;
- finfo->name = (char *)malloc(len);
- if (!finfo->name) {
- free(finfo);
- _E("Malloc failed");
- return -ENOMEM;
- }
- strncpy(finfo->name, filename, len);
-
- fileinfo_to_stat(file_info, &finfo->stat, mode);
-
- g_hash_table_insert(dinfo->file_hash, finfo->name, finfo);
- }
-
- return 0;
-}
-
-int extract_zipfile_details(
- struct tzip_mount_entry *entry, const char *zip_path)
-{
- uLong i;
- int ret = 0;
- mode_t mode;
-
- _D("Adding mount (%s, %s) to list", entry->path, zip_path);
-
- /* Open the zip file */
- unzFile *zipfile = unzOpen(zip_path);
- if (!zipfile) {
- _E("unzOpen Failed %s ", zip_path);
- return -EINVAL ;
- }
-
- /* Get info about the zip file */
- unz_global_info global_info;
- if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK) {
- _E("unzGetGlobalInfo Failed");
- ret = -EINVAL;
- goto out;
- }
-
- /* Loop to extract all files */
- for (i = 0; i < global_info.number_entry; ++i) {
- /* Get info about current file. */
- unz_file_info file_info = {0,};
- char filename[MAX_FILENAME_LEN] = {0};
-
- ret = unzGetCurrentFileInfo(zipfile, &file_info, filename,
- MAX_FILENAME_LEN, NULL, 0, NULL, 0);
- if (ret != UNZ_OK) {
- _E("unzGetCurrentFileInfo Failed");
- ret = -EINVAL;
- goto out;
- }
-
- _D("unzGetCurrentFileInfo file name - %s", filename);
-
- /* Check if this entry is a directory or file. */
- const size_t filename_length = strlen(filename);
-
- if (filename[filename_length-1] == DIR_DELIMETER) {
- _D("Entry is a directory");
- filename[filename_length-1] = 0;
- mode = S_IFDIR;
- } else {
- _D("Entry is a file");
- mode = S_IFREG;
- }
-
- ret = add_path_dirs_info(entry, filename, &file_info, mode);
- if (ret)
- break;
-
- /* Go the the next entry listed in the zip file. */
- if ((i+1) < global_info.number_entry) {
- ret = unzGoToNextFile(zipfile);
- if (ret != UNZ_OK) {
- _E("unzGoToNextFile Failed");
- ret = -EINVAL ;
- break;
- }
- }
- }
-
-out:
- unzClose(zipfile);
- return ret;
-}
-
-int add_mount_entry(const char *zip_path, const char *mount_path)
-{
- struct tzip_mount_entry *entry = NULL;
- int ret = 0;
- int len;
-
- /* check if this mount path is already there, return error if yes */
- entry = get_mount_entry(mount_path);
- if (entry) {
- _E("mount_path : %s already exists ", mount_path);
- return -EEXIST;
- }
-
- entry = (struct tzip_mount_entry *)malloc(
- sizeof(struct tzip_mount_entry));
- if (!entry) {
- _E("Malloc failed");
- return -ENOMEM;
- }
- entry->dir_hash = NULL;
-
- len = strlen(mount_path) + 1;
- entry->path = (char *)malloc(len);
- if (!entry->path) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
- snprintf(entry->path, len, "%s", mount_path);
-
- len = strlen(zip_path) + 1;
- entry->zip_path = (char *)malloc(len);
- if (!entry->zip_path) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- strncpy(entry->zip_path, zip_path, len);
-
- g_hash_table_insert(hashmap, entry->path, entry);
-
- /* pasrse zip file and update list */
- ret = extract_zipfile_details(entry, zip_path);
- if (ret) {
- free_mount_node(entry);
- return ret;
- }
-
-out:
- if (ret < 0 && entry) {
- free(entry->path);
- free(entry);
- }
- return ret;
-}
-
-void copy_file_stat(struct stat *src, struct stat *dest)
-{
- dest->st_mode = src->st_mode;
- dest->st_nlink = src->st_nlink;
- dest->st_atime = src->st_atime;
- dest->st_mtime = src->st_mtime;
- dest->st_ctime = src->st_ctime;
- dest->st_size = src->st_size;
-}
-
-int get_file_info(const char *file_path, struct tzip_file_info *flist)
-{
- struct tzip_mount_entry *entry;
- struct tzip_dir_info *dinfo;
- struct tzip_file_info *finfo;
- char *file_name;
- int file_index = 0;
- int dir_status;
-
- _D("File path : %s ", file_path);
-
- /* return file_info for a given file and mount path */
- entry = find_mount_entry(file_path, &dir_status);
- if (!entry) {
- _E("mount_path : %s is not mounted, dir_status %d", file_path, dir_status);
- return dir_status;
- }
-
- _D("Got mount path : %s", entry->path);
- file_index = strlen(entry->path);
-
- file_name = strrchr(&file_path[file_index], '/');
- if (!file_name) {
- _D("Parent Directory");
- return 1;
- } else if (strlen(file_name) == strlen(&file_path[file_index])) {
- _D("Checking dir : %s", ".");
- dinfo = get_dir_list(entry, ".");
- } else {
- *file_name = 0;
- _D("Checking dir : %s", &file_path[file_index+1]);
- dinfo = get_dir_list(entry, &file_path[file_index+1]);
- }
- if (!dinfo) {
- _D(" Empty Folder %s", file_path);
- return -ENOENT;
- }
-
- file_name = file_name+1;
- _D("File name : %s ", file_name);
-
- finfo = (struct tzip_file_info *)g_hash_table_lookup(
- dinfo->file_hash, file_name);
- if (!finfo) {
- _E("File %s not found", file_path);
- return -ENOENT;
- }
-
- flist->name = finfo->name;
- copy_file_stat(&finfo->stat, &flist->stat);
-
- return 0;
-}
-
-int get_path_prop(const char *path, struct stat *stbuf)
-{
- int ret = 0;
- struct tzip_file_info file;
-
- ret = get_file_info(path, &file);
- if (ret < 0) {
- _E("File not found : %s ", path);
- return -ENOENT;
- }
-
- if (ret == 1) {
- stbuf->st_mode = S_IFDIR | DEFAULT_FILE_MODE;
- stbuf->st_nlink = 1;
- stbuf->st_size = 4096;
- } else {
- stbuf->st_mode = file.stat.st_mode | DEFAULT_FILE_MODE;
- stbuf->st_nlink = 1;
- stbuf->st_atime = file.stat.st_atime;
- stbuf->st_mtime = file.stat.st_mtime;
- stbuf->st_ctime = file.stat.st_ctime;
- stbuf->st_size = file.stat.st_size;
- }
-
- return 0;
-}
-
-struct tzip_dir_info *get_dir_files(const char *dir)
-{
- struct tzip_mount_entry *entry;
- struct tzip_dir_info *dinfo;
- int file_index = 0;
- int dir_status;
- int dir_len = 0;
-
- _D("Dir path : %s ", dir);
-
- entry = find_mount_entry(dir, &dir_status);
- if (!entry) {
- _E("mount_path : %s is not mounted, dir_status %d", dir, dir_status);
- return NULL;
- }
-
- _D("Mount path : %s", entry->path);
- file_index = strlen(entry->path);
-
- dir_len = strlen(dir);
- if (file_index == dir_len) {
- _D("Checking dir : %s", ".");
- dinfo = get_dir_list(entry, ".");
- } else {
- _D("Checking dir : %s", &dir[file_index+1]);
- dinfo = get_dir_list(entry, &dir[file_index+1]);
- }
- if (!dinfo) {
- _D(" Empty Folder %s ", dir);
- return NULL;
- }
-
- return dinfo;
-}
-
-int remove_mount_entry(const char *mount_path)
-{
- struct tzip_mount_entry *entry;
-
- if (!mount_path) {
- _E("Invalid mount path ");
- return -ENOENT;
- }
-
- entry = (struct tzip_mount_entry *)get_mount_entry(mount_path);
- if (!entry) {
- _D("Mount path : %s not found", mount_path);
- return -ENOENT;
- }
-
- free_mount_node(entry);
- return 0;
-}
-
-void free_mount_node(struct tzip_mount_entry *entry)
-{
- struct tzip_file_info *finfo;
- struct tzip_dir_info *dinfo;
- GHashTableIter f_iter;
- GHashTableIter d_iter;
- gpointer fkey, fval;
- gpointer dkey, dval;
-
- if (!entry->dir_hash)
- goto out;
-
- g_hash_table_iter_init(&d_iter, entry->dir_hash);
- while (g_hash_table_iter_next(&d_iter, &dkey, &dval)) {
- dinfo = (struct tzip_dir_info *)dval;
-
- g_hash_table_iter_init(&f_iter, dinfo->file_hash);
- while (g_hash_table_iter_next(&f_iter, &fkey, &fval)) {
- finfo = (struct tzip_file_info *)fval;
- g_hash_table_remove(dinfo->file_hash, fkey);
- free(finfo->name);
- free(finfo);
- }
-
- g_hash_table_remove(entry->dir_hash, dkey);
- free(dinfo->name);
- if (dinfo->file_hash)
- g_hash_table_destroy(dinfo->file_hash);
- free(dinfo);
- }
-
-out:
- g_hash_table_remove(hashmap, entry->path);
- free(entry->path);
- free(entry->zip_path);
- if (entry->dir_hash)
- g_hash_table_destroy(entry->dir_hash);
- free(entry);
-}
-
-void tzip_lock_init(void)
-{
- if (sem_init(&tzip_sem, 0, 1) == -1)
- _E("sem_init failed");
-}
-
-void tzip_lock_deinit(void)
-{
- if (sem_destroy(&tzip_sem) == -1)
- _E("sem_destroy failed");
-}
-
-void tzip_lock(void)
-{
- sem_wait(&tzip_sem);
-}
-
-void tzip_unlock(void)
-{
- sem_post(&tzip_sem);
-}
-
-int reset_zipfile(struct tzip_handle *handle)
-{
- int ret;
-
- ret = unzCloseCurrentFile(handle->zipfile);
- if (ret != UNZ_OK) {
- _E("unzOpenCurrentFile Failed");
- return -EINVAL;
- }
- if (unzLocateFile(handle->zipfile, handle->file, CASE_SENSITIVE) != UNZ_OK) {
- _E("File :[%s] Not Found : unzLocateFile failed", handle->file);
- return -ENOENT;
- }
- ret = unzOpenCurrentFile(handle->zipfile);
- if (ret != UNZ_OK) {
- _E("unzOpenCurrentFile Failed");
- return -EINVAL;
- }
- return 0;
-}
-int read_zipfile(struct tzip_handle *handle, char *buf,
- size_t size, off_t offset)
-{
- int bytes_read;
- int ret;
-
- if (offset > handle->file_info->uncompressed_size) {
- _E("Invalid Offset (%jd) for file size (%d)", offset, handle->file_info->uncompressed_size);
- return -EINVAL;
- }
-
- if (offset != handle->offset) {
- int diff_size;
- /* seek and read buffer */
- _D("offset (%jd) handle->from(%jd) (offset + size) (%jd) handle->to (%jd) handle->offset (%jd)",
- offset, handle->from, (offset + size), handle->to, handle->offset);
- if (offset >= handle->from && (offset + size) <= handle->to && handle->pbuf) {
- _D("Have already read this chunk");
- memcpy(buf, handle->pbuf + (offset - handle->from), size);
- return size;
- }
-
- if (offset > handle->offset) {
- /* read from current position */
- diff_size = offset - handle->offset;
- _D("Read from current position (%jd) till offset (%jd)", handle->offset, offset);
- if (handle->pbuf)
- free(handle->pbuf);
-
- handle->pbuf = (char *)malloc(diff_size);
- if (!handle->pbuf) {
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- bytes_read = 0;
- do {
- ret = unzReadCurrentFile(handle->zipfile,
- handle->pbuf+bytes_read, diff_size - bytes_read);
- if (ret < 0) {
- _E("unzReadCurrentFile Failed");
- free(handle->pbuf);
- handle->pbuf = NULL;
- return -EINVAL;
- }
- bytes_read += ret;
- } while (bytes_read < diff_size && ret != 0);
-
- if (bytes_read == diff_size) {
- handle->from = handle->offset;
- handle->to = offset;
- } else {
- free(handle->pbuf);
- handle->pbuf = NULL;
- }
- } else if (offset) {
- char *tmp_buf;
- int buf_size;
- int chunk_count;
- int i;
-
- /* read from the begining*/
- _D("Read from the begining till offset (%jd)", offset);
- if (offset < 0)
- diff_size = handle->offset + offset;
- else
- diff_size = offset;
-
- if (reset_zipfile(handle)) {
- _E("reset_zipfile Failed");
- return -EINVAL;
- }
-
- /* dont read more than MAX_CHUNK_SIZE at once */
- if (diff_size < MAX_CHUNK_SIZE)
- buf_size = diff_size;
- else
- buf_size = MAX_CHUNK_SIZE;
-
- tmp_buf = (char *)malloc(buf_size);
- if (!tmp_buf) {
- _E("Malloc failed");
- return -ENOMEM;
- }
-
- /* chunk_count will have total number of chunks to read to reach offset position */
- chunk_count = diff_size/buf_size;
- if (diff_size % buf_size)
- chunk_count += 1;
-
- for (i = 0; i < chunk_count; i++) {
- /* adjust last chunk size according to offset */
- if (chunk_count > 1 && chunk_count == i + 1)
- buf_size = diff_size - (buf_size * i);
- bytes_read = 0;
- do {
- ret = unzReadCurrentFile(handle->zipfile,
- tmp_buf+bytes_read, buf_size - bytes_read);
- if (ret < 0) {
- _E("unzReadCurrentFile Failed");
- free(tmp_buf);
- return -EINVAL;
- }
- bytes_read += ret;
- } while (bytes_read < buf_size && ret != 0);
- if (!ret) {
- _E("EOF reached");
- break;
- }
- }
- free(tmp_buf);
- }
- }
-
- bytes_read = 0;
- do {
- ret = unzReadCurrentFile(handle->zipfile,
- buf + bytes_read, size - bytes_read);
- if (ret < 0) {
- _E("unzReadCurrentFile Failed");
- return -EINVAL;
- }
- bytes_read += ret;
- } while (bytes_read < size && ret != 0);
-
- /* store current zip position for subsequent read */
- handle->offset = offset + bytes_read;
-
- _D("bytes_read : %d [offset : %jd, total size : %d]", bytes_read, handle->offset, handle->file_info->uncompressed_size);
- return bytes_read;
-}
-
-GHashTable *hashmap_init(void)
-{
- hashmap = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
-
- return hashmap;
-}
-
-GHashTable *get_hashmap(void)
-{
- return hashmap;
-}
-
-int tzip_store_mount_info(const char *zip_path, const char *mount_path)
-{
- FILE *fp;
- int len;
- int ret = 0;
- char *file_entry;
-
- if (!zip_path || !mount_path) {
- _E("Invalid Arguments path : %p buf %p ", zip_path, mount_path);
- return -ENOENT;
- }
- _D("zip_path - : [%s] mount_path : [%s] ", zip_path, mount_path);
-
- fp = fopen(TZIP_INFO_FILE, "a+");
- if (fp == NULL) {
- _E("fopen() Failed!!!");
- return -EIO;
- }
-
- len = sizeof(char) * (strlen(zip_path) + strlen(mount_path) + 3);
- file_entry = (char *)malloc(len);
- if (!file_entry) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
- snprintf(file_entry, len, "%s:%s\n", zip_path, mount_path);
-
- len = strlen(file_entry);
- if (fwrite(file_entry, sizeof(char), len, fp) != len) {
- _E(" fwrite Failed !!!! ");
- ret = -EIO;
- goto out;
- }
-
-out:
- free(file_entry);
- fclose(fp);
- return ret;
-}
-
-int tzip_remount_zipfs(const char *src_file, const char *mount_point)
-{
- int ret = 0;
- char *tzip_path;
- int path_len, mp_len;
-
- if (!src_file || !mount_point) {
- _E("Invalid Arguments src_file : %p mount_point %p ", src_file, mount_point);
- return -EINVAL;
- }
-
- ret = add_mount_entry(src_file, mount_point);
- if (ret) {
- _E("Failed to add_mount_entry %s", mount_point);
- return ret;
- }
-
- path_len = sizeof(TZIP_ROOT_PATH); /* strlen(TZIP_ROOT_PATH) + 1 */
- mp_len = strlen(mount_point);
- tzip_path = (char *)malloc(path_len + mp_len);
- if (!tzip_path) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
- strncpy(tzip_path, TZIP_ROOT_PATH, path_len);
- strncat(tzip_path, mount_point, mp_len);
-
- _D("creating sym link : %s and %s", tzip_path, mount_point);
- ret = unlink(mount_point);
- if (ret) {
- _E("unlink failed");
- ret = -errno;
- goto out;
- }
-
- ret = symlink(tzip_path, mount_point);
- if (ret) {
- _E("symlink failed");
- ret = -errno;
- goto out;
- }
-
-out:
- if (ret < 0)
- remove_mount_entry(mount_point);
- free(tzip_path);
- _D("Exit : %d", ret);
- return ret;
-}
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TZIP_UTILITY_H__
-#define __TZIP_UTILITY_H__
-
-#include <stdio.h>
-#include <glib.h>
-
-#define TZIP_ROOT_PATH "/run/tzip"
-
-#define MAX_FILENAME_LEN 256
-
-#define DIR_DELIMETER '/'
-
-#define DEFAULT_FILE_MODE 0755
-
-#define TZIP_INFO_FILE "/run/.deviced"
-
-#define TZIP_MSGQ_NAME "/tzipmsgq"
-
-#define CASE_SENSITIVE 1
-
-#define MAX_CHUNK_SIZE 4096
-
-/* structure for storing a file info */
-struct tzip_file_info {
- char *name;
- struct stat stat;
-};
-
-/* structure for storing a dir info */
-struct tzip_dir_info {
- char *name;
- struct stat stat;
- GHashTable *file_hash; /* hash table for storing all files present in a given directory */
-};
-
-/* table containing mount path and corresponding files */
-struct tzip_mount_entry {
- char *path;
- char *zip_path;
- GHashTable *dir_hash; /* hash table for storing all directory info of a given zip file */
-};
-
-/* Structure containing Zip file handle */
-struct tzip_handle {
- unzFile *zipfile;
- unz_file_info *file_info;
- char *path;
- char *file;
- off_t offset;
- off_t from;
- off_t to;
- char *pbuf;
- sem_t lock;
-};
-
-/* structure containing message queue data */
-struct tzip_msg_data {
- char type; /* 'm' for mount , 'u' for unmount */
- char *zippath;
- char *mountpath;
- char *smack;
-};
-
-struct tzip_dir_info *get_dir_files(const char *dir);
-int add_mount_entry(const char *zip_path, const char *mount_path);
-int remove_mount_entry(const char *mount_path);
-int get_path_prop(const char *path, struct stat *stbuf);
-struct tzip_mount_entry *get_mount_entry(const char *mount_path);
-struct tzip_mount_entry *find_mount_entry(const char *mount_path, int *dir_status);
-void tzip_lock_init(void);
-void tzip_lock_deinit(void);
-void tzip_lock(void);
-void tzip_unlock(void);
-
-/* local function declrations */
-int get_file_info(const char *file_path, struct tzip_file_info *file_info);
-void copy_file_stat(struct stat *src, struct stat *dest);
-int extract_zipfile_details(struct tzip_mount_entry *node, const char *zip_path);
-int add_path_dirs_info(struct tzip_mount_entry *entry, const char *path, unz_file_info *file_info, mode_t mode);
-int add_dir_info(struct tzip_mount_entry *mnode, const char *parent_dir, const char *dir, unz_file_info *file_info, mode_t mode);
-void fileinfo_to_stat(unz_file_info *file_info, struct stat *file_stat, mode_t mode);
-struct tzip_dir_info *get_dir_list(struct tzip_mount_entry *dir_node, const char *dir_name);
-void free_mount_node(struct tzip_mount_entry *mount_node);
-int reset_zipfile(struct tzip_handle *handle);
-int read_zipfile(struct tzip_handle *handle, char *buf, size_t size, off_t offset);
-GHashTable *hashmap_init(void);
-GHashTable *get_hashmap(void);
-int tzip_store_mount_info(const char* zip_path, const char* mount_path);
-int tzip_remount_zipfs(const char *src_file, const char *mount_point);
-#endif /* __TZIP_UTILITY_H__ */
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define FUSE_USE_VERSION 26
-
-#include "core/log.h"
-#include "core/devices.h"
-#include "core/edbus-handler.h"
-#include "core/list.h"
-#include "core/device-notifier.h"
-#include "core/common.h"
-
-#include <fuse.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unzip.h>
-#include <pthread.h>
-#include <signal.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <attr/xattr.h>
-#include <linux/limits.h>
-#include <tzplatform_config.h>
-
-#include "tzip.h"
-#include "tzip-utility.h"
-
-
-static pthread_t thread;
-static pthread_t mount_thread;
-static pthread_attr_t attr;
-static struct fuse *fuse_handle = NULL;
-static struct fuse_chan *channel = NULL;
-static GAsyncQueue *async_queue;
-
-static int check_smack_label(pid_t pid)
-{
- char attr[64];
- size_t len;
- int ret;
-
- ret = get_privilege(pid, attr, sizeof(attr));
- if (ret < 0) {
- _E("Failed to get privilege of PID(%d)", pid);
- return 0;
- }
-
- len = strlen(attr) + 1;
-
- if (!strncmp("System", attr, len))
- return 1;
-
- if (!strncmp("User", attr, len))
- return 1;
-
- if (!strncmp("System::Privileged", attr, len))
- return 1;
-
- return 0;
-}
-
-static int check_path_available(char *mountpath)
-{
- const char *path;
-
- if (!mountpath)
- return 0;
-
- path = tzplatform_getenv(TZ_SYS_HOME);
- if (path && !strncmp(mountpath, path, strlen(path)))
- return 1;
-
- path = tzplatform_getenv(TZ_SYS_RW_APP);
- if (path && !strncmp(mountpath, path, strlen(path)))
- return 1;
-
- return 0;
-}
-
-static int is_app_privileged(pid_t pid, char *mountpath)
-{
- int priv;
-
- priv = check_path_available(mountpath);
- if (priv == 0) {
- _E("TZIP mount path is invalid (%s)", mountpath);
- return priv;
- }
-
- priv = check_smack_label(pid);
- if (priv == 0)
- _E("PID (%d) cannot use TZIP due to smack label");
-
- return priv;
-}
-
-static int tzip_getattr(const char *path, struct stat *stbuf)
-{
- int res = 0;
-
- if (!path || !stbuf) {
- _E("Invalid Arguments path : %p stbuf %p ", path, stbuf);
- return -EINVAL;
- }
-
- _D("Get ATTR path [%s]", path);
-
- tzip_lock();
- res = get_path_prop(path, stbuf);
- tzip_unlock();
-
- _D("Exit : %d \n", res);
-
- return res;
-}
-
-static int tzip_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
- off_t offset, struct fuse_file_info *fi)
-{
- struct tzip_dir_info *flist;
- GHashTableIter iter;
- gpointer key, value;
- char *name;
- int ret;
-
- if (!path || !buf) {
- _E("Invalid Arguments path : %p buf %p ", path, buf);
- return -EINVAL;
- }
-
- filler(buf, ".", NULL, 0);
- filler(buf, "..", NULL, 0);
-
- tzip_lock();
- flist = get_dir_files(path);
- if (flist == NULL) {
- _E("No Files in Dir : %s ", path);
- ret = 0;
- goto out_unlock;
- }
-
- g_hash_table_iter_init(&iter, flist->file_hash);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- name = (char *)key;
- filler(buf, name, NULL, 0);
- }
-
- ret = 0;
-
-out_unlock:
- tzip_unlock();
-
- return ret;
-}
-
-static int tzip_open(const char *path, struct fuse_file_info *fi)
-{
- int ret;
- char *file = NULL;
- char *zippath = NULL;
- int dir_status;
- struct tzip_mount_entry *entry = NULL;
- struct tzip_handle *handle = NULL;
- unz_file_info *file_info = NULL;
- unz_global_info global_info;
- unzFile *zipfile = NULL;
- int len;
- int file_len;
-
- if (!path || !fi) {
- _E("Invalid Arguments path : %p fi : %p", path, fi);
- return -EINVAL;
- }
- _D("Open - Path : %s", path);
-
- tzip_lock();
- entry = find_mount_entry(path, &dir_status);
- if (!entry) {
- _E("Mount Entry Not Found ");
- ret = -ENOENT;
- goto out_unlock;
- }
-
- len = strlen(entry->zip_path) + 1;
- zippath = (char *)malloc(len);
- if (!zippath) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out_unlock;
- }
- snprintf(zippath, len, "%s", entry->zip_path);
-
- len = strlen(entry->path);
- file_len = strlen(path) - len + 1;
- file = (char *)malloc(file_len);
- if (!file) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out_unlock;
- }
- strncpy(file, path + len + 1, file_len);
- tzip_unlock();
-
- zipfile = unzOpen(zippath);
- if (!zipfile) {
- _E("unzOpen Failed");
- ret = -ENOENT;
- goto out;
- }
-
- /* Get info about the zip file */
- if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK) {
- _E("unzGetGlobalInfo Failed");
- ret = -EINVAL;
- goto out;
- }
-
- if (unzLocateFile(zipfile, file, CASE_SENSITIVE) != UNZ_OK) {
- _E("File :[%s] Not Found : unzLocateFile failed", file);
- ret = -ENOENT;
- goto out;
- }
-
- file_info = (unz_file_info *)malloc(sizeof(unz_file_info));
- if (!file_info) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- ret = unzGetCurrentFileInfo(zipfile, file_info, (char *)file,
- strlen(file), NULL, 0, NULL, 0);
- if (ret != UNZ_OK) {
- _E("unzGetCurrentFileInfo Failed");
- ret = -EINVAL;
- goto out;
- }
-
- ret = unzOpenCurrentFile(zipfile);
- if (ret != UNZ_OK) {
- _E("unzOpenCurrentFile Failed");
- ret = -EINVAL;
- goto out;
- }
- handle = (struct tzip_handle *)malloc(sizeof(struct tzip_handle));
- if (!handle) {
- unzCloseCurrentFile(zipfile);
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
- handle->file_info = file_info;
- handle->zipfile = zipfile;
- handle->offset = 0;
- handle->path = zippath;
- handle->file = file;
- handle->pbuf = NULL;
- handle->from = 0;
- handle->to = 0;
- if (sem_init(&handle->lock, 0, 1) == -1)
- _E("sem_init failed");
-
-#ifdef ARCH_32BIT
- int hd = (int)handle;
- fi->fh = (uint64_t)hd;
-#else
- fi->fh = (uint64_t)handle;
-#endif
- return 0;
-
-out_unlock:
- tzip_unlock();
-out:
- free(zippath);
- free(file);
- free(file_info);
- if (zipfile)
- unzClose(zipfile);
- return ret;
-}
-
-static int tzip_read(const char *path, char *buf, size_t size, off_t offset,
- struct fuse_file_info *fi)
-{
- struct tzip_handle *handle;
- int ret;
-
- if (!path || !buf) {
- _E("Invalid Arguments path : %p buf %p ", path, buf);
- return -EINVAL;
- }
- if (!fi || fi->fh == 0) {
- _E("Invalid Zip Handle ");
- return -EINVAL;
- }
-
-#ifdef ARCH_32BIT
- int hd = (int)fi->fh;
- handle = (struct tzip_handle *)hd;
-#else
- handle = (struct tzip_handle *)(fi->fh);
-#endif
-
- _D("Read - Path : %s size : %zd offset : %jd ", path, size, offset);
- sem_wait(&handle->lock);
- ret = read_zipfile(handle, buf, size, offset);
- sem_post(&handle->lock);
- _D("Read ret = %d", ret);
- return ret;
-}
-
-static int tzip_release(const char *path, struct fuse_file_info *fi)
-{
- struct tzip_handle *handle;
-
- if (!path) {
- _E("Invalid Arguments path : %p", path);
- return -EINVAL;
- }
- if (!fi || fi->fh == 0) {
- _E("Invalid Zip Handle ");
- return -EINVAL;
- }
-
-#ifdef ARCH_32BIT
- int hd = (int)fi->fh;
- handle = (struct tzip_handle *)hd;
-#else
- handle = (struct tzip_handle *)(fi->fh);
-#endif
-
- if (sem_destroy(&handle->lock) == -1)
- _E("sem_destroy failed");
-
- unzCloseCurrentFile(handle->zipfile);
- unzClose(handle->zipfile);
- free(handle->file);
- free(handle->path);
- free(handle->file_info);
- if (handle->pbuf)
- free(handle->pbuf);
- free(handle);
-
- return 0;
-}
-
-static struct fuse_operations tzip_oper = {
- .getattr = tzip_getattr,
- .open = tzip_open,
- .read = tzip_read,
- .release = tzip_release,
- .readdir = tzip_readdir,
-};
-
-static void *tzip_thread(void *arg)
-{
- int ret;
- GHashTable *hash;
- FILE *fp;
- char *file_path;
- char *mount_dir;
- char *mount_info = NULL;
- size_t len;
- ssize_t read;
- char *saveptr = NULL;
- char *argv[4] = {"deviced", "-o", "allow_other", NULL};
- struct fuse_args args = FUSE_ARGS_INIT(3, argv);
-
- ret = mkdir(TZIP_ROOT_PATH, 0755);
- if (ret < 0 && errno != EEXIST) {
- _E("fail to make dir %s", TZIP_ROOT_PATH);
- return NULL;
- }
-
- tzip_lock();
- channel = fuse_mount(TZIP_ROOT_PATH, &args);
- if (!channel) {
- _E("Trying to mount after cleaning up previous instance %p ", TZIP_ROOT_PATH);
- fuse_unmount(TZIP_ROOT_PATH, NULL);
-
- channel = fuse_mount(TZIP_ROOT_PATH, NULL);
- if (!channel) {
- _E("Failed at mount_point %p ", TZIP_ROOT_PATH);
- goto out_unlock;
- }
- }
-
- fuse_handle = fuse_new(channel, NULL,
- &tzip_oper, sizeof(tzip_oper), NULL);
- if (!fuse_handle) {
- _E("Failed at fuse_new");
- goto out_unlock;
- }
-
- /* initialize string hash table */
- hash = hashmap_init();
- if (!hash) {
- _E("Failed at hashmap_init");
- goto out_unlock;
- }
- fp = fopen(TZIP_INFO_FILE, "r");
- if (fp) {
- while ((read = getline(&mount_info, &len, fp)) != -1) {
- if (mount_info) {
- mount_info[strcspn(mount_info, "\n")] = '\0';
- file_path = (char *)strtok_r(mount_info, ":", &saveptr);
- mount_dir = (char *)strtok_r(NULL, ":", &saveptr);
-
- if (file_path != NULL && mount_dir != NULL)
- tzip_remount_zipfs(file_path, mount_dir);
- free(mount_info);
- mount_info = NULL;
- }
- }
- fclose(fp);
- }
- tzip_unlock();
-
- if (fuse_loop_mt(fuse_handle)) {
- _E("Failed at fuse_loop_mt");
- goto out;
- }
-
- tzip_lock();
- if (fuse_handle) {
- fuse_destroy(fuse_handle);
- fuse_handle = NULL;
- }
-
-out_unlock:
- tzip_unlock();
-out:
- return NULL;
-}
-
-static void *tzip_mount_thread(void *arg)
-{
- struct tzip_msg_data *msgdata;
- int ret = 0;
-
- /* if g_async_queue_new() fails, tzip mount/unmount requests can not be handled */
- async_queue = g_async_queue_new();
- assert(async_queue);
-
- while (1) {
- /* g_async_queue_pop() is a blocking call, it should never return NULL */
- msgdata = (struct tzip_msg_data *)g_async_queue_pop(async_queue);
- assert(msgdata);
-
- if (msgdata->type == 'm') {
- ret = tzip_mount_zipfs(msgdata->zippath, msgdata->mountpath,
- msgdata->smack);
- free(msgdata->zippath);
- free(msgdata->mountpath);
- if (msgdata->smack)
- free(msgdata->smack);
- } else if (msgdata->type == 'u') {
- ret = tzip_unmount_zipfs(msgdata->mountpath);
- free(msgdata->mountpath);
- }
- free(msgdata);
-
- if (ret)
- _E("Failed to process mount/unmount request");
- }
-
- /* dead code, added just to satisfy compiler */
- return NULL;
-}
-
-void tzip_server_init(void)
-{
- if (pthread_attr_init(&attr) != 0)
- _E("pthread_attr_init Failed");
-
- if (pthread_create(&thread, &attr, &tzip_thread, NULL))
- _E("pthread_create Failed");
-
- if (pthread_create(&mount_thread, &attr, &tzip_mount_thread, NULL))
- _E("pthread_create Failed");
-}
-
-void tzip_server_exit(void)
-{
- if (!fuse_handle || !channel)
- return;
-
- tzip_lock();
- fuse_exit(fuse_handle);
- fuse_unmount(TZIP_ROOT_PATH, channel);
- fuse_destroy(fuse_handle);
- fuse_handle = NULL;
- channel = NULL;
- tzip_unlock();
-}
-
-static int tzip_check_mount_point(const char *mount_point)
-{
- int ret;
-
- if (unlink(mount_point) == 0)
- return 0;
-
- ret = errno;
- if (ret == ENOENT)
- return 0;
-
- _E("Failed to remove previous symlink file(errno:%d)", ret);
- return ret;
-}
-
-int tzip_mount_zipfs(const char *src_file, const char *mount_point, const char *smack)
-{
- int ret = 0;
- char *tzip_path = NULL;
- int path_len, mp_len;
-
- tzip_lock();
-
- ret = add_mount_entry(src_file, mount_point);
- if (ret) {
- _E("Failed to add_mount_entry %s", mount_point);
- goto out;
- }
-
- ret = tzip_check_mount_point(mount_point);
- if (ret < 0) {
- _E("Failed to mount via tzip (ret:%d)", ret);
- remove_mount_entry(mount_point);
- goto out;
- }
-
- path_len = sizeof(TZIP_ROOT_PATH); /* strlen(TZIP_ROOT_PATH) + 1 */
- mp_len = strlen(mount_point);
- tzip_path = (char *)malloc(path_len + mp_len);
- if (!tzip_path) {
- _E("Malloc failed");
- remove_mount_entry(mount_point);
- ret = -ENOMEM;
- goto out;
- }
- strncpy(tzip_path, TZIP_ROOT_PATH, path_len);
- strncat(tzip_path, mount_point, mp_len);
-
- _D("creating sym link : %s and %s", tzip_path, mount_point);
- ret = symlink(tzip_path, mount_point);
- if (ret) {
- _E("symlink failed");
- remove_mount_entry(mount_point);
- ret = -errno;
- } else {
- ret = tzip_store_mount_info(src_file, mount_point);
- if (ret != 0)
- _E("Failed to store_mount_info %s", mount_point);
-
- if (smack) {
- ret = lsetxattr(mount_point, "security.SMACK64", smack, strlen(smack), 0);
- if (ret < 0) {
- _E("setting smack label using lsetxattr() failed");
- remove_mount_entry(mount_point);
- ret = -errno;
- }
- }
- }
-
-out:
- tzip_unlock();
- free(tzip_path);
- _D("Exit : %d", ret);
- return ret;
-}
-
-int tzip_unmount_zipfs(const char *mount_point)
-{
- int ret = 0;
- char *tzip_path = NULL;
- int path_len, mp_len;
-
- tzip_lock();
- ret = remove_mount_entry(mount_point);
- if (ret) {
- _E("Failed to remove_mount_entry %s", mount_point);
- goto out_unlock;
- }
-
- path_len = sizeof(TZIP_ROOT_PATH); /* strlen(TZIP_ROOT_PATH) + 1 */
- mp_len = strlen(mount_point);
- tzip_path = (char *)malloc(path_len + mp_len);
- if (!tzip_path) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out_unlock;
- }
- strncpy(tzip_path, TZIP_ROOT_PATH, path_len);
- strncat(tzip_path, mount_point, mp_len);
-
- _D("deleting sym link : %s and %s", tzip_path, mount_point);
- ret = unlink(mount_point);
- if (ret) {
- _E("unlink failed");
- ret = -errno;
- }
-
-out_unlock:
- tzip_unlock();
- free(tzip_path);
- _D("Exit : %d", ret);
- return ret;
-}
-
-int tzip_is_mounted(const char *mount_point)
-{
- struct tzip_mount_entry *entry = NULL;
- int ret = 0;
- char *tzip_path;
- struct stat sb;
- int path_len, mp_len;
-
- if (!mount_point) {
- _E("Invalid Arguments mount_point %p ", mount_point);
- return -EINVAL;
- }
-
- if (!get_hashmap()) {
- _E("tzip init is not done yet");
- return 0;
- }
-
- entry = get_mount_entry(mount_point);
- if (!entry) {
- _E("mount_path : %s does not exists ", mount_point);
- return 0;
- }
-
- path_len = sizeof(TZIP_ROOT_PATH); /* strlen(TZIP_ROOT_PATH) + 1 */
- mp_len = strlen(mount_point);
- tzip_path = (char *)malloc(path_len + mp_len);
- if (!tzip_path) {
- _E("Malloc failed");
- return -ENOMEM;
- }
- strncpy(tzip_path, TZIP_ROOT_PATH, path_len);
- strncat(tzip_path, mount_point, mp_len);
-
- if (stat(tzip_path, &sb) == -1 || stat(mount_point, &sb) == -1)
- ret = 0;
- else
- ret = 1;
-
- free(tzip_path);
- return ret;
-}
-
-static DBusMessage *edbus_request_mount_tzip(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusError err;
- DBusMessageIter iter;
- DBusMessage *reply;
- char *zippath;
- char *mountpath;
- char *smack;
- int ret;
- struct tzip_msg_data *msgdata = NULL;
- pid_t pid;
-
- dbus_error_init(&err);
-
- if (!dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &mountpath,
- DBUS_TYPE_STRING, &zippath,
- DBUS_TYPE_STRING, &smack,
- DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto out;
- }
-
- if (!mountpath || !zippath) {
- _E("invalid input");
- ret = -EINVAL;
- goto out;
- }
-
- pid = get_edbus_sender_pid(msg);
- if (!is_app_privileged(pid, mountpath)) {
- _E("PID (%d) is not privileged to use tzip", pid);
- ret = -EPERM;
- goto out;
- }
-
- if (!fuse_handle)
- tzip_server_init();
-
- msgdata = malloc(sizeof(struct tzip_msg_data));
- if (!msgdata) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- msgdata->type = 'm';
- msgdata->zippath = strdup(zippath);
- msgdata->mountpath = strdup(mountpath);
- if (!msgdata->zippath ||
- !msgdata->mountpath) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- if (smack) {
- msgdata->smack = strdup(smack);
- if (!msgdata->smack) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
- } else /* Use default smack */
- msgdata->smack = NULL;
-
- if (async_queue) {
- g_async_queue_push(async_queue, (gpointer)msgdata);
- ret = 0;
- } else
- ret = -EAGAIN;
-
-out:
- if (ret < 0 && msgdata) {
- free(msgdata->zippath);
- free(msgdata->mountpath);
- if (msgdata->smack)
- free(msgdata->smack);
- free(msgdata);
- }
-
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
- return reply;
-}
-
-static DBusMessage *edbus_request_unmount_tzip(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusError err;
- DBusMessageIter iter;
- DBusMessage *reply;
- char *mountpath;
- int ret;
- struct tzip_msg_data *msgdata = NULL;
- pid_t pid;
-
- dbus_error_init(&err);
-
- if (!dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &mountpath, DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto out;
- }
-
- if (!mountpath) {
- _E("invalid input");
- ret = -EINVAL;
- goto out;
- }
-
- pid = get_edbus_sender_pid(msg);
- if (!is_app_privileged(pid, mountpath)) {
- _E("PID (%d) is not privileged to use tzip", pid);
- ret = -EPERM;
- goto out;
- }
-
- if (!fuse_handle)
- tzip_server_init();
-
- msgdata = malloc(sizeof(struct tzip_msg_data));
- if (!msgdata) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- msgdata->type = 'u';
- msgdata->mountpath = strdup(mountpath);
- if (!msgdata->mountpath) {
- _E("Malloc failed");
- ret = -ENOMEM;
- goto out;
- }
-
- if (async_queue) {
- g_async_queue_push(async_queue, (gpointer)msgdata);
- ret = 0;
- } else
- ret = -ENOMEM;
-
-out:
- if (ret < 0 && msgdata) {
- free(msgdata->mountpath);
- free(msgdata);
- }
-
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
- return reply;
-}
-
-static DBusMessage *edbus_request_ismounted_tzip(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusError err;
- DBusMessageIter iter;
- DBusMessage *reply;
- char *mountpath;
- int ret;
-
- dbus_error_init(&err);
-
- if (!dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &mountpath, DBUS_TYPE_INVALID)) {
- _E("there is no message");
- ret = -EINVAL;
- goto out;
- }
-
- ret = tzip_is_mounted(mountpath);
-
-out:
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
- return reply;
-}
-
-static const struct edbus_method edbus_methods[] = {
- { "Mount", "sss", "i", edbus_request_mount_tzip },
- { "Unmount", "s", "i", edbus_request_unmount_tzip },
- { "IsMounted", "s", "i", edbus_request_ismounted_tzip },
- /* Add methods here */
-};
-
-static int booting_done(void *data)
-{
- if (!fuse_handle)
- tzip_server_init();
-
- return 0;
-}
-
-static int tzip_poweroff(void *data)
-{
- _I("TZIP poweroff");
- tzip_server_exit();
- return 0;
-}
-
-static void tzip_init(void *data)
-{
- int ret;
- _D("tzip_init ");
-
- tzip_lock_init();
-
- register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
- register_notifier(DEVICE_NOTIFIER_POWEROFF, tzip_poweroff);
-
- ret = register_edbus_interface_and_method(DEVICED_PATH_TZIP,
- DEVICED_INTERFACE_TZIP,
- edbus_methods, ARRAY_SIZE(edbus_methods));
- if (ret < 0)
- _E("fail to init edbus method(%d)", ret);
-}
-
-static void tzip_exit(void *data)
-{
- _D("tzip_exit ");
- tzip_server_exit();
- unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
- unregister_notifier(DEVICE_NOTIFIER_POWEROFF, tzip_poweroff);
-
- tzip_lock_deinit();
-}
-
-static const struct device_ops tzip_device_ops = {
- .name = "tzip",
- .init = tzip_init,
- .exit = tzip_exit,
-};
-
-DEVICE_OPS_REGISTER(&tzip_device_ops)
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TZIP_H__
-#define __TZIP_H__
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief mounts a zip file to a particular system path.
- * @remarks This is asynchronous method, zip file is mounted or not should be checked using tzip_is_mounted(mount_path) before using mounted path.
- * @since_tizen 3.0
- * @param[in] zip_file The input zip file
- * @param[in] mount_path The mount path
- * @param[in] smack Smack label for mount path
- * @return @c 0 if the mount operation is successful, \n @c negative error code if the mount operation fails
- */
-int tzip_mount_zipfs(const char *zip_file, const char *mount_path, const char *smack);
-
-/**
- * @brief unmounts a already mounted path
- * @since_tizen 3.0
- * @param[in] mount_path The mounted path
- * @return @c 0 if the unmount operation is successful, \n @c negative error code if the unmount operation fails
- */
-int tzip_unmount_zipfs(const char *mount_path);
-
-/**
- * @brief checks if given path is mounted
- * @since_tizen 3.0
- * @param[in] mount_path The mount path
- * @return @c 1 if the given path is mounted and 0 if it is not mounted, \n @c negative error code if this operation fails
- */
-int tzip_is_mounted(const char *mount_path);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __TZIP_H__