summaryrefslogtreecommitdiff
path: root/src/common/file-system/mf-ug-fs-oper.c
blob: 8646ec075eb555328d11fe3b338f858f15fd85a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
/*
 * Copyright 2012          Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://floralicense.org/license/
 *
 * 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 <libgen.h>
#include <glib.h>
#include "mf-ug-fs-util.h"
#include "mf-ug-util.h"

static int __mf_ug_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2);
static int __mf_ug_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2);

/*********************
**Function name:	__mf_ug_fs_oper_file_system_error
**Parameter:
**	const char* src:	source path
**	const char* dst:	destination path
**	int check_option:	check option
**
**Return value:
**	error code
**
**Action:
**	input parameter checking
**
*********************/
static const char *__mf_ug_fs_oper_get_file(const char *path)
{
	char *result = NULL;

	if (!path) {
		return NULL;
	}
	if ((result = strrchr(path, '/'))) {
		result++;
	} else {
		result = (char *)path;
	}
	return result;
}


static int __mf_ug_fs_oper_file_system_error(const char *src, const char *dst, int check_option)
{
	if ((check_option & MF_ERROR_CHECK_SRC_ARG_VALID) && (src == NULL)) {
		return MYFILE_ERR_SRC_ARG_INVALID;
	}
	if ((check_option & MF_ERROR_CHECK_SRC_EXIST) && (!ecore_file_exists(src))) {
		return MYFILE_ERR_SRC_NOT_EXIST;
	}

	if (check_option & MF_ERROR_CHECK_SRC_PATH_VALID) {
		if (!ecore_file_is_dir(src)) {
			if (mf_ug_file_attr_is_right_file_path(src)) {
				return MYFILE_ERR_INVALID_FILE_PATH;
			}
		} else {
			if (mf_ug_file_attr_is_right_dir_path(src)) {
				return MYFILE_ERR_INVALID_DIR_PATH;
			}
		}
	}

	if (check_option & MF_ERROR_CHECK_DUPLICATED) {
		char *parent_path = NULL;

		if (!mf_ug_file_attr_get_parent_path(dst, &parent_path)) {
			if (mf_ug_file_attr_is_duplicated_name(parent_path, __mf_ug_fs_oper_get_file(dst))) {
				UG_SAFE_FREE_CHAR(parent_path);
				return MYFILE_ERR_DUPLICATED_NAME;
			}
			UG_SAFE_FREE_CHAR(parent_path);
		} else {
			UG_SAFE_FREE_CHAR(parent_path);
			return MYFILE_ERR_GET_PARENT_PATH_FAIL;
		}
	}
	return MYFILE_ERR_NONE;
}

