-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpfs.h
153 lines (140 loc) · 5.04 KB
/
pfs.h
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
/* Copyright (c) 2013-2014 Anton Titov.
* Copyright (c) 2013-2014 pCloud Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of pCloud Ltd nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL pCloud Ltd BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PSYNC_FS_H
#define _PSYNC_FS_H
#include "psynclib.h"
#include "ptree.h"
#include "pintervaltree.h"
#include "papi.h"
#include "psettings.h"
#include "pfsfolder.h"
#include "pfstasks.h"
#include "pcompat.h"
#include "pcrypto.h"
#include "pcrc32c.h"
#include <pthread.h>
#if defined(P_OS_POSIX)
#define psync_fs_need_per_folder_refresh() psync_fs_need_per_folder_refresh_f()
#define psync_fs_need_per_folder_refresh_const() 1
#else
#define psync_fs_need_per_folder_refresh() (psync_invalidate_os_cache_needed() && psync_fs_need_per_folder_refresh_f())
#define psync_fs_need_per_folder_refresh_const() 1
#endif
extern char *psync_fake_prefix;
extern size_t psync_fake_prefix_len;
typedef struct {
uint64_t frompage;
uint64_t topage;
uint64_t length;
uint64_t requestedto;
uint64_t id;
time_t lastuse;
} psync_file_stream_t;
typedef struct {
pthread_cond_t cond;
uint64_t extendto;
uint64_t extendedto;
uint32_t waiters;
int error;
unsigned char ready;
unsigned char kill;
} psync_enc_file_extender_t;
typedef struct {
psync_tree tree;
psync_file_stream_t streams[PSYNC_FS_FILESTREAMS_CNT];
pthread_mutex_t mutex;
psync_interval_tree_t *writeintervals;
psync_fstask_folder_t *currentfolder;
char *currentname;
psync_fsfileid_t fileid;
psync_fsfileid_t remotefileid;
union {
uint64_t hash;
const char *staticdata;
};
uint64_t initialsize;
uint64_t currentsize;
uint64_t laststreamid;
uint64_t indexoff;
union {
uint64_t writeid;
time_t staticctime;
};
time_t currentsec;
time_t origctime;
psync_file_t datafile;
psync_file_t indexfile;
uint32_t refcnt;
uint32_t condwaiters;
uint32_t runningreads;
uint32_t currentspeed;
uint32_t bytesthissec;
unsigned char modified;
unsigned char newfile;
unsigned char releasedforupload;
unsigned char deleted;
unsigned char encrypted;
unsigned char throttle;
unsigned char staticfile;
/*
* for non-encrypted files only offsetof(psync_openfile_t, encoder) bytes are allocated
* keep all fields for encryption after encoder
*/
psync_crypto_aes256_sector_encoder_decoder_t encoder;
psync_tree *sectorsinlog;
psync_interval_tree_t *authenticatedints;
psync_fast_hash256_ctx loghashctx;
psync_enc_file_extender_t *extender;
psync_file_t logfile;
uint32_t logoffset;
} psync_openfile_t;
typedef struct {
uint64_t offset;
uint64_t length;
} psync_fs_index_record;
typedef struct {
int dummy[0];
} psync_fs_index_header;
int psync_fs_crypto_err_to_errno(int cryptoerr);
int psync_fs_update_openfile(uint64_t taskid, uint64_t writeid, psync_fileid_t newfileid, uint64_t hash, uint64_t size, time_t ctime);
//void psync_fs_uploading_openfile(uint64_t taskid);
int psync_fs_rename_openfile_locked(psync_fsfileid_t fileid, psync_fsfolderid_t folderid, const char *name);
void psync_fs_mark_openfile_deleted(uint64_t taskid);
int64_t psync_fs_get_file_writeid(uint64_t taskid);
int64_t psync_fs_load_interval_tree(psync_file_t fd, uint64_t size, psync_interval_tree_t **tree);
int psync_fs_remount();
void psync_fs_inc_of_refcnt_locked(psync_openfile_t *of);
void psync_fs_inc_of_refcnt(psync_openfile_t *of);
void psync_fs_dec_of_refcnt(psync_openfile_t *of);
void psync_fs_inc_of_refcnt_and_readers(psync_openfile_t *of);
void psync_fs_dec_of_refcnt_and_readers(psync_openfile_t *of);
void psync_fs_refresh();
int psync_fs_need_per_folder_refresh_f();
void psync_fs_refresh_folder(psync_folderid_t folderid);
void psync_fs_pause_until_login();
void psync_fs_clean_tasks();
#endif