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