/*********************
**Function name:	mf_ug_fs_oper_read_dir
**Parameter:
**	char *path:				path which we need to read
**	Eina_List** dir_list:	output parameter of dir list under specified path
**	Eina_List** file_list:	output parameter of file list under specified path
**
**Return value:
**	error code
**
**Action:
**	read element under the specified path
**
*********************/
int mf_ug_fs_oper_read_dir(const char *path, Eina_List **dir_list, Eina_List **file_list)
{
	UG_TRACE_BEGIN;
	DIR *pDir = NULL;
	struct dirent *ent;

	ug_mf_retvm_if(path == NULL, MYFILE_ERR_INVALID_ARG, "path is null");
	ug_mf_retvm_if(dir_list == NULL, MYFILE_ERR_INVALID_ARG, "dir_list is null");
	ug_mf_retvm_if(file_list == NULL, MYFILE_ERR_INVALID_ARG, "file_list is null");

	int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_SRC_EXIST | MF_ERROR_CHECK_SRC_PATH_VALID;
	int ret = __mf_ug_fs_oper_file_system_error(path, NULL, option);

	if (ret != MYFILE_ERR_NONE) {
		return ret;
	}

	pDir = opendir(path);

	if (pDir == NULL) {
		return MYFILE_ERR_DIR_OPEN_FAIL;
	}

	while ((ent = readdir(pDir)) != NULL) {
		GString *childpath = NULL;
		ugFsNodeInfo *pNode = NULL;

		if (strncmp(ent->d_name, ".", 1) == 0 || strcmp(ent->d_name, "..") == 0) {
			continue;
		}

		if ((ent->d_type & DT_DIR) == 0 && (ent->d_type & DT_REG) == 0) {
			continue;
		}
#ifdef	UG_DEBUG_FOLDER_OPTION
		if ((ent->d_type & DT_DIR) != 0) {
			if ((strlen(path) == strlen(PHONE_FOLDER)) && (strcmp(path, PHONE_FOLDER) == 0)
			    && (strlen(ent->d_name) == strlen(DEBUG_FOLDER)) && (strcmp(ent->d_name, DEBUG_FOLDER) == 0)) {
				continue;
			}
		}
#endif
		pNode = (ugFsNodeInfo *) malloc(sizeof(ugFsNodeInfo));

		if (pNode == NULL) {
			continue;
		}
		memset(pNode, 0, sizeof(ugFsNodeInfo));
		snprintf(pNode->path, sizeof(pNode->path), "%s", path);
		snprintf(pNode->name, sizeof(pNode->name), "%s", ent->d_name);
		if (ent->d_type & DT_DIR) {
			pNode->type = UG_FILE_TYPE_DIR;
		} else if (ent->d_type & DT_REG) {
			mf_ug_file_attr_get_file_category(ent->d_name, &(pNode->type));
		}
		childpath = g_string_new(path);
		if (childpath == NULL) {
			free(pNode);
			pNode = NULL;
			continue;
		}
		g_string_append_printf(childpath, "/%s", ent->d_name);
		mf_ug_file_attr_get_file_stat(childpath->str, &pNode);
		if (pNode->type == UG_FILE_TYPE_DIR) {
			ug_mf_debug("dir append\n");
			*dir_list = eina_list_append(*dir_list, pNode);
		} else {
			ug_mf_debug("file append\n");
			ret = mf_ug_file_attr_get_file_ext(childpath->str, &pNode->ext);
			if (ret != MYFILE_ERR_NONE) {
				pNode->ext = NULL;
			}
			*file_list = eina_list_append(*file_list, pNode);
		}

		g_string_free(childpath, TRUE);
	}
	closedir(pDir);
	UG_TRACE_END;

	return MYFILE_ERR_NONE;
}

/*********************
**Function name:	__mf_ug_fs_oper_exec_filter
**Parameter:
**	ugFsNodeInfo* pnode_info:	the node we need to check for filter
**	int option:				filter
**
**Return value:
**	error code
**
**Action:
**	check if the node satisfied the filter option
*********************/
static mf_ug_drm_file_mime_type __mf_ug_fs_oper_get_drm_file_type_by_mime(char *mime_type)
{
	gchar **result = NULL;
	if (mime_type != NULL) {
		result = g_strsplit(mime_type, "/", 0);
		if (result && (*result)) {
			ug_mf_debug("*result is [%s]", *result);
			if (g_strcmp0(*result, "audio") == 0) {
				g_strfreev(result);
				return MF_UG_DRM_RINGTONE_FILE;
			} else if (g_strcmp0(*result, "image") == 0) {
				g_strfreev(result);
				return MF_UG_DRM_IMAGE_FILE;
			} else {
				g_strfreev(result);
				return MF_UG_DRM_UNKNOW_FILE;
			}
		} else {
			g_strfreev(result);
			return MF_UG_DRM_UNKNOW_FILE;
		}
	} else {
		return MF_UG_DRM_UNKNOW_FILE;
	}
}

mf_ug_drm_file_mime_type mf_ug_fs_oper_get_drm_type(char *path)
{
	drm_result_e res = 0;
	drm_content_info_s dcf_content_info;

	res = drm_get_content_info(path, &dcf_content_info);


	if (res == DRM_RETURN_SUCCESS) {
		mf_ug_drm_file_mime_type drm_mime_type = __mf_ug_fs_oper_get_drm_file_type_by_mime(dcf_content_info.mime_type);
		return drm_mime_type;
	} else {
		return MF_UG_DRM_UNKNOW_FILE;
	}
}

