+static int _mkdir(const char *dir, mode_t mode) {
+ char tmp[256];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp),"%s",dir);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, mode);
+ *p = '/';
+ }
+ return mkdir(tmp, mode);
+}
+
+static char* _media_svc_get_thumb_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ media_svc_error("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ media_svc_error("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+char* _media_svc_get_thumb_internal_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ media_svc_error("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ media_svc_error("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
+ }
+
+ mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+char* _media_svc_get_thumb_external_path(uid_t uid)
+{
+ char *result_psswd = NULL;
+ struct group *grpinfo = NULL;
+ if(uid == getuid())
+ {
+ result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ }
+ else
+ {
+ struct passwd *userinfo = getpwuid(uid);
+ if(userinfo == NULL) {
+ media_svc_error("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if(grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ // Compare git_t type and not group name
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ media_svc_error("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
+ }
+
+ _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
+
+ return result_psswd;
+}
+
+int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)