[cleanup]revise file location and name
[platform/core/connectivity/mtp-responder.git] / include / mtp_util_fs.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_FS_H_
18 #define _MTP_FS_H_
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include <dirent.h>
25 #include "mtp_datatype.h"
26 #include "mtp_config.h"
27
28 #define LINUX_MAX_PATHNAME_LENGTH       4096
29 #define MTP_FILE_ATTR_INVALID           0xFFFFFFFF
30 #define MTP_LOG_FILE                    "/var/log/mtp.log"
31 #define MTP_LOG_MAX_SIZE                5 * 1024 * 1024 /*5MB*/
32
33 typedef enum {
34         MTP_FILE_TYPE = 0,
35         MTP_DIR_TYPE,
36         MTP_ALL_TYPE
37 } file_type_t;
38
39 typedef enum {
40         MTP_FILE_ATTR_MODE_NONE = 0x00000000,
41         MTP_FILE_ATTR_MODE_REG  = 0x00000100,
42         MTP_FILE_ATTR_MODE_DIR = 0x00000200,
43         MTP_FILE_ATTR_MODE_READ_ONLY = 0x00000400,
44         MTP_FILE_ATTR_MODE_HIDDEN = 0x00000800,
45         MTP_FILE_ATTR_MODE_SYSTEM = 0x00001000
46 } file_attr_mode_t;
47
48 typedef struct {
49         file_attr_mode_t attribute;
50         mtp_uint64 fsize;
51         time_t ctime;  /* created time */
52         time_t mtime;   /* modified time */
53 } file_attr_t;
54
55 typedef struct {
56         mtp_char filename[MTP_MAX_PATHNAME_SIZE + 1];
57         file_type_t type;
58         file_attr_t attrs;
59 } dir_entry_t;
60
61 typedef enum {
62         MTP_FILE_READ = 0x1,
63         MTP_FILE_WRITE = 0x2,
64         MTP_FILE_APPEND = 0x4,
65         MTP_FILE_TRUNCATE = 0x8
66 } file_mode_t;
67
68 typedef struct {
69         mtp_uint64 disk_size;
70         mtp_uint64 avail_size;
71         mtp_uint64 reserved_size;
72 } fs_info_t;
73
74 FILE* _util_file_open(const mtp_char *filename, file_mode_t mode,
75                 mtp_int32 *error);
76 void _util_file_read(FILE* fhandle, void *bufptr, mtp_uint32 size,
77                 mtp_uint32 *read_count);
78 mtp_uint32 _util_file_write(FILE* fhandle, void *bufptr, mtp_uint32 size);
79 mtp_int32 _util_file_close(FILE* fhandle);
80 mtp_bool _util_file_seek(FILE* fhandle, off_t offset, mtp_int32 whence);
81 mtp_bool _util_file_copy(const mtp_char *origpath, const mtp_char *newpath,
82                 mtp_int32 *error);
83 mtp_bool _util_copy_dir_children_recursive(const mtp_char *origpath,
84                 const mtp_char *newpath, mtp_uint32 store_id, mtp_int32 *error);
85 mtp_bool _util_file_move(const mtp_char *origpath, const mtp_char *newpath,
86                 mtp_int32 *error);
87 mtp_bool _util_get_file_attrs(const mtp_char *filename, file_attr_t *attrs);
88 mtp_bool _util_set_file_attrs(const mtp_char *filename, mtp_dword attrs);
89 mtp_bool _util_dir_create(const mtp_char *dirname, mtp_int32 *error);
90 mtp_int32 _util_remove_dir_children_recursive(const mtp_char *dirname,
91                 mtp_uint32 *num_of_deleted_file, mtp_uint32 *num_of_file, mtp_bool readonly);
92 mtp_bool _util_ifind_next(char *dir_name, DIR *dirp, dir_entry_t *dir_info);
93 mtp_bool _util_ifind_first(char *dir_name, DIR **dirp, dir_entry_t *dir_info);
94 mtp_bool _util_is_file_opened(const mtp_char *fullpath);
95 mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info);
96 void _util_count_num_lines(FILE* fhandle, mtp_uint32 *num_lines);
97 void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index, FILE* fhandle,
98                 mtp_uint32 size);
99 void FLOGD(const char *fmt, ...);
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif /* _MTP_FS_H_ */