int mf_ug_fs_oper_drm_is_action_allowed(const char *path, drm_action_type_e action, drm_setas_category_e category)
{
	drm_bool_type_e is_allowed = 0;
	drm_action_allowed_data_s action_data;

	int ret = -1;
	memset(&action_data,0x0,sizeof(drm_action_allowed_data_s));
	UG_SAFE_STRCPY(action_data.file_path, path);

	action_data.data = category;

	ret = drm_is_action_allowed(action,&action_data,&is_allowed);
	if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_allowed){
		return true;
	}else{
		return false;
	}
}

bool mf_ug_fs_oper_drm_is_valid(const char *path, drm_permission_type_e perm_type)
{
	int res = DRM_RETURN_SUCCESS;
	drm_license_status_e licence_status = DRM_LICENSE_STATUS_UNDEFINED;
	if (path) {
		res = drm_get_license_status(path, perm_type, &licence_status);
	}

	ug_error("res is [%d] licence is [%d]", res, licence_status);
	if (res == DRM_RETURN_SUCCESS && licence_status == DRM_LICENSE_STATUS_VALID) {
		return true;
	} else {
		return false;
	}

}
static bool __mf_ug_fs_oper_exec_drm_filter(ugFsNodeInfo *pnode_info, int option)
{
	if (pnode_info == NULL) {
		return FALSE;
	}

	int result = -1;
	char *fullpath = NULL;
	drm_result_e res = DRM_RETURN_INTERNAL_ERROR;
	if (option & MF_UG_FILTER_DRM_ALL) {
		return TRUE;
	}

	if (option & MF_UG_FILTER_DRM_WITHOUT_FL) {
		fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL);
		res = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_IS_FORWARDING_ALLOWED, DRM_SETAS_NONE);
		if (res == DRM_RETURN_SUCCESS) {
			return FALSE;
		} else {
			return TRUE;
		}
	}

	if (option & MF_UG_FILTER_DRM_IMAGE) {
		fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL);

		result = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_HAS_VALID_SETAS_STATUS, DRM_SETAS_WALLPAPER);
		if (result) {
			mf_ug_drm_file_mime_type drm_mime_type = mf_ug_fs_oper_get_drm_type(fullpath);
			if (drm_mime_type == MF_UG_DRM_IMAGE_FILE)
				return TRUE;
			else
				return FALSE;
		} else {
			return FALSE;
		}
	}

	if (option & MF_UG_FILTER_DRM_RINGTONE) {
		fullpath = g_strconcat(pnode_info->path, "/", pnode_info->name, NULL);

		result = mf_ug_fs_oper_drm_is_action_allowed(fullpath, DRM_HAS_VALID_SETAS_STATUS, DRM_SETAS_RINGTONE);
		if (result) {
			mf_ug_drm_file_mime_type drm_mime_type = mf_ug_fs_oper_get_drm_type(fullpath);
			if (drm_mime_type == MF_UG_DRM_RINGTONE_FILE)
				return TRUE;
			else
				return FALSE;
		} else {
			return FALSE;
		}

	}

	return FALSE;
}

