Fix double free
[platform/core/connectivity/mtp-responder.git] / include / mtp_entity_store.h
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _MTP_STORE_H_
18 #define _MTP_STORE_H_
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include "mtp_entity_object.h"
25
26
27 /* First six members of SStorageInfo structure */
28 #define FIXED_LENGTH_MEMBERS_MTPSTORE_SIZE \
29         (sizeof(mtp_uint16) * 3 + sizeof(mtp_uint64) * 2 + sizeof(mtp_uint32))
30
31 typedef enum {
32         MTPSTORE_WMPINFO_PHONE = 1,
33         MTPSTORE_WMPINFO_CARD
34 } store_special_obj_t;
35
36 /*
37  * store_info
38  * This structure stores store information for each store
39  */
40 typedef struct {
41         mtp_uint16 store_type;  /*storage type*/
42         mtp_uint16 fs_type;     /*file system type*/
43         mtp_uint16 access;      /*access capability(read/write)*/
44         mtp_uint64 capacity;    /*maximum capacity in bytes*/
45         mtp_uint64 free_space;  /*free space in bytes*/
46         mtp_uint32 free_space_in_objs;  /*free space in objects*/
47         ptp_string_t store_desc;
48         ptp_string_t vol_label; /*optional volume label: variable length*/
49 } store_info_t;
50
51 /*
52  * MTP store structure.
53  * This structure is instantiated for each store within the MTP device.
54  */
55 typedef struct {
56         mtp_char *root_path;    /* Root path of the store */
57         mtp_uint32 store_id;
58         store_info_t store_info;
59         slist_t obj_list;
60         mtp_bool is_hidden;     /*for hidden storage*/
61 } mtp_store_t;
62
63 typedef struct {
64         mtp_uint32 h_parent;
65         mtp_store_t *store;
66         ptp_array_t child_data;
67 } missing_child_data_t;
68
69 typedef enum {
70         MTP_INTERNAL_STORE_ID = 0x10001,
71         MTP_EXTERNAL_STORE_ID = 0x20001
72 } mtp_store_id_t;
73
74 typedef enum {
75         MTP_ADDREM_AUTO,
76         MTP_ADDREM_INTERNAL,
77         MTP_ADDREM_EXTERNAL,
78         MTP_ADDREM_ALL
79 } add_rem_store_t;
80
81 void _entity_update_store_info_run_time(store_info_t *info,
82                 mtp_char *root_path);
83 mtp_bool _entity_get_store_path_by_id(mtp_uint32 store_id, mtp_char *path);
84 mtp_uint32 _entity_get_store_info_size(store_info_t *info);
85 mtp_uint32 _entity_pack_store_info(store_info_t *info, mtp_uchar *buf,
86                 mtp_uint32 buf_sz);
87 mtp_uint32 _entity_get_store_id_by_path(const mtp_char *path_name);
88 mtp_bool _entity_init_mtp_store(mtp_store_t *store, mtp_uint32 store_id,
89                 mtp_char *store_path);
90 mtp_obj_t *_entity_add_file_to_store(mtp_store_t *store, mtp_uint32 h_parent,
91                 mtp_char *file_path, mtp_char *file_name, dir_entry_t *file_info);
92 mtp_obj_t *_entity_add_folder_to_store(mtp_store_t *store, mtp_uint32 h_parent,
93                 mtp_char *file_path, mtp_char *file_name, dir_entry_t *file_info);
94 mtp_bool _entity_add_object_to_store(mtp_store_t *store, mtp_obj_t *obj);
95 mtp_obj_t *_entity_get_object_from_store(mtp_store_t *store, mtp_uint32 handle);
96 mtp_obj_t *_entity_get_last_object_from_store(mtp_store_t *store,
97                 mtp_uint32 handle);
98 mtp_obj_t *_entity_get_object_from_store_by_path(mtp_store_t *store,
99                 const mtp_char *file_path);
100 mtp_uint32 _entity_get_objects_from_store(mtp_store_t *store,
101                 mtp_uint32 obj_handle, mtp_uint32 fmt, ptp_array_t *obj_arr);
102 mtp_uint32 _entity_get_objects_from_store_till_depth(mtp_store_t *store,
103                 mtp_uint32 obj_handle, mtp_uint32 fmt_code, mtp_uint32 depth,
104                 ptp_array_t *obj_arr);
105 mtp_uint32 _entity_get_objects_from_store_by_format(mtp_store_t *store,
106                 mtp_uint32 format, ptp_array_t *obj_arr);
107 mtp_uint32 _entity_get_num_object_with_same_format(mtp_store_t *store,
108                 mtp_uint32 format);
109 mtp_uint32 _entity_get_num_children(mtp_store_t *store, mtp_uint32 h_parent,
110                 mtp_uint32 format);
111 mtp_uint32 _entity_get_child_handles(mtp_store_t *store, mtp_uint32 h_parent,
112                 ptp_array_t *child_arr);
113 mtp_uint32 _entity_get_child_handles_with_same_format(mtp_store_t *store,
114                 mtp_uint32 h_parent, mtp_uint32 format, ptp_array_t *child_arr);
115 mtp_bool _entity_remove_object_mtp_store(mtp_store_t *store, mtp_obj_t *obj,
116                 mtp_uint32 format, mtp_uint16 *response, mtp_bool *atleast_one,
117                 mtp_bool read_only);
118 mtp_uint16 _entity_delete_obj_mtp_store(mtp_store_t *store,
119                 mtp_uint32 obj_handle, mtp_uint32 fmt, mtp_bool read_only);
120 mtp_uint32 _entity_get_object_tree_size(mtp_store_t *store, mtp_obj_t *obj);
121 mtp_bool _entity_check_if_B_parent_of_A(mtp_store_t *store,
122                 mtp_uint32 handleA, mtp_uint32 handleB);
123 mtp_uint32 _entity_generate_next_obj_handle(void);
124 mtp_uint16 _entity_format_store(mtp_store_t *store, mtp_uint32 fs_format);
125 void _entity_destroy_mtp_store(mtp_store_t *store);
126 void _entity_store_recursive_enum_folder_objects(mtp_store_t *store,
127                 mtp_obj_t *pobj);
128 void _entity_list_modified_files(mtp_uint32 minutes);
129 void _entity_copy_store_data(mtp_store_t *dst, mtp_store_t *src);
130
131 #ifdef __cplusplus
132 }
133 #endif
134
135 #endif /* _MTP_STORE_H_ */