static bool __mf_ug_fs_oper_exec_filter(ugFsNodeInfo *pnode_info, int option)
{
	if (pnode_info == NULL) {
		return FALSE;
	}
	if (option & UG_FILTER_CATEGORY_IMAGE) {
		if (pnode_info->type == UG_FILE_TYPE_IMAGE) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VIDEO) {
		if (pnode_info->type == UG_FILE_TYPE_VIDEO) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_SOUND) {
		if (pnode_info->type == UG_FILE_TYPE_SOUND) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VOICE) {
		if (pnode_info->type == UG_FILE_TYPE_VOICE) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_MUSIC) {
		if (pnode_info->type == UG_FILE_TYPE_MUSIC) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_HTML) {
		if (pnode_info->type == UG_FILE_TYPE_HTML) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_FLASH) {
		if (pnode_info->type == UG_FILE_TYPE_FLASH) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_GAME) {
		if (pnode_info->type == UG_FILE_TYPE_GAME) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_APP) {
		if (pnode_info->type == UG_FILE_TYPE_APP) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_THEME) {
		if (pnode_info->type == UG_FILE_TYPE_THEME) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_DOC) {
		if (pnode_info->type == UG_FILE_TYPE_DOC) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_EXCEL) {
		if (pnode_info->type == UG_FILE_TYPE_EXCEL) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_PPT) {
		if (pnode_info->type == UG_FILE_TYPE_PPT) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_PDF) {
		if (pnode_info->type == UG_FILE_TYPE_PDF) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_TXT) {
		if (pnode_info->type == UG_FILE_TYPE_TXT) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VCONTACT) {
		if (pnode_info->type == UG_FILE_TYPE_VCONTACT) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VCALENDAR) {
		if (pnode_info->type == UG_FILE_TYPE_VCALENDAR) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VNOTE) {
		if (pnode_info->type == UG_FILE_TYPE_VNOTE) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VBOOKMARK) {
		if (pnode_info->type == UG_FILE_TYPE_VBOOKMARK) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_VIDEO_PROJECT) {
		if (pnode_info->type == UG_FILE_TYPE_VIDEO_PROJECT) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_SVG) {
		if (pnode_info->type == UG_FILE_TYPE_SVG) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_RSS) {
		if (pnode_info->type == UG_FILE_TYPE_RSS) {
			return TRUE;
		}
	}
	if (option & UG_FILTER_CATEGORY_ETC) {
		if (pnode_info->type == UG_FILE_TYPE_ETC) {
			return TRUE;
		}
	}
	return FALSE;
}

int mf_ug_fs_oper_list_filter(Eina_List *in_list, Eina_List **out_list, int option, int drm_opt)
{
	ug_mf_debug();
	if (in_list == NULL) {
		return MYFILE_ERR_SRC_ARG_INVALID;
	}

	if (out_list == NULL) {
		return MYFILE_ERR_DST_ARG_INVALID;
	}

	if (option == 0) {
		*out_list = in_list;
		return MYFILE_ERR_NONE;
	}

	Eina_List *l = NULL;
	ugFsNodeInfo *data = NULL;
	EINA_LIST_FOREACH(in_list, l, data) {
		if (data->type == UG_FILE_TYPE_DRM && __mf_ug_fs_oper_exec_drm_filter(data, drm_opt)) {
			ug_debug("file [%s] is drm file", data->name);
			*out_list = eina_list_append(*out_list, data);
		} else if (__mf_ug_fs_oper_exec_filter(data, option)) {
			*out_list = eina_list_append(*out_list, data);
		}
	}
	return MYFILE_ERR_NONE;
}

/******************************
** Prototype    : ug_mf_list_filter_by_extention
** Description  : filter from list by extension
** Input        : Eina_List *in_list
**                Eina_List **out_list
**                char* ext
** Output       : None
** Return Value :
** Calls        :
** Called By    :
**
**  History        :
**  1.Date         : 2010/12/10
**    Author       : Samsung
**    Modification : Created function
**
******************************/
int mf_ug_fs_oper_list_filter_by_extension(Eina_List *in_list, Eina_List **out_list, char *ext)
{
	if (in_list == NULL) {
		return MYFILE_ERR_SRC_ARG_INVALID;
	}

	if (out_list == NULL) {
		return MYFILE_ERR_DST_ARG_INVALID;
	}

	if (ext == NULL) {
		*out_list = in_list;
		return MYFILE_ERR_NONE;
	}

	Eina_List *l = NULL;
	ugFsNodeInfo *data = NULL;

	char *seps = ";";
	char *temp_ext = malloc(strlen(ext) + 1);
	gchar **result = NULL;
	gchar **params = NULL;

	EINA_LIST_FOREACH(in_list, l, data) {
		memset(temp_ext, 0, strlen(ext) + 1);
		strncpy(temp_ext, ext, strlen(ext));
		result = g_strsplit(temp_ext, seps, 0);
		if (result == NULL) {
			continue;
		}
		for (params = result; *params; params++) {
			if (data->ext == NULL)
				break;
			if (strcasecmp(data->ext, *params) == 0) {
				*out_list = eina_list_append(*out_list, data);
				break;
			}
		}

		g_strfreev(result);
		result = NULL;
	}
	free(temp_ext);
	return MYFILE_ERR_NONE;
}

static int __mf_ug_fs_oper_sort_by_priority(const void *d1, const void *d2, int sequence_type)
{
	int ret = 0;
	switch(sequence_type) {
	case MF_UG_SORT_BY_PRIORITY_TYPE_A2Z:
		ret = __mf_ug_fs_oper_sort_by_date_cb_O2R(d1, d2);
		if (ret == 0) {
			ret = __mf_ug_fs_oper_sort_by_size_cb_S2L(d1, d2);
			if (ret == 0) {
				ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2);
			}
		}
		break;
	case MF_UG_SORT_BY_PRIORITY_TYPE_Z2A:
		ret = __mf_ug_fs_oper_sort_by_date_cb_R2O(d1, d2);
		if (ret == 0) {
			ret = __mf_ug_fs_oper_sort_by_size_cb_L2S(d1, d2);
			if (ret == 0) {
				ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2);
			}
		}
		break;
	case MF_UG_SORT_BY_PRIORITY_DATE_O2R:
		ret = __mf_ug_fs_oper_sort_by_size_cb_S2L(d1, d2);
		if (ret == 0) {
			ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2);
		}
		break;
	case MF_UG_SORT_BY_PRIORITY_DATE_R2O:
		ret = __mf_ug_fs_oper_sort_by_size_cb_L2S(d1, d2);
		if (ret == 0) {
			ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2);
		}
		break;
	case MF_UG_SORT_BY_PRIORITY_SIZE_S2L:
		ret = __mf_ug_fs_oper_sort_by_name_cb_A2Z(d1, d2);
		break;
	case MF_UG_SORT_BY_PRIORITY_SIZE_L2S:
		ret = __mf_ug_fs_oper_sort_by_name_cb_Z2A(d1, d2);
		break;
	default:
		break;
	}
	return ret;
}
/*********************
**Function name:	__sort_by_name_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 > d2
**
**Action:
**	sort the list order by the Assic table

**
*********************/
static int __mf_ug_fs_oper_sort_by_name_cb_A2Z(const void *d1, const void *d2)
{
	ugFsNodeInfo *txt1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *txt2 = (ugFsNodeInfo *) d2;
	gchar *name1 = NULL;
	gchar *name2 = NULL;
	int result = 0;

	if (!txt1) {
		return (1);
	}
	if (!txt2) {
		return (-1);
	}

	name1 = g_ascii_strdown(txt1->name, strlen(txt1->name));
	if (name1 == NULL) {
		return (-1);
	}
	name2 = g_ascii_strdown(txt2->name, strlen(txt2->name));
	if (name2 == NULL) {
		g_free(name1);
		name1 = NULL;
		return (-1);
	}
	result = g_strcmp0(name1, name2);

	g_free(name1);
	name1 = NULL;
	g_free(name2);
	name2 = NULL;
	return result;

}

/*********************
**Function name:	__sort_by_date_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 > d2
**
**Action:
**	sort the list order by the later created the later shown
*********************/
static int __mf_ug_fs_oper_sort_by_date_cb_O2R(const void *d1, const void *d2)
{
	int ret = 0;
	ugFsNodeInfo *time1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *time2 = (ugFsNodeInfo *) d2;

	if (!d1) {
		return 1;
	}
	if (!d2) {
		return -1;
	}

	if (time1->date > time2->date) {
		ret = 1;
	} else if (time1->date < time2->date) {
		ret = -1;
	} else {
		ret = 0;
	}

	if (ret == 0) {
		ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_DATE_O2R);
	}
	return ret;
}

/*********************
**Function name:	__sort_by_type_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 < d2
**	0	if d1 = d2
**	1	if d1 > d2
**
**Action:
**	sort the list order by the category type value
*********************/
static int __mf_ug_fs_oper_sort_by_type_cb_A2Z(const void *d1, const void *d2)
{
	ugFsNodeInfo *type1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *type2 = (ugFsNodeInfo *) d2;
	gchar *ext1 = NULL;
	gchar *ext2 = NULL;
	int result = 0;

	if (type1 == NULL || type1->ext == NULL) {
		return 1;
	}

	if (type2 == NULL || type2->ext == NULL) {
		return -1;
	}
	ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext));
	if (ext1 == NULL) {
		return (-1);
	}
	ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext));
	if (ext2 == NULL) {
		g_free(ext1);
		ext1 = NULL;
		return (-1);
	}
	result = g_strcmp0(ext1, ext2);

	g_free(ext1);
	ext1 = NULL;
	g_free(ext2);
	ext2 = NULL;

	if (result == 0) {
		result = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_TYPE_A2Z);
	}

	return result;
}

/*order:	the one with smaller size will be shown earlier*/
/*********************
**Function name:	__sort_by_name_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 > d2
**
**Action:
**	sort the list order by size, rule is the smaller the later shown
*********************/
static int __mf_ug_fs_oper_sort_by_size_cb_S2L(const void *d1, const void *d2)
{
	int ret = 0;
	ugFsNodeInfo *size1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *size2 = (ugFsNodeInfo *) d2;

	if (!d1) {
		return 1;
	}

	if (!d2) {
		return -1;
	}

	if (size1->size > size2->size) {
		ret = 1;
	} else if (size1->size < size2->size) {
		ret = -1;
	} else {
		ret = 0;
	}

	if (ret == 0) {
		ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_SIZE_S2L);
	}
	return ret;
}

/*********************
**Function name:	__mf_fs_oper_sort_by_name_cb_Z2A
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	1	if d1 > d2
**	-1	if d1 <= d2
**
**Action:
**	sort the list order by the Assic table

**
*********************/
static int __mf_ug_fs_oper_sort_by_name_cb_Z2A(const void *d1, const void *d2)
{
	ugFsNodeInfo *txt1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *txt2 = (ugFsNodeInfo *) d2;

	int result = 0;

	if (!txt1) {
		return (1);
	}
	if (!txt2) {
		return (-1);
	}
	result = strcasecmp(txt1->name, txt2->name);

	if (result < 0) {
		return (1);
	} else {
		return (-1);
	}
}

/*********************
**Function name:	__sort_by_date_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 < d2
**
**Action:
**	sort the list order by the later created the later shown
*********************/
static int __mf_ug_fs_oper_sort_by_date_cb_R2O(const void *d1, const void *d2)
{
	int ret = 0;
	ugFsNodeInfo *time1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *time2 = (ugFsNodeInfo *) d2;

	if (!d1) {
		return -1;
	}
	if (!d2) {
		return 1;
	}
	if (time1->date > time2->date) {
		ret = -1;
	} else if (time1->date < time2->date) {
		ret = 1;
	} else {
		ret = 0;
	}

	if (ret == 0) {
		ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_DATE_R2O);
	}
	return ret;
}

/*********************
**Function name:	__sort_by_type_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 < d2
**
**Action:
**	sort the list order by the category type value
*********************/
static int __mf_ug_fs_oper_sort_by_type_cb_Z2A(const void *d1, const void *d2)
{
	ugFsNodeInfo *type1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *type2 = (ugFsNodeInfo *) d2;
	gchar *ext1 = NULL;
	gchar *ext2 = NULL;
	int result = 0;

	if (type1 == NULL || type1->ext == NULL) {
		return -1;
	}

	if (type2 == NULL || type2->ext == NULL) {
		return 1;
	}

	ext1 = g_ascii_strdown(type1->ext, strlen(type1->ext));
	if (ext1 == NULL) {
		return (1);
	}
	ext2 = g_ascii_strdown(type2->ext, strlen(type2->ext));
	if (ext2 == NULL) {
		g_free(ext1);
		ext1 = NULL;
		return (-1);
	}
	result = g_strcmp0(ext1, ext2);
	g_free(ext1);
	ext1 = NULL;
	g_free(ext2);
	ext2 = NULL;
	if (result == 0) {
		result = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_TYPE_Z2A);
	}

	return -result;
}

/*order:	the one with smaller size will be shown earlier*/
/*********************
**Function name:	__sort_by_name_cb
**Parameter:
**	const void *d1:	node1 to compare
**	const void *d2:	node2 to compare
**
**Return value:
**	-1	if d1 > d2
**	0	if d1 = d2
**	1	if d1 < d2
**
**Action:
**	sort the list order by size, rule is the smaller the later shown
*********************/
static int __mf_ug_fs_oper_sort_by_size_cb_L2S(const void *d1, const void *d2)
{
	int ret = 0;
	ugFsNodeInfo *size1 = (ugFsNodeInfo *) d1;
	ugFsNodeInfo *size2 = (ugFsNodeInfo *) d2;

	if (!d1) {
		return -1;
	}

	if (!d2) {
		return 1;
	}

	if (size1->size > size2->size) {
		ret = -1;
	} else if (size1->size < size2->size) {
		ret = 1;
	} else {
		ret = 0;
	}

	if (ret == 0) {
		ret = __mf_ug_fs_oper_sort_by_priority(d1, d2, MF_UG_SORT_BY_PRIORITY_SIZE_L2S);
	}
	return ret;
}

/*********************
**Function name:	mf_fs_oper_sort_list
**Parameter:
**	Eina_List **list:	the list we need to sort
**	int sort_opt:		sort option
**
**Return value:
**	void
**
**Action:
**	sort the list order by sort option with the call back
*********************/
void mf_ug_fs_oper_sort_list(Eina_List **list, int sort_opt)
{
	Eina_Compare_Cb sort_func = NULL;
	if (!(*list)) {
		return;
	}
	switch (sort_opt) {
	case MF_UG_SORT_BY_NAME_A2Z:
		sort_func = __mf_ug_fs_oper_sort_by_name_cb_A2Z;
		break;
	case MF_UG_SORT_BY_TYPE_A2Z:
		sort_func = __mf_ug_fs_oper_sort_by_type_cb_A2Z;
		break;
	case MF_UG_SORT_BY_SIZE_S2L:
		sort_func = __mf_ug_fs_oper_sort_by_size_cb_S2L;
		break;
	case MF_UG_SORT_BY_DATE_O2R:
		sort_func = __mf_ug_fs_oper_sort_by_date_cb_O2R;
		break;
	case MF_UG_SORT_BY_NAME_Z2A:
		sort_func = __mf_ug_fs_oper_sort_by_name_cb_Z2A;
		break;
	case MF_UG_SORT_BY_TYPE_Z2A:
		sort_func = __mf_ug_fs_oper_sort_by_type_cb_Z2A;
		break;
	case MF_UG_SORT_BY_SIZE_L2S:
		sort_func = __mf_ug_fs_oper_sort_by_size_cb_L2S;
		break;
	case MF_UG_SORT_BY_DATE_R2O:
		sort_func = __mf_ug_fs_oper_sort_by_date_cb_R2O;
		break;
	default:
		sort_func = __mf_ug_fs_oper_sort_by_type_cb_A2Z;
		break;
	}
	*list = eina_list_sort(*list, eina_list_count(*list), sort_func);
}

int mf_ug_fs_oper_create_dir(const char *dir)
{
	int option = MF_ERROR_CHECK_SRC_ARG_VALID | MF_ERROR_CHECK_DUPLICATED;
	int ret = __mf_ug_fs_oper_file_system_error(dir, dir, option);

	if (ret != 0) {
		return ret;
	}

	ret = mf_ug_file_attr_is_right_dir_path(dir);

	if (ret != 0) {
		return ret;
	}

	mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;

	if (mkdir(dir, default_mode) < 0) {
		return MYFILE_ERR_DIR_CREATE_FAIL;
	}
	return MYFILE_ERR_NONE